• [1] ROS2基础知识-操作命令总结版



    本文主要是对之前用到的ROS2指令进行汇总, 便于后续查阅。 主要包括:功能包、节点、话题、服务、动作、参数、launch、ros2 bag等操作命令。

    1. 功能包

    # 1.创建工作空间
    mkdir -p test_ws/src 
    cd test_ws/src
    # 2.创建功能包
    ros2 pkg create <package-name> --build-type {cmake,ament_cmake,ament_python} --dependencies <依赖名字>
    # 3.编译功能包
    colcon build --packages-select <package-name>
    
    # 4.列出所有功能包
    ros2 pkg list
    # 5.列出功能包下的可执行文件
    ros2 pkg executables turtlesim
    # 6.列出功能包的路径
    ros2 pkg prefix turtlesim
    # 7.列出功能包的描述文件
    ros2 pkg xml turtlesim
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    详文链接:[3] ROS2初探之功能包使用方法

    2. 节点

    # ros2 run 功能包名称 可执行文件名称 
    ros2 run <package_name> <executable_name>
    
    # 查看所有节点名称
    ros2 node list
    # 查看节点信息
    ros2 node info /turtlesim
    # 节点重映射
    ros2 run turtlesim turtlesim_node --ros-args --remap __node:=my_turtle
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    详文链接:[4] ROS2初探之节点的使用方法

    3. 话题

    # 1.查看话题列表
    ros2 topic list  
    # 2.查看带有类型属性后缀的话题列表
    ros2 topic list -t
    # 3.查看话题内容 ros2 topic echo <topic_name>
    ros2 topic echo /turtle1/cmd_vel
    # 4.查看话题info
    ros2 topic info /turtle1/cmd_vel
    # 5.查看话题消息的数据结构,配合 ros2 topic list -t使用
    ros2 interface show /geometry_msgs/msg/Twist
    # 6.查看话题发布频率
    ros2 topic hz /turtle1/cmd_vel
    # 7.发布话题消息ros2 topic pub <topic_name> <msg_type> '<args>'
    ros2 topic pub --once /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}}"
    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}}"
    # 使用插件查看话题之间的关系
    rqt_graph
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    详文链接:[5] ROS2初探之通信机制学习(话题)

    4. 服务

    # 1.查看服务列表
    ros2 service list
    # 2.查看服务接口类型
    ros2 service type /add_two_ints
    # 3.查找使用某一接口的服务
    ros2 service find example_interfaces/srv/AddTwoInts
    # 4.调用服务接口
    ros2 service call /add_two_ints example_interfaces/srv/AddTwoInts "{a: 5,b: 10}"
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    详文链接:[7] ROS2初探之通信机制学习(服务)

    5. 动作

    # 1. 查看Action列表
    ros2 action list
    # 2. 查看Action列表+Action类型
    ros2 action list -t
    # 3. 查看接口信息内容
    ros2 interface show [Action类型]
    # 4. 查看Action信息
    ros2 action info [Action名称]
    # Action请求服务端发送数据
    ros2 action send_goals [Action名称] [Action类型] [valus] --feedback
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    详文链接:[10] ROS2初探之通信机制学习(动作)

    6. 参数

    # 1. 查看所有节点的参数列表
    ros2 param list
    # 2. 查看一个参数的详细信息
    ros2 param describe <node_name> <param_name>
    # 3. 获取参数的直
    ros2 param get <node_name> <param_name>
    # 4. 设置参数的值(临时修改)
    ros2 param set <node_name> <parameter_name> <value>
    # 5. 先set设置参数值,再dump保存参数文件(yaml格式)
    ros2 param dump <node_name>
    # 6. 加载调用参数文件
    ros2 param load <node_name> <file_name>
    # 7. 启动节点时加载调用参数文件
    ros2 run <package_name> <executable_name> --ros-args --params-file <file_name> 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    详文链接:[12] ROS2初探之通信机制学习(参数)

    7. launch模板

    # 在ROS2中,一般launch文件后缀格式为name_launch.py或者name.launch.py
    touch my_script_launch.py
    gedit my_script_launch.py
    
    • 1
    • 2
    • 3
    from launch import LaunchDescription
    from launch_ros.actions import Node
    
    def generate_launch_description():
        return LaunchDescription([
            Node(
                package='turtlesim',
                namespace='turtlesim1',
                executable='turtlesim_node',
                name='sim'
            ),
            Node(
                package='turtlesim',
                namespace='turtlesim2',
                executable='turtlesim_node',
                name='sim'
            ),
            Node(
                package='turtlesim',
                executable='mimic',
                name='mimic',
                remappings=[
                    ('/input/pose', '/turtlesim1/turtle1/pose'),
                    ('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
                ]
            )
        ])
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    详文链接:[14] ROS2初探之节点管理工具launch文件

    8. ros2 bag

    # 1.记录话题消息
    ros2 bag record <topic_name>
    # 2.记录多个话题消息
    ros2 bag record -o <file_dir_name> <topic_name_1> <topic_name_2>...<topic_name_n>
    # 3.记录所有话题消息
    ros2 bag record -a
    # 4.查看话题数据记录文件信息(比如话题记录的时间,大小,类型,数量)
    ros2 bag info <file_dir_name>
    # 5.播放记录下来的话题数据
    ros2 bag play <file_dir_name>
    # 6.循环播放记录下来的话题数据
    ros2 bag play <file_dir_name> -l
    # 7.倍速播放(2倍速)
    ros2 bag play <file_dir_name> -r 2
    # 8.播放指定话题的数据
    ros2 bag play <file_dir_name> --topic <topic_name>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    详文链接:[15] ROS2初探之记录话题的数据ros2 bag

  • 相关阅读:
    文章提交秒收录软件
    优雅的使用token
    【饭谈-鸡血篇】自以为对,就是错。
    2023年中国家用路由器市场发展概况分析:家用路由器线上市场整体销量为1050.6万台[图]
    【Note】CNN与现代卷积神经网络part4(附PyTorch代码)
    12-2- DCGAN -简单网络-卷积网络
    php 安装rabbitmq:如何使用 PHP 安装 RabbitMQ?
    《入门级-Cocos2dx4.0 塔防游戏开发》---第十一课:游戏地图信息初始化
    计算机网络实验——基于TCP协议的socket编程
    【思维构造】Element Extermination—CF1375C
  • 原文地址:https://blog.csdn.net/qq_41821678/article/details/125633778