LiDAR Control Module#
Access LiDAR sensor data from the Unitree Go2 robot or the Mujoco Simulator.
Users are recommended to interact with LIDARModule when
PointCloud2 data is needed.
If the provided modules do not sufficiently meet your needs, you can bypass them and use an alternative approach. You can also submit a feature request on the main GitHub page, and it will be considered for future updates.
- class go2.modules.lidar.lidar_module.LIDARModule(publish_hz: int = 10)[source]#
Bases:
DogModuleLIDARModuleprovides a simple API for:Receiving decoded
PointCloud2structures as xyz-(optionally intensity) numpy arrays
Users should not access or construct this class directly. Rather, they should access it through the
Go2Controllerinstance.- Parameters:
publish_hz (int) –
The publishing frequency (in Hz) of decoded point cloud frames. This dictates how many times per second the registered callback is triggered. A lower publishing rate results in a longer point accumulation time per frame, yielding a denser point cloud with greater field-of-view (FOV) coverage, but introduces higher delay between publishings. (Although, the data transfer will always be an O(1) pointer-swap internally). Must be in the range [5, 100]. Default is 10.
When running in
HardwareType.Nativemode,publish_hzdoes not control the actual publish rate of the physical LIDAR sensor. You must configure that rate manually via the LIDAR’s own driver/firmware settings. In this mode,publish_hzonly governs how frequently this wrapper internally polls for new data over IPC from the ROS2 publisher node to this receiver.When running in
HardwareType.Virtualmode,publish_hzdoes matter, since we are mocking the real LIDAR and fully control when it publishes data.
Important
When executing on
HardwareType.Nativethis module launches ROS2 nodes. In such a case, it is critical that students ALWAYS callGo2Controller.safe_shutdown()after normal (error free) script exit.- register_decoded_pointcloud_callback(callback: Callable[[int, ndarray], None]) None[source]#
Register a callback to receive decoded PointCloud2 data. The callback is triggered whenever a new raw point cloud sample is received via Iceoryx2.
- Parameters:
callback (Callable[[int, np.ndarray], None]) –
- A function to be called with:
timestamp (int): The source timestamp in nanoseconds.
- points (np.ndarray): A Fortran-contiguous
float32array of shape(3, N) for [x, y, z] or
(4, N)if intensity is supported [x, y, z, intensity].
- points (np.ndarray): A Fortran-contiguous
Important
- Shared Views:
During each cycle, all subscribers receive views of the same underlying data. This is done for performance. Modifying data through the returned view is unsafe, as it affects the shared data. If you need to modify the data, create a copy first.
- Cache Locality & Iteration:
Because the array is Fortran-contiguous, the data is laid out column-by-column in memory (e.g., x0, y0, z0, x1, y1, z1…). This means all coordinates (plus intensity) for a single point are tightly packed together. Therefore, column-major iteration should be greatly prefered over row-major iteration to maximize cache efficiency. If you need a C-contiguous array (row-major) you can use use
numpy.ascontiguousarray(array).