← Back to Projects
Self-Balancing Robot: Hybrid LQR-PID Control in Simscape
June 2025 · Team Project (6 members): URDF robot model, dynamics derivation, control architecture design
MATLABSimulinkSimscapeState-SpaceLQRPID

Problem

A two-wheeled self-balancing robot is inherently unstable, and its longitudinal dynamics (forward motion and pitch) are strongly coupled with its lateral dynamics (yaw). A single centralized LQR with integrator could not stabilize velocity, pitch, and yaw together: tuning one variable destabilized another.

Approach

  • Derived the dynamic model from Newton’s laws, covering the DC motor, wheels, and chassis, and linearized it into a 6-state state-space model (position, velocity, pitch, pitch rate, yaw, yaw rate).
  • Decomposed control into two subsystems:
    • Longitudinal: LQR for optimal pitch stabilization, combined with PID for velocity reference tracking.
    • Lateral: a separate PID controller for yaw angle.
  • Rebuilt the robot as a Simscape Multibody model converted from URDF, with joystick input and virtual sensors. This replaced a MATLAB/Gazebo co-simulation that ran too slowly to keep the controller in sync.
  • Ran a systematic sweep of the LQR Q and R weights (11 Q variations plus 4 R values) on the same maneuver scenario (accelerate, turn, hard brake, settle), and tuned the yaw PID over 10 parameter sets.

My Contribution

Group project for TF4014 Multivariable Control Systems at Institut Teknologi Bandung. My part:

  • URDF robot model: built the 3D model of the robot, which was converted into the Simscape Multibody plant.
  • Dynamics derivation: derived the physical equations (DC motor, wheels, chassis) behind the state-space model.
  • Control architecture: designed the decomposed LQR-PID structure after the centralized controller failed.

Result

  • The decomposed LQR-PID architecture stabilized the robot and tracked velocity and yaw references, which the centralized controller could not.
  • Heavy penalties on pitch and pitch rate (Q = diag(1, 1000, 1000)) kept the chassis upright under hard braking, while a large velocity penalty caused overshoot and large pitch excursions.
  • A large R (5 to 100) made control too “expensive” and caused oscillation during braking. A very small R gave a good pitch response but slow velocity tracking.
  • For yaw, the derivative term was essential: P-only, I-only, and PI tunings let the robot fall, while the Ziegler-Nichols-based PID gave the best response.

Limitations

  • Simulation only: the controller was validated in Simulink/Simscape and has not been tested on a physical robot.
  • Linearized model: the state-space model is linearized, so it is only valid near the upright equilibrium.
  • Real-hardware effects not covered: effects seen on the hardware build, such as motor deadzone and wheel grip on different surfaces, are not part of this study.

This course project builds on an earlier team side project (a hardware build) that balanced with a single PID loop on tilt angle: Self-Balancing Robot: ESP32 Hardware Build. The simulation goes further with a full dynamic model and multi-state LQR control, which the hardware version does not have yet.

6
State variables
11
LQR Q-weight variations
10
Yaw PID tunings
Gallery