Solution for Take Home Exam 1 Problems 2.6, 2.7, 2.8, 2.12, 3.4, 3.5, 3.9, & 3.10. 2.6 For the open-loop system G ( s ) =

1 , s ( s + 25) 2

2

a) Design feedback assuming you have access to all the state elements. Place the closedloop system poles at s = [-1 +- 1j, -0.5 +- 5j]. b) Design an estimator for the system so that it has poles at s = [-2 +- 2j, -2 +- 8j]. c) Find the transfer function of the complete controller consisting of the control from part a) and the estimator from part b). Please note that some students achieved better results than this. This is not intended to show the â&#x20AC;&#x2DC;bestâ&#x20AC;&#x2122; result; it is to illustrate the main elements of a solution procedure and display of results. The matlab code is: function prob_2_6() % sysG = tf(1,[1 0 25 0 0]); sys = ss(sysG); [F,G,H,J] = ssdata(sysG); [F,G,H,J] = ssdata(sys); % part a pc = [-1-i,-1+i,-.5+5i,-.5-5i]; K = acker(F,G,pc) %part b pe = [-2-2*i,-2+2*i,-2+8*i,-2-8*i]; L = acker(F',H',pe)' % part c rsys = ss(F-L*H-G*K,L,-K,J); rsys = reg(sys,K,L); sysCL = -feedback(sys*rsys,1,+1); figure(1) step(sysCL) [num,den] = tfdata(rsys); tf(num,den)

The results are: K= 6.0000 L=

2.1250 26.2500 25.2500

-565.5000 208.0000 134.0000 16.0000 Transfer function: -970.5 s^3 + 3763 s^2 - 4.391e004 s - 2.747e004 ----------------------------------------------------------s^4 + 11 s^3 + 120.2 s^2 + 591.5 s + 1611

Step Response 1.8 poleplace transfer function

1.6 1.4

Amplitude

1.2 1 0.8 0.6 0.4 0.2 0

0

1

2

3

4

5

6

Time (sec)

Note the difference in the response between the desired response and the controlled response with the estimator. My only explanation is that it’s an artifact of the estimator placement poles. 2.7 Consider a pendulum with control torque Tc and disturbance torque Td whose differential equation is: θ + 4θ = Tc + Td . Assume there is a potentiometer at the pin that measures the output angle θ , that is, y =θ .

a) Design a lead compensation using a root locus that provides for an Mp < 10% and a rise time tr < 1 sec. b) Add an integral term to your controller so that there is no steady-state error in the presence of a constant disturbance, Td, and modify the compensation so that the specifications are still met. The code is: function prob_2_7a() % sys = tf(1,[1 0 4]); a = 2; b = 150; sysd = tf([1 a],[1 b]); figure(1) margin(sys) figure(2) OL = sys*sysd; margin(OL) figure(3) k = 0:10:1500; rlocus(OL,k),axis([-10,0,0,3]) w = 50; z = 1; k = rlocfind(OL,-z*w+w*sqrt(1-z*z)*i); figure(4) OL = k*OL; margin(OL) figure(5) sysCL = feedback(OL,1); y = step(sysCL,5); ymax = max(y); Mp = (ymax/y(end)-1)*100; step(sysCL,3),grid on title(['step with [Mp,k] = ',num2str([Mp,k])])

Bode Diagram Gm = Inf dB (at Inf rad/sec) , Pm = 73.8 deg (at 34.1 rad/sec) 400

Magnitude (dB)

300 200 100 0 -100 -315

Phase (deg)

-360 -405 -450 -495 -540 -1

10

0

1

10

2

10

3

10

10

4

10

step w ith [Mp,k] = 9.9573885

5216.6667

1.4

1.2

Amplitude

1

0.8

0.6

0.4

0.2

0

0

0.5

1

1.5 Time (sec)

2

2.5

3

