We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
‘Appendix B: MATLAB Tutoral
pause
'7(3)" § Display Label
‘Tfeedback (KG, 1) $ Find closed-loop transfer
§ function
S with selected K and display.
step(t) S Generate closed~loop step
§ root locus.
title ("Step Response for K=", num2str (K)])
¥ Give step response a titiewnacn
\ includes the value of K.
pause
Chapter 9: Design Via Root Locus
ch9p1 (Example 9.3) Wecan use MATLAB to design PD controllers. The program
allows us to input a desired percent overshoot via the keyboard. MATLAB then
produces a root locus for tke uncompensated system with an overlay of the percent
overshoot line. We interactively select the intessection of the root locus aud the desired
percent overshoot line to set the gain, MATLAB outputs an estimate of the un-
Compensated system's performance specifications and a step response of the un-
‘compensated system for us to determine the required settling time. After we input
the settling time through the Keyboard, MATLAB designs the PD controller and
produces a root locus of the PD compensated system from which we can interactively
select the gain. Finally, MATLAB produces an estimate of the PD compensated
system's performance specifications anda step response of the PD compensated system.
* (ch9p1) Example 9.3" Display label.
elt § Clear graph on screen.
‘Uncompensated Systen' $ Display label.
numget; ¥Generate numerator of G(s) -
deng=poly ((0 ~4 61) + Generate denominator of G(s)
"G(s)* § Display label.
Get (nung, deng) ‘Create anddisplay G(s).
poe-input (Type deoizad percent everehoot')7
§ Input desired percent overshoot.
2-1og (pos/100) /sqrt (pi*24{1og (pos/100)]*2);
calculate dampiny ratio.
locus (6) ‘Plot uncompensated root Locus.
sgrid(z,0) ‘overtay desired percent
‘oversnoot Line.
title (('Uncompensated Root Locus with’, num2str (Pos) ,
overshoot Line')) {Title uncompensated root locus.
[K, plerloctind (6); SGenerate gain, k, and closed-loop
poles, p, for point selected
interactively on the root locus.
"Closed-Loop poles= ‘Display label.
Pe § Display closed-loop poles.
faint (Give pole nomber that Ss operating point")
‘Choose uncompensated system
‘S dominant pole.
‘conmany of cotimated opcci fications for oclected point en!
‘uncompensated root Locus! § Display label.
operat ingpoint=p (£) Display uncompensated dominant
Spole.B2MATLAB Examples
gasn-x ‘Display uncompensated gain.
estimated_settling_time=4/abs (real (p(f)))
‘8 Display uncompensated settling
Stine.
estimated_peak_time=pi/abs (imag (p(f)))
'§ Display uncompensated peak tine.
estimated_percent_overshoot=pos
4 Display uncompensated percent
S overshoot
estimated_damping_ratio=z Display uncompensated damping
¥ ratio.
eotimated_natural_frequency-oqrt (real (p (#))“2+imag (p(£)) 2)
§ Display uncompensated natural
& frequency.
umkv=cony (1 0}, nung) + ‘Set up numerator to evaluate Kv.
denkv=deng; Set up denominator to evaluate Kv.
Get (numky, denky) : SCreate s6(s).
sGeminreal (56) ; Cancel comon potes and zeros.
Kvedegain (K*s6) § Display uncompensated Kv.
essel/Ky § Display uncompensated
& steady-state
Serxor for unit ramp input.
"rest $ Display label.
‘Tefeedback(K*G, 1) ‘Find uncompensated (s) .
step(T) ‘Plot step response of
@ enconpensated system
title (('Uncompensated System Step Response with ,num2str (Pos) , «
"overshoot '}) Add title to uncompensated step
4 responce.
‘Press any key to goto PD compensation’
S Display label.
pause
‘compensated system! ‘Display label.
‘Ts=input (‘Type Desired Settling Time ') >
‘Input desired settling time from
‘the keyboard.
wnea/(ts*2) 7 S calculate ratural frequency,
desired_pole=(~2*wn) + (wntsgrt (1-2°2)*4) 7
‘$s Calculate cesired dominant pole
S location.
angle_at_desired_pole=(180/pi)*.
angle (poiyval (nung, desired _pole) /polyval (deng, desired pole) );
E calculate angular contribution
& to desired pole without PD
S compensator.
PD_angle-180~anyle_at_desired_pole;
Scaiculate required angular
S contribution from PD
S compensator.
ze=( (imag (desired_pole) /tan(PD_angle* pi/180))..-
real (desired pole)); S calculate #0 zero location.
PD'Compensatoz? Display label.
unce{1 ze}; ‘calculate rumerator of Ge(s) -
dencs{0 117 Calculate rumerator of Ges).
"ec(s)" 4 Display latel.s10
Appendix B: MATLAB Tutorial
Gost (nunc, denc)
#6 (s)6c(s)"
Ge-ctce
locus (Ge, 0:0.005:100)
sgrid(z,0)
title (('PDCompensatedoot Locus with', num2str (pos) ,
"overshoot Line")
(K,plerlocting (Ge) +
‘closed-loop poles="
P
S create anddisplay Ge(s) .
§ Display label.
8 cascade G(s) andGe(s)
§ Plot root Locus of PD compensated
S system,
S overlay desired percent
‘Add title to PD compensated root
Slocus.
SGenerate gain, K, and closed-loop
Spoles, p, for point selected
§ interactively on the root Locus
§ Display label.
§ Display PD compensated systems!
§ closed-Loop poles
f+input ("Give pole number that is operating point ');
§ Choose PD compensated system
S dominant pole.
‘summary of estimated speci fications for selected point on FD"
‘companaated root lowe!
operatingpoint=p(£)
gein-k
§ Diaplay lahal
‘§ Display PD compensated dominant.
Spole.
§ Diaplay PD compsneated gain.
eetimated_settling_time=4/abs (real (p(£)))
's Display PD compensated settling
seine.
‘estimated_peak_time-pi/abs (imag (p(£)))
estimated percent_overshoot=pos
estimated damping ratio-z
‘Display PD compensated peak time.
§ Display PD compensated percent
overshoot.
§ Display PD compensated damping
Sratio
estimated_natural_frequencyssqrt (real (p(f)) “2+imag(p(f) )*2
sete (O11);
eCe~e+Ge
sGe=minreal (sGe);
Kvndegain(K*sGe)
eusel /Kw
"TUs)"
Tefeedback (K*Ge, 1)
§ Display PD compensated natural
8 frequency.
$ Created transfer function,
§ Craate 260 (2)
§ Cancel common poles and zeros,
§ Display compensated Kv.
§ Display compensated
§ steady-state error for
S unit ramp input.
Display Label.
S Create and display 80 compensated
aris).
"Press any key to continue and obtain the PD compensated step!
'zesponse’
pause
step(T)
‘Display label.
§ Plot step response for PD
& compensated system.
title ('PP Compensated system Step Response with!
nun2str (pes), '$Overshoot'))
pouse
Add title to step response
of PD compensated system.
7 Use Matlab to Obtain Root Locus for a Given System and Find Performance Specifications From Them, Study Effect of Addition of Zero and Pole on Root Locus