Skip to content
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

Merged
merged 12 commits into from
Aug 21, 2018
Merged

[ros2] Add gazebo_ros_ray_sensor #785

merged 12 commits into from
Aug 21, 2018

Conversation

kev-the-dev
Copy link
Collaborator

@kev-the-dev kev-the-dev commented Jul 31, 2018

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.

raysensor

Copy link
Contributor

@chapulina chapulina left a 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_ros_force
gazebo_ros_template
gazebo_ros_ray_sensor
Copy link
Contributor

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>
Copy link
Contributor

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

Copy link
Contributor

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:
Copy link
Contributor

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed

Copy link
Contributor

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">
Copy link
Contributor

Choose a reason for hiding this comment

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

sensor

Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can remove _ prefix

Copy link
Contributor

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;
Copy link
Contributor

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

Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Collaborator Author

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

Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Contributor

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);
Copy link
Contributor

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()?

Copy link
Collaborator Author

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);
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's been documented

@kev-the-dev
Copy link
Collaborator Author

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

@kev-the-dev kev-the-dev changed the base branch from ros2 to ros2-utils August 1, 2018 21:43
@kev-the-dev kev-the-dev changed the base branch from ros2-utils to ros2 August 6, 2018 23:49

void GazeboRosRaySensorPrivate::PublishRange(ConstLaserScanStampedPtr & _msg)
{
// Convert Laser scan to PointCloud2
Copy link
Contributor

Choose a reason for hiding this comment

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

PointCloud2 -> Range

Copy link
Contributor

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_;
Copy link
Contributor

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?

Copy link
Collaborator Author

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

@chapulina
Copy link
Contributor

@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.

@kev-the-dev kev-the-dev force-pushed the ros2-ray-sensor branch 3 times, most recently from 9ffcf8f to 4916e3f Compare August 10, 2018 20:23
@kev-the-dev
Copy link
Collaborator Author

Added the test world and expanded the test to verify the correctness of the message content's using gazebo's ground truth

@mikaelarguedas
Copy link

@ros-pull-request-builder retest this please

@dhood dhood added the ros2 label Aug 17, 2018
@chapulina
Copy link
Contributor

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:

  • I couldn't get the LaserScan messages to show on RViz for either ray or gpu_ray sensors. The Status is ok, messages are received, but it always says "Showing [0] points from [0] messages". We could be forgetting to publish some field? Or maybe it's RViz's fault? I see stuff when echoing the messages.

  • When I have only one vertical ray, the point cloud's position looks wrong. See how the 1-vertical-ray gpu_ray is way below the output for the 300-vertical-rays ray sensor:

gpu_ray_1vert_pc

This happens even if I put one vertical ray for the ray sensor, note how the intensities are properly colored but the result is also under the ground:

ray_1vert_pc

chapulina
chapulina previously approved these changes Aug 21, 2018
@chapulina chapulina dismissed their stale review August 21, 2018 17:01

approved by mistake

@chapulina
Copy link
Contributor

The issue with the LaserScan not being visible on RViz seems to be due to ros2/rviz#332

@chapulina
Copy link
Contributor

The issue with 1 vertical ray was happening if there was a <vertical> tag with 1 sample, but not if there was no <vertical> tag. So I changed the example world and also added a warning.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants