-
Notifications
You must be signed in to change notification settings - Fork 773
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
[ros2] Add gazebo_ros_ray_sensor #785
Conversation
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.
I've done a first high level pass over the code.
There are a few changes to the math that I'd like to take a closer look at. If we want to say with some degree of confidence that users should be able to migrate from some specific old sensor type to this new one, we will need to:
-
Write detailed migration guides explaining, for example:
- what parameters changed
- how noise can be configured to behave the same way as before
- any expected changes in sensor output, and why
-
Add some tests that show behaviour is still the same
I realize these tasks can become arbitrarily long. We need to weigh the effort of providing a robust migration path against the effort of maintaining, at least for now, 4 different plugins that do similar things but at least behave as they did in ROS 1.
Let's start a dedicated wiki page for the migration documentation: https://github.com/ros-simulation/gazebo_ros_pkgs/wiki/ROS-2-Migration:-Ray-sensors
gazebo_plugins/CMakeLists.txt
Outdated
gazebo_ros_force | ||
gazebo_ros_template | ||
gazebo_ros_ray_sensor |
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.
It would be convenient to keep these in alphabetical order
#include <sensor_msgs/msg/point_cloud2.hpp> | ||
#include <sensor_msgs/msg/range.hpp> | ||
#include <gazebo_ros/node.hpp> | ||
#include <boost/variant.hpp> |
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.
Most of these includes can be (re)moved
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.
Done in 63a3e1f
\details | ||
SDF parameters: | ||
\verbatim | ||
<outputType>: Optional. The message type of the plugin's output. Can be any of the following: |
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.
It always seemed odd to me that some of the tags were camelCase
. Both URDF and SDF use the underscore_case
convention, and gazebo_ros::Node
, as of now, is also using that.
So I think it would be nice to also convert all tags to this style. Thoughts?
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.
Agreed
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.
This has been done
|
||
Example SDF: | ||
\code{.xml} | ||
<plugin name="my_ray_senor_plugin" filename="libgazebo_ros_ray_sensor.so"> |
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.
sensor
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.
It's fixed
virtual ~GazeboRosRaySensor(); | ||
|
||
// Documentation Inherited | ||
void Load(gazebo::sensors::SensorPtr _parent, sdf::ElementPtr _sdf); |
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.
Can remove _
prefix
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.
I'm now leaning towards leaving this in, sorry for the roundabout, as far as I know, this doesn't conflict with any ROS2 styles, and it's convenient.
/// Gazebo subscribe to parent sensor's laser scan | ||
gazebo::transport::SubscriberPtr laser_scan_sub_; | ||
|
||
int rayCount; |
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.
Double-check which of these variables are actually needed and:
- remove the unused ones
- document and add
_
suffix to the used ones
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.
It's been cleanup
} | ||
} | ||
|
||
void GazeboRosRaySensorPrivate::PublishLaserScan(ConstLaserScanStampedPtr & _msg) |
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.
Do you think it makes sense to have functions like sensor_msgs::msg::LaserScan Convert(const gazebo::msgs::LaserScanStamped & msg)
which do most of the heavy-lifting and then the plugin just sets extra stuff like frame_id
?
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.
That would be a lot cleaner. I have to first make sure the gazebo message has everything needed to do the conversion, but this sounds like a good refactor
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.
It's been addressed
{ | ||
} | ||
|
||
void GazeboRosRaySensor::Load(gazebo::sensors::SensorPtr _parent, sdf::ElementPtr _sdf) |
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.
Consider renaming _parent
to sensor
, so it is clear that it isn't the parent model or link for example.
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.
Done
size_t start = (verticalRangeCount / 2) * rangeCount; | ||
|
||
// Copy ranges and intensities over | ||
ls.ranges.resize(rangeCount); |
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.
Why not use _msg->scan().ranges_size()
?
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.
I think this would be a problem if there is greater than one vertical ray as this is just a planar scan. rangeCount is the number of horizontal rays, where as _msg->scan().ranges_size() is all the rays
range_msg.header.frame_id = frame_name_; | ||
range_msg.header.stamp.sec = _msg->time().sec(); | ||
range_msg.header.stamp.nanosec = _msg->time().nsec(); | ||
range_msg.field_of_view = std::max(pDiff, yDiff); |
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.
On gazebo_ros_range
the FOV is set from the SDF but now it comes from the sensor itself. If the <fov>
param wasn't useful, let's document it.
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.
It's been documented
Migration notes with examples added to the wiki. I'm going to recommit the conversion/utility functions in a separate PR than come back to address the specific issues for gazebo_ros_ray_sensor |
01c70f9
to
0cd7cad
Compare
0cd7cad
to
ff2bc88
Compare
ff2bc88
to
b77a942
Compare
|
||
void GazeboRosRaySensorPrivate::PublishRange(ConstLaserScanStampedPtr & _msg) | ||
{ | ||
// Convert Laser scan to PointCloud2 |
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.
PointCloud2
-> Range
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.
it's fixed
/// ROS node used to verify output of plugin | ||
static rclcpp::Node::SharedPtr node_; | ||
/// ROS executor to call node_'s callbacks | ||
static rclcpp::executor::Executor::SharedPtr executor_; |
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.
Just curious, why are you making these static?
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.
Rewrote test to actually verify correctness of output using gazebo's ground truth in
3f117fe
@ironmig , could you also add a demo world besides the test world? On the world, add comments explaining how to launch RViz to visualize the various sensors. |
9ffcf8f
to
4916e3f
Compare
Added the test world and expanded the test to verify the correctness of the message content's using gazebo's ground truth |
@ros-pull-request-builder retest this please |
63a3e1f
to
c39e1c1
Compare
Thanks for the demo world, @ironmig! I added a few more examples to it on 9c74f9c and I noticed some possible problems which I need to investigate further:
This happens even if I put one vertical ray for the |
The issue with the |
The issue with 1 vertical ray was happening if there was a I think this is good to go if the CI comes clean. I'll add a note to the migration page about #778 (comment) by @dhood. |
Add gazebo_ros_ray_sensor, a plugin to replace gazebo_ros_laser, gazebo_ros_gpu_laser, gazebo_ros_block_laser, and gazebo_ros_range. It attaches to a ray or gpu_ray sensor and publishes an output message in ROS based with the type configured via an sdf parameter.
The test is currently non-exhaustive and only checks the content of the range type, ensuring that that all types just publish messages. I will be adding more extensive tests.