The matlab code is: function prob_2_7b() % sys = tf(1,[1 0 4]); a = 3; a1 = 0.15; b = 150; sysd = tf([1 a],[1 b])*tf([1 a1],[1 0]); figure(1) OL = sys*sysd; margin(OL) figure(2) % subplot(211) k = 0:10:3000; rlocus(OL,k),axis([-10,0,0,4]) w = 0.25; z = 0.6; k = rlocfind(OL,-z*w+w*sqrt(1-z*z)*i); figure(3) % k = 220; OL = k*OL; margin(OL) figure(4) sysCL = feedback(OL,1); y = step(sysCL); ymax = max(y); Mp = (ymax/y(end)-1)*100; step(sysCL) title(['step with [Mp,k] = ',num2str([Mp,k])]) figure(5) sysDist = feedback(sys,sysd); step(sysDist)

Bode Diagram Gm = Inf dB (at Inf rad/sec) , Pm = 45.3 deg (at 3.46 rad/sec) 400

Magnitude (dB)

300 200 100 0 -100 -200 -315

Phase (deg)

-360 -405 -450 -495 -540 -3

10

-2

10

-1

10

0

10

1

10

2

3

4

10

10

10

50

60

70

step w ith [Mp,k] = 0

261.1323

1 0.9 0.8 0.7

Amplitude

0.6 0.5 0.4 0.3 0.2 0.1 0

0

10

20

30 Time (sec)

40

Step Response 0.5 0.45 0.4 0.35

Amplitude

0.3 0.25 0.2 0.15 0.1 0.05 0

0

1000

2000

3000

4000

5000

6000

7000

8000

Time (sec)

2.8 Consider a pendulum with control Tc and disturbance torque Td whose differential equation is θ + 4θ = Tc + Td . Assume there is a potentiometer at the pin that measures the output angle θ , that is, y =θ . a) Design a lead compensation using frequency response that provides for an PM > 50 degrees and a bandwidth > 1 rad/sec. b) Add an integral term to your controller so that there is no steady-state error in the presence of a constant disturbance, Td, and modify the compensation so that the specifications are still met. The matlab code is: function prob_2_8a() % w = 5; a = w/sqrt(10); b = w*sqrt(10); k = 100; sys1 = tf(1,[1 0 4]); D = k*tf([1 a],[1 b]); sys2 = D*sys1; figure(1) margin(sys1) figure(2) margin(sys2)

The original plant bode diagram is shown below. Bode Diagram Gm = Inf dB (at Inf rad/sec) , Pm = 0 deg (at 2.24 rad/sec) 150

Magnitude (dB)

100

50

0

-50 -180

Phase (deg)

-225 -270 -315 -360 -1

0

10

1

10

10

The compensated system bode diagram is: Bode Diagram Gm = Inf dB (at Inf rad/sec) , Pm = 53.9 deg (at 6.61 rad/sec) 400

Magnitude (dB)

300 200 100 0 -100 -315

Phase (deg)

-360 -405 -450 -495 -540 -1

10

0

10

1

10

2

10

3

10

Step Response 1.4

1.2

Amplitude

1

0.8

0.6

0.4

0.2

0

0

0.5

1

1.5

Time (sec)

The main issue guiding the design of the above is to avoid the resonant peak at 2 rad/sec. Consequently, the frequency crossover must be > 2 rad/sec. As shown in the bode plot above the bandwidth > 6.61 rad/sec, thus avoiding instability due to oscillation (see the step response above). In part b) we are to add an integrator, which will increase the slope of the system. So, the controller has 2 objectives: 1) Avoid resonant peak at 2 rad/sec by crossing over > 2 rad/sec. 2) Stabilize an increased slope. Since we must get more ‘lift’ out of our lead the simplest approach is to provide 2 sections of the original lead as below. s +a s +b K  s + a  s + a    Lead in part b): D ( s ) =  s  s + b  s + b 

Lead in part a): D ( s ) = K

The matlab code is: function prob_2_8b() % w = 7; a = w/(10);

b = w*(10); k = 40000; sys1 = tf(1,[1 0 4]); D = k*tf([1 a],[1 b 0])*tf([1 a],[1 b]); sys2 = D*sys1; figure(1) margin(sys1) figure(2) margin(sys2) figure(3) sysdist = feedback(sys1,D); step(sysdist,20)

Note that the integrator is added in the 1st section of D above. Note also, that figure (3) displays the disturbance rejection capabilities of the new system. Bode Diagram Gm = Inf dB (at Inf rad/sec) , Pm = 0 deg (at 2.24 rad/sec) 150

