151 lines
3.1 KiB
Markdown
151 lines
3.1 KiB
Markdown
# Gazebo Simulation
|
|
|
|
Running the GPS-denied drone simulation with Gazebo (Linux only).
|
|
|
|
## Quick Start (2 Terminals)
|
|
|
|
**Terminal 1 - Start Gazebo:**
|
|
```bash
|
|
source activate.sh
|
|
gz sim gazebo/worlds/drone_landing.sdf
|
|
```
|
|
|
|
**Terminal 2 - Run Controllers:**
|
|
```bash
|
|
source activate.sh
|
|
python run_gazebo.py --pattern circular --speed 0.3
|
|
```
|
|
|
|
## Options
|
|
|
|
```bash
|
|
python run_gazebo.py --help
|
|
|
|
Options:
|
|
--pattern stationary, linear, circular, square, random
|
|
--speed, -s Rover speed in m/s (default: 0.5)
|
|
--amplitude, -a Movement amplitude (default: 2.0)
|
|
--no-rover Disable rover controller
|
|
```
|
|
|
|
## Spawning the Drone
|
|
|
|
If the drone isn't in the world, spawn it:
|
|
|
|
```bash
|
|
gz service -s /world/drone_landing_world/create \
|
|
--reqtype gz.msgs.EntityFactory \
|
|
--reptype gz.msgs.Boolean \
|
|
--req 'sdf_filename: "gazebo/models/drone/model.sdf", name: "drone"'
|
|
```
|
|
|
|
## GPS-Denied Sensors
|
|
|
|
The `run_gazebo.py` script provides the same sensor interface as PyBullet:
|
|
|
|
| Sensor | Source |
|
|
|--------|--------|
|
|
| IMU | Gazebo odometry |
|
|
| Altimeter | Gazebo Z position |
|
|
| Velocity | Gazebo twist |
|
|
| Camera | Gazebo camera sensor |
|
|
| Landing Pad | Computed from relative position |
|
|
|
|
## Gazebo Topics
|
|
|
|
| Topic | Type | Description |
|
|
|-------|------|-------------|
|
|
| `/drone/cmd_vel` | `Twist` | Velocity commands |
|
|
| `/model/drone/odometry` | `Odometry` | Drone state |
|
|
| `/drone/camera` | `Image` | Camera images |
|
|
|
|
## Headless Mode
|
|
|
|
Run without GUI:
|
|
|
|
```bash
|
|
gz sim -s gazebo/worlds/drone_landing.sdf
|
|
```
|
|
|
|
---
|
|
|
|
## ROS 2 Launch File (Advanced)
|
|
|
|
**Location:** `gazebo/launch/drone_landing.launch.py`
|
|
|
|
This launch file automates Gazebo startup for ROS 2 integration:
|
|
1. Starts Gazebo with the world
|
|
2. Spawns the drone automatically
|
|
3. Starts `ros_gz_bridge` to connect topics
|
|
|
|
### Option 1: Direct Launch (Recommended)
|
|
|
|
Run the launch file directly with `ros2 launch`:
|
|
|
|
```bash
|
|
source activate.sh
|
|
ros2 launch gazebo/launch/drone_landing.launch.py
|
|
```
|
|
|
|
Then in another terminal, run just the controllers:
|
|
```bash
|
|
source activate.sh
|
|
python controllers.py --pattern circular
|
|
```
|
|
|
|
### Option 2: Include in Your ROS 2 Package
|
|
|
|
If you have a ROS 2 package, copy the launch file and use:
|
|
```bash
|
|
ros2 launch my_drone_package drone_landing.launch.py
|
|
```
|
|
|
|
### Launch Arguments
|
|
|
|
| Argument | Default | Description |
|
|
|----------|---------|-------------|
|
|
| `use_sim_time` | `true` | Use Gazebo clock |
|
|
| `headless` | `false` | Run without GUI |
|
|
|
|
```bash
|
|
ros2 launch gazebo/launch/drone_landing.launch.py headless:=true
|
|
```
|
|
|
|
### Topics Bridged by Launch File
|
|
|
|
| ROS 2 Topic | Description |
|
|
|-------------|-------------|
|
|
| `/drone/cmd_vel` | Velocity commands |
|
|
| `/model/drone/odometry` | Drone state |
|
|
| `/drone/imu` | IMU sensor |
|
|
| `/clock` | Simulation time |
|
|
|
|
---
|
|
|
|
## Troubleshooting
|
|
|
|
### Model not found
|
|
|
|
Set the model path:
|
|
```bash
|
|
export GZ_SIM_RESOURCE_PATH=$PWD/gazebo/models:$GZ_SIM_RESOURCE_PATH
|
|
```
|
|
|
|
### Drone falls immediately
|
|
|
|
Enable the velocity controller:
|
|
```bash
|
|
gz topic -t /drone/enable -m gz.msgs.Boolean -p 'data: true'
|
|
```
|
|
|
|
### "Cannot connect to display"
|
|
|
|
Use headless mode or WSLg:
|
|
```bash
|
|
# Headless
|
|
gz sim -s gazebo/worlds/drone_landing.sdf
|
|
|
|
# Or ensure DISPLAY is set
|
|
export DISPLAY=:0
|
|
```
|