feat: enhance ArduPilot SITL startup with improved dependency checks, detailed error messages, and a robust TCP port readiness wait.
This commit is contained in:
@@ -25,7 +25,6 @@ if [ -f "$HOME/.ardupilot_env" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Activate ArduPilot venv (has empy and other dependencies)
|
# Activate ArduPilot venv (has empy and other dependencies)
|
||||||
# This MUST be the active venv for sim_vehicle.py to work
|
|
||||||
if [ -f "$HOME/venv-ardupilot/bin/activate" ]; then
|
if [ -f "$HOME/venv-ardupilot/bin/activate" ]; then
|
||||||
source "$HOME/venv-ardupilot/bin/activate"
|
source "$HOME/venv-ardupilot/bin/activate"
|
||||||
fi
|
fi
|
||||||
@@ -38,41 +37,70 @@ echo ""
|
|||||||
# Check dependencies
|
# Check dependencies
|
||||||
if ! command -v sim_vehicle.py &> /dev/null; then
|
if ! command -v sim_vehicle.py &> /dev/null; then
|
||||||
echo "[ERROR] sim_vehicle.py not found"
|
echo "[ERROR] sim_vehicle.py not found"
|
||||||
echo "Add to PATH: export PATH=\$PATH:~/ardupilot/Tools/autotest"
|
echo ""
|
||||||
|
echo "Fix: Add ArduPilot tools to PATH:"
|
||||||
|
echo " export PATH=\$PATH:~/ardupilot/Tools/autotest"
|
||||||
|
echo ""
|
||||||
|
echo "Or source the ArduPilot environment:"
|
||||||
|
echo " source ~/.ardupilot_env"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Verify correct Python environment (ArduPilot venv should have empy)
|
# Verify empy is available
|
||||||
if ! python3 -c "import em" 2>/dev/null; then
|
if ! python3 -c "import em" 2>/dev/null; then
|
||||||
echo "[WARN] empy not found in current Python environment"
|
echo "[ERROR] empy not found"
|
||||||
echo "[INFO] Attempting to use ArduPilot venv..."
|
echo ""
|
||||||
if [ -f "$HOME/venv-ardupilot/bin/activate" ]; then
|
echo "Fix: Install empy in ArduPilot venv:"
|
||||||
source "$HOME/venv-ardupilot/bin/activate"
|
echo " source ~/venv-ardupilot/bin/activate"
|
||||||
fi
|
echo " pip install empy==3.3.4"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start SITL in background
|
echo "[INFO] Environment OK"
|
||||||
|
echo "[INFO] Python: $(which python3)"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Start SITL with console output
|
||||||
echo "[INFO] Starting ArduPilot SITL..."
|
echo "[INFO] Starting ArduPilot SITL..."
|
||||||
sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON --no-mavproxy &
|
echo "[INFO] This will build ArduCopter if needed (first run takes ~2 min)"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Run sim_vehicle in a way that shows output
|
||||||
|
sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON --console --map &
|
||||||
SITL_PID=$!
|
SITL_PID=$!
|
||||||
|
|
||||||
# Wait for SITL to start
|
# Wait for SITL to be ready (check for TCP port 5760)
|
||||||
sleep 5
|
echo "[INFO] Waiting for SITL to start (TCP 5760)..."
|
||||||
|
TRIES=0
|
||||||
# Check if SITL started
|
MAX_TRIES=60 # 60 seconds max
|
||||||
if ! kill -0 $SITL_PID 2>/dev/null; then
|
while ! nc -z 127.0.0.1 5760 2>/dev/null; do
|
||||||
echo "[ERROR] SITL failed to start"
|
sleep 1
|
||||||
exit 1
|
TRIES=$((TRIES + 1))
|
||||||
fi
|
if [ $TRIES -ge $MAX_TRIES ]; then
|
||||||
|
echo "[ERROR] Timeout waiting for SITL on port 5760"
|
||||||
echo "[OK] SITL started (PID: $SITL_PID)"
|
kill $SITL_PID 2>/dev/null || true
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# Check if SITL process is still running
|
||||||
|
if ! kill -0 $SITL_PID 2>/dev/null; then
|
||||||
|
echo "[ERROR] SITL process died"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo -n "."
|
||||||
|
done
|
||||||
echo ""
|
echo ""
|
||||||
|
echo "[OK] SITL is ready on TCP 5760"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Give it a moment more to stabilize
|
||||||
|
sleep 2
|
||||||
|
|
||||||
# Trap to kill SITL on exit
|
# Trap to kill SITL on exit
|
||||||
trap "echo ''; echo '[INFO] Stopping SITL...'; kill $SITL_PID 2>/dev/null; exit 0" INT TERM
|
trap "echo ''; echo '[INFO] Stopping SITL...'; kill $SITL_PID 2>/dev/null; exit 0" INT TERM
|
||||||
|
|
||||||
# Run controller
|
# Run controller
|
||||||
echo "[INFO] Starting drone controller..."
|
echo "[INFO] Starting drone controller..."
|
||||||
|
echo "[INFO] Press Ctrl+C to stop"
|
||||||
echo ""
|
echo ""
|
||||||
cd "$PROJECT_DIR"
|
cd "$PROJECT_DIR"
|
||||||
python scripts/run_ardupilot.py "$@"
|
python scripts/run_ardupilot.py "$@"
|
||||||
|
|||||||
Reference in New Issue
Block a user