CMU
UM


Example: Solution to the inverted pendulum problem using Root Locus method

Transfer functions
Root locus design
Lead-lag controller
What happens to the cart's position?

The state equations for this problem are:

The design criteria (with the pendulum receiving a 1N impulse force from the cart) are:

To see how this problem was originally set up, consult the inverted pendulum modeling page.

Transfer functions

The rlocus command in Matlab can find the root locus for a system described by state-space equations or by a transfer function. For this problem it will be easier in the long run to use a transfer function (the reason for this will become clear later). Matlab can find the transfer function of the system from the state-space equations using the following m-file:

M = .5;
m = 0.2;
b = 0.1;
i = 0.006;
g = 9.8;
l = 0.3;

p = i*(M+m)+M*m*l^2; %denominator for the A and B matricies
A = [0      1              0           0;
     0 -(i+m*l^2)*b/p  (m^2*g*l^2)/p   0;
     0      0              0           1;
     0 -(m*l*b)/p       m*g*l*(M+m)/p  0];
B = [0; (i+m*l^2)/p; 0; m*l/p];
C = [1 0 0 0;
     0 0 1 0];
D = [0;0];

[num,den] = ss2tf(A,B,C,D)
By running this m-file, the numerator and denominator of the transfer function should be shown in the Matlab command window. You should see the following lines of code:
num =
         0   -0.0000    1.8182    0.0000  -44.5455
         0    0.0000    4.5455    0.0000         0

den =
    1.0000    0.1818  -31.1818   -4.4545         0
