127 lines
3.8 KiB
Markdown
127 lines
3.8 KiB
Markdown
# Docker Setup for RDC Simulation
|
|
|
|
This guide explains how to run the RDC Simulation environment inside a Docker container with NVIDIA GPU support and X11 display forwarding. This approach isolates the simulation environment from your host system while providing full hardware acceleration.
|
|
|
|
## Prerequisites
|
|
|
|
1. **Docker Engine**: Install Docker for your OS.
|
|
2. **NVIDIA GPU & Drivers**: Ensure you have an NVIDIA GPU and proprietary drivers installed.
|
|
3. **NVIDIA Container Toolkit**: Required for GPU pass-through to Docker.
|
|
|
|
```bash
|
|
# Install NVIDIA Container Toolkit
|
|
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
|
|
echo "deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://nvidia.github.io/libnvidia-container/stable/deb/$(. /etc/os-release;echo $ID$VERSION_ID) /" | sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
|
|
sudo apt update && sudo apt install -y nvidia-container-toolkit
|
|
sudo systemctl restart docker
|
|
```
|
|
|
|
## Quick Start
|
|
|
|
### 1. Build the Image
|
|
|
|
```bash
|
|
cd ~/RDC_Simulation
|
|
docker compose build
|
|
```
|
|
*This may take 15-20 minutes mostly due to compiling Gazebo plugins.*
|
|
|
|
### 2. Allow X11 Display Access
|
|
|
|
To allow the container to display the Gazebo GUI on your host screen:
|
|
|
|
```bash
|
|
xhost +local:docker
|
|
```
|
|
|
|
### 3. Run the Container
|
|
|
|
```bash
|
|
docker compose run --rm simulation
|
|
```
|
|
|
|
This drops you into a bash shell inside the container as the user `pilot`.
|
|
|
|
---
|
|
|
|
## Running the Simulation
|
|
|
|
Once inside the container, the environment is pre-configured.
|
|
|
|
### 1. Start the Environment
|
|
You can use the helper script to verify everything is ready:
|
|
|
|
```bash
|
|
./docker-entrypoint.sh
|
|
```
|
|
|
|
### 2. Launch Components (Multi-Terminal)
|
|
|
|
Since `docker compose run` gives you a single terminal, you can verify basic functionality, but for the full workflow you might want to run the combined script:
|
|
|
|
```bash
|
|
# Run everything (Gazebo + SITL + Controller)
|
|
./scripts/run_ardupilot_controller.sh
|
|
```
|
|
|
|
**Or** manually launch components in background/separate terminals:
|
|
|
|
To open a second terminal into the *running* container:
|
|
1. Find the container name or ID: `docker ps`
|
|
2. Exec into it: `docker exec -it <container_name> bash`
|
|
|
|
Then run your components:
|
|
* **Terminal 1:** Gazebo
|
|
```bash
|
|
./scripts/run_ardupilot_sim.sh runway
|
|
```
|
|
* **Terminal 2:** ArduPilot SITL
|
|
```bash
|
|
sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON --console
|
|
```
|
|
* **Terminal 3:** Controller
|
|
```bash
|
|
python scripts/run_ardupilot.py --pattern square
|
|
```
|
|
|
|
---
|
|
|
|
## Video Recording
|
|
|
|
The Docker image includes `ffmpeg` and tools to record the simulation.
|
|
|
|
### Record Flight
|
|
Run a flight pattern and save the video automatically:
|
|
|
|
```bash
|
|
python scripts/record_flight.py --pattern square --quality high --output my_flight_video
|
|
```
|
|
Videos are saved to the `recordings/` directory which is mounted inside the container (if you used a volume mount) or can be copied out.
|
|
|
|
### Record Manually
|
|
```bash
|
|
./scripts/record_simulation.sh --duration 30
|
|
```
|
|
|
|
---
|
|
|
|
## Headless Mode (CI/Server)
|
|
|
|
If you are running on a remote server without a display attached, use the headless service. Note that standard Gazebo GUI will not show, but you can still run simulations and record videos (rendering offscreen).
|
|
|
|
```bash
|
|
docker compose run --rm simulation-headless
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
**"All CUDA-capable devices are busy or unavailable"**
|
|
Check your NVIDIA drivers on the host. verifying with `nvidia-smi`.
|
|
|
|
**"Example: Could not connect to display :0"**
|
|
Make sure you ran `xhost +local:docker` on the host machine.
|
|
If using SSH, ensure X11 forwarding is enabled (`ssh -X`).
|
|
|
|
**Persisting Data**
|
|
The `docker-compose.yml` mounts the project directory. Changes to python scripts *inside* the container are reflected on your host machine.
|