Magnitude (dB)

100

50

0

-50 -180

Phase (deg)

-225 -270 -315 -360 -1

10

0

10

1

10

Bode Diagram Gm = 24.3 dB (at 68.6 rad/sec) , Pm = 66.7 deg (at 8.56 rad/sec) 400

Magnitude (dB)

300 200 100 0 -100 -200 -270

Phase (deg)

-360 -450 -540 -630 -2

-1

10

0

10

1

10

2

10

10

3

4

10

10

Step Response

step response

1.5

1

0.5

0

0

2

4

6

8

10

12

14

16

18

20

14

16

18

20

Time (sec) Step Response disturbance response

0.06

0.04

0.02

0

0

2

4

6

8

10 Time (sec)

12

2.12 For the open-loop system G ( s) =

1 , use a single lead compensation in s ( s + 2s + 100 ) 2

2

the feedback to achieve as fast a response as possible. From the bode diagram of the plant model a single lead will only have stabilizing effect up to ~10 rad/sec. Note that it would take 3 or more leads to stabilize the phase margin at 10 rad/sec. The matlab code is: function prob_2_12() % sysG = tf(1,[1 2 100 0 0]); figure(1) margin(sysG) Wn = 1; a = Wn/10; b = Wn*10; k = 1800; D = tf(k*[1 a],[1 b]); figure(2) margin(D*sysG) syscl = feedback(D*sysG,1); damp(syscl) figure(3) step(syscl) Bode Diagram Gm = Inf , Pm = -0.115 deg (at 0.1 rad/sec) 50

Magnitude (dB)

0 -50 -100 -150 -200 -180

Phase (deg)

-225 -270 -315 -360 -1

10

0

1

10

2

10

Bode Diagram Gm = 4.64 dB (at 9.11 rad/sec) , Pm = 74.3 deg (at 1.83 rad/sec) 200

Magnitude (dB)

100

0

-100

Phase (deg)

-200 -90

-180

-270

-360 -3

-2

10

-1

10

0

10

1

10

2

10

3

10

10

Step Response 1.4

1.2

Amplitude

1

0.8

0.6

0.4

0.2

0

0

2

4

6

8 Time (sec)

The damping results are:

10

12

14

16

Eigenvalue

Damping

-1.06e-001 -2.19e+000 -8.71e+000 -4.96e-001 + 9.41e+000i -4.96e-001 - 9.41e+000i

1.00e+000 1.00e+000 1.00e+000 5.26e-002 5.26e-002

Freq. (rad/s) 1.06e-001 2.19e+000 8.71e+000 9.43e+000 9.43e+000

The damping coefficient is 0.0526, which is slightly over 0.05 (the lower limit). Therefore, this is very close to the fastest response while maintaining the damping coefficient limit. 3.4 For the compensator D( s ) = 5

s +2 use Eulerâ&#x20AC;&#x2122;s forward rectangular method to s + 20

determine the difference equations for a digital implementation with a sample rate of 80 Hz. Repeat the calculations using the backward rectangular method and compare the difference equation coefficients. The matlab code is: function prob_3_4() % T = 1/80; a = 2; b = 20; k = 5; cforward = [1-b*T,k*(a*T-1),k] cbackward = [1/(1+b*T),-k/(1+b*T),k*(1+a*T)/(1+b*T)]

The results are: cforward = 0.7500 -4.8750

5.0000

cbackward = 0.8000 -4.0000

4.1000

3.5 The read arm on a computer disk drive has the transfer function G(s) = 1000/s/s. Design a digital PID controller that has a bandwidth of 100 Hz, a PM of 50 degrees, and has no output error for a constant bias torque from the drive motor. Use a sample rate of 6 kHz.

The 1st step is to design a lead that satisfies the requirements in the continuous time Td s 2 + Ti s + 1 domain. Therefore, D( s ) = which may be rewritten as Ti s T 1 s2 + i s + KTd Td Td . We may now use pole placement in the numerator to help D(s) = Ti s achieve the specs. Now we inspect the bode plot of the plant. The plot on the left is the uncompensated plant while the plot on the right is the compensated plant.

