Controls + AI / system

Double
pendulum.

I wanted a project that brought together software, hardware and electronics. I am building a pendulum on a cart and training neural networks in simulation to balance it, so I can compare them with a classical controller I can reason through step by step.

AI or classical control?

Balancing a pendulum upright is a classic control problem. One way to solve it is with a controller built from a model of the physics, where every step can be explained. The other is a neural network that learns through repeated attempts in simulation. I wanted to put both on the same system and see how they compare when they have to work on real hardware.

The rig.

The rig is an inverted pendulum on a cart. A motor drives the cart along a one-metre rail with a belt, and it has to swing the rod up from hanging and then keep it balanced upright. I am starting with a single rod, with a second rod added on top for the double.

Both controllers run on the same Raspberry Pi Pico 2 at the same rate, so the comparison is fair. The classical controller uses energy shaping to swing the pendulum up and LQR to balance it. The AI side does the same job with two neural networks, one for swing-up and one for balance, trained with reinforcement learning in a MuJoCo simulation. I designed and 3D-printed the cart and mounts, and added end-stops, an emergency stop and a brake relay so the motor can always be stopped safely.

What I learned in simulation.

Sensor noise stopped the networks from learning, even though they could handle it once they were trained. This meant training without noise and then always testing on a realistic simulation with every imperfection switched on. Results also varied a lot between training runs, so I trained several, picked the best using validation tests, and scored it once on a separate set it had never seen.

96%Single pendulum: swing-up and balance on the held-out realistic rigs.
97–100Out of 100 for double balance, once the state came from a Kalman filter at 50 Hz.
68%Double swing-up on realistic rigs. Not dependable, so the classical controller stays the hardware plan.

The training and the rig.

Neural-network training

Double-pendulum setup

What I took from it

Why the physical system mattered.

The project was not about treating AI as the answer. It was about understanding what a model could learn, where that differed from a control system I could explain, and how both behave on a problem that is hard to keep in balance.