# ros2学习 **Repository Path**: wuyanfei2025/ros2-learning ## Basic Information - **Project Name**: ros2学习 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-05-14 - **Last Updated**: 2025-06-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ros2学习 #### 介绍 {这是一个ros2常用命令集合)} #### ros2常用命令集合 #### SLAM和NAV2向关 1. sudo apt install ros-humble-slam-toolbox #安装建图包 2. ros2 pkg list | grep slam_toolbox # 检查包是否存在 3. ros2 launch slam_toolbox online_async_launch.py # 尝试启动(会报错但验证安装) 4. sudo apt install ros-humble-navigation2 ros-humble-nav2-bringup #导航工具包(Navigation2)安装 5. sudo apt install ros-humble-rplidar-ros #激光雷达(LIDAR)​​(如 RPLIDAR) 6. sudo apt install ros-humble-imu-tools #安装IMU​​(如 MPU6050) 7. ros2 launch slam_toolbox offline_launch.py #离线建图(已有数据包) 8. ros2 launch slam_toolbox online_async_launch.py use_sim_time:=True # online_async_launch:在线异步建图模式,use_sim_time:=True(​​关键参数​​:启用仿真时间,而非系统实时时间),异步处理​​:SLAM 算法在后台运行,不阻塞其他节点。增量式建图​​:支持动态更新地图(如机器人移动时持续扩展地图)。适用于​​:真实机器人或仿真环境(如 Gazebo) 9. sudo apt install ros-humble-tf2-* ros-humble-rviz2 #安装TF工具​​。 10. ros2 run nav2_map_server map_saver_cli -f room #保存地图名称为room 11. sudo apt install ros-${ROS_DISTRO}-gazebo-ros2-control #安装 gazebo_ros2_control 插件​​ 12. ros2 run tf2_tools view_frames.py 生成 TF 树 PDF 可视化 13. ros2 topic echo /joint_states检查关节状态话题 14. ros2 topic info /tf_static 检查静态 TF 数据 15. check_urdf your_robot.urdf 验证 URDF 结构完整性 16. ros2 control list_controllers 验证控制器状态​,正常输出应显示控制器为 active:joint_state_broadcaster[active]diff_drive_controller[active] 17. robot_state_publisher​​ 18. sudo apt install ros-humble-rqt-tf-tree ,安装后执行rm ~/.config/ros.org/rqt_gui.ini rm ~/.ros/log/ 19. sudo apt install ros-humble-nav2-map-server 安装map server 20. ros2 node info /acml 查看导航配置文件节点/acml 21. ros2 launch nav2_bringup tb3_simulation_launch.py headless:=False 22. sudo apt remove --purge brltty -y 解决usb端口占用问题 23. sudo usermod -aG dialout 'whoami' 解决Usb权限问题 24. cp -r xxx xyz 复制xxx工程命令为新工程xyz 25. # 创建Python功能包(依赖rclpy和sensor_msgs) ros2 pkg create --build-type ament_python imu_serial_reader \ --dependencies rclpy sensor_msgs serial 26. # 停止扫描 ros2 service call /stop_scan std_srvs/srv/Empty # 开始扫描 ros2 service call /start_scan std_srvs/srv/Empty 27. 激活platformio 虚拟空间 penv 下 . bin/activate 28. ros2 pkg list | grep control 查看ros2功能包 cotrol相关包 ​​类别​​ ​​命令​​ ​​说明​​ ​​示例/备注​​ ​​1. 查看节点信息​​ ros2 node list 列出当前系统中所有活跃的节点名称。 ros2 node list → /turtlesim ros2 node info 查看节点的详细信息(订阅、发布、服务、动作等接口)。 ros2 node info /turtlesim ​​2. 运行节点​​ ros2 run 运行指定包中的可执行文件(节点)。 ros2 run turtlesim turtlesim_node ros2 launch 通过启动文件批量运行节点(需 Python 格式的 .launch.py 文件)。 ros2 launch turtlesim multisim.launch.py ros2 run --ros-args --remap __node:= 重映射节点名称或命名空间。 ros2 run turtlesim turtlesim_node --ros-args --remap __node:=my_turtle ​​3. 调试与监控​​ ros2 topic echo 订阅并打印指定话题的消息(调试用)。 ros2 topic echo /turtle1/cmd_vel ros2 param list 列出节点的所有参数。 ros2 param list /turtlesim → background_b ros2 param get 获取节点某个参数的值。 ros2 param get /turtlesim background_b → 255 ros2 node list --no-daemon 实时监控节点的动态加入或退出(需保持终端运行)。 按 Ctrl+C 退出监控模式。 rqt_graph 可视化节点、话题和服务的连接关系(需安装 rqt_graph)。 需先安装:sudo apt install ros-humble-rqt-graph ​​4. 生命周期管理​​ ros2 lifecycle set 管理节点生命周期状态(如 configure、activate、shutdown)。 ros2 lifecycle set /turtlesim shutdown Ctrl+C 在终端中手动终止当前运行的节点。 通用终止方法。 ​​其他工具​​ ros2 pkg prefix 查找节点所属的包安装路径。 ros2 pkg prefix turtlesim → /opt/ros/humble/share/turtlesim ros2 run --ros-args --log-level 设置节点日志级别(如 debug、info、warn)。 ros2 run turtlesim turtlesim_node --ros-args --log-level debug ros2 run --ros-args -p := 启动时直接传递参数。 #### 参与贡 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)