快三下期怎么推算:ROS2入门示例-ROS1与ROS2通讯

青海快三下载 www.41pi3.cn ROS2入门教程-ROS1与ROS2通讯

说明:

  • 介绍ros1_bridge包的使用

概要

  • ros1_bridge包提供了一个网络桥接器,以便ROS1和ROS2之间能够交换消息

  • 该包目前是通过C++来实现的,故仅支持限于桥的编译时可用的消息/服务类型

  • 提供预编译ros2二进制文件的桥支持常用的ros接口(消息/服务),如 ros2/common_interfaces repositorytf2_msgs 列出的接口包

  • 更多关于ros1和ros2接口相关联的信息,请参阅:https://github.com/ros2/ros1_bridge/blob/master/doc/index.rst

  • 若要使用其他接口的桥(如自定义的类型),需要在源代码上构建

  • Note: For binary releases up to and including release-alpha8, some of the interfaces in common_interfaces are skipped - check the git tag of the release in question to see which interfaces were built.

前提准备

  • 需要预先安装好ros2和ros1以及ros1_bridge包

  • 需要用到的ros1包:

    • catkin

    • roscpp

    • roslaunch (for roscore executable)

    • rosmsg

    • std_msgs

    • as well as the Python package rospkg

  • 若要运行以下例子,仍需这些ros1包:

    • rosbash (for rosrun executable)

    • roscpp_tutorials

    • rospy_tutorials

    • rostopic

    • rqt_image_view

用源代码构建ros1_bridge

  • 注意事项:

    • 开始前请确认ros_commrosbag是否是1.11.16以上的版本

    • 请完成前面ros2和ros1的安装再进行ros1_bridge的安装

    • Here are the steps (for Linux and OSX; you probably don't have ROS 1 installed on Windows).
      You should first build everything but the ROS 1 bridge with normal make arguments. We don't recommend having your ROS 1 environment sourced during this step as it can add OpenCV 3 to your path. The ROS 2 image demos you build in this step would then use OpenCV 3 and require it to be on your path when you run them, while the standard installation on Ubuntu Xenial is OpenCV 2.

      colcon build --symlink-install --packages-skip ros1_bridge

  • source一下环境

source /opt/ros/melodic/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 package.xml of the bridge, so that colcon will add them to the path before it builds the bridge. Alternatively you can do it manually by sourcing the relevant workspaces yourself, e.g.:
# You have already sourced your ROS installation.
# Source your ROS 2 installation:
. <install-space-with-ros2>/local_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

注意:编译时需占用大量内存,但若机器内存不足,可以尝试设置环境变量MAKEFLAGS=-j1来限制并行作业的数量。

示例1:run the bridge and the example talker and listener

  • talker和listener可以是ROS1或ROS2节点。桥将透明地传递消息。

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.

  • 示例1.1 ROS 1 talker and ROS 2 listener

  • 首先运行ros1的roscore

# Shell A:
. /opt/ros/melodic/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
roscore
  • 然后运行dynamic bridge,该程序将定期开始输出ROS 1和ROS 2中当前可用的主题
d# Shell B:
. /opt/ros/melodic/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
. <install-space-with-bridge>/setup.bash
export ROS_MASTER_URI=//localhost:11311
ros2 run ros1_bridge dynamic_bridge
  • 接着运行ROS 1 talker,可以看到该节点发布的消息会显示在终端上
# Shell C:
. /opt/ros/melodic/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
rosrun rospy_tutorials talker
  • 运行ROS 2 listener,同样可以看到该节点发布的消息会显示在终端上
# Shell D:
. <install-space-with-ros2>/setup.bash - 
ros2 run demo_nodes_cpp listener
  • 在shell B上会看到一段关于该topic的桥已创建的说明:
created 1to2 bridge for topic '/chatter' with ROS 1 type 'std_msgs/String' and ROS 2 type 'std_msgs/String'
  • 当中止程序后,可以看到shell B出现关于桥已被移除的说明:
removed 1to2 bridge for topic '/chatter'

Note: When the bridge is run using the default ROS 2 middleware implementation, which uses Fast RTPS, it does not always remove bridges instantly. See https://github.com/ros2/ros1_bridge/issues/38.

  • 示例运行截图如下:

![请输入图片描述]:4

  • 示例1.2:ROS 2 talker and ROS 1 listener

  • 第一步:

# Shell A:
. /opt/ros/melodic/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
roscore
  • 第二步:
# Shell B:
. /opt/ros/melodic/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
. <install-space-with-bridge>/setup.bash
export ROS_MASTER_URI=//localhost:11311
ros2 run ros1_bridge dynamic_bridge
  • 第三步:
# Shell C:
. <install-space-with-ros2>/setup.bash
ros2 run demo_nodes_py talker
  • 最后:
 # Shell D:
. /opt/ros/melodic/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
rosrun roscpp_tutorials listener

示例2:run the bridge and exchange images

  • 该例子将演示桥能够传递更大更复杂的消息。ROS2节点正在发布从相机拍到的图像,在ROS1节点中使用rqt_image_view在GUI中渲染图像。ROS1发布者可以发送消息来切换ROS2节点中的选项。

  • 第一步:

# Shell A:
. /opt/ros/melodic/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
roscore

# Shell B:
. /opt/ros/melodic/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
. <workspace-with-bridge>/install/setup.bash
export ROS_MASTER_URI=//localhost:11311
ros2 run ros1_bridge dynamic_bridge
  • 第二步:
# Shell C:
. /opt/ros/melodic/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
rqt_image_view /image
  • 第三步:
# Shell D:
. <workspace-with-ros2>/install/setup.bash
ros2 run image_tools cam2image
  • 通过ros1节点向ros2节点发布。通过向flip_image topic发布truefalse,相机节点将在发送之前翻转图像??梢允褂?code>rqt中的Message Publisher插件在主题flip_image上发布std_msgs/Bool消息,也可以运行以下两个rostopic命令之一:
# Shell E:
. /opt/ros/melodic/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}"
  • 例子运行截图:

