This manual documents the modelling of an inverted pendulum, developing a full state feedback control using LQR to balance the unstable equilibrium and evaluatin the LQR on the hardware setup.
This experiment will demonstrate the control of a system using full state feedback, where the control system is designed using the principles of Linear Quadratic Regulator (LQR) theory. This is an analysis technique that would be seen in more detail during advanced studies. You are not required to completely understand the derivation of the method itself. However, you should understand how to formulate the required matrices (Q and R) and why the overall goal (to minimize the cost, J) leads to the requirements on those matrices, as well as the reasoning behind the formulation of the cost equation, which serves as the purpose behind the method’s derivation.
Consider the system
such that the closed-loop system
We will demonstrate the previous LQR design using a simple mass-spring-damper system as shown in Fig. 7.2. The equation of motion is
or in state-space form
Choose the weighting matrices as
The Riccati equation gives
Expanding, we obtain
Solving these equations, we get
or that
The optimal gain matrix is given by
The closed-loop system matrix is
The closed-loop system is stable.
The purpose of this experiment is to design a balance control using the principles of linear quadratic regulator (LQR) theory for an inverted pendulum mechanism.
In this lab, we demonstrate a control design using modern “state-space” methods. The plant consists of an inverted pendulum on a cart. The plant has two distinct equilibrium points of which one is stable and the other is unstable. In this experiment, we will show how the plant in its unstable configuration can be controlled using a suitable controller. The methodology used to design the control law is based on the linear quadratic regulator (LQR) theory. The inverted pendulum mechanism to be used in this lab is shown in Fig. 7.3.
The equations of motion for the system can be easily derived using the free-body diagrams shown in Fig. 7.6 as follows (here we assume that the track on which the cart moves without sliding):
First, we write the motor equation as
or
where
The torque generated at the output of the motor is given by
Thus, the force transmitted to the cart via the pinion is
and on substituting the values of
we get
Substitution of the above expression for F in the linearized equations results in
The LQR formulation provides a linear control law
which minimizes the quadratic cost given by
Assuming the time-domain design specifications are:
one can choose
The block diagram of the experimental setup in the lab is shown in Fig. 7.7.
Assume that:
Using the lqr
command in MATLAB, calculate the optimal feedback gain vector K. The lqr
command basically solves the Algebraic Ricatti Equation that you met earlier. >> [k,s,e] = lqr(A,B,Q,R);
Compute the open-loop and closed-loop eigenvalues of the system and comment on the stability of the open and closed-loop systems.
Compute the natural frequencies and damping ratios of the closed-loop system.
CAUTION: Always be ready to stop the experiment if the cart goes unstable. This can be done either by pressing the stop button in the Simulink or turning the power off.
Turn the power on.
Open the MATLAB and locate the file InvPendulum_LQR.mdl under the path C:\AE4610_Controls_Lab\Inverted_Pendulum and open it. This is the block diagram for this part of the experiment.
Switch the Command Signal block to 0.
Enter the gains you obtained in the corresponding gain blocks.
Put the cart right in the middle of the track and hold up the pendulum fixed and straight. Do not release it until the controller is on.
Double click on the scopes and open then.
Gently disturb the pendulum to see the effect of the controller and then stop the simulation.
Switch the command signal to step input. It should make the cart to move 20 cm to the right after 10 seconds.
Save the data with a descriptive name. DO NOT SAVE THE MODEL.
Turn the POWER OFF
Individual: Include the results from the controller design procedure Steps 1-5.
Group: Build a SIMULINK block diagram using Fig. 7.7 and obtain the simulated response to the same command input used in the experiment. Compare the simulated response with the experimental response and explain any differences between them.
Average the first 5 seconds of the experimental data to obtain initial conditions for your state-space block in SIMULINK
where is a state vector and is a control input vector. Therefore, and are matrices of dimensions and , respectively. Let us suppose that we wish to design a state-feedback controller
is stable. Here is a matrix of gains of dimensions . In achieving closed-loop stability, we wish to use as little control effort as possible. We also wish to avoid large overshoot of the trajectories during the transients. One way to achieve both of these objectives is to find a control law which minimizes the following quadratic cost
where and are weighing matrices of appropriate dimensions. In order for the previous problem to make sense we must ensure that the two terms in the integral are positive. The requirement that
for all vectors is satisfied if the matrix is positive semi-definite (all its eigenvalues are greater than or equal to zero). The requirement that
for all vectors is satisfied if the matrix is positive definite (all its eigenvalues are greater than zero). This optimization problem has a closed-form solution. The optimal gain matrix is given by
where the matrix is the positive definite solution of the following Algebraic Riccati Equation (ARE):
where and . Let and . The system matrices are
Notice that the solution matrix P is positive definite. Its eigenvalues are .
and the eigenvalues are
Consider an inverted pendulum of mass and length connected on a sliding cart of mass as shown in Fig. 7.4.
The angle is measured from the up-right position. We can apply a force to the cart through the cartwheel motors. We wish to design a controller to balance the pendulum to the upright position . Note that the problem of balancing a pendulum is akin to the problem of stabilizing a rocket during ascent.
where is the moment of inertia about the pendulum's mass center given by .
This system has two equilibria which are and .
The first equilibrium corresponds to the down position (stable) and the second equilibrium corresponds to the upright position (unstable) of the pendulum. Linearizing the previous equations about the equilibrium of interest we obtain the following equations:
The input force in the above equations can be written in terms of the input voltage applied to the motor of the cart and the cart velocity as shown below.
: voltage applied to motor (Volts)
: current in motor (Amp)
: back EMF constant (Volt/(rad/sec))
: gear ratio in motor gearbox
: motor armature resistance (Ohms)
: angular velocity of the wheel (rad/sec)
: cart velocity (m/sec)
: radius of motor pinion that meshes with the track (m)
where is the motor torque constant given by
where is the conversion factor from volt-amp to N-m given by
Letting and , the input force F can be written as
The above set of linear differential equations is of the form , where . We seek a linear control law of the form , where is a vector of gains.
for some user-defined matrices and . It is assumed that is positive semi-definite (all the eigenvalues are non-negative) and is positive definite (all the eigenvalues are positive). Here is the input voltage, given by
is the state vector, and given by
is the controller gain vector. Note that the input voltage is scalar and therefore, is also scalar. In practice, the weighting matrices and are chosen to be diagonal. A simple way for choosing and is the following (Bryson's rule):
Further tuning of and may be required for improving the controller performance. Note that increasing means increasing the penalty on the control input (using less control effort). Similarly, increasing means increasing the penalty on the states (states reaching equilibrium position quickly and with less overshoot).
(Note: Conventional error signal shown, but )
where is position of the cart, is velocity of the cart, is angular position of the rod from the vertical, is angular velocity of the rod, and is a vector of feedback gains .
Obtain the A and B matrices of the system using , and .
Choose and based on the following:
No constraints on and . (They can go to infinity…)
According to Bryson’s rule, this will result in the following and matrices:
and
To build the model, click the down arrow on Monitor & Tune under the Hardware tab and then click Build for monitoring . This generates the controller code.
Press Connect button under Monitor & Tune and then press Start .