gazebosim / ros_gz

Integration between ROS (1 and 2) and Gazebo simulation
https://gazebosim.org
Apache License 2.0
233 stars 135 forks source link

Add custom GZ -> ROS mapping (Humble/Garden) #536

Open AntonioViscomi opened 5 months ago

AntonioViscomi commented 5 months ago

Hi all, I need to use Gazebo Garden alongside ROS 2 Humble . I want to use the ros_gz_bridge to obtain measurements from virtual sensors on my robot and process them in ROS.
In my ros_gz version (this one ) there is no mapping between gz.msgs.NavSat and gps_msgs/msg/GPSFix.
I need this mapping because I want to transport also the ENU velocity in ROS, which is not possible using sensor_msgs/msg/NavSatFix

Desired behavior

A map betweem gz.msgs.NavSat and gps_msgs/msg/GPSFix in ros_gz_bridge (ros-humble-ros-gzgarden).

Alternatives considered

I've cloned the "humble" branch (which should correspond to my installed version of ros_gz_bridge) and:

  1. I've included gps_msgs.hpp in ros_gz/ ros_gz_bridge/include/ros_gz_bridge/convert

  2. Added #include <ros_gz_bridge/convert/gps_msgs.hpp> to convert.hpp

  3. Added gps_msgs.cpp in ros_gz/ros_gz_bridge/src/convert

  4. Added inside ros_gz/ros_gz_bridge/mappings.py:

    'gps_msgs': [
        Mapping('GPSFix', 'NavSat'),
    ], 
  5. Added gps_msgs in package.xml

I am unsure if this will work because I've installed gps_msgs as a custom interface inside my custom interfaces package and I also need to ffigure out how to install this "new package" I've created. Am I missing anything?

Additional context:

OS: Ubuntu 22.04.

ahcorde commented 5 months ago

I created backports for Iron and Humble

AntonioViscomi commented 5 months ago

Thanks a lot. I've been able to solve this issue by myself, sharing the solution could be useful?

yschulz commented 5 months ago

I would be more than happy to open another issue for this, but I think this fits here and since this issue is still open:

I am actually very interested in custom message mappings. With the ease of protobuf message generation, both in ros and in gazebo, it feels necessary that I should be able to generate my own custom mappings by configuration instead of programmatically. Even programmatically it seems necessary to fork this repo and inject the mappings directly like @AntonioViscomi has suggested in his first comment. Is there any intent of adding a plugin like api or cmake generations or a cli tool to make this process easier?

azeey commented 5 months ago

Is there any intent of adding a plugin like api or cmake generations or a cli tool to make this process easier?

Yes, we would like to add this at some point, but I don't think there's an actual issue for it. I know for sure we've had discussions about it. The code was adapted from https://github.com/ros2/ros1_bridge/ which I've been told has a way to add custom messages, but I haven't tried it myself. If anyone would be willing to figure out how it's done for ros1_bridge and adapt it to ros_gz_bridge, it would be fantastic!

yschulz commented 5 months ago

Thanks for the quick reply and the link, I can see the resemblance.

I would gladly take a look into it and see how this can be integrated here in the gz bridge. When I have a better overview I'd open a new issue!