diff --git a/README.md b/README.md index f52db7b0..112df87f 100644 --- a/README.md +++ b/README.md @@ -346,3 +346,76 @@ Launch AddTwoInts client: . /setup.bash ros2 run demo_nodes_cpp add_two_ints_client ``` + +## Example 4: bridge only selected topics and services +This example expands on example 3 by selecting a subset of topics and services to be bridged. +This is handy when, for example, you have a system that runs most of it's stuff in either ROS 1 or ROS 2 but needs a few nodes from the 'opposite' version of ROS. +Where the `dynamic_bridge` bridges all topics and service, the `parameter_bridge` uses the ROS 1 parameter server to choose which topics and services are bridged. +For example, to bridge only eg. the `/chatter` topic and the `/add_two_ints service` from ROS1 to ROS2, create this configuration file, `bridge.yaml`: + +```yaml +topics: + - + topic: /chatter # ROS1 topic name + type: std_msgs/msg/String # ROS2 type name + queue_size: 1 # For the publisher back to ROS1 +services_1_to_2: + - + service: /add_two_ints # ROS1 service name + type: example_interfaces/srv/AddTwoInts # The ROS2 type name +``` + +Start a ROS 1 roscore: + +```bash +# Shell A (ROS 1 only): +. /opt/ros/melodic/setup.bash +# Or, on OSX, something like: +# . ~/ros_catkin_ws/install_isolated/setup.bash +roscore +``` + +Then load the bridge.yaml config file and start the talker to publish on the `/chatter` topic: + +```bash +Shell B: (ROS1 only): +. /opt/ros/melodic/setup.bash +# Or, on OSX, something like: +# . ~/ros_catkin_ws/install_isolated/setup.bash +rosparam load bridge.yaml + +rosrun rospy_tutorials talker +``` + +```bash +Shell C: (ROS1 only): +. /opt/ros/melodic/setup.bash +# Or, on OSX, something like: +# . ~/ros_catkin_ws/install_isolated/setup.bash + +rosrun roscpp_tutorials add_two_ints_server +``` + +Then, in a few ROS 2 terminals: + +```bash +# Shell D: +. /setup.bash +ros2 run ros1_bridge parameter_bridge +``` + +If all is well, the logging shows it is creating bridges for the topic and service and you should be able to call the service and listen to the ROS 1 talker from ROS 2: + +```bash +# Shell E: +. /setup.bash +ros2 run demo_nodes_cpp listener +``` +This should start printing text like `I heard: [hello world ...]` with a timestamp. + +```bash +# Shell F: +. /setup.bash +ros2 service call /add_two_ints example_interfaces/srv/AddTwoInts "{a: 1, b: 2}" +``` +If all is well, the output should contain `example_interfaces.srv.AddTwoInts_Response(sum=3)`