ros2 / ros1_bridge

ROS 2 package that provides bidirectional communication between ROS 1 and ROS 2
Apache License 2.0
436 stars 283 forks source link

Feature Request: Allow Custom ROS1 and ROS2 Node Names #333

Closed civerachb-cpr closed 2 years ago

civerachb-cpr commented 2 years ago

Feature request

Feature description

Add additional command-line arguments to allow specifying the ROS1 and ROS2 node names

Currently the name of the ROS1 and ROS2 nodes for the dynamic_bridge are hard-coded to ros_bridge. This means it is impossible to have multiple bridges running concurrently, as the ROS1 nodes will clobber each other. This prevents the use case where you have multiple ROS2 domains and want them all bridged together onto a single ROS1 master.

Adding the ability to specify the node name (e.g ros2 run ros1_bridge dynamic_bridge --bridge-all-topics --ros1-node ros_bridge_domain_1) would alleviate this problem.

For my current use-case I only need to be able to rename the ROS1 node, but there may be additional use-cases where renaming the ROS2 node would also be desirable.

Implementation considerations

The current ros_bridge default values can be preserved if the new arguments are omitted. Modifying parse_command_options in dynamic_bridge.cpp should suffice.

It's likely desirable to add this feature to the other bridge classes (e.g. parameter_bridge).

clalancette commented 2 years ago

This is already possible using the general ros2 remapping facilities, i.e.:

ros2 run ros1_bridge dynamic_bridge --bridge-all-topics --ros-args -r __node:=/mynode
civerachb-cpr commented 2 years ago

That renames the ROS2 node, but the ROS1 node is still named "ros_bridge":

roscore is running in a third terminal in the following example, run on Ubuntu 20.04 with Foxy and Noetic installed

Terminal 1:

$ source /opt/ros/foxy/setup.bash
$ ros2 run ros1_bridge dynamic_bridge --bridge-all-topics --ros-args -r __node:=mynode &
$ ros2 node list
/mynode

Terminal 2:

$ source /opt/ros/noetic/setup.bash
$ rosnode list
/ros_bridge
/rosout

The issue is that the ROS1 node always has the same name. As soon as I start a second bridge, the first one gets killed because it has the same name as an existing node.

clalancette commented 2 years ago

Ah, I see, I misunderstood. Thanks for clarifying, I'll reopen.

civerachb-cpr commented 2 years ago

No worries. Hopefully the issue is clear enough now. (I'm new to ROS2 and wasn't aware of the remapping. Thanks for that tip!)

I've made a hacky work-around to add the feature as I initially described here: https://github.com/civerachb-cpr/ros1_bridge

The implementation isn't pretty, but it's functional for my immediate use-case of being able to launch bridges to 3 separate ROS2 domains to get all of those topics available in ROS1.

It would be great if the ability to set the name of the ROS1 node was eventually rolled into main repo.

clalancette commented 2 years ago

I took another quick look at this, and there is a way to make this partially work.

You should be able to do something like this:

ros2 run ros1_bridge dynamic_bridge --bridge-all-topics __name:=blah --ros-args -r __node:=blah

That is, the __name remaps the ROS 1 node name, and the --ros-args -r __node:=blah remaps the ROS 2 node name.

Unfortunately, due to a bug in here, those names have to match exactly; if they don't, things will fail to start up. So there is still a bug, but the above may be enough to unblock your current use cases.

civerachb-cpr commented 2 years ago

I'm not too worried about needing to have the names match. I'll give this a shot and let you know if it unblocks my current efforts. Thanks!

clalancette commented 2 years ago

The original request here, to be able to remap the ROS 1 and ROS 2 names, seems to have been taken care of by https://github.com/ros2/ros1_bridge/issues/333#issuecomment-951001532 . There is still an issue that has to do with renaming the ROS 1 and ROS 2 nodes differently, but that is not specific to this repository and doesn't seem to be a problem for the original reporter. Given that, I'm actually going to close this out. But feel free to reopen or keep commenting if you'd like to continue the conversation.