Bode Diagram Gm = 0 dB (at 31.6 rad/sec) , Pm = 0 deg (at 31.6 rad/sec) 20

Bode Diagram Gm = -15 dB (at 146 rad/sec) , Pm = 54.3 deg (at 453 rad/sec) 200

15 150

5

Magnitude (dB)

Magnitude (dB)

10

0 -5

100

50

-10 0

-20 -179

-50 -90

-179.5

-135 Phase (deg)

Phase (deg)

-15

-180

-180.5

-180

-225

-181

-270 1

2

10

10

0

1

10

2

10

3

10

4

10

We can then place the roots of the numerator significantly below the desired bandwidth using a damping coefficient of 1 for real response. The pole placement concept is Ti 1 2 = s 2 + 2ζws + w 2 where ς = 1 and w = 2π100/f, where f >=4 illustrated as s + s + Td Td and f is used for tuning. The sampling effect on PM is calculated by ζφ = − matlab code follows:

function Prob_3_5() %

wT . The 2

G = tf(1000,[1 0 0]); w = 2*pi*100/4.3;% require 2 zeroes to be a factor of ~4 below desired BW % to achieve desired PM. This factor becomes a tuning parameter. T = 1/6000; z = 1; % z = .707; Td = 1/w/w; Ti = Td*2*z*w; k = 120; % k = 70; kk = k*Td/Ti; D = tf(kk*[1 Ti/Td 1/Td],[1 0]); k*[(1+T/Ti+Td/T),-(1+2*Td/T),Td/T] % equation 3.17, page 66 figure(1) subplot(2,2,[1 3]) margin(G),grid on subplot(2,2,[2 4]) margin(G),grid on,hold on margin(D*G),grid on,hold off figure(2) [Gm,Pm,Wcg,Wcp] = margin(D*G); sysCL = feedback(D*G,1); % [mag,phase,w] = bode(sysCL); % loglog(w,mag(:)),grid on step(sysCL),grid on title(['step response PM = ',num2str(Pm-Wcp*180/pi*T/2)])

The step response with final PM is: step response PM = 52.1016 1.4

1.2

Amplitude

1

0.8

0.6

0.4

0.2

0

0

0.005

0.01

0.015

0.02 Time (sec)

0.025

0.03

0.035

0.04

The remaining part is to compute the discrete PID implementation. We may use eqn 3.17, p. 66 of the text. The results are: k*[(1+T/Ti+Td/T),-(1+2*Td/T),Td/T] = [155.1829 -187.4434

3.9 The antenna tracker has the transfer function G ( s ) =

33.7217]

10 . Design a continuous s( s + 2 )

lead compensation so that the closed-loop system has a rise time tr < 0.3 sec and overshoot Mp < 10%. Modify the matlab file fig32.m so that you can evaluate the digital version of your lead compensation using Eulerâ&#x20AC;&#x2122;s forward rectangular method. Try different sample rates, and find the slowest one where the overshoot does not exceed 20%. For the specs we 1st try to establish the bandwidth: wn = 1.8/tr = 1.8/0.3 = 6 rad/s. So, our bandwidth should be 6 rad/s or greater for a tr < 0.3 s. Mp = 10% is relatively low so try for a large PM. The bode plot of the plant shows that the PM must be raised and the bandwidth increased by the compensator. Bode Diagram Gm = Inf dB (at Inf rad/sec) , Pm = 34.9 deg (at 2.86 rad/sec) 40

Magnitude (dB)

20 0 -20 -40 -60

Phase (deg)

-80 -90

-135

-180 -1

10

0

1

10

The matlab code is shown below. function Prob_3_9() % close all G = tf(10,[1 2 0]); k = 77; w = 6;

2

10

