|
|
|
Adding a PID controller
Plotting the closed-loop response
Choosing the gains for the PID controller
From the main problem, the dynamic equations in state-space form are the
following:


For the original problem setup and the derivation of the above equations and schematic, please refer to the bus modeling page.
We want to design a feedback controller so that when the road disturbance (W) is simulated by a unit step input, the output (X1-X2) has a settling time less than 5 seconds and an overshoot less than 5%. For example, when the bus runs onto a 10 cm high step, the bus body will oscillate within a range of +/- 5 mm and will stop oscillating within 5 seconds.
The system model can be represented in Matlab by creating a new m-file and entering the following commands (refer to main problem for the details of getting those commands).
m1=2500; m2=320; k=10000; b=140000; A=[0 1 0 0 -k/m1 -b/m1 k/m1 b/m1 0 0 0 1 k/m2 b/m2 -2*k/m2 -b/m2]; B=[0 0 1 0 0 0 0 k/m2]; C=[1 0 -1 0]; D=[0 0]; [nump,denp]=ss2tf(A, B, C, D, 1); nump=[nump(3) nump(4) nump(5)]; [num1,den1]=ss2tf(A,B,C,D,2); num1=[num1(3) num1(4) num1(5)]; numf=num1; denf=nump;
Recall that the transfer function for a PID controller is:

where KP is the proportional gain, KI is the integral gain, and KD is the derivative gain. Let's assume that we will need all three of these gains in our controller. To begin, we might start with a unity gain for each: KP=1, KI=1 and KD=1. This can be implemented into Matlab by adding the following code into your m-file:
KP=1; KI=1; KD=1; numc=[KD,KP,KI]; denc=[1 0];Now let's simulate the response of the system (the distance X1-X2) to a step disturbance on the road. From the schematic above we can find the transfer function from the road disturbance W to the output(X1-X2):

numa=conv(conv(numf,nump),denc); dena=conv(denf,polyadd(conv(denp,denc),conv(nump,numc)));Note that the function "polyadd" is not a standard function in Matlab; you will need to copy it to a new m-file to use it. Click here for more information on defining new functions in Matlab.
Now we have created the closed-loop transfer function in Matlab that will represent the plant, the disturbance, as well as the controller. Let's see what the closed-loop step response for this system looks like before we begin the control process. Keep in mind that we are going to use a 0.1 m high step as our disturbance, to simulate this, all we need to do is to multiply numa by 0.1. Add the following code into your m-file:
t=0:0.01:10; step(0.1*numa,dena,t) axis([0 10 -.01 .01])you should see the response (X1-X2) to a step W like this:

Now that we have the closed-loop transfer function, controlling the system is simply a matter of changing the KP, KI, and KD variables. From the figure above, we can see that the system has a very small damping and the settling time is extremely long. This response doesn't satisfy the 5 seconds settling time requirement. As mentioned before, this can be rectified by adjusting the KP, KI and KD variables to find better response. Let's increase KD to 100 to see what will happen. Go back to your m-file and change KD to 100 then rerun the program, you should get the following plot:

Now we see that the overshoot is a little smaller but the bus body still oscillates (the oscillation will die out after about 150 seconds).
For this problem, it turns out that the PID design method does not adequately control the system. This can been seen by looking at the root locus. When the root locus is plotted, we can see that large poles in left half plane will be needed to pull the asymptotes to the left. Such a task can hardly be achieved by simply changing the gains of a PID controller. Feel free to play around with all three of the parameters, but you will most likely get either unstable or marginally stable responses. But if you do find a good PID design, please email us with your results! We are always interested in different ways to solve our examples; we may include your solution in a future version of these tutorials.
