在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):ros2/ros1_bridge开源软件地址(OpenSource Url):https://github.com/ros2/ros1_bridge开源编程语言(OpenSource Language):C++ 55.1%开源软件介绍(OpenSource Introduction):Bridge communication between ROS 1 and ROS 2This package provides a network bridge which enables the exchange of messages between ROS 1 and ROS 2. The bridge is currently implemented in C++ as at the time the Python API for ROS 2 had not been developed.
Because of this its support is limited to only the message/service types available at compile time of the bridge.
The bridge provided with the prebuilt ROS 2 binaries includes support for common ROS interfaces (messages/services), such as the interface packages listed in the ros2/common_interfaces repository and For efficiency reasons, topics will only be bridged when matching publisher-subscriber pairs are active for a topic on either side of the bridge.
As a result using PrerequisitesIn order to run the bridge you need to either:
After that you can run both examples described below. For all examples you need to source the environment of the install space where the bridge was built or unpacked to.
Additionally you will need to either source the ROS 1 environment or at least set the The following ROS 1 packages are required to build and use the bridge:
To run the following examples you will also need these ROS 1 packages:
Prerequisites for the examples in this fileIn order to make the examples below portable between versions of ROS, we define two environment variables, If you installed Noetic in the default location, then the definition of Building the bridge as described below requires you to build all of ROS 2.
We assume that you have downloaded it to If you've chosen to install either or both versions of ROS somewhere else, you will need adjust the definitions below to match your installation paths. Because these definitions are used continuously throughout this page, it is useful to add the following lines to your shell startup file ( export ROS1_INSTALL_PATH=/opt/ros/noetic
export ROS2_INSTALL_PATH=~/ros2_rolling/install Note that no trailing '/' character is used in either definition. If you have problems involving paths, please verify that you have the correct path to the installation location, and that you do not have a trailing '/' in either definition. Building the bridge from sourceBefore continuing you should have the prerequisites for building ROS 2 from source installed following these instructions. In the past, building this package required patches to ROS 1, but in the latest releases that is no longer the case.
If you run into trouble first make sure you have at least version The bridge uses Here are the steps for Linux and OSX. You should first build everything but the ROS 1 bridge with normal colcon arguments. We don't recommend having your ROS 1 environment sourced during this step as it can add other libraries to the path. colcon build --symlink-install --packages-skip ros1_bridge Next you need to source the ROS 1 environment.
If you set the source ${ROS1_INSTALL_PATH}/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash The bridge will be built with support for any message/service packages that are on your path and have an associated mapping between ROS 1 and ROS 2.
Therefore you must add any ROS 1 or ROS 2 workspaces that have message/service packages that you want to be bridged to your path before building the bridge.
This can be done by adding explicit dependencies on the message/service packages to the # You have already sourced your ROS installation.
# Source your ROS 2 installation:
source ${ROS2_INSTALL_PATH}/setup.bash
# And if you have a ROS 1 overlay workspace, something like:
# . <install-space-to-ros1-overlay-ws>/setup.bash
# And if you have a ROS 2 overlay workspace, something like:
# . <install-space-to-ros2-overlay-ws>/local_setup.bash Then build just the ROS 1 bridge: colcon build --symlink-install --packages-select ros1_bridge --cmake-force-configure Note: If you are building on a memory constrained system you might want to limit the number of parallel jobs by setting e.g. the environment variable Example 1: run the bridge and the example talker and listenerThe talker and listener can be either a ROS 1 or a ROS 2 node. The bridge will pass the message along transparently. Note: When you are running these demos make sure to only source the indicated workspaces. You will get errors from most tools if they have both workspaces in their environment. Example 1a: ROS 1 talker and ROS 2 listenerFirst we start a ROS 1 # Shell A (ROS 1 only):
source ${ROS1_INSTALL_PATH}/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
roscore Then we start the dynamic bridge which will watch the available ROS 1 and ROS 2 topics. Once a matching topic has been detected it starts to bridge the messages on this topic. # Shell B (ROS 1 + ROS 2):
# Source ROS 1 first:
source ${ROS1_INSTALL_PATH}/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
# Source ROS 2 next:
source ${ROS2_INSTALL_PATH}/setup.bash
# For example:
# . /opt/ros/dashing/setup.bash
export ROS_MASTER_URI=http://localhost:11311
ros2 run ros1_bridge dynamic_bridge The program will start outputting the currently available topics in ROS 1 and ROS 2 in a regular interval. Now we start the ROS 1 talker. # Shell C:
source ${ROS1_INSTALL_PATH}/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
rosrun rospy_tutorials talker The ROS 1 node will start printing the published messages to the console. Now we start the ROS 2 listener from the # Shell D:
source ${ROS2_INSTALL_PATH}/setup.bash
ros2 run demo_nodes_cpp listener The ROS 2 node will start printing the received messages to the console. When looking at the output in shell B there will be a line stating that the bridge for this topic has been created: created 1to2 bridge for topic '/chatter' with ROS 1 type 'std_msgs/String' and ROS 2 type 'std_msgs/String' At the end stop all programs with removed 1to2 bridge for topic '/chatter' The screenshot shows all the shell windows and their expected content: Example 1b: ROS 2 talker and ROS 1 listenerThe steps are very similar to the previous example and therefore only the commands are described. # Shell A:
source ${ROS1_INSTALL_PATH}/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
roscore # Shell B:
source ${ROS1_INSTALL_PATH}/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
source ${ROS2_INSTALL_PATH}/setup.bash
export ROS_MASTER_URI=http://localhost:11311
ros2 run ros1_bridge dynamic_bridge Now we start the ROS 2 talker from the # Shell C:
source ${ROS2_INSTALL_PATH}/setup.bash
ros2 run demo_nodes_py talker Now we start the ROS 1 listener. # Shell D:
source ${ROS1_INSTALL_PATH}/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
rosrun roscpp_tutorials listener Example 2: run the bridge and exchange imagesThe second example will demonstrate the bridge passing along bigger and more complicated messages.
A ROS 2 node is publishing images retrieved from a camera and on the ROS 1 side we use First we start a ROS 1 # Shell A:
source ${ROS1_INSTALL_PATH}/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
roscore # Shell B:
source ${ROS1_INSTALL_PATH}/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
source ${ROS2_INSTALL_PATH}/install/setup.bash
export ROS_MASTER_URI=http://localhost:11311
ros2 run ros1_bridge dynamic_bridge Now we start the ROS 1 GUI: # Shell C:
source ${ROS1_INSTALL_PATH}/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
rqt_image_view /image Now we start the ROS 2 image publisher from the # Shell D:
source ${ROS2_INSTALL_PATH}/install/setup.bash
ros2 run image_tools cam2image You should see the current images in To exercise the bridge in the opposite direction at the same time you can publish a message to the ROS 2 node from ROS 1.
By publishing either # Shell E:
source ${ROS1_INSTALL_PATH}/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
rostopic pub -r 1 /flip_image std_msgs/Bool "{data: true}"
rostopic pub -r 1 /flip_image std_msgs/Bool "{data: false}" The screenshot shows all the shell windows and their expected content (it was taken when Indigo was supported - you should use Melodic): Example 3: run the bridge for AddTwoInts serviceIn this example we will bridge a service TwoInts from ros/roscpp_tutorials and AddTwoInts from ros2/roscpp_examples. While building, ros1_bridge looks for all installed ROS and ROS2 services. Found services are matched by comparing package name, service name and fields in a request and a response. If all names are the same in ROS and ROS2 service, the bridge will be created. It is also possible to pair services manually by creating a yaml file that will include names of corresponding services. You can find more information here. So to make this example work, please make sure that the roscpp_tutorials package is installed on your system and the environment is set up correctly while you build ros1_bridge. Launch ROS master # Shell A:
source ${ROS1_INSTALL_PATH}/setup.bash
roscore -p 11311 Launch dynamic_bridge: # Shell B:
source ${ROS1_INSTALL_PATH}/setup.bash
source ${ROS2_INSTALL_PATH}/setup.bash
export ROS_MASTER_URI=http://localhost:11311
ros2 run ros1_bridge dynamic_bridge Launch TwoInts server: # Shell C:
source ${ROS1_INSTALL_PATH}/setup.bash
export ROS_MASTER_URI=http://localhost:11311
rosrun roscpp_tutorials add_two_ints_server Launch AddTwoInts client: # Shell D:
source ${ROS2_INSTALL_PATH}/setup.bash
ros2 run demo_nodes_cpp add_two_ints_client Example 4: bridge only selected topics and servicesThis 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 topics:
-
topic: /chatter # Topic name on both ROS 1 and ROS 2
type: std_msgs/msg/String # Type of topic to bridge
queue_size: 1 # Queue size
services_2_to_1:
-
service: /add_two_ints # ROS 1 service name
type: roscpp_tutorials/TwoInts # The ROS 1 service type name Start a ROS 1 roscore: # Shell A (ROS 1 only):
source ${ROS1_INSTALL_PATH}/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 Shell B: (ROS 1 only):
source ${ROS1_INSTALL_PATH}/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
rosparam load bridge.yaml
rosrun rospy_tutorials talker Shell C: (ROS 1 only):
source ${ROS1_INSTALL_PATH}/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: # Shell D:
source ${ROS2_INSTALL_PATH}/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: # Shell E:
source ${ROS2_INSTALL_PATH}/setup.bash
ros2 run demo_nodes_cpp listener This should start printing text like # Shell F:
source ${ROS2_INSTALL_PATH}/setup.bash
ros2 service call /add_two_ints example_interfaces/srv/AddTwoInts "{a: 1, b: 2}" If all is well, the output should contain Parametrizing Quality of ServiceAn advantage of ROS 2 over ROS 1 is the possibility to define different Quality of Service settings per topic.
The parameter bridge optionally allows for this as well.
For some topics, like topics:
-
topic: /tf_static
type: tf2_msgs/msg/TFMessage
queue_size: 1
qos:
history: keep_all
durability: transient_local All other QoS options (as documented here in https://docs.ros.org/en/foxy/Concepts/About-Quality-of-Service-Settings.html) are available: topics:
-
topic: /some_ros1_topic
type: std_msgs/msg/String
queue_size: 1
qos:
history: keep_last # OR keep_all, then you can omit `depth` parameter below
depth: 10 # Only required when history == keep_last
reliability: reliable # OR best_effort
durability: transient_local # OR volatile
deadline:
secs: 10
nsecs: 2345
lifespan:
secs: 20
nsecs: 3456
liveliness: liveliness_system_default # Values from https://design.ros2.org/articles/qos_deadline_liveliness_lifespan.html, eg. LIVELINESS_AUTOMATIC
liveliness_lease_duration:
secs: 40
nsecs: 5678 Note that the |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论