a = w/5; b = w*5; D = tf(k*[1 a],[1 b]); figure(1) margin(G) figure(2) margin(D*G) figure(3) for Hz = 25:120 frHz(Hz) = Hz; bd(Hz) = b/Hz; end plot(frHz',bd'),grid on axis([25 120 0 4]) xlabel('Hz') ylabel('discrete pole') title('stability analyses for discrete b') figure(4) tfin = 10; t = [0:0.01:tfin]; y = step(feedback(D*G,1),t); ymax = (max(y)/y(end)-1)*100; step(feedback(D*G,1),0.5),hold on Hz = 34; Dd = tf(k*[1 -(1-a/Hz)],[1 -(1-b/Hz)],1/Hz); Dnum = k*[1 -(1-a/Hz)]; Dden = [1 -(1-b/Hz)]; [numGd,denGd] = c2dm(10,[1 2 0],1/Hz,'zoh'); OL = tf(conv(Dnum,numGd),conv(Dden,denGd),1/Hz); y = step(feedback(OL,1),[0:1/Hz:tfin]); ymax = [ymax,(max(y)/y(end)-1)*100]; step(feedback(OL,1),[0:1/Hz:0.5]),hold on Hz = 32; Dd = tf(k*[1 -(1-a/Hz)],[1 -(1-b/Hz)],1/Hz); Dnum = k*[1 -(1-a/Hz)]; Dden = [1 -(1-b/Hz)]; [numGd,denGd] = c2dm(10,[1 2 0],1/Hz,'zoh'); OL = tf(conv(Dnum,numGd),conv(Dden,denGd),1/Hz); y = step(feedback(OL,1),[0:1/Hz:tfin]); ymax = [ymax,(max(y)/y(end)-1)*100]; step(feedback(OL,1),[0:1/Hz:0.5]),hold on title(['step, [k a b] = ',num2str([k a b]),... ', Mp cont, 34 & 32 Hz = ',num2str(ymax)])

The remaining results are:

Bode Diagram Gm = Inf dB (at Inf rad/sec) , Pm = 57.2 deg (at 21 rad/sec)

Magnitude (dB)

50

0

-50

Phase (deg)

-100 -45

-90

-135

-180 -1

0

10

1

10

2

10

3

10

10

step, [k a b] = 77 1.4

1.2

30, Mp cont, 34 & 32 Hz = 9.63846

19.577

22.9054

1.2

Amplitude

1

0.8

0.6

0.4

0.2

0

0

0.05

0.1

0.15

0.2

0.25 Time (sec)

0.3

0.35

0.4

0.45

0.5

A useful guide or starting point for estimating sampling frequencies is shown in figure (3) in the code as shown below: stability analyses for discrete b 1.5

discrete pole

1

0.5

0

30

40

50

60

70 Hz

80

90

100

110

120

By inspection we know to begin somewhere above 30 Hz sampling rate for estimating the sampling rate effects. 3.10 The antenna tracker has the transfer function G ( s ) =

10 . Design a continuous s( s + 2 )

lead compensation so that the closed-loop system has a rise time tr < 0.3 sec and overshoot Mp < 10%. Approximate the effect of a digital implementation to be G( s) =

10 , and estimate Mp for a digital implementation with a sample rate of 10 s( s + 2 )

Hz. We basically repeat 3.9 with a different means of estimation of the sampling rate effects. The matlab code is shown below. function Prob_3_10() % close all G = tf(10,[1 2 0]); k = 5; w = 5; a = w/2; b = w*2; D = tf(k*[1 a],[1 b]); figure(1)

tfin = 10; Hz = 10; t = [0:0.01:tfin]; t1 = [0:0.01:1]; y = step(feedback(D*G,1),t); ymax = (max(y)/y(end)-1)*100; step(feedback(D*G,1),t),hold on y = step(feedback(D*G*tf(2*Hz,[1 2*Hz]),1),t); ymax = [ymax,(max(y)/y(end)-1)*100]; step(feedback(D*G*tf(2*Hz,[1 2*Hz]),1),t1),hold on, grid on title(['step, [k a b] = ',num2str([k a b]),... ', Mp = ',num2str(ymax)])

step, [k a b] = 5

2.5

10, Mp = 10.1018

22.0988

1.4 continuous discrete appox 1.2

Amplitude

1

0.8

0.6

0.4

0.2

0

0

0.1

0.2

0.3

0.4

0.5 Time (sec)

0.6

0.7

0.8

0.9

1

Solution for Take Home Exam 1

, a) Design feedback assuming you have access to all the state elements. Place the closed- loop system poles at s = [-1 +- 1j, -0.5 +- 5j]....