How to reate Matlab Sript an Simulink Moel for Designing a Pole Plaement Controller
Pole Plaement Controller Design H tot Y( Kr B ( R ( AC ( ( BD ( ( P ( AC ( ( BD ( (
Polplaement Equation ( ( ( ( [egree] ( ( ( ( ( B P K D C n n n n n n n P D B C A r n n n n a b b a p Choose egree: Set:
Pole Plaement Example Bertil Thomas, Moern reglerteknik y( k Y,8Y H ( B(,8y U Y,5 k A(,8,5u,5U,5 k,5,5,8,5u,5u k { Z :} (x Desire: ubble pole in,5
Pole Plaement Example,5,5 ( ( n p P,8 (,5,5 ( A B Desire: ubble pole in,5 ( ( D n n C n n a b,5 (,5 (,5 (,8 ( : P BD AC
Pole Plaement Example,5,8 (,5,85,8 (,5,5,8,8 (,5 (,5 (,8 (,5,5,8,5,8,5,8,5,5,8 ACBD P
Pole Plaement Example,8,5,5,8,5,5,8,8,5,5,8,8,5,5,36,3,5» X[,.5; -.8,.5]\[-.8,.5] X -.363.5»
Pole Plaement Example P B,5,5,5 K r P( B(,5,5,5,5 E U R K E C r Y D
Pole Plaement Example E U R K E C r Y D E,5 R,5Y U E,363 U E,363U Differens equations: U (,363 E e,5r, 5y k k k u k ek k,363u
Integrating Blok To avoi resiual error if we have a isturbane V we nee an integrating ontroller. A ( A( ( * During alulations the integrator is plae in A(, here alle A * (. ( easiest
With Integrating Blok Searhe P( has ubble pole,5 an extra pole in origo.,5 (,5 ( ( n p P (,8 ( (,8 (,5,5 ( * A A B ( ( D n n C n n a b *,5 (,5 (,5 ( (,8 ( : P BD A C
With Integrating Blok 3,5,5 (,8,5,5,8 (,8,5,8 ( (,5 (,5 ( (,8 (,5,8,5 (,8,57,5,5,8,5,5,5,8 (,8,8,5,5,8 (» X[,.5,;-.8,.5,.5;.8,,.5]\[.8,-.57,] X.38.876 -.66»
With Integrating Blok P B,5,5,5 K r P( B(,5,5,5,5 C * D( C( (,876,66 ( K r,5,6,38,88,63 (,38,68,5,5,8 Integrator now in C-blok! * C B A,38 D
Controller Differene Equations E U R K E * C r Y D E,5 R,88Y,63Y U,6 E,38 U,6U,38U E U E,6U,38U Differene Equations: ek,5rk,88 yk,63 yk u,6 k ek uk, 38uk
Matlab Sript for Lab 3 Pole plaement requires extensive alulations every time you want to try new poles. This is something you o not have time to o uring the lab you have to automate alulations using a Matlab sript. When solving the preparation tasks, evelop a MATLAB sript to be able to quikly reo the alulations uring the lab with the values of the real proess.
Matlab Sript for Lab 3 % poleplae.m % % Preparation for IE34 Lab 3: Pole plaement ontroller. % % E U GP % R -->Kr-->O--->/C(--->B(/A(----> Y % Htot(: -^ % % --------D(<------------ % % Proess transfer funtion GP has two time onstants Start the sript with a omment (%. That omment is printe when writing help poleplae in the Matlab omman winow goo pratie to show what the sript oes.
Matlab Sript for Lab 3 Prior to the lab, we assume that proess gain an time onstants have the following values: % Proess transfer funtion GP [m] % has two time onstants Kp 3 % Change proess gain if neee T6 % Change first time onstant if neee T % Change seon time onstant if neee s tf('s'; GP Kp / ( T*s / ( T*s [GpNum,GpDen]tfata(GP,'v' These values must be hange to atual proess values at the lab [V]
Assume values prior to lab. KP GP { KP 3 T 6 T } ( Ts( Ts s s s s ( 6 ( 6 7 3 3 3 Perform the system ientifiation at lab. Note! Use sript: [a,p]ap(q,n
Matlab Sript for Lab 3 It is ommon pratie to insert results from the omman winow as ommans in the sript! Kp 3 % Change proess gain if neee T 6 % Change first time onstant if neee T % Change seon time onstant if neee s tf('s'; GP Kp / ( T*s / ( T*s [GpNum,GpDen]tfata(GP,'v' % Default transfer funtion: % 3 % ------------------ % 6 s^ 7 s % GpNum 3 % GpDen 6 7
Matlab Sript for Lab 3 For pole plaement alulations, we nee the proess isretetime moel. Matlab an print the moel in positive ( n or negative ( -n form. % Disretie the proess isp('now isretiing' h.6; % sampling interval HP(GP,h; fprintf('\nhp Negative notation' HP.variable '^-' fprintf('\nhp Positive notation' HP.variable '' % Disrete transfer funtion: % HP Negative notation % Transfer funtion: %.47 ^-.3935 ^- % ----------------------------- % -.877 ^-.8794 ^- % Sampling time (seons:.6 % % HP Positive notation % Transfer funtion: %.47.3935 % ---------------------- % ^ -.877.8794 % Sampling time (seons:.6
Matlab Sript for Lab 3 We nee proess transfer funtion in negative form, split into enominator (A an numerator (B. % HPB/A [B,A]tfata(HP,'v' % HP Negative notation % Transfer funtion: %.47 ^-.3935 ^- % ----------------------------- % -.877 ^-.8794 ^- % B [.4.39] % A [. -.8767.8794]
Matlab Sript for Lab 3 A an B are both of seon egee an for now we use the following preliminary poles to reate the pole plaement polynomial:,7 ±,i an. % 3 poles suggestion: p.7.i; % Change if neee p.7-.i; % Change if neee p3; P ( AC ( ( BD ( ( % Prompt user for pole values % p input('first pole (abi: '; % p input('seon pole (a-bi: '; % isplay('thir pole at origo i'; % Poleplaement polynomial P poly([p,p,p3] % P [. -.4.53 ] When trying many ifferent pole values it might be onvenient to have the sript prompt the user!
Matlab Sript for Lab 3 Controller polynomials C an D: % Controller polynomials C an D % C _*^- % D *^- AC ( ( BD ( ( P ( Parameters oh _ are alulate by ientifiation of the ontroller polynomial s equivalent terms. This algebra an not be performe with Matlab (when the Maple moule is missing but may be one with paper an penil or with Mathematia. When the algebra is mae, Matlab an solve the equation system numerially. You must present the algebrai alulations at the lab!
Parameter names in Matlab % P [. -.4.53 ] [P(4 P(3 P( P(] P(4*^-3 P(4*^- P(4*^- P(4*^- % HPB/A [B,A]tfata(HP,'v' % B [.4.39] [B(3 B( B(] B(3*^- B(*^- B(*^- % A [. -.8767.8794] [A(3 A( A(] A(3*^- A(*^- A(*^- % Controller polynomials C an D % C [ _] _*^- % D [ ] *^- Ientify: AC ( ( BD ( ( P (
Matlab Sript for Lab 3 Desribe your algebrai alulations at the lab! This Matlab an solve left [ B( A( B(3 B( A(3 B(3 ]; right [P(-A(, P(3-A(3, P(4]' ; left \ right; _ ans(, _ ans(, _ ans(3 % _.48 % _ 63.7665 % _ -48.5 Now we have the parameters _ alulate!
Matlab Sript for Lab 3 K r P( B( % KrP(/B( Kr polyval(p, / polyval(b, % Kr 6.664 Now we have all the parameters!
Matlab Sript for Lab 3 % Controller bloks D [ ] D_blok tf( D,[ ],h; fprintf('\nblok D positive notation' D_blok.variable '' % D 63.7665-48.5 % % Blok D positive notation % Transfer funtion: % 63.77-48. % --------------- % % Sampling time (seons:.6
Matlab Sript for Lab 3 % Controller bloks C [ _] C_blok tf([ ],C,h ; fprintf('\nblok C positive notation' C_blok.variable '' % C..48 % % Blok C positive notation % Transfer funtion: % % ---------- %.48 % Sampling time (seons:.6
Matlab Sript for Lab 3 % Total transfer funtion % Kr*B Htot % Htot --------- % A*C B*D % Transfer funtion of ontrolle system: fprintf('\ntotal system, positive notation' Htot tf( Kr*B, onv(a,c onv(b,d,h ; Htot.variable '' Kr B ( AC ( ( BD ( ( % Transfer funtion: %.6639.636 % ----------------------------------- % ^3 -.4 ^.53.776e-7
Matlab Sript for Lab 3 Commans to plot system info. % Print system info. figure('name','step Response of Proess','numbertitle','off' step(gp % step response of proess opt stepdataoptions('stepamplitue',.5, 'InputOffset',.5; figure('name','step Response of Feebak Loop','numbertitle','off' step(htot, opt % step response of feebak loop figure('name','margins of Feebak Loop','numbertitle','off' margin(htot % Gain an phase margins of feebak loop [Y,T]step(Htot, opt; stepinfo(y,t,'settlingtimethreshol',.5
Matlab Sript for Lab 3 How o you hek that the sript is orret an that the poles are orretly plae? [P,Z]pmap(Htot % P %.7.i %.7-.i % Z -.958 Poles are as esire, the sript is orret!
Simulink Moel
Export transfer funtions to Simulink Simulink an simulate ontinuous-time an isrete-time systems together. For the proess it is onvenient to use the ontinuous-time moel. [GpNum,GpDen]tfata(GP,'v' GpNum an GpDen polynomials are importe in Simulink moel. William Sanqvist william@kth.se
Export transfer funtions to Simulink % Controller bloks D [ ] D_blok tf( D,[ ],h; fprintf('\nblok D positive notation' D_blok.variable '' % D 63.7665-48.5 % % Blok D positive notation % Transfer funtion: % 63.77-48. % --------------- % % Sampling time (seons:.6 D polynomial is importe in Simulink moel.
Export transfer funtions to Simulink C [ _] C_blok tf([ ],C,h ; fprintf('\nblok C positive notation' C_blok.variable '' % C..48 % % Blok C positive notation % Transfer funtion: % % ---------- %.48 % Sampling time (seons:.6 C polynomial is importe in Simulink moel.
Export transfer funtions to Simulink % KrP(/B( P( B( Kr polyval(p, / polyval(b, % Kr6.664 K r Kr value is importe in Simulink moel.
Plot Simulation Result in Matlab The following Matlab sript reates one figure for ontrol input an another for proess output. The plots are upate when a new simulation is mae. % stepplot.m % Plots output (y an ontrol input (u. figure('name','output, y','numbertitle','off' plot(t,y linkata on figure('name','control Input,u','numbertitle','off' stairs(t,u linkata on
Simulation Plots Simulation result when referene value is hange from.5v to 3V after 5s. Proess output y(k is ontinous, while ontrol input u(k is isrete.
Matlab sript for C-oe (Not part of the ourse. Matlab an write to a file! For example, the pole plaement ontroller an be printe as a C funtion, whih an be inlue when ompiling a C program. fifopen('pp.','w'; fprintf(fi,'float PolePlaeController(float r, float y\n'; fprintf(fi,'{\n'; fprintf(fi,' stati float pre_u ;\n'; fprintf(fi,' stati float pre_y ;\n'; fprintf(fi,' float e;\n'; fprintf(fi,' float u;\n\n'; fprintf(fi,' e %6.3f*r - %6.3f*y - %6.3f*pre_y;\n',Kr,_,_; fprintf(fi,' u e - %6.3f*pre_u;\n\n',_; fprintf(fi,' pre_u u;\n'; fprintf(fi, pre_y y;\n\n'; fprintf(fi,' return u;\n}\n'; flose(fi;
C-funtion (not part of the Course