The objective of this project is to design and implement a digital controller for a self-balancing car using state-space control techniques. Specifically, we focus on the Linear Quadratic Regulator (LQR) for achieving stability. The report details the mathematical modeling, system identification, control design, simulation, and experimental validation using an STM32-based self-balancing car.
The dynamics of the self-balancing car can be derived using Newton-Euler equations. The primary equations governing the system are:
where:
-
$A$ represents the system dynamics matrix, -
$B$ is the input matrix, -
$C$ is the output matrix, -
$D$ is the feedthrough matrix.
The state-space model is derived based on the system parameters:
where the values of
The physical parameters of the self-balancing car are:
- Wheel mass:
$m = 0.035$ kg - Wheel radius:
$r = 0.0672/2$ m - Vehicle body mass:
$M = 1.000-2m$ - Distance from center of mass to chassis:
$L = 0.5 \times 0.0766$ - Moment of inertia:
$J_{centroid}$
Using these values, we computed the state-space matrices A and B in MATLAB.
The LQR controller minimizes the cost function:
where
Q = [7700 0 0 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0; 0 0 0 1600 0 0; 0 0 0 0 500 0; 0 0 0 0 0 0];
R = [1 0; 0 1];
K = lqr(A,B,Q,R);The computed gain matrix K is:
A Simulink model was developed for simulation, incorporating:
- State-space representation of the system
- LQR gain implementation as feedback control
- Disturbance rejection analysis
The simulation results show:
- Stable balancing of the car
- Effective disturbance rejection
- Smoother response compared to PID control
A screenshot of the Simulink simulation output is attached.
The computed LQR controller was implemented on the STM32-based car. The control algorithm was embedded using Keil uVision & STM32CubeIDE. Key observations:
- Real-time angle estimation using Kalman Filtering
- PWM-based motor control for dynamic balance
- Successful real-world validation of the LQR controller
This project successfully designed and implemented an LQR-based digital controller for a self-balancing car. The results demonstrate improved stability and disturbance rejection compared to other control methods. Future work includes:
- Fine-tuning Kalman Filter for better sensor fusion
- Extending control for obstacle avoidance
- Deploying advanced optimization techniques (e.g., MPC)