This project provides a Python-based controller for operating a drone in AirSim simulation environment, typically integrated with Unreal Engine 4 (UE4). The script allows real-time keyboard control of a virtual drone for testing and development purposes.
- Real-time keyboard control of drone movement
- Intuitive control scheme:
W/S: Move forward/backwardA/D: Move left/right↑/↓(Arrow keys): Ascend/descendQ/E: Rotate left/rightESC: Land and exitC: Capture and save current camera viewY: Send current camera view to YOLO object detection model
- Live camera feed display during flight
- Automatic image saving with sequential numbering
- YOLO object detection integration (requires separate YOLO server)
- Smooth drone movement with configurable speed settings
- Safe takeoff and landing procedures
Before running this project, ensure you have:
- Unreal Engine 4 installed
- AirSim plugin installed and configured with UE4
- Python 3.10 installed (virtual environment recommended)
- Required Python packages:
airsimkeyboardopencv-pythonnumpyrequests
-
Clone this repository:
git clone <repository-url> cd drone
-
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
- On Windows:
venv\Scripts\activate
- On macOS/Linux:
source venv/bin/activate
- On Windows:
-
Install required packages:
pip install airsim keyboard opencv-python numpy requests
-
Start your AirSim simulation environment (UE4 project with AirSim plugin)
-
(Optional) Start your YOLO object detection server on a separate port (local or cloud)
-
Update the
YOLO_SERVER_URLindrone.pyto point to your YOLO server if different from default -
Run the drone controller:
python drone.py
-
The drone will automatically takeoff and await your commands
-
Use the keyboard controls listed above to maneuver the drone
-
Press
Cto capture and save the current camera view at any time -
Press
Yto send the current camera view to the YOLO model for object detection -
Press
Qto close the live camera feed window -
Press
ESCto land the drone and exit the program
Images will be saved in the captured_images directory with sequential numbering.
You can adjust the drone's behavior by modifying these parameters in drone.py:
DRONE_SPEED: Movement speed in meters per second (default: 5)ROTATION_SPEED: Rotation speed in degrees per second (default: 45)IMAGE_DIR: Directory where captured images are saved (default: "captured_images")YOLO_SERVER_URL: URL of the YOLO object detection server (default: "http://localhost:5000/yolo")
.
├── drone.py # Main drone control script
├── README.md # This file
├── .gitignore # Git ignore rules
├── venv/ # Python virtual environment (ignored by Git)
└── captured_images/ # Directory for saved drone camera images (created automatically)
- The drone automatically lands when the program exits
- The virtual environment is excluded from Git tracking
- Ensure your AirSim simulation is running before executing the script
Feel free to fork this project and submit pull requests with improvements or bug fixes.