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

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