Inverted Cart Pendulum
A real-time systems engineering project focused on balancing an inverted pendulum through advanced control strategies. Designed, modeled, and prototyped at UCL, this project integrates three control algorithms (PID, LQR, and Pole Placement) with custom hardware and a custom fabricated PCB.
Multiple controllers
PID, LQR, and Pole Placement controllers were implemented and rigorously benchmarked, enabling comparative analysis of performance, stability, and robustness under various real-time conditions.
Custom 4 layer PCB
A meticulously designed 4-layer PCB integrates ESP32 and Arduino microcontrollers, sensor interfaces, and motor drivers, ensuring efficient signal, compact layout, and streamlined assembly.
Precise stability
Python-based simulations utilizing state-space models allowed tuning of control parameters. This approach enhanced controller accuracy, enabling stable pendulum performance and most importantly reduced tuning time.
Design stage
When I initially envisioned the inverted pendulum, I thought of placing it on an aluminum extrusion rod driven by a stepper motor. This setup would have allowed better control over the robot, minimizing sensor noise and vibrations. Unfortunately, we soon realized this design didn't meet our project constraints—it needed to be a wheeled cart.
​
We completely turned our initial design around and envisioned a cart with four wheels capable of handling extreme conditions and weight to stabilize the inverted pendulum. At least this way, we wouldn't face hardware issues.
​
We opted for a 2000 CPR high-precision encoder to ensure accurate readings with minimal noise.


CAD design
Demonstrating the sturdiness of the rod holder
Something I definitely underestimated about this project was the design of the rod holder. I initially thought it would be a straightforward part, but it turned out to be way more critical than expected. It had to be extremely sturdy and durable—not just to support the rod, but also to handle the forces and vibrations from the pendulum’s movement without any wobble. One of the trickiest parts was figuring out how to mount the encoder accurately onto the perpendicular axle of the inverted pendulum rod frame. That alignment had to be spot on for the readings to make any sense. After a few iterations—some frustrating, some enlightening—I landed on a final design that worked fabulously well.
Main Rod Holder
Finished design with encoder



Bearing and axle holder

Motor mount

Mass holder

PCB design
I wanted a clean and professional look for my circuit, so I opted for a custom-fabricated PCB. Breadboards or even hand-soldered perf boards often end up messy, and debugging them can quickly turn into a nightmare.
​
Designing the PCB in KiCad gave me full control and the chance to thoroughly test my layout before fabrication. I went with a 4-layer design to simplify the routing and keep everything as compact and organized as possible. The end result? A board that not only works well but looks great too.

The main components used were as follows:
-
Esp32
-
Voltage Regulator (12v to 5v)
-
High Precision Encoder (For the Rod)
-
2 Motor encoders (placed on opposite ends of the robot)
-
2 L293D Motor Drivers ICs
-
4 DC geared Motors



Assembly and prototyping
This was by far the most critical stage of the project. It tested the quality of the PCB, validated the hardware design, and revealed any practical limitations in our approach. It also marked the point where everything started coming together—once the electronics were assembled and working, we could finally begin coding the robot and bringing it to life.
Slapped the motor mount and finally the motors themseleves on the base frame which had the rod holder (with it's encoder)

Inserted the pendulum to present the final Prototype

Connected all the wires to the PCB to finally give the robot some life

Demonstration
The following video demonstrates the inverted pendulum with 3 different controllers, PID, LQR and pole. For code and detailed explanation please refer to my publication at the end of the page.
The following video showcases two key evaluations. The first demonstrates the robot’s stability and robustness during basic operation. The second highlights its ability to traverse a 2-meter distance and come to a smooth stop—all while keeping the pendulum balanced throughout the motion.