A C++17 autonomous UAV flight-control software stack demonstrating cascaded position, attitude and altitude control, actuator allocation, nonlinear 6-DOF rigid-body simulation, and PX4/Gazebo Software-in-the-Loop (SITL) validation.
The project implements a modular autonomous UAV flight-control software stack and validates it using both a custom nonlinear 6-DOF simulation and the PX4/Gazebo Software-in-the-Loop environment:
Position Command → Position Controller → Attitude Controller → Motor Mixer → Actuator Model → 6-DOF Vehicle Dynamics → State Feedback
The implementation is designed as a modular Software-in-the-Loop development and validation environment for small autonomous UAS.
The repository implements an end-to-end autonomous flight-control software stack. The control pipeline is validated at two complementary levels:
- Custom Nonlinear 6-DOF simulation for controller implementation and algorithm validation.
- PX4/Gazebo Software-in-the-Loop (SITL) for autopilot integration, autonomous mission execution, and flight-log-based verification.
flowchart LR
A[Mission or Position Setpoint] --> B[Position Controller]
B --> C[Attitude Controller]
C --> D[Control Allocation / Motor Mixer]
D --> E1[Custom Actuator Model]
E1 --> F1[Custom Nonlinear 6-DOF Plant]
F1 --> G1[State Feedback]
G1 --> B
D --> E2[PX4 / Gazebo SITL]
E2 --> F2[Simulated IMU and GNSS]
F2 --> G2[EKF2 State Estimation]
G2 --> H[uORB Middleware]
H --> B
H --> I[ULog Flight Logger]
I --> J[Python Flight Analysis]
autonomous-uav-avionics-control-stack/
├── src/
│ ├── application/
│ ├── control/
│ ├── actuation/
│ ├── simulation/
│ ├── drivers/
│ ├── middleware/
│ ├── platform/
│ └── services/
├── include/
│ └── avionics/
├── tests/
│ └── unit/
├── analysis/
│ └── px4/
├── docs/
├── examples/
├── firmware/
│ └── stm32/
├── CMakeLists.txt
└── README.md
- Ubuntu 22.04 LTS (tested)
- CMake ≥ 3.22
- GCC/G++ ≥ 11
- Python 3
- PX4 SITL + Gazebo Harmonic (for flight validation)
- QGroundControl (mission planning)
git clone https://github.com/Vaiy108/autonomous-uav-avionics-control-stack.git
cd autonomous-uav-avionics-control-stackmkdir build
cd build
cmake ..
make -j$(nproc)./avionics_demo./closed_loop_attitude_demo
./position_hold_6dof_demo
./closed_loop_6dof_democtest --output-on-failureThe clean build completed successfully, and all 7/7 flight-control unit tests passed.
Start PX4 SITL with Gazebo:
cd ~/Projects/PX4-Autopilot
make px4_sitl gz_x500Launch QGroundControl and upload the mission.
After the mission completes, copy the generated .ulg flight log into:
results/px4/Run the Post-flight analysis:
python3 analysis/analyze_px4_ulog.pyThe script automatically computes:
- Flight duration
- Position RMSE
- Altitude RMSE
- Roll/Pitch tracking RMSE
- Motor command utilization
- Motor saturation statistics
and generates the validation plots shown below.
The repository has been verified to build successfully from a clean clone on Ubuntu 22.04 using CMake and GCC 11.
| Component | Technology |
|---|---|
| Programming Language | C++17 |
| Build System | CMake |
| Unit Testing | Standalone C++ unit tests |
| Vehicle Simulation | Custom Nonlinear 6-DOF |
| Autopilot | PX4 |
| Physics Engine | Gazebo |
| Mission Planning | QGroundControl |
| Middleware | PX4 uORB |
| Flight Logging | ULog |
| Post-processing | Python + PyULog + Matplotlib |
| Development Platform | Ubuntu 22.04 |
The project follows a layered validation strategy similar to industrial flight-control software development.
flowchart TD
A[Controller Implementation]
--> B[Unit Tests]
B --> C[Closed-loop 6-DOF Simulation]
C --> D[PX4 SITL Integration]
D --> E[uORB Runtime Inspection]
E --> F[ULog Flight Analysis]
F --> G[Build and Regression Verification]
- Custom C++17 Non-linear 6-DOF flight-control simulation
- PX4/Gazebo autonomous mission validation
- 7/7 flight-control unit tests passing
- ULog-based commanded-versus-measured performance analysis
- Embedded-oriented C++17 flight-control implementation
- Cascaded XY position, attitude and altitude control
- PID control with output limiting and integral protection
- X-configuration quadrotor motor mixing
- Motor/actuator thrust and torque modelling
- Nonlinear 6-DOF rigid-body vehicle dynamics
- Quaternion-based attitude propagation
- Translational and rotational dynamic coupling
- Closed-loop mission simulation
- Quantitative flight-performance analysis
- Unit and integration testing
- PX4 SITL / Gazebo validation environment
The cascaded controller was evaluated using a Nonlinear 6-DOF quadrotor model.
Initial vehicle state:
- Position:
(0, 0, 1 m) - Level attitude
- Zero translational velocity
Commanded position:
- X:
5 m - Y:
3 m - Altitude:
1 m
The outer position controller generates roll and pitch commands, which are tracked by the inner attitude controller. The altitude controller independently regulates collective thrust.
| Metric | Result |
|---|---|
| Position target | 5.0 m X / 3.0 m Y |
| Final position | 5.020 m X / 3.032 m Y |
| Final horizontal position error | 0.038 m |
| X overshoot | 11.74% |
| Y overshoot | 12.96% |
| X settling time (2%) | 8.36 s |
| Y settling time (2%) | 8.75 s |
| Final altitude | 1.00045 m |
| Minimum altitude | 0.969 m |
| Maximum altitude | 1.007 m |
| Maximum attitude excursion | ~13.5° |
| Motor saturation | None |
The vehicle converges to the commanded horizontal position while maintaining approximately 1 m altitude and returning to near-level attitude at the target.
The flight-control work was extended to an industry-standard PX4 Software-in-the-Loop (SITL) environment using Gazebo and QGroundControl.
A simulated PX4 x500 quadrotor was used to execute an autonomous waypoint mission while vehicle state, estimator outputs, navigation status, and actuator commands were inspected through PX4 uORB topics. The resulting PX4 ULog was then processed offline to quantitatively evaluate closed-loop flight performance.
The PX4 validation path is:
QGroundControl Mission → PX4 Navigation → Position / Attitude Control → Control Allocation → Gazebo Vehicle Dynamics → Simulated Sensors → EKF2 State Estimation → uORB State Feedback
This complements the custom C++ 6-DOF simulation by validating autonomous flight behavior using the PX4 autopilot software stack and a physics-based simulation environment.
The mission was created in QGroundControl and consisted of:
- autonomous takeoff
- waypoint navigation
- altitude-controlled flight
- multi-waypoint trajectory execution
- Return-to-Launch (RTL)
- autonomous descent and landing
The vehicle initially climbed to approximately 5 m for waypoint navigation. During the return sequence, PX4 commanded the configured RTL altitude before descending back to the launch position.
The mission was executed using the PX4 x500 multicopter model in Gazebo, with QGroundControl providing mission planning and vehicle monitoring.
PX4's uORB middleware was inspected during SITL operation to verify the flow of navigation, state-estimation, vehicle-status, and actuator data.
The following topics were examined:
vehicle_local_position— EKF local position and velocity estimatevehicle_gps_position— simulated GNSS position and velocityvehicle_status— arming and navigation statevehicle_attitude— estimated vehicle orientationactuator_motors— normalized motor commands
The in-flight actuator inspection confirms that individual motor commands are actively modulated by the PX4 control and allocation pipeline during waypoint tracking.
The PX4 ULog generated during the autonomous mission was parsed using
PyULog. Commanded setpoints were compared against estimated vehicle
states over the detected flight interval.
| Metric | Result |
|---|---|
| Autonomous flight duration | 104.56 s |
| Maximum horizontal displacement | ~134 m |
| Maximum altitude | ~30 m |
| Horizontal position RMSE | 0.139 m |
| Vertical position RMSE | 0.044 m |
| Roll tracking RMSE | 1.323° |
| Pitch tracking RMSE | 1.080° |
| Maximum motor command | 0.889 |
| Motor saturation samples | 0 |
The results show close agreement between commanded and estimated vehicle states throughout the autonomous mission. Position and altitude tracking remain accurate through waypoint navigation and RTL, while the attitude controller follows roll and pitch commands generated during trajectory changes.
No motor saturation was observed during the analyzed flight.
The measured local X/Y trajectory closely follows the PX4 position setpoints through outbound waypoint navigation and the return trajectory.
The altitude response captures the initial waypoint-flight altitude, the higher PX4 RTL altitude, and the final autonomous descent.
Measured roll and pitch closely follow their respective attitude setpoints during acceleration, waypoint transitions, and RTL.
The four motor commands show differential control activity during maneuvers while remaining below saturation throughout the mission.
The PX4 SITL campaign demonstrates the complete autonomous-flight validation workflow:
Mission Planning → Autonomous Execution → State Estimation → Flight Control → Actuator Allocation → Physics Simulation → Flight Logging → Post-Flight Performance Analysis
Together with the custom Nonlinear 6-DOF simulation, this provides two complementary validation layers:
- Custom C++ flight-control simulation for controller implementation, vehicle dynamics, actuator modelling, and algorithm-level analysis.
- PX4 SITL / Gazebo validation for autopilot integration, autonomous mission execution, uORB inspection, and flight-log-based system validation.
Current implementation includes:
- ✔ Cascaded position and attitude controller
- ✔ Motor mixer
- ✔ Actuator model
- ✔ Nonlinear 6-DOF quadrotor dynamics
- ✔ Closed-loop simulation
- ✔ Unit tests
- ✔ PX4 SITL autonomous mission validation
- ✔ uORB middleware inspection
- ✔ ULog Post-flight analysis
Planned future work:
- ROS 2 integration
- PX4 custom flight modes
- Hardware-in-the-loop (HIL)
- Optical-flow navigation
- Visual-Inertial Odometry (VIO)
- SLAM-based autonomous navigation
Vasan Iyer
GNC / Embedded Systems Engineer
Focus areas:
- Embedded systems: C++ and Python
- Guidance, navigation and control
- Flight dynamics and control
- Sensor fusion and state estimation
- Autonomous systems
- UAV systems
GitHub: https://github.com/Vaiy108










