Ardupilot Install Script Fix

This commit is contained in:
2026-01-04 00:42:40 +00:00
parent 6804180e21
commit 23c619c4dd
3 changed files with 207 additions and 320 deletions

View File

@@ -56,17 +56,21 @@ source ~/.bashrc
``` ```
**Installs:** **Installs:**
- Micro-XRCE-DDS-Gen (required for DDS)
- ArduPilot SITL - ArduPilot SITL
- ardupilot_gz (Gazebo integration) - ardupilot_gz (Gazebo integration)
- MAVProxy - MAVProxy (`~/.local/bin/mavproxy.py`)
**Run:** **Run (2 terminals):**
Terminal 1:
```bash ```bash
# Terminal 1
source ~/ardu_ws/install/setup.bash source ~/ardu_ws/install/setup.bash
ros2 launch ardupilot_gz_bringup iris_runway.launch.py ros2 launch ardupilot_gz_bringup iris_runway.launch.py
```
# Terminal 2 Terminal 2:
```bash
mavproxy.py --console --map --master=:14550 mavproxy.py --console --map --master=:14550
``` ```
@@ -96,21 +100,16 @@ source activate.sh
python standalone_simulation.py python standalone_simulation.py
``` ```
**Note:** ROS 2 and Gazebo not supported on macOS. Use standalone mode. **Note:** ROS 2 and Gazebo not supported. Use standalone mode.
--- ---
## Manual Install ## Manual Install
```bash ```bash
# Create virtual environment
python3 -m venv venv python3 -m venv venv
source venv/bin/activate source venv/bin/activate
# Install packages
pip install -r requirements.txt pip install -r requirements.txt
# Run
python standalone_simulation.py python standalone_simulation.py
``` ```
@@ -123,3 +122,42 @@ python -c "import pybullet; print('PyBullet OK')"
python -c "import cv2; print('OpenCV OK')" python -c "import cv2; print('OpenCV OK')"
python -c "from pymavlink import mavutil; print('pymavlink OK')" python -c "from pymavlink import mavutil; print('pymavlink OK')"
``` ```
---
## Troubleshooting
### MAVProxy not found
```bash
# Install
pip3 install --user mavproxy
# Add to PATH
echo 'export PATH=$PATH:~/.local/bin' >> ~/.bashrc
source ~/.bashrc
# Verify
which mavproxy.py
```
### microxrceddsgen not found
```bash
# Install (needed for ArduPilot DDS)
git clone --recurse-submodules https://github.com/eProsima/Micro-XRCE-DDS-Gen.git ~/Micro-XRCE-DDS-Gen
cd ~/Micro-XRCE-DDS-Gen
./gradlew assemble
# Add to PATH
echo 'export PATH=$PATH:~/Micro-XRCE-DDS-Gen/scripts' >> ~/.bashrc
source ~/.bashrc
```
### Build errors
```bash
# Rebuild with override flag
cd ~/ardu_ws
colcon build --packages-up-to ardupilot_gz_bringup --allow-overriding ros_gz_bridge ros_gz_sim sdformat_urdf
```

View File

