Ardupilot Controller Script
This commit is contained in:
61
scripts/run_ardupilot_controller.sh
Executable file
61
scripts/run_ardupilot_controller.sh
Executable file
@@ -0,0 +1,61 @@
|
||||
#!/bin/bash
|
||||
# =============================================================================
|
||||
# ArduPilot Controller Launcher
|
||||
# =============================================================================
|
||||
# Starts ArduPilot SITL and your drone controller together.
|
||||
#
|
||||
# Usage:
|
||||
# Terminal 1: ./scripts/run_ardupilot_sim.sh runway
|
||||
# Terminal 2: ./scripts/run_ardupilot_controller.sh
|
||||
# =============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
|
||||
echo "=============================================="
|
||||
echo " ArduPilot Controller"
|
||||
echo "=============================================="
|
||||
echo ""
|
||||
|
||||
# Check dependencies
|
||||
if ! command -v sim_vehicle.py &> /dev/null; then
|
||||
echo "[ERROR] sim_vehicle.py not found"
|
||||
echo "Add to PATH: export PATH=\$PATH:~/ardupilot/Tools/autotest"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Activate virtual environment if exists
|
||||
if [ -f "$PROJECT_DIR/venv/bin/activate" ]; then
|
||||
source "$PROJECT_DIR/venv/bin/activate"
|
||||
fi
|
||||
|
||||
# Start SITL in background
|
||||
echo "[INFO] Starting ArduPilot SITL..."
|
||||
sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON --no-mavproxy &
|
||||
SITL_PID=$!
|
||||
|
||||
# Wait for SITL to start
|
||||
sleep 5
|
||||
|
||||
# Check if SITL started
|
||||
if ! kill -0 $SITL_PID 2>/dev/null; then
|
||||
echo "[ERROR] SITL failed to start"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[OK] SITL started (PID: $SITL_PID)"
|
||||
echo ""
|
||||
|
||||
# Trap to kill SITL on exit
|
||||
trap "echo ''; echo '[INFO] Stopping SITL...'; kill $SITL_PID 2>/dev/null; exit 0" INT TERM
|
||||
|
||||
# Run controller
|
||||
echo "[INFO] Starting drone controller..."
|
||||
echo ""
|
||||
cd "$PROJECT_DIR"
|
||||
python run_ardupilot.py "$@"
|
||||
|
||||
# Cleanup
|
||||
kill $SITL_PID 2>/dev/null
|
||||
Reference in New Issue
Block a user