• ROS学习_基础


    ROS命令行工具使用

    一、常用命令

    • roscore :启动ros
    • rosrun :rosrun [package_name] [node_name] 调用节点 参数为功能包名和节点名称
    • rosnode :rosnode list 列出当前运行的节点
    • rqt_graph :可视化当前运行的节点
    • rostopic :进行话题的操作
      • rostopic pub :发布话题消息
      • rostopic type :查看消息类型
    • rosservice :进行服务的操作
      • rosservice call:发布服务请求
    • rosparam
    • rosmsg :获取消息的详细信息
    • rossrv

    二、示例:海龟仿真

    1. 启动ROS Master:$roscore

    2. 启动海龟仿真器:$rosrun turtlesim turtlesim_node

    3. 启动海龟控制节点:$rosrun turtlesim turtle_teleop_key
      注意:这三个命令分别在三个终端执行。

    4. 运行
      在这里插入图片描述

    三、发布话题消息

    发布消息 让海龟一直移动。

    1. 先查看消息类型
    ~$ rostopic type /turtle1/cmd_vel 
    geometry_msgs/Twist
    
    ~$ rosmsg show geometry_msgs/Twist
    geometry_msgs/Vector3 linear
      float64 x
      float64 y
      float64 z
    geometry_msgs/Vector3 angular
      float64 x
      float64 y
      float64 z
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    1. 编写参数
    ~$ rostopic pub -r 10 /turtle1/cmd_vel geometry_msgs/Twist "
    linear:
     x: 1.0
     y: 0.0
     z: 0.0
    angular:
     x: 0.0
     y: 0.0
     z: 0.0
    "
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    注意:参数对齐

    1. 运行
      在这里插入图片描述

    四、发布服务请求

    发布服务请求,添加新的海龟。

    1. 查看请求信息
    ~$ rosservice info /spawn
    Node: /turtlesim
    URI: rosrpc://ros2go:39063
    Type: turtlesim/Spawn
    Args: x y theta name
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    1. 发布请求
    ~$ rosservice call /spawn "
     x: 5.0
     y: 5.0
     theta: 0.0
     name: 'turtle2'
     "
    name: "turtle2"
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    1. 运行
      在这里插入图片描述

    五、话题和服务的区别

    1. 话题 (Topic)
    • 节点间的异步通信机制
    • 使用 发布/订阅 模型
    • 话题数据:消息(Message) 文件格式.msg
      在这里插入图片描述
    1. 服务 (Service)
    • 节点间的同步通信机制
    • 使用 客户端/服务器(C/S) 模型
    • 数据:文件格式.srv
      在这里插入图片描述
  • 相关阅读:
    设计模式与应用:命令模式
    SpringMVC---CRUD实现
    记录一次Docker与Redis冲突
    2022年牛客多校第四场补题
    maven
    5、Maven创建Web工程
    ExtJS-Sencha CMD工具
    亚马逊重大更新,底层卖家的机会来了(干货)
    消防大数据平台建设解决方案
    油田勘探问题
  • 原文地址:https://blog.csdn.net/weixin_44342705/article/details/125569579