@@ -3,17 +3,12 @@
# ArduPilot ROS 2 + Gazebo Installation Script # ArduPilot ROS 2 + Gazebo Installation Script
# ============================================================================= # =============================================================================
# Installs the official ArduPilot ROS 2 packages with DDS and Gazebo support. # Installs the official ArduPilot ROS 2 packages with DDS and Gazebo support.
# This is the recommended way to run ArduPilot SITL with ROS 2.
# #
# Prerequisites: # Usage: ./install_ardupilot.sh
# - Ubuntu 22.04 (ROS 2 Humble)
# - ROS 2 Humble installed
#
# Usage: ./install_ardupilot.sh [--skip-sitl] [--skip-gazebo]
# #
# This installs: # This installs:
# 1. ArduPilot SITL with DDS support # 1. Micro-XRCE-DDS-Gen (required for DDS)
# 2. ardupilot_ros - ArduPilot ROS 2 packages # 2. ArduPilot SITL with DDS support
# 3. ardupilot_gz - ArduPilot Gazebo integration # 3. ardupilot_gz - ArduPilot Gazebo integration
# 4. MAVProxy ground control station # 4. MAVProxy ground control station
# ============================================================================= # =============================================================================
@@ -25,33 +20,17 @@ echo " ArduPilot ROS 2 + Gazebo Installation"
echo "==============================================" echo "=============================================="
echo "" echo ""
# Parse arguments
SKIP_SITL=false
SKIP_GAZEBO=false
for arg in "$@"; do
case $arg in
--skip-sitl)
SKIP_SITL=true
;;
--skip-gazebo)
SKIP_GAZEBO=true
;;
esac
done
# Get script directory # Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
# Directories # Directories
ARDUPILOT_WS="$HOME/ardu_ws" ARDUPILOT_WS="$HOME/ardu_ws"
ARDUPILOT_DIR="$HOME/ardupilot"
# Check for ROS 2 # Check for ROS 2
if [ ! -f "/opt/ros/humble/setup.bash" ] && [ ! -f "/opt/ros/jazzy/setup.bash" ]; then if [ ! -f "/opt/ros/humble/setup.bash" ] && [ ! -f "/opt/ros/jazzy/setup.bash" ]; then
echo "[ERROR] ROS 2 not found!" echo "[ERROR] ROS 2 not found!"
echo "Please install ROS 2 first:" echo "Install with: ./setup/install_ubuntu.sh"
echo " ./setup/install_ubuntu.sh"
exit 1 exit 1
fi fi
@@ -59,89 +38,85 @@ fi
if [ -f "/opt/ros/humble/setup.bash" ]; then if [ -f "/opt/ros/humble/setup.bash" ]; then
source /opt/ros/humble/setup.bash source /opt/ros/humble/setup.bash
ROS_DISTRO="humble" ROS_DISTRO="humble"
GZ_VERSION="harmonic"
elif [ -f "/opt/ros/jazzy/setup.bash" ]; then elif [ -f "/opt/ros/jazzy/setup.bash" ]; then
source /opt/ros/jazzy/setup.bash source /opt/ros/jazzy/setup.bash
ROS_DISTRO="jazzy" ROS_DISTRO="jazzy"
GZ_VERSION="harmonic"
fi fi
echo "[INFO] ROS 2 Distro: $ROS_DISTRO" GZ_VERSION="harmonic"
echo "[INFO] Gazebo Version: $GZ_VERSION"
echo "[INFO] ROS 2: $ROS_DISTRO"
echo "[INFO] Gazebo: $GZ_VERSION"
echo "[INFO] Workspace: $ARDUPILOT_WS" echo "[INFO] Workspace: $ARDUPILOT_WS"
echo "" echo ""
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Step 1: Install System Dependencies # Step 1: System Dependencies
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
echo "[STEP 1/7] Installing system dependencies..." echo "[STEP 1/7] Installing system dependencies..."
sudo apt-get update sudo apt-get update
sudo apt-get install -y \ sudo apt-get install -y \
git \ git cmake build-essential \
cmake \ python3 python3-pip python3-dev python3-venv \
build-essential \ python3-vcstool python3-rosdep python3-colcon-common-extensions \
python3 \ wget curl default-jre gradle
python3-pip \
python3-dev \
python3-venv \
python3-vcstool \
python3-rosdep \
python3-colcon-common-extensions \
wget \
curl
# Install additional dependencies echo "[OK] System dependencies"
sudo apt-get install -y \
default-jre \
libxml2-dev \
libxslt1-dev \
libtool \
automake \
autoconf \
libexpat1-dev \
ccache || true
echo "[INFO] System dependencies installed"
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Step 2: Install Gazebo Harmonic # Step 2: Install Micro-XRCE-DDS-Gen (required for DDS)
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
if [ "$SKIP_GAZEBO" = false ]; then echo ""
echo "" echo "[STEP 2/7] Installing Micro-XRCE-DDS-Gen..."
echo "[STEP 2/7] Installing Gazebo $GZ_VERSION..."
# Add Gazebo APT sources XRCEDDSGEN_DIR="$HOME/Micro-XRCE-DDS-Gen"
sudo wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg
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
# Install Gazebo if ! command -v microxrceddsgen &> /dev/null; then
sudo apt-get install -y gz-$GZ_VERSION || { if [ ! -d "$XRCEDDSGEN_DIR" ]; then
echo "[WARN] Could not install gz-$GZ_VERSION, trying gz-garden..." git clone --recurse-submodules https://github.com/eProsima/Micro-XRCE-DDS-Gen.git "$XRCEDDSGEN_DIR"
sudo apt-get install -y gz-garden || true fi
}
echo "[INFO] Gazebo installed" 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 else
echo "" echo "[OK] Micro-XRCE-DDS-Gen already installed"
echo "[STEP 2/7] Skipping Gazebo installation (--skip-gazebo)"
fi fi
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Step 3: Create ArduPilot ROS 2 Workspace # Step 3: Install Gazebo Harmonic
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
echo "" echo ""
echo "[STEP 3/7] Setting up ArduPilot ROS 2 workspace..." echo "[STEP 3/7] Installing Gazebo Harmonic..."
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" mkdir -p "$ARDUPILOT_WS/src"
cd "$ARDUPILOT_WS" cd "$ARDUPILOT_WS"
# Import ArduPilot ROS 2 repositories using vcstool # Import ArduPilot repos
echo "[INFO] Importing ArduPilot ROS 2 repositories..." vcs import --recursive src < <(cat << 'EOF'
# Create ros2.repos file for ArduPilot packages
cat > /tmp/ardupilot_ros2.repos << 'EOF'
repositories: repositories:
ardupilot: ardupilot:
type: git type: git
@@ -152,200 +127,108 @@ repositories:
url: https://github.com/ArduPilot/ardupilot_gz.git url: https://github.com/ArduPilot/ardupilot_gz.git
version: main version: main
EOF EOF
) || true
vcs import --recursive src < /tmp/ardupilot_ros2.repos # Import Gazebo packages
vcs import --input https://raw.githubusercontent.com/ArduPilot/ardupilot_gz/main/ros2_gz.repos --recursive src 2>/dev/null || true
# Also import Gazebo-related packages echo "[OK] Repositories imported"
if [ "$SKIP_GAZEBO" = false ]; then
echo "[INFO] Importing Gazebo packages..."
vcs import --input https://raw.githubusercontent.com/ArduPilot/ardupilot_gz/main/ros2_gz.repos --recursive src || true
fi
echo "[INFO] ArduPilot ROS 2 repositories imported"
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Step 4: Install ArduPilot SITL Prerequisites # Step 5: Install ArduPilot Prerequisites
# -----------------------------------------------------------------------------
if [ "$SKIP_SITL" = false ]; then
echo ""
echo "[STEP 4/7] Installing ArduPilot SITL prerequisites..."
cd "$ARDUPILOT_WS/src/ardupilot"
# Run ArduPilot prerequisites installer
Tools/environment_install/install-prereqs-ubuntu.sh -y
# Reload profile
. ~/.profile || true
echo "[INFO] ArduPilot SITL prerequisites installed"
else
echo ""
echo "[STEP 4/7] Skipping SITL prerequisites (--skip-sitl)"
fi
# -----------------------------------------------------------------------------
# Step 5: Configure rosdep for Gazebo
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
echo "" echo ""
echo "[STEP 5/7] Configuring rosdep..." echo "[STEP 5/7] Installing ArduPilot prerequisites..."
# Initialize rosdep if needed 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 if [ ! -f /etc/ros/rosdep/sources.list.d/20-default.list ]; then
sudo rosdep init || true sudo rosdep init || true
fi fi
rosdep update rosdep update
# Add Gazebo sources to rosdep (for non-default ROS 2 Humble + Gazebo Harmonic pairing) # Add Gazebo Harmonic sources
if [ "$ROS_DISTRO" = "humble" ] && [ "$GZ_VERSION" = "harmonic" ]; then sudo wget https://raw.githubusercontent.com/osrf/osrf-rosdep/master/gz/00-gazebo.list \
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
-O /etc/ros/rosdep/sources.list.d/00-gazebo.list || true rosdep update || true
rosdep update || true
fi
# Install ROS dependencies # Install dependencies
cd "$ARDUPILOT_WS" cd "$ARDUPILOT_WS"
rosdep install --from-paths src --ignore-src -y || true rosdep install --from-paths src --ignore-src -y || true
echo "[INFO] rosdep configured" # Build
# -----------------------------------------------------------------------------
# Step 6: Build ArduPilot ROS 2 Packages
# -----------------------------------------------------------------------------
echo ""
echo "[STEP 6/7] Building ArduPilot ROS 2 packages..."
cd "$ARDUPILOT_WS"
source /opt/ros/$ROS_DISTRO/setup.bash source /opt/ros/$ROS_DISTRO/setup.bash
# Set Gazebo version environment variable
export GZ_VERSION=$GZ_VERSION 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 || {
# Build packages echo "[WARN] Full build failed, trying ardupilot_sitl only..."
if [ "$SKIP_GAZEBO" = false ]; then
echo "[INFO] Building with Gazebo support..."
colcon build --packages-up-to ardupilot_gz_bringup --symlink-install || {
echo "[WARN] Full build failed, trying core packages only..."
colcon build --packages-up-to ardupilot_sitl --symlink-install
}
else
echo "[INFO] Building SITL only..."
colcon build --packages-up-to ardupilot_sitl --symlink-install colcon build --packages-up-to ardupilot_sitl --symlink-install
fi }
echo "[INFO] ArduPilot ROS 2 packages built" echo "[OK] Build complete"
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Step 7: Configure Environment Variables # Step 7: Configure Environment
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
echo "" echo ""
echo "[STEP 7/7] Configuring environment variables..." echo "[STEP 7/7] Configuring environment..."
BASHRC_MARKER="# === ArduPilot ROS 2 Configuration ===" BASHRC_MARKER="# === ArduPilot ROS 2 ==="
if ! grep -q "$BASHRC_MARKER" ~/.bashrc; then if ! grep -q "$BASHRC_MARKER" ~/.bashrc; then
echo "" >> ~/.bashrc cat >> ~/.bashrc << EOF
echo "$BASHRC_MARKER" >> ~/.bashrc
echo "" >> ~/.bashrc
# Gazebo version $BASHRC_MARKER
echo "# Gazebo Version" >> ~/.bashrc export GZ_VERSION=$GZ_VERSION
echo "export GZ_VERSION=$GZ_VERSION" >> ~/.bashrc export PATH=\$PATH:$ARDUPILOT_WS/src/ardupilot/Tools/autotest
echo "" >> ~/.bashrc export PATH=\$PATH:\$HOME/.local/bin
source /opt/ros/$ROS_DISTRO/setup.bash
# ArduPilot workspace [ -f $ARDUPILOT_WS/install/setup.bash ] && source $ARDUPILOT_WS/install/setup.bash
echo "# ArduPilot ROS 2 Workspace" >> ~/.bashrc EOF
echo "export ARDUPILOT_WS=$ARDUPILOT_WS" >> ~/.bashrc echo "[OK] Environment configured"
echo "" >> ~/.bashrc
# ArduPilot SITL paths
echo "# ArduPilot SITL" >> ~/.bashrc
echo "export PATH=\$PATH:$ARDUPILOT_WS/src/ardupilot/Tools/autotest" >> ~/.bashrc
echo "" >> ~/.bashrc
# Source ROS 2 and workspace
echo "# Source ROS 2 and ArduPilot workspace" >> ~/.bashrc
echo "source /opt/ros/$ROS_DISTRO/setup.bash" >> ~/.bashrc
echo "if [ -f $ARDUPILOT_WS/install/setup.bash ]; then" >> ~/.bashrc
echo " source $ARDUPILOT_WS/install/setup.bash" >> ~/.bashrc
echo "fi" >> ~/.bashrc
echo "" >> ~/.bashrc
echo "[INFO] Environment variables added to ~/.bashrc"
else else
echo "[INFO] Environment variables already configured in ~/.bashrc" echo "[OK] Environment already configured"
fi fi
# Install pymavlink in venv if it exists # Install MAVProxy
if [ -d "$PROJECT_ROOT/venv" ]; then
echo "[INFO] Installing pymavlink in project venv..."
source "$PROJECT_ROOT/venv/bin/activate"
pip install pymavlink mavproxy || true
deactivate
fi
# Also install pymavlink and mavproxy globally
pip3 install --user pymavlink mavproxy || true pip3 install --user pymavlink mavproxy || true
# ----------------------------------------------------------------------------- # Verify
# Verification
# -----------------------------------------------------------------------------
echo "" echo ""
echo "==============================================" echo "=============================================="
echo " Verifying Installation" echo " Verifying Installation"
echo "==============================================" echo "=============================================="
echo ""
# Source the workspace source "$ARDUPILOT_WS/install/setup.bash" 2>/dev/null || true
source "$ARDUPILOT_WS/install/setup.bash" || true
# Check ROS 2 packages ros2 pkg list 2>/dev/null | grep -q "ardupilot_sitl" && echo "[OK] ardupilot_sitl" || echo "[WARN] ardupilot_sitl not found"
ros2 pkg list | grep -q "ardupilot_sitl" && echo "[OK] ardupilot_sitl package" || 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)"
if [ "$SKIP_GAZEBO" = false ]; then
ros2 pkg list | grep -q "ardupilot_gz_bringup" && echo "[OK] ardupilot_gz_bringup package" || echo "[WARN] ardupilot_gz_bringup not found"
fi
# Check Gazebo
if command -v gz &> /dev/null; then
echo "[OK] Gazebo (gz command)"
elif command -v ign &> /dev/null; then
echo "[OK] Gazebo Fortress (ign command)"
else
echo "[WARN] Gazebo command not found"
fi
# Check MAVProxy
python3 -c "from pymavlink import mavutil" &> /dev/null && echo "[OK] pymavlink" || echo "[WARN] pymavlink not found"
# -----------------------------------------------------------------------------
# Complete
# -----------------------------------------------------------------------------
echo "" echo ""
echo "==============================================" echo "=============================================="
echo " ArduPilot ROS 2 Installation Complete!" echo " Installation Complete!"
echo "==============================================" echo "=============================================="
echo "" echo ""
echo "IMPORTANT: Run the following to apply changes:" echo "Run: source ~/.bashrc"
echo " source ~/.bashrc"
echo "" echo ""
echo "Quick Start - Run SITL with ROS 2:" echo "Quick Start (2 terminals):"
echo " source ~/ardu_ws/install/setup.bash"
echo " ros2 launch ardupilot_sitl sitl_dds_udp.launch.py \\"
echo " transport:=udp4 \\"
echo " synthetic_clock:=True \\"
echo " model:=quad"
echo "" echo ""
echo "Quick Start - Run with Gazebo:" echo "Terminal 1:"
echo " source ~/ardu_ws/install/setup.bash" echo " source ~/ardu_ws/install/setup.bash"
echo " ros2 launch ardupilot_gz_bringup iris_runway.launch.py" echo " ros2 launch ardupilot_gz_bringup iris_runway.launch.py"
echo "" echo ""
echo "MAVProxy (in another terminal):" echo "Terminal 2:"
echo " mavproxy.py --console --map --master=:14550" echo " mavproxy.py --console --map --master=:14550"
echo "" echo ""
echo "ROS 2 Topics:"
echo " ros2 topic list"
echo " ros2 topic echo /ap/geopose/filtered"
echo ""
echo "For more info, see: docs/ardupilot.md"
echo ""

