137994230 matlab tutorial

439
Cơ sở MATLAB Vector Các hàm Vẽ Đa thức Ma trận In ấn Sử dụng M-files trong M ATLAB Tìm trợ giúp trong M ATLAB Các lệnh chính của MATLAB được dùng trong tài liệu này là: plot, polyval, roots, conv, deconv, inv, eig và poly. MATLAB là một chương trình tính toán bằng số và hiển thị số liệu theo kiểu tương tác. Nó được dùng chủ yếu trong phân tích và thiết kế hệ thống điều khiển tự động. Có nhiều hộp công cụ (Toolbox) để mở rộng ứng dụng các hàm cơ bản của MATLAB vào các lĩnh vực khác nhau. Trong tài liệu này, chúng tôi tập trung vào sử dụng các hộp công cụ điều khiển (Control Systems Toolbox). MATLAB có các phiên bản chạy trong môi trường Unix, Macintosh và Windows. Hiện có một phiên bản MATLAB dùng cho đào tạo, chạy trên PC. Muốn có thông tin chi tiết về MATLAB hãy liên hệ với MathWorks . Ý tưởng của chúng tôi khi viết tài liệu này là để bạn có thể hiện bài học trong một cửa sổ trong khi chạy MATLAB trong cửa sổ khác. Bạn có thể chạy các lệnh tính toán và vẽ trong tài liệu bằng cách cắt văn bản và dán vào MATLAB hoặc vào một M-file. Vector Chúng ta bắt đầu từ việc tạo một đối tượng đơn giản, như một vector. Nhập các phần tử của vector (cách nhau một dấu trống) giữa 2 ngoặc vuông và gán nó vào một biến. Ví dụ, để tạo vector a, hãy nhập dòng sau vào cửa sổ lệnh của MATLAB (bạn có thể "copy" và "paste" từ browser vào MATLAB cho dễ): a = [1 2 3 4 5 6 9 8 7] MATLAB trả về: a = 1 2 3 4 5 6 9 8 7 Nếu bạn muốn tạo một vector có các phần tử từ 0 đến 20, mỗi phần tử cách nhau 2 (phương pháp này thường được dùng để tạo vector thời gian): 1

Upload: an-binh

Post on 25-Nov-2015

234 views

Category:

Documents


6 download

