Training an AI to steer a spacecraft

A university project where an AI learned, by trial and error, how to turn a spacecraft with its reaction wheels, and then ran on a small computer standing in for the real onboard one.

Illustration: a satellite in orbit learning to point at a target star, with earlier training attempts, a rising reward curve and the onboard computer running the trained agent
Type
University project
Approach
Reinforcement learningCurriculum learning
Tools
BasiliskStable Baselines3
Hardware
Raspberry Pi 4

Challenge

Pointing in space is hard

A spacecraft has to face exactly the right way: its antenna towards Earth, its camera towards a target. In space there is nothing to push against, so it turns itself with reaction wheels, spinning wheels inside the spacecraft. Speed a wheel up one way and the spacecraft slowly rotates the other way.

Doing this well means turning quickly, stopping right on target and not wasting energy. Normally engineers hand-tune a controller for that. We wanted to see if an AI could learn it on its own.

How it works

How the AI learns to steer

1. A practice space

We built a virtual spacecraft with reaction wheels in Basilisk, a spacecraft simulator, so the AI could practise thousands of times without risking real hardware.

2. Trial and reward

At each moment the AI sees where the spacecraft points and how fast it spins, then decides how to drive the wheels. Getting closer to the target earns a reward; overshooting or wasting effort costs points.

3. Easy to hard

Training started with small, easy turns and slowly moved to bigger ones, like learning to ride a bike with training wheels. The AI used an algorithm called soft actor-critic.

4. Onto real hardware

The trained AI was moved onto a Raspberry Pi, a small computer standing in for the spacecraft's own, and tested while connected to the simulation.

Testing

From simulation to a real computer

The AI first ran inside the simulation on a laptop, then on the Raspberry Pi. Running it on separate, small hardware showed that the trained AI is light enough to work on the kind of computer a real spacecraft carries.

Raspberry Pi 4 in a black heatsink case, connected to a MacBook during testing
The Raspberry Pi running the trained AI during testing.

Measuring success

How we judged it

Settling time

How quickly the spacecraft reaches the target direction and stays there.

Control effort

How much the reaction wheels have to work, which means energy used.

Accuracy

How close the spacecraft ends up to exactly the right direction.