HOME

Using LQR to stabilize an Inverted pendulum

Nasser M. Abbasi
April 12, 2012

index_1.gif

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 index_2.gif , hence the Lagrangian is now found and equations of motion is found for the bob mass and for the cart mass as follows

index_3.gif

The Lagrangian

index_4.gif

index_5.gif

find equation of motion for the bob

index_6.gif

index_7.gif

find equation of motion for the cart.

index_8.gif

index_9.gif

Find the state space representation using 90 degree and x=0 as the equilibrium point

index_10.gif

index_11.gif

Hence, the A matrix is

index_12.gif

index_13.gif

and the B matrix is

index_14.gif

index_15.gif

And the C matrix is

index_16.gif

index_17.gif

obtain optimal state feedback gain. First make up a weight matrix Q

index_18.gif

index_19.gif

Now use LQR to find state feedback gain vector

index_20.gif

index_21.gif

Plot the response of the system using this state feedback gain from an initial position. First generate the closed loop system

index_22.gif

index_23.gif

index_24.gif

index_25.gif

Plot the x(t) and θ(t) responses to see if they do come to the equilibrium position

index_26.gif

index_27.gif

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

Spikey Created with Wolfram Mathematica 8.0