Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PX4 Offboard Controller + Gazebo Camera (Unified Pygame GUI)

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.


✈️ Features

  • ✅ 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

🧰 Prerequisites

1. Base System

Tested on Ubuntu 24.04 (Noble) with:

  • Gazebo Garden 8.9+
  • PX4-Autopilot
  • Python 3.12+

2. System Dependencies

sudo apt update
sudo apt install -y \
  python3-gz-transport13 python3-gz-msgs10 \
  gz-transport13 \
  gz-sim8 \
  python3-pip

3. PX4 SITL & Gazebo

Clone 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_x500

When you see Gazebo open and the console print pxh>, your sim is live.


🎥 Add a Camera to the Drone (Gazebo Setup)

If 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.sh

Then restart the simulator:

pkill -f "gz sim" || true
pkill -f "/px4" || true
cd ~/PX4-Autopilot
make px4_sitl gz_x500

Confirm camera topic exists:

gz topic -l | grep front_cam

You should see:

/world/default/model/x500_0/link/base_link/sensor/front_cam/image

🐍 Project Setup

  1. Clone the project
git clone https://github.com/sbussiso/Pygame-Ardupilot-Controler.git
cd Pygame-Ardupilot-Controler

after gazebo is running, run:

chmod +x run.sh
./run.sh

🎮 Controls

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

Gazebo UI Pygame UI

About

a pygame UI for streaming camera video and controling a simulated drone with Gazebo Simulator

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages