enhance installation guides, add environment setup, and expand troubleshooting for all platforms.

This commit is contained in:
2026-01-07 19:55:10 +00:00
parent 232ee2d8d5
commit e6ed6fcfac
6 changed files with 451 additions and 45 deletions

View File

@@ -1,13 +1,23 @@
# ArduPilot + Gazebo Simulation
## Prerequisites
Before running, ensure your environment is set up:
```bash
source activate.sh
# or
source ~/.ardupilot_env && source ~/venv-ardupilot/bin/activate
```
## Quick Start (2 Terminals)
**Terminal 1:**
**Terminal 1 - Start Gazebo:**
```bash
./scripts/run_ardupilot_sim.sh runway
```
**Terminal 2:**
**Terminal 2 - Start Controller:**
```bash
./scripts/run_ardupilot_controller.sh
```
@@ -21,33 +31,41 @@
└─────────────────┘ └─────────────────┘ └─────────────────┘
```
**Communication:**
- Gazebo ↔ SITL: JSON sensor data over UDP (port 9002)
- SITL ↔ Your Code: MAVLink over TCP (port 5760)
## World Options
```bash
./scripts/run_ardupilot_sim.sh runway # Default
./scripts/run_ardupilot_sim.sh warehouse # Indoor
./scripts/run_ardupilot_sim.sh zephyr # Fixed-wing
./scripts/run_ardupilot_sim.sh runway # Default (outdoor runway)
./scripts/run_ardupilot_sim.sh warehouse # Indoor warehouse
./scripts/run_ardupilot_sim.sh gimbal # With camera gimbal
./scripts/run_ardupilot_sim.sh zephyr # Fixed-wing aircraft
./scripts/run_ardupilot_sim.sh custom # Your custom world
./scripts/run_ardupilot_sim.sh my_world # gazebo/worlds/my_world.sdf
```
## GPS-Denied Mode
The simulation runs in GPS-denied mode by default.
The simulation runs in GPS-denied mode by default. The controller disables GPS checks and uses visual navigation.
For manual debugging with MAVProxy:
```bash
sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON --console
# In MAVProxy:
# In MAVProxy console:
param set ARMING_CHECK 0
mode stabilize
arm throttle force
rc 3 1500 # Throttle up
```
## Controller Options
```bash
./scripts/run_ardupilot_controller.sh # Auto takeoff
./scripts/run_ardupilot_controller.sh --no-takeoff # Manual
./scripts/run_ardupilot_controller.sh --no-takeoff # Manual control
./scripts/run_ardupilot_controller.sh -a 10 # 10m altitude
```
@@ -55,18 +73,130 @@ arm throttle force
| File | Purpose |
|------|---------|
| `scripts/run_ardupilot_sim.sh` | Gazebo + GPU detection |
| `scripts/run_ardupilot_controller.sh` | SITL + Controller |
| `scripts/run_ardupilot.py` | MAVLink interface |
| `src/drone_controller.py` | Your algorithm |
| `scripts/run_ardupilot_sim.sh` | Gazebo launcher with GPU detection |
| `scripts/run_ardupilot_controller.sh` | SITL + Controller launcher |
| `scripts/run_ardupilot.py` | MAVLink interface script |
| `src/drone_controller.py` | Your landing algorithm |
## Environment Variables
The scripts automatically set these, but for manual runs:
```bash
# ArduPilot tools
export PATH=$PATH:~/ardupilot/Tools/autotest
# ArduPilot venv (has empy, pymavlink, etc.)
source ~/venv-ardupilot/bin/activate
# Gazebo plugin paths
export GZ_SIM_SYSTEM_PLUGIN_PATH=~/ardupilot_gazebo/build:$GZ_SIM_SYSTEM_PLUGIN_PATH
export GZ_SIM_RESOURCE_PATH=~/ardupilot_gazebo/models:~/ardupilot_gazebo/worlds:$GZ_SIM_RESOURCE_PATH
```
## Troubleshooting
### "No JSON sensor message"
Start Gazebo (Terminal 1) before the controller.
### "No JSON sensor message" or "No heartbeat"
### Drone doesn't respond
Check mode is GUIDED in MAVProxy.
**Cause:** Gazebo isn't running or ArduPilot plugin isn't loaded.
### Simulation laggy
Check GPU: `glxinfo | grep "OpenGL renderer"`
**Fix:**
1. Start Gazebo first (Terminal 1)
2. Wait for world to fully load
3. Then start controller (Terminal 2)
### "sim_vehicle.py not found"
**Cause:** ArduPilot tools not in PATH.
**Fix:**
```bash
source ~/.ardupilot_env
# or
export PATH=$PATH:~/ardupilot/Tools/autotest
```
### "empy not found" during waf build
**Cause:** Wrong Python environment.
**Fix:**
```bash
source ~/venv-ardupilot/bin/activate
pip install empy==3.3.4
cd ~/ardupilot
./waf configure --board sitl
./waf copter
```
### Drone doesn't respond to commands
**Possible causes:**
1. Not in GUIDED mode - check MAVProxy: `mode`
2. Not armed - run: `arm throttle force`
3. Pre-arm checks failing - run: `param set ARMING_CHECK 0`
### Drone immediately crashes in Gazebo
**Cause:** Usually a physics/plugin issue.
**Fix:**
```bash
# Rebuild the ArduPilot Gazebo plugin
cd ~/ardupilot_gazebo/build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j4
```
### Simulation is laggy
**Cause:** Software rendering or GPU not detected.
**Check:**
```bash
glxinfo | grep "OpenGL renderer"
```
Should show your GPU name, not "llvmpipe" or "software".
**Fix for WSL:**
- Install NVIDIA drivers for WSL: https://developer.nvidia.com/cuda/wsl
- Ensure WSLg is enabled (Windows 11)
### MAVProxy console not opening
**Cause:** Missing `--console` flag or display issues.
**Fix:**
```bash
# Run directly
sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON --console --map
# If display errors:
export DISPLAY=:0 # Linux/WSL with X server
```
## Advanced: Custom Takeoff
To customize the takeoff behavior, edit `scripts/run_ardupilot.py`:
```python
# Change altitude
TAKEOFF_ALTITUDE = 15 # meters
# Change timeout
CONNECTION_TIMEOUT = 60 # seconds
```
## Logs
ArduPilot logs are saved to:
```
~/ardupilot/logs/
~/ardupilot/build/sitl/logs/
```
View with:
```bash
mavlogdump.py --types GPS,ATT ~/ardupilot/logs/LASTLOG.BIN
```

View File

@@ -1,6 +1,6 @@
# Installation
## Quick Install
## Quick Install (Ubuntu/WSL)
```bash
./setup/install_ubuntu.sh
@@ -13,11 +13,101 @@ source ~/.bashrc
| Component | Location |
|-----------|----------|
| ArduPilot SITL | `~/ardupilot` |
| ArduPilot venv | `~/venv-ardupilot` |
| ardupilot_gazebo | `~/ardupilot_gazebo` |
| Gazebo Harmonic | System |
| ROS 2 | System |
| MAVProxy | `~/.local/bin` |
## Platform-Specific Installation
### Ubuntu (Native)
```bash
./setup/install_ubuntu.sh --with-ardupilot
```
### Windows (via WSL2)
WSL2 (Windows Subsystem for Linux) is the recommended way to run this simulation on Windows.
#### Step 1: Install WSL2
Open PowerShell as Administrator:
```powershell
wsl --install -d Ubuntu-24.04
```
Restart your computer when prompted.
#### Step 2: Configure WSL2 for GUI Apps
WSL2 on Windows 11 has built-in GUI support (WSLg). For Windows 10, you may need an X server:
```powershell
# Windows 11 - WSLg is automatic, no extra setup needed
# Windows 10 - Install VcXsrv or X410 from Microsoft Store
```
#### Step 3: Install in WSL
Open Ubuntu from Start menu:
```bash
# Clone the project (or copy from Windows)
git clone https://github.com/your-repo/RDC_Simulation.git
cd RDC_Simulation
# Run installation
./setup/install_ubuntu.sh
./setup/install_ardupilot.sh
source ~/.bashrc
```
#### Step 4: GPU Acceleration in WSL
For best performance with Gazebo:
```bash
# Check GPU availability
glxinfo | grep "OpenGL renderer"
# Should show your GPU, not "llvmpipe"
# If using NVIDIA, install NVIDIA GPU driver for WSL:
# https://developer.nvidia.com/cuda/wsl
```
#### WSL Tips
- **Access Windows files:** `/mnt/c/Users/YourName/`
- **Open file explorer:** `explorer.exe .`
- **Copy to clipboard:** `cat file | clip.exe`
- **Memory limit:** Create `%UserProfile%\.wslconfig`:
```ini
[wsl2]
memory=8GB
processors=4
```
### macOS
Gazebo is not officially supported on macOS. Use standalone mode:
```bash
./setup/install_macos.sh
python standalone_simulation.py
```
For full simulation, use a Linux VM (UTM for Apple Silicon) or Docker.
### Arch Linux
```bash
./setup/install_arch.sh
```
ROS 2 and Gazebo are available via AUR - see script output for details.
## Dependencies
```bash
@@ -34,29 +124,107 @@ pip install -r requirements.txt
## Verify Installation
```bash
# Source the environment
source activate.sh
# Check ArduPilot tools
sim_vehicle.py --help
which mavproxy.py
# Check Gazebo
gz sim --help
```
## Environment Setup
After installation, always source the environment before running:
```bash
source activate.sh
# or
source ~/.bashrc # if ArduPilot was installed
```
The activation script sets up:
- ROS 2 environment
- ArduPilot Python venv (with empy, pymavlink, etc.)
- Gazebo resource paths
- ArduPilot tools path
## Troubleshooting
### sim_vehicle.py not found
### "empy not found" or waf configure fails
The ArduPilot venv isn't activated. Run:
```bash
source ~/venv-ardupilot/bin/activate
pip install empy==3.3.4
```
### sim_vehicle.py not found
```bash
source ~/.ardupilot_env
# or
export PATH=$PATH:~/ardupilot/Tools/autotest
```
### mavproxy.py not found
```bash
export PATH=$PATH:~/.local/bin
```
### pexpect error
```bash
pip install pexpect
```
### Gazebo slow
### Gazebo slow / Software rendering
```bash
glxinfo | grep "OpenGL renderer"
```
Should show GPU, not "llvmpipe".
Should show your GPU, not "llvmpipe". Install proper GPU drivers:
- **NVIDIA:** `sudo apt install nvidia-driver-XXX`
- **AMD:** `sudo apt install mesa-vulkan-drivers`
- **Intel:** Usually works out of box
- **WSL:** Install NVIDIA WSL driver from nvidia.com
### Wrong Python environment
If you see errors about missing packages that should be installed:
```bash
# Check which Python is being used
which python3
# Should be: ~/venv-ardupilot/bin/python3
# If not, activate the correct venv:
source ~/venv-ardupilot/bin/activate
```
### WSL: Display not working
```bash
# Check DISPLAY variable
echo $DISPLAY
# For WSLg (Windows 11), should be auto-set
# For Windows 10 with X server:
export DISPLAY=:0
```
### WSL: Out of memory
Create `%UserProfile%\.wslconfig`:
```ini
[wsl2]
memory=8GB
swap=4GB
```
Then restart WSL: `wsl --shutdown`