A Unity-based quadcopter/drone physics simulation implementing advanced PID control systems for realistic flight dynamics.
- Realistic Physics Simulation: Uses Unity's physics engine with Rigidbody components for accurate drone behavior
- PID Control Systems: Multiple PID controllers for position, velocity, and angular velocity control
- Quadcopter Dynamics: Four-propeller system with individual thrust control and torque calculations
- 3D Flight Control: Full six degrees of freedom (6DOF) movement including translation and rotation
- Visual Debugging: Debug visualization of force vectors, velocity projections, and control outputs
- Modular Architecture: Multiple control implementations (basic and advanced versions)
- Single-axis vertical stabilization
- PID control for height/altitude maintenance
- Real-time velocity calculation and error correction
- Four independent PID controllers for propeller thrust
- Angular velocity stabilization (pitch, roll, yaw)
- Velocity mapping and projection onto propeller axes
- Torque compensation for rotational stability
- Height control with integral windup protection
- Six-degree-of-freedom control using Euler angles
- Position and orientation stabilization
- Advanced PID cascade for translation and rotation
- Direct angle-based control for precise maneuvers
- IMU simulation with sensor noise modeling
- Kalman filtering for state estimation
- Averaging filters for signal smoothing
- Gaussian noise simulation for realistic sensor data
- Advanced state estimation and control
- Force Application: Realistic thrust vector application at propeller positions
- Torque Calculation: Angular momentum effects from propeller forces
- Velocity Projection: Mathematical projection of drone velocity onto propeller axes
- PID Tuning: Configurable proportional, integral, and derivative gains
- Wind Simulation: Optional environmental forces for realistic conditions
| Key | Action |
|---|---|
↑ |
Move Forward |
↓ |
Move Backward |
← |
Move Left |
→ |
Move Right |
Space |
Ascend |
C |
Descend |
K |
Rotate Counterclockwise |
J |
Rotate Clockwise |
- Unity 2020.3 or later
- Windows/macOS/Linux
-
Clone the repository:
git clone https://github.com/mihasm/unity-drone-control.git
-
Open the project in Unity:
- Launch Unity Hub
- Click "Open" and select the cloned repository folder
- Select the appropriate Unity version
-
Open the SampleScene:
- Navigate to
Assets/Scenes/ - Open
SampleScene.unity
- Navigate to
-
Configure the drone:
- Select the drone GameObject in the scene
- Attach one of the controller scripts:
Kontrola.cs: Basic vertical stabilizationKontrola2.cs: Full quadcopter control (recommended)Kontrola3.cs: Euler angle-based controlKontrola4.cs: Advanced control with Kalman filtering
- Adjust PID parameters in the Inspector for desired behavior
The repository includes four different drone control implementations, each demonstrating different approaches to flight control:
- Kontrola.cs: Start here for basic PID concepts
- Kontrola2.cs: Production-ready quadcopter control
- Kontrola3.cs: Alternative control using Euler angles
- Kontrola4.cs: Advanced control with sensor simulation
- Create a GameObject with a Rigidbody component
- Add a collider (BoxCollider recommended for drone body)
- Attach one of the controller scripts:
Kontrola.cs: Simple vertical controlKontrola2.cs: Full quadcopter controlKontrola3.cs: Euler angle controlKontrola4.cs: Kalman filter enhanced control
- Position four child objects at propeller locations (for advanced controllers)
- Run the scene and use keyboard controls to fly
Adjust the PID gains in the Inspector:
- Kp (Proportional): Response to current error
- Ki (Integral): Correction of steady-state error
- Kd (Derivative): Prediction of future error
- Output Attenuation: Scaling factor for control output
The advanced controller (Kontrola2.cs) provides visual debugging:
- Red Lines: Thrust force vectors
- Blue Lines: Projected velocity vectors
- Green Lines: Torque vectors
- GUI Display: Real-time PID component values
Assets/
├── Scenes/
│ ├── SampleScene.unity # Main demo scene
│ ├── Kontrola.cs # Basic PID controller
│ ├── Kontrola2.cs # Advanced quadcopter controller
│ ├── Kontrola3.cs # Euler angle control system
│ └── Kontrola4.cs # Kalman filter enhanced control
└── Terrain/
└── New Terrain.asset # Terrain for outdoor simulation
- Thrust Forces: Applied at propeller positions with realistic force magnitudes
- Torque Effects: Counter-rotating propellers create stabilizing moments
- Velocity Mapping: Linear algebra projections for axis-specific control
- Time Integration: FixedUpdate-based control loop with dt calculations
The controllers use standard PID formula:
output = Kp * error + Ki * ∫error dt + Kd * d(error)/dt
With additional features:
- Integral windup prevention through clamping
- Bias terms for baseline thrust
- Separate PID loops for different control axes
This project demonstrates advanced control systems and physics simulation techniques in Unity. Key learning areas include:
- PID control theory and implementation
- 3D rigidbody physics
- Quaternion mathematics for rotation
- Vector projections and transformations
- Real-time control system design
This project is open source and available under the MIT License.