Add CpuLidar system plugin with optimized physics raycasting#3343
Open
apojomovsky wants to merge 17 commits intogazebosim:mainfrom
Open
Add CpuLidar system plugin with optimized physics raycasting#3343apojomovsky wants to merge 17 commits intogazebosim:mainfrom
apojomovsky wants to merge 17 commits intogazebosim:mainfrom
Conversation
Zyrin
reviewed
Feb 20, 2026
8489df8 to
d7fa3d6
Compare
…ulation, result feeding, and integration tests Generated-by: Claude Opus 4.6 Signed-off-by: Alexis Pojomovsky <apojomovsky@gmail.com>
Generated-by: Claude Opus 4.6 Signed-off-by: Alexis Pojomovsky <apojomovsky@gmail.com>
Generated-by: Claude Opus 4.6 Signed-off-by: Alexis Pojomovsky <apojomovsky@gmail.com>
Generated-by: Claude Opus 4.6 Signed-off-by: Alexis Pojomovsky <apojomovsky@gmail.com>
Generated-by: Claude Opus 4.6 Signed-off-by: Alexis Pojomovsky <apojomovsky@gmail.com>
Generated-by: Claude Opus 4.6 Signed-off-by: Alexis Pojomovsky <apojomovsky@gmail.com>
Physics was raycasting every simulation step (e.g. 1 kHz) even though a CPU lidar only needs fresh results at its own update rate (e.g. 10 Hz). This caused ~100× wasted raycast work per real scan. Generated-by: Claude Opus 4.6 Signed-off-by: Alexis Pojomovsky <apojomovsky@gmail.com>
Generated-by: Claude Opus 4.6 Signed-off-by: Alexis Pojomovsky <apojomovsky@gmail.com>
Generated-by: Claude Opus 4.6 Signed-off-by: Alexis Pojomovsky <apojomovsky@gmail.com>
Generated-by: Claude Opus 4.6 Signed-off-by: Alexis Pojomovsky <apojomovsky@gmail.com>
Generated-by: Claude Opus 4.6 Signed-off-by: Alexis Pojomovsky <apojomovsky@gmail.com>
Generated-by: Claude Sonnet 4.6 Signed-off-by: Alexis Pojomovsky <apojomovsky@gmail.com>
This reverts commit 4de207b. Signed-off-by: Alexis Pojomovsky <apojomovsky@gmail.com>
Signed-off-by: Alexis Pojomovsky <apojomovsky@gmail.com>
Generated-by: Copilot Signed-off-by: Alexis Pojomovsky <apojomovsky@gmail.com>
…ocessed - Default RaycastDataInfo::needsRaycast to true so that manually-created RaycastData components are processed by Physics without needing to know about the optimization flag. The CpuLidar system already explicitly manages the flag each step. - Add a topic subscriber in the RaycastResultsProcessed test so that HasConnections() returns true and the CpuLidar system requests raycasts. Generated-by: Amp <amp@ampcode.com> Signed-off-by: Alexis Pojomovsky <apojomovsky@gmail.com>
d7fa3d6 to
01235ee
Compare
Contributor
|
As mentioned in gazebosim/gz-sensors#26, here's the manually triggered CI job that builds all of your branches on gz-sensors, gz-physics and gz-sim. |
Zyrin
reviewed
Mar 23, 2026
Comment on lines
+200
to
+202
| std::function<void(const msgs::LaserScan &)> cb = | ||
| [](const msgs::LaserScan &){}; | ||
| node.Subscribe("/test/cpu_lidar", cb); |
Contributor
There was a problem hiding this comment.
Suggested change
| std::function<void(const msgs::LaserScan &)> cb = | |
| [](const msgs::LaserScan &){}; | |
| node.Subscribe("/test/cpu_lidar", cb); | |
| node.Subscribe("/test/cpu_lidar", [](const msgs::LaserScan &){}); |
To make it consistent with e.g. line 205.
And there are some more lambdas further down where this can be applied, too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎉 New feature
This PR is 3 out of 3 that implement: gazebosim/gz-sensors#26
Depends on:
Summary
Add the
CpuLidarsystem plugin that bridgesCpuLidarSensor(gz-sensors) with the physics raycasting pipeline. The end result is a close match in performance to that found on Gazebo Classic, while tested with a 128-beam × 80-ring lidar scene).CpuLidar system plugin
A new system plugin following the
Imusystem pattern (ISystemConfigure+ISystemPreUpdate+ISystemPostUpdate):SensorFactoryreference.<sensor type="lidar">entities viaEachNew<CpuLidar>, createsCpuLidarSensorinstances, callsGenerateRays()to populate theRaycastDataECM component, and sets theneedsRaycastflag when a scan is due.RaycastDataresults (populated by the Physics system), feeds them toCpuLidarSensor::SetRaycastResults(), and callssensor->Update()to trigger publishing.Performance optimization 1: Batch raycasting in Physics.cc
UpdateRayIntersections()now tries the batch API first. When available (dartsim + Bullet), all rays are submitted in a singleGetBatchRayIntersectionFromLastStep()call. The single-ray loop is retained as a fallback.Performance optimization 2: Frequency-gated raycasting
UpdateRayIntersections()was called every physics step (1 kHz default), but the sensor only needs results at its own rate (e.g. 10 Hz). AneedsRaycastflag inRaycastDataInfois set byCpuLidar::PreUpdateonly when a scan is due andthere are active subscribers. The Physics system skips entities where the flag is
false. Both the batch and fallback paths are gated.raycast()at physics rate)btWorld::rayTest()needsRaycastfrequency gatingTest it
Manual test:
gz sim examples/worlds/cpu_lidar_sensor.sdf # In another terminal: gz topic -e -t /lidar gz topic -e -t /lidar/pointsChecklist
codecheckpassed (See contributing)Generated-by: Claude Opus 4.6
Disclaimer: The code here was reviewed, tested, and profiled by hand by the author.
Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-byandGenerated-bymessages.output.mp4