This repository contains the Attitude Control and Determination System (ACDS) for a CubeSat, developed as part of the PAE 2022 nanosatellite project. The ACDS is the subsystem that answers two questions for the spacecraft:
- Determination — how is the satellite oriented, and where is it? The attitude is estimated by comparing on-board sensor readings against physical reference models: the Earth's magnetic field (from the IGRF-13 model) and the satellite's orbital position (from the SGP4 propagator), expressed as a unit quaternion between the Earth-Centred-Inertial (ECI) frame and the body frame.
- Control — how do we reach and hold the desired orientation? Immediately after deployment the satellite tumbles, so a B-dot controller drives the magnetorquers to remove that spin (detumbling). Once stable, a three-axis quaternion PID controller slews the satellite to and holds a target attitude, with per-axis anti-windup on the actuator command.
The code here is the algorithmic core of the ACDS: the control laws, the attitude maths, and the reference models. It is written in portable C and can be built and run on a desktop for analysis and validation; the same routines run on the satellite's STM32/FreeRTOS on-board computer.
| Stage | Method | Where |
|---|---|---|
| Geomagnetic reference field | IGRF-13 spherical-harmonic model | src/models/igrf13syn.c |
| Orbit position / velocity | SGP4 propagation of a TLE | src/models/sgp4.c |
| Attitude representation & maths | Unit quaternions (compose, invert, axis-angle, matrix conversions) | src/help_adcs.c |
| Detumbling | B-dot control law: m = -k · dB/dt, torque = m × B |
src/adcs.c |
| Pointing | Three-axis quaternion PID with anti-windup | src/help_adcs.c (PID3Axis) |
The detumbling law needs no attitude estimate — it only reacts to the rate of change of the measured magnetic field, which makes it robust in the initial tumbling phase. Once the body rate is low, the PID controller uses the quaternion attitude error to command a torque proportional to the pointing error while respecting the actuator saturation limit.
ACDS/
├── src/
│ ├── adcs.c / adcs.h B-dot detumbling control law
│ ├── help_adcs.c / help_adcs.h quaternion maths + 3-axis PID controller
│ ├── main.c desktop demonstration harness
│ └── models/
│ ├── igrf13syn.c / .h IGRF-13 geomagnetic field model
│ └── sgp4.c / .h SGP4 orbit propagator (Vallado/CelesTrak model)
├── Makefile
├── LICENSE
└── README.md
The demonstration harness compiles as a single translation unit, so one command is enough:
make runor, equivalently:
gcc src/main.c -lm -o adcs_demo && ./adcs_demoThis runs one update of the three-axis PID controller with a representative CubeSat configuration and prints the commanded torque per axis. It requires only a C compiler and the standard maths library — no hardware.
Some routines read external data that is not bundled here, because it is either large or mission-specific:
- IGRF-13 (
igrf13()) reads its time-interpolated Gauss coefficients from agh.txtfile in the working directory. - SGP4 (
sgp4()) is initialised from a satellite's NORAD Two-Line Element (TLE) set. detumbling_sim()replays recorded magnetometer and angular-rate traces (det_mag_field.txt,det_vel_ang.txt) to validate the B-dot law offline.
The commented examples at the bottom of src/main.c show how the IGRF-13 and
SGP4 models are called.
The ACDS is one subsystem of a larger CubeSat on-board computer built on an STM32L4 microcontroller running FreeRTOS. This repository isolates the attitude determination and control algorithms so they can be read, reused and validated independently of the flight firmware.
The IGRF-13 geomagnetic field and the SGP4 orbit propagator are standard, widely-used aerospace models; the implementations here follow those published references (SGP4 following the Vallado/CelesTrak algorithm).
Developed by Alex Melendez Ramos and Albert Fàbregas.
Released under the MIT License — see LICENSE.