MISRA-Compliant ADCS Software in C++
Write flight-grade attitude control code that meets aerospace safety standards
Last reviewed: March 2026Overview
Every satellite must point accurately — antennas toward Earth, solar panels toward the Sun, instruments toward targets. The software that performs this task, the Attitude Determination and Control System (ADCS), is among the most safety-critical code on the spacecraft. A bug in the ADCS doesn't just cause incorrect pointing — it can cause uncontrolled tumbling, solar panel misalignment leading to power loss, and mission failure.
Flight software is held to standards that commercial software rarely sees. MISRA C++ (Motor Industry Software Reliability Association) is a set of coding guidelines that ban or restrict error-prone C++ features: dynamic memory allocation, exceptions, recursive functions, multiple inheritance, and more. Combined with 100% branch coverage requirements, formal code review, and static analysis, MISRA compliance is the baseline for safety-critical embedded systems in aerospace and automotive.
In this project, you'll implement a complete ADCS algorithm suite in MISRA-compliant C++: quaternion algebra, TRIAD attitude determination, B-dot detumbling, and a reaction wheel PD controller. You'll enforce MISRA compliance using Cppcheck, write unit tests with Google Test, and measure code coverage with gcov. This is the hardest software engineering project on the site — and the most directly valuable for a flight software career.
What You'll Learn
- ✓ Implement quaternion arithmetic and rotations in fixed-point-friendly C++ without dynamic allocation
- ✓ Code the TRIAD algorithm for attitude determination from two vector measurements
- ✓ Implement B-dot magnetic detumbling and reaction wheel PD attitude control laws
- ✓ Apply MISRA C++ guidelines using Cppcheck static analysis and resolve violations
- ✓ Write comprehensive unit tests with Google Test achieving 100% branch coverage on all ADCS functions
Step-by-Step Guide
Study MISRA C++ and Set Up the Toolchain
Obtain the MISRA C++:2008 standard (PDF available via purchase or institutional access). Read sections 0–5 to understand the rule categories: required rules (must never be violated), advisory rules (violated only with documented justification). Key flight software restrictions: no dynamic memory (no new/delete), no exceptions, no recursion, fixed-point math preferred over floating-point where possible.
Set up the toolchain: GCC/Clang for compilation, Cppcheck with the MISRA addon for static analysis, Google Test for unit testing, and gcov/lcov for code coverage measurement. Create a Makefile or CMake build system that runs static analysis as part of the build.
Implement Quaternion Algebra
Write a Quaternion class that implements: multiplication, conjugate, normalization, rotation of a 3-vector, conversion to/from rotation matrix, and conversion to/from Euler angles. All operations must be MISRA-compliant: no exceptions, no dynamic allocation, no virtual functions in the core math path.
Use double for attitude math (not float — the precision matters). Write a full unit test suite covering: identity quaternion behavior, round-trip conversion tests, gimbal lock cases, and numerical normalization under repeated operations. Target 100% branch coverage on the Quaternion class before moving on.
Implement TRIAD Attitude Determination
The TRIAD algorithm computes the spacecraft attitude from two measured vectors (e.g., sun direction and magnetic field vector) compared to their expected values in the inertial frame. Implement triad(v1_body, v2_body, v1_inertial, v2_inertial) -> Quaternion.
Test with synthetic data: generate a known rotation, rotate reference vectors, apply TRIAD, and verify the recovered quaternion matches the true rotation. Test with noisy measurements (add Gaussian noise to body vectors) to characterize accuracy under realistic sensor conditions.
Implement B-dot Detumbling
B-dot detumbling uses magnetorquers to damp spacecraft rotation after deployment, when the satellite may be tumbling at several degrees per second. The control law is: magnetic moment m = -k × dB/dt, where dB/dt is the time derivative of the magnetic field measured in the body frame and k is a gain constant.
Implement a B-dot controller that: reads body-frame magnetometer measurements, computes the numerical time derivative, computes the commanded magnetic moment, and clips to the maximum magnetorquer capability. Simulate the detumbling in Python (using scipy ODE solver) to validate the C++ control law produces stable damping.
Implement Reaction Wheel PD Control
For precise pointing, implement a PD attitude controller using reaction wheels. The control law: torque = -Kp × q_error_vector - Kd × omega_error, where q_error is the quaternion error between desired and current attitude and omega_error is the angular rate error.
Implement reaction wheel torque distribution using the pseudo-inverse of the wheel momentum matrix (pre-computed at compile time as a constant matrix). Test with a simulated slew maneuver: rotate from one pointing attitude to another and verify settling time and pointing accuracy meet CubeSat ADCS specifications (typically ±1° pointing accuracy).
Static Analysis and Coverage Enforcement
Run Cppcheck with MISRA addon on all source files: cppcheck --enable=all --addon=misra.py src/. Work through every violation systematically. Document any advisory rule violations with justification comments in the code (MISRA allows violations with documented rationale).
Run gcov on the complete test suite and generate an HTML coverage report with lcov. Identify any uncovered branches and write additional tests until 100% branch coverage is achieved. Submit the final code with a coverage report and MISRA compliance summary — this is exactly what flight software deliverables look like.
Career Connection
See how this project connects to real aerospace careers.
Space Operations →
CubeSat and small satellite ADCS software is a high-demand skill as the small satellite industry grows — companies like Planet, Spire, and new-space startups constantly hire flight software engineers with this background
Aerospace Engineer →
GNC engineers who can also implement their algorithms in flight-grade C++ are significantly more employable than those who can only do the math
Avionics Technician →
Flight control computer software maintenance requires understanding of the same coding standards (DO-178C in aviation, MISRA in space) that this project covers
Astronaut →
Astronauts who understand ADCS principles and flight software architecture can more effectively monitor, diagnose, and override automated attitude control during mission anomalies
Go Further
Continue toward flight-qualified software development:
- AUTOSAR / DO-178C — study how MISRA principles extend to aviation (DO-178C) and automotive (AUTOSAR) safety standards; the rules differ but the philosophy is identical
- Hardware-in-the-loop — deploy the ADCS software on a STM32 microcontroller with real magnetometer and gyroscope sensors; run the control loop at 10 Hz on actual embedded hardware
- Extended Kalman Filter — replace TRIAD (which gives one-shot estimates) with a full EKF that fuses gyroscope, magnetometer, and sun sensor measurements over time for more accurate attitude estimation
- Fault detection — add sensor fault detection logic: identify when a magnetometer reading is out of range or implausible compared to the model, and gracefully switch to the backup sensor