The first thing to notice is that the numerator has two rows; one row represents the cart's position and the other represents the pendulum's angle. For this problem, we want to stabilize the angle of the pendulum. Therefore, the first row will be ignored for now (we will return to the cart's position later).

The next thing to notice is that in the second row of the numerator, the first and last element are 0, while the second and fourth element are 0.0000. If you look closer at each of these elements, you will find that they are not zero, but in fact some very small number. These numbers are not really supposed to be part of the transfer function, and should be eliminated. Click here, and look at how to use the ss2tf command to see why. The numerator can be corrected by adding the following line of code to the end of your m-file:

num = [num(2,3) 0 num(2,5)];
The transfer function numerator now reflects only the output of interest, and the zeros at infinity are not causing errors.

The control of this problem is a little different than the standard control problems you may be used to. Since we are trying to control the pendulum's position, which should return to the vertical after the initial disturbance, the reference signal we are tracking should be zero. The force applied to the cart can be added as an impulse disturbance. The schematic for this problem should look like the following.

It will be easier to determine the appropriate transfer function to enter into Matlab if we first rearrange the schematic as follows:

Now, we can find the closed-loop transfer function.

Root locus design

This closed-loop transfer function can be modeled in Matlab. The first thing to do is to look at the root locus for the plant by itself, with no compensator. To pick the gain for the proportional control, remember that the settling time has to be less than 5 seconds. This implies that sigma should be more than 4.6/5=0.92. We can put this criteria right on the root locus using the sigma function, which has to be copied to a m-file. To do this, copy the following code to the end of your m-file:

rlocus(num,den)
sigma(0.92)
axis([-6 6 -6 6])
[k,poles]=rlocfind(num,den);
You should see the following rlocus plot:

When prompted to select a point, pick a point on the real axis near the sigma line. As you can see, one of the roots of the closed-loop transfer function is in the right-half-plane. As you know, this means that the system will be unstable. Look back at the root locus to see why. Part of the root locus lies between the origin and the pole in the right-half-plane. No matter what gain you chose, you will always have a closed-loop pole in this region, making your impulse response unstable. To solve this problem, we need to add another pole at the origin so all the zeros and poles at the origin will cancel each other out and multiple roots will be created in this right-half-plane region. The multiple roots can then be drawn into the left-half-plane to complete the design. Change your m-file to look like the following:

M = .5;
m = 0.2;
b = 0.1;
i = 0.006;
g = 9.8;
l = 0.3;

p = i*(M+m)+M*m*l^2; %denominator for the A and B matricies
A = [0      1              0           0;
     0 -(i+m*l^2)*b/p  (m^2*g*l^2)/p   0;
     0      0              0           1;
     0 -(m*l*b)/p       m*g*l*(M+m)/p  0];
B = [0; (i+m*l^2)/p; 0; m*l/p];
C = [1 0 0 0;
     0 0 1 0];
D = [0;0];

[num,den] = ss2tf(A,B,C,D);
num = [4.5455 0 0];

p1 = 0;

dentemp = [1 p1];

num2 = num;
den2 = conv(den, dentemp);

rlocus(num2,den2)
sigma(0.92)
axis([-10 10 -10 10])
You should get the following root locus plot with multiple roots in the right-half-plane:

Now we can begin trying to draw the branches of the root locus into the left half plane. Enter the following two commands into the command window:

roots(num2)
roots(den2)
You should get see the following output in the Matlab command window:
ans =
     0
     0

ans =
         0
         0
   -5.6041
    5.5651
   -0.1428
As you can see there are five poles and only two zeros. This means there will be three asymptotes: one along the real axis in the negative direction, and the other two at 120 degree angles from this.

This configuration will never have the multiple roots in the left-half-plane. We must reduce the number of asymptotes from three to two by adding one more zero than pole the controller. If just a zero is added, then the intersection of the asymptotes (alpha) would be [(-5.6041+5.5651-0.1428+0+0)-(0+0+z2)]/2. This means the two asymptotes will leave the real axis at roughly -0.1-(1/2)z2. Making z2 as small as possible (assume near the origin) will not pull the multiple roots far enough into the left-half-plane to meet the design requirements (asymptotes will leave at about -0.1).

Lead-lag controller

The solution to this problem is to add another pole far to the left of the other poles and zeros. To keep the right number of asymptotes, another zero should be added as well. The placement of the added pole and zeros is not important except that the pole should be relatively large and the zeros should be relatively small. Try the m-file below to see what effect the poles and zeros have on the root locus.

M = .5;
m = 0.2;
b = 0.1;
i = 0.006;
g = 9.8;
l = 0.3;

p = i*(M+m)+M*m*l^2; %denominator for the A and B matricies
A = [0      1              0           0;
     0 -(i+m*l^2)*b/p  (m^2*g*l^2)/p   0;
     0      0              0           1;
     0 -(m*l*b)/p       m*g*l*(M+m)/p  0];
B = [0; (i+m*l^2)/p; 0; m*l/p];
C = [1 0 0 0;
     0 0 1 0];
D = [0;0];

[num,den] = ss2tf(A,B,C,D);
num = [4.5455 0 0];

z1 = 3;
p1 = 0;
z2 = 4;
p2 = 50;

numlag = [1 z1];
denlag = [1 p1];
numlead = [1 z2];
denlead = [1 p2];

num3 = conv(conv(num, numlead), numlag);
den3 = conv(conv(den, denlead), denlag);

rlocus(num3,den3)
sigma(0.92)
axis([-50 50 -50 50])
figure
rlocus(num3,den3)
sigma(0.92)
axis([-10 10 -10 10])
[k,poles]=rlocfind(num3,den3)
figure

numc = conv(conv(num,denlead),denlag);
denc = polyadd(k*num3,den3);
impulse(numc,denc)
axis([0 2 -0.05 0.05])
The poles and zeros were found by trial and error. The only things to keep in mind was that one pole had to be at the origin, the other had to be far to the left, and the two zeros had to be small. Furthermore, I found that if the two zeros were close together and to the right of the farthest left plant pole, the response was better. You should see first the following root locus plot with the zeros and poles listed above:

The second plot should be of the same root locus magnified a little so that the root locus around the origin can be seen.

When prompted to pick a location on the root locus, chose a spot on the multiple roots just before they return to the real axis. Your velocity response to the impulse disturbance should look similar to the following:

The response now mets all of the requirements, so no further iteration is needed.

What happens to the cart's position?

At the beginning on this solution page, the block diagram for this problem was given. The diagram was not entirely complete. The block representing the the position was left out because that part was not being controlled. It would be interesting though, to see what is happening to the cart's position when the controller for the pendulum's angle is in place. To see this, we need to consider the actual system block diagram:

Rearranging a little bit, you get the following block diagram:

The feedback loop represents the controller we have designed for the pendulum. The transfer function from the cart's position to the impulse force, with the PID feedback controller which we designed, is given as follows:

Recall that den1=den2 (the two transfer functions G1 and G2 differ in numerator alone), so the transfer function is simply:

Now that we have the transfer function, let's take a look at the response. Create a new m-file that looks like the following:

If you select the point on the root locus you selected before (near the real axis), you should see the following plot:

The top curve represents the pendulum's angle, and the bottom curve represents the cart's position. As you can see, the cart moves, is stabilized at near zero for almost five seconds, and then goes unstable. It is possible that friction (which was neglected in the modeling of this problem) will actually cause the cart's position to be stabilized. Keep in mind that if this is in fact true, it is due more to luck than to anything else, since the cart's position was not included in the control design.


User Survey
Your anonymous answers to the following questions will help us to improve future versions of these tutorials.
How useful was this example?
Very useful Useful Somewhat useful Not very useful A waste of time
How was the level of the example?
Too simple About right Too difficult
How much time did you spend on it?
Less than 30 mins. 30 - 60 mins. More than 60 mins.
How much of the Matlab code did you run?
None Some Most

We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.

If you would like to receive a response, send your comments or questions to ctm-feedback@umich.edu


Root Locus Examples
Cruise Control | DC Motor | Bus Suspension | Inverted Pendulum

Inverted Pendulum Examples
Modeling | PID | Root Locus | Frequency Response | State Space

Tutorials

Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Examples

8/28/96 JDP