当前位置:网站首页>[1] ROS2基础知识-操作命令总结版
[1] ROS2基础知识-操作命令总结版
2022-07-07 11:28:00 【酸梅果茶】
本文主要是对之前用到的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
详文链接:[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
详文链接:[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
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}"
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
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>
7. launch模板
# 在ROS2中,一般launch文件后缀格式为name_launch.py或者name.launch.py
touch my_script_launch.py
gedit my_script_launch.py
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'),
]
)
])
详文链接:[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>
边栏推荐
- [QNX Hypervisor 2.2用户手册]6.3.4 虚拟寄存器(guest_shm.h)
- 工具箱之 IKVM.NET 项目新进展
- About how appium closes apps (resolved)
- RecyclerView的数据刷新
- 存储过程的介绍与基本使用
- 【学习笔记】线段树选做
- Split screen bug notes
- Sed of three swordsmen in text processing
- Read PG in data warehouse in one article_ stat
- JS slow motion animation principle teaching (super detail)
猜你喜欢
随机推荐
[untitled]
MongoDB 遇见 spark(进行整合)
单片机学习笔记之点亮led 灯
Analysis of DHCP dynamic host setting protocol
Write it down once Net a new energy system thread surge analysis
Mongodb replication (replica set) summary
cmake 学习使用笔记(一)
JS中为什么基础数据类型可以调用方法
记一次 .NET 某新能源系统 线程疯涨 分析
PAcP learning note 1: programming with pcap
regular expression
clion mingw64中文乱码
解决缓存击穿问题
DETR介绍
Mongodb slice summary
MongoDB内部的存储原理
About the problem of APP flash back after appium starts the app - (solved)
[Presto profile series] timeline use
Summary of import, export, backup and recovery of mongodb
如何让join跑得更快?