Files
ROS2-Gazebo-GO2/README_EN.md
lulijing ed0ef0f437 docs(readme): clarify mapping and Nav2 multi-terminal workflow
- Document per-terminal commands for Cartographer SLAM and map save path
- Document Nav2 two-terminal flow and custom map:= usage
- Warn against pasting blocking launch commands in one shell
- Fix Docker comment: compose service name is go2_sim
- Sync README_EN.md with the same structure

Made-with: Cursor
2026-04-10 13:53:16 +08:00

156 lines
6.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 1. Project Description
This repository is the foundational ROS2-Gazebo simulation project for Chapter 1 of the Unitree robot dog series. The repository will be updated from time to time as the full project series progresses. You can check the current project plan on my Feishu page: [Feishu Project Page](https://ai.feishu.cn/wiki/CVpbwLIiMiwGnekKjhMcLXTRnag?from=from_copylink). This is expected to be a very long-term project.
# 2. How to Use the Project
## 2.1 Build and Run Directly
Go to the workspace:
```bash
cd go2_sim_ws
colcon build
source install/setup.bash
```
After sourcing, the `gazebo_sim` package extends **Gazebo model search paths** (`GZ_SIM_RESOURCE_PATH` / `IGN_GAZEBO_RESOURCE_PATH`) and sets **CycloneDDS** `CYCLONEDDS_URI` to the XML shipped with the package (under `share/gazebo_sim/dds/`), avoiding broken `file://~/...` URIs where `~` is not expanded. To use your own DDS config, run `unset CYCLONEDDS_URI` after sourcing or `export` an absolute `file:///...` path.
![alt text](images/image-17.png)
Launch the simulation. The first launch may take longer because required world resources need to be downloaded:
```bash
ros2 launch gazebo_sim launch.py
```
After a successful launch, you should see something like this:
![alt text](images/image-18.png)
This project includes:
- A front monocular camera to simulate the GO2 front camera
- Two LiDAR sensors:
- A front L1 LiDAR to simulate GO2s built-in LiDAR
- An external VLP16 LiDAR
Both LiDARs can publish `LaserScan` and `PointCloud2` data simultaneously, making mapping and navigation workflows easier. A D435i camera has also been added.
Use keyboard teleoperation:
```bash
cd go2_sim_ws
source install/local_setup.bash
ros2 run teleop_twist_keyboard teleop_twist_keyboard --ros-args -r /cmd_vel:=/robot1/cmd_vel
```
After running the command above, you can control the robot dog with your keyboard. You can also use the following service to control behavior. Supported commands are `walk`, `up`, and `sit`.
```bash
ros2 service call /robot1/robot_behavior_command quadropted_msgs/srv/RobotBehaviorCommand "{command: 'walk'}"
```
## 2.2 Using Docker
Before using Docker, please read the Docker setup guide briefly, since environments may differ. In my setup, I use mounted volumes.
The following commands cover the main Docker workflow:
```bash
cd go2_sim_ws/src/docker
docker compose up -d --build --remove-orphans # Build containers
docker compose up -d go2_sim # Start in detached mode; go2_sim is the compose service name
docker compose ps # List containers
docker compose exec go2_sim bash # Enter container
docker compose down # Remove containers
```
Inside the Docker container, follow the same steps as direct local usage:
```bash
colcon build
source install/setup.bash
```
![alt text](images/image-19.png)
Launch the simulation. First launch may take longer due to resource downloads:
```bash
ros2 launch gazebo_sim launch.py # Launch GO2 without extended sensors
ros2 launch gazebo_sim launch.py sensors:=true world:=warehouse.sdf # Launch GO2 with extended sensors in selected map
```
After successful startup, you should see:
![alt text](images/image-20.png)
As above, the project includes a front monocular camera and two LiDARs (GO2 front L1 + external VLP16), both of which can publish `LaserScan` and `PointCloud2`. This supports later mapping/navigation tasks. A D435i camera is also included.
```bash
cd go2_sim_ws
source install/local_setup.bash
ros2 run teleop_twist_keyboard teleop_twist_keyboard --ros-args -r /cmd_vel:=/robot1/cmd_vel
```
Once the command runs, you can control the robot dog with keyboard input. Behavior services support `walk`, `up`, and `sit`.
```bash
ros2 service call /robot1/robot_behavior_command quadropted_msgs/srv/RobotBehaviorCommand "{command: 'walk'}"
```
## 2.3 Mapping and Navigation
**Multiple terminals are required.** `ros2 launch ...` blocks the shell until you stop it with Ctrl+C. For mapping you must run **Gazebo, Cartographer, and teleop** at the same time, so use **separate terminals** (or tmux/screen panes). **Do not** paste all commands into one terminal in sequence—the first `launch` will block and the rest will never run.
**In every new terminal**, load the workspace:
```bash
cd go2_sim_ws
source install/setup.bash
```
### Mapping (Cartographer SLAM)
1. **Terminal 1 — Gazebo** (extended sensors, warehouse world):
```bash
ros2 launch gazebo_sim launch.py sensors:=true world:=warehouse.sdf
```
2. **Terminal 2 — Cartographer + RViz**:
```bash
ros2 launch cartographer go2_cartographer.launch.py
```
3. **Terminal 3 — Keyboard teleop (strongly recommended)** so the robot explores; otherwise the map will stay poor or incomplete.
```bash
ros2 run teleop_twist_keyboard teleop_twist_keyboard --ros-args -r /cmd_vel:=/robot1/cmd_vel
```
4. **Terminal 4 — Save the occupancy grid** (run when you are happy with the map; writes `warehouse_map.yaml` and `warehouse_map.pgm` in the **current directory**):
```bash
cd go2_sim_ws
source install/setup.bash
mkdir -p maps_out && cd maps_out
ros2 run nav2_map_server map_saver_cli -t map -f warehouse_map
```
If you open a fresh terminal elsewhere, `cd` into `go2_sim_ws`, `source install/setup.bash`, then `cd` to the save directory and run `map_saver_cli`. For Nav2, pass the **absolute path** to `warehouse_map.yaml` as `map:=` (from `maps_out`, run `realpath warehouse_map.yaml`).
![alt text](images/image-21.png)
### Navigation (Nav2)
When using the bundled warehouse map, keep the same world as for mapping (`warehouse.sdf`).
1. **Terminal 1 — Gazebo**:
```bash
ros2 launch gazebo_sim launch.py sensors:=true world:=warehouse.sdf
```
2. **Terminal 2 — Nav2** (default map: installed `navigation2/maps/warehouse_map.yaml`):
```bash
ros2 launch navigation2 go2_navigation2.launch.py
```
To use a map you saved yourself:
```bash
ros2 launch navigation2 go2_navigation2.launch.py map:=/absolute/path/to/go2_sim_ws/maps_out/warehouse_map.yaml
```
Set the initial pose and goal in RViz; Nav2 plans and executes—keyboard teleop is not required as the primary interface.
![alt text](images/image-22.png)