TRANSCRIPT

  • C s MATLABVectorCc hmVa thcMa trnIn nS dng M-files trong MATLABTm tr gip trong MATLAB

    Cc lnh chnh ca MATLAB c dng trong ti liu ny l: plot, polyval, roots, conv, deconv, inv,eig v poly.

    MATLAB l mt chng trnh tnh ton bng s v hin th s liu theo kiu tng tc. N c dngch yu trong phn tch v thit k h thng iu khin t ng. C nhiu hp cng c (Toolbox) m rng ng dng cc hm c bn ca MATLAB vo cc lnh vc khc nhau. Trong ti liu ny, chngti tp trung vo s dng cc hp cng c iu khin (Control Systems Toolbox). MATLAB c ccphin bn chy trong mi trng Unix, Macintosh v Windows. Hin c mt phin bn MATLAB dngcho o to, chy trn PC. Mun c thng tin chi tit v MATLAB hy lin h vi MathWorks.

    tng ca chng ti khi vit ti liu ny l bn c th hin bi hc trong mt ca s trong khichy MATLAB trong ca s khc. Bn c th chy cc lnh tnh ton v v trong ti liu bng cchct vn bn v dn vo MATLAB hoc vo mt M-file.

    Vector

    Chng ta bt u t vic to mt i tng n gin, nh mt vector. Nhp cc phn t ca vector(cch nhau mt du trng) gia 2 ngoc vung v gn n vo mt bin. V d, to vector a, hynhp dng sau vo ca s lnh ca MATLAB (bn c th "copy" v "paste" t browser vo MATLABcho d):

    a = [1 2 3 4 5 6 9 8 7]

    MATLAB tr v:

    a = 1 2 3 4 5 6 9 8 7

    Nu bn mun to mt vector c cc phn t t 0 n 20, mi phn t cch nhau 2 (phng php nythng c dng to vector thi gian):

    1

  • t = 0:2:20

    t = 0 2 4 6 8 10 12 14 16 18 20

    S dng cc vector cng d nh to ra chng. Trc ht, nu mun cng thm 2 vo mi phn t cavector 'a', bn hy nhp biu thc sau:

    b = a + 2

    b = 3 4 5 6 7 8 11 10 9

    By gi, gi s bn mun cng 2 vector vi nhau. Nu chng c di bng nhau th tht l d, chcn g vo biu thc:

    c = a + b

    c = 4 6 8 10 12 14 20 18 16

    Tr cc vector c cng chiu di c thc hin hon ton ging nh cng chng.

    Cc hm (Functions)

    cho thun tin, MATLAB c tch hp nhiu hm chun. Mi hm l mt khi lnh thc hinmt chc nng nht nh. MATLAB c tt c cc hm ton hc chun, nh sin, cos, log, exp, sqrt,...Cc hng thng dng, nh pi hay i, j trong cn bc 2 ca -1, cng c trong MATLAB.

    sin(pi/4)

    ans =

    0.7071

    xem cch s dng hm, g help [tn_hm] trong ca s lnh ca MATLAB.

    MATLAB cn cho php bn to hm ring ca mnh vi lnh function.Hy bm vo y hc cchto hm v xem danh sch chng ti to ra trong ti liu ny.

    V (Plotting)

    Vic to mt th trong MATLAB cng d dng. Gi s bn mun v th hm sin theo thi gian.Trc ht, to mt vector thi gian (du chm phy (;) sau mi dng lnh ngn MATLAB a rangay gi tr), sau tnh gi tr hm sin cho mi gi tr t.

    t=0:0.25:7;y = sin(t);plot(t,y)

    2

  • th cha khong mt chu k ca hm sin. Chc nng v c bn ca MATLAB rt d dng, ngoi ralnh plot cn thm cc kh nng b sung khc. Bn hy link n trang plotting bit thm v khnng ny.

    a thc (Polynomials)

    Trong MATLAB, mt a thc c biu din thng qua mt vector. To mt a thc trong MATLABbng cch nhp cc h s ca n theo th t gim dn ca s m. V d a thc sau

    c biu din trong MATLAB di dng vector:

    x = [1 3 -15 -2 9]

    x = 1 3 -15 -2 9

    MATLAB hiu mt vector c n+1 phn t l mt a thc bc n. V vy, nu a thc b khuyt mt sh s th ta phi in thm s 0 vo v tr tng ng. V d a thc

    s c biu din trong MATLAB nh sau:

    y = [1 0 0 0 1]

    Mun tm gi tr ca a thc ta dng hm polyval. V d, tm gi tr ca a thc trn ti s=2 nh sau

    z = polyval([1 0 0 0 1],2)

    z = 17

    Ta cng c th tm nghim ca mt a thc. iu rt thun tin khi c a thc bc cao. V d tmnghim ca a thc

    3

  • nh lnh sau:

    roots([1 3 -15 -2 9])

    ans = -5.5745 2.5836 -0.7951 0.7860

    Mun nhn 2 a thc vi nhau, ta dng hm conv (convolution) nhn ln lt cc h s ca chng.V d

    x = [1 2];y = [1 4 8];z = conv(x,y)

    z = 1 6 16 16

    chia hai a thc, ta dng hm deconv.Hm ny tr v c thng s v phn d. V d, cn chia zcho y v kim tra xem c nhn li c x hay khng, ta lm nh sau:

    [xx, R] = deconv(z,y)

    xx = 1 2

    R = 0 0 0 0

    Ta thy li ng a thc (vector) x to trn. Nu php chia khng ht th phn d s khc khng.

    Ma trn (Matrices)

    Trong MATLAB, ma trn c biu din tng t nh vector, ch khc l cc hng c phn cch bidu chm phy (;) hoc chng c vit thnh tng hng ring bit:

    B = [1 2 3 4;5 6 7 8;9 10 11 12]

    B = 1 2 3 4 5 6 7 8 9 10 11 12

    B = [ 1 2 3 4 5 6 7 8 9 10 11 12]

    B = 1 2 3 4 5 6 7 8 9 10 11 12

    Cc ma trn c x l trong MATLAB theo nhiu cch. Trc ht, tm ma trn chuyn v C cama trn B, ta dng du lc ('):

    C = B'

    4

  • C = 1 5 9 2 6 10 3 7 11 4 8 12

    Nu C c dng phc th du lc s cho kt qu phc lin hp. nhn c chuyn v hy dng .'(hai lnh ny cho kt qu nh nhau nu C khng c dng phc).

    Php nhn 2 ma trn B v C c biu din nh bnh thng, nhng phi ch th t ca chng.

    D = B * C

    D = 30 70 110 70 174 278 110 278 446

    D = C * B

    D = 107 122 137 152 122 140 158 176 137 158 179 200 152 176 200 224

    Khi cn nhn cc phn t tng ng ca 2 ma trn, ta dng ton t .*. Khi 2 ma trn phi c cngkch thc.

    E = [1 2;3 4]F = [2 3;4 5]G = E .* F

    E = 1 2 3 4

    F = 2 3 4 5

    G = 2 6 12 20

    Nu c mt ma trn vung, bn c th nhn n vi chnh n bao nhiu ln tu bng php nng lytha:

    E^3

    ans = 37 54 81 118

    tnh lp phng ca mi phn t trong ma trn, ta lm nh sau:

    E.^3

    5

  • ans = 1 8 27 64

    Nghch o ca mt ma trn c tm nh hm inv:

    X = inv(E)

    X = -2.0000 1.0000 1.5000 -0.5000

    hoc gi tr ring (eigenvalues):

    eig(E)

    ans = -0.3723 5.3723

    MATLAB cn c hm tnh cc h s trong a thc c trng ca ma trn. Hm poly to ra mtvector cha cc h s ca a thc c trng.

    p = poly(E)

    p =

    1.0000 -5.0000 -2.0000

    Ch rng cc gi tr ring (eigenvalues) ca mt ma trn chnh l cc nghim ca a thc c trngca ma trn ::

    roots(p)

    ans = 5.3723 -0.3723

    In (Printing)

    in trong MATLAB cn thc hin cc bc sau:

    Trong Macintosh

    Mun in mt th hoc m-file trong Macintosh, ch cn kch chut vo th hoc m-file,chn Print trong menu File v n Return.

    Trong Windows

    Mun in mt th hoc m-file trong Windows, chn Print trong menu File trong ca s ca th hoc m-file v n Return.

    Trong Unix

    Mun in mt th hoc m-file trong Unix th nhp lnh:

    6

  • print -P

    Nu mun lu th in sau th nhp lnh:

    print plot.ps

    Khi cn in th nhp lnh "lpr -P plot.ps". Nu bn ang dng my in HP th dng lnh "lpr-d plot.ps".

    Mun in mt m-file th cng thao tc tng t nh cc file khc, dng lnh "lpr -P .m". Nu dng my in HP th dng lnh "lpr -d plot.ps.m".

    Dng M-files trong MATLAB

    S dng M-file trong mi h iu hnh c hi khc nhau.

    Trong Macintosh

    C mt b son tho chuyn cho m-files. Chn "New M-file" trong menu File. Bn c th dngmt b son tho bt k nhng phi nh ghi cc file di dng text v np chng mi khi khing MATLAB.

    Trong Windows

    Chy MATLAB trong Windows tng t nh trong Macintosh. Tuy nhin, m-file c npvo b nh cn ghi n di dng file tn_file.m

    Trong Unix

    Bn cn chy mt b son tho c lp t MATLAB. Tt nht l to mt th mc cha tt ccc m-files, sau cd ti th mc trc khi khi ng MATLAB v b son tho. khing MATLAB t ca s Xterm ca bn ch cn g: matlab.

    Bn c th g cc trc tip g cc lnh trong ca s lnh ca MATLAB hoc a tt c cc lnh cnthit trong mt m-file v chy file . Nu bn cha tt c cc m-files ca bn trong cng th mc mt bn khi ng MATLAB th MATLAB s lun lun tm chng.

    Tm tr gip (Help) trong MATLAB

    MATLAB c mt h tr gip trc tuyn tng i tt. tm tr gip v mt lnh no , g:

    help tn_lnh

    Bn rt cn bit tn lnh m bn tm kim tr gip. Danh sch cc lnh dng trong ti liu ny ccho trong danh sch lnh. Phm MatLab Commands cui mi trang cho php link n trang danhsch ny.

    Here are a few notes to end this tutorial.

    Bn c th nhn c gi tr ca mi bin bng cch g tn bin:

    B

    B =

    7

  • 1 2 3 4 5 6 7 8 9

    Bn c th nhp nhiu lnh trn cng mt dng, cc lnh cch nhau bng du chm phy (;) hoc duphy (,).

    Nu khng gn php tnh hoc kt qu cho mt bin no th MATLAB s gn n vo mt bin tm thi,tn l "ans".

    TutorialsMATLAB C s | MATLAB - To m hnh | PID | Qu tch nghim | p ng tn s | Khng giantrng thi | iu khin s | Simulink C s | Simulink - To m hnh | Cc v d

    8

  • Simulink Examples IndexExample Description Tutorial

    Cruise ControlMotor Speed Control

    Motor Position ControlBus Suspension

    Inverted PendulumPitch Control

    Ball and Beam

    Descriptions of the MATLAB tutorial examples are available here.

    Cruise Control

    This is a simple example of the modeling and control of a first order system. This model takes inertia anddamping into account. Newton's laws are modeled directly in this example, where forces are summed up toprovide the acceleration of the vehicle. A simple PI controller is implemented.

    1

  • Motor Speed Control

    A DC motor has second order speed dynamics when mechanical properties such as inertia and damping aswell as electrical properties such as inductance and resistance are taken into account. Newton's law andKirchoff's law are modeled directly by summing forces and summing voltages to provide the motor'sacceleration and armature current, respectively. A lag compensator is implemented.

    Motor Position Control

    The model of the position dynamics of a DC motor is third order, because measuring position is equivalentto integrating speed, which adds an order to the motor speed example. In this example, however, the motorparameters are taken from an actual DC motor used in an undergraduate controls course. This motor hasvery small inductance, which effectively reduces the example to second order. This uses the same model asthe motor speed example with an additional integrator to provide position from the velocity signal. In thisexample, a discrete-time model extraction and a discrete-time controller are implemented around thecontinuous plant model.

    2

  • Bus Suspension

    This example looks at the active control of the vertical motion of a bus suspension. It takes into accountboth the inertia of the bus and the inertia of the suspension/tires, as well as springs and dampers. An actuatoris added between the suspension and the bus. Newton's law is modeled directly by summing forces acting oneach of the two inertias. A full-state feedback controller is implemented by extracting a set of states directlyfrom the model.

    3

  • Inverted Pendulum

    The inverted pendulum is a classic controls demonstration where a pole is balanced vertically on amotorized cart. It is interesting because without control, the system is unstable. This is a fourth ordernonlinear system. This is a particularly difficult system to model in Simulink because of the algebraicconstraint. While Newton's laws are still modeled directly, some calculations must be done in advance toderive the form of the algebraic constraint. A PID controller is implemented using Simulink's built-in PIDblock.

    4

  • Pitch Control

    The pitch angle of an airplane is controlled by adjusting the angle (and therefore the lift force) of the rearelevator. The aerodynamic forces (lift and drag) as well as the airplane's inertia are taken into account. Thisis a third order, nonlinear system which is linearized about the operating point. The Simulink model is basedon the State-Space model developed in the MATLAB tutorials, and the state equations are implementeddirectly. Because of this, the state vector is available for use in a full-state-feedback controller.

    5

  • Ball and Beam

    This is another classic controls demo. A ball is placed on a straight beam and rolls back and forth as one endof the beam is raised and lowered by a cam. The position of the ball is controlled by changing the angularposition of the cam. This is a second order system, since only the inertia of the ball is taken into account,and not that of the cam or the beam. Rather than modeling forces and accelerations, the Lagrangianequations of motion are implemented is Simulink, eliminating the need to express the algebraic constraintexplicitly as was done in the inverted pendulum example.

    TutorialsMATLAB Basics | MATLAB Modeling | PID | Root Locus | Frequency Response | State Space | Digital

    6

  • Control | Simulink Basics | Simulink Modeling | Examples

    7

  • MATLAB - To m hnhH thng xe laM hnh tch v nh lut NewtonBin trng thi v cc phng trnh raBiu din trong MATLAB

    MATLAB c th c dng m t h thng hoc m hnh vt l. Trong ti liu ny chng ta s hccch s dng phng trnh vi phn to m hnh trong MATLAB. By gi chng ta s biu din hthng vt l nh tp hp cc phng trnh vi phn.

    H thng xe la

    Gi thit h thng ch c mt u my v mt toa xe v chy theo mt hng. Chng ta cn iukhin xe sao cho n khi ng v dng m v chy vi tc khng i.

    K hiu khi lng ca u my v ca toa ln lt l M1 v M2, cng ca l xo lin kt giachng l k, lc ko ca u my l F v h s ma st ln ti cc bnh xe l .

    M hnh tch v nh lut Newton

    Sau khi tch lin kt, m hnh h thng c biu din nh sau:

    T nh lut Newton, chng ta bit rng tng cc lc tc dng ln vt bng tch khi lng ca vt vigia tc ca n. Trong trng hp ny, h lc tc dng ln M1 gm lc l xo, lc ma st v lc ko cang c. H lc tc dng ln M2 gm lc l xo v lc ma st. Cc lc tc dng theo phng thngng, gm trng lc v phn lc vung gc vi mt ng, cn bng. V vy khng c gia tc theophng thng ng. Cc phng trnh chuyn ng theo phng nm ngang nh sau:

    1

  • Bin trng thi v cc phng trnh ra

    H phng trnh trng thi c xy dng vi cc bin trng thi, gm cc to X1, X2; vn tc V1,V2 v thng s u vo l lc ko F. H phng trnh c dng sau:

    Gi s thng s ra ca h thng l vn tc ca xe. V vy phng trnh ra s l:

    1. Hm truyn

    tm hm truyn ca h thng, trc ht phi biu din cc phng trnh vi phn di dngLaplace.

    Thng s ra Y(s) = V2(s) = s X2(s). Kh X1 xut hin t s Y(s)/F(s). Khi tm hm truyn, githit rng iu kin u bng 0. Hm truyn c dng sau:

    2. Khng gian trng thi

    Phng php khc gii bi ton l s dng khng gian trng thi. Bn ma trn A, B, C, D c trngcho h thng s c dng gii bn ton. Dng khng gian trng thi c tm t cc bin trngthi v phng trnh thng s ra c biu din nh sau:

    2

  • Biu din trong MATLAB

    By gi chng ta s a cc phng trnh trn vo m-file ca MATLAB. V MATLAB khng th dngcc bin k t, chng ta gn gi tr cho cc bin nh sau:

    M1 = 1 kgM2 = 0.5 kgk = 1 N/mF= 1 Nu = 0.002 sec/mg = 9.8 m/s^2

    Chng ta to mt m-file vi cc bin sau:

    M1=1;M2=0.5;k=1;F=1;u=0.002;g=9.8;

    gii bi ton, chng ta c 2 phng n: 1) Dng hm truyn, hoc 2) Dng khng gian trng thi.

    Nu dng hm truyn th hy thm cc dng sau vo cui m-file va to ra:

    num=[M2 M2*u*g 1];den=[M1*M2 2*M1*M2*u*g M1*k+M1*M2*u*u*g*g+M2*k M1*k*u*g+M2*k*u*g];train=tf(num,den)

    Nu dng khng gian trng thi th thm cc lnh sau, thay cho cc ma trn num v den:

    A=[ 0 1 0 0; -k/M1 -u*g k/M1 0; 0 0 0 1; k/M2 0 -k/M2 -u*g];B=[ 0;1/M1; 0; 0];C=[0 1 0 0];

    3

  • D=[0];train=ss(A,B,C,D)

    Hy xem cch nhp ma trn trong MATLAB c s.

    Tip tc gii bi ton

    Khi h cc phng trnh vi phn m t h thng c nhp vo MATLAB di dng hm truynhoc khng gian trng thi th c th nghin cu v h thng iu khin kn hoc h.

    Hu ht bi ton c th gii bng cch s dng hm truyn hoc m hnh khng gian trng thi. Hnna, c th chuyn i gia dng ny sang dng khc. Phng php chuyn i c trnh by trongtrang Chuyn i.

    Sau y l danh sch 7 trang trnh by cc v d v to m hnh, bn c th link n nghin cu.

    Modeling ExamplesCruise Control | Motor Speed | Motor Position | B gim xc xe but | Inverted Pendulum |Pitch Controller | Ball and Beam

    TutorialsMATLAB c s | MATLAB - To m hnh | PID | Qu tch nghim | p ng tn s | Khng giantrng thi | iu khin s | Simulink C s | Simulink - To m hnh | Cc v d

    4

  • V d: M hnh h iu khin xe

    M t h thngCc ch tiu thit kM hnh MATLABp ng h knHm truyn mch kn

    M t h thng

    M hnh iu khin xe tng i n gin. Nu b qua qun tnh ca cc bnh xe v gi thit rng lcma st (t l thun vi vn tc ca xe) tc dng ngc chiu chuyn ng ca xe, th m hnh trthnh m hnh khi lng v gim chn nh di y.

    Theo nh lut Newton, nhn c h phng trnh m t h thng nh sau:

    (1)

    trong u l lc pht ng ca ng c. Trong v d ny, chng ta dng cc gi tr

    m = 1000 kgb = 50N sec/m

    u = 500 N

    Cc ch tiu thit k

    H cn phi tho mn cc ch tiu thit k sau:. Khi lc ko ca ng c bng 500 N, xe s t vn

    1

  • tc ln nht l 10 m/s (22 mph) trong khong thi gian khng qu 5 giy. Cho php lng qu iukhin tc ti 10% v sai s tnh ln nht l 2%.

    Thi gian gia tc < 5 secQu iu khin tc < 10%Sai s tnh < 2%

    M hnh MATLAB

    1. Hm truyn

    tm hm truyn cn bin i h phng trnh (1) sang Laplace. Khi xc nh hm truyn, cn githit iu kin u bng 0. Dng chuyn i Laplace ca 2 phng trnh nh sau:

    V vn tc l thng s ra, ta thay V(s) bng Y(s)

    Vy hm truyn ca h bng

    gii bi ton trong MATLAB, bn copy on lnh sau vo m-file mi:

    m=1000;b=50;u=500;num=[1];den=[m b];cruise=tf(num,den)

    Lnh ny s cn c dng li tm p ng h kn ca h thng trc tn hiu vo dng bc thangn v. Nhng trc khi lm iu , ta cn xem xt m hnh khng gian trng thi.

    2. Khng gian trng thi

    Chng ta vit li h phng trnh ban u (1) di dng m hnh khng gian trng thi.

    Mun dng MATLAB gii bi ton, cn to m-file nh sau:

    m = 1000;b = 50;

    2

  • u = 500;A = [-b/m];B = [1/m];C = [1];D = 0;cruise=ss(A,B,C,D)

    Ghi ch: C th chuyn i bi ton t dng khng gian trng thi sang dng hm truyn v ngcli trong MATLAB. Chi tit v chuyn i, xem Chuyn i

    p ng h kn

    Chng ta hy xem phn ng h kn trc thng s vo l bc thang n v (step input). Thm lnh sauvo cui m-file v chy trong ca s lnh ca MATLAB:

    step(u*cruise)

    Bn s nhn c th sau:

    T th, ta thy thi gian xe t vn tc 10 m/s vt qu 100 giy. iu khng t yu cu vthi gian tng tc (khng qu 5 giy).

    Hm truyn mch kn

    ci thin cht lng iu khin, ta to h iu khin kn vi mch phn hi n v, c s khinh hnh sau.

    Hm truyn ca i tng (plant) chnh l hm truyn xc nh c trn {Y(s)/U(s)=1/ms+b}.B iu khin cn c thit k tho mn cc iu kin t ra ban u. C 4 phng php thit kb iu khin c lit k cui trang m bn c th chn, gm PID (t l - tch phn - vi phn),

    3

  • Root-locus (qu tch nghim), Frequency response (p ng tn s), hoc State-space (khng giantrng thi).

    Cc v d v m hnh hoCruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | PitchController | Ball and Beam

    Cc v d iu khin xeModeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Simulink

    TutorialsMATLAB c s | MATLAB - To m hnh | PID | Qu tch nghim | p ng tn s | Khng giantrng thi | iu khin s | Simulink C s | Simulink - To m hnh | Cc v d

    4

  • V d: M hnh iu khin tc ng c in mtchiu

    M hnh vt l v h phng trnhYu cu thit kBiu din trong MATLAB v p ng mch kn

    M hnh vt l v h phng trnh

    ng c in mt chiu (DC Motor) l thit b chp hnh c dng ph bin trong iu khin. Ncung cp chuyn ng quay, v cng vi cc c cu truyn ng c kh khc, nh bnh rng, tangtrng, cp,... c th cho chuyn ng tnh tin. Mch in phn ng v s tch ca rotor nh tronghnh sau:

    Gi thit cc thng s vt l ca h thng nh sau.

    * Moment qun tnh ca rotor (J) = 0.01 kg.m^2/s^2 * H s gim chn ca h thng c kh (b) = 0.1 Nms * Hng s in c (K=Ke=Kt) = 0.01 Nm/Amp * in tr (R) = 1 ohm * in cm (L) = 0.5 H * Input (V): in p ngun * Output (theta): v tr ca trc * Gi thit rotor v trc cng vng tuyt i

    M men trn trc, T, c quan h vi dng in phn ng, i, thng qua hng s Kt. Sut in ngphn ng, e, quan h vi tc quay qua cc phng trnh:

    1

  • Trong h n v SI (m chng ta s dng), Kt (hng s phn ng) bng Ke (hng s motor) v ck hiu chung l K.

    T hnh v trn, chng ta c th vit cc phng trnh da trn nh lut Newton, kt hp vi nhlut Kirchhoff:

    1. Hm truyn

    Sau bin i Laplace, m hnh h thng c dng.

    Bng cch kh I(s) chng ta nhn c hm truyn mch h, trong , in p ngun l thng s vov tc quay ca trc l thng s ra.

    2. Khng gian trng thi

    Di dng khng gian trng thi, c th biu din cc phng trnh trn bng cch chn tc quayv dng in lm cc bin h thng, in p ngun lm input v tc quay lm output.

    Yu cu thit k

    Thot u ng c ch c th quay vi tc 0.1 rad/sec vi in p vo l 1 V (ta s thy khi mphng p ng mch h). Yu cu c bn i vi ng c l quay vi vn tc yu cu v sai s tnhdi 1%. Yu cu khc v nng sut l thi gian ng c phi t ti vn tc n nh sau khi khing l khng qu 2 giy. trnh s c do tc ng c qu cao, cn hn ch lng qu iukhin nh hn 5%.

    Nu chng ta cp in p vo di dng bc thang n v th tc quay (output) phi t cc yucu:

    Thi gian t vn tc n nh di 2 giyQu iu khin di 5%

    2

  • Sai s tnh di 1%

    Biu din trong MATLAB v p ng mch h

    1. Hm truyn

    Chng ta c th biu din hm truyn ni trn trong MATLAB bng cch nh ngha cc ma trn t sv mu s nh sau:

    To m-file mi v nhp cc lnh:

    J=0.01;b=0.1;K=0.01;R=1;L=0.5;num=K;den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2)];motor=tf(num,den);

    By gi chng ta s xem h thng h ban u c hnh thnh nh th no. Thm cc lnh sau vocui m-file v chy n trong ca s lnh ca MATLAB:

    step(motor,0:0.1:3);title('Step Response for the Open Loop System');

    Ta s nhn c th sau:

    T th, ta nhn thy khi t in p 1 V vo ng c th n ch t vn tc ti a l 0.1 rad/s, nhhn 10 ln so vi vn tc yu cu. Hn na, thi gian ng c t vn tc n nh ko di ti 3 s.

    3

  • iu cng khng tho mn yu cu v thi gian gia tc.

    2. Khng gian trng thi

    Chng ta cng c th biu din h thng nh m hnh khng gian trng thi. Hy chy th on lnhtrong m-file sau:

    J=0.01;b=0.1;K=0.01;R=1;L=0.5;A=[-b/J K/J -K/L -R/L];B=[0 1/L];C=[1 0];D=0;motor_ss=ss(A,B,C,D);

    step(motor_ss)

    Chy m-file trong ca s lnh ca MATLAB, bn s nhn c ng kt qu nh trn.

    Modeling ExamplesCruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | PitchController | Ball and Beam

    Motor Speed ExamplesModeling | PID | Root Locus | Frequency Response | State Space | Digital Control: PID |Simulink

    TutorialsMATLAB Basics | MATLAB Modeling | PID Control | Root Locus | Frequency Response | StateSpace | Digital Control | Simulink Basics | Simulink Modeling | Examples

    4

  • Example: Modeling DC Motor PositionPhysical SetupSystem EquationsDesign RequirementsMATLAB Representation and Open-Loop Response

    Physical Setup

    A common actuator in control systems is the DC motor. Itdirectly provides rotary motion and, coupled with wheels ordrums and cables, can provide transitional motion. Theelectric circuit of the armature and the free body diagram ofthe rotor are shown in the following figure:

    For this example, we will assume the following values for the physical parameters. These values werederived by experiment from an actual motor in Carnegie Mellon's undergraduate controls lab.

    * moment of inertia of the rotor (J) = 3.2284E-6 kg.m^2/s^2* damping ratio of the mechanical system (b) = 3.5077E-6 Nms* electromotive force constant (K=Ke=Kt) = 0.0274 Nm/Amp

    * electric resistance (R) = 4 ohm* electric inductance (L) = 2.75E-6 H

    * input (V): Source Voltage* output (theta): position of shaft

    * The rotor and shaft are assumed to be rigid

    System Equations

    The motor torque, T, is related to the armature current, i, by a constant factor Kt. The back emf, e, isrelated to the rotational velocity by the following equations:

    1

  • In SI units (which we will use), Kt (armature constant) is equal to Ke (motor constant).

    From the figure above we can write the following equations based on Newton's law combined withKirchhoff's law:

    1. Transfer Function

    Using Laplace Transforms the above equations can be expressed in terms of s.

    By eliminating I(s) we can get the following transfer function, where the rotating speed is the outputand the voltage is an input.

    However during this example we will be looking at the position, as being the output. We can obtainthe position by integrating Theta Dot, therefore we just need to divide the transfer function by s.

    2. State Space

    These equations can also be represented in state-space form. If we choose motor position, motorspeed, and armature current as our state variab, we can write the equations as follows:

    Design requirements

    We will want to be able to position the motor very precisely, thus the steady-state error of the motorposition should be zero. We will also want the steady-state error due to a disturbance, to be zero as

    2

  • well. The other performance requirement is that the motor reaches its final position very quickly. Inthis case, we want it to have a settling time of 40ms. We also want to have an overshoot smaller than16%.

    If we simulate the reference input (R) by a unit step input, then the motor speed output should have:

    Settling time less than 40 millisecondsOvershoot less than 16%No steady-state errorNo steady-state error due to a disturbance

    MATLAB representation and open-loop response

    1. Transfer Function

    We can put the transfer function into MATLAB by defining the numerator and denominator as vectors:

    Create a new m-file and enter the following commands:

    J=3.2284E-6;b=3.5077E-6;K=0.0274;R=4;L=2.75E-6;num=K;den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2) 0];motor=tf(num,den);

    Now let's see how the original open-loop system performs. Add the following command onto the endof the m-file and run it in the MATLAB command window:

    step(motor,0:0.001:0.2)

    You should get the following plot:

    From the plot we see that when 1 volt is applied to the system, the motor position changes by 6

    3

  • radians, six times greater than our desired position. For a 1 volt step input the motor should spinthrough 1 radian. Also, the motor doesn't reach a steady state which does not satisfy our designcriteria

    2. State Space

    We can put the state space equations into MATLAB by defining the system's matrices as follows:

    J=3.2284E-6;b=3.5077E-6;K=0.0274;R=4;L=2.75E-6;

    A=[0 1 00 -b/J K/J0 -K/L -R/L];B=[0 ; 0 ; 1/L];C=[1 0 0];D=[0]; motor=ss(A,B,C,D);

    The step response is obtained using the command

    step(motor)

    Modeling ExamplesCruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | PitchController | Ball and Beam

    Motor Position ExamplesModeling | PID | Root Locus | Frequency Response | State Space | Digital Control:RL| Simulink

    TutorialsMATLAB Basics | MATLAB Modeling | PID Control | Root Locus | Frequency Response | StateSpace | Digital Control | Simulink Basics | Simulink Modeling | Examples

    4

  • Example: Modeling a Bus Suspension System usingTransfer Functions

    Physical setupDesign requirementsEquations of motionTransfer function equationEntering equations into MATLABOpen-loop responseControl Block DiagramState Space Method

    Physical setup

    Designing an automatic suspension system for a bus turns out to be an interesting control problem. When thesuspension system is designed, a 1/4 bus model (one of the four wheels) is used to simplify the problem to a onedimensional spring-damper system. A diagram of this system is shown below:

    Where:

    * body mass (m1) = 2500 kg,* suspension mass (m2) = 320 kg,

    * spring constant of suspension system(k1) = 80,000 N/m,* spring constant of wheel and tire(k2) = 500,000 N/m,

    * damping constant of suspension system(b1) = 350 Ns/m.* damping constant of wheel and tire(b2) = 15,020 Ns/m.

    * control force (u) = force from the controller we are going to design.

    Design requirements:

    A good bus suspension system should have satisfactory road holding ability, while still providing comfort when

    1

  • riding over bumps and holes in the road. When the bus is experiencing any road disturbance (i.e. pot holes, cracks,and uneven pavement),the bus body should not have large oscillations, and the oscillations should dissipatequickly. Since the distance X1-W is very difficult to measure, and the deformation of the tire (X2-W) is negligible,we will use the distance X1-X2 instead of X1-W as the output in our problem. Keep in mind that this is anestimation.

    The road disturbance (W) in this problem will be simulated by a step input. This step could represent the buscoming out of a pothole. We want to design a feedback controller so that the output (X1-X2) has an overshoot lessthan 5% and a settling time shorter than 5 seconds. For example, when the bus runs onto a 10 cm high step, thebus body will oscillate within a range of +/- 5 mm and return to a smooth ride within 5 seconds.

    Equations of motion:

    From the picture above and Newton's law, we can obtain the dynamic equations as the following:

    Transfer Function Equation:

    Assume that all of the initial condition are zeroes, so these equations represent the situation when the bus wheelgoes up a bump. The dynamic equations above can be expressed in a form of transfer functions by taking LaplaceTransform of the above equations. The derivation from above equations of the Transfer Functions G1(s) andG2(s) of output,X1-X2, and two inputs,U and W, is as follows.

    Find the inverse of matrix A and then multiple with inputs U(s)and W(s) on the right hand side as the following:

    When we want to consider the control input U(s) only, we set W(s) = 0. Thus we get the transfer function G1(s)as the following:

    When we want to consider the disturbance input W(s) only, we set U(s) = 0. Thus we get the transfer functionG2(s) as the following:

    2

  • Entering equations into MATLAB

    We can put the above Transfer Function equations into MATLAB by defining the numerator and denominator ofTransfer Functions in the form, nump/denp for actuated force input and num1/den1 for disturbance input, of thestandard transfer function G1(s) and G2(s):

    G1(s) = nump/denp

    G2(s) = num1/den1

    Now, let's create a new m-file and enter the following code:

    m1=2500;m2=320;k1=80000;k2=500000;b1 = 350;b2 = 15020;

    nump=[(m1+m2) b2 k2];denp=[(m1*m2) (m1*(b1+b2))+(m2*b1) (m1*(k1+k2))+(m2*k1)+(b1*b2) (b1*k2)+(b2*k1) k1*k2];P=tf(nump,denp);

    num1=[-(m1*b2) -(m1*k2) 0 0];den1=[(m1*m2) (m1*(b1+b2))+(m2*b1) (m1*(k1+k2))+(m2*k1)+(b1*b2) (b1*k2)+(b2*k1) k1*k2];G2=tf(0.1*num1,den1);

    Open-loop response

    We can use MATLAB to display how the original open-loop system performs (without any feedback control). Addthe following commands into the m-file and run it in the MATLAB command window to see the response of unitstep actuated force input and unit step disturbance input. Note that the step command will generate the unit stepinputs for each input.

    step(P)

    From this graph of the open-loop response for a unit step actuated force, we can see that the system is under-damped. People sitting in the bus will feel very small amount of oscillation and the steady-state error is about0.013 mm. Moreover, the bus takes an unacceptably long time to reach the steady state (the settling time is verylarge). The solution to this problem is to add a feedback controller to the system.

    3

  • step(G2)

    To see some details, you can change the axis:

    axis([0 10 -.1 .1])

    From this graph of open-loop response for 0.1 m step disturbance, we can see that when the bus passes a 10 cmhigh bump on the road, the bus body will oscillate for an unacceptably long time(100 seconds) with largeramplitude, 13 cm, than the initial impact. People sitting in the bus will not be comfortable with such an oscillation.The big overshoot (from the impact itself) and the slow settling time will cause damage to the suspension system.The solution to this problem is to add a feedback controller into the system to improve the performance. Theschematic of the closed-loop system is the following:

    4

  • From the above transfer functions and schematic, we can draw the bus-system block diagram as the following:

    From the schematic above we see that:

    Plant = nump/denp

    F * Plant=num1/den1

    so that

    F=num1/(den1*Plant)

    Modeling ExamplesCruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Balland Beam

    Bus Suspension ExamplesModeling | PID | Root Locus | Frequency Response | State Space | Digital | Simulink

    TutorialsMATLAB Basics | MATLAB Modeling | PID Control | Root Locus | Frequency Response | State Space |Digital Control | Simulink Basics | Simulink Modeling | Examples

    5

  • Example: Modeling an Inverted PendulumProblem setup and design requirementsForce analysis and system equationsMATLAB representation and the open-loop response

    Problem setup and design requirements

    The cart with an inverted pendulum, shown below, is "bumped" with an impulse force, F. Determinethe dynamic equations of motion for the system, and linearize about the pendulum's angle, theta = Pi(in other words, assume that pendulum does not move more than a few degrees away from thevertical, chosen to be at an angle of Pi). Find a controller to satisfy all of the design requirementsgiven below.

    For this example, let's assume that

    M mass of the cart 0.5 kgm mass of the pendulum 0.2 kgb friction of the cart 0.1 N/m/secl length to pendulum center of mass 0.3 mI inertia of the pendulum 0.006 kg*m^2F force applied to the cartx cart position coordinatetheta pendulum angle from vertical

    For the PID, root locus, and frequency response sections of this problem we will be only interested inthe control of the pendulum's position. This is because the techniques used in these tutorials can onlybe applied for a single-input-single-output (SISO) system. Therefore, none of the design criteria dealwith the cart's position. For these sections we will assume that the system starts at equilibrium, andexperiences an impulse force of 1N. The pendulum should return to its upright position within 5seconds, and never move more than 0.05 radians away from the vertical.

    1

  • The design requirements for this system are:

    Settling time of less than 5 seconds.Pendulum angle never more than 0.05 radians from the vertical.

    However, with the state-space method we are more readily able to deal with a multi-output system.Therefore, for this section of the Inverted Pendulum example we will attempt to control both thependulum's angle and the cart's position. To make the design more challenging we will be applying astep input to the cart. The cart should achieve its desired position within 5 seconds and have a risetime under 0.5 seconds. We will also limit the pendulum's overshoot to 20 degrees (0.35 radians), andit should also settle in under 5 seconds.

    The design requirements for the Inverted Pendulum state-space example are:

    Settling time for x and theta of less than 5 seconds.Rise time for x of less than 0.5 seconds.Overshoot of theta less than 20 degrees (0.35 radians).

    Force analysis and system equations

    Below are the two Free Body Diagrams of the system.

    Summing the forces in the Free Body Diagram of the cart in the horizontal direction, you get thefollowing equation of motion:

    Note that you could also sum the forces in the vertical direction, but no useful information would begained.

    Summing the forces in the Free Body Diagram of the pendulum in the horizontal direction, you can getan equation for N:

    If you substitute this equation into the first equation, you get the first equation of motion for thissystem:

    2

  • (1)

    To get the second equation of motion, sum the forces perpendicular to the pendulum. Solving thesystem along this axis ends up saving you a lot of algebra. You should get the following equation:

    To get rid of the P and N terms in the equation above, sum the moments around the centroid of thependulum to get the following equation:

    Combining these last two equations, you get the second dynamic equation:

    (2)

    Since MATLAB can only work with linear functions, this set of equations should be linearized abouttheta = Pi. Assume that theta = Pi + ( represents a small angle from the vertical upward direction).Therefore, cos(theta) = -1, sin(theta) = - , and (d(theta)/dt)^2 = 0. After linearization the twoequations of motion become (where u represents the input):

    1. Transfer Function

    To obtain the transfer function of the linearized system equations analytically, we must first take theLaplace transform of the system equations. The Laplace transforms are:

    Since we will be looking at the angle Phi as the output of interest, solve the first equation for X(s),

    then substitute into the second equation, and re-arrange. The transfer function is:

    3

  • where,

    From the transfer function above it can be seen that there is both a pole and a zero at the origin. Thesecan be canceled and the transfer function becomes:

    2. State-Space

    After a little algebra, the linearized system equations equations can also be represented in state-spaceform:

    The C matrix is 2 by 4, because both the cart's position and the pendulum's position are part of theoutput. For the state-space design problem we will be controlling a multi-output system so we will beobserving the cart's position from the first row of output and the pendulum's with the second row.

    MATLAB representation and the open-loop response

    1. Transfer Function

    4

  • The transfer function found from the Laplace transforms can be set up using MATLAB by inputting thenumerator and denominator as vectors. Create an m-file and copy the following text to model thetransfer function:

    M = .5;m = 0.2;b = 0.1;i = 0.006;g = 9.8;l = 0.3;

    q = (M+m)*(i+m*l^2)-(m*l)^2; %simplifies input

    num = [m*l/q 0];den = [1 b*(i+m*l^2)/q -(M+m)*m*g*l/q -b*m*g*l/q];pend=tf(num,den)

    Your output should be:

    Transfer function: 4.545 s----------------------------------s^3 + 0.1818 s^2 - 31.18 s - 4.455

    To observe the system's velocity response to an impulse force applied to the cart add the followinglines at the end of your m-file:

    t=0:0.01:5;impulse(pend,t)axis([0 1 0 60])

    You should get the following velocity response plot:

    As you can see from the plot, the response is entirely unsatisfactory. It is not stable in open loop. Youcan change the axis to see more of the response if you need to convince yourself that the system isunstable.

    Although the output amplitude increases past 60 radians (10 revolutions), the model is only valid forsmall . In actuality, the pendulum will stop rotating when it hits the cart ( =90 degree).

    5

  • 2. State-Space

    Below, we show how the problem would be set up using MATLAB for the state-space model. If youcopy the following text into a m-file (or into a '.m' file located in the same directory as MATLAB) andrun it, MATLAB will give you the A, B, C, and D matrices for the state-space model and a plot of theresponse of the cart's position and pendulum angle to a step input of 0.2 m applied to the cart.

    M = .5;m = 0.2;b = 0.1;i = 0.006;g = 9.8;l = 0.3;

    p = i*(M+m)+M*m*l^2; %denominator for the A and B matricesA = [0 1 0 0; 0 -(i+m*l^2)*b/p (m^2*g*l^2)/p 0; 0 0 0 1; 0 -(m*l*b)/p m*g*l*(M+m)/p 0]B = [ 0; (i+m*l^2)/p; 0; m*l/p]C = [1 0 0 0; 0 0 1 0]D = [0; 0]pend=ss(A,B,C,D);T=0:0.05:10;U=0.2*ones(size(T));[Y,T,X]=lsim(pend,U,T);plot(T,Y)axis([0 2 0 100])

    You should see the following output after running the m-file:

    The blue line represents the cart's position and the green line represents the pendulum's angle. It isobvious from this plot and the one above that some sort of control will have to be designed to improvethe dynamics of the system. Several example controllers are included with these tutorials; select frombelow the one you would like to use.

    6

  • Note: The solutions shown in the PID, root locus and frequency response examples may not yield aworkable controller for the inverted pendulum problem. As stated previously, when we put thisproblem into the single-input, single-output framework, we ignored the x position of the cart. Thependulum can be stabilized in an inverted position if the x position is constant or if the cart moves at aconstant velocity (no acceleration). Where possible in these examples, we will show what happens tothe cart's position when our controller is implemented on the system. We emphasize that the purposeof these examples is to demonstrate design and analysis techniques using MATLAB; not to actuallycontrol an inverted pendulum.

    Modeling ExamplesCruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | PitchController | Ball & Beam

    Inverted Pendulum ExamplesModeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Simulink

    TutorialsMATLAB Basics | MATLAB Modeling | PID Control | Root Locus | Frequency Response | StateSpace | Digital Control | Simulink Basics | Simulink Modeling | Examples

    7

  • Example: Modeling a Pitch ControllerPhysical setup and system equationsDesign requirementsTransfer function and state-spaceMATLAB representation and open-loop responseClosed-loop transfer function

    Physical setup and system equations

    The equations governing the motion of an aircraft are a very complicated set of six non-linear coupleddifferential equations. However, under certain assumptions, they can be decoupled and linearized intothe longitudinal and lateral equations. Pitch control is a longitudinal problem, and in this example, wewill design an autopilot that controls the pitch of an aircraft.

    The basic coordinate axes and forces acting on an aircraft are shown in the figure below:

    Assume that the aircraft is in steady-cruise at constant altitude and velocity; thus, the thrust and dragcancel out and the lift and weight balance out each other. Also, assume that change in pitch angle doesnot change the speed of an aircraft under any circumstance (unrealistic but simplifies the problem abit). Under these assumptions, the longitudinal equations of motion of an aircraft can be written as:

    (1)

    Please refer to any aircraft-related textbooks for the explanation of how to derive these equations.Also, click Variables to see what each variable represents.

    For this system, the input will be the elevator deflection angle, and the output will be the pitch angle.

    1

  • Design requirements

    The next step is to set some design criteria. We want to design a feedback controller so that the outputhas an overshoot of less than 10%, rise time of less than 2 seconds, settling time of less than 10seconds, and steady-state error of less than 2%. For example, if the input is 0.2 rad (11 degrees), thenthe pitch angle will not exceed 0.22 rad, reaches 0.2 rad within 2 seconds, settles to 2% of thesteady-state within 10 seconds, and stays within 0.196 to 0.204 rad at the steady-state.

    Overshoot: Less than 10%Rise time: Less than 2 secondsSettling time: Less than 10 secondsSteady-state error: Less than 2%

    Transfer function and the state-space

    Before finding transfer function and the state-space model, let's plug in some numerical values tosimplify the modeling equations (1) shown above.

    (2)

    These values are taken from the data from one of Boeing's commercial aircraft.

    1. Transfer function

    To find the transfer function of the above system, we need to take the Laplace transform of the abovemodeling equations (2). Recall from your control textbook, when finding a transfer function, zeroinitial conditions must be assumed. The Laplace transform of the above equations are shown below.

    After few steps of algebra, you should obtain the following transfer function.

    2. State-space

    Knowing the fact that the modeling equations (2) are already in the state-variable form, we canrewrite them into the state-space model.

    2

  • Since our output is the pitch angle, the output equation is:

    MATLAB representation and open-loop response

    Now, we are ready to observe the system characteristics using MATLAB. First, let's obtain anopen-loop system to a step input and determine which system characteristics need improvement. Letthe input (delta e) be 0.2 rad (11 degrees). Create an new m-file and enter the following commands.

    de=0.2;

    num=[1.151 0.1774];den=[1 0.739 0.921 0];pitch=tf(num,den);step(de*pitch)axis([0 15 0 0.8])

    Running this m-file in the MATLAB command window should give you the following plot.

    From the plot, we see that the open-loop response does not satisfy the design criteria at all. In fact theopen-loop response is unstable.

    If you noticed, the above m-file uses the numerical values from the transfer function. To use the

    3

  • state-space model, enter the following commands into a new m-file (instead of the one shown above)and run it in the command window.

    de=0.2;

    A=[-0.313 56.7 0; -0.0139 -0.426 0; 0 56.7 0];B=[0.232; 0.0203; 0];C=[0 0 1];D=[0];pitch=ss(A,B,C,D);step(de*pitch)axis([0 15 0 0.8])

    You should get the same response as the one shown above.

    Note: It is possible to convert from the state-space to transfer function, or vice versa using MATLAB.To learn more about conversions, see Conversions

    Closed-loop transfer function

    To solve this problem, a feedback controller will be added to improve the system performance. Thefigure shown below is the block diagram of a typical unity feedback system.

    A controller needs to be designed so that the step response satisfies all design requirements. Severaldifferent methods to design a controller are listed at the bottom of this page.

    Modeling ExamplesCruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | PitchController | Ball and Beam

    Pitch Controller ExamplesModeling | PID | Root Locus | Frequency Response | State Space | Digital Control| Simulink

    TutorialsMATLAB Basics | MATLAB Modeling | PID Control | Root Locus | Frequency Response | StateSpace | Digital Control | Simulink Basics | Simulink Modeling | Examples

    4

  • V d: M hnh qu bng v thanh Thit lp bi tonPhng trnh h thngBiu din p ng ca h thng h trong Matlab

    Thit lp bi ton

    Mt qu bng t trn thanh nh hnh bn di, y qu bng c ln trn thanh , l mtbc t do. Mt tay quay c gn 1 u vo thanh , u kia gn vo ng c. Khi ng c quay 1gc teta, tay n s lm cho thanh quay 1 gc alpha. Khi thanh thay i gc t v tr cn bng,trng lc s khin qu bng ln trn thanh . Ta cn thit k mt b iu khin kim sot v trca qu bng.

    Vi bi ton ny, chng ta gi thit qu bng ln khng trt trn thanh v ma st gia bng vthanh l khng ng k. Cc tham s v bin cho bi ton ny xc nh nh sau:

    M khi lng ca bng 0.11 kg

    R bn knh ca bng 0.015 m

    d tay quay 0.03 m

    g gia tc trng trng 9.8 m/s^2

    L chiu di thanh 1.0 m

    J momen qun tnh ca bng 9.99e-6 kgm^2

    r to ca bng

    alpha to gc ca thanh

    theta gc quay ca ng c

    1

  • Mc tiu ra iu khin:

    Thi gian qu khng qu 3 giy qu iu chnh nh hn 5%

    Phng trnh h thng

    o hm bc hai ca gc quay alpha trn thc t s lm thay i to r. Tuy nhin, chng ta b quaiu ny. Phng trnh Lagrange dch chuyn ca bng c vit nh sau:

    Tuyn tnh ho gc quay ca alpha (alpha = 0) cho ta phng trnh gn ng sau:

    Phng trnh m t mi lin h gia gc quay ca thanh v gc quay ca ng c vit gn ngnh sau:

    Thay vo phng trnh trc, ta c phng trnh:

    1. Hm truyn

    Bin i Laplace phng trnh trn ta c phng trnh mi:

    Vit li di dng hm truyn gia gc quay ca ng c teta(s) v to dich chuyn ca bng R(s)ta c hm truyn.

    2

  • Ch hm truyn ca c cu chp hnh y l tch phn cp hai. Do vy n bin n nh v s rtphc tp c th iu khin.

    2. Khng gian trng thi

    Phng trnh tuyn tnh ho ca h cng c th biu din bng khng gian trng thi. iu ny thchin bng cch chn to r v vn tc r chm lm bin trng thi, gc quay teta lm u vo. Khnggian trng thi c biu din nh sau :

    Tuy nhin, vi v d nay ta biu din hi khc mt cht. Phng trnh cho bng vn gi nguynnhng thay v iu khin to bng theo gc quay teta ca ng c ta s iu khin momen quayca thanh . Di y l phng trnh biu din ca khng gian trng thi:

    Ch : Vi h thng mi ny ta coi nh khng c tay quay v ng c, thay vo l mt ng cgn vo gia thanh to momen quay iu khin to bng.

    3

  • Biu din trong Matlab v kho st p ng ca h thng h

    1. Hm truyn

    Hm truyn sau khi bin i Laplace c th biu din trong Matlab bng cch khai bo t s v mus nh hai vector. lm iu ny ta to mt m-file c cc lnh nh sau:

    m = 0.111;R = 0.015;g = -9.8;L = 1.0;d = 0.03;J = 9.99e-6;

    K = (m*g*d)/(L*(J/R^2+m)); %simplifies input

    num = [-K];den = [1 0 0];ball=tf(num,den)

    Hm truyn cui cng se l:

    Transfer function:0.21----s^2

    By gio chng ta quan st xem qu bng s ln nh th no khi u vo l tn hiu bc thang 0.25 m.Thm vo m-file lnh sau:

    step(0.25*ball)

    Ta s c to dch chuyn ca bng theo thi gian nh sau:

    T th trn ta thy rng h thng h l khng n nh, bng s ln ra khi thanh . Do vy ta cn

    4

  • mt s phng php iu khin to bng. Bn c c th chn trong 3 phng php l PID,Qu tch nghim (Root Locus), v p ng tn s (Frequency Response).

    2. Khng gian trng thi

    Khng gian trng thi c biu din trong Matlab vi cc lnh sau y (cc phng trnh ny dngcho iu khin momen quay nh cp trn).

    m = 0.111;R = 0.015;g = -9.8;J = 9.99e-6;

    H = -m*g/(J/(R^2)+m); A=[0 1 0 0 0 0 H 0 0 0 0 1 0 0 0 0];B=[0;0;0;1];C=[1 0 0 0];D=[0];ball=ss(A,B,C,D);

    p ng vi u vo tn hiu bc thang 0,25m c c sau khi thc hin lnh:

    step(0.25*ball)

    u ra theo thi gian c dng sau:

    Cng ging nh th c c t hm truyn ta thy rng h thng h l khng n nh, bng s lnra khi thanh . Do vy ta cn mt s phng php iu khin to bng. Cc v d v khnggian trng thi s cho bn mt s cch iu khin iu hnh.

    Nu bn mun bit cch lm sao chuyn t biu din trong khng gian trng thi sang biu dintheo hm truyn tham kho phn Chuyn i.

    5

  • Cc m hnh v diu khin xe | iu khin tc ng c | iu khin gc quay ng c | Bus Suspension |iu khin con lc ngc | Pitch Controller | Bi ton qu bng v thanh

    Ball & Beam ExamplesModeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Simulink

    TutorialsMATLAB Basics | MATLAB Modeling | PID Control | Root Locus | Frequency Response | StateSpace | Digital Control | Simulink Basics | Simulink Modeling | Examples

    6

  • PIDGii thiuBa lut iu khinc tnh ca tng lut iu khin P, I, v DCc v d

    p ng bc thang n v ca h thng vng hiu khin t lPiu khin t l-vi phnPiu khin t l-tch phniu khin t l-vi phn-tch phn

    Nhng gi chung thit k b iu khin PID

    Lnh dng trong MATLAB tm hiu v phn ny l: step feedback

    Gii thiu

    Phn ny s cho cc bn bit v c tnh ca tng lut iu khin t l(P), vi phn(D) v tch phn(I)v cch dng chng c c p ng mong mun. Ta xt 1 h thng nh sau:

    Plant: L 1 c cu php hnh cn iu khinController: a ra nhng kch thch cho plant v c thit k iu khin ton b h thng

    Ba lutiu khin

    The hm truyn ca phng php iu khin PID c dng nh sau:

    1

  • Kp = H s t lKI = H s tch phnKd = H s vi phn

    Trc tin, ta tm hiu xem b iu khin PID lm vic nh th no, ta ly s h thng trn. Bine th hin cho sai s gia u vo mong mun R v u ra chp hnh Y. Tn hiu lch ny s c gin b iu khin PID v b iu khin PID s tnh c tch phn v vi phn ca sai s. Tn hiuiu khin u c gi tr bng Kp ln bin ca sai s cng vi Ki ln tch phn ca sai s cng vi Kdln vi phn ca sai s.

    Tn hiu u s c gi ti c cu chp hnh, v cho ra u ra Y. u ra Y s c gi n sensor ov ta li c gi tr sai s e mi. B iu khin s li ly gi tr sai s mi, tnh ton tch phn, vi phnv li a ra tn hiu iu khin. Qu trnh ny s c lp i lp li.

    c tnh ca lut iu khin P, I, v D

    Lut iu khin P c tc dng lm gim thi gian qu nhng khng th kh c steady-stateerror. Lut iu khin I c tc dng kh c steady-state error, nhng n lm gim kh nng p ngtc thi ca h thng. Lut iu khin D c tc dng tng n nh ca h thng gim overshoot, vci thin kh nng p ng tc thi. Hiu qu ca tng lut iu khin P, I, v D ln h thng vngkn c tng kt qua bng sau.

    .

    CL RESPONSE RISE TIME OVERSHOOT SETTLING TIME S-S ERROR

    Kp Gim Tng t thay i Gim

    Ki Gim Tng Tng Kh c

    Kd t thay i Gim Gim t thay i

    Nn nh s tng quan ny khng hon ton tuyt i, v cc gi tr Kp, Ki, v Kd l ph thuc vonhau. Trn thc t, khi thay i gi tr ca h s lut iu khin ny s lm thay i hiu qu tc ngca lut kia. V vy bng trn ch l tham kho trong qu trnh thit k ta c th chn Ki, Kp vKd.

    V d

    Gi s ta c 1 h khi lng, l xo v chng rung nh sau.

    2

  • Phng trnh ng lc hc ca h thng trn l

    (1)

    Bin i Laplace t (1), ta c

    Hm truyn gia dch chuyn X(s) v u vo F(s) by gi l

    Ly cc gi tr

    M = 1kgb = 10 N.s/mk = 20 N/mF(s) = 1

    Lp cc gi tr trn vo hm truyn ta c

    Mc ch ca v d ny l minh ho cho vic chn Kp, Ki v Kd sao cho

    Qu nhanhOvershoot nh nhtKhng c steady-state error

    p ng bc thang n v ca h thng h

    Trc ht ta kho st p ng bc thang n v ca h thng h. To mt m-file c cc lnh nh sau:

    num=1;den=[1 10 20];plant=tf(num,den);step(plant)

    3

  • Chy m-file ny ta s c th nh sau.

    Gi tr DC gain ca hm truyn l 1/20, do vy 0.05 l gi tr cui ca output p ng u vo bcthang n v. Nh vy steady-state error l 0.95, thc s l kh ln. Hn na, thi gian qu khong1 giy, thi gian n nh khong 1,5 giy. By gi nhim v ca ta l thit k b iu khin sao chogim thi gian qu , thi gian n n nh ngn, v kh c steady-state error.

    Lut iu khin P

    Chng ta bit lut iu khin P lm gim thi gian qu , tng overshoot, v gim steady-stateerror. Hm truyn iu khin vng kn vi lut iu khin P by gi l:

    Chn Kp = 300 v thm vo m-file on m lnh sau:

    Kp=300;contr=Kp;sys_cl=feedback(contr*plant,1);t=0:0.01:2;step(sys_cl,t)

    Chy m-file trong MATLAB ta c kt qu nh sau.

    4

  • Ch : Hm feedback dng to mt hm truyn vng kn t mt hm truyn vng h cho trc(thay cho vic thit lp li bng tay).

    T th trn ta thy rng lut iu khin P lm gim thi gian qu v steady-state error, nhngtng qu iu chnh, v lm ko di thi gian n n nh i 1 cht.

    iu khin t l-vi phn

    By gi chng ta xt n lut iu khin PD. Nh bng nu phn trc, ta thy rng lut iukhin D lm gim c qu iu chnh v lm h thng nhanh n n nh. Hm truyn vng knvi lut iu khin PD by gi l:

    Nh trc ta vn ly Kp = 300, ly Kd = 10. Nh trc ta thm vo m-file on m lnh sau v chycho ra th.

    Kp=300;Kd=10;contr=tf([Kd Kp],1);sys_cl=feedback(contr*plant,1);t=0:0.01:2;step(sys_cl,t)

    5

  • th ny cho ta thy ngay lut iu khin D gim c qu iu chnh v lm h thng nhanhn n nh so vi trc, v tc ng khng ng k ti thi gian qu cng nh steady-state error.

    iu khin t l-tch phn

    Trc khi xy dng b iu khin PID, chng ta xem xt ti lut iu khin PI . Nh bng tng kt, tathy rng lu iu khin I lm gim thi gian qu , nhng lm tng qu iu chnh v ko dithi gian n n nh ca h thng, nhng li kh c steady-state error. Vi h thng trn, chuynthnh hm truyn vng kn vi lut iu khin PI ta c hm truyn mi:

    By gi ta chn li Kp = 30, Ki = 70. To m-file vi cc dng lnh sau.

    Kp=30;Ki=70;contr=tf([Kp Ki],[1 0]);sys_cl=feedback(contr*plant,1);t=0:0.01:2;step(sys_cl,t)

    Chy chng trnh trong MATLAB ta c th sau.

    6

  • L do chng ta gim Kp i l v lut iu khin I cng c tc dng lm gim thi gian qu v tng qu iu chnh nh lut iu khin P. th trn cho ta thy lut iu khin I kh c sai sxc lp.

    iu khin t l-tch phn-vi phn(PID)

    By gi ta xt n b iu khin PID. Hm truyn ca h thng trn vi b iu khin PID vng knby gi l:

    Sau mt s ln chy th vi cc tham s khc nhau, ta chn c Kp=350, Ki=300, v Kd=50 hthng s t c c tnh nh mong mun. Bn c c th th li bng cch to m-file vi cc lnhsau v chy th. Chng ta s c th p ng nh mong mun.

    Kp=350;Ki=300;Kd=50;contr=tf([Kd Kp Ki],[1 0]);sys_cl=feedback(contr*plant,1);t=0:0.01:2;step(sys_cl,t)

    7

  • By gi ta c mt h thng iu khin vng kn khng c qu iu chnh, qu nhanh, vkhng c sai s xc lp.

    Mt s gi cho thit k b iu khin PID

    Khi mun thit k mt b iu khin PID cho mt h thng no ta i theo nhng bc sau y.

    Kho st ht thng h v xc nh iu g cn c ci thin1.Thm vo lut iu khin P ci thin qu trnh qu 2.Thm vo lut iu khin D gim qu iu chnh3.Thm vo lut iu khin I kh sai s xc lp4.i chnh cc gi tr Kp, Ki, v Kd cho n khi t c p ng nh mong mun. Bn cng cth tham kho trang "PID Tutorial" bit lut iu khin no tc ng vo nhng c tnhno.

    5.

    Cui cng, xin nh l khng pha lc no ta cng phi kt hp c 3 lut iu khin (t l, vi phn, vtch phn) vo h thng. V d, nu lut iu khin PI cho p ng t cht lng tt ri (nh v dtrn), th chng ta khng nht thit thm vo c lut iu khin D. Cn thit k lm sao h thngca ta cng n gin cng tt.

    V d v b iu khin PIDiu khin xe | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | PitchController | Ball and Beam

    TutorialsMATLAB Basics | MATLAB Modeling | PID Control | Root Locus | Frequency Response | StateSpace | Digital Control | Simulink Basics | Simulink Modeling | Examples

    8

  • V d: Gii php iu khin xe s dng b iukhin PID

    iu khin t liu khin PIiu khin PID

    Hm truyn ca h thng iu khin xe c dng.

    m = 1000b = 50U(s) = 10Y(s) = vn tc ra

    s khi chung c feedback ca h thng nh sau.

    Tiu chun t ra cho thit k iu khin l:

    Thi gian qu < 5 sec qu iu chnh < 10%

    Sai s xc lp < 2%

    bit cch thit lp m hnh h thng, xem trang M hnh iu khin xe .

    Nhc li kin thc t PID tutorial, hm truyn ca 1 b iu khin PID l

    Trc ht ta xem xt lut iu khin P.

    iu khin P

    iu u tin cn quan tm l tm ra hm truyn iu khin vng kn vi lut iu khin P t h thngtrn. Bng cch bin i s khi, hm truyn iu khin vng kn vi lut iu khin P by gi l:

    1

  • Nhc li kin thc v b iu khin PID, Lut iu khin P lm gim thi gian qu . V y cng lvn t ra phn M hnh iu khin xe .

    Trc ht ta cho Kp = 100 v xem th h thng p ng nh th no. To mt m-file c cc lnh sau.

    Kp=100;m=1000;b=50;u=10;num=[1];den=[m b];cruise=tf(num,den);sys_cl=feedback(Kp*cruise,1);t=0:0.1:20;step(u*sys_cl,t)axis([0 20 0 10])

    Chy m-file trong MATLAB s c p ng bc thang n v nh sau.

    Nh ta thy trn th, c sai s xc lp v thi gian qu u khng t c mc tiu ra. Ta cth tng h s Kp ci thin cht lng u ra. Sa li m-file 1 cht Kp = 10000 v chy li trongMATLAB. Ta s c th sau

    .

    2

  • Sai s xc lp gim gn v 0 trong khi thi gian qu ch cn nh hn 0.5 giy. Tuy nhin,p ng trn l khng thc t lm bi v mt h thng iu khin xe trn thc t khng th thay ivn tc xe t 0 n 10 m/s trong thi gian nh hn 0.5 giy.

    Gii php cho vn ny l chn Kp sao cho c mt thi gian qu hp l, v thm vo iu khintch phn kh sai s xc lp.

    iu khin PI

    Hm truyn iu khin vng kn ca h thng iu khin xe vi b lut iu khin PI l:

    Nhc li kin thc phn PID tutorial, khi ta thm iu khin tch phn vo h thng th s c tc dngkh sai s xc lp. By gi cho Kp = 600, Ki = 1 v xem p ng ca ht thng by gi ra sao. Sa lim-file nh sau.

    m=1000;b=50;num=[1];den=[m b];cruise=tf(num,den);Kp = 600;Ki = 1;contr=tf([Kp Ki],[1 0]);sys_cl=feedback(contr*cruise,1);u=10;t=0:0.1:20;step(u*sys_cl,t)axis([0 20 0 10])

    Ta c th p ng u ra nh sau:

    3

  • By gi ta iu chnh cc h s Kp v Ki t c p ng mong mun. Khi iu chnh Ki, chngta nn bt u vi gi tr nh v nu Ki ln s c th lm h thng mt n nh.

    Khi Kp = 800 v Ki =l 40, p ng bc thang n v s c dng sau:

    Nh chng ta thy, p ng ny t c mc tiu ra.

    iu khin PID

    Vi v d ny, ta khng cn thc hin lut iu khin D m vn t c muc tiu ra. Tuy nhin, tacng nn xem h thng s hot ng nh th no nu c b iu khin PID c th tham kho sauny. Hm truyn iu khin vng kn ca h thng vi b iu khin PID nh sau.

    Cho Kp = 1, Ki = 1, v Kd = 1 sau to mt m-file nh sau.

    Kp=1; Ki=1; Kd=1; m=1000;

    4

  • b=50; u=10; cruise=tf(num,den); contr=tf([Kd Kp Ki],[1 0]); sys_cl=feedback(contr*cruise,1); t=0:0.1:20;step(u*sys_cl,t)axis([0 20 0 10])

    Chy m-file ny ta s c p ng ca h thng. iu chnh cc gi tr Kp, Kd, v Ki n khi bn cc p ng nh mun. Chng ti ginh vic cho bn t thc hnh.

    Li khuyn: Thng thng vic chn cc gi tr tham s phi tri qua qu trnh th nhiu ln. Cch ttnht trnh cng vic bun t l bn nn iu chnh tng tham s (Kp, Kd, hoc Ki) mt v quanst xem tham s nh hng th no n u ra ca ht thng. Nhng c tnh nh hung ca Kp,Kd, v Ki c tng hp trong phn PID Tutorial.

    V d v b iu khin PID Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | PitchController | Ball and Beam

    V d v iu khin xeModeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Simulink

    TutorialsMATLAB Basics | MATLAB Modeling | PID Control | Root Locus | Frequency Response | StateSpace | Digital Control | Simulink Basics | Simulink Modeling | Examples

    5

  • V d: iu khin PID vn tc ng c mt chiuiu khin t liu khin PIiu chnh h s

    T v d trc y, ta c phng trnh ng lc hc ca v hm truyn h ca m hnh ng c 1chiu nh sau:

    v s khi ca h thng c dng nh sau:

    bit cch thit lp m hnh h thn, xem trang Modeling a DC Motor.

    Vi hm u vo bc thang 1 rad/sec, mc tiu thit k l:

    Thi gian n nh nh hn 2 giy qu iu chnh nh hn 5%Sai s xc lp nh hn 1%

    By gi ta thit k 1 b iu khin PID thm vo ht thng. Trc ht to mt m-file gm cc culnh sau (tham kho phn Modeling).

    J=0.01;b=0.1;K=0.01;R=1;L=0.5;num=K;den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2)];motor=tf(num,den);

    Nh li hm truyn ca b iu khin PID.

    1

  • iu khin P

    Trc ht ta th iu khin P vi Kp = 100. lp hm truyn iu khin vng kn, ta dng lnhfeedback. Thm vo cui m-file va ri cc lnh sau:

    Kp=100;contr=Kp;sys_cl=feedback(contr*motor,1);

    By gi ta s xem p ng bc thang ca h thng nh th no. Li thm tip vp cui m-file va rion lnh sau:

    t=0:0.01:5;step(sys_cl,t)title('Step response with Proportional Control')

    Khi chy m-file ta s c th nh sau:

    iu khin PID

    T th trn ta c th thy sai s xc lp v qua iu chnh u rt ln. Nh li phn PIDtutorial rng lut iu khin I kh c sai s xc lp v lut D lm gim qu iu chnh. Ta cngth b iu khin PID vi cc gi tr nh ca Ki v Kd. Sa li m-file nh di y. Sau chym-file ta s c th.

    J=0.01;b=0.1;K=0.01;R=1;L=0.5;

    2

  • num=K;den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2)];motor=tf(num,den);

    Kp=100;Ki=1;Kd=1;contr=tf([Kd Kp Ki],[1 0]);sys_cl=feedback(contr*motor,1);step(sys_cl)title('PID Control with small Ki and Kd')

    iu chnh h s

    Hin ti ta thy thi gian n nh l qu ln. Ta phi tng gi tr Ki gim thi gian n t n nh.Sa li gi tr Ki trong m-file bng 200. Cho chy m-file ta s c th nh sau:

    3

  • By gi ta c th thy p ng nhanh n nh hn trc, nhng gi tr Ki ln lm gim kh nngp ng tc thi ( qu iu chnh ln). Ta tng Kd gim q iu chnh. Sa li gi tr Kd trongm-file bng 10. Cho chy m-file ta s c th nh sau:

    By gi ta c b iu khin PID vi

    Kp=100,Ki=200,Kd=10,

    tho mn mc tiu t ra

    4

  • V d v b iu khin PIDiu khin xe | iu khin tc ng c | iu khin gc quay ng c | Bus Suspension |Inverted Pendulum | Pitch Controller | Ball and Beam

    Motor Speed ExamplesModeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Simulink

    TutorialsMATLAB Basics | MATLAB Modeling | PID Control | Root Locus | Frequency Response | StateSpace | Digital Control | Simulink Basics | Simulink Modeling | Examples

    5

  • V d: iu khin PID gc quay ng ciu khin t liu khin PIDiu chnh h s

    t vn , phung trnh ng lc hc hm truyn ca h thng nh sau:

    v s khi ca h thng:

    bit cch thit lp m hnh h thng tham kho trang M hnh ng c 1 chiu

    Vi u vo bc thang 1 rad, mc tiu thit k l:

    Thi gian n nh nh hn 0,04 giy qu iu chnh nh hn 16%Khng c sai s thit lpKhng b pht sinh sai s thit lp do nhiu

    Ta thit k 1 b iu khin PID cho vo trong h thng trn. Trc tin ta to mi 1 m-file c cc dnglnh sau (tham kho hm truyn pha trn).

    J=3.2284E-6;b=3.5077E-6;K=0.0274;R=4;L=2.75E-6;num=K;den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2) 0];motor=tf(num,den);

    Nh li hm truyn ca b iu khin PID c dng:

    1

  • iu khin t l

    Trc tin ta th iu khin t l vi h s Kp = 1,7. lp hm truyn iu khin vng kn ta dnglnh feedback. Thm cc lnh sau vo m-file:

    Kp=1.7;contr=Kp;sys_cl=feedback(contr*motor,1);

    By gi mun xem p ng ca h thng nh th no ta thm cc lnh tip theo vo m-file v chy:

    t=0:0.001:0.2;step(sys_cl,t)

    Ta c th nh sau:

    By gi mun bit p ng vi nhiu nh th no ta thm cc lnh sau vo cui m-file, sau chytrong Matlab:

    dist_cl=feedback(motor,contr);step(dist_cl,t)

    Ta s c th sau:

    2

  • iu khin PID

    T th trn ta thy rng sai s thit lp l chp nhn c nhng thi gian n nh qu ln cng nh qu iu chnh l cao. Cng c th thy rng sai s thit lp do nhiu tc ng cng ln. Nh liphn PID tutorial rng lut P kh c sai s thit lp v lut D lm gim qu iu chnh. Nhngtrc ht hy th iu khin PI khc phc nh hng ca nhiu. Sa li m-file nh sau:

    J=3.2284E-6;b=3.5077E-6;K=0.0274;R=4;L=2.75E-6;num=K;den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2) 0];motor=tf(num,den);

    Kp=1.7;Ki=20;contr=tf([Kp Ki],[1 0]);sys_cl=feedback(contr*motor,1);t=0:0.001:0.4;step(sys_cl,t)

    Ta s c th nh sau:

    3

  • V xem nh hng ca nhiu bc thang nh th no, hy thm cc lnh sau vo m-file:

    figuredist_cl=feedback(motor,contr);step(dist_cl,t)

    Ta s c th sau:

    Nh vy lut I c tc dng lm gim sai s thit lp v gi tr 0.

    iu chnh h s

    Ta thy thi gian t ti n nh vn qu di. Ta phi tng gi tr cc h s qu trnh n nhnhanh hn na. Sa li gi tr Ki = 200 v Kp = 17 trong m-file. Cho chy trong Matlab ta s c thnh sau:

    4

  • By gi c th thy thi gian t n nh nhanh hn, nhng gi tr Ki ln li lm tng qu iuchnh. By gi ta phi dng lut D gim qu iu chnh. Sa li m-file nh sau ri cho chy trongMatlab.

    Kp=17;Ki=200;Kd=0.15;contr=tf([Kd Kp Ki],[1 0]);sys_cl=feedback(contr*motor,1);t=0:0.001:0.1;step(sys_cl,t)

    Ta s c th sau:

    5

  • V th p ng vi u vo nhiu bc thang nh sau:

    By gi ta c th thy qu trnh qu tt hn hn, qu iu chnh nh hn 16% thi gian qu ch khong 40ms, v khng c sai s thit lp. Tuy nhin p ng vi nhiu li n nh chm. Ta stng Ki p ng vi nhiu n nh nhanh hn. Cho Ki = 600 trong m-file chy trong Matlab. Ta sc th sau:

    6

  • By gi ta c k qu l qu trnh qu ch khong 40ms, qu eu chnh nh hn 16%, v khngc sai s thit lp. p ng vi nhiu khng b sai s thit lp. Nh vy b iu khin PID vi

    Kp=17,Ki=600,Kd=.15,

    tho mn yu cu iu khin ra.

    V d v b iu khin PIDiu khin xe | iu khin tc ng c | iu khin gc quay ng c | Bus Suspension |Inverted Pendulum | Pitch Controller | Ball and Beam

    V d v u khin gc quay ng c

    7

  • Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Simulink

    TutorialsMATLAB Basics | MATLAB Modeling | PID Control | Root Locus | Frequency Response | StateSpace | Digital Control | Simulink Basics | Simulink Modeling | Examples

    8

  • Example:PID Design Method for the Bus SuspensionSystem

    Adding a PID controllerPlotting the closed-loop responseChoosing the gains for the PID controller

    From the main problem, the dynamic equations in transfer function form are the following:

    and the system schematic looks like:

    For the original problem setup and the derivation of the above equations and schematic, please refer to the busmodeling page.

    We want to design a feedback controller so that when the road disturbance (W) is simulated by a unit step input,the output (X1-X2) has a settling time less than 5 seconds and an overshoot less than 5%. For example, when thebus runs onto a 10 cm high step, the bus body will oscillate within a range of +/- 5 mm and will stop oscillatingwithin 5 seconds.

    The system model can be represented in MATLAB by creating a new m-file and entering the following commands(refer to main problem for the details of getting those commands).

    m1=2500;m2=320;k1 = 80000;k2 = 500000;b1 = 350;b2 = 15020;

    nump=[(m1+m2) b2 k2]denp=[(m1*m2) (m1*(b1+b2))+(m2*b1) (m1*(k1+k2))+(m2*k1)+(b1*b2) (b1*k2)+(b2*k1) k1*k2];G1=tf(nump,denp);

    num1=[-(m1*b2) -(m1*k2) 0 0];

    1

  • den1=[(m1*m2) (m1*(b1+b2))+(m2*b1) (m1*(k1+k2))+(m2*k1)+(b1*b2) (b1*k2)+(b2*k1) k1*k2];G2=tf(num1,den1);

    numf=num1;denf=nump;F=tf(numf,denf);

    Adding a PID controller

    Recall that the transfer function for a PID controller is:

    where KP is the proportional gain, KI is the integral gain, and KD is the derivative gain. Let's assume that we willneed all three of these gains in our controller. To begin, we might start with guessing a gain for each: KP=208025,KI=832100 and KD=624075. This can be implemented into MATLAB by adding the following code into yourm-file:

    KD=208025;KP=832100;KI=624075;contr=tf([Kd Kp Ki],[1 0]);

    Now let's simulate the response of the system (the distance X1-X2) to a step disturbance on the road. From theschematic above we can find the transfer function from the road disturbance W to the output(X1-X2), andsimulate:

    sys_cl=F*feedback(F*G1,contr);

    Plotting the closed-loop response

    Now we have created the closed-loop transfer function in MATLAB that will represent the plant, the disturbance,as well as the controller. Let's see what the closed-loop step response for this system looks like before we beginthe control process. Keep in mind that we are going to use a 0.1 m high step as our disturbance, to simulate this,all we need to do is to multiply sys_cl by 0.1. Add the following code your m-file:

    t=0:0.05:5;step(0.1*sys_cl,t)title('closed-loop response to 0.1m high step w/ pid controller')

    you should see the response (X1-X2) to a step W like this:

    2

  • From the graph, the percent overshoot is 9mm, which is larger than the 5mm requirement, but the settling time issatisfied, less than 5 seconds. To choose the proper gain that yields reasonable output from the beginning, we startwith choosing a pole and two zeros for PID controller. A pole of this controller must be at zero and one of thezeros has to be very close to the pole at the origin, at 1. The other zero, we will put further from the first zero, at 3,actually we can adjust the second-zero's position to get the system to fulfill the requirement. Add the followingcommand in the m-file, so you can adjust the second-zero's location and choose the gain to have a rough ideawhat gain you should use for KD,KP, and KI.

    z1=1;z2=3;p1=0;numc=conv([1 z1],[1 z2]);denc=[1 p1];contr=tf(numc,denc);rlocus(contr*G1)title('root locus with PID controller')[K,p]=rlocfind(contr*G1)

    you should see the closed-loop poles and zeros on the s-plane like this and you can choose the gain and dominantpoles on the graph by yourself:

    3

  • We will explain root locus method in more detail in the "Root Locus" page.

    Choosing the gains for the PID controller

    Now that we have the closed-loop transfer function, controlling the system is simply a matter of changing theKD,KP,and KI variab. From the figure above, we can see that the system has larger damping than required, butthe settling time is very short. This response still doesn't satisfy the 5% overshoot requirement. As mentionedbefore, this can be rectified by adjusting the KD, KP and KI variab to find better response. Let's increaseKP,KI,KD by a factor of 2 to see what will happen. Go back to your m-file and multiply KP,KI,KD by 2 andthen rerun the program, you should get the following plot:

    To compare this graph with the graph of low-gain PID controller, you can change the axis:

    axis([0 5 -.01 .01])

    4

  • Now we see that the percent overshoot and settling time meet the requirements of the system. The percentovershoot is about 5% of the input's amplitude and settling time is 2 seconds which is less than the 5 secondrequirement.

    For this problem, it turns out that the PID design method adequately controls the system. This can been seen bylooking at the root locus plot. Such a task can be achieved by simply changing only the gains of a PID controller.Feel free to play around with all three of the parameters,KD,KP and KI, as we suggested, but you will most likelyget the response to have either large percent overshoot or very long settling time.

    PID ExamplesCruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Balland Beam

    Bus Suspension ExamplesModeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Simulink

    TutorialsMATLAB Basics | MATLAB Modeling | PID Control | Root Locus | Frequency Response | State Space |Digital Control | Simulink Basics | Simulink Modeling | Examples

    5

  • V d: Gii php iu khin PID cho con lc ngcBiu din h thng hHm truyn ca h thng iu khin vng knTch hp b iu khin PIDiu g xy ra vi v tr ca xe

    Hm truyn ca c cu chp hnh nh sau:

    y,

    Mc tiu thit k (vi iu kin lc u con lc nhn c xung lc1N t xe) l:

    Thi gian n nh nh hn 5 giy.Con lc di chuyn khng qu 0,05 rad so vi phng thng ng.

    bit cch xy dng m hnh bi ton ny nh th no tham kho phn m hnh con lc ngc

    Biu din h thng h

    iu u tin cn lm khi mun thit k b PID l tm hm truyn ca h thng v xem xt n. Hmtruyn sau khi bin i Laplace vi u ra Phi (gc quay ca con lc) c th c biu din trongMatlab vi t s v mu s l hai vector. To mt m-file c cc lnh sau thit lp hm truyn:

    M = .5;m = 0.2;b = 0.1;i = 0.006;g = 9.8;l = 0.3;

    q = (M+m)*(i+m*l^2)-(m*l)^2; %simplifies input

    num = [m*l/q 0];den = [1 b*(i+m*l^2)/q -(M+m)*m*g*l/q -b*m*g*l/q];

    1

  • pend=tf(num,den);

    Hm truyn ca h thng iu khin vng kn

    M hnh ca h thng ny c th hi khc so vi nhng m hnh truyn thng m ta quen bit. Do vy y t bi ton l iu khin con lc v tr thng bng vi u vo nhiu l mt xung lc ban u,tn hiu reference l 0. Xung lc ban u y chnh l mt xung nhiu. S h thng nh vy s cdng sau.

    d dng chuyn i thnh hm truyn trong Matlab ta bin i tng ng thnh s sau:

    Tch hp b iu khin PID

    Hm truyn trn c thit lp trong Matlab bng cc lnh sau:

    Kd = 1;Kp = 1;Ki = 1;contr=tf([Kd Kp Ki],[1 0]);sys_cl=feedback(pend,contr);

    cho tin vi hm truyn ny ta ly lun c 3 lut iu khin P, I v D (iu ny cng khng btbuc, bn c vn c th bt u tng bc mt vi cc b iu khin PI, PD tu theo mnh).

    contr=tf([Kp Ki],[1 0]); % PI controlcontr=tf([Kd Kp],1); % PD control

    By gi l lc ta bt u iu khin h thng hin ti. Trc ht ta xem p ng xung ca h thnghin ti ra sao. Thm cc cu lnh sau vo M-Enter the following code to the end of your m-file:

    t=0:0.01:5;impulse(sys_cl,t)axis([0 1.5 0 40])

    Ta c p ng dch chuyn ca h thng nh sau:

    2

  • p ng ny cha n nh. Trc ht ta tng h s Kp xem tc ng nh th no, cho Kp=100, vt li h to bng lnh axis([0, 2.5, -0.2, 0.2]), ta s c th sau:

    Thi gian qu 2 giy y l chp nhn c. V sai s xc lp v 0 nn ta khng cn iu khinKi thm na. Bn c th thy iu bng cch th thay i Ki v chy li. D nhn thy l quiu chnh l qu ln v ta cn gi quyt vn ny. gii quyt ta tng gi tr Kd. Vi Kd = 20, tac kt qu nh mong mun. Hy xem p ng vi gi tr Kd = 20:

    3

  • Nh ta thy, qu iu chnh gim xung nh hn 0,05 rad nh th ngha l con lc dch chuynxung quanh v tr thng ng khng qu 0,05 rad. Mc tiu iu khin t, khng cn thit phiiu chnh tip na.

    iu g xy ra vi v tr ca xe?

    Ngay t u, chng ta a ra m hnh ca h thng. Nhng m hnh cha thc s hon thin.Chng ta b qua dch chuyn ca xe v ta ang quan tm ti gc quay ca con lc. S rt hay nu taxem xt dch chuyn ca xe ra sao khi ta ang iu khin gc quay ca con lc. c th, trc ht taxem s khi thc t nh sau:

    Bin i li 1 cht ta c s khi nh sau

    :

    4

  • Vng kn trn l h thng ta va thit k vi b iu khin PID cho gc quay con lc. Hm truynvi u ra l dch chuyn ca xe by gi nh sau:

    By gi ta c th xy dng hm truyn cho ton b h thng, hy xem p ng ca n ra sao.Trc ht ta tm hm truyn cho dich chuyn ca xe. c uc iu ny ta phi s dng bin iLaplace cho phng trnh h thng ri tm mi lin h gia X(s) v U(s). Ta c phng trnh sau:

    y,

    bit thm v bin i Laplace tham kho phn m hnh con lc ngc.

    Lc ny li xut hin pole/zero hm truyn m lc trc c gin c trong hm truyn ca Phi.Do den1 = den2. By gi to 1 m-file vi cc dng lnh sau:

    M = .5;m = 0.2;b = 0.1;i = 0.006;g = 9.8;l = 0.3;

    q = (M+m)*(i+m*l^2)-(m*l)^2; %simplifies input

    num1 = [m*l/q 0 0];den1 = [1 b*(i+m*l^2)/q -(M+m)*m*g*l/q -b*m*g*l/q 0];G1=tf(num1,den1);

    num2 = [(i+m*l^2)/q 0 -m*g*l/q];den2 = den1;G2=tf(num2,den2); kd = 20;kp = 100;ki = 1;contr=tf([kd kp ki],[1 0]);

    xpos=feedback(1,G1*contr)*G2;

    t=0:0.01:5;impulse(xpos,t)

    5

  • Nh ta thy, xe chuyn ng theo chiu m vi vn tc l hng s ngha l theo thi gian v tr xe stin ra v cng. Nh vy mc d b iu khin PID n nh c gc quay ca con lc nhng thit k khng kh thi ng dng thc t.

    V d v b iu khin PIDiu khin xe | iu khin tc ng c | iu khin gc quay ng c | Bus Suspension |iu khin con lc ngc | Pitch Controller | Ball & Beam

    Inverted Pendulum ExamplesModeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Simulink

    TutorialsMATLAB Basics | MATLAB Modeling | PID Control | Root Locus | Frequency Response | StateSpace | Digital Control | Simulink Basics | Simulink Modeling | Examples

    6

  • Example: PID Design method for the PitchController

    Proportional controlProportional-Derivative controlProportional-Integral-Derivative control

    In the Pitch Controller Modeling page, the transfer function was derived as

    The input (elevator deflection angle, delta e) will be 0.2 rad (11 degrees), and the output is the pitchangle (theta).

    The design requirements are

    Overshoot: Less than 10%Rise time: Less than 2 secondsSettling time: Less than 10 secondsSteady-state error: Less than 2%

    To see the original problem setup, please refer to the Pitch Controller Modeling page.

    Recall from the PID Tutorial page, the transfer function of a PID controller is:

    We will implement combinations of proportional (Kp), integral (Ki), and derivative (Kd) controllers inan unity feedback system shown below to study the system output.

    Let's first take a look at a proportional control.,

    Proportional control

    The first thing in solving this problem using PID control is to find a closed-loop transfer function with aproportional control (Kp). A closed-loop transfer function can be obtained either by hand or using theMATLAB function called feedback. By hand, you should obtain the closed-loop transfer function as:

    1

  • Note: MATLAB cannot manipulate symbolic variab. To use the function feedback, enter the followingcommands to an m-file and run it in the MATLAB command window.

    Kp=[1];num=[1.151 0.1774];den=[1 0.739 0.921 0];pitch=tf(num,den);contr=tf(Kp,1);sys_cl=feedback(contr*pitch,1);

    For now, let the proportional gain (Kp) equal 2 and observe the system behavior. Enter the followingcommands into a new m-file and run it in the MATLAB command window. You should obtain the stepresponse similar to the one shown below:

    de=0.2;Kp=2;sys_cl=feedback(Kp*pitch,1);t=0:0.01:30;step(de*sys_cl,t)

    As you see, both the overshoot and the settling time need some improvement.

    PD control

    Recall from the PID Tutorial page, the derivative controller will reduce both the overshoot and thesettling time. Let's try a PD controller. The closed-loop transfer function of the system with a PDcontroller is:

    2

  • Using the commands shown below and with several trial-and-error runs, a proportional gain (Kp) of 9and a derivative gain (Kd) of 4 provided the reasonable response. To confirm this, change your m-fileto the following and run it in the MATLAB command window. You should obtain the step responsesimilar to the one shown below:

    de=0.2;Kp=9;Kd=4;contr=tf([Kd Kp],1);sys_cl=feedback(contr*pitch,1);t=0:0.01:10;step(de*sys_cl,t)

    This step response shows the rise time of less than 2 seconds, the overshoot of less than 10%, thesettling time of less than 10 seconds, and the steady-state error of less than 2%. All designrequirements are satisfied.

    PID Control

    Even though all design requirements were satisfied with the PD controller, the integral controller (Ki)can be added to reduce the sharp peak and obtain a smoother response. After several trial-and-errorruns, the proportional gain (Kp) of 2, the integral gain (Ki) of 4, and the derivative gain (Kd) of 3provided a smoother step response that still satisfies all design requirements. To confirm this, enter thefollowing commands to an m-file and run it in the command window. You should obtain the stepresponse shown below:

    de=0.2;Kp=2;Kd=3;Ki=4;

    num=[1.151 0.1774];den=[1 0.739 0.921 0];

    pitch=tf(num,den);contr=tf([Kd Kp Ki],[1 0]);

    sys_cl=feedback(contr*pitch,1); t=0:0.01:10; step(de*sys_cl,t)

    3

  • Comments

    To find appropriate gains (Kp, Kd, and Ki), you can use the table shown in PID Tutorial page;however, please keep in your mind that changing one gain might change the effect of the othertwo. As a result, you may also need to change the other two gains.

    1.

    Our system with a PI controller does not provide the desired response; thus, a PI Controlsection was omitted from this page. You may confirm this by using the m-file shown in PIDControl section, and set Kd to zero.

    2.

    PID ExamplesCruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | PitchControl | Ball and Beam

    Pitch Control ExamplesModeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Simulink

    TutorialsMATLAB Basics | MATLAB Modeling | PID Control | Root Locus | Frequency Response | StateSpace | Digital Control | Simulink Basics | Simulink Modeling | Examples

    4

  • V d: Gii php cho bi ton Bng &Thanh sdng b iu khin PID

    Biu din h thng vng kniu khin T liu khin T l-Vi phn

    Hm truyn h thng h thit lp trong phn m hnh nh sau:

    Mc tiu thit k b iu khin:

    Thi gian qu nh hn 3 giy qu iu chnh nh hn 5%

    bit cch thit lp m hnh ton hc trn, tham kho trang m hnh bng v thanh .

    Biu din h thng iu khin vng kn

    S khi h thng iu khin vng kn nh sau:

    Trc tin, ta xem p ng ca h thng ra sao vi b iu khin P. Sau s thm vo cc lut Dhoc I nu cn thit.

    Nhc li rng hm truyn ca b iu khin PID c dng:

    iu khin t l

    Hm truyn ca h thng iu khin t l vng kn vi Kp = 100 c thit lp trong Matlab bng cchto ra mt m-file c lnh sau:

    1

  • m = 0.111;R = 0.015;g = -9.8;L = 1.0;d = 0.03;J = 9.99e-6;

    K = (m*g*d)/(L*(J/R^2+m)); %simplifies input

    num = [-K];den = [1 0 0];ball=tf(num,den);

    kp = 1;sys_cl=feedback(kp*ball,1);

    xem p ng ca h thng vi u vo l tn hiu bc thang 0.25 m. Thm lnh sau vo cui m-filev chy:

    step(0.25*sys_cl)

    Ta s c th sau:

    Nh ta thy Kp khng lm h thng n nh. Hy th mt s gi tr khc c Kp, bn s vn thy hthng khng th n nh.

    iu khin T l - Vi phn

    By gi ta thm lut D vo b iu khin. To mt m-file c cc lnh sau ri chy.

    m = 0.111;R = 0.015;g = -9.8;L = 1.0;d = 0.03;J = 9.99e-6;

    K = (m*g*d)/(L*(J/R^2+m)); %simplifies input

    2

  • num = [-K];den = [1 0 0];ball=tf(num,den);

    kp = 10;kd = 10;contr=tf([kd kp],1);

    sys_cl=feedback(contr*ball,1);

    t=0:0.01:5;step(0.25*sys_cl)

    th sau khi chy chng trnh s c dng sau:

    By gi h thng n nh song qu iu chnh li rt ln, v thi gian qu cng cn iuchnh nhanh hn 1 cht. phn PID tutorial trong bng tng kt v cc lut iu khin P, I, v D tabit rng nu tng Kd ln th s ci thin c qu iu chnh v thi gian qu mt cht. Do ,thay i m-file cho Kd = 20 v chy li ta s c th sau:

    3

  • qu iu chnh t nhng cn gim thi gian qu mt cht. Ta tip tc tng Kd ln mt cht.Tng Kd cng c tc dng lm gim qu iu chnh do Kp to ra. Sau mt s ln iu chnh vi Kp= 15 v Kd =40 ta c p ng:

    Nh ta thy ch cn s dng iu khin P v D l ta gii quyt yu cu t ra (thi gian qu thm ch cn b hn 2% thi gian yu cu). Nn nh rng vi bt k vn iu khin no ta cngphi c ln hn 1 phng n th mi m bo.

    Xem cc lin kt bn di c thm nhng phng php iu khin khc cho bi ton bng v thanh.

    PID Examplesiu khin xe | iu khin tc ng c | iu khin gc quay ng c | Bus Suspension |

    4

  • iu khin con lc ngc | Pitch Controller | Bi ton bng v thanh

    V d v bi ton bng v thanh Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Simulink

    TutorialsMATLAB Basics | MATLAB Modeling | PID Control | Root Locus | Frequency Response | StateSpace | Digital Control | Simulink Basics | Simulink Modeling | Examples

    5

  • Qu tch nghim (Root Locus)Cc ca h kn th qu tch nghim ca mt hm truynChn gi tr K t qu tch nghimp ng mch kn

    Cc lnh MATLAB quan trng trong phn ny: feedback, rlocfind, rlocus, sgrid, step

    Cc ca h kn

    Qu tch nghim (mch h) ca mt hm truyn H(s) l th th hin v tr ca tt c cc cc ca hkn vi h s t l K v phn hi n v:

    Hm truyn mch kn vi phn hi n v bng:

    v v vy, cc ca h kn l cc gi tr, sao cho 1 + K H(s) = 0.

    Nu vit H(s) = b(s)/a(s), th phng trnh c dng:

    Gi n l bc ca a thc a(s) v m l bc ca a thc b(s) [bc ca mt a thc l s m cao nht ctrong a thc ].

    Chng ta tt c cc gi tr dng ca K. Ti gii hn K -> 0, cc ca h kn ng vi a(s) = 0 hoccc ca H(s). Ti gii hn K -> v cng, cc ca h kn ng vi b(s) = 0 hoc im 0 ca H(s).

    D K ng vi im no i na th h kn cng phi lun lun c n cc, trong n chnh l s ccca H(s). ng qu tch phi c n nhnh, mi nhnh xut pht t cc ca H(s) v chy n im 0ca H(s). Nu H(s) c s cc nhiu hn s im 0 (iu thng xy ra), m < n th ta ni rng H(s) c

    1

  • im 0 v cng. Trong trng hp ny, gii hn ca H(s) khi s -> v cng bng 0. S im 0 vcng l hiu n-m, ngha l hiu gia s cc v s im 0 v l s nhnh ca qu tch nghim tin ti vcng (tim cn).

    V qu tch nghim biu din mi v tr c th ca cc cc ca h kn, nn t qu tch nghim chng tac th chn h s truyn t cc tnh nng t ra cho h thng. Nu c bt k mt cc no nmtrong na mt phng pha phi th h kn s khng n nh. Cc cng nm gn trc o th nh hngcng nhiu n p ng h kn. V vy, d h c ti 3 hay 4 cc th n cng ch hot ng nh h bchai, thm ch bc 1, tu thuc vo v tr ca cc cc ch o.

    V qu tch nghim ca hm truyn

    Gi s c h h vi hm truyn sau:

    Chng ta cn thit k mt b iu khin c phn hi bng phng php qu tch nghim theo cc chtiu k thut sau: qu iu khin 5% v thi gian n nh 1 giy. To mt m-file vi tn rl.m. Nhphm truyn v lnh v qu tch nghim nh sau:

    num=[1 7];den=conv(conv([1 0],[1 5]),conv([1 15],[1 20]));sys=tf(num,den);rlocus(sys)axis([-22 3 -15 15])

    Chn gi tr ca K t qu tch nghim

    th trn biu din v tr ca tt c cc cc ca b iu khin thun tu t l. Tt nhin, khng phitt c cc cc u tho mn cc ch tiu thit k. xc nh xem cc no c th chp nhn c,chng ta dng lnh sgrid(Zeta,Wn) v cc ng c h s gim chn v tn s dao ng ringbng hng s. Hai tham s ca lnh chnh l h s gim chn (Zeta) v tn s dao ng ring (Wn)

    2

  • [chng c th l cc vector nu chng ta mun nhn thy khong cc gi tr c th chp nhn c].Trong bi ton ny, chng ta cn lng qu iu khin di 5% (ngha l h s gim chn Zeta > 0.7)v thi gian xc lp b hn 1 giy (ngha l tn s dao ng ring Wn > 1.8). Nhp thm chng vocui m-file trc :

    zeta=0.7;Wn=1.8;sgrid(zeta, Wn)

    Trn th, 2 ng nt chm nghing gn 45 th hin v tr ca cc cc ng vi gi tr Zeta = 0.7.Nm gia 2 ng ny l cc cc ng vi Zeta > 0.7 v pha ngoi l cc cc vi Zeta < 0.7. Navng trn th hin cc cc vi tn s dao ng ring Wn = 1.8. Cc cc nm pha trong ng vi Wn 1.8.

    Tr li bi ton, lng qu iu khin nh hn 5%, th cc cc phi nm gia 2 ng nt chm,cn mun c thi gian xc lp ngn hn 1 giy th cc cc phi nm ngoi na vng trn. Nh vy,ch c on qu tch nghim nm ngoi na vng trn v gia 2 ng nt chm l tho mn yu cu.Tt c cc cc trn on ny u nm na mt phng bn tri, nn h kn thit k ra s n nh.

    T th trn, ta thy ch c mt phn ca qu tch nghim l nm trong vng mong mun. V vy,chng ta ch cn 1 b iu khin t l a cc cc v vng ny. Chng ta dng lnh rlocfind tm cc cc mong mun trn qu tch:

    [k,poles] = rlocfind(sys)

    Dng chut kch vo im m chng ta nh dng lm cc ca h kn. Bn c th chn cc im nhtrong hnh di tho mn cc ch tiu thit k.

    3

  • Ch rng, v qu tch nghim c trn 1 nhnh nn khi chn mt cc, bn c th tm ra v tr ca cccc khc. Nh rng chng cng nh hng n p ng ca h thng. T th trn, chng ta c ththy tt c cc cc chn (c du +) l tho mn yu cu. By gi chng ta tip tc s dng gi trK chn cho b iu khin t l.

    Phn ng h kn

    tm p ng ca h vi tn hiu vo bc thang, chng ta cn bit hm