View File

@@ -3,7 +3,6 @@
# Drone Simulation - Ubuntu/Debian Installation Script # Drone Simulation - Ubuntu/Debian Installation Script
# ============================================================================= # =============================================================================
# Installs ROS 2, Gazebo, PyBullet, and all required dependencies # Installs ROS 2, Gazebo, PyBullet, and all required dependencies
# Use --with-ardupilot to also install ArduPilot SITL
# #
# Usage: # Usage:
# ./install_ubuntu.sh # Basic installation # ./install_ubuntu.sh # Basic installation
@@ -35,11 +34,19 @@ else
UBUNTU_VERSION="22.04" UBUNTU_VERSION="22.04"
fi fi
# Check for ArduPilot option
INSTALL_ARDUPILOT=false
for arg in "$@"; do
if [ "$arg" = "--with-ardupilot" ]; then
INSTALL_ARDUPILOT=true
fi
done
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Step 1: System Dependencies # Step 1: System Dependencies
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
echo "" echo ""
echo "[STEP 1/8] Installing system dependencies..." echo "[STEP 1/7] Installing system dependencies..."
sudo apt-get update sudo apt-get update
sudo apt-get install -y \ sudo apt-get install -y \
@@ -52,23 +59,16 @@ sudo apt-get install -y \
python3-venv \ python3-venv \
git \ git \
cmake \ cmake \
build-essential build-essential \
wget
echo "[INFO] System dependencies installed" echo "[INFO] System dependencies installed"
# Check for ArduPilot option
INSTALL_ARDUPILOT=false
for arg in "$@"; do
if [ "$arg" = "--with-ardupilot" ]; then
INSTALL_ARDUPILOT=true
fi
done
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Step 2: ROS 2 Repository Setup # Step 2: ROS 2 Repository Setup
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
echo "" echo ""
echo "[STEP 2/8] Setting up ROS 2 repository..." echo "[STEP 2/7] Setting up ROS 2 repository..."
# Add ROS 2 GPG key # Add ROS 2 GPG key
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
@@ -92,7 +92,7 @@ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-a
# Step 3: Install ROS 2 # Step 3: Install ROS 2
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
echo "" echo ""
echo "[STEP 3/8] Installing ROS 2 $ROS_DISTRO..." echo "[STEP 3/7] Installing ROS 2 $ROS_DISTRO..."
sudo apt-get update sudo apt-get update
sudo apt-get install -y ros-${ROS_DISTRO}-ros-base ros-${ROS_DISTRO}-geometry-msgs ros-${ROS_DISTRO}-std-msgs ros-${ROS_DISTRO}-nav-msgs ros-${ROS_DISTRO}-sensor-msgs sudo apt-get install -y ros-${ROS_DISTRO}-ros-base ros-${ROS_DISTRO}-geometry-msgs ros-${ROS_DISTRO}-std-msgs ros-${ROS_DISTRO}-nav-msgs ros-${ROS_DISTRO}-sensor-msgs
@@ -100,30 +100,22 @@ sudo apt-get install -y ros-${ROS_DISTRO}-ros-base ros-${ROS_DISTRO}-geometry-ms
echo "[INFO] ROS 2 $ROS_DISTRO installed" echo "[INFO] ROS 2 $ROS_DISTRO installed"
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Step 4: Install Gazebo (optional) # Step 4: Install Gazebo
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
echo "" echo ""
echo "[STEP 4/8] Installing Gazebo..." echo "[STEP 4/7] Installing Gazebo..."
if [ "$ROS_DISTRO" = "jazzy" ]; then
GZ_VERSION="harmonic"
GZ_PKG="gz-harmonic"
else
GZ_VERSION="fortress"
GZ_PKG="gz-fortress"
fi
# Install ros-gz bridge # Install ros-gz bridge
sudo apt-get install -y ros-${ROS_DISTRO}-ros-gz || { sudo apt-get install -y ros-${ROS_DISTRO}-ros-gz || {
echo "[WARN] Could not install ros-gz" echo "[WARN] Could not install ros-gz"
} }
# Install Gazebo itself (provides gz or ign command) # Install Gazebo
sudo apt-get install -y $GZ_PKG || { if [ "$ROS_DISTRO" = "jazzy" ]; then
echo "[WARN] Could not install $GZ_PKG" sudo apt-get install -y gz-harmonic || true
echo "[INFO] Trying ros-ign-gazebo..." else
sudo apt-get install -y ros-${ROS_DISTRO}-ros-ign-gazebo || true sudo apt-get install -y gz-fortress || sudo apt-get install -y ros-${ROS_DISTRO}-ros-ign-gazebo || true
} fi
# Verify installation # Verify installation
if command -v gz &> /dev/null; then if command -v gz &> /dev/null; then
@@ -131,42 +123,35 @@ if command -v gz &> /dev/null; then
elif command -v ign &> /dev/null; then elif command -v ign &> /dev/null; then
echo "[INFO] Gazebo Fortress installed (ign command available)" echo "[INFO] Gazebo Fortress installed (ign command available)"
else else
echo "[WARN] Gazebo command not found - use PyBullet instead" echo "[WARN] Gazebo command not found - use standalone mode"
fi fi
echo "[INFO] Gazebo installation complete"
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Step 5: Create Python Virtual Environment # Step 5: Create Python Virtual Environment
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
echo "" echo ""
echo "[STEP 5/8] Creating Python virtual environment..." echo "[STEP 5/7] Creating Python virtual environment..."
# Remove existing venv if present
if [ -d "$VENV_DIR" ]; then if [ -d "$VENV_DIR" ]; then
rm -rf "$VENV_DIR" rm -rf "$VENV_DIR"
fi fi
# Create virtual environment
python3 -m venv "$VENV_DIR" python3 -m venv "$VENV_DIR"
echo "[INFO] Virtual environment created at: $VENV_DIR" echo "[INFO] Virtual environment created at: $VENV_DIR"
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Step 6: Install Python Dependencies # Step 6: Install Python Dependencies
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
echo "" echo ""
echo "[STEP 6/8] Installing Python dependencies..." echo "[STEP 6/7] Installing Python dependencies..."
source "$VENV_DIR/bin/activate" source "$VENV_DIR/bin/activate"
pip install --upgrade pip pip install --upgrade pip
if [ -f "$PROJECT_ROOT/requirements.txt" ]; then if [ -f "$PROJECT_ROOT/requirements.txt" ]; then
echo "[INFO] Installing from requirements.txt..."
pip install -r "$PROJECT_ROOT/requirements.txt" pip install -r "$PROJECT_ROOT/requirements.txt"
else else
echo "[INFO] Installing packages manually..." pip install pybullet numpy pillow opencv-python pymavlink
pip install pybullet numpy pillow pyinstaller
fi fi
echo "[INFO] Python packages installed" echo "[INFO] Python packages installed"
@@ -175,7 +160,7 @@ echo "[INFO] Python packages installed"
# Step 7: Create Activation Script # Step 7: Create Activation Script
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
echo "" echo ""
echo "[STEP 7/8] Creating activation script..." echo "[STEP 7/7] Creating activation script..."
cat > "$PROJECT_ROOT/activate.sh" << 'EOF' cat > "$PROJECT_ROOT/activate.sh" << 'EOF'
#!/bin/bash #!/bin/bash
@@ -186,77 +171,63 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Source ROS 2 # Source ROS 2
if [ -f "/opt/ros/jazzy/setup.bash" ]; then if [ -f "/opt/ros/jazzy/setup.bash" ]; then
source /opt/ros/jazzy/setup.bash source /opt/ros/jazzy/setup.bash
echo "[OK] ROS 2 jazzy sourced" echo "[OK] ROS 2 jazzy"
elif [ -f "/opt/ros/humble/setup.bash" ]; then elif [ -f "/opt/ros/humble/setup.bash" ]; then
source /opt/ros/humble/setup.bash source /opt/ros/humble/setup.bash
echo "[OK] ROS 2 humble sourced" echo "[OK] ROS 2 humble"
else
echo "[WARN] ROS 2 not found - standalone_simulation.py will work"
fi fi
# Activate Python venv # Activate Python venv
if [ -f "$SCRIPT_DIR/venv/bin/activate" ]; then if [ -f "$SCRIPT_DIR/venv/bin/activate" ]; then
source "$SCRIPT_DIR/venv/bin/activate" source "$SCRIPT_DIR/venv/bin/activate"
echo "[OK] Python venv activated" echo "[OK] Python venv"
fi fi
# Set Gazebo model path # Set Gazebo paths
export GZ_SIM_RESOURCE_PATH="$SCRIPT_DIR/gazebo/models:$GZ_SIM_RESOURCE_PATH" export GZ_SIM_RESOURCE_PATH="$SCRIPT_DIR/gazebo/models:$GZ_SIM_RESOURCE_PATH"
# Set ArduPilot paths if installed # Add ~/.local/bin to PATH (for mavproxy.py)
if [ -d "$HOME/ardupilot" ]; then export PATH="$PATH:$HOME/.local/bin"
export ARDUPILOT_HOME="$HOME/ardupilot"
export PATH="$PATH:$ARDUPILOT_HOME/Tools/autotest"
echo "[OK] ArduPilot SITL available"
fi
# Set ArduPilot Gazebo plugin path if installed # ArduPilot workspace
if [ -d "$HOME/ardupilot_gazebo/build" ]; then if [ -f "$HOME/ardu_ws/install/setup.bash" ]; then
export GZ_SIM_SYSTEM_PLUGIN_PATH="$HOME/ardupilot_gazebo/build:$GZ_SIM_SYSTEM_PLUGIN_PATH" source "$HOME/ardu_ws/install/setup.bash"
export GZ_SIM_RESOURCE_PATH="$HOME/ardupilot_gazebo/models:$HOME/ardupilot_gazebo/worlds:$GZ_SIM_RESOURCE_PATH" echo "[OK] ArduPilot workspace"
echo "[OK] ArduPilot Gazebo plugin available"
fi fi
echo "" echo ""
echo "Environment ready! Run one of:" echo "Ready! Run: python standalone_simulation.py"
echo " python standalone_simulation.py (No ROS 2 required)"
echo " python simulation_host.py (With ROS 2)"
echo " python run_ardupilot.py (With ArduPilot SITL)"
echo ""
EOF EOF
chmod +x "$PROJECT_ROOT/activate.sh" chmod +x "$PROJECT_ROOT/activate.sh"
echo "[INFO] Created: $PROJECT_ROOT/activate.sh" echo "[INFO] Created: $PROJECT_ROOT/activate.sh"
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Step 8: Verification # Verification
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
echo "" echo ""
echo "[STEP 8/8] Verifying installation..." echo "=============================================="
echo " Verifying Installation"
echo "=============================================="
source "$PROJECT_ROOT/activate.sh" source "$PROJECT_ROOT/activate.sh"
echo "" python3 -c "import pybullet; print('[OK] PyBullet')" || echo "[FAIL] PyBullet"
echo "Checking Python packages:" python3 -c "import numpy; print('[OK] NumPy')" || echo "[FAIL] NumPy"
python3 -c "import pybullet; print(' PyBullet: OK')" || echo " PyBullet: FAILED" python3 -c "import cv2; print('[OK] OpenCV')" || echo "[WARN] OpenCV not installed"
python3 -c "import numpy; print(' NumPy: OK')" || echo " NumPy: FAILED" python3 -c "from pymavlink import mavutil; print('[OK] pymavlink')" || echo "[WARN] pymavlink not installed"
python3 -c "from PIL import Image; print(' Pillow: OK')" || echo " Pillow: FAILED"
python3 -c "from pymavlink import mavutil; print(' pymavlink: OK')" || echo " pymavlink: FAILED"
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Step 9: ArduPilot SITL Installation (if requested) # ArduPilot Installation (if requested)
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
if [ "$INSTALL_ARDUPILOT" = true ]; then if [ "$INSTALL_ARDUPILOT" = true ]; then
echo "" echo ""
echo "[STEP 9] Installing ArduPilot SITL..." echo "[INFO] Installing ArduPilot SITL..."
echo "[INFO] Calling dedicated ArduPilot install script..."
# Call the dedicated ArduPilot install script
if [ -f "$SCRIPT_DIR/install_ardupilot.sh" ]; then if [ -f "$SCRIPT_DIR/install_ardupilot.sh" ]; then
bash "$SCRIPT_DIR/install_ardupilot.sh" bash "$SCRIPT_DIR/install_ardupilot.sh"
else else
echo "[ERROR] install_ardupilot.sh not found!" echo "[ERROR] install_ardupilot.sh not found!"
echo "[INFO] Please run: ./setup/install_ardupilot.sh"
fi fi
fi fi
@@ -269,17 +240,12 @@ echo "Quick start:"
echo " source activate.sh" echo " source activate.sh"
echo " python standalone_simulation.py" echo " python standalone_simulation.py"
echo "" echo ""
echo "With ROS 2 + Gazebo:" echo "With Gazebo (2 terminals):"
echo " python simulation_host.py # Terminal 1" echo " Terminal 1: ros2 launch gazebo/launch/drone_landing.launch.py"
echo " python run_bridge.py # Terminal 2" echo " Terminal 2: python run_gazebo.py --pattern circular"
echo ""
echo "With ArduPilot SITL (realistic flight controller):"
echo " ros2 launch gazebo/launch/ardupilot_drone.launch.py # Terminal 1"
echo " sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON # Terminal 2"
echo " python run_ardupilot.py --no-sitl # Terminal 3"
echo "" echo ""
if [ "$INSTALL_ARDUPILOT" != true ]; then if [ "$INSTALL_ARDUPILOT" != true ]; then
echo "To install ArduPilot SITL, run:" echo "For ArduPilot SITL:"
echo " ./setup/install_ubuntu.sh --with-ardupilot" echo " ./setup/install_ardupilot.sh"
echo "" echo ""
fi fi