Aerospace · Oct 2025 to now
A rocket that steers itself
Most model rockets stay straight because of their fins. Mine has none. Left alone it would flip over, so the only way to keep it pointed up is to steer the motor itself, 200 times a second. I designed the rocket, built a 6-degree-of-freedom simulator for it, and trained a neural network from scratch to fly it.
Independent researcher and engineer. Aiming for publication in the Journal of Emerging Investigators.
Ground control

Flight states
- Pad. Armed and waiting. Go/no-go checks must pass: link, IMU, barometer, level on the pad (under 2°), battery above 7.4 V, servo sweep done, chute release tested.
- Countdown. A T-10 countdown started from the ground station.
- Powered. Motor burning. The controller runs 200 times a second, tilting the nozzle to hold the rocket vertical.
- Coast. Motor out. There is no thrust to steer with, so the gimbal returns to centre.
- Descent. The parachute is released and the rocket comes down.
The rocket

- The airframe is 601 mm long, 76 mm wide and finless. Its centre of pressure sits well ahead of its centre of gravity, so it is aerodynamically unstable.
- An Estes F15 motor sits in a two-axis gimbal driven by two SG90 servos through a linkage geared about 5.7:1. The nozzle can tilt up to ±7°.
- The avionics bay holds an ESP32 flight computer, an IMU (gyroscope and accelerometer) and a BMP280 barometric altitude sensor.
- A spring-loaded piston pushes the parachute out when the flight computer releases it at apogee.
- Every part was designed in Onshape so the airframe, mount and electronics fit together before printing.

