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 transfer function of the plant for this problem is given below:

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). The transfer function found from the Laplace transforms for the output Phi (the pendulum's angle) can be set up using Matlab by inputting the numerator and denominator as vectors. Create an m-file (or a '.m' file located in the same directory as Matlab) and copy the following text to model the transfer function:

Your output should be:

3. Block Diagram

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 sigrid function, which has to be copied to a m-file. To do this, copy the following code to the end of your m-file (whether your using the transfer function from the Laplace transforms or from the state-space representation):


Note: Matlab commands from the control system toolbox are highlighted in red.


Note: Non-standard Matlab commands used in this example are highlighted in green.

You should see the following rlocus plot:

As you can see, one of the roots of the closed-loop transfer function is in the right-half-plane. 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. Add the following to your m-file:

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:

If you are using the laplace transform transfer function, you should get the following output in the Matlab command window,
As you can see there are four poles and only one zero. 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. For the state-space transfer function there will be one extra pole and zero.

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. The polyadd function needs to be copied to the directory you are running Matlab in.

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 meets 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 feedback controller which we designed, is given as follows:

Recall that den1=den2 if the pole/zero at the origin that was canceled is added back in. So the transfer function from X to F can be simplified to:

Now that we have the transfer function for the entire system, let's take a look at the response. First we need the transfer function for the cart's position. To get this we need to go back to the laplace transforms of the system equations and find the transfer function from X(s) to U(s). Below is this transfer function:

For more about the Laplace transform please refer to the inverted pendulum modeling page.

The pole/zero at the origin canceled out of the transfer function for Phi, has been put back in. So that now den1 = den2, making calculations easier. Now, create a new m-file and run it in the command window:

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 Feedback

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.


Root Locus Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball & Beam

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

Tutorials

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

8/12/97 CJC