Skip to content

Latest commit

 

History

40 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Autonomous UAV Avionics & Flight-Control Stack

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.


System Architecture

The repository implements an end-to-end autonomous flight-control software stack. The control pipeline is validated at two complementary levels:

  1. Custom Nonlinear 6-DOF simulation for controller implementation and algorithm validation.
  2. 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]
Loading

Repository Structure

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

Build and Test

Prerequisites

  • Ubuntu 22.04 LTS (tested)
  • CMake ≥ 3.22
  • GCC/G++ ≥ 11
  • Python 3
  • PX4 SITL + Gazebo Harmonic (for flight validation)
  • QGroundControl (mission planning)

Clone

git clone https://github.com/Vaiy108/autonomous-uav-avionics-control-stack.git
cd autonomous-uav-avionics-control-stack

Configure and Build

mkdir build
cd build

cmake ..
make -j$(nproc)

Run

Run the Avionics Demo

./avionics_demo

Run Flight-Control Examples

./closed_loop_attitude_demo
./position_hold_6dof_demo
./closed_loop_6dof_demo

Run Unit Tests

ctest --output-on-failure

Build & Unit Test Validation

build_and_unit_tests

build_and_unit_tests_results

The clean build completed successfully, and all 7/7 flight-control unit tests passed.

PX4 SITL Validation

Start PX4 SITL with Gazebo:

cd ~/Projects/PX4-Autopilot

make px4_sitl gz_x500

Launch 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.py

The 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.


Software Stack

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

Verification Workflow

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]
Loading

Project Highlights

  • 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

Key Capabilities

  • 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

6-DOF Closed-Loop Flight-Control Validation

The cascaded controller was evaluated using a Nonlinear 6-DOF quadrotor model.

Validation Mission

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.

Results

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.


Position Tracking

6-DOF position tracking

XY Flight Trajectory

6-DOF XY trajectory

Attitude Tracking

6-DOF attitude tracking

Altitude Hold

6-DOF altitude hold


PX4 SITL / Gazebo Autonomous Flight Validation

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.

Validation Architecture

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.

Autonomous Mission

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.

Mission Plan

PX4 SITL autonomous mission plan

Autonomous Mission Execution

PX4 Gazebo autonomous mission execution

The mission was executed using the PX4 x500 multicopter model in Gazebo, with QGroundControl providing mission planning and vehicle monitoring.


uORB Runtime Inspection

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 estimate
  • vehicle_gps_position — simulated GNSS position and velocity
  • vehicle_status — arming and navigation state
  • vehicle_attitude — estimated vehicle orientation
  • actuator_motors — normalized motor commands

Local Position

PX4 uORB local position

GNSS Position

PX4 uORB GNSS position

Vehicle Status

PX4 uORB vehicle status

Motor Commands During Flight

PX4 uORB 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.


PX4 ULog Flight-Performance Analysis

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.

Quantitative Results

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.

Local Position Tracking

PX4 SITL local position tracking

The measured local X/Y trajectory closely follows the PX4 position setpoints through outbound waypoint navigation and the return trajectory.

Altitude Tracking

PX4 SITL altitude tracking

The altitude response captures the initial waypoint-flight altitude, the higher PX4 RTL altitude, and the final autonomous descent.

Attitude Tracking

PX4 SITL attitude tracking

Measured roll and pitch closely follow their respective attitude setpoints during acceleration, waypoint transitions, and RTL.

Motor Commands

PX4 SITL motor commands

The four motor commands show differential control activity during maneuvers while remaining below saturation throughout the mission.

PX4 Validation Summary

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:

  1. Custom C++ flight-control simulation for controller implementation, vehicle dynamics, actuator modelling, and algorithm-level analysis.
  2. PX4 SITL / Gazebo validation for autopilot integration, autonomous mission execution, uORB inspection, and flight-log-based system validation.

Project Status

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

👤 Author

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

About

Autonomous UAV avionics and flight-control stack with C++17 cascaded control, nonlinear 6-DOF simulation, PX4 SITL/Gazebo validation, uORB inspection, and ULog flight analysis.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages