A comprehensive Python 3 library for controlling Parrot AR.Drone 2.0 quadcopters with HD video streaming, real-time navigation data, and advanced flight control capabilities.
- ๐ฅ HD Video Streaming - True 720p H.264 video with 1280x720 resolution
- ๐ Full Python 3 Compatibility - Tested with Python 3.6+ and 3.12.3
- ๐ Complete AR.Drone 2.0 Support - Optimized for AR.Drone 2.0 firmware 2.4.8+
- ๐ก Advanced Network Management - Session management and proper codec configuration
- ๐งฉ Modular Architecture - Clean, maintainable package structure
- ๐ฎ Interactive Demo - Feature-rich pygame interface with HD video display
- ๐ง Mock Mode - Testing capabilities without physical hardware
- โก Real-time Data - Live navigation data, sensor readings, and flight status
This library includes comprehensive AR.Drone 2.0 specific improvements:
- H.264 Decoder: Native H.264 video decoding with ffmpeg integration
- PAVE Parser: Proper Parrot Video Encapsulation frame processing
- HD Support: Both 720p HD and 360p SD video modes
- Session Management: Proper AR.Drone 2.0 session/profile/app ID handling
- Multi-threading: Background video and navigation data processing
| Feature | HD Mode | SD Mode |
|---|---|---|
| Resolution | 1280ร720 | 640ร360 |
| Codec | H.264 (ID: 131) | H.264 (ID: 129) |
| Bitrate | 4 Mbps | 1 Mbps |
| FPS | 30 | 30 |
| Format | numpy arrays | numpy arrays |
- Python 3.6+ (Python 3.12.3 recommended)
- ffmpeg (for H.264 video decoding)
- AR.Drone 2.0 with firmware 2.4.8+
# Clone the repository
git clone https://github.com/DaTiC0/python-ardrone-2.0.git
cd python-ardrone-2.0
# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install numpy pygame
# Install ffmpeg (for video decoding)
# Ubuntu/Debian: sudo apt install ffmpeg
# macOS: brew install ffmpeg
# Windows: Download from https://ffmpeg.org/
# Test with mock mode
python demo_hd.py --mock
# Run with real drone
python demo_hd.pyfrom libardrone import ARDrone2
# HD video with context manager
with ARDrone2(hd_video=True) as drone:
# Takeoff and basic flight
drone.takeoff()
# Get real-time video (numpy array)
image = drone.get_image() # Shape: (720, 1280, 3) for HD
# Get navigation data
navdata = drone.get_navdata()
battery = drone.get_battery()
altitude = drone.get_altitude()
roll, pitch, yaw = drone.get_attitude()
# Flight controls
drone.move(roll=0.1, pitch=0.1, yaw=0.1, gaz=0.1)
drone.hover()
drone.land()
# Mock mode for testing
with ARDrone2(mock=True) as drone:
print("Testing without hardware")import libardrone
# Original API still works
drone = libardrone.ARDrone()
drone.takeoff()
drone.move_forward()
drone.land()
drone.halt()from libardrone import ARDrone2, H264Decoder, PAVEParser
# Custom video processing
decoder = H264Decoder(frame_size=(1280, 720))
parser = PAVEParser()
# Advanced configuration
drone = ARDrone2(
ip='192.168.1.1',
hd_video=True, # 720p HD mode
mock=False # Use real hardware
)
with drone:
# Check systems status
print(f"Video ready: {drone.is_video_ready()}")
print(f"Flying: {drone.is_flying()}")
print(f"Emergency: {drone.is_emergency()}")
# Real-time monitoring
while True:
navdata = drone.get_navdata()
if navdata:
print(f"Battery: {navdata.vbat_flying_percentage}%")
print(f"Altitude: {navdata.altitude}mm")
break# HD video with full interface
python demo_hd.py
# SD video mode
python demo_hd.py --sd
# Mock mode for testing
python demo_hd.py --mock
# Custom IP address
python demo_hd.py --ip 192.168.1.100| Key | Action | Key | Action |
|---|---|---|---|
| Space | Takeoff/Land | E | Emergency Stop |
| Arrow Keys | Move | A/D | Rotate Left/Right |
| W/S | Up/Down | Q | Quit |
python demo.py # Original demo (still works)libardrone/
โโโ __init__.py # Main package exports
โโโ ardrone.py # ARDrone2 main class
โโโ arnetwork.py # Network management
โโโ at.py # AT command interface
โโโ h264decoder.py # H.264 video decoder
โโโ navdata.py # Navigation data parser
โโโ paveparser.py # PAVE video frame parser
- ARDrone2: Main control class with HD video and threading
- ARNetworkManager: Socket handling with session management
- H264Decoder: ffmpeg-based video decoding with mock fallback
- PAVEParser: Parrot Video Encapsulation frame extraction
- NavDataDecoder: Complete navigation data parsing
- AT Commands: Low-level drone communication
- No video output: Install ffmpeg, check network connection
- Poor video quality: Try SD mode with
--sdflag - Video lag: Ensure strong WiFi signal, reduce bitrate if needed
- Can't connect: Verify AR.Drone WiFi network connection
- "Not connected to drone" error: This has been fixed in the latest version - ensure you're using the updated library
- Port conflicts: Use
python cleanup_ports.pyto resolve port binding issues - Connection timeout: Check that drone IP is
192.168.1.1and ports 5554-5556 are accessible - Emergency state: Use emergency reset before takeoff
# Test basic connectivity
python test_connection.py
# Clean up port conflicts if needed
python cleanup_ports.py
# Run with mock mode for testing
python demo_hd.py --mock- HD video requires good WiFi signal and processing power
- Mock mode for development without hardware
- SD mode for lower bandwidth/processing requirements
connect()- Connect to dronedisconnect()- Disconnect and cleanup- Context manager support with
withstatement
takeoff()- Take offland()- Landemergency()- Emergency stopmove(roll, pitch, yaw, gaz)- Move with specified controlshover()- Hover in place
get_image()- Get latest video frame (numpy array)get_navdata()- Get navigation data objectget_battery()- Get battery percentageget_altitude()- Get altitude in mmget_attitude()- Get (roll, pitch, yaw) in degreesget_velocity()- Get (vx, vy, vz) in mm/s
is_flying()- Check if drone is flyingis_emergency()- Check emergency stateis_video_ready()- Check video system status
This repository represents the evolution of AR.Drone Python libraries:
-
Original Library: venthur/python-ardrone
- Created by Bastian Venthur
- Basic AR.Drone 1.0/2.0 support
- Python 2.x compatible
-
AR.Drone 2.0 Fork: python-ardrone-master
- Enhanced by Adrian Taylor and others
- AR.Drone 2.0 specific improvements
- H.264 decoder and HD video support
- Advanced PAVE parsing
-
This Repository: DaTiC0/python-ardrone-2.0
- Integrated best features from both repositories
- Full Python 3 compatibility
- Modular architecture
- Modern API design
- Comprehensive testing and documentation
Contributions are welcome! Areas for improvement:
- Video Codecs: Additional codec support
- Navigation: Enhanced autonomous flight features
- Testing: More comprehensive test coverage
- Documentation: API examples and tutorials
- Performance: Optimization for different hardware
This software is published under the terms of the MIT License.
- Bastian Venthur (venthur) - Original python-ardrone implementation
- Adrian Taylor - AR.Drone 2.0 enhancements, H.264 decoder, and PAVE parser
- Andreas Bresser - AR.Drone 2.0 improvements and testing
- AR.Drone Community - Continued support and development
- Contributors - Everyone who helped modernize this library for Python 3 import libardrone import time
drone = libardrone.ARDrone() drone.enable_video_stream() time.sleep(3) # Wait for initialization
if 'drone_state' in drone.navdata: state = drone.navdata['drone_state'] print(f"Video enabled: {state.get('video_mask', 0)}") print(f"Video thread: {state.get('video_thread_on', 0)}")
if drone.image: print(f"Video working! Frame size: {len(drone.image)} bytes") else: print("No video data received")
drone.halt()
**For complete documentation, installation, and API reference, see the full README content below.**
---
## ๐ฆ Installation
### Quick Start
```bash
# Clone the repository
git clone https://github.com/DaTiC0/python-ardrone-2.0.git
cd python-ardrone-2.0
# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install pygame
# Run the demo
python demo.py
- Python 3.12+ (Python 2 no longer supported)
- Pygame 2.x (for the demo application)
- AR.Drone with firmware 1.5.1 (unmodified)
import libardrone
# Connect to drone
drone = libardrone.ARDrone()
# Basic flight operations
drone.takeoff() # Automatically resets emergency state
drone.hover()
drone.move_forward()
drone.turn_left()
drone.land()
drone.halt() # Clean shutdown
# Access live data
image = drone.image # Latest camera frame
navdata = drone.navdata # Navigation/telemetry dataRun the demo with: python demo.py
| Key | Action |
|---|---|
| RETURN | Takeoff (with auto emergency reset) |
| SPACE | Land |
| BACKSPACE | Manual emergency reset |
| W/S | Move forward/backward |
| A/D | Move left/right |
| โ/โ | Adjust altitude |
| โ/โ | Turn left/right |
| 1-0 | Set speed (0.1 to 1.0) |
| T | Toggle test pattern (video testing) |
| ESC | Exit application |
- Test the video system: Press T in the demo to show test pattern
- Check connection: Ensure you're connected to AR.Drone WiFi
- Verify IP: Drone should be accessible at
192.168.1.1 - Check diagnostics: Demo shows connection status and data availability
- The library now automatically resets emergency state before takeoff
- If takeoff still fails: Press BACKSPACE then RETURN
- Emergency landing can be triggered with BACKSPACE
- The library now uses
SO_REUSEADDRfor better port handling - Use Ctrl+C for graceful shutdown to prevent port conflicts
- Connect to AR.Drone WiFi network (usually named
ardrone2_...) - Verify drone IP: Should be
192.168.1.1 - Ensure ports 5554-5556 are not blocked by firewall
- Run the demo:
python demo.py
- Fixed all
printstatements to use parentheses - Changed
raw_input()toinput() - Fixed integer division operators (
/โ//) - Updated socket communication to handle bytes properly
- Fixed string/bytes handling in struct operations
- Auto-reset takeoff: Eliminates manual emergency reset needs
- Better error handling: Graceful degradation when drone not connected
- Improved demo: Shows instructions and connection status
- Test patterns: Video system verification without real drone
- Diagnostic info: Real-time connection and data status
This repository is a modernized fork of the original AR.Drone Python library:
- Original: venthur/python-ardrone
- AR.Drone 2.0 Fork: python-ardrone-master
- This fork: DaTiC0/python-ardrone-2.0
This software is published under the terms of the MIT License.
Contributions are welcome! Please feel free to:
- Report bugs and issues
- Suggest new features
- Submit pull requests
- Improve documentation
- Thanks to venthur for the original implementation
- AR.Drone community for continued support and development
- Contributors who helped modernize this library for Python 3