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 ROS namespaces to GZ topics #512

Closed Kotochleb closed 6 months ago

Kotochleb commented 6 months ago

🎉 New feature

Summary

This PR adds the ability to apply ROS node namespace onto GZ topics. This adds option for global namespaces, private namespaces and should also work for substitutions.

I believe this feature later could be easily ported to Iron and Rolling.

As it is an API breaking feature, I also introduced a new ROS parameter, preserving backward compatibility.

Test it

In the config_file YAML file, create topics as:

- topic_name: "chatter"
  ros_type_name: "std_msgs/msg/String"
  gz_type_name: "gz.msgs.StringMsg"
  direction: ROS_TO_GZ

- topic_name: "/chatter_global"
  ros_type_name: "std_msgs/msg/String"
  gz_type_name: "gz.msgs.StringMsg"
  direction: ROS_TO_GZ

- topic_name: "~/chatter_private_ns"
  ros_type_name: "std_msgs/msg/String"
  gz_type_name: "gz.msgs.StringMsg"
  direction: ROS_TO_GZ

- ros_topic_name: "chatter_ros_ns"
  gz_topic_name: "/chatter_ign_global"
  ros_type_name: "std_msgs/msg/String"
  gz_type_name: "gz.msgs.StringMsg"
  direction: ROS_TO_GZ

This should create ROS topics:

$ ros2 topic list
/my_namespace/chatter
/chatter_global
/my_namespace/ros_gz_bridge/chatter_private_ns
/my_namespace/chatter_ros_ns

And GZ topics:

$ ign topic --list
/my_namespace/chatter
/chatter_global
/my_namespace/ros_gz_bridge/chatter_private_ns
/chatter_ign_global
Kotochleb commented 6 months ago

@ahcorde I applied your suggestions and signed the commits

azeey commented 6 months ago

hmm, not sure why this is trying to run Rpr__ros_gz__ubuntu_noble_amd64 . It should be testing with Humble on Jammy.

Kotochleb commented 6 months ago

@azeey do you think I should just wait for the CI to be solved on your side? It doesn't seem to be broken by my changes

azeey commented 6 months ago

@azeey do you think I should just wait for the CI to be solved on your side? It doesn't seem to be broken by my changes

Yes, this is unrelated to your PR. Hopefully, we'll have a fix soon.

Kotochleb commented 6 months ago

@ahcorde I added new section about the remapping to the README.md. I also sort of allowed myself to change source commands to have humble instead of galactic, as this is humble branch. Since it is a very minor change and I am already making changes in the README, I thought it will be fine to push it with this PR.

ahcorde commented 6 months ago

@Kotochleb thank you for your contribution, do you have some time to do the forward port in iron and rolling?

Kotochleb commented 6 months ago

@ahcorde you are welcome. I would have time, but it will take me a few more days, as this feature for Humble was something I needed right now. Hopefully I will submit the PRs till end of this week.

ahcorde commented 6 months ago

backports