install script updates 3

This commit is contained in:
2026-01-09 19:57:57 +00:00
parent 33d5731e7c
commit 1bee44bcff
5 changed files with 214 additions and 280 deletions

View File

@@ -1,18 +1,19 @@
#!/bin/bash
# =============================================================================
# Drone Simulation - Ubuntu/Debian Installation Script
# RDC Simulation - Ubuntu/WSL2 Installation Script
# =============================================================================
# Installs ROS 2, Gazebo, PyBullet, and all required dependencies
# Complete installation for GPS-Denied Drone Landing Simulation
# Installs: ROS 2, Gazebo, ArduPilot SITL, and all dependencies
#
# Usage:
# ./install_ubuntu.sh # Basic installation
# ./install_ubuntu.sh --with-ardupilot # Include ArduPilot SITL
# ./setup/install_ubuntu.sh # Full installation (recommended)
# ./setup/install_ubuntu.sh --skip-ardupilot # Skip ArduPilot (basic only)
# =============================================================================
set -e
echo "=============================================="
echo " Drone Simulation - Ubuntu Installation"
echo " RDC Simulation - Ubuntu Installation"
echo "=============================================="
echo ""
@@ -21,6 +22,10 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
VENV_DIR="$PROJECT_ROOT/venv"
# ArduPilot directories
ARDUPILOT_HOME="$HOME/ardupilot"
ARDUPILOT_GZ="$HOME/ardupilot_gazebo"
echo "[INFO] Project root: $PROJECT_ROOT"
echo "[INFO] Virtual environment: $VENV_DIR"
@@ -34,19 +39,27 @@ else
UBUNTU_VERSION="22.04"
fi
# Check for ArduPilot option
INSTALL_ARDUPILOT=false
# Check for skip ArduPilot option (default is to install ArduPilot)
INSTALL_ARDUPILOT=true
for arg in "$@"; do
if [ "$arg" = "--with-ardupilot" ]; then
INSTALL_ARDUPILOT=true
if [ "$arg" = "--skip-ardupilot" ]; then
INSTALL_ARDUPILOT=false
fi
done
# -----------------------------------------------------------------------------
# Step 1: System Dependencies
# -----------------------------------------------------------------------------
if [ "$INSTALL_ARDUPILOT" = true ]; then
TOTAL_STEPS=10
echo "[INFO] Full installation with ArduPilot SITL"
else
TOTAL_STEPS=7
echo "[INFO] Basic installation (no ArduPilot)"
fi
echo ""
echo "[STEP 1/7] Installing system dependencies..."
# =============================================================================
# STEP 1: System Dependencies
# =============================================================================
echo "[STEP 1/$TOTAL_STEPS] Installing system dependencies..."
sudo apt-get update
sudo apt-get install -y \
@@ -57,18 +70,26 @@ sudo apt-get install -y \
python3 \
python3-pip \
python3-venv \
python3-dev \
git \
cmake \
build-essential \
wget
wget \
netcat-openbsd \
libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev \
gstreamer1.0-plugins-bad \
gstreamer1.0-libav \
gstreamer1.0-gl \
libopencv-dev
echo "[INFO] System dependencies installed"
echo "[OK] System dependencies installed"
# -----------------------------------------------------------------------------
# Step 2: ROS 2 Repository Setup
# -----------------------------------------------------------------------------
# =============================================================================
# STEP 2: ROS 2 Installation
# =============================================================================
echo ""
echo "[STEP 2/7] Setting up ROS 2 repository..."
echo "[STEP 2/$TOTAL_STEPS] Installing ROS 2..."
# 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
@@ -88,63 +109,50 @@ echo "[INFO] Using ROS 2 $ROS_DISTRO"
# Add repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
# -----------------------------------------------------------------------------
# Step 3: Install ROS 2
# -----------------------------------------------------------------------------
echo ""
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
echo "[INFO] ROS 2 $ROS_DISTRO installed"
# -----------------------------------------------------------------------------
# Step 4: Install Gazebo
# -----------------------------------------------------------------------------
echo ""
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
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
echo "[OK] ROS 2 $ROS_DISTRO installed"
# =============================================================================
# STEP 3: Gazebo Installation
# =============================================================================
echo ""
echo "[STEP 3/$TOTAL_STEPS] Installing Gazebo..."
# Add Gazebo repository
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
# Install Gazebo Harmonic (preferred) or Garden as fallback
sudo apt-get install -y gz-harmonic || sudo apt-get install -y gz-garden || {
echo "[WARN] Could not install Gazebo Harmonic/Garden"
}
# Verify installation
if command -v gz &> /dev/null; then
echo "[INFO] Gazebo installed (gz command available)"
elif command -v ign &> /dev/null; then
echo "[INFO] Gazebo Fortress installed (ign command available)"
echo "[OK] Gazebo installed ($(gz sim --version 2>/dev/null | head -1 || echo 'version unknown'))"
else
echo "[WARN] Gazebo command not found - use standalone mode"
echo "[WARN] Gazebo command not found"
fi
# -----------------------------------------------------------------------------
# Step 5: Create Python Virtual Environment
# -----------------------------------------------------------------------------
# =============================================================================
# STEP 4: Python Virtual Environment
# =============================================================================
echo ""
echo "[STEP 5/7] Creating Python virtual environment..."
echo "[STEP 4/$TOTAL_STEPS] Creating Python virtual environment..."
if [ -d "$VENV_DIR" ]; then
rm -rf "$VENV_DIR"
fi
python3 -m venv "$VENV_DIR"
echo "[INFO] Virtual environment created at: $VENV_DIR"
# -----------------------------------------------------------------------------
# Step 6: Install Python Dependencies
# -----------------------------------------------------------------------------
echo ""
echo "[STEP 6/7] Installing Python dependencies..."
source "$VENV_DIR/bin/activate"
pip install --upgrade pip
@@ -154,17 +162,18 @@ else
pip install pybullet numpy pillow opencv-python pymavlink pexpect
fi
echo "[INFO] Python packages installed"
echo "[OK] Python virtual environment created"
# -----------------------------------------------------------------------------
# Step 7: Create Activation Script
# -----------------------------------------------------------------------------
# =============================================================================
# STEP 5: Create Activation Script
# =============================================================================
echo ""
echo "[STEP 7/7] Creating activation script..."
echo "[STEP 5/$TOTAL_STEPS] Creating activation script..."
cat > "$PROJECT_ROOT/activate.sh" << 'EOF'
#!/bin/bash
# Drone Simulation - Environment Activation
# RDC Simulation - Environment Activation
# Usage: source activate.sh
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -197,7 +206,7 @@ fi
# Set Gazebo paths
export GZ_SIM_RESOURCE_PATH="$SCRIPT_DIR/gazebo/models:$GZ_SIM_RESOURCE_PATH"
# Add paths for ArduPilot tools and MAVProxy
# Add paths for ArduPilot tools
export PATH="$PATH:$HOME/.local/bin"
export PATH="$PATH:$HOME/ardupilot/Tools/autotest"
@@ -212,15 +221,13 @@ echo "Ready! See README.md for usage instructions."
EOF
chmod +x "$PROJECT_ROOT/activate.sh"
echo "[INFO] Created: $PROJECT_ROOT/activate.sh"
echo "[OK] Created: $PROJECT_ROOT/activate.sh"
# -----------------------------------------------------------------------------
# Verification
# -----------------------------------------------------------------------------
# =============================================================================
# STEP 6: Verify Base Installation
# =============================================================================
echo ""
echo "=============================================="
echo " Verifying Installation"
echo "=============================================="
echo "[STEP 6/$TOTAL_STEPS] Verifying base installation..."
source "$PROJECT_ROOT/activate.sh"
@@ -229,42 +236,148 @@ 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"
# -----------------------------------------------------------------------------
# ArduPilot Installation (if requested)
# -----------------------------------------------------------------------------
# =============================================================================
# ARDUPILOT INSTALLATION (Steps 7-10, if not skipped)
# =============================================================================
if [ "$INSTALL_ARDUPILOT" = true ]; then
# =========================================================================
# STEP 7: Clone and Setup ArduPilot
# =========================================================================
echo ""
echo "[INFO] Installing ArduPilot SITL..."
echo "[STEP 7/$TOTAL_STEPS] Setting up ArduPilot SITL..."
if [ -f "$SCRIPT_DIR/install_ardupilot.sh" ]; then
bash "$SCRIPT_DIR/install_ardupilot.sh"
if [ ! -d "$ARDUPILOT_HOME" ]; then
echo "[INFO] Cloning ArduPilot repository..."
git clone --recurse-submodules https://github.com/ArduPilot/ardupilot.git "$ARDUPILOT_HOME"
else
echo "[ERROR] install_ardupilot.sh not found at $SCRIPT_DIR/"
echo "[INFO] ArduPilot directory already exists"
fi
cd "$ARDUPILOT_HOME"
# Install ArduPilot prerequisites (this creates ~/.ardupilot_env)
echo "[INFO] Installing ArduPilot prerequisites (this may take a while)..."
Tools/environment_install/install-prereqs-ubuntu.sh -y
. ~/.profile || true
# Source ArduPilot environment
if [ -f "$HOME/.ardupilot_env" ]; then
source "$HOME/.ardupilot_env"
fi
echo "[OK] ArduPilot prerequisites installed"
# =========================================================================
# STEP 8: Build ArduCopter SITL
# =========================================================================
echo ""
echo "[STEP 8/$TOTAL_STEPS] Building ArduCopter SITL..."
cd "$ARDUPILOT_HOME"
./waf configure --board sitl
./waf copter
echo "[OK] ArduCopter SITL built"
# =========================================================================
# STEP 9: Build ArduPilot Gazebo Plugin
# =========================================================================
echo ""
echo "[STEP 9/$TOTAL_STEPS] Building ArduPilot Gazebo plugin..."
if [ ! -d "$ARDUPILOT_GZ" ]; then
echo "[INFO] Cloning ardupilot_gazebo repository..."
git clone https://github.com/ArduPilot/ardupilot_gazebo.git "$ARDUPILOT_GZ"
else
echo "[INFO] ardupilot_gazebo directory already exists"
fi
cd "$ARDUPILOT_GZ"
mkdir -p build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
echo "[OK] ArduPilot Gazebo plugin built"
# =========================================================================
# STEP 10: Configure Environment
# =========================================================================
echo ""
echo "[STEP 10/$TOTAL_STEPS] Configuring shell environment..."
BASHRC_MARKER="# === RDC Simulation ArduPilot ==="
if ! grep -q "$BASHRC_MARKER" ~/.bashrc; then
cat >> ~/.bashrc << EOF
$BASHRC_MARKER
# Source ArduPilot environment
if [ -f ~/.ardupilot_env ]; then
source ~/.ardupilot_env
fi
export ARDUPILOT_HOME=$ARDUPILOT_HOME
export PATH=\$PATH:$ARDUPILOT_HOME/Tools/autotest
export PATH=\$PATH:\$HOME/.local/bin
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] Added ArduPilot configuration to ~/.bashrc"
else
echo "[OK] ArduPilot configuration already in ~/.bashrc"
fi
# Install MAVProxy
pip3 install --user pymavlink mavproxy pexpect
# Verify ArduPilot installation
echo ""
echo "Verifying ArduPilot installation..."
source ~/.bashrc 2>/dev/null || true
export PATH=$PATH:$ARDUPILOT_HOME/Tools/autotest:$HOME/.local/bin
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"
fi
# =============================================================================
# INSTALLATION COMPLETE
# =============================================================================
echo ""
echo "=============================================="
echo " Installation Complete!"
echo "=============================================="
echo ""
echo "Quick start (3 terminals):"
echo ""
echo "Terminal 1 - Start Gazebo:"
echo " cd ~/RDC_Simulation"
echo " ./scripts/run_ardupilot_sim.sh runway"
echo ""
echo "Terminal 2 - Start ArduCopter SITL:"
echo " source ~/.ardupilot_env"
echo " sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON --console"
echo ""
echo "Terminal 3 - Run Controller:"
echo " cd ~/RDC_Simulation"
echo " source activate.sh"
echo " python scripts/run_ardupilot.py --pattern square"
echo ""
if [ "$INSTALL_ARDUPILOT" != true ]; then
echo "For ArduPilot SITL (required for flight):"
echo " ./setup/install_ardupilot.sh"
if [ "$INSTALL_ARDUPILOT" = true ]; then
echo "IMPORTANT: Run this command to reload your environment:"
echo " source ~/.bashrc"
echo ""
echo "Quick Start (3 terminals):"
echo ""
echo "Terminal 1 - Start Gazebo:"
echo " cd ~/RDC_Simulation"
echo " ./scripts/run_ardupilot_sim.sh runway"
echo ""
echo "Terminal 2 - Start ArduCopter SITL:"
echo " source ~/.bashrc"
echo " sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON --console"
echo ""
echo "Terminal 3 - Run Controller:"
echo " cd ~/RDC_Simulation"
echo " source activate.sh"
echo " python scripts/run_ardupilot.py --pattern square"
else
echo "Basic installation complete."
echo ""
echo "To install ArduPilot SITL later, run:"
echo " ./setup/install_ubuntu.sh"
echo ""
echo "Or run manually:"
echo " cd ~/RDC_Simulation"
echo " source activate.sh"
fi
echo ""