Designed and built a self-balancing robot using Lego Spike, starting with deriving equations of motion and formulating a state-space model. Validated the design through MATLAB simulations, static/dynamic sensor testing, and iterative hardware prototyping. Achieved close alignment between simulated predictions and physical performance, demonstrating robust control system integration. The robot was built using two motors, two wheels, and the LEGO Spike hub, which includes a built-in battery and an IMU (gyroscope + accelerometer). All code runs directly on the hub. A picture of the hardware setup is shown below.
The dynamic model was derived using Newton’s laws, summing forces and moments. The system considers four states: position, linear velocity, tilt angle, and angular velocity. A small-angle approximation was applied (sin(θ)≈θ, cos(θ)≈1), introducing an error below 1.5% for angles between ±15°. The resulting state-space representation was used both for simulation and control design.
The LQR controller consistently stabilized the robot for several minutes (battery-dependent). In contrast, the PID controller showed inconsistent behavior, with brief stabilization (up to a minute) depending on the surface and tuning.