1. 常用命令
1.1. node 相关命令
1 2 3 4 5 6 7 8 9 10
| ros2 node list
ros2 node info <node_name>
ros2 run <package_name> <executable_name>
ros2 run turtlesim turtlesim_node
ros2 run <package_name> <executable_name> --ros-args --params-file <file_name>
|
1.2. topic 相关命令
1 2 3 4 5 6
| ros2 topic list
ros2 topic type <topic_name>
ros2 topic info <topic_name>
|
1.3. service 相关命令
1 2 3 4 5 6
| ros2 service list
ros2 service type <service_name>
ros2 service info <service_name>
|
1.4. action 相关命令
1 2 3 4 5 6 7 8 9 10 11 12
| ros2 action list
ros2 action list -t
ros2 action type <action_name>
ros2 action info <action_name>
ros2 action send_goal <action_name> <action_type> <values>
ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: 1.57}"
|
1.5. param 相关命令
1 2 3 4 5 6 7 8 9 10 11 12
| ros2 param list
ros2 param get <node_name> <parameter_name>
ros2 param set <node_name> <parameter_name> <value>
ros2 param dump <node_name>
ros2 param load <node_name> <parameter_file>
ros2 run <package_name> <executable_name> --ros-args --params-file <file_name>
|
1.6. interface 相关命令
1 2 3 4
| ros2 interface show <interface_name>
ros2 interface show turtlesim/action/RotateAbsolute
|
2. ROS节点的创建、编译和运行流程
2.1. 创建 workspace ros2_ws
1 2
| mkdir -p ~/ros2_ws/src cd ~/ros2_ws/src
|
2.2. 创建 package
1 2 3
| ros2 pkg create --build-type ament_cmake --license Apache-2.0 <package_name>
ros2 pkg create --build-type ament_cmake --license Apache-2.0 cpp_pubsub
|
2.3. 检查 dependencies
检查依赖项并安装依赖项
1
| rosdep install -i --from-path src --rosdistro jazzy -y
|
如果出现以下报错:
1
| ERROR: your rosdep installation has not been initialized yet.
|
执行以下命令初始化rosdep:
1 2
| sudo rosdep init rosdep update
|
2.4. 构建 package
1 2 3 4 5 6
| cd ~/ros2_ws
colcon build
colcon build --packages-select <package_name>
|
2.5. 运行 node
1 2 3 4 5 6 7 8 9
| source install/local_setup.zsh
ros2 run <package_name> <executable_name>
ros2 run cpp_pubsub talker
ros2 run cpp_pubsub listener
|
3. ros2doctor 工具
3.1. 工具介绍
ros2doctor是ROS2的诊断工具,它会检查ROS2的各个方面,包括平台、版本、网络、环境、正在运行的系统等,并就可能出现的错误及问题原因向你发出警告。
ros2doctor
它是ros2cli
包的一部分,在安装ROS2时就默认已经安装。当你的ROS2设置未按预期运行时,你可以使用ros2doctor工具检查其设置。
3.2. 工具使用
1 2 3 4 5 6 7
| ros2 doctor
ros2 doctor --report
|
3.3. 参考文档
https://docs.ros.org/en/jazzy/Tutorials/Beginner-Client-Libraries/Getting-Started-With-Ros2doctor.html#