Cart-Pole in Hardware: State Estimation and Real-Time Control

Built the inverted pendulum on a rail, read its state off quadrature encoders, and balanced it from an embedded control loop.

2024 · CSCI 5143 Real-Time and Embedded Systems, University of Minnesota · created with Kuba Kedzior

Built with Embedded C, PID control, Quadrature encoders, State-space modelling

The assembled cart-pole rig.
The assembled cart-pole rig.

A cart-pole balancer built from parts for a real-time embedded systems course. A DC motor drives a cart along a rail through a belt and pulley, and a pendulum hangs freely from the cart. We built the rail and drive, the motor driver and sensing circuit, the quadrature decoding that turns two encoder signals into an angle, and the real-time loop that moves the cart to keep the pendulum upright. The system is modelled in state space over cart position, cart velocity, pendulum angle, and angular velocity. An AVR microcontroller running embedded C reads the sensors, and a laptop runs the floating-point control. The pendulum balances under PID control.

My role

Derived the state-space model, wrote the quadrature decoding and the real-time control loop, and built the encoder and motor-driver circuit.

Results

The balancing controller works, under PID rather than the LQR originally planned. The limiting factor was sensor drift. The optical encoders are precise but accumulate error, their datasheet warns that vibration causes misreads, and mounting one on a moving cart supplied exactly that. Once the estimated angle drifts there is no way to detect or recover it in software, which leaves the controller without the state it needs. Fixing it means adding a drift-free Hall effect sensor and fusing it with the encoder through a complementary or Kalman filter. We dropped the swing-up controller for the same reason.

Media

System architecture. The motor supply and controller drive the belt. A cart-mounted encoder, a belt-mounted encoder, and a time-of-flight sensor feed the AVR, and a laptop does the floating-point control.
System architecture. The motor supply and controller drive the belt. A cart-mounted encoder, a belt-mounted encoder, and a time-of-flight sensor feed the AVR, and a laptop does the floating-point control.
The physical cart-pole balancing under closed-loop control.
Detail of the cart, belt drive and pendulum mount.
Detail of the cart, belt drive and pendulum mount.
System diagram of the cart-pole.
System diagram of the cart-pole.
Control block diagram.
Control block diagram.
Motor driver and sensing circuit.
Motor driver and sensing circuit.
Rotary encoder used to measure pendulum angle.
Rotary encoder used to measure pendulum angle.

Documents