Using LQR to stabilize an Inverted pendulum
Nasser M. Abbasi
April 12, 2012
Introduction
This is an analysis of the dynamics of inverted bob pendulum on a moving cart. The equations of motion for the cart and the pendulum bob mass are derived using Lagrangian formulation, then state space model is derived and then LQR is used to find the state gain vector to bring the pendulum to the upright position from an initial position. The analysis uses Mathematica. Viscous friction is assumed to be present. This is friction between the cart itself and the rail that the cart moves on.
PDF file is here
Mathematica notebook is here
Derivation of the equations of motion
Let ν be the viscous friction coefficient. The potential energy of the system is PE=m g L sin(θ) and the kinetic energy is , hence the Lagrangian is now found and equations of motion is found for the bob mass and for the cart mass as follows
The Lagrangian
find equation of motion for the bob
find equation of motion for the cart.
Find the state space representation using 90 degree and x=0 as the equilibrium point
Hence, the A matrix is
and the B matrix is
And the C matrix is
obtain optimal state feedback gain. First make up a weight matrix Q
Now use LQR to find state feedback gain vector
Plot the response of the system using this state feedback gain from an initial position. First generate the closed loop system
Plot the x(t) and θ(t) responses to see if they do come to the equilibrium position
We see from above that both the x position of the cart and the upright pendulum position have been brought back to the equilibrium position