-
Notifications
You must be signed in to change notification settings - Fork 43
Made it possible to initialize LiDARSensor later so that it works with the built app. #197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Made it possible to initialize LiDARSensor later so that it works with the built app. #197
Conversation
…works with the built app.
…into feature/for-simulator-app
…so that it works with the built app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the initialization logic for the LiDAR sensor components so that sensors can be initialized later in the built app without triggering exceptions.
- LiDARPointCloud2MsgPublisher now checks for a null source and logs an error before aborting initialization.
- RaycastLiDARSensor and DepthBufferLiDARSensor have been modified to check for a null scanPattern before executing initialization, delegating further logic to an overridden Initialize method.
- LiDARSensor now provides a virtual Initialize method that clamps sensor parameters and configures point cloud data only when the scanPattern is available.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
Assets/UnitySensorsROS/Runtime/Scripts/Publishers/SensorMsgs/PointCloud2Msg/LiDARPointCloud2MsgPublisher.cs | Added null check for _source to prevent a NullReferenceException. |
Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/RaycastLiDAR/RaycastLiDARSensor.cs | Switched to a deferred initialization pattern by checking scanPattern and overriding Initialize. |
Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/LiDARSensor.cs | Modified Init to delay initialization when _scanPattern is not available and introduced Initialize. |
Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/DepthBufferLiDAR/DepthBufferLiDARSensor.cs | Applied a similar deferred initialization approach as with RaycastLiDARSensor. |
...sorsROS/Runtime/Scripts/Publishers/SensorMsgs/PointCloud2Msg/LiDARPointCloud2MsgPublisher.cs
Outdated
Show resolved
Hide resolved
Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/RaycastLiDAR/RaycastLiDARSensor.cs
Show resolved
Hide resolved
Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/DepthBufferLiDAR/DepthBufferLiDARSensor.cs
Show resolved
Hide resolved
…ointCloud2Msg/LiDARPointCloud2MsgPublisher.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…iDAR/DepthBufferLiDARSensor.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…/RaycastLiDARSensor.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I will merge it.
Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/DepthBufferLiDAR/DepthBufferLiDARSensor.cs
Show resolved
Hide resolved
71ad0ff
into
Field-Robotics-Japan:master
In the previous version, the simulation was executed after the LiDARSensor settings were completed in the editor, and the Init function was called. However, in the built app, the Init function was called before the settings were made, resulting in a NullReferenceException. To ensure that the app works in the built version as well, I modified the code so that if an element is null, it is not initialized immediately but can be initialized later.