Skip to content

About

Autonomous vision based Obstacle avoidance and RTL Auto docking Drone

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Autonomous-Drone

Autonomous vision-based obstacle avoidance and RTL auto-docking drone.

This repository holds the ground station: the laptop-side video receiver and computer-vision pipeline for an F450 quadcopter running ArduCopter on a Pixhawk 2.4.8, with a Raspberry Pi companion computer streaming live video over WiFi.

Raspberry Pi                        Laptop
┌──────────────┐                   ┌──────────────────────────────────┐
│ Pi Camera    │                   │ ffmpeg decode → NumPy → OpenCV   │
│      ↓       │   H.264 over TCP  │      ↓                           │
│ rpicam-vid   │ ────────────────► │ ArUco / motion → HUD → display   │
└──────────────┘                   └──────────────────────────────────┘

The Pi does one job: encode and ship pixels. All vision work runs on the laptop, where there is CPU and GPU to spare. Telemetry travels separately over a SiK radio link, so the Pi needs no connection to the flight controller.

Features

  • Low-latency H.264 receiver — drives ffmpeg as a subprocess and pipes raw BGR frames into NumPy, with explicit low-delay flags. Automatic reconnection with exponential backoff.
  • Newest-frame-wins buffering — frames arriving while the pipeline is busy are dropped rather than queued, so latency stays flat instead of growing.
  • ArUco marker detection with sub-pixel corner refinement, target selection and normalised steering offsets.
  • Motion detection via frame differencing.
  • Live HUD showing link health, throughput, dropped-frame ratio and stage output.
  • Recording and snapshots to disk, toggled from the keyboard.
  • Stream relay — works around the single-client limit of rpicam-vid --listen so several viewers can watch at once.
  • Synthetic camera — a test stream that imitates rpicam-vid closely enough to develop and test the entire pipeline with no hardware attached.
  • Printable ArUco marker generator, including a multi-marker test sheet.

Requirements

  • Python 3.10+
  • opencv-python 4.7+ (ArUco moved into the main module at 4.7)
  • numpy
  • ffmpeg / ffprobe on PATH
sudo apt install -y ffmpeg
pip install opencv-python numpy

Quick start

No drone or camera required — the synthetic stream exercises the full path:

cd groundstation
./tools/fakepi_ctl.sh start
python3 -m dronecam view --source tcp://127.0.0.1:8888 --aruco
./tools/fakepi_ctl.sh stop

Against a real Pi:

python3 -m dronecam view --host <pi-ip> --aruco

Keys: q quit · s snapshot · r record · a ArUco · m motion · h help

Commands

python3 -m dronecam view  --host <ip> [--aruco] [--motion] [--no-gui] [--seconds N]
python3 -m dronecam relay --host <ip> --relay-port 9000
python3 -m dronecam probe --host <ip>

Pi setup

# on the Pi
sudo ./groundstation/pi/setup_stream.sh 640 480 30 8888

Installs a systemd service that starts the camera stream at boot. The script auto-detects rpicam-vid or libcamera-vid depending on OS release, and refuses to install if no camera is detected rather than leaving a crash-looping unit.

A read-only diagnostic is included for camera troubleshooting:

./groundstation/pi/diagnose_camera.sh

The one-client rule

rpicam-vid --listen accepts exactly one TCP client and exits when that client disconnects. Two consequences worth knowing before debugging a dead feed:

  • A video player and the OpenCV script cannot both connect; the second is refused.
  • Closing your viewer ends the stream on the Pi — which is why the systemd unit sets Restart=always.

Use the relay to watch from several places at once:

python3 -m dronecam relay --host <pi-ip> --relay-port 9000
python3 -m dronecam view --source tcp://127.0.0.1:9000 --aruco

ArUco markers

python3 groundstation/tools/make_markers.py --ids 7 13 23 --mm 100 --sheet

Print at 100% / actual size — "fit to page" silently rescales the marker and invalidates distance work. Keep the white quiet zone; markers trimmed to the black border often fail to detect.

Layout

groundstation/
  dronecam/
    receiver.py    ffmpeg subprocess → NumPy frames, reconnect, drop-stale
    pipeline.py    ArUco / motion stages, recorder, target selection
    hud.py         status overlay
    cli.py         view / relay / probe
  tools/
    fake_pi_stream.sh   synthetic camera for hardware-free development
    fakepi_ctl.sh       start/stop helper
    make_markers.py     printable markers + test sheet
  pi/
    setup_stream.sh     installs the systemd stream service
    diagnose_camera.sh  read-only camera fault finder

Extending

select_target() in groundstation/dronecam/pipeline.py decides which marker the aircraft treats as its target when several are visible. The default picks the largest; the docstring documents the trade-offs of alternatives (most-centred, lowest-id, hysteresis) and the fields available on each detection.

Hardware

Component Part
Frame F450 quadcopter
Flight controller Pixhawk 2.4.8, ArduCopter 4.5.x
Companion computer Raspberry Pi (4 / Zero 2 W)
Camera Raspberry Pi Camera Module (CSI)
Telemetry SiK radio pair
Ground station Linux laptop, Python + OpenCV

About

Autonomous vision based Obstacle avoidance and RTL Auto docking Drone

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages