# ros2_robot_learning **Repository Path**: ethanjoker/ros2_robot_learning ## Basic Information - **Project Name**: ros2_robot_learning - **Description**: it's a robot learning project - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-14 - **Last Updated**: 2026-05-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ROS2 差速机器人仿真 一个跑在 Gazebo 里的差速移动机器人,能自己往前走、靠激光检测前方障碍、撞之前先退一下再转头绕开。主要是拿来熟悉 ROS2 + Gazebo + ros2_control 这一套流程的练手项目。 ## 依赖 - Ubuntu 22.04 - ROS2 Humble(Jazzy 应该也行,脚本会自己探测) - Gazebo Classic(`gazebo_ros`) - colcon 没装的话先来一发: ```bash sudo apt update sudo apt install -y ros-humble-desktop ros-humble-gazebo-ros-pkgs \ ros-humble-gazebo-ros2-control python3-colcon-common-extensions ``` ## 跑起来 ```bash cd guiding_project chmod +x scripts/*.sh ros2_ws/src/robot_bringup/scripts/*.py ./scripts/health_check.sh # 先做个语法/依赖自检 ./scripts/launch_sim.sh # 起 Gazebo + 机器人 + 避障 + RViz ``` 启动后机器人会直行,靠近箱子时 `/obstacle_detected` 变 `true`,于是先倒一小段再原地转向,转开之后继续往前。 ## 目录结构 ```text guiding_project/ ├── ros2_ws/src/robot_bringup/ │ ├── launch/ # sim.launch.py 一键起全套 │ ├── urdf/ # diffbot.urdf.xacro 机器人模型 + 传感器 │ ├── worlds/ # 带两个箱子的训练场地 │ ├── config/ # 控制器参数 + RViz 配置 │ └── scripts/ # obstacle_detector.py / simple_avoidance.py ├── scripts/ # setup_env / health_check / launch_sim ├── docs/ # 排障笔记 └── README.md ``` ## 避障是怎么连起来的 激光雷达 `/front_range`(在 URDF 里是个 ray 传感器,不是深度相机——深度相机只挂在 RViz 上看)发出扫描,`obstacle_detector.py` 取最近距离发到 `/obstacle_distance` 和 `/obstacle_detected`,`simple_avoidance.py` 再据此发 `/cmd_vel`。两个节点用话题解耦,调起来方便。 ## 踩过的坑 - 激光传感器一开始放在车头(`x=0.17`),结果扫到自己车身,距离全是 0.08,怎么都以为前面有障碍。挪到 `x=0.24` 车体外面才正常。 - 深度相机别在 `` 里乱加 pitch,Gazebo 相机默认就朝 +x,一转反而对着天。 - 避障早期只会原地转,车头顶着箱子转不动,后来加了「先后退再转」才稳。 更多排查见 `docs/troubleshooting.md`。