A 1D Digital Twin for Control Systems and Mission Logic.
Quadcopter-Sim-V1 is a modular 1D flight simulator designed to bridge the gap between high-level autonomous mission planning and low-level physical control. It implements a full robotics stack—from custom DSL parsing to recursive state estimation.
The project is divided into four distinct layers, mirroring the architecture of industrial flight stacks:
graph TD
subgraph Mission Control
A[Mission DSL Parser] -->|Target Altitude| B(PID Controller)
end
subgraph Physics & Environment
B -->|Thrust Command| C[Newtonian Physics Engine]
C -->|True Altitude| D{Gaussian Sensor Noise}
end
subgraph Perception
D -->|Raw Measurement| E(Kalman Filter)
E -->|Clean State Estimate| B
end
- Mission Layer (
parser.py): A stateful interpreter for "DroneScript" (a custom DSL). It handles time-based (WAIT) and position-based (MOVE) commands using a Finite State Machine logic. - Estimation Layer (
drone_sim.py): A Linear Kalman Filter that suppresses Gaussian sensor noise to recover the "Ground Truth" altitude. - Control Layer (
drone_sim.py): A PID feedback loop with gravity feed-forward compensation for stable vertical positioning. - Physics Layer (
main.py): A Newtonian engine using Euler Integration to solve for acceleration, velocity, and position in discrete time steps.
The following plot captures a full mission sequence including Takeoff, Hover/Wait, and Landing.
- Filtering: The Kalman Filter successfully dampens sensor noise, providing a smooth state estimate for the PID controller.
-
Transient Response: There is a slight overshoot during rapid altitude changes, which can be further optimized by tuning the
$K_d$ (Derivative) gain in future iterations.
The simulator implements a recursive Bayesian filter. It calculates the optimal state estimate by balancing the physics-based prediction with noisy sensor telemetry.
The Kalman Gain (
Where:
-
$P_{p}$ : Prediction error covariance. -
$R$ : Measurement noise covariance (sensor uncertainty).
Altitude stability is maintained through a PID control law. The required thrust
-
Proportional (
$K_p$ ): Minimizes current altitude error. -
Integral (
$K_i$ ): Eliminates steady-state error (gravity offset). -
Derivative (
$K_d$ ): Dampens oscillations by predicting future error.
The simulation environment approximates Newtonian motion in discrete steps (
-
Net Force:
$F = T - mg$ -
Velocity Update:
$v_{k+1} = v_k + (\frac{F}{m}) \Delta t$ -
Position Update:
$p_{k+1} = p_k + v_{k+1} \Delta t$
Testing autonomous flight logic requires massive scale. By containerizing this SITL engine, we can deploy it as a Kubernetes batch job to run hundreds of simultaneous Monte Carlo simulations, testing different PID tunings in parallel.
# 1. Build the headless simulator image
docker build -t quadcopter-sitl .
# 2. Run the simulation and extract the telemetry plot via volume mount
docker run --rm -v $(pwd)/assets:/app/data quadcopter-sitl
- Phase B: Transition to 6-DOF Dynamics using Quaternions/Euler Angles.
- Phase C: Formal Lexer/Tokenization for complex mission grammars using Regex.
- Phase D: Asynchronous Failsafe Interrupts for emergency landing scenarios.
- Phase E (Cloud): Kubernetes Job manifest generation for parallelized genetic algorithm tuning of the PID controller.
# Clone the repository
git clone [https://github.com/alfayezahmad/Quadcopter-Sim-V1.git](https://github.com/alfayezahmad/Quadcopter-Sim-V1.git)
cd Quadcopter-Sim-V1
# Install dependencies
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
# Run simulation
python src/main.py
This project is licensed under the MIT License - see the LICENSE file for details.
