Update Install Scripts

This commit is contained in:
2026-02-09 04:20:22 +00:00
parent e70d4a8fcd
commit 5c0d3e2fb4
10 changed files with 1072 additions and 836 deletions

View File

@@ -1,7 +1,9 @@
#!/bin/bash
# Full simulation launch script with ArduPilot SITL
# This script launches Gazebo, ArduPilot SITL, and MAVROS
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
@@ -35,16 +37,26 @@ done
if [ -z "$ROS_DISTRO" ]; then
echo -e "${RED}ERROR: No ROS 2 installation found!${NC}"
echo "Please install ROS 2 first. See docs/setup_guide.md or docs/wsl_setup_guide.md"
echo "Please install ROS 2 first. See docs/setup_guide.md"
exit 1
fi
echo -e "${GREEN}Using ROS 2: $ROS_DISTRO${NC}"
# Source ROS 2
# Check ArduPilot installation
ARDUPILOT_HOME="${ARDUPILOT_HOME:-$HOME/ardupilot}"
if [ ! -d "$ARDUPILOT_HOME" ]; then
echo -e "${RED}ERROR: ArduPilot not found at $ARDUPILOT_HOME${NC}"
echo ""
echo "Please install ArduPilot first:"
echo " bash scripts/install_ardupilot.sh"
echo ""
exit 1
fi
# Source environments
source /opt/ros/${ROS_DISTRO}/setup.bash
# Source Gazebo setup (CRITICAL for shader paths)
if [ -f /usr/share/gazebo/setup.bash ]; then
source /usr/share/gazebo/setup.bash
elif [ -f /usr/share/gazebo-11/setup.bash ]; then
@@ -52,9 +64,10 @@ elif [ -f /usr/share/gazebo-11/setup.bash ]; then
fi
# Parse arguments
WORLD=""
WORLD="$PROJECT_DIR/worlds/iris_runway.world"
VEHICLE="copter"
USE_SOFTWARE_RENDER=false
HEADLESS=false
INSTANCE=0
while [[ $# -gt 0 ]]; do
case $1 in
@@ -62,34 +75,32 @@ while [[ $# -gt 0 ]]; do
WORLD="$2"
shift 2
;;
--headless)
HEADLESS=true
shift
--vehicle)
VEHICLE="$2"
shift 2
;;
--no-gpu|--software-render)
--software-render)
USE_SOFTWARE_RENDER=true
shift
;;
--instance)
INSTANCE="$2"
shift 2
;;
--help)
echo "Usage: $0 [OPTIONS] [WORLD_FILE]"
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --world FILE Specify world file (default: empty_custom.world)"
echo " --headless Run without GUI (gzserver only)"
echo " --software-render Force software rendering (recommended for WSL)"
echo " --help Show this help"
echo ""
echo "Examples:"
echo " $0 # Default world"
echo " $0 worlds/indoor_warehouse.world # Indoor environment"
echo " $0 --software-render # For WSL without GPU"
echo " --world FILE World file (default: iris_runway.world)"
echo " --vehicle TYPE Vehicle type: copter, rover (default: copter)"
echo " --software-render Force software rendering (for WSL)"
echo " --instance N Vehicle instance number (default: 0)"
echo " --help Show this help"
exit 0
;;
*)
if [ -f "$1" ]; then
WORLD="$1"
elif [ -f "$PROJECT_DIR/$1" ]; then
WORLD="$PROJECT_DIR/$1"
elif [ -f "$PROJECT_DIR/worlds/$1" ]; then
WORLD="$PROJECT_DIR/worlds/$1"
fi
@@ -98,109 +109,172 @@ while [[ $# -gt 0 ]]; do
esac
done
# Default world
if [ -z "$WORLD" ]; then
WORLD="$PROJECT_DIR/worlds/empty_custom.world"
fi
# Validate world file
if [ ! -f "$WORLD" ]; then
echo -e "${RED}ERROR: World file not found: $WORLD${NC}"
echo "Available worlds:"
ls -1 "$PROJECT_DIR/worlds/"*.world 2>/dev/null || echo " (none found)"
exit 1
fi
# Setup Gazebo paths
export GAZEBO_MODEL_PATH="$PROJECT_DIR/models:${GAZEBO_MODEL_PATH:-}"
export GAZEBO_RESOURCE_PATH="$PROJECT_DIR/worlds:${GAZEBO_RESOURCE_PATH:-}"
# ArduPilot Gazebo paths (if installed)
if [ -d "$HOME/ardupilot_gazebo" ]; then
export GAZEBO_MODEL_PATH="$HOME/ardupilot_gazebo/models:$GAZEBO_MODEL_PATH"
export GAZEBO_RESOURCE_PATH="$HOME/ardupilot_gazebo/worlds:$GAZEBO_RESOURCE_PATH"
fi
# WSL-specific setup
# WSL/Display setup
if $IS_WSL; then
# Source WSL environment if exists
if [ -f "$PROJECT_DIR/wsl_env.sh" ]; then
source "$PROJECT_DIR/wsl_env.sh"
fi
# Set DISPLAY if not set
if [ -z "$DISPLAY" ]; then
if [ -d "/mnt/wslg" ]; then
export DISPLAY=:0
else
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
fi
export DISPLAY=:0
fi
echo -e "${BLUE}DISPLAY: $DISPLAY${NC}"
# Force software rendering in WSL by default if having issues
if ! $USE_SOFTWARE_RENDER; then
echo -e "${YELLOW}TIP: If Gazebo crashes or has rendering issues, use --software-render${NC}"
fi
fi
# Apply software rendering if requested or in WSL with issues
if $USE_SOFTWARE_RENDER; then
echo -e "${YELLOW}Using software rendering${NC}"
export LIBGL_ALWAYS_SOFTWARE=1
export MESA_GL_VERSION_OVERRIDE=3.3
export MESA_GLSL_VERSION_OVERRIDE=330
fi
# Cleanup function
cleanup() {
echo ""
echo -e "${YELLOW}Shutting down simulation...${NC}"
# Kill processes
pkill -f "sim_vehicle.py" 2>/dev/null || true
pkill -f "mavproxy" 2>/dev/null || true
pkill -f "ArduCopter" 2>/dev/null || true
pkill -f "ArduRover" 2>/dev/null || true
pkill -f "gzserver" 2>/dev/null || true
pkill -f "gzclient" 2>/dev/null || true
pkill -f "gazebo" 2>/dev/null || true
sleep 1
pkill -f "mavros" 2>/dev/null || true
sleep 2
echo -e "${GREEN}Cleanup complete.${NC}"
}
trap cleanup EXIT INT TERM
# Activate virtual environment if exists
# Activate virtual environment
if [ -f "$PROJECT_DIR/venv/bin/activate" ]; then
source "$PROJECT_DIR/venv/bin/activate"
fi
# Source workspace if built
if [ -f "$PROJECT_DIR/../install/setup.bash" ]; then
source "$PROJECT_DIR/../install/setup.bash"
elif [ -f "$PROJECT_DIR/install/setup.bash" ]; then
source "$PROJECT_DIR/install/setup.bash"
fi
echo ""
echo -e "${GREEN}Starting simulation with world: $(basename $WORLD)${NC}"
echo -e "${BLUE}World path: $WORLD${NC}"
echo ""
# Check if ROS package exists
ROS_PKG_EXISTS=false
if ros2 pkg list 2>/dev/null | grep -q "uav_ugv_simulation"; then
ROS_PKG_EXISTS=true
fi
# Launch simulation
if $ROS_PKG_EXISTS; then
echo -e "${GREEN}Launching via ROS 2...${NC}"
ros2 launch uav_ugv_simulation full_simulation.launch.py world:="$WORLD"
else
echo -e "${YELLOW}ROS package not built. Launching Gazebo directly...${NC}"
echo -e "${BLUE}To build the package: cd ~/ros2_ws && colcon build --packages-select uav_ugv_simulation${NC}"
echo ""
if $HEADLESS; then
gzserver --verbose "$WORLD"
# Use ardupilot_gazebo iris world if no custom world specified
if [ ! -f "$WORLD" ]; then
if [ -f "$HOME/ardupilot_gazebo/worlds/iris_arducopter_runway.world" ]; then
WORLD="$HOME/ardupilot_gazebo/worlds/iris_arducopter_runway.world"
else
gazebo --verbose "$WORLD"
echo -e "${RED}ERROR: World file not found: $WORLD${NC}"
exit 1
fi
fi
echo ""
echo -e "${GREEN}Configuration:${NC}"
echo " Vehicle: $VEHICLE"
echo " World: $(basename $WORLD)"
echo " Instance: $INSTANCE"
echo ""
# Calculate ports
MAVLINK_PORT=$((14550 + INSTANCE * 10))
SITL_PORT=$((5760 + INSTANCE * 10))
# Start Gazebo in background
echo -e "${GREEN}Starting Gazebo...${NC}"
gazebo --verbose "$WORLD" &
GAZEBO_PID=$!
sleep 5
# Check if Gazebo started
if ! kill -0 $GAZEBO_PID 2>/dev/null; then
echo -e "${RED}ERROR: Gazebo failed to start${NC}"
exit 1
fi
echo -e "${GREEN}Gazebo running (PID: $GAZEBO_PID)${NC}"
# Start ArduPilot SITL
echo -e "${GREEN}Starting ArduPilot SITL...${NC}"
cd "$ARDUPILOT_HOME"
if [ "$VEHICLE" = "copter" ]; then
VEHICLE_DIR="ArduCopter"
FRAME="gazebo-iris"
elif [ "$VEHICLE" = "rover" ]; then
VEHICLE_DIR="Rover"
FRAME="gazebo-rover"
else
VEHICLE_DIR="ArduCopter"
FRAME="gazebo-iris"
fi
cd "$ARDUPILOT_HOME/$VEHICLE_DIR"
# Start sim_vehicle.py in background
python3 "$ARDUPILOT_HOME/Tools/autotest/sim_vehicle.py" \
-v "$VEHICLE_DIR" \
-f "$FRAME" \
--no-mavproxy \
-I "$INSTANCE" \
--no-rebuild \
&
SITL_PID=$!
sleep 10
# Check if SITL started
if ! kill -0 $SITL_PID 2>/dev/null; then
echo -e "${RED}ERROR: ArduPilot SITL failed to start${NC}"
exit 1
fi
echo -e "${GREEN}ArduPilot SITL running (PID: $SITL_PID)${NC}"
# Start MAVROS
echo -e "${GREEN}Starting MAVROS...${NC}"
ros2 run mavros mavros_node --ros-args \
-p fcu_url:="udp://127.0.0.1:${MAVLINK_PORT}@" \
-p gcs_url:="" \
-p target_system_id:=1 \
-p target_component_id:=1 \
&>/dev/null &
MAVROS_PID=$!
sleep 5
echo ""
echo -e "${GREEN}==========================================${NC}"
echo -e "${GREEN} Simulation Running${NC}"
echo -e "${GREEN}==========================================${NC}"
echo ""
echo -e "${BLUE}Components:${NC}"
echo " - Gazebo: PID $GAZEBO_PID"
echo " - ArduPilot SITL: PID $SITL_PID"
echo " - MAVROS: PID $MAVROS_PID"
echo ""
echo -e "${BLUE}MAVROS Topics:${NC}"
echo " ros2 topic list | grep mavros"
echo ""
echo -e "${BLUE}Control UAV:${NC}"
echo " # Arm"
echo " ros2 service call /mavros/cmd/arming mavros_msgs/srv/CommandBool \"{value: true}\""
echo ""
echo " # Set mode to GUIDED"
echo " ros2 service call /mavros/set_mode mavros_msgs/srv/SetMode \"{base_mode: 0, custom_mode: 'GUIDED'}\""
echo ""
echo " # Takeoff to 5 meters"
echo " ros2 service call /mavros/cmd/takeoff mavros_msgs/srv/CommandTOL \"{altitude: 5}\""
echo ""
echo " # Send position setpoint (x, y, z in meters)"
echo " ros2 topic pub /mavros/setpoint_position/local geometry_msgs/PoseStamped \\"
echo " \"{header: {frame_id: 'map'}, pose: {position: {x: 10, y: 5, z: 5}}}\""
echo ""
echo -e "${YELLOW}Press Ctrl+C to stop simulation${NC}"
echo ""
# Wait for all processes
wait

View File

@@ -1,25 +0,0 @@
#!/bin/bash
echo "Setting up NVIDIA GPU for Gazebo..."
if ! command -v nvidia-smi &> /dev/null; then
echo "NVIDIA driver not found. Skipping GPU setup."
exit 0
fi
echo "NVIDIA GPU detected:"
nvidia-smi --query-gpu=name,driver_version --format=csv,noheader
export __NV_PRIME_RENDER_OFFLOAD=1
export __GLX_VENDOR_LIBRARY_NAME=nvidia
export VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/nvidia_icd.json
if [ -f /usr/lib/x86_64-linux-gnu/libEGL_nvidia.so.0 ]; then
export __EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/10_nvidia.json
fi
echo "NVIDIA GPU environment configured."
echo ""
echo "Add these to your ~/.bashrc for permanent setup:"
echo " export __NV_PRIME_RENDER_OFFLOAD=1"
echo " export __GLX_VENDOR_LIBRARY_NAME=nvidia"

View File

@@ -1,174 +0,0 @@
#!/bin/bash
# WSL Quick Setup Script
# This script sets up the simulation environment specifically for WSL2
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}==========================================${NC}"
echo -e "${BLUE} UAV-UGV Simulation - WSL Setup${NC}"
echo -e "${BLUE}==========================================${NC}"
echo ""
# Check if running in WSL
if ! grep -qEi "(microsoft|wsl)" /proc/version 2>/dev/null; then
echo -e "${YELLOW}This script is designed for WSL. Running anyway...${NC}"
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
# Detect Ubuntu version
. /etc/os-release
echo -e "${BLUE}Detected: Ubuntu $VERSION_ID ($VERSION_CODENAME)${NC}"
# Determine ROS distro
case "$VERSION_ID" in
"22.04") ROS_DISTRO="humble" ;;
"24.04") ROS_DISTRO="jazzy" ;;
*) ROS_DISTRO="humble"; echo -e "${YELLOW}Unknown Ubuntu version, defaulting to Humble${NC}" ;;
esac
echo -e "${BLUE}Target ROS 2 distro: $ROS_DISTRO${NC}"
echo ""
# Step 1: Update and install prerequisites
echo -e "${GREEN}[1/6] Installing prerequisites...${NC}"
sudo apt-get update
sudo apt-get install -y \
software-properties-common \
curl \
gnupg \
lsb-release \
x11-apps \
x11-xserver-utils \
dbus-x11 \
mesa-utils \
libgl1-mesa-glx
# Step 2: Add ROS 2 repository
echo -e "${GREEN}[2/6] Adding ROS 2 repository...${NC}"
if [ ! -f /usr/share/keyrings/ros-archive-keyring.gpg ]; then
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key \
-o /usr/share/keyrings/ros-archive-keyring.gpg
fi
if [ ! -f /etc/apt/sources.list.d/ros2.list ]; then
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] \
http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
fi
sudo apt-get update
# Step 3: Install ROS 2
echo -e "${GREEN}[3/6] Installing ROS 2 $ROS_DISTRO...${NC}"
if [ ! -d "/opt/ros/$ROS_DISTRO" ]; then
sudo apt-get install -y ros-${ROS_DISTRO}-desktop python3-colcon-common-extensions || {
echo -e "${YELLOW}Desktop install failed, trying base...${NC}"
sudo apt-get install -y ros-${ROS_DISTRO}-ros-base
}
else
echo -e "${BLUE}ROS 2 $ROS_DISTRO already installed${NC}"
fi
# Step 4: Install ROS packages
echo -e "${GREEN}[4/6] Installing ROS 2 packages...${NC}"
sudo apt-get install -y \
ros-${ROS_DISTRO}-mavros \
ros-${ROS_DISTRO}-mavros-extras \
ros-${ROS_DISTRO}-cv-bridge \
ros-${ROS_DISTRO}-image-transport \
ros-${ROS_DISTRO}-tf2-ros 2>/dev/null || {
echo -e "${YELLOW}Some packages unavailable for $ROS_DISTRO${NC}"
}
# Gazebo (different for Humble vs Jazzy)
if [ "$ROS_DISTRO" = "humble" ]; then
sudo apt-get install -y ros-humble-gazebo-ros-pkgs 2>/dev/null || true
elif [ "$ROS_DISTRO" = "jazzy" ]; then
sudo apt-get install -y ros-jazzy-ros-gz 2>/dev/null || true
fi
# GeographicLib datasets
echo -e "${GREEN}[5/6] Installing GeographicLib datasets...${NC}"
GEOGRAPHICLIB_SCRIPT="/opt/ros/${ROS_DISTRO}/lib/mavros/install_geographiclib_datasets.sh"
if [ -f "$GEOGRAPHICLIB_SCRIPT" ] && [ ! -f /usr/share/GeographicLib/geoids/egm96-5.pgm ]; then
sudo "$GEOGRAPHICLIB_SCRIPT" || echo -e "${YELLOW}GeographicLib install failed${NC}"
fi
# Step 5: Setup Python environment
echo -e "${GREEN}[6/6] Setting up Python environment...${NC}"
cd "$PROJECT_DIR"
sudo apt-get install -y python3-pip python3-venv python3-opencv libopencv-dev
if [ ! -d "venv" ]; then
python3 -m venv venv
fi
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt 2>/dev/null || echo -e "${YELLOW}Some pip packages failed${NC}"
# Create WSL environment file
cat > "$PROJECT_DIR/wsl_env.sh" << 'EOF'
#!/bin/bash
# WSL Environment Setup
# DISPLAY configuration
if [ -d "/mnt/wslg" ]; then
# WSLg (Windows 11)
export DISPLAY=:0
else
# X server (Windows 10)
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
fi
# OpenGL settings for WSL
export LIBGL_ALWAYS_INDIRECT=0
export MESA_GL_VERSION_OVERRIDE=3.3
# Uncomment for software rendering if GPU issues:
# export LIBGL_ALWAYS_SOFTWARE=1
# Gazebo performance
export OGRE_RTT_MODE=Copy
EOF
chmod +x "$PROJECT_DIR/wsl_env.sh"
# Add to bashrc
if ! grep -q "wsl_env.sh" ~/.bashrc 2>/dev/null; then
echo "" >> ~/.bashrc
echo "# UAV-UGV Simulation WSL environment" >> ~/.bashrc
echo "[ -f \"$PROJECT_DIR/wsl_env.sh\" ] && source \"$PROJECT_DIR/wsl_env.sh\"" >> ~/.bashrc
echo "[ -f /opt/ros/${ROS_DISTRO}/setup.bash ] && source /opt/ros/${ROS_DISTRO}/setup.bash" >> ~/.bashrc
fi
# Make scripts executable
chmod +x "$PROJECT_DIR/scripts/"*.sh 2>/dev/null || true
chmod +x "$PROJECT_DIR/setup.sh" 2>/dev/null || true
chmod +x "$PROJECT_DIR/activate_venv.sh" 2>/dev/null || true
echo ""
echo -e "${GREEN}==========================================${NC}"
echo -e "${GREEN} WSL Setup Complete!${NC}"
echo -e "${GREEN}==========================================${NC}"
echo ""
echo -e "${BLUE}Next steps:${NC}"
echo " 1. Close and reopen your terminal (or run: source ~/.bashrc)"
echo " 2. Test GUI: xcalc (should open calculator)"
echo " 3. Test Gazebo: gazebo --verbose"
echo " 4. Run simulation: source activate_venv.sh && bash scripts/run_simulation.sh"
echo ""
echo -e "${YELLOW}WSL Tips:${NC}"
echo " - Windows 11: GUI works out of the box (WSLg)"
echo " - Windows 10: Install VcXsrv and run XLaunch first"
echo " - Slow graphics? Run with: bash scripts/run_simulation.sh --software-render"
echo " - See docs/wsl_setup_guide.md for detailed help"
echo ""