← Ethan Ieong

02Sep 2024 — present

Rocket Avionics and Roll Control

A flight computer that keeps a rocket from spinning. Partway up, the board decides on its own that the moment has come, powers the canard fins and starts actively cancelling the roll — knowing which way it is pointing, how high it is and how fast it is going, all estimated on board in real time.

The canards bay: decks carrying the flight computer, battery, servos and the canard fins, stacked on standoffs inside the airframe.
Where
MetRocketry Design Team
Stack
C, C++, STM32F446, FreeRTOS, Eigen, FatFs
Built with
Ranvir Singh
Source
Repository

The control cycle

Four stages run per cycle: sense, estimate, control, actuate. Sensors go in at the top and canard deflection comes out at the bottom.

Logging and telemetry hang off the state estimate rather than sitting inside the loop, so nothing downstream can stall the part that is actually flying the rocket. A slow SD write cannot delay a fin command.

FreeRTOS runs on an STM32F446, generated out of CubeMX and built with CMake and Ninja. The attitude filter is C++ with Eigen, bridged into the C tasks, and logging goes through FatFs over SDIO.

The bay in section. Flight computer on the third deck, battery above it, and the canard shafts and servo linkage on the bottom deck.

The flight state machine

The board tracks the flight on its own, using accelerometer thresholds, timers and its own velocity estimate, and moves through six states: PAD → BOOSTER_BURNOUT → SEPARATION → SUSTAINER_IGNITION → CANARDS_ACTIVATE → DESCENT.

It detects liftoff, booster burnout, stage separation and sustainer ignition, brings the canards live for exactly the window they are needed in, then recognises descent and shuts them down again. The servo power switch is cut in every state except CANARDS_ACTIVATE, so the highest-current rail on the board is only ever energised when the fins are actually flying.

The fins the state machine brings live. Canards on the lower deck, driven off the servo and linkage directly beneath the flight computer.

The task set

Each task pre-empts and runs the moment its input is ready. The watchdog is gated behind a heartbeat that polls every task, so a stalled estimator resets the board instead of flying it on a frozen state.

TaskWhat it does
readSensorReads the IMU, magnetometer and barometer, and low-pass filters them.
launchDetRuns the flight state machine and tells everything downstream.
oriEstQuaternion EKF for roll, pitch, yaw and tilt.
altEstKalman filter fusing barometer and accelerometer for altitude and vertical velocity.
controlPID roll controller driving the canard servos.
dataStoreSnapshots telemetry and writes CSV rows to the SD card.
heartbeatRefreshes the watchdog, but only once every flight task reports healthy.

Estimation and control

Attitude comes from a quaternion EKF written in C++ with Eigen. Altitude and vertical velocity come from a separate Kalman filter fusing the barometer with the accelerometer. Roll is rotation about the long axis of the rocket, which is the estimator's yaw, and the units are pinned down across the whole codebase: Pa, mg, m, m/s, degrees.

The roll controller is PID, and it drives the fins through an aerodynamic force-to-deflection model that corrects for airspeed and air density. The same control effort produces the same roll authority on the pad and at altitude, which is what lets one set of gains work across the whole flight.

The deck stack the controller acts through: servo horn and pushrod on the bottom deck, turning a commanded deflection angle into fin rotation.

Bus architecture

The IMU gets read every control cycle and feeds the attitude estimator directly. The GPS does long UBX transactions. They sit on separate buses with separate mutexes, so the attitude estimator can never end up blocked behind a navigation transfer and the control path always runs on time.

BusDeviceWhat it carries
SPI1LSM6DSO32 IMUGyro and accelerometer. Feeds the EKF; the highest-priority traffic on the board.
SPI1RFM69HCW radioTelemetry downlink. Wired and driven, not switched on yet.
SPI2MS5611 barometerAltitude and vertical velocity for the Kalman filter.
SPI2u-blox NEO-M9N GPSPosition and velocity over UBX. Driver written, not enabled in flight builds yet.
I2C1MMC5983MA magnetometerHeading reference and yaw correction.
SDIOmicroSD card, 4-bitFlight logging through FatFs, on DMA.
TIM3Two servo channelsCanard actuation, live only during CANARDS_ACTIVATE.

Where it stands

The board is built and the firmware flies. Sensor drivers, the attitude EKF, the altitude Kalman filter, launch detection and the flight state machine, PID roll control with the aerodynamic model, and SD logging are all done and exercised. Flight logs have been pulled back off the card and gone through against what the estimator thought was happening at the time.

GPS and radio are wired and driven; turning both on in flight builds is next. A new flight computer is in design for December, carrying these lessons into it — SDIO on a single package edge this time, and controlled-impedance routing planned out from the stackup at the start. The next build cycle covers roll canards, airbrakes and a live video downlink.