Unformatted text preview: 40 ECE 147a: (Fall 95) Matlab Computer Modules 4 Module 2: PID Control 4.1 Overview
The background material to this module is covered in Chapter 3 of the text. This module will illustrate the e ects of proportional (P), proportionalintegral (PI), proportionalderivative (PD) and proportionalintegralderivative (PID) control on a variety of systems. Module 1 studied the relationship between pole position and dynamic response. This knowledge can aid in the prediction of the e ect of each of these types of controller. Some control schemes, PI or PID in particular, will change the type of the resulting system. In these cases, if the open loop system had a steady state error for a step input the closed loop system will (usually) not have such an error. Refer to page 110 of the text for more detail on this subject. One would get the impression from this module that PID gains are chosen by trial and error  and this might often be the case. However, by understanding the e ect of each form of control the \trials" can be very intelligently performed. Furthermore, by using a computer one can readily try a number of candidate controllers before attempting to control the physical system. Later in the quarter more systematic methods for control design will be presented. However, gaining intuition about typical plant behavior will always be of bene t in control design. Various approaches to tuning PID parameters have been studied in the past. One example is the ZeiglerNichols method which is discussed on page 120 of the text. This is applicable to a wide range of control problems, particularly in the process control industry. 4.2 Module 2: Listing and Graphics
clg;axis( 1,2,3,4]);axis; echo on %% % Dept. of Electrical & Computer Eng. % University of California, Santa Barbara. % % ECE 147 A: Feedback Control Systems % % module2: PID control Module 2: PID Control 41 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %  This module will show graphically the varying effects of proportional (P), proportionalintegral (PI), proportionalderivative (PD) and proportionalintegralderivative (PID) controllers on several typical systems. The plants, we will discuss here are a motor with a voltage input and a velocity output, the spring mas dashpot (SMD) system from module 1, and a % third order Butterworth filter. The controllers we will look at are of the form: C1(s) = Kp C2(s) = Kp + Ki/s (proportional only) (proportional and integral) C3(s) = Kp + Kd*s/(s/beta + 1) (prop. and derviative) NOTE: The (s/beta + 1) term is added to the derivative term to make it proper. beta is chosen as a frequency well above the bandwidth of the system so that the effect of 1/(s/beta +) is approximately equal to 1 in the frequency range of interest. C4(s) = Kp + Ki/s + Kd*s/(s/beta + 1) (prop., integ., deriv.) pause % press any key to continue % % The plants we will use have the following form: % % P1(s) = A/(s+B) (voltage > velocity) % % P2(s) = C/(S^2 + 2*z*wn*s + wn^2) % (force > position) % % P3(s) = 1/((s + 1)(s^2 + 1.4142*s + 1)) % (Butterworth filter) % % % We will be graphing time response curves to illustrate 42
% % % % % % % % ECE 147a: (Fall 95) Matlab Computer Modules
the effect of each gain on the closed loop time response. Typically, PID controllers are tuned by control engineers that understands which way to adjust specific gains in order to achieve the desired response. For simple systems there are some rules of thumb about tuning PID controllers (look up ZeiglerNichols rules for example). Often it is a trial and error process with the control engineer eventually getting a feel for the effect of the various gains. % In each case we will consider the standard unity gain negative % feedback setup: % % _________ __________ % y     error ref. % <o plant < C(s) <(+)<%  _______ ________ ^%   % ________________________________________ % The objective is to design C(s) so that the output, y, is equal % to the reference (this is the ideal  we will never get them % exactly equal). pause % press any key to continue. % For this control example, we must first build the models % of the plants and controllers. For the motor model, we % use values of A = 5 and B = 15. Thus, P1(s) = 5/(s+15). num = 0 5]; den = 1 15]; P1 = nd2sys(num,den); % The SMD model values are the same as in module 1; % C = 90, wn = 10, and z = .1. So, % P2(s) = 90/(s^2 + 2s + 100). num = 0 0 90]; den = 1 2 100]; P2 = nd2sys(num,den); % The butterworth system is P3(s) = 1/((s+1)(s^2+1.412s+1)). P3 = mmult(nd2sys(1, 1,1]),nd2sys(1, 1,sqrt(2),1])); pause % press any key to continue % We will vary each of the controller gains to illustrate to Module 2: PID Control 43 % % % % effect of that gain on the particular system. Trends in rise time, overshoot, settling time, and final value will be found to coincide with trends in gain changes. We now define the gains to be used. % Proportional gains Kp1 = 1.0; Kp2 = 2.0; Kp3 = 5.0; % Integrator gains Ki1 = .5; Ki2 = 1; Ki3 = 1.5; % Differential gains Kd1 = .1; Kd2 = .5; Kd3 = 2; % The high frequency pole for the derivative term. beta = 100; pause % press any key to continue % For a baseline reference, the openloop time response of each % system is examined. u = step_tr( 0], 1],.1,20.0); P1_tr = trsp(P1,u,1,.005); P2_tr = trsp(P2,u,5,.025); P3_tr = trsp(P3,u,20,.15); clg; subplot(221); axis( 0,1,0,1]); vplot('iv,d',P1_tr,'',u,''); title('Openloop step: Motor'); ylabel('vel.'); xlabel('time (sec)'); subplot(222); axis( 0,5,0,2]); vplot('iv,d',P2_tr,'',u,''); title('Openloop step: SMD'); ylabel('posn.'); xlabel('time (sec)'); 44 ECE 147a: (Fall 95) Matlab Computer Modules subplot(223); axis( 0,20,0,1.5]); vplot('iv,d',P3_tr,'',u,''); title('Openloop step: Butterworth'); xlabel('time (sec)'); % meta mod2fig1 1 0.8 Openloop step: Motor 2 1.5 Openloop step: SMD posn. vel. 0.6 0.4 0.2 0 0 0.5 time (sec) Openloop step: Butterworth 1 1 0.5 0 0 time (sec) 5 1.5 1 0.5 0 0 5 10 time (sec) 15 20 pause % % % % % % % % press any key to continue As you can see, the motor is a 1st order system, the SMD system is 2nd order, lightly damped and therefore oscillatory, and the butterworth has a smooth response. An ideal step response has fast rise and settling times, low overshoot, and a step response steady state value of 1. Note these characteristics of our three plants, and attempt to find the controller that improves them. clear P1_tr P2_tr P3_tr; % % % % Proportional controllers will be examined initially. Note that the error in the closed loop system is given by e(s) = 1/(1+Kp*P(s)) which will decrease as the gain is increased. Look for this property in the following. Module 2: PID Control 45 pause % press any key to continue % Examine the motor response with proportional controllers % Kp1, Kp2, & Kp3. clp_P1_Kp1 = starp(mmult( 1;1],P1,Kp1, 1,1]),1); clp_P1_Kp2 = starp(mmult( 1;1],P1,Kp2, 1,1]),1); clp_P1_Kp3 = starp(mmult( 1;1],P1,Kp3, 1,1]),1); % Calculate the time response of 5 seconds starting at t=0, % magnitude 1, and .1 seconds spacing between vector points. u = step_tr( 0], 1],.1,5.0); % Calulate and plot the time responses of the motor with each % controller. p1_Kp1_tr = trsp(clp_P1_Kp1,u,2,.01); p1_Kp2_tr = trsp(clp_P1_Kp2,u,2,.01); p1_Kp3_tr = trsp(clp_P1_Kp3,u,2,.01); clg; subplot(221); axis( 0,1,0,1]); vplot('iv,d',p1_Kp1_tr,'',p1_Kp2_tr,'.',p1_Kp3_tr,''); title('P1,C(s)=P: Kp1(),Kp2(.),Kp3()'); ylabel('vel.'); xlabel('time (sec)'); clear p1_Kp1_tr p1_Kp2_tr p1_Kp3_tr; % % % % % % % As you can see from this plot, the constant gain controller affects the DC (steady state) value, and the rise time of this first order system. As the gain is increased, the system becomes faster, and the reference error decreases. Again, these are both good things, but when gain is increased, noise is often also amplified and the power required to drive the system increases. % press any key to continue pause % Now examine the effect of proportional control on the % SMD system. clp_P2_Kp1 = starp(mmult( 1;1],P2,Kp1, 1,1]),1); clp_P2_Kp2 = starp(mmult( 1;1],P2,Kp2, 1,1]),1); clp_P2_Kp3 = starp(mmult( 1;1],P2,Kp3, 1,1]),1); % Calculate and plot the step response of the SMD closed 46
% loop system. ECE 147a: (Fall 95) Matlab Computer Modules p2_Kp1_tr = trsp(clp_P2_Kp1,u,5,.025); p2_Kp2_tr = trsp(clp_P2_Kp2,u,5,.025); p2_Kp3_tr = trsp(clp_P2_Kp3,u,5,.025); subplot(222); axis( 0,5,0,2]); vplot('iv,d',p2_Kp1_tr,'',p2_Kp2_tr,'.',p2_Kp3_tr,''); title('P2,C(s)=P: Kp1(),Kp2(.),Kp3()'); ylabel('posn.'); xlabel('time (sec)'); clear p2_Kp1_tr p2_Kp2_tr p2_Kp3_tr; % % % % % The tradeoffs between high gains and faster rise times is more apparent in this graph. One can clearly see how the second order system has more overshoot, as the gain increases. The resonant frequency of the system increases with increasing gain. The steady state error is reduced with increasing gain. % press any key to continue pause % The Butterworth filter with proportional feedback is now % examined. clp_P3_Kp1 = starp(mmult( 1;1],P3,Kp1, 1,1]),1); clp_P3_Kp2 = starp(mmult( 1;1],P3,Kp2, 1,1]),1); clp_P3_Kp3 = starp(mmult( 1;1],P3,Kp3, 1,1]),1); % Calculate and the step response of the Butterworth closed % loop system. p3_Kp1_tr = trsp(clp_P3_Kp1,u,20,.15); p3_Kp2_tr = trsp(clp_P3_Kp2,u,20,.15); p3_Kp3_tr = trsp(clp_P3_Kp3,u,20,.15); subplot(223); axis( 0,20,0,2]) vplot('iv,d',p3_Kp1_tr,'',p3_Kp2_tr,'.',p3_Kp3_tr,''); title('P3,C(s)=P: Kp1(),Kp2(.),Kp3()'); ylabel('Butterworth State'); xlabel('time (sec)'); % meta mod2fig2 clear p3_Kp1_tr p3_Kp2_tr p3_Kp3_tr; Module 2: PID Control 47 1 P1,C(s)=P: Kp1(),Kp2(.),Kp3() 0.8 2 P2,C(s)=P: Kp1(),Kp2(.),Kp3() 1.5 posn. vel. 0.6 0.4 0.2 0 0 0.5 time (sec) 2 P3,C(s)=P: Kp1(),Kp2(.),Kp3() 1 1 0.5 0 0 time (sec) 5 Butterworth State 1.5 1 0.5 0 0 5 10 time (sec) 15 20 % % % % % % % % % % % There is something new in this graph as we see instability for the first time. This is interesting, obviously third order systems require more than just a constant controller if quick rise times are desired. Other than this the lessons of the lower ordered systems also apply here. In each of these examples, increasing the gain reduced the steady state error. However to get this error to go to zero, the proportional gain must go to infinity. Clearly this is not a viable approach for reducing the steady state error. It will be seen that integral control has exactly the desired characteristic. This is studied next. % press any key to continue pause % % % % % % % % The C2 controller series are the PI controllers. We don't often build pure integral controllers, because we would like to keep some of the characteristics of the proportional controller. The PI controller is a system with a pole at the origin, and a zero at Ki/Kp. In general, the system cannot reach steady state with a nonzero error. If it did, the error would integrate in the controller and the controller output would continue to change. Furthermore 48 ECE 147a: (Fall 95) Matlab Computer Modules % (if we get the signs correct), the controller output changes % in the direction that reduces the error. % Three different controllers, each with varying amounts of % integral gain will be studied. num den C2a num C2b num C2c = Kp2 Ki1]; = 1 0]; = nd2sys(num,den); = Kp2 Ki2]; = nd2sys(num,den); = Kp1 Ki3]; = nd2sys(num,den); % press any key to continue pause clp_P1_C2a = starp(mmult( 1;1],P1,C2a, 1,1]),1); clp_P1_C2b = starp(mmult( 1;1],P1,C2b, 1,1]),1); clp_P1_C2c = starp(mmult( 1;1],P1,C2c, 1,1]),1); % Calculate and plot the responses to each controller P1_C2a_tr = trsp(clp_P1_C2a,u,2,.01); P1_C2b_tr = trsp(clp_P1_C2b,u,2,.01); P1_C2c_tr = trsp(clp_P1_C2c,u,2,.01); clg; subplot(221); axis( 0,2,0,1]); vplot('iv,d',P1_C2a_tr,'',P1_C2b_tr,'.',P1_C2c_tr,''); title('P1,C(s)=PI, Kp2,Ki1(),Ki2(.),Ki3()'); ylabel('vel.'); xlabel('time (sec)'); clear P1_C2a_tr P1_C2b_tr P1_C2c_tr; % This plot clearly shows the effect of integrator compensation. % The steady state error will eventually go to zero and these % outputs will all reach one (in the limit). pause % press any key to continue % Now examine the effect of each of these controllers on % the SMD system. clp_P2_C2a = starp(mmult( 1;1],P2,C2a, 1,1]),1); clp_P2_C2b = starp(mmult( 1;1],P2,C2b, 1,1]),1); clp_P2_C2c = starp(mmult( 1;1],P2,C2c, 1,1]),1); Module 2: PID Control 49 % Calculate and plot the responses to each controller P2_C2a_tr = trsp(clp_P2_C2a,u,5,.01); P2_C2b_tr = trsp(clp_P2_C2b,u,5,.01); P2_C2c_tr = trsp(clp_P2_C2c,u,5,.01); subplot(222); axis( 0,5,0,2]) vplot('iv,d',P2_C2a_tr,'',P2_C2b_tr,'.',P2_C2c_tr,''); title('P2,C(s)=PI: Kp2,Ki1(),Ki2(.),Ki3()'); ylabel('posn.'); xlabel('time (sec)'); clear P2_C2a_tr P2_C2b_tr P2_C2c_tr; % Again, you can see how the integrator is mostly interested in % reducing the error of the system. There is nothing really new % here and we still have too much oscillation. pause % press any key to continue % Now look at the responses of the Butterworth system. clp_P3_C2a = starp(mmult( 1;1],P3,C2a, 1,1]),1); clp_P3_C2b = starp(mmult( 1;1],P3,C2b, 1,1]),1); clp_P3_C2c = starp(mmult( 1;1],P3,C2c, 1,1]),1); % Calculate and plot the responses to each controller P3_C2a_tr = trsp(clp_P3_C2a,u,20,.01); P3_C2b_tr = trsp(clp_P3_C2b,u,20,.01); P3_C2c_tr = trsp(clp_P3_C2c,u,20,.01); subplot(223); axis( 0,20,0,2]) vplot('iv,d',P3_C2a_tr,'',P3_C2b_tr,'.',P3_C2c_tr,''); title('P3,C(s)=PI: Kp2,Ki1(),Ki2(.),Ki3()'); xlabel('time (sec)'); % meta mod2fig3 clear P3_C2a_tr P3_C2b_tr P3_C2c_tr; 50 ECE 147a: (Fall 95) Matlab Computer Modules
P1,C(s)=PI, Kp2,Ki1(),Ki2(.),Ki3() 1 0.8 P2,C(s)=PI: Kp2,Ki1(),Ki2(.),Ki3() 2 1.5 posn. vel. 0.6 0.4 0.2 0 0 0.5 1 time (sec) P3,C(s)=PI: Kp2,Ki1(),Ki2(.),Ki3() 2 1.5 1 0.5 0 0 1.5 2 1 0.5 0 0 time (sec) 5 5 10 time (sec) 15 20 % % % % Again the integral control has the effect of (eventually) bringing the steady state error to zero. We still haven't solved the problem of going unstable when the gains get too high here. % press any key to continue pause % % % % % Derivative control offers the possibility of increasing the speed of system response if the error suddenly changes. When the input has a fast transition (like a step) the derivative action in the controller will give the system a kick to get it going. % Again three controllers will be studied, each with progressively % more derivative action. % The controller is C3(s) = (Kp*(s/beta + 1)+Kd*s)/(s/beta + 1) % with Kp1 as the proportional gain. C3a = madd(Kp2,nd2sys( Kd1,0], 1/beta,1])); C3b = madd(Kp2,nd2sys( Kd2,0], 1/beta,1])); C3c = madd(Kp2,nd2sys( Kd3,0], 1/beta,1])); Module 2: PID Control 51 clp_P1_C3a = starp(mmult( 1;1],P1,C3a, 1,1]),1); clp_P1_C3b = starp(mmult( 1;1],P1,C3b, 1,1]),1); clp_P1_C3c = starp(mmult( 1;1],P1,C3c, 1,1]),1); P1_C3a_tr = trsp(clp_P1_C3a,u,2,.01); P1_C3b_tr = trsp(clp_P1_C3b,u,2,.01); P1_C3c_tr = trsp(clp_P1_C3c,u,2,.01); clg; subplot(221); axis( 0,2,0,1]); vplot('iv,d',P1_C3a_tr,'',P1_C3b_tr,'.',P1_C3c_tr,''); title('P1,C(s)=PD: Kp2,Kd1(),Kd2(.),Kd3()'); ylabel('vel.'); xlabel('time (sec)'); clear P1_C3a_tr P1_C3b_tr P1_C3c_tr; % % % % As you can see in this graph, the derivative controller gives the "kick" as predicted. Also, note that the steady state of the system is unchanged, so after the initial kick, the controller settles back down to the steady state. % press any key to continue pause % Now the SMD system under PD control is analyzed. clp_P2_C3a = starp(mmult( 1;1],P2,C3a, 1,1]),1); clp_P2_C3b = starp(mmult( 1;1],P2,C3b, 1,1]),1); clp_P2_C3c = starp(mmult( 1;1],P2,C3c, 1,1]),1); P2_C3a_tr = trsp(clp_P2_C3a,u,2,.01); P2_C3b_tr = trsp(clp_P2_C3b,u,2,.01); P2_C3c_tr = trsp(clp_P2_C3c,u,2,.01); subplot(222); axis( 0,2,0,2]); vplot('iv,d',P2_C3a_tr,'',P2_C3b_tr,'.',P2_C3c_tr,''); title('P2,C(s)=PD: Kp2,Kd1(),Kd2(.),Kd3()'); ylabel('posn.'); xlabel('time (sec)'); clear P2_C3a_tr P2_C3b_tr P2_C3c_tr; % % % % % % This response set of curves illustrate the increase in response speed as Kd is increased. The higher the gain the more intense of a kick that is given to the system. Note that the derivative action also seems to take away some of the oscillatory response. This is often expressed as a rule of thumb that derivative control adds more damping 52
% % % % ECE 147a: (Fall 95) Matlab Computer Modules
to the system. This is a bit of a simplification, the real story is more complicated than that. However before the quarter is finished you will understand exactly what is going on here. % press any key to continue pause % Now study the PD controller on the Butterworth system. clp_P3_C3a = starp(mmult( 1;1],P3,C3a, 1,1]),1); clp_P3_C3b = starp(mmult( 1;1],P3,C3b, 1,1]),1); clp_P3_C3c = starp(mmult( 1;1],P3,C3c, 1,1]),1); P3_C3a_tr = trsp(clp_P3_C3a,u,20,.01); P3_C3b_tr = trsp(clp_P3_C3b,u,20,.01); P3_C3c_tr = trsp(clp_P3_C3c,u,20,.01); subplot(223); axis( 0,20,0,1.5]); vplot('iv,d',P3_C3a_tr,'',P3_C3b_tr,'.',P3_C3c_tr,''); title('P3,C(s)=PD: Kp2,Kd1(),Kd2(.),Kd3()'); xlabel('time (sec)'); % meta mod2fig4 clear P3_C3a_tr P3_C3b_tr P3_C3c_tr; P1,C(s)=PD: Kp2,Kd1(),Kd2(.),Kd3() 1 0.8 P2,C(s)=PD: Kp2,Kd1(),Kd2(.),Kd3() 2 1.5 posn.
0.5 1 time (sec) 1.5 2 vel. 0.6 0.4 0.2 0 0 1 0.5 0 0 0.5 1 time (sec) 1.5 2 P3,C(s)=PD: Kp2,Kd1(),Kd2(.),Kd3() 1.5 1 0.5 0 0 5 10 time (sec) 15 20 Module 2: PID Control 53 % % % % % % This graph is very interesting. As the Kd gain is increased, the rise time decreases as expected, but the overshoot also decreases. Other feature of interest is the fact that the highest gain system is now stable. The derivative action clearly has a lot of benefits here. Notice that the steady state error doesn't go to zero  we need some integral control to achieve that. % press any key to continue pause % % % % % % % % Now we will try putting everything together and examining PID control. Only one example, with one controller will be looked at here  there has to be something left for you to do in the exercises. We will start with the great PD response on the system and see if adding a bit integral control steady state error go to zero without giving up the other good features (fast risetime, little Butterworth can make the too much on overshoot). PID = madd(Kp2,nd2sys( Kd3,0], 1/beta,1]),nd2sys(Ki2, 1,0])); clp_P3_PID = starp(mmult( 1;1],P3,PID, 1,1]),1); P3_PID_tr = trsp(clp_P3_PID,u,20,.01); clg; axis( 0,20,0,1.5]); vplot('iv,d',P3_PID_tr); title('P3,C(s)=PID: Kp2,Kd3,Ki2'); xlabel('time (sec)'); % meta mod2fig5 clear P3_PID_tr; 54 ECE 147a: (Fall 95) Matlab Computer Modules
P3,C(s)=PID: Kp2,Kd3,Ki2 1.4 1.2 1 0.8 0.6 0.4 0.2 0 0 2 4 6 8 10 time (sec) 12 14 16 18 20 % Not too bad. I might get a job doing this sort of thing yet. %echo off 4.3 Problems
1. Adjust the gains to get a good PI controller for the motor system. 2. Adjust the gains to get a good PD controller for the SMD system. Notice what happens when you try to improve the steady state error by increasing the proportional gain. 3. For each of the three systems, nd PID gains to give you good controllers. ...
View
Full Document
 Spring '07
 RODWELL

Click to edit the document details