请输入图片描述

示例3:run the bridge for AddTwoInts service

  • 该示例桥接了ros/roscpp_tutorials的TwoInts服务和ros2/roscpp_examples的AddTwoInts

  • 在构建时,ros1_bridge会查找所有已安装的ROS和ROS2服务。通过比较请求和响应中的包名称,服务名称和字段来匹配找到的服务。如果ROS和ROS2服务中的所有名称相同,则将创建桥。也可以通过创建包含相应服务名称的yaml文件来手动配对服务。若想了解更多信息请参阅:https://github.com/ros2/ros1_bridge/blob/master/doc/index.rst

  • 运该示例时,请确保已安装roscpp_tutorials软件包,并在构建ros1_bridge时正确设置了环境

  • 运行ROS master

# Shell A:
. <ros-install-dir>/setup.bash
roscore -p 11311
  • 运行dynamic_bridge
# Shell B:
. <ros-install-dir>/setup.bash
. <ros2-install-dir>/setup.bash
export ROS_MASTER_URI=//localhost:11311
ros2 run ros1_bridge dynamic_bridge
  • 运行TwoInts server
# Shell C:
. <ros-install-dir>/setup.bash
export ROS_MASTER_URI=//localhost:11311
rosrun roscpp_tutorials add_two_ints_server
  • 运行 AddTwoInts client
# Shell D:
. <ros2-install-dir>/setup.bash
ros2 run demo_nodes_cpp add_two_ints_client

参考链接:

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: ros2入门示例

  • 北新建材荣登“中国500最具价值品牌”100强 2018-11-24
  • 杨梅:谣言太多伤不起 2018-11-24
  • 13岁少年杀3幼童被收容教养 下调入刑年龄可控犯罪 2018-09-04
  • 银保监会:6月22日前上报保险消费风险提示落实情况 2018-07-25
  • 刘杰的专栏作者中国国家地理网 2018-07-25
  • 漫游宝澄清“无证”传闻 2018-07-24
  • 罗青林的专栏作者中国国家地理网 2018-07-24
  • 2018世界杯 竞彩游戏的投注方式 2018-07-23
  • 足球,从工人阶级平民运动到资本主义商业游戏 2018-07-23
  • 奚梦瑶穿牛仔套装帅气十足 双手接护照礼仪满分 2018-07-22
  • 看了看某同事放长线的账户,居然赔掉了三分之二的本金[可怜] 2018-07-22
  • 克罗地亚VS尼日利亚前瞻:克罗地亚或是最大黑马 2018-07-21
  • 崔世安:澳门须主动融入和参与粤港澳大湾区建设 2018-07-20
  • 《亲爱的活祖宗》甜蜜开播 原声带上线亲爱的活祖宗 原声带 2018-07-20
  • 年底北斗系统将为“一带一路”建设参与国提供服务 2018-07-19
  • 702| 835| 194| 377| 1000| 799| 207| 354| 952| 583|