This project implements an autonomous obstacle avoidance system for a differential drive (skid-steer) rover using an OAK-D depth camera and MAVLink communication via mavlink-router. It uses depth data to detect obstacles in real-time and issues RC override commands to a Pixhawk (or similar) running ArduPilot.
- Depth Sensing: Powered by the Luxonis OAK-D stereo camera using DepthAI SDK.
- Obstacle Detection: Custom-defined Regions of Interest (ROIs) in the camera view allow fine-tuned detection zones.
- Reactive Movement: Based on proximity and position of detected obstacles, the rover can stop, turn, or reverse.
- Control Interface: Sends RC override commands to the rover through MAVLink protocol via
pymavlink.
- Real-time obstacle detection using spatial depth data.
- Tunable obstacle response logic (
STOP,TURN_LEFT,TURN_RIGHT,REVERSE). - Safety-aware geometric check to prevent unsafe turns near obstacles.
- Configurable ROIs to match your rover’s field of view and size.
- Graceful exit on SIGINT/SIGTERM (Ctrl+C or shutdown).
- Pixhawk-compatible autopilot with ArduPilot Rover firmware
- OAK-D or OAK-D Lite stereo camera
- Companion computer (e.g., Raspberry Pi, Jetson Nano)
- Python 3.7+
depthaipymavlinkmavlink-router
Install dependencies:
pip install depthai pymavlinkBefore running the script, tune the following parameters as needed:
| Parameter | Description |
|---|---|
MAVLINK_ROUTER_HOST |
IP address where mavlink-router is listening (usually 127.0.0.1) |
MAVLINK_ROUTER_PORT |
UDP port configured in mavlink-router (e.g., 14551) |
MAVLINK_SYSTEM_ID / COMPONENT_ID |
Target system/component IDs for your Pixhawk |
GCS_SOURCE_SYSTEM |
Source ID for this script (typically 255) |
| Parameter | Description |
|---|---|
DEPTH_RESOLUTION |
Mono camera resolution (THE_400_P, THE_720_P, etc.) |
DEPTH_RATE_HZ |
Frame rate for depth processing |
CONFIDENCE_THRESHOLD |
Filter for noisy pixels (suggested: 220) |
| Parameter | Description |
|---|---|
OBSTACLE_THRESHOLD_M |
Trigger distance for obstacle detection (e.g., 0.5m) |
OBSTACLE_ACTION |
Action taken on center obstacle (STOP, TURN_LEFT, etc.) |
| Parameter | Description |
|---|---|
DRIVE_NEUTRAL_PWM |
PWM value for motor stop (usually 1500) |
DRIVE_FORWARD_PWM |
PWM value for forward motion |
DRIVE_REVERSE_PWM |
PWM value for reverse motion |
RC_CHAN_LEFT_THROTTLE_IDX / RIGHT_THROTTLE_IDX |
Channel index for left/right motors |
| Parameter | Description |
|---|---|
ROVER_WIDTH_M |
Full width of rover in meters |
SIDE_CLEARANCE_M |
Buffer distance to prevent unsafe turns |
- DepthAI pipeline is initialized with stereo cameras and spatial ROI calculations.
- ROIs are configured to detect obstacles in the center, left, and right regions.
- RC override commands are sent based on obstacle distance and location.
- Geometric checks ensure turns won’t cause collisions with nearby obstacles.
- The rover reacts accordingly by stopping, turning, or reversing.
- Make sure
mavlink-routeris running and properly configured. - Connect the OAK-D camera to your companion computer.
- Arm your rover and switch to Manual or Acro mode.
- Run the script:
python3 obstacle_avoidance.pyPress Ctrl+C to stop safely at any time.
- Use visual tools to debug ROIs and adjust their size and location.
- Start with low forward PWM and small ROIs.
- Increase
SIDE_CLEARANCE_Mif the rover gets too close to obstacles on turns. - Test in simulation with SITL + MAVProxy if hardware is unavailable.
Built using: