Answers for Homework #6 for CST 407 02P Assigned 5/10/07, Due 5/17/07 Constructing Evans root locus diagrams in Scilab Root Locus It is easy to construct a root locus of a transfer function in Scilab. Consider the open loop transfer function z H z = z 2 1.8 z 0.8 It is easy to construct a root locus of this transfer function. First, you define the transfer function in Scilab: >H = %z / (%z^2 1.8 * %z + 0.8); (note that you don't have to define H.dt; the Evans root locus doesn't care about that). Then you execute the 'evans' function: >evans(h) Here's the resulting plot: Figure 1: An Evans Root Locus, as is. This isn't very useful. Scilab makes nice root locus plots, but it doesn't do a good job making things look good. You need to do three things to this plot: make the axes isometric, make the plot a reasonable size, and show the unit circle so we can see stability.
You can make the view isometric by setting the figure's isoview parameter to on: >a = gca(); // get the figure's handle >a.isoview = on ; // turn on isometric viewing If you do this to the figure above, you'll still get something that's not very useful. The plot is huge, so you cannot see the unit circle, which is what you're interested in. If you could zoom in, you wouldn't be able to see much detail. You can solve both the size and the detail problems by restricting the range of gains that the evans function sweeps through: >clf; // clear the previous figure >evans(h, 4); // display the root locus plot >a = gca(); // get the figure's handle >a.isoview = on ; // turn on isometric viewing This will give you the following figure: Figure 2: An improved Evans root locus. To make this look good we lay down a unit circle before we do the root locus plot: clf; // clear the figure a = gca(); // get the handle a.isoview = on ; // make it isometric xarc( 1, 1, 2, 2, 0, 64*360); // draw the unit circle evans(h, 4); // Do the plot Do these operations step by step and observe their affect on the figure. When you are done, you should have a figure that look like Figure 3.
Figure 3: Final Evans root locus, finally. This plot shows us how the actual pole positions in a system would vary if it had an open loop transfer function equal to H ol z =a H z and we varied a from 0 to 4 (we specified the 4 in the call to 'evans' above). To automate all this typing, cut and paste Listing 1 into a file named classevans.sci, and put it in the directory that you use when you're using Scilab (you can see your directory in Scilab by typing 'cd' or 'pwd'; you can change it with 'cd'). // A prettier view of the Evans root locus plot function classevans(h, kmax) clf; // clear the figure a = gca(); // get the figure handle a.isoview = "on"; // make it isometric xarc( 1, 1, 2, 2, 0, 64*360); // draw the unit circle if (exists('kmax')) evans(h, kmax); else evans(h); end // if endfunction // Do the plot // Do the plot Listing 1: An automatically pretty Evans root locus.
To load this function into Scilab (it must be done explicitly) type >exec classevans.sci; To use it as we have before, call >classevans(h, 4); Try this with different values for the final gain, such as 1, 10, or 100. See how the final value of the gain changes the plot. Note that now that we've made it so easy, you don't have to explicitly define the system. Try this: >classevans(%z^2 / (%z^2 1.9 * %z + 0.95)); Now try it for different gain values (note that in Scilab you can get previously typed lines by hitting the up arrow key, so you don't have to retype the whole darn thing. Once you have the line, you can edit it with the back arrow key, backspace, delete, and so on): >classevans(%z^2 / (%z^2 1.9 * %z + 0.95), 5); >classevans(%z^2 / (%z^2 1.9 * %z + 0.95), 50); >classevans(%z^2 / (%z^2 1.9 * %z + 0.95), 5000); The Evans root locus in Scilab It is important to have an idea of what your controller design will do to your system behavior, and for this it helps to know ahead of time what a root locus plot will look like. The hard way to learn this is to learn how to construct the Evans root locus plot by hand. The techniques for doing so aren't presented in this class, but they're not a bad thing to learn. We'll learn some of this by making many plots and seeing what their result is. 1. Root loci depart from poles, and arrive at zeros. Even when the loci don't arrive at a zero directly, they are attracted to them. Make Evans root locus plots of systems with the following three openloop gains and compare/contrast their behavior. For each of these plots, report the approximate pole values where the root locus plot departed the real number line, the pole values where it exited the unit circle (if at all), and the ultimate values of each pole (itemize it for both poles, noting if a pole goes to infinity or not). 1 a. H 1 = z 2 1.9 z 0.9 From the graph, the poles leave the real line at about z = 0.95, and they exit the unit circle at z = 0.95 ± j0.3 and a gain of k = 0.1. I can also compute the real line departure point by observing that the denominator of the closed loop transfer function will be z 2 1.9z + 0.9 + k. The real parts of the roots of this polynomial must always sum to 0.95, which dictates the departure point from the real line. If I know that the poles are complex, I can predict that they will be on the unit circle at k = 0.1, because the trailing term in the polynomial is the product of the magnitudes of the poles; because the poles are in complex conjugate they will both hit the unit circle at the same time, and they will do so when 0.9 + k = 1; this must happen when k = 1. Furthermore, I can use the binomial theorem to find that the pole values will be
2 2 z= 1.9 2 ± j 1 1.9 0.95± j 0.312. As yet another alternative, I can observe that the point where the poles leave the real number line will be a value of z where H 1 reaches a local maxima; this will happen where the derivative of H 1 is zero: d dz H z = d 1 1 dz z 2 1.9 z 0.9 = 2z 1.9 z 2 1.9 z 0.9 2, this occurs when the numerator of the above function is zero, which occurs at (surprise, surprise), z = 0.95. z b. H 2 = z 2 1.9 z 0.9 From the graph, the poles split at about 0.95, and one exits the unit circle at z = 1 when the gain k = 3.8. Note that this system is better than the one for 1.a in the sense that you can get a faster system with a reasonable damping ratio, but only a little bit. It is much better in that you have significantly higher gain margin. I can also observe that this system has a denominator polynomial that goes as z 2 (1.9 k)z + 0.9. From this, I know that the poles will have magnitudes whose product is always 0.9; this means that they will be equal when they split from the real number line (and when they rejoin), indicating that they will have a magnitude of z=± 0.9 0.949 (this is equal to 0.95 for all practical purposes). Or I can use the derivative of the transfer function as z is swept along the real number line. Note that this method always works for any system, where the method above depends on the transfer function being 2 nd order. Here's the result: d dz H 1 z = d dz z z 2 1.9 z 0.9 = z2 1.9z 0.9 2z 2 1.9 z = z 2 1.9 z 0.9 2 z 2 0.9 z 2 1.9 z 0.9 2 This gives us entering and exiting points at z=± 0.9 0.949. c. H 3 = z2 0.5 z z 2 1.9 z 0.9 If I scrunch up my eyes I can see that the plot departs the real number line at a magnitude slightly less than 0.95. It's obvious that the plot never leaves the unit circle; the poles just get closer and closer to z = 0, and it takes huge gains to get it there. I can use the magic of the binomial theorem to find the pole departure points: in this case I'm looking at a system characteristic polynomial of (1 + k)z 2 1.9z + 0.9; this can only be real when (1.9/2) 2 (1 + k)(0.9), which is only true for k (1.9/2) 2 /(0.9) 1 = 0.00278, and which gives roots of 0.947 I must have squinted really hard.
Again, the above technique only works for binomial system polynomials. Using the alternate d method, I get dz H z = d z 2 1 dz z 2 1.9 z 0.9 = 2z3 3.8 z 2 1.8 z 2z 3 1.9 z 2 z 2 1.9 z 0.9 2 which works out to d dz H 1 z = d dz z 2 z 2 1.9 z 0.9 = 1.9 z2 1.8 z z 2 1.9 z 0.9 2 ; this is zero at z = 0 and z = 1.8/1.9 = 0.947. 2. Poles that are unmatched by zeros tend to go off to infinity in a starburst pattern from the root locus plot. This can be most easily seen by plotting an all pole plot, but is also apparent for other plots. Try these: a. An all delay transfer function is just z n. Do root locus plots of H ol = 1 z 2 H ol = 1 z 3 H ol = 1 z 4 (note that the root locus plot shows the asymptotic directions for more complicated plots the loci approach these asymptotes). Figure 4: Root locus using classevans(1/%z^2, 5) Figure 5: Root locus from classevans(1/%z^3, 5)
Figure 6: Root Locus plot using classevans(1/%z^4, 5) b. The poles don't have to be located one on top of another. Take a system who's structure is a double integrator and a single pole: 0.001 H ol = z 1 2 z 0.95 Try this for a final gain of 1, then a final gain of 1000. Given the results from the gain of 1, is there any positive gain value for which this system will be stable? Given the results from the gain of 1000, does the locus approach the asymptotes? Looking at Figure 7 you can see that the loci starting from the double root at z = 0 immediately depart from the unit circle; if they follow their asymptotes as they seem to be doing they will remain unstable.
Figure 7: Root Locus with gain ending at 1 classevans(0.001/((%z 1)^2 * (%z 0.95)), 1) Looking at Figure 8 you can see that the poles follow their asymptotes to the point where you cannot easily discern the area (easily seen in Figure 7) where they don't follow the asymptotes. Figure 8: Root Locus with gain ending at 1000 classevans(0.001/((%z 1)^2 * (%z 0.95)), 1000) c. Poles and zeros that are close together will initially act like they are the only things on the plot
their asymptotes become their tracks for low gains. At higher gains their loci begin to be affected by elements farther away. Consider a system that has a motor driven by a torque, and controlled by a PID controller. This system will have a double integrator and a low frequency pole, like the previous problem, but it will have a pair of zeros from the controller: H ol = z 2 1.53 z 0.6 z 1 2 z 0.95 Plot the root locus for this open loop gain with gains of 1, 2, and 10, then answer the following: Are there gains that will stabilize this system? Are there gains that are too low to stabilize this sysem? Are there gains that are too high to stabilize this system? Figure 9 through Figure 11 show the results. From Figure 9 you can see that a gain of 1 will stabilize this system, and will put the poles at a fairly reasonable spot as far as damping goes (although it could be better). You can also see that for very low gains the loci starting at z = 1 curl away from the stability circle before the zeros start pulling them in compare this to the locus in Figure 7, where the poles curl away from the stability circle in much the same way, but never come back inside because there are no zeros. Figure 9: Plot from classevans((%z^2 1.53 * %z + 0.6)/((%z 1)^2*(%z 0.95)), 1)
Figure 10: Plot from classevans((%z^2 1.53 * %z + 0.6)/((%z 1)^2*(%z 0.95)), 2) Figure 11 shows that for high gains, the root locus exits the plot at z = 1. Note that for most real systems there will probably be a multiplicity of poles and zeros around z = 0, which will cause the real instability point to happen at a lower gain, and at some frequency other than ½ the sampling rate. Figure 11: Plot from classevans((%z^2 1.53 * %z + 0.6)/((%z 1)^2*(%z 0.95)), 10) 3. You can use the Evans root locus plot for systems who's transfer function varies by a parameter in a linear way, but which doesn't conform to the open loop transfer function and a gain model. Consider a system with a double integrating plant, and a PD (proportional derivative) controller:
k d (1-d)(z - 1) + - Σ z - d + Σ + z + 1 (z - 1) 2 k p Figure 12: A System with PD Control. This system has an open loop transfer function that's equal to H ol z = k k 1 d z 1 z 1 p d z d 2 z 1 which expands to H ol z = k 1 d k p d z 2 1 d k p z k p 1 d k d z 3 2 d z 2 1 2d z d and a closed loop transfer function that's equal to k H z = p 1 d k d z 2 1 d k p z k p d 1 d k d z 3 2 d k p 1 d k d z 2 1 2d 1 d k p z 1 d k d d k p d a. Let k p = 0.014 and k d = 0.14. Separate the denominator of H such that you have H z = k p 1 d k d z 2 1 d k p z k p d 1 d k d P 0 z dp 1 z where P 0 and P 1 are each polynomials in z with no other dependencies. I get P 0 =z 3 2 k p k d z 2 1 k p z k d and P 1 = k d 1 z 2 2 k p z 1 k p k d b. Construct an Evans root locus plot with a gain that ranges from 0 to 1 with the transfer function T fol z = P 1 z P 0 z See Figure 13,
Figure 13: Root Locus as d is varied. c. What is the physical meaning of this root locus plot? The differentiator pole limits the frequency of the differentiator action in the extreme, when d = 1 the differentiator ceases to have any effect at all. As this pole approaches 1, the differentiator loses it's stabilizing effect, and the loop goes unstable. d. How might you use this plot to determine the value of d in a system? With a simplified system model like this lots of differentiator action leads to more stability. In real systems, however, too much differentiator gain can cause instability at high frequencies. I would use a plot like this to guide my selection of d both by using it to tell me what to expect while looking at a Bode plot, and to determine directly, through experimentation with the final gain value, the value that will improve system performance without driving the dominant (i.e. slow) pole too close to the stability boundary. Bode Plots In Scilab, you construct a Bode plot using the bode function. You must define the time domain in your transfer function; this is done by setting the 'dt' field. To plot a Bode plot for the system in problem 3, can keep the proportional and differential gains at 0.014 and 0.14 respectively, but we must choose a value of d. I'll use 0.1: >kp = 0.014; kd = 0.14; // set the gains >d = 0.1; // and the differentiator pole >// set the transfer functions >H = kp + kd * (1 d) * (%z 1) / (%z d); H.dt = 'd'; >G = (%z + 1) / (%z 1)^2; G.dt = 'd'; >clf; bode(h * G, 0.001, 0.4, 0.01); // make a bode plot Listing 2: Constructing a Bode plot from transfer functions. Note that I have changed the plot around: instead of allowing Scilab to use it's defaults I have forced the plot to range from 0.001 times the sampling rate up to 0.4 times the sampling rate, and I have forced it to
show a good number of points. Figure 14 shows the results. If we assume that the system was stable to start with, this plot allows us to determine the overall system stability. Figure 14: A Bode Plot of a System. 4. For the system above: a. What are the gain and phase margins for this system? The open loop gain passes through 0dB at 0.045 times the sampling rate; at this frequency the phase shift is 127 degrees or so, for a phase margin of 180 127 = 53 degrees. The open loop phase passes through 180 degrees at 0.23 times the sampling rate, where the gain is about 15dB; thus the gain margin is 15dB. b. Modify H with a differentiator pole of 0.8 (this make the differentiator less assertive at high frequencies, and is often good if you have measurement noise problems). Listing 3 shows how I generate the modified Bode plot, while Figure 15 shows the plot itself. >kp = 0.014; kd = 0.14; // set the gains >d = 0.8; // and the differentiator pole >// set the transfer functions >H = kp + kd * (1 d) * (%z 1) / (%z d); H.dt = 'd'; >G = (%z + 1) / (%z 1)^2; G.dt = 'd'; >clf; bode(h * G, 0.001, 0.4, 0.01); // make a bode plot Listing 3: Constructing a Bode plot from transfer functions.
Figure 15: Bode plot of system with reduced bandwidth differentiator. c. For the modified system, what are the gain and phase margins? The open loop gain crosses 0dB at about 0.044 times the sampling rate (this is essentially the same frequency as before), but the phase at this frequency is now 163 degrees. This gives a phase margin of 180 163 = 17 degrees; this is loss of 36 degrees of phase margin, taking us from a system with low but perfectly acceptable phase margin to one with a dangerously low phase margin. The open loop phase phase now crosses 180 degrees at 0.083 times the sampling rate, at which point the open loop gain is 10dB, for a gain margin of 10dB. 5. You measure the frequency response of a thermal system with your controller, which is sampling at 20Hz. You put the results in the file freq_resp.txt (attached; you may want to see what its format is). Put it in the directory that Scilab points to (check with 'pwd', change with 'cd'). You can read it in using >[x, text] = fscanfmat('freq_resp.txt'); // get the raw data >fr = x(:, 1); // get the frequencies >rr = x(:, 2) + %i * x(:, 3); // get the responses >clf; bode(f, r); // check the response >Ts = 0.05; // set the sample time You should get a bode plot that looks like Figure 16.
Figure 16: A Bode Plot of a Thermal System. You are going to wrap this plant with a PID controller. Define the Scilab function in Listing 4:
// PID bode plotter for problem 5, homework 6 // // inputs: // kp: Proportional gain // ki: integrator gain // kd: derivative gain function trypid(kp, ki, kd) // Note that we're assuming that the following are // already defined: // Ts sampling rate // fr frequencies of measured plant responses // rr measured plant responses, as complex numbers // make the controller G = kp + kd * (%z 1) / %z + ki / (%z 1); // Get the open loop response r_ol = rr.* horner(g, exp(%i * 2 * %pi * Ts * fr)); // show open loop Bode plot scf(0); // select graphic 0 clf; bode(fr, r_ol); // show the plot // show closed loop Bode plot scf(1); // select graphic 1 clf; bode(fr, r_ol./ (1 + r_ol)); endfunction // show the plot Listing 4: A PID Bode Plotter. a. I have done a preliminary loop tuning, and I've found that a proportional gain of 30 and a derivative gain of 100 gives pretty good results. Here's what I've done: >trypid(30, 0, 100); This got me the open loop bode plot shown in Figure 17. Look at this figure, and report on the gain and phase margins.
Figure 17: Thermal system with PD control ('cause ki = 0). The open loop gain crosses the 0dB point at about 0.52Hz, with a phase of 100 degrees for a phase margin of 80 degrees. The open loop phase crosses 180 degrees at about 2.6Hz, where the gain is 11dB, for a gain margin of 11dB. b. The system above would work OK, except that thermal systems are subject to variations due to ambient temperature changes. You can fix this by adding some integral action, for example, to see what happens with an integrator gain of 0.1 you call trypid(30, 0.1, 100); Keep increasing the integrator gain above until your phase margin is around 60 degrees. Include your Bode plots in your homework. Report on your integrator gain, the phase margin you achieved, and the gain margin you observe. Comment on the looks of the closed loop plot is there anything there that may not be good?
Figure 18: Thermal Control with PID Open loop. This required an integrator gain of 1.8 it is unusual to have an integrator gain that's more than 1 in a real system; I assume my model was not realistic (but hey, this is homework) The phase crosses 180 degrees at about 2.6Hz, where the gain is 10dB so the gain margin hasn't changed that much.
Figure 19: Closed loop Bode plot of thermal system. The 3dB peaking around ¼Hz is to be expected; the long, slow drop off between 0.4Hz and 2Hz is a bit odd, and can usually be improved. c. For the above system, increase the proportional gain from 30 to 50 and plot. Include your plots. Report the new phase and gain margins, and comment on any change that you observed in your closed loop Bode plot.
Figure 20: Open loop thermal system bode plot with increased proportional gain. Figure 20 shows the open loop response. The 0dB point has been shifted up to 0.8Hz, with a phase margin of around 55 degrees. The phase crossing frequency has gone down slightly to 2.5 or 2.4Hz, but the gain margin is holding at 10dB. The closed loop response shown in Figure 21 is much better note that not only does the system now have a 3dB bandwidth in excess of 1Hz, but that the amplitude response also very flat out to that point.
Figure 21: Closed loop thermal system Bode plot with increased proportional gain.