A complete keyboard-driven drone controller for PX4 SITL with Gazebo camera streaming and a unified Pygame GUI.
It lets you fly, view live camera feed, record video, take snapshots, and apply live OpenCV filters — all from one window.
- ✅ Connects automatically to PX4 SITL (
udpin://0.0.0.0:14540) - ✅ Subscribes to a Gazebo camera topic (via
gz.transport13) - ✅ Keyboard control:
WASD,R/F,Q/E,SHIFT,SPACE,ESC - ✅ HUD overlay with live telemetry (altitude, yaw, velocity)
- ✅ Snapshots (
P) and MP4 recording (V) - ✅ Optional OpenCV Canny edge overlay (
C) - ✅ One-window display using Pygame + OpenCV
Tested on Ubuntu 24.04 (Noble) with:
Gazebo Garden 8.9+PX4-AutopilotPython 3.12+
sudo apt update
sudo apt install -y \
python3-gz-transport13 python3-gz-msgs10 \
gz-transport13 \
gz-sim8 \
python3-pipClone and build PX4 if you haven’t already:
cd ~
git clone https://github.com/PX4/PX4-Autopilot.git --recursive
cd PX4-Autopilot
make px4_sitl gz_x500If your world doesn’t already have an onboard camera, run this script once:
cat <<'EOF' > ~/PX4-Autopilot/add_drone_cam.sh
#!/usr/bin/env bash
set -euo pipefail
SDF="$HOME/PX4-Autopilot/Tools/simulation/gz/models/x500_base/model.sdf"
BACKUP="$SDF.bak.$(date +%s)"
CAM_BLOCK=' <!-- Onboard forward camera -->
<sensor name="front_cam" type="camera">
<pose>0.12 0 0.06 0 -0.15 0</pose>
<always_on>true</always_on>
<update_rate>30</update_rate>
<visualize>true</visualize>
<camera>
<horizontal_fov>1.047</horizontal_fov>
<image>
<width>640</width>
<height>360</height>
<format>R8G8B8</format>
</image>
<clip><near>0.05</near><far>100</far></clip>
</camera>
</sensor>'
cp -a "$SDF" "$BACKUP"
awk -v cam="$CAM_BLOCK" '
BEGIN{inbase=0}
{ if ($0 ~ /<link name="base_link">/) inbase=1
if (inbase==1 && $0 ~ /<\/link>/) {print cam; inbase=0}
print
}' "$BACKUP" > "$SDF"
echo "✅ Camera added under base_link. Restart PX4 SITL to apply."
EOF
chmod +x ~/PX4-Autopilot/add_drone_cam.sh
~/PX4-Autopilot/add_drone_cam.shThen restart the simulator:
pkill -f "gz sim" || true
pkill -f "/px4" || true
cd ~/PX4-Autopilot
make px4_sitl gz_x500gz topic -l | grep front_cam/world/default/model/x500_0/link/base_link/sensor/front_cam/image- Clone the project
git clone https://github.com/sbussiso/Pygame-Ardupilot-Controler.git
cd Pygame-Ardupilot-Controlerchmod +x run.sh
./run.sh| Key | Action |
|---|---|
| W/S | Forward / Backward |
| A/D | Left / Right |
| R/F | Up / Down |
| Q/E | Yaw Left / Right |
| SHIFT | Boost speed |
| SPACE | Brake |
| ESC | Land + Exit |
| V | Toggle video recording |
| P | Take snapshot (PNG) |
| C | Toggle Canny edge overlay |