Inside, top to bottom
- Nose cone, hollow to keep weight low at the top.
- Chute bay between the two purple bulkheads, where the parachute is packed.
- Chute release on the lower bulkhead: the piston and spring that push the chute out.
- Avionics sled in green, carrying the flight computer, IMU, barometer and battery.
- TVC mount in orange, holding the gimbal and its two servos.
- Motor in red, sitting in the gimbal so it can tilt on two axes.
1. How tilting the motor steers
The motor pushes with thrust . Tilt it by a small gimbal angle and part of that thrust pushes sideways. Because the gimbal sits a distance below the centre of mass, that sideways push turns the rocket.
is the turning torque, is the rocket's moment of inertia about its centre of mass, and is the angular acceleration. More thrust or a longer lever arm gives more control authority; a heavier, longer rocket responds more slowly.
The gimbal is limited to , so the controller's output is clamped:
The rocket can only be steered while the motor is burning. After burnout and the gimbal has nothing to push with.
Climbing straight. The nozzle is centred and all the thrust pushes up.
2. Knowing which way is up
To correct tilt, the flight computer first has to measure it. The IMU's gyroscope reports angular rate . Starting from a gravity-levelled reference taken on the pad, integrating rate over time gives orientation, which the flight computer stores as a unit quaternion instead of three angles. Quaternions don't suffer from gimbal lock and are cheap to update.
From the computer rotates the rocket's nose axis into the world frame and reads off how far it leans toward X and toward Z. Those two tilt angles, and , are what the controller drives to zero.
3. The PID controller
Each axis has its own controller. The error is the measured tilt, since the target is , straight up. The gimbal command is the sum of three terms:
- Proportional pushes back harder the further the rocket leans.
- Integral removes a steady lean, such as from an off-centre motor or a crooked mount.
- Derivative uses the gyro's rate to brake the correction before it overshoots.
On the flight computer it runs in discrete steps of length :
Using the gyro rate for the derivative term avoids the noise of differencing tilt measurements. The PID has three jobs in this project: it's the baseline the network is measured against, the teacher the network first learns from, and the fallback that stays in the firmware.
4. Altitude: barometer plus Kalman filter
The BMP280 measures air pressure . Pressure falls predictably with height, so altitude above the pad comes from the barometric formula, with measured on the pad:
Raw barometer readings are noisy, and the accelerometer drifts if you integrate it. A Kalman filter combines the two. Its state is height and vertical speed, . It predicts forward using the measured vertical acceleration , then corrects toward the barometer reading:
is the Kalman gain: it decides how much to trust the barometer versus the prediction, based on the noise levels and . The filtered vertical speed is what the flight computer watches for apogee. When crosses zero the rocket has stopped climbing, and it's time to release the chute.
5. The brain: a neural-network flight controller
What the network sees and does
Every control cycle, the flight computer boils the rocket's state down to six numbers:
- Tilt error : how far, and in which direction, the rocket would have to rotate to be vertical again.
- Angular rate : how fast it is rotating right now, straight from the gyro.
- Integrated error : tilt error accumulated over the burn and clamped, which lets it correct slow, persistent biases like a slightly crooked motor.
Each input is divided by a typical magnitude so all six sit around and none swamps the others. The network outputs the nozzle angle for each gimbal axis, and the firmware converts those into servo commands through the linkage gearing.
Architecture
A small fully connected network: 6 inputs, two hidden layers of 16 neurons, and 2 outputs, with activations throughout.
That's tiny by modern standards, on purpose:
- It fits on a microcontroller. One forward pass is a few hundred multiply-adds and 34 calls, easily done inside the 5 ms control loop.
- It can't exceed the hardware. The last outputs values between −1 and 1, scaled by the gimbal's limit, so the network can never command the nozzle past its hard stops.
I wrote the whole network, including backpropagation and the Adam optimizer, from scratch in NumPy. No ML framework is involved, so I understand every line that will eventually fly.
Why not just PID?
A PID controller is linear, and the real actuator chain isn't. Servos have deadband and a maximum slew rate, the linkage has backlash, and there's latency between sensing and moving the nozzle. A PID can only be tuned around those effects. A neural network can be trained against them, by flying thousands of simulated flights where every one of those imperfections is modelled.
The simulator it learns in
All training happens in a custom 6-degree-of-freedom simulator I built for this rocket. It models:
- Rigid-body dynamics with quaternion attitude, plus mass, centre of gravity and inertia that change as the propellant burns.
- The full actuator chain: control latency, servo quantization, deadband, lag and slew limits, the non-linear horn-and-pushrod geometry, backlash, and the nozzle hard stops.
- A realistic IMU: noise, extra vibration noise while the motor burns, residual bias, mounting misalignment, and scale and cross-axis errors. The controller only ever sees what the flight computer would actually estimate, not the true attitude.
- Aerodynamics (including the finless instability), wind with gusts, and motor thrust curves.
The physics is vectorized, so one simulator instance flies hundreds of rockets in parallel. That's what makes training practical on a laptop.
Stage 1: learning from a teacher (DAgger)
First the network learns to imitate the PID. The naive way, recording PID flights and fitting the network to them, has a well-known flaw: the network only ever sees states a good controller visits, so the moment it makes a small mistake it ends up somewhere it has never seen and doesn't know how to recover. DAgger (Dataset Aggregation) fixes that:
- Round 1. The PID flies 128 randomized flights, with exploration noise and random “kicks” that knock the rocket off course. Every state is labelled with the PID's command.
- Later rounds. A blend of the PID and the network flies, with control handed more and more to the network each round. Every state the network visits is still labelled with what the PID would have done.
- Retrain. After each round the network retrains on the whole growing dataset , minimising the squared error to the teacher:
is the share of control the PID keeps in round , shrinking each round. After six rounds the network has learned how to fly and also how to recover from its own mistakes.
Stage 2: going beyond the teacher (evolution strategies)
Imitation can only make the network as good as the PID. To go further I fine-tune it with evolution strategies (ES), a gradient-free reinforcement-learning method:
- Each generation creates 48 slightly perturbed copies of the weights, in mirrored pairs (antithetic sampling) to reduce noise.
- Every copy flies the same 8 randomized scenarios so they're compared fairly: 392 simulated flights per generation.
- Each flight is scored by a cost that penalizes tilt, angular rate, control effort, servo jitter (sudden changes in command, which wear out servos and excite backlash), and a large penalty for any failed flight.
- The weights move toward the better-scoring copies. A rank-based update keeps one lucky flight from dominating, and Adam smooths the steps.
Here is random noise, sets how big each perturbation is, copies, and turns costs into ranks. The key advantage is that ES never needs gradients through the simulator. Deadband, backlash and quantization aren't differentiable and break gradient-based methods, but ES trains against the exact model anyway.
Domain randomization
My measurements of the real rocket will never be perfect, so every training flight is slightly different. Each one randomizes mass, thrust, burn time, CG and CP location, moment of inertia, motor misalignment, servo speed, linkage geometry, servo centering, backlash, latency, wind, gusts, initial tilt and sensor errors. The network never sees the same rocket twice, which pushes it toward a control law that works across the whole range of rockets I might actually have built, not just a perfect simulated one.
Proving it's robust
I don't trust a controller until I've tried to break it.
- Benchmarking. The network and the PID each fly 200 randomized boosts, compared on success rate, RMS tilt, and worst-case (95th percentile) tilt.
- Robustness sweep. I deliberately make the simulated rocket differ from the one the network trained on: control authority scaled from 0.25× to 4×, up to 80 ms of extra latency, half servo speed, changed inertia, added backlash and misalignment, a rotated IMU, triple wind, and 5× gyro noise. The target is to survive at least a 0.5× to 2× change in loop gain and 20 ms of extra delay, the same margins you'd want from a classically tuned controller.
From Python to flight hardware
When training is done, one click exports the network as a dependency-free C header: the weights as constant arrays plus a short forward-pass function using tanhf. The flight firmware includes it and switches from PID to neural network with a single flag.
The setback: my first flight computer was an Arduino, and it couldn't run the network fast enough for the control loop. Rather than shrink the network until it stopped being useful, I upgraded to an ESP32, a much more powerful microcontroller with plenty of headroom for the forward pass every 5 ms.
The firmware's estimator and observation code is written to match the simulator line for line, and a PC test compiles it and checks it against the Python version. They agree to about one part in a million, so the network sees exactly the same inputs in the air that it saw in training.
Status and next steps
The controller is trained and validated in simulation; it hasn't flown yet. Next is closing the gap between the simulator and reality:
- Bench-test the actuators and fire the motor on a two-axis test stand.
- Use the simulator's system-identification tools to fit its parameters to the logged data.
- Retrain the network on the corrected model and repeat the robustness testing.
- Free flight.
References
- K. J. Åström, R. M. Murray. Feedback Systems: An Introduction for Scientists and Engineers. Princeton University Press (2008).
- R. E. Kalman. A New Approach to Linear Filtering and Prediction Problems. Journal of Basic Engineering 82, 35–45 (1960).
- J. B. Kuipers. Quaternions and Rotation Sequences. Princeton University Press (1999).
- G. P. Sutton, O. Biblarz. Rocket Propulsion Elements, 9th ed. Wiley (2016).
- S. Ross, G. Gordon, D. Bagnell. A Reduction of Imitation Learning and Structured Prediction to No-Regret Online Learning. AISTATS (2011).
- T. Salimans, J. Ho, X. Chen, S. Sidor, I. Sutskever. Evolution Strategies as a Scalable Alternative to Reinforcement Learning. arXiv:1703.03864 (2017).
- D. P. Kingma, J. Ba. Adam: A Method for Stochastic Optimization. ICLR (2015).