Skip to content

Conversation

@pascal-roth
Copy link
Collaborator

@pascal-roth pascal-roth commented Jan 25, 2026

Description

This PR fixes a bug in the lidar pattern horizontal angle calculation and enhances the test suite for ray caster patterns.

Bug Fix: The lidar pattern was generating incorrect number of horizontal angles, causing the actual angular resolution to differ from the requested resolution. For example, requesting 90° resolution for a 360° FOV produced only 3 rays (120° spacing) instead of 4 rays (90° spacing)

Test Enhancements:

  • Added comprehensive parameterized tests to verify the fix
  • Parameterized all tests over both CUDA and CPU devices
  • Consolidated redundant tests (reduced from 24 to 18 test functions while maintaining coverage)
  • Improved test efficiency with batched operations

Fixes #4430

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality - enhanced test suite)

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the changelog and the corresponding version in the extension's config/extension.toml file
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

@github-actions github-actions bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels Jan 25, 2026
@pascal-roth pascal-roth self-assigned this Jan 25, 2026
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 25, 2026

Greptile Overview

Greptile Summary

Fixed a critical bug in lidar_pattern where the horizontal angle calculation produced incorrect angular spacing. The issue was that torch.linspace(start, end, n) creates n-1 intervals, so requesting 90° resolution for 360° FOV produced only 3 rays with 120° spacing instead of 4 rays with 90° spacing.

Key Changes:

  • Added + 1 to num_horizontal_angles calculation in patterns.py:157-159 to account for linspace interval behavior
  • Added comprehensive test suite (test_ray_caster_patterns.py) with:
    • Parameterized test test_lidar_pattern_exact_angles specifically validating angular spacing matches requested resolution
    • Device parameterization (CUDA/CPU) across all tests via pytest fixture
    • Tests for grid, lidar, bpearl, and pinhole camera patterns
    • Validation of ray count, angular spacing, normalization, and wraparound behavior

The fix is mathematically correct and thoroughly tested.

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The change is a minimal, well-understood mathematical fix (+1 to a calculation) that addresses a specific bug. The comprehensive test suite validates the fix across multiple scenarios and devices, and the change has no breaking implications.
  • No files require special attention

Important Files Changed

Filename Overview
source/isaaclab/isaaclab/sensors/ray_caster/patterns/patterns.py Fixed critical horizontal angle calculation bug by adding +1 to num_horizontal_angles to ensure correct angular resolution
source/isaaclab/test/sensors/test_ray_caster_patterns.py Added comprehensive test suite with parameterized tests validating the fix, including angular spacing verification and device coverage

Sequence Diagram

sequenceDiagram
    participant User
    participant LidarPatternCfg
    participant lidar_pattern
    participant torch
    participant RayCaster

    User->>LidarPatternCfg: Create config with horizontal_res=90°, FOV=360°
    User->>lidar_pattern: Call lidar_pattern(cfg, device)
    
    lidar_pattern->>lidar_pattern: Create vertical_angles via linspace
    
    lidar_pattern->>lidar_pattern: Check if 360° FOV (line 151-154)
    Note over lidar_pattern: If 360°: up_to = -1<br/>Else: up_to = None
    
    lidar_pattern->>lidar_pattern: Calculate num_horizontal_angles (FIX)
    Note over lidar_pattern: OLD: ceil(360/90) = 4<br/>NEW: ceil(360/90) + 1 = 5
    
    lidar_pattern->>torch: linspace(start, end, num_horizontal_angles)
    Note over torch: Creates 5 points: [-180°, -90°, 0°, 90°, 180°]
    
    lidar_pattern->>lidar_pattern: Apply [:up_to] slicing
    Note over lidar_pattern: For 360° FOV: removes last point<br/>Result: [-180°, -90°, 0°, 90°]<br/>Spacing: 90° ✓
    
    lidar_pattern->>lidar_pattern: Convert to radians and create meshgrid
    lidar_pattern->>lidar_pattern: Spherical to Cartesian conversion
    lidar_pattern->>RayCaster: Return (ray_starts, ray_directions)
    
    Note over User,RayCaster: Result: Correct 90° angular spacing<br/>4 rays instead of 3 (120° spacing)
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@tobiabir
Copy link

A very clean fix. Thank you @pascal-roth. This does indeed solve #4430.

nit: Long-term, I still think it would be nice to have consistency in the configuration between horizontal and vertical (i.e. number of channels vs resolution).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug Report] Lidar pattern does not follow horizontal resolution

3 participants