|
|
|
Open-loop transfer function
Closed-loop transfer function
Adding the PID 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:
The first thing to do when using PID control in Matlab is to find the transfer function of the system and to check to see if it makes sense. In this problem, we are given the state-space equations for the system. This set of equations can be changed to a transfer function by creating the following m-file (or a '.m' file located in the same directory as Matlab):
The next thing to notice is that in the second row of the numerator, the first and last elements are 0, while the second and fourth element are 0.0000. If you look closely at each of these elements (try format long e), you will find that they are not exactly zero, but in fact a 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:
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.

This closed-loop transfer function can be modeled in Matlab by copying the following code to the end of your m-file:

This response is still not stable. Let's start by increasing the proportional control to the system. Increase the k variable to see what effect it has on the response. If you set k=100, and set the axis to axis([0, 2.5, -0.2, 0.2]), you should get the following velocity response plot:

The settling time is acceptable at about 2 seconds. Since the steady-state error has already been reduced to zero, no more integral control is needed. You can remove the integral gain constant to see for yourself that the small integral control is needed. The overshoot is too high, so that must be fixed. To alleviate this problem, increase the kd variable. With kd=20, you should get a satisfactory result. You should now see the following velocity response plot:

As you can see, the overshoot has been reduced so that the pendulum does not move more than 0.05 radians away from the vertical. All of the design criteria have been met, so no further iteration is needed.
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 variable was not being controlled. It is 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's. 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 differ in numerator alone), so the transfer function from X to F can be simplified to:

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:

As you can see, the cart moves in the negative direction with a constant velocity. So although the PID controller stabilizes the angle of the pendulum, this design would not be feasible to implement on an actual physical system.
Tutorials
