159 lines
3.1 KiB
Markdown
159 lines
3.1 KiB
Markdown
# Gazebo Simulation
|
||
|
||
Running the GPS-denied drone simulation with Gazebo.
|
||
|
||
## Prerequisites
|
||
|
||
Install Gazebo and ROS-Gazebo bridge:
|
||
|
||
```bash
|
||
./setup/install_ubuntu.sh
|
||
source activate.sh
|
||
```
|
||
|
||
## Quick Start
|
||
|
||
**Terminal 1 - Start Gazebo:**
|
||
```bash
|
||
source activate.sh
|
||
gz sim gazebo/worlds/drone_landing.sdf
|
||
```
|
||
|
||
**Terminal 2 - Spawn drone and start bridge:**
|
||
```bash
|
||
source activate.sh
|
||
|
||
# Spawn drone
|
||
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"'
|
||
|
||
# Start bridge
|
||
python gazebo_bridge.py
|
||
```
|
||
|
||
**Terminal 3 - Run controllers:**
|
||
```bash
|
||
source activate.sh
|
||
python controllers.py --pattern circular --speed 0.3
|
||
```
|
||
|
||
## World Description
|
||
|
||
The `drone_landing.sdf` world contains:
|
||
|
||
| Object | Description |
|
||
|--------|-------------|
|
||
| Ground Plane | Infinite flat surface |
|
||
| Sun | Directional light with shadows |
|
||
| Landing Pad | Green box with "H" marker at origin |
|
||
|
||
## Drone Model
|
||
|
||
Quadrotor drone with:
|
||
|
||
- **Body**: 0.3m × 0.3m × 0.1m, 1.0 kg
|
||
- **Rotors**: 4 spinning rotors
|
||
- **IMU**: Orientation and angular velocity
|
||
- **Camera**: 320x240 downward-facing sensor
|
||
- **Odometry**: Position and velocity
|
||
|
||
### Gazebo Plugins
|
||
|
||
| Plugin | Function |
|
||
|--------|----------|
|
||
| MulticopterMotorModel | Motor dynamics |
|
||
| MulticopterVelocityControl | Velocity commands |
|
||
| OdometryPublisher | Pose and twist |
|
||
|
||
## Camera System
|
||
|
||
The drone has a downward-facing camera:
|
||
|
||
| Property | Value |
|
||
|----------|-------|
|
||
| Resolution | 320 x 240 |
|
||
| FOV | 60 degrees |
|
||
| Format | Base64 encoded JPEG |
|
||
| Update Rate | 30 Hz (Gazebo) / ~5 Hz (in telemetry) |
|
||
| Topic | `/drone/camera` |
|
||
|
||
## Gazebo Topics
|
||
|
||
| Topic | Type | Description |
|
||
|-------|------|-------------|
|
||
| `/drone/cmd_vel` | `gz.msgs.Twist` | Velocity commands |
|
||
| `/model/drone/odometry` | `gz.msgs.Odometry` | Drone state |
|
||
| `/drone/camera` | `gz.msgs.Image` | Camera images |
|
||
| `/drone/imu` | `gz.msgs.IMU` | IMU data |
|
||
|
||
## GPS-Denied Sensors
|
||
|
||
The `gazebo_bridge.py` converts Gazebo data to GPS-denied sensor format:
|
||
|
||
| Sensor | Source |
|
||
|--------|--------|
|
||
| IMU | Odometry orientation + angular velocity |
|
||
| Altimeter | Odometry Z position |
|
||
| Velocity | Odometry twist |
|
||
| Camera | Camera sensor (base64 JPEG) |
|
||
| Landing Pad | Computed from relative position |
|
||
|
||
## Headless Mode
|
||
|
||
Run without GUI:
|
||
|
||
```bash
|
||
gz sim -s gazebo/worlds/drone_landing.sdf
|
||
```
|
||
|
||
## Using the Launch File
|
||
|
||
For ROS 2 packages:
|
||
|
||
```bash
|
||
ros2 launch <package_name> drone_landing.launch.py
|
||
```
|
||
|
||
## Troubleshooting
|
||
|
||
### "Cannot connect to display"
|
||
|
||
```bash
|
||
export DISPLAY=:0
|
||
# or use headless mode
|
||
gz sim -s gazebo/worlds/drone_landing.sdf
|
||
```
|
||
|
||
### Drone falls immediately
|
||
|
||
The velocity controller may need to be enabled:
|
||
|
||
```bash
|
||
gz topic -t /drone/enable -m gz.msgs.Boolean -p 'data: true'
|
||
```
|
||
|
||
### Topics not visible in ROS
|
||
|
||
Ensure the bridge is running:
|
||
|
||
```bash
|
||
python gazebo_bridge.py
|
||
```
|
||
|
||
### Model not found
|
||
|
||
Set the model path:
|
||
|
||
```bash
|
||
export GZ_SIM_RESOURCE_PATH=$PWD/gazebo/models:$GZ_SIM_RESOURCE_PATH
|
||
```
|
||
|
||
### Camera image not in telemetry
|
||
|
||
Ensure PIL/Pillow is installed:
|
||
```bash
|
||
pip install pillow
|
||
```
|