Ardupilot Install Script Fix 2

This commit is contained in:
2026-01-04 00:49:28 +00:00
parent 23c619c4dd
commit 40286fa90c
4 changed files with 170 additions and 260 deletions

View File

@@ -1,17 +1,17 @@
# Drone Landing Simulation (GPS-Denied)
A GPS-denied drone landing simulation with multiple backends. Land a drone on a moving platform using only relative sensors (IMU, altimeter, camera).
Land a drone on a moving platform using only relative sensors (IMU, altimeter, camera).
## Quick Start
### Standalone Mode (No ROS 2 - Any Platform)
### Standalone (1 Terminal - Any Platform)
```bash
source activate.sh
python standalone_simulation.py --pattern circular --speed 0.3
python standalone_simulation.py --pattern circular
```
### Gazebo + ROS 2 (Linux/WSL2)
### Gazebo + ROS 2 (2 Terminals)
**Terminal 1:**
```bash
@@ -22,86 +22,64 @@ ros2 launch gazebo/launch/drone_landing.launch.py
```bash
source activate.sh
python run_gazebo.py --pattern circular
python camera_viewer.py # Optional: view camera feed
```
### ArduPilot SITL (Realistic Flight Controller)
### ArduPilot SITL (2 Terminals)
**Terminal 1:**
```bash
source ~/ardu_ws/install/setup.bash
ros2 launch ardupilot_gz_bringup iris_runway.launch.py
gz sim -v4 -r ~/ardupilot_gazebo/worlds/iris_runway.sdf
```
**Terminal 2:**
```bash
mavproxy.py --console --map --master=:14550
sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON --console
```
## Installation
```bash
# Ubuntu/Debian (includes ROS 2 + Gazebo)
# Ubuntu/Debian
./setup/install_ubuntu.sh
# With ArduPilot SITL
# ArduPilot SITL (optional)
./setup/install_ardupilot.sh
# Activate environment
source activate.sh
```
| Platform | Install Script |
|----------|---------------|
| Ubuntu/Debian | `./setup/install_ubuntu.sh` |
| ArduPilot SITL | `./setup/install_ardupilot.sh` |
| Arch Linux | `./setup/install_arch.sh` |
| macOS | `./setup/install_macos.sh` |
| Windows | `.\setup\install_windows.ps1` |
## Files
| File | Description |
|------|-------------|
| `standalone_simulation.py` | **All-in-one** (no ROS 2) |
| `standalone_simulation.py` | All-in-one simulation |
| `run_gazebo.py` | Gazebo controllers |
| `run_ardupilot.py` | ArduPilot launcher |
| `camera_viewer.py` | Drone camera window |
| `drone_controller.py` | **Your landing algorithm** |
| `camera_viewer.py` | Drone camera window |
| `config.py` | Configuration |
## Sensors Available
## Sensors
| Sensor | Data |
|--------|------|
| IMU | Orientation (roll, pitch, yaw), angular velocity |
| IMU | Orientation, angular velocity |
| Altimeter | Altitude, vertical velocity |
| Velocity | Estimated velocity (x, y, z) |
| Camera | Downward-facing image |
| Landing Pad | Relative position when visible |
| Camera | 320x240 downward image |
| Landing Pad | Relative position (when visible) |
## Configuration
Edit `config.py` to customize:
- Drone/rover positions
- Controller gains (Kp, Kd)
- Camera settings
- Landing thresholds
## Command Line Options
## Options
```bash
# Movement patterns
--pattern, -p stationary, linear, circular, square, random
--speed, -s Speed in m/s (default: 0.5)
--amplitude, -a Amplitude in meters (default: 2.0)
```
## Documentation
| Document | Description |
|----------|-------------|
| [Installation](docs/installation.md) | Full setup guide |
| [Installation](docs/installation.md) | Setup guide |
| [Architecture](docs/architecture.md) | System overview |
| [ArduPilot](docs/ardupilot.md) | ArduPilot SITL guide |
| [Gazebo](docs/gazebo.md) | Gazebo guide |
| [ArduPilot](docs/ardupilot.md) | ArduPilot SITL |
| [Drone Guide](docs/drone_guide.md) | Algorithm guide |

View File

@@ -2,9 +2,7 @@
## Operation Modes
### 1. Standalone (Any Platform)
Single process, no ROS 2 required:
### 1. Standalone (Any Platform, 1 Terminal)
```bash
python standalone_simulation.py --pattern circular
@@ -13,11 +11,7 @@ python standalone_simulation.py --pattern circular
```
┌────────────────────────────────────────┐
│ standalone_simulation.py │
┌──────────────────────────────────┐
│ │ PyBullet Physics + Camera │ │
│ │ Built-in Controller │ │
│ │ Rover Movement │ │
│ └──────────────────────────────────┘ │
PyBullet Physics + Camera + Controllers
└────────────────────────────────────────┘
```
@@ -41,54 +35,55 @@ Terminal 1 Terminal 2
└───────────────────┘ └───────────────────┘
```
### 3. ArduPilot SITL (2 Terminals)
### 3. ArduPilot SITL + Gazebo (2 Terminals)
**Terminal 1:**
```bash
ros2 launch ardupilot_gz_bringup iris_runway.launch.py
gz sim -v4 -r ~/ardupilot_gazebo/worlds/iris_runway.sdf
```
**Terminal 2:**
```bash
mavproxy.py --console --map --master=:14550
sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON --console
```
```
┌─────────────────────────────────────────────┐
│ Single Launch Command │
(Starts SITL + Gazebo + RViz)
├─────────────────────────────────────────────┤
│ ArduPilot SITL ◄──► Gazebo ◄──► ROS 2 │
│ ▲ │
│ │ /ap/* topics │
│ ▼ │
│ MAVProxy (GCS) │
└─────────────────────────────────────────────┘
Terminal 1 Terminal 2
┌───────────────────┐ ┌───────────────────┐
│ Gazebo + │◄──────►│ ArduPilot SITL
│ ArduPilot Plugin │ JSON │ + MAVProxy │
└───────────────────┘ UDP └───────────────────┘
```
**Key features:**
- Full ArduPilot flight controller
- EKF, stabilization, failsafes
- MAVLink protocol
- Compatible with QGroundControl, Mission Planner
## Key Components
| Component | Description |
|-----------|-------------|
| `standalone_simulation.py` | All-in-one PyBullet simulation |
| `run_gazebo.py` | Gazebo bridge + controllers |
| `drone_controller.py` | Your landing algorithm |
| `gazebo_bridge.py` | Gazebo ↔ ROS bridge |
| `mavlink_bridge.py` | MAVLink commands |
| `camera_viewer.py` | Camera display |
| `camera_viewer.py` | Camera display window |
## ROS 2 Topics
## ROS 2 Topics (Gazebo Mode)
| Topic | Direction | Description |
|-------|-----------|-------------|
| `/drone/telemetry` | ← | Sensor data (JSON) |
| `/cmd_vel` | → | Velocity commands |
| `/drone/camera` | ← | Camera images |
| `/rover/telemetry` | ← | Landing pad position |
## ArduPilot Topics
## Sensors
| Topic | Type |
|-------|------|
| `/ap/pose/filtered` | Position |
| `/ap/twist/filtered` | Velocity |
| `/ap/imu/filtered` | IMU |
| `/ap/battery` | Battery |
| Sensor | Data |
|--------|------|
| IMU | orientation, angular_velocity |
| Altimeter | altitude, vertical_velocity |
| Velocity | x, y, z (m/s) |
| Camera | 320x240 image |
| Landing Pad | relative_x, relative_y (when visible) |

View File

@@ -2,17 +2,16 @@
Run the simulation with a realistic ArduPilot flight controller.
## Quick Start
## Quick Start (2 Terminals)
**Terminal 1 - Simulation:**
**Terminal 1 - Gazebo:**
```bash
source ~/ardu_ws/install/setup.bash
ros2 launch ardupilot_gz_bringup iris_runway.launch.py
gz sim -v4 -r ~/ardupilot_gazebo/worlds/iris_runway.sdf
```
**Terminal 2 - Control:**
**Terminal 2 - SITL + MAVProxy:**
```bash
mavproxy.py --console --map --master=:14550
sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON --console
```
## Installation
@@ -23,79 +22,81 @@ source ~/.bashrc
```
This installs:
- ArduPilot SITL with DDS
- Gazebo with ardupilot_gz
- ArduPilot SITL
- Gazebo Harmonic
- ardupilot_gazebo plugin
- MAVProxy
## MAVProxy Commands
Once `sim_vehicle.py` is running:
```bash
# Set mode
# Set GUIDED mode
mode guided
# Arm
arm throttle
# Takeoff
# Takeoff to 5m
takeoff 5
# Land
mode land
# Disarm
disarm
```
## ROS 2 Topics
ArduPilot publishes native ROS 2 topics:
```bash
# List topics
ros2 topic list
# View position
ros2 topic echo /ap/geopose/filtered
# View battery
ros2 topic echo /ap/battery
```
| Topic | Type |
|-------|------|
| `/ap/pose/filtered` | PoseStamped |
| `/ap/twist/filtered` | TwistStamped |
| `/ap/imu/filtered` | Imu |
| `/ap/battery` | BatteryState |
## Available Worlds
```bash
# Iris on runway
ros2 launch ardupilot_gz_bringup iris_runway.launch.py
gz sim -v4 -r ~/ardupilot_gazebo/worlds/iris_runway.sdf
# Iris in maze
ros2 launch ardupilot_gz_bringup iris_maze.launch.py
# Rover
ros2 launch ardupilot_gz_bringup wildthumper_playpen.launch.py
# Zephyr plane
gz sim -v4 -r ~/ardupilot_gazebo/worlds/zephyr_runway.sdf
```
## Using the Launcher
## Standalone SITL (No Gazebo)
```bash
python run_ardupilot.py --world runway
python run_ardupilot.py --world maze
python run_ardupilot.py --vehicle rover
sim_vehicle.py -v ArduCopter --console --map
```
This opens a 2D map view for testing without Gazebo.
## How It Works
```
Gazebo ArduPilot SITL
┌─────────────────┐ ┌─────────────────┐
│ iris_runway.sdf │◄────►│ sim_vehicle.py │
│ + ArduPilot │ JSON │ + MAVProxy │
│ Plugin │ UDP │ │
└─────────────────┘ └─────────────────┘
▼ MAVLink
Your Controller
```
The ArduPilot Gazebo plugin communicates with SITL via JSON over UDP.
## Troubleshooting
**No ROS 2 topics:**
**sim_vehicle.py not found:**
```bash
# Check DDS is enabled
param set DDS_ENABLE 1
export PATH=$PATH:~/ardupilot/Tools/autotest
```
**Plugin not loading:**
```bash
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
```
**Can't arm:**
```bash
# Disable pre-arm checks (simulation only)
# In MAVProxy, disable pre-arm checks
param set ARMING_CHECK 0
```

View File

@@ -1,22 +1,17 @@
#!/bin/bash
# =============================================================================
# ArduPilot ROS 2 + Gazebo Installation Script
# ArduPilot SITL + Gazebo Installation Script (MAVLink Mode)
# =============================================================================
# Installs the official ArduPilot ROS 2 packages with DDS and Gazebo support.
# Installs ArduPilot SITL with the ardupilot_gazebo plugin.
# This uses MAVLink instead of DDS - simpler and more reliable.
#
# Usage: ./install_ardupilot.sh
#
# This installs:
# 1. Micro-XRCE-DDS-Gen (required for DDS)
# 2. ArduPilot SITL with DDS support
# 3. ardupilot_gz - ArduPilot Gazebo integration
# 4. MAVProxy ground control station
# =============================================================================
set -e
echo "=============================================="
echo " ArduPilot ROS 2 + Gazebo Installation"
echo " ArduPilot SITL + Gazebo Installation"
echo "=============================================="
echo ""
@@ -25,175 +20,111 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
# Directories
ARDUPILOT_WS="$HOME/ardu_ws"
ARDUPILOT_HOME="$HOME/ardupilot"
ARDUPILOT_GZ="$HOME/ardupilot_gazebo"
# Check for ROS 2
if [ ! -f "/opt/ros/humble/setup.bash" ] && [ ! -f "/opt/ros/jazzy/setup.bash" ]; then
echo "[ERROR] ROS 2 not found!"
echo "Install with: ./setup/install_ubuntu.sh"
exit 1
fi
# Source ROS 2
if [ -f "/opt/ros/humble/setup.bash" ]; then
source /opt/ros/humble/setup.bash
ROS_DISTRO="humble"
elif [ -f "/opt/ros/jazzy/setup.bash" ]; then
source /opt/ros/jazzy/setup.bash
ROS_DISTRO="jazzy"
else
echo "[WARN] ROS 2 not found, will install in standalone mode"
ROS_DISTRO=""
fi
GZ_VERSION="harmonic"
echo "[INFO] ROS 2: $ROS_DISTRO"
echo "[INFO] Gazebo: $GZ_VERSION"
echo "[INFO] Workspace: $ARDUPILOT_WS"
echo "[INFO] ROS 2: ${ROS_DISTRO:-not installed}"
echo ""
# -----------------------------------------------------------------------------
# Step 1: System Dependencies
# -----------------------------------------------------------------------------
echo "[STEP 1/7] Installing system dependencies..."
echo "[STEP 1/5] Installing system dependencies..."
sudo apt-get update
sudo apt-get install -y \
git cmake build-essential \
python3 python3-pip python3-dev python3-venv \
python3-vcstool python3-rosdep python3-colcon-common-extensions \
wget curl default-jre gradle
python3 python3-pip python3-dev \
wget curl
echo "[OK] System dependencies"
# -----------------------------------------------------------------------------
# Step 2: Install Micro-XRCE-DDS-Gen (required for DDS)
# Step 2: Clone and Setup ArduPilot
# -----------------------------------------------------------------------------
echo ""
echo "[STEP 2/7] Installing Micro-XRCE-DDS-Gen..."
echo "[STEP 2/5] Setting up ArduPilot SITL..."
XRCEDDSGEN_DIR="$HOME/Micro-XRCE-DDS-Gen"
if ! command -v microxrceddsgen &> /dev/null; then
if [ ! -d "$XRCEDDSGEN_DIR" ]; then
git clone --recurse-submodules https://github.com/eProsima/Micro-XRCE-DDS-Gen.git "$XRCEDDSGEN_DIR"
fi
cd "$XRCEDDSGEN_DIR"
./gradlew assemble
# Add to PATH
if ! grep -q "Micro-XRCE-DDS-Gen" ~/.bashrc; then
echo "" >> ~/.bashrc
echo "# Micro-XRCE-DDS-Gen" >> ~/.bashrc
echo "export PATH=\$PATH:$XRCEDDSGEN_DIR/scripts" >> ~/.bashrc
fi
export PATH=$PATH:$XRCEDDSGEN_DIR/scripts
echo "[OK] Micro-XRCE-DDS-Gen installed"
else
echo "[OK] Micro-XRCE-DDS-Gen already installed"
if [ ! -d "$ARDUPILOT_HOME" ]; then
git clone --recurse-submodules https://github.com/ArduPilot/ardupilot.git "$ARDUPILOT_HOME"
fi
cd "$ARDUPILOT_HOME"
# Install ArduPilot prerequisites
Tools/environment_install/install-prereqs-ubuntu.sh -y
. ~/.profile || true
# Build ArduCopter SITL (without DDS to avoid complexity)
./waf configure --board sitl
./waf copter
echo "[OK] ArduPilot SITL built"
# -----------------------------------------------------------------------------
# Step 3: Install Gazebo Harmonic
# -----------------------------------------------------------------------------
echo ""
echo "[STEP 3/7] Installing Gazebo Harmonic..."
echo "[STEP 3/5] Installing Gazebo..."
# Add Gazebo repo
sudo wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg 2>/dev/null
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null
sudo apt-get update
sudo apt-get install -y gz-harmonic || echo "[WARN] Could not install gz-harmonic"
echo "[OK] Gazebo"
# -----------------------------------------------------------------------------
# Step 4: Create ArduPilot Workspace
# -----------------------------------------------------------------------------
echo ""
echo "[STEP 4/7] Setting up ArduPilot workspace..."
mkdir -p "$ARDUPILOT_WS/src"
cd "$ARDUPILOT_WS"
# Import ArduPilot repos
vcs import --recursive src < <(cat << 'EOF'
repositories:
ardupilot:
type: git
url: https://github.com/ArduPilot/ardupilot.git
version: master
ardupilot_gz:
type: git
url: https://github.com/ArduPilot/ardupilot_gz.git
version: main
EOF
) || true
# Import Gazebo packages
vcs import --input https://raw.githubusercontent.com/ArduPilot/ardupilot_gz/main/ros2_gz.repos --recursive src 2>/dev/null || true
echo "[OK] Repositories imported"
# -----------------------------------------------------------------------------
# Step 5: Install ArduPilot Prerequisites
# -----------------------------------------------------------------------------
echo ""
echo "[STEP 5/7] Installing ArduPilot prerequisites..."
cd "$ARDUPILOT_WS/src/ardupilot"
Tools/environment_install/install-prereqs-ubuntu.sh -y
. ~/.profile || true
echo "[OK] ArduPilot prerequisites"
# -----------------------------------------------------------------------------
# Step 6: Configure rosdep and Build
# -----------------------------------------------------------------------------
echo ""
echo "[STEP 6/7] Building packages..."
# Configure rosdep
if [ ! -f /etc/ros/rosdep/sources.list.d/20-default.list ]; then
sudo rosdep init || true
fi
rosdep update
# Add Gazebo Harmonic sources
sudo wget https://raw.githubusercontent.com/osrf/osrf-rosdep/master/gz/00-gazebo.list \
-O /etc/ros/rosdep/sources.list.d/00-gazebo.list 2>/dev/null || true
rosdep update || true
# Install dependencies
cd "$ARDUPILOT_WS"
rosdep install --from-paths src --ignore-src -y || true
# Build
source /opt/ros/$ROS_DISTRO/setup.bash
export GZ_VERSION=$GZ_VERSION
colcon build --packages-up-to ardupilot_gz_bringup --symlink-install --allow-overriding ros_gz_bridge ros_gz_sim sdformat_urdf || {
echo "[WARN] Full build failed, trying ardupilot_sitl only..."
colcon build --packages-up-to ardupilot_sitl --symlink-install
# Install Gazebo
sudo apt-get install -y gz-harmonic || sudo apt-get install -y gz-garden || {
echo "[WARN] Could not install Gazebo Harmonic/Garden"
}
echo "[OK] Build complete"
echo "[OK] Gazebo installed"
# -----------------------------------------------------------------------------
# Step 7: Configure Environment
# Step 4: Build ArduPilot Gazebo Plugin
# -----------------------------------------------------------------------------
echo ""
echo "[STEP 7/7] Configuring environment..."
echo "[STEP 4/5] Building ArduPilot Gazebo plugin..."
BASHRC_MARKER="# === ArduPilot ROS 2 ==="
if [ ! -d "$ARDUPILOT_GZ" ]; then
git clone https://github.com/ArduPilot/ardupilot_gazebo.git "$ARDUPILOT_GZ"
fi
cd "$ARDUPILOT_GZ"
mkdir -p build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
echo "[OK] ArduPilot Gazebo plugin built"
# -----------------------------------------------------------------------------
# Step 5: Configure Environment
# -----------------------------------------------------------------------------
echo ""
echo "[STEP 5/5] Configuring environment..."
BASHRC_MARKER="# === ArduPilot SITL ==="
if ! grep -q "$BASHRC_MARKER" ~/.bashrc; then
cat >> ~/.bashrc << EOF
$BASHRC_MARKER
export GZ_VERSION=$GZ_VERSION
export PATH=\$PATH:$ARDUPILOT_WS/src/ardupilot/Tools/autotest
export ARDUPILOT_HOME=$ARDUPILOT_HOME
export PATH=\$PATH:$ARDUPILOT_HOME/Tools/autotest
export PATH=\$PATH:\$HOME/.local/bin
source /opt/ros/$ROS_DISTRO/setup.bash
[ -f $ARDUPILOT_WS/install/setup.bash ] && source $ARDUPILOT_WS/install/setup.bash
export GZ_SIM_SYSTEM_PLUGIN_PATH=$ARDUPILOT_GZ/build:\$GZ_SIM_SYSTEM_PLUGIN_PATH
export GZ_SIM_RESOURCE_PATH=$ARDUPILOT_GZ/models:$ARDUPILOT_GZ/worlds:\$GZ_SIM_RESOURCE_PATH
EOF
echo "[OK] Environment configured"
else
@@ -201,20 +132,23 @@ else
fi
# Install MAVProxy
pip3 install --user pymavlink mavproxy || true
pip3 install --user pymavlink mavproxy
# Verify
# -----------------------------------------------------------------------------
# Verification
# -----------------------------------------------------------------------------
echo ""
echo "=============================================="
echo " Verifying Installation"
echo "=============================================="
source "$ARDUPILOT_WS/install/setup.bash" 2>/dev/null || true
source ~/.bashrc 2>/dev/null || true
export PATH=$PATH:$ARDUPILOT_HOME/Tools/autotest:$HOME/.local/bin
ros2 pkg list 2>/dev/null | grep -q "ardupilot_sitl" && echo "[OK] ardupilot_sitl" || echo "[WARN] ardupilot_sitl not found"
ros2 pkg list 2>/dev/null | grep -q "ardupilot_gz_bringup" && echo "[OK] ardupilot_gz_bringup" || echo "[WARN] ardupilot_gz_bringup not found"
command -v microxrceddsgen &> /dev/null && echo "[OK] microxrceddsgen" || echo "[WARN] microxrceddsgen not in PATH"
command -v mavproxy.py &> /dev/null && echo "[OK] MAVProxy" || echo "[WARN] MAVProxy not in PATH (add ~/.local/bin to PATH)"
command -v sim_vehicle.py &> /dev/null && echo "[OK] sim_vehicle.py" || echo "[WARN] sim_vehicle.py not found"
command -v gz &> /dev/null && echo "[OK] Gazebo (gz)" || echo "[WARN] Gazebo not found"
command -v mavproxy.py &> /dev/null && echo "[OK] MAVProxy" || echo "[WARN] MAVProxy not in PATH"
[ -f "$ARDUPILOT_GZ/build/libArduPilotPlugin.so" ] && echo "[OK] ArduPilot Gazebo plugin" || echo "[WARN] Plugin not built"
echo ""
echo "=============================================="
@@ -225,10 +159,12 @@ echo "Run: source ~/.bashrc"
echo ""
echo "Quick Start (2 terminals):"
echo ""
echo "Terminal 1:"
echo " source ~/ardu_ws/install/setup.bash"
echo " ros2 launch ardupilot_gz_bringup iris_runway.launch.py"
echo "Terminal 1 - Start Gazebo:"
echo " gz sim -v4 -r $ARDUPILOT_GZ/worlds/iris_runway.sdf"
echo ""
echo "Terminal 2:"
echo " mavproxy.py --console --map --master=:14550"
echo "Terminal 2 - Start SITL + MAVProxy:"
echo " sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON --console"
echo ""
echo "Or use sim_vehicle.py standalone (no Gazebo):"
echo " sim_vehicle.py -v ArduCopter --console --map"
echo ""