Self-balancing robot

A two-wheeled inverted pendulum, modelled and simulated in MATLAB/Simulink, then built and tuned until it balanced on the bench.
A two-wheeled robot that balances itself like an inverted pendulum. It uses geared DC motors on an L298N driver, an MPU-6050 gyro and accelerometer, an Arduino Uno and two 3.7 V lithium cells on a stacked plate frame.
What I did
- Derived and linearised the system model, obtained the transfer function and compared PD and PID controllers against the specified transient response in MATLAB/Simulink.
- Built the prototype and tuned the controller on hardware, then analysed why measured behaviour diverged from simulation.
- Added a detachable 3D-printed limiter (the red part) that catches the robot when it falls, so it is not damaged during tuning.
What went wrong, and the fix
- Problem:
Gains calculated from theory (Kp 705, Ki 70, Kd 19) did not work on the real robot, because of friction and errors in the model parameters.
Fix:Retuned on the bench to Kp 23, Ki 90, Kd 1.8, after which the robot balanced reliably.
From the bench
SolidWorks model of the stacked-plate frame
Battery pack, IMU and the red fall limiter
Geared DC motor and wheel
Arduino Uno and L298N wiring
Detachable 3D-printed limiter