Lab 3: PI Control of Incubator In the previous laboratory we found that a simple first-order model of the incubator has the transfer function Θ πΆπ = π π +π where N is the PWM value given to the heater resistor, p is the system time constant (or rather, its inverse) and C gives the magnitude of the response in Fahrenheit. Our task for this lab is to design a suitable control system for the incubator. As we learned in class, the first-order system is best controlled through a combination of proportional and integral control. Temperature Setpoint s + E πΎπ + πΎπ π N πΆπ π +π Temperature (Output) A control system for the incubator is shown above. The error for the system is given by πΈ(π ) = Θπ − Θ And the output of the controller (and input to the incubator) is π = (πΎπ + πΎπ ) (Θπ − Θ) π Of course, the maximum allowable value for N is 255 - this puts a limit on the values that we can use for Kp and Ki. Solving for the transfer function of the controlled system gives πΎπ π + πΎπ Θ = 2 Θπ π + (1 + πΎπ πΆ)ππ + πΎπ πΆπ This is a second-order system with numerator dynamics (there is at least one power of s in the numerator). In exploring the behavior of the controlled system, we will ignore the numerator dynamics for the moment. The standard form for the second-order transfer function is π ππ2 = πππ π 2 + 2πππ π + ππ2 1 so that ππ2 = πΎπ πΆπ (1) 2πππ = (1 + πΎπ πΆ)π (2) To arrive at suitable values for Kp and Ki, we must take a slight detour into the realm of second-order systems. Behavior of Second Order Systems The transfer function of the most basic second order system is given by π ππ2 = πππ π 2 + 2πππ π + ππ2 where ζ is the damping ratio and ωn is the natural frequency. Applying a unit step input to the system results in 1 ππ2 π= ( 2 ) π π + 2πππ π + ππ2 Looking at Row 24 in the Laplace transform table, the step response of the second-order system is π₯(π‘) = 1 − ππ −ππ π‘ π sin(π π‘ + π) π π ππ (3) where ππ = ππ √1 − π 2 is the damped natural frequency and φ is the phase angle. Of course, this response is only valid for underdamped systems, where ζ is less than 1. The response of the second order system to a step input is shown in the figure below, for a variety of damping ratios. As you can see, a low damping ratio produces large oscillations, and takes a long time to settle down, while a high damping ratio hardly oscillates at all. On the other hand, the low damping ratios reach the setpoint quickly (although they overshoot it soon afterward) and the high damping ratios take longer to reach the setpoint. Settling Time We can define a few performance parameters for the second order system. First, we might be interested in how long it takes the system to “settle out” to its steady-state value. The exponential term in Equation (3) gives the “envelope” of the oscillations and determines how quickly they die out. If we define the time constant, τ, 2 Step response of second order system 1.8 = 0.1 1.6 = 0.3 = 0.5 1.4 = 0.7 Response 1.2 1 0.8 = 0.9 0.6 0.4 0.2 0 0 5 10 15 20 25 Time(s) π= then the oscillations decay to π −ππππ = π 30 35 40 45 50 1 πππ 1 ) −πππ ( πππ = 0.3679 or 37% of their peak value after one time constant has elapsed. Usually, we define the settling time to be four time constants so that 4 ) −πππ ( ππ π π = 0.0183 the oscillations have decayed to less than 2% of their peak value after the settling time has elapsed. Maximum Overshoot We are also interested in the maximum overshoot: the peak value reached by the system at the beginning of its oscillations. The time required to reach the maximum overshoot can be found by taking the time derivative of Equation (3) and setting it to zero. ππ₯ πππ2 −ππ π‘ π sin(π + π) − π π −πππ π‘ cos(π π‘ + π) = 0 = π π π π ππ‘ ππ 3 [ πππ sin(ππ π‘ + π) − cos(ππ π‘ + π)] π −ππππ‘ = 0 ππ since the exponential function never reaches zero, we conclude that the quantity inside the brackets must be zero. πππ sin(ππ π‘ + π) − cos(ππ π‘ + π) = 0 ππ Using the definition of damped natural frequency gives π √1 − π 2 sin(ππ π‘ + π) − cos(ππ π‘ + π) = 0 Looking at the entry in Row 24, we see that the quantity in front of the sine function is the inverse of the phase angle 1 sin(ππ π‘ + π) − cos(ππ π‘ + π) = 0 tan π Now use the trigonometric sum formulas to separate out the quantities inside parentheses 1 (sin ππ π‘ cos π + cos ππ π‘ sin π) − cos ππ π‘ cos π + sin ππ π‘ sin π = 0 tan π Divide through by cos π 1 (sin ππ π‘ + cos ππ π‘ tan π) − cos ππ π‘ + sin ππ π‘ tan π = 0 tan π sin ππ π‘ + cos ππ π‘ − cos ππ π‘ + sin ππ π‘ tan π = 0 tan π sin ππ π‘ + sin ππ π‘ tan π = 0 tan π sin ππ π‘ + sin ππ π‘ tan2 π = 0 sin ππ π‘ + 1 − π2 sin ππ π‘ = 0 π2 sin ππ π‘ = 0 This is an amazingly simple result after so long a derivation! For this to be true, we must have 4 ππ π‘π = ππ or π‘π = ππ ππ This gives the times of each peak (or trough) in the oscillations. Since we first set out to find the maximum overshoot, we are really only interested in the first peak π‘π = π ππ Substitute this into Equation (3) to find the peak value π₯(π‘π ) = 1 − π₯(π‘π ) = 1 − ππ ππ −ππ ππ π π ππ sin ( + π) ππ ππ ππ ππ √1 − π 2 π₯(π‘π ) = 1 + π − 1 √1 − π 2 πππ π ππ √1−π 2 π − ππ √1−π 2 sin(π + π) sin(π) To find sin(π), let us draw a triangle using the definition of tan(π). The hypotenuse of the triangle is found using the Pythagorean theorem 2 π 2 + (√1 − π 2 ) = 1 1 √1 − π 2 Thus, we have sin π = √1 − π 2 π The maximum overshoot is then π₯(π‘π ) = 1 + π − ππ √1−π 2 As the damping ratio approaches 1, the peak value also approaches 1, as expected. Note that the peak input was found for a unit step input. Often we are interested in the maximum percentage overshoot, regardless of the magnitude of the step input. In this case, we define ππ = 100% ⋅ π − ππ √1−π 2 5 Rise Time We are also interested in how long it takes the system to initially reach its steady-state value, before the oscillations begin. Since the steady-state value is 1 for the unit step input, we can use Equation (3) to find 1=1− 0= ππ −ππ π‘ π π sin(π π‘ + π) π π π ππ ππ −ππ π‘ π π sin(π π‘ + π) π π π ππ As before, the exponential function never reaches zero, so that sin(ππ π‘π + π) = 0 ππ π‘π + π = ππ π‘π = ππ − π ππ This formula can be used to find the time of each crossing of the steady-state value. Of course, we are mainly interested in the first crossing, where n = 1. The table below summarizes some of the important formulas we’ve derived so far for the second-order system. Table 1: Handy formulas for second-order systems Quantity Variable Formula Natural frequency ππ π √ π Damping ratio π Damped natural frequency ππ ππ √1 − π 2 Settling time π‘π 4 πππ Rise time π‘π π−π ππ Peak time π‘π π ππ Maximum percent overshoot ππ π 2√ππ 100% ⋅ π − ππ √1−π 2 6 Designing the Control System Recall that the transfer function for the incubator system (with PI control) is given by πΎπ π + πΎπ Θ = 2 Θπ π + (1 + πΎπ πΆ)ππ + πΎπ πΆπ Using the formulas derived above, we find that π= ππ = √πΎπ πΆπ (1 + πΎπ πΆ)π 2√πΎπ πΆπ To determine the gains Kp and Ki, we must specify two of the parameters of the second order response. As a first guess, let us try setting the maximum overshoot to 1.1 (or 10% above the steady-state value) and the settling time to 1000s. Rearrange the maximum overshoot equation to solve for damping ratio (ln π)2 π=√ 2 = 0.5912 π + (ln π)2 for 10% (0.1) overshoot. The settling time is π‘π = 4 πππ so that ππ = 4 rad = 0.00677 ππ‘π s Substitute these values into Equations (1) and (2) to find suitable values for Kp and Ki. For the parameters given, we have πΎπ = 1.2845 πΎπ = 0.0354 We can use these values in the Simulink simulation shown below 7 Response of Incubator System Input to Heating Resistor 25 140 120 20 15 80 N Theta (deg) 100 60 10 40 5 20 0 0 200 400 600 Time (s) 800 1000 0 1200 0 200 400 600 Time (s) 800 1000 1200 The results are shown in the plots above. We must plot the PWM value sent to the heating resistor to make sure it doesn’t exceed 255. In this case, we are comfortably below 255 - the maximum value sent to the resistor is 120 or so. Given this low number, you may wish to increase the performance of the controller by lowering the settling time. A settling time of 400 seconds results in the plots below. Input to Heating Resistor 250 20 200 15 150 N Theta (deg) Response of Incubator System 25 10 100 5 50 0 0 100 200 300 Time (s) 400 500 600 0 0 100 200 300 Time (s) 400 500 600 8