当前位置:网站首页>[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>
边栏推荐
猜你喜欢
迅为iTOP-IMX6ULL开发板Pinctrl和GPIO子系统实验-修改设备树文件
[untitled]
MySQL入门尝鲜
Esp32 construction engineering add components
Digital IC Design SPI
【Presto Profile系列】Timeline使用
高端了8年,雅迪如今怎么样?
Practical example of propeller easydl: automatic scratch recognition of industrial parts
Esp32 ① compilation environment
PAcP learning note 1: programming with pcap
随机推荐
QQ medicine, Tencent ticket
Some principles of mongodb optimization
10 张图打开 CPU 缓存一致性的大门
Signal strength (RSSI) knowledge sorting
Cmake learning and use notes (1)
抓细抓实抓好安全生产各项工作 全力确保人民群众生命财产安全
QQ的药,腾讯的票
Cinnamon 任务栏网速
The difference between cache and buffer
记一次 .NET 某新能源系统 线程疯涨 分析
MongoDB的导入导出、备份恢复总结
centso7 openssl 报错Verify return code: 20 (unable to get local issuer certificate)
【Presto Profile系列】Timeline使用
Practical example of propeller easydl: automatic scratch recognition of industrial parts
MongoDB复制(副本集)总结
Unity build error: the name "editorutility" does not exist in the current context
LIS 最长上升子序列问题(动态规划、贪心+二分)
MongoDB 遇见 spark(进行整合)
LIS longest ascending subsequence problem (dynamic programming, greed + dichotomy)
shell 批量文件名(不含扩展名)小写改大写