文章目录
 - 指令帮助
 - 创建功能包
 - 功能包查找
 - 编译
 - 执行
 - 节点
 - 查看话题
 - 服务命令
 - 接口命令
 - 动作命令
 - 参数命令
 - 录制控制命令
 
 
 
  
 
指令帮助
 
ros2 --help  # 帮助查看命令
 
创建功能包
 
ros2 pkg create 包名 --build-type 构建类型 --dependencies 依赖列表 --node-name 可执行程序名称
 
功能包查找
 
ros2 pkg executables [包名] # 输出所有功能包或指定功能包下的可执行程序。
ros2 pkg list # 列出所有功能包
ros2 pkg prefix 包名 # 列出功能包路径
ros2 pkg xml # 输出功能包的package.xml内容
 
编译
 
colcon build							  #编译所有功能包
colcon build --packages-select 功能包列表   #编译指定功能包
 
执行
 
ros2 run 功能包 可执行程序 参数                 #语法
ros2 run turtlesim turtlesim_node           #实例 运行节点
ros2 run turtlesim turtle_teleop_key        #实例 运行节点
 
节点
 
ros2 node list               # 查看节点列表
ros2 node info <node_name>   # 查看节点信息
 
查看话题
 
ros2 topic list                # 查看话题列表
ros2 topic echo <topic_name>   # 查看话题实时数据
ros2 topic info <topic_name>   # 查看话题信息
ros2 topic hz <topic_name>     # 查看话题发布频率
ros2 topic bw <topic_name>     # 查看话题传输带宽
ros2 topic pub <topic_name> <msg_type> <msg_data> # 发布话题消息
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}}"    #实例 通过命令行发布话题消息
 
服务命令
 
ros2 service list                  # 查看服务列表
ros2 service type <service_name>   # 查看服务数据类型
ros2 service call <service_name> <service_type> <service_data>   # 调用服务
ros2 service call /spawn turtlesim/srv/Spawn "{x: 2, y: 2, theta: 0.2, name: ''}"                  # 实例 调用服务
 
接口命令
 
ros2 interface list                    # 查看系统接口列表
ros2 interface show <interface_name>   # 查看某个接口的详细定义
ros2 interface package <package_name>  # 查看某个功能包中的接口定义
 
动作命令
 
$ ros2 action list                  # 查看动作列表
$ ros2 action info <action_name>    # 查看动作数据类型
$ ros2 action send_goal <action_name> <action_type> <action_data>   # 调用动作
ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "theta: 3" #实例 调用动作目标,让海龟转到指定角度
ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: -1.57}"  #实例 调用动作目标,让海龟转到指定角度
$ ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: -1.57}" --feedback  #实例 调用动作目标,让海龟转到指定角度,并且反馈
 
参数命令
 
$ ros2 param list
$ ros2 param describe turtlesim background_b   # 查看某个参数的描述信息$ ros2 param get turtlesim background_b        # 查询某个参数的值
$ ros2 param set turtlesim background_b 10     # 修改某个参数的值$ ros2 param dump turtlesim >> turtlesim.yaml  # 将某个节点的参数保存到参数文件中
$ ros2 param load turtlesim turtlesim.yaml     # 一次性加载某一个文件中的所有参数
 
录制控制命令
 
ros2 bag record /turtle1/cmd_vel  # 录制控制
ros2 bag play rosbag2_2022_04_11-17_35_40/rosbag2_2022_04_11-17_35_40_0.db3         # 播放控制