MIDDLE EAST TECHNICAL UNIVERSITY EE 402 RECITATION #13 REPORT LEAD-LAG COMPENSATOR DESIGN F. Kağan İPEK Utku KIRAN Ç. Berkan Şahin 5/16/2013
Contents INTRODUCTION... 3 MODELLING... 3 OBTAINING PTF of OPEN LOOP... 6 SAMPLING PERIOD PROBLEM... 8 LAG-LEAD COMPENSATOR DESIGN... 10 EFFECT OF LEAD-LAG COMPENSATOR ON TRANSIENT RESPONSE... 21 CONCLUSION... 26
INTRODUCTION In this week s recitation, lead-lag compensator design on a real system, which is a solution to the fifth senior design project, will be discussed. The importance of sampling on representing a continuous system in discrete domain and possible problems that can occur will be analyzed. A complete lead-lag design procedure will be given for the system and then effect of a lead-lag compensator on a system will be analyzed by changing poles and zeros of lead and lag compensator. MODELLING The robot has two wheels at the back and a caster ball at the front for drive system. It has a separate DC motor for each wheel for differential driving. Expectation from the drive system is the ability to go in a certain heading with a certain speed. In order to meet these requirements two encoders and a magnetometer are placed on the robot. Encoders enable the robot to control the speed of its wheels and magnetometer, which is configured to function as a compass, enables the robot to head to a particular direction. In order to implement control loops, DC motor model should be obtained. Motors on the robot have the following specifications: τ stall =0.42 Nm I stall = 1.6 A No load speed = 120 rpm = 4π rad/sec @6V No load current = 70 ma @6V R internal = 3 Ω Torque and back EMF constants are needed to derive mathematical model. To find torque constant: K τ = τ stall = 0.42 = 0.2625 N/A I stall 1.6 To find back EMF constant, use the DC motor equivalent circuit under no load conditions (@6V): K b = 6 R internal No load current No load speed = 6 3 0.07 4 π 0.461 Vsec/rad Viscous damping factor and rotor inertia are also needed for a complete modeling; however these coefficients are not given and assumed to be zero, which is a valid assumption since the motors are very small.
Since robot controls the motor voltages by the means of PWM duty cycle with 8 bit resolution, conversion from PWM duty cycle to voltage is also included in the motor model. This conversion is in the following form: voltage = battery voltage 2 PWM resolution 1 Overall DC motor model is shown in Figure 1. Figure 1: DC Motor Model As mentioned above the robot has two control loops: one is separate speed control for both motors and the other is heading control which affects the both motors. Speed control is straight forward, directly use Linear Velocity output of the motor model for feedback. For heading control assume that the robot turns about its own axis to head to desired direction, and to do this it applies same voltage to the motors except that voltages are applied in opposite direction; therefore, one wheel will turn in one direction where the other will turn in the opposite direction. Then, if the distance travelled by one wheel relative to the other is found and halved, it would be distance travelled by wheels while they are doing the turn motion mentioned above. Note that the robot needs how much it turned; thus the obtained distance value is divided by the radius of rotation of the robot to obtain turn angle. Also notice that heading controller (Discrete PID Controller3 in Figure 2) effort is applied to both motors.
Figure 2: Overall System As it can be seen from Figure 2, speed control is established by just feeding linear velocity output of the DC motor block to the controller. For heading control, first distance travelled by two wheels are subtracted and halved and then feedback to the heading controller. Figure 3 shows the three control loops in action. At t=1 sec, both motors are set to same speed and at t=2 sec, heading set point changes from 0 to 0.5, notice that at that instant one wheel is speeding up and the other is slowing down. In other words the robot is performing the turning operation explained above.
Figure 3: Overall System in Action OBTAINING PTF of OPEN LOOP The open loop pulse transfer function of the system is needed to design a lead/lag compensator. The compensator is designed for heading control. To obtain the PTF MATLAB Control and Estimation tool is used. Note: Sampling period is set to 0.05 sec, since the robot is actually running the control loops every 50 msecs. However, this sampling period is problematic for this system. The problem will be discussed later on. First, open loop is formed in simulink (Figure 4) and then the tool is started by selecting Tools>Control Design>Linear Analysis... from the top menu in simulink (Figure 5).
Figure 4: Open Loop PTF for Heading Control Figure 5: Linear Analysis with Control and Estimation Tool Then from the new window opened Linearize Model is selected and then the model is exported to the MATLAB workspace. At this point MATLAB generates the transfer function in z-domain since; there is a zero order hold in front of the DC motor model. Generated PTF is: G z = 0.001861 z + 0.0004032 z 2 1.004 z + 0.004136 The PTF should be transformed to w-domain before compensator design procedure. In order to perform transformation from z-domain to w-domain MATLAB function d2c() is used with tustin as the method argument. Tustin method is the bilinear transformation as discussed in lectures. Open loop transfer function in w-domain is:
G w = 0.0007259 w2 0.01606 w + 1.804 w 2 + 39.67 w SAMPLING PERIOD PROBLEM In continuous domain the system has the open loop transfer function of: G s = 4.991 s 2 + 109.8 s Notice that the system has two poles: one is at zero and the other is at -109.8. Figure 6 shows the bode plots of previously obtained G(z), G(w) and G(s). Figure 6: Bode Plot of G(z), G(w), G(s). Ts=0.05sec Note that the vertical line in Figure 6 is w s /2 = π T s = π 63 rad/sec 0.05 which is smaller than the pole at s=-109.8. As it can be seen from Figure 6, bode plot of G(z) ends at the vertical line, meaning that the 0.05 sec sampling period cannot represent frequencies higher than
63 rad/sec. When w-domain transform is performed, resulting transfer function is only able to represent the actual system for frequencies lower than ws/2. Therefore, same error can be seen in G(w). In order to represent the system properly in z or w domain, sampling frequency should be such that ws/2 is much greater than the higher pole of the system. For example, if the sampling period is reduced to 0.001 sec, new bode plots of G(z), G(w) and G(s) becomes as shown in Figure 7. Figure 7: : Bode Plot of G(z), G(w), G(s). Ts=0.001 sec Note that the system pole at 109.8 rad/sec is now left of the vertical line, and it is represented in the both z and w domain. To make a proper compensator design for this system, sampling period should be reduced; however the robot cannot run (CPU wise) faster than 20 Hz; thus, the design will be done over 0.05 sec sampling period to preserve realism and see how, poor sampling period affects compensator design.
LAG-LEAD COMPENSATOR DESIGN For the design part of the recitation, a lead-lag compensator is designed to connect in a cascaded manner to the plant. By adding the lead-lag compensator, it is aimed to improve some performance criteria of the overall system, i.e. stability. The design procedure is started with a lead compensator design which is followed by the lag compensator design part. Before starting the compensator design, the design is multiplied by a gain, K to satisfy the error coefficient specification which will be mentioned later in this report. The procedure that is followed during the lead-lag compensator design is lined up below. 1) Finding out the system type. 2) Calculating the gain, K that need to be added to the system. 3) Obtaining the Bode Plots of the system. 4) Designing the LEAD compensator part of the overall compensator. 5) Finding the new system transfer function which is obtained by adding the lead compensator part. 6) Obtaining the Bode plots of this new system. 7) Designing the LAG compensator part of the compensator. 8) Checking the resultant system if it satisfies the specifications or not. 9) Some modifications according to step 8. After that point, the design procedure will be applied step by step to finalize the design. During the design, the necessary information will also be given. The open loop transfer function of the position control part of the project (EE494) in W domain is given below. 2 0.0007259w 0.01606w 1.804 G( w) 2 w 39.67w This transfer function is obtaining from the discrete time transfer function(ptf) and 0.05 seconds is used a sampling period, T. This T is exactly the period of the control loop of the project. The lead-lag compensator is designed using this transfer function. The following specifications are selected to be achieved on the compensated system. Design specifications:
PM : 60⁰ GM = 8 db ess(under unit ramp) 0.05 The gain margin specification seems a little bit extraordinary. A low value is selected because obtaining a higher gain margin is too hard by adding a lead-lag compensator to the given W domain transfer function. This problem is caused by the sampling period. Sampling period is not changed to remain true to the real system and to observe the effect of sampling period on the system. Step by step design: 1) Finding out the system type. According to the specifications, there should be no steady state error under unit step input and a constant one under unit ramp. To achieve that, the system should be type 1 and it is type 1, hence there is no need to add a pole at the origin to increase the type of the system. 2) Calculating the gain, K that need to be added to the system. The design specification that is satisfied first is the steady state error specification. Steady state error can be found using the basic formula : sse=1/ K V, where K V is the velocity error coefficient. 0.05=1/ K V K V =20 Velocity error coefficient is given by the following formula K V K *1.804 lim w* G' ( w) lim K * w* G( w) 20 w 0 w 0 39.67 K 440
At that point selecting an appropriate K value is so significant. During the design procedure, first the lead compensator will be designed. Lead compensator design procedure can only by applied to the stable systems, hence an appropriate K which both satisfies the design specifications and does not violates the stability of the system should be carefully selected. Increasing K value increases the positive gain that is added to the system and that shifts the magnitude part of the Bode plots up. This may end up with a negative gain margin which means the system becomes unstable. By considering the issues mentioned above, K is selected as 600. K=600 3) Obtaining the Bode Plots of the system. After multiplying the system with K=600, the following transfer function is obtained. 0.4355w G' ( w) 2 w 2 9.636w 1082 39.67w The design will be continued according to this new transfer function. Thus, the Bode plots of it should be obtained to understand the system well and attack to it for lead compensator design part. Figure 8: Bode Plots of the uncompensated system
Phase and gain margin of the uncompensated system: PM = 41.5 deg. GM = 7.22 db It is seen that the uncompensated system has a gain margin of 7.22 db. If the gain, K were selected as 2000, for example, instead of 600, it will result in 20log(2000/600)=10.45 db shift in the magnitude and the GM would be -3.23 db which means instability. Thus, K=600 can, again, be considered as an acceptable value. 4) Designing the LEAD compensator part of the overall compensator. The Bode plots are obtained and the system is ready to be used for a lead compensator design. Adding a lead compensator improves the PM but decreases the GM of a system. In the system whose Bode plots are drawn above has already a low GM and decreasing it more by adding a lead compensator is not an acceptable solution for achieving the desired PM. Thus the effort of the lead compensator part is limited and the principal part of the compensation to achieve the desired PM is handled by the lag compensator part. The PM of the system is tried to be made 46.5 degrees from 41.5 degrees by adding 5 degrees. First, the maximum phase of the lead compensator to be designed should be calculated. Φ max = PM specified + correction factor PM uncompensated Φ max = 46.5 + 5 41.5 = 10 Then, α should be calculated using this maximum phase. α = 1 sin Φ max 1 sin 10 = =0.704 1+sin Φ max 1+sin 10 For a lead compensator of the form pole of the compensator. G cd 1 Tw ( w) 1 Tw, this α gives the location of the The gain that is introduced by the uncompensated system at the new gain crossover frequency can be found using the following formula 20log α = 20log 0.704 = -1.52 db After finding this gain we can use it to find the new gain crossover frequency by using the Bode plots of the uncompensated system. The uncompensated system introduces -1.52 db gain at the frequency
ω M =38 rad/sec which is the gain crossover frequency of the overall system after adding the lead compensator. Then, T= 1 = 1 ω M α 38 0.704 = 0.0314 αt = 0.704 0.0314 = 0.022 The transfer function of the designed lead compensator: G cd 1 Tw ( w) 1 Tw = 1 0.0314w 1 0.022w Figure 9: Bode Plots of the designed lead compensator 5) Finding the new system transfer function which is obtained by adding the lead compensator part. Overall system s transfer function after adding the lead compensator is given below. 3 2 0.01368w 0.7381w 24.35w 1082 G( w) 3 2 0.022w 1.873w 39.67w
Now, let s check the Bode plots of the system with lead compensator. 6) Obtaining the Bode plots of this new system. PM = 44.2 deg. GM = 4.13 db Figure 10: Bode Plots of the lead compensated system It can be said that the desired phase margin which is 46.5 degrees can not be achieved. The phase margin of the system must increase by 2.7 degrees although a 5 degrees correction factor is added during design. On the other hand, the GM of the system decreases by nearly 3 db (from 7.22 to 4.13) even though the desired PM cannot be achieved. This means that lead compensator is not a good solution to increase the PM of the system by not decreasing the GM too much. This reason of this problem is the slope of the magnitude Bode plot of the system around the gain crossover frequency. This slope too small, hence the lead compensator cannot really affect the system. This small slope is a result of the selected sampling period that is used to transform the PTF to W domain. If a higher Φ max were used in the lead compensator design, a larger drop on the GM would occur and the system would become unstable which is not preferable. 7) Designing the LAG compensator part of the compensator. For the lag compensator part, the lead compensated system is used. Now, the desired PM is the PM specification that is given in the beginning of the design procedure.
Lag compensator design is started by finding out the phase of the overall compensated system. To do that the following calculation is done. Phase(G final )= -180 + PM desired + correction factor Phase(G final )= -180 + 60 + 5 = -115 degrees The lead compensated system s Bode plots is used to find the frequency at which the system has the phase of -115 degrees and ω M =18.5 rad/sec This ω M will be the gain crossover frequency of the system that is obtained after adding lag compensator. ω Wo should be selected sufficiently small enough than the gain crossover frequency not to affect the system s behavior. Selecting it 1 of 10 of the gain crossover frequency is sufficiently enough. Then, ω wo =0.1*ω M =1.85 rad/sec After finding that, ω wp should also be found. To do that, the gain that is introduced by the lag compensator at the final gain crossover frequency have to be calculated. G cg G afterlead = 1 = 0 db at 18.5 rad/sec which is the final gain crossover frequency G afterlead can be found using the Bode plots of the lead compensated system. G afterlead = 1.6538 at 18.5 rad/sec. Then, 1 = G G cg = 1 = 0.6046 afterlead 1.6538 If the lag compensator is considered to be a unity gain compensator. G cg = 0.6046 = ω wp ω wo
ω wp = 0.6046 * ω wo ω wp = 0.6046 * 1.85 rad/sec ω wp = 1.119 rad/sec Then, the transfer functions of the lag compensator and the overall system which is compensated by the lead-lag compensator is shown below. G cg 1 ( w) 1 w ww w w 0 wp 1 0.541w 1 0.89w G final ( w) 0.007399w 4 3 0.413w 12.44w 2 w 39.67w 2 603.9w 1082 Figure 11: Bode Plots of the designed lag compensator
Figure 12: Bode Plots of the lead-lag compensated system PM = 62.4 deg GM = 8.45 db The overall system has a PM of 62.4 and a GM of 8.45 db which are okay according to the design specifications. It was already mentioned that, this low gain margin is caused by the sampling period used in the z to w domain transformation. If a better sampling period were selected, the resultant system would have a better GM. The following equations are system transfer function for T=0.001 instead of T=0.05, the lead compensator transfer function and the lag compensator transfer function respectively. G 2 0.0000912w 9.788w 19944 w) w 109.7w ( 2 G G cd cg ( w) ( w) 1 0.0087w 1 0.00612w 1 0.15w 1 0.39w
The uncompensated system has the following properties: Figure 13: Bode Plots of the uncompensated system which is obtained for T=0.001 PM=38.6 deg. GM=21 db After the lead-lag compensator design is completed the following Bode plots are obtained. PM = 61.8 deg GM = 29.2 db Figure 14: Bode Plots of the lead-lag compensated system which is obtained for T=0.001
When the sampling period decreases the system is improved and a better GM is obtained. Decreasing the sampling period also decreases the settling time of the system and as a trade off, it introduces a higher percent overshoot. These results can be observed from the following 2 figures, one is the step response of the lead-lag compensated system for T=0.05 and the other is for T=0.001 Figure 15: Step response of the lead-lag compensated system which is obtained for T=0.05 Figure 16: Step response of the lead-lag compensated system which is obtained for T=0.001
EFFECT OF LEAD-LAG COMPENSATOR ON TRANSIENT RESPONSE Effect of lead-lag compensator is demonstrated in MATLAB environment with the help of Control and Estimation tool. This tool enables user to design lead-lag compensator for a system and observe its effects in real time. It offers diverse plots (step response, Nyquist, pole-zero, bode plots etc.). In this section compensator design is not done in a formal way but it is done with trial and errors. Figure 17 shows bode plots and Figure 18 shows step response of the closed loop of uncompensated system. The goal is to improve transient response and stability margins. Note that a gain of 2000 is added to the plant to improve steady state errors to some degree. Steady state error under unit step is also improved by the compensator design. For the plant: GM = 11.2 db PM = 85.5⁰ Rise Time = 0.00242 sec e ss unit step = 1 0.833 100 = 16.7% 1 Figure 17: Bode plot of the Plant
The controller is designed for speed control loop mentioned in modeling section. The pulse transfer function of the system is: G z = 0.00026 z 0.896 First, system is transformed to w-domain and then MATLAB tool is started with the command sisotool(<system>). Note: For this case the sampling period is chosen as 0.001 sec, because in continuous system, there is a pole at 109.8 rad. In order to see the effect of this only pole, sampling frequency should be high. From the tool s window under Analysis Plots tab, different plots of the system can be observed in real time. To observe the compensators effect on transient response, step response of closed system is selected. Then under Compensator Editor tab, by right clicking in Dynamics panel, a lead compensator is added. Next task is to choose pole and zero of the lead compensator. Since it is not a formal design, it is done based on basic properties of lead compensator. Figure 18: Transient Response of the Plant
First thing to remember about lead compensators is that they mostly affect high frequency behavior and they add positive phase to the system near gain crossover frequency of the plant. In our case plant has a single pole at 109.8 rad, therefore it is expected that this plant has a gain cross over frequency above 109.8 rad. Thus zero and pole of the lead compensator is chosen as -110 and -140 respectively. As it can be seen from the window, MATLAB calculates the maximum phase and the frequency at which the compensator provides that phase. For this lead compensator maximum phase is 6.8 degrees at 124.1 rad, so it is a reasonable design. After lead compensator the system s bode plot is as shown in Figure 19 and transient response is as shown in Figure 20. As expected, the plant s phase margin is increased and gain margin is decreased. However, it should be noted that rise time of the system is almost halved. Lead compensators introduce a high frequency pole-zero pair to the system and this pair cause the roots of the closed system to shift left, making system faster at the expense of gain margin. Now it is time to decrease steady state error. To do so, gain of the plant is increased; however this action also decreases gain margin and may push the system to unstable region. In order to prevent this, a lag compensator is added and then gain is increased. Adding a lag compensator is the same as adding a lead compensator for Control and Estimation tool. After adding the lag compensator, again its pole and zero should be defined. The default pole and zero is actually suitable for this particular plant, which are a pole at -1 and a zero at -10. As it is the case with lead compensator, lag compensator also shifts closed loop poles towards itself, therefore after adding lag compensator transient response worsens. In order to decrease the effect of lag compensator its pole and zero can be shifted left to -50 and -10 respectively.
Figure 19: Bode plot of Lead+Plant Figure 20: Transient Response of Lead+Plant
Then, overall system s bode plot becomes as shown in Figure 21. Figure 21: Bode plot of Lag+Lead+Plant Now that the system has a considerable gain margin (23.1 db), gain of the plant can be increased to obtain better steady state error. For this case it is increased to 7000 from 2000, then the system s transient response becomes as shown in Figure 22. After lead-lag compensator systems specifications become: GM = 12.2 db PM = 87.7 0 Rise time = 0.004 sec e ss unit step = 1 0.946 100 = 5.4% 1 It seems that tough stability margins are improved; it is not a big improvement. That is because lead compensator s contribution was small and the gain margin provided by the lag compensator is spent on steady state error. Besides, it should be added that, adding a lead compensator for this system is useless; because system has already a high frequency pole and sufficient phase margin. Lag
compensator, on the other hand, makes high plant gain possible and thus decreases steady state error. Figure 22:Tansient Response of Lag+Lead+Plant CONCLUSION The mathematical model of solution to the fifth project has been obtained and it has been seen that poor sampling period can degrade original continuous system s representation in discrete domain. However it is also observed that compensator design can still be done, tough specification is not as fine as it is with high sampling rate. In addition, effect of lead-lag compensation has been discussed on pole zero level and on transient response of the closed loop system. It has been seen that pole zero pair of the lead compensator shifts the closed loop poles to the left and contributes to the systems responsiveness; whereas lag compensator makes the system slower but allows more gain to be added to the system which improves steady state behavior of the system.