• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

[ros2学习]-CLI Tools – 了解ROS 2主题(topics)

人工智能 越来越胖了_mengleijin 2469次浏览 0个评论

文章目录

 

    • ① 背景
    • ② 前提
    • ③ 任务
      • Ⅰ 准备
      • Ⅱ rqt_graph
      • Ⅲ ros2 topic 命令
        • ros2 topic list
        • ros2 topic echo
        • ros2 topic info
        • ros2 msg show (eloquent版本 ros2 interface show)
          • dashing 版本
          • eloquent 版本
          • 两个版本都可以
        • ros2 topic pub
        • ros2 topic hz
    • ④ 总结

 

① 背景

  ROS 2将复杂的系统分解为许多模块化 节点(node)。 主题(topic)是ROS图的重要元素,它充当节点(node)交换消息的总线。 节点(node)可以将数据发布到任意数量的主题(topic),并同时具有对任意数量的主题(topic)的订阅。 主题(topic)是数据在节点(node)之间以及因此在系统的不同部分之间移动的重要方式之一。 说面了就是通过topic来通讯,通过node 来发现互相  

② 前提

 

  • 装ros2
  • 配置环境
  • 装小乌龟

 

③ 任务

 

Ⅰ 准备

  启动小乌龟 命令:  

ros2 run turtlesim turtlesim_node
ros2 run turtlesim turtle_teleop_key

 

Ⅱ rqt_graph

  这个是个可是化的工具,命令:  

rqt_graph

  不像ros1 还要rosrun  
[ros2学习]-CLI Tools - 了解ROS 2主题(topics)   这个是个自检工具  

Ⅲ ros2 topic 命令

 

ros2 topic list

  ros2 topic list 列出所有topic ros2 topic list -t列出topic 顺便带上了消息类型,这个好 下面是帮助文档,  

usage: ros2 topic list [-h] [--spin-time SPIN_TIME] [-t] [-c]
                       [--include-hidden-topics]

Output a list of available topics

optional arguments:
  -h, --help            show this help message and exit
  --spin-time SPIN_TIME
                        Spin time in seconds to wait for discovery (only
                        applies when not using an already running daemon)
  -t, --show-types      Additionally show the topic type
  -c, --count-topics    Only display the number of topics discovered
  --include-hidden-topics
                        Consider hidden topics as well

 
[ros2学习]-CLI Tools - 了解ROS 2主题(topics)   发现两个隐藏的,rqt_graph 去掉hide的勾选也能看到  
[ros2学习]-CLI Tools - 了解ROS 2主题(topics)  

ros2 topic echo

  可以查看对应topic上 publish 的数据 命令:  

ros2 topic echo <topic_name>

  小乌龟的例子:  

ros2 topic echo /turtle1/cmd_vel

  这样会直观点  
[ros2学习]-CLI Tools - 了解ROS 2主题(topics)  

ros2 topic info

  看topic的详细信息,命令:ros2 topic info /turtle1/cmd_vel  
[ros2学习]-CLI Tools - 了解ROS 2主题(topics)  

ros2 msg show (eloquent版本 ros2 interface show)

  用 ros2 topic list -t看到了cmd_vel 的消息类型 是 geometry_msgs/msg/Twist这个  

dashing 版本

 

  • 我们可以用 ros2 msg show geometry_msgs/msg/Twist

 
[ros2学习]-CLI Tools - 了解ROS 2主题(topics)  

eloquent 版本

 

  • 我们可以用 ros2 interface show geometry_msgs/msg/Twist.msg

 
[ros2学习]-CLI Tools - 了解ROS 2主题(topics)  

两个版本都可以

 

  • 也可以通过 ros2 topic echo /turtle1/cmd_vel 来看

 
[ros2学习]-CLI Tools - 了解ROS 2主题(topics)   可以通过rqt来看  
[ros2学习]-CLI Tools - 了解ROS 2主题(topics)   也可以去官网查http://docs.ros.org/api/geometry_msgs/html/msg/Twist.html  
[ros2学习]-CLI Tools - 了解ROS 2主题(topics)  

  • ide 配置好之后可以跳到头文件去看也行
  • 去msg文件看也行 方法有点多

 

ros2 topic pub

  可以通过命令行去发送消息  

ros2 topic pub <topic_name> <msg_type> '<args>'

  我们通过命令下发去控制小乌龟  

ros2 topic pub  --rate 1 /turtle1/cmd_vel geometry_msgs/msg/Twist '{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}'

  选项 --rate 1 或者不加 是以1HZ的速度publish,--once 是只发一次  
[ros2学习]-CLI Tools - 了解ROS 2主题(topics)  

ros2 topic hz

  实时统计topic的消息频率  

ros2 topic hz topic_name

 
[ros2学习]-CLI Tools - 了解ROS 2主题(topics)  

④ 总结

这个和ros1 区别不大


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明[ros2学习]-CLI Tools – 了解ROS 2主题(topics)
喜欢 (0)

您必须 登录 才能发表评论!

加载中……