05.08.2013 Views

Using MATLAB and Simulink for Control System Simulation and ...

Using MATLAB and Simulink for Control System Simulation and ...

Using MATLAB and Simulink for Control System Simulation and ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Using</strong> <strong>MATLAB</strong> <strong>and</strong> <strong>Simulink</strong> <strong>for</strong><br />

<strong>Control</strong> <strong>System</strong> <strong>Simulation</strong> <strong>and</strong> Design<br />

1/29/03


Outline<br />

• Overview (<strong>and</strong> review) of <strong>MATLAB</strong> <strong>and</strong> <strong>Simulink</strong><br />

• <strong>Using</strong> <strong>MATLAB</strong> <strong>and</strong> <strong>Simulink</strong> <strong>for</strong> dynamical system<br />

analysis <strong>and</strong> simulation, <strong>and</strong> control design<br />

• Nonlinear vs. linear simulation <strong>and</strong> analysis<br />

• Application to Pan-Tilt plat<strong>for</strong>m


Last Time<br />

Equation of motion <strong>for</strong> dynamical systems:<br />

1-link: ( I<br />

2<br />

+ N I ) "" + ( B + NB ) " = N + mg!<br />

sin<br />

General:<br />

θ θ τ θ<br />

! m ! ! m ! m c !<br />

M( θθ ) "" + B( θ" ) + C( θθθ , " ) "<br />

+ G(<br />

θ) = τ<br />

As a control system, we may regard ττττ is the input, θθθθ l is<br />

the output. Today, we will see how to use <strong>MATLAB</strong><br />

<strong>and</strong> <strong>Simulink</strong> to simulate the response of the system<br />

<strong>for</strong> a given input trajectory.


<strong>MATLAB</strong><br />

A powerful package with built-in math functions, array<br />

<strong>and</strong> matrix manipulation capabilities, plotting <strong>and</strong> lots<br />

of add-on toolboxes (e.g., control, image processing,<br />

symbolic manipulation, block diagram programming,<br />

i.e., <strong>Simulink</strong>, etc.)


<strong>MATLAB</strong><br />

• Vectors: theta=[theta_1;theta_2];<br />

• Matrices: M=[M11 M12; M21 M22];<br />

• Polynomials: p=[a3 a2 a1 a0];<br />

• Transfer functions: G=tf(num,den);<br />

• Linear simulation:<br />

• step response: step(G);<br />

• impulse response: impulse(G);<br />

• general response: y=lsim(G,u,t);


<strong>MATLAB</strong> (Cont.)<br />

• Solving ODE x" = f(, t x)<br />

[t,x]=ode23(‘func’,[0 tf],xinit); f=func(t,x)<br />

• Plotting: plot(t,x1,t,x2);xlabel(‘time (sec)’);ylabel(‘theta<br />

(deg)’); title(‘theta(t)’); legend(‘\theta_1’,’\theta_2’);<br />

• Printing (to printer or file)<br />

print -f -d <br />

• <strong>Using</strong> m-files in <strong>MATLAB</strong><br />

use any editor (or <strong>MATLAB</strong> built-in editor, just type in edit)<br />

function f=func(t,x) ...<br />

• Getting help in <strong>MATLAB</strong>: help or just help<br />

on-line tutorial: http://www.engin.umich.edu/group/ctm/


Application to Pan-Tilt Plat<strong>for</strong>m<br />

pantilt.m gives the symbolic expression <strong>for</strong><br />

M (2x2 mass matrix)<br />

C (2x1 coriolis/centrifugal torque)<br />

G (2x1 gravity vector)<br />

For numerical computation, take a look of<br />

pantiltmodel.m: set up I, p, m <strong>for</strong> the two bodies<br />

massmatrix.m calculates M ( θ<br />

)<br />

coriolis.m calculates C( θθθ , " ) "<br />

gravity.m<br />

G( θ )


<strong>Simulation</strong><br />

Consider input as the motor torques ττττ (2x1) <strong>and</strong> output as<br />

the joint angles (link) θθθθ (2x1). <strong>Simulation</strong> involves find the<br />

output response <strong>for</strong> a given input trajectory.<br />

You will use a high fidelity simulation to validate your design<br />

(including nonlinearity, friction, saturation, etc.). For your<br />

control design, you will need to use a linearized model.<br />

ττττ θθθθ<br />

pan-tilt<br />

dynamics


Linearization<br />

Equation of motion is nonlinear (M, C, G are nonlinear<br />

functions of θθθθ). To facilitate control system design,<br />

we first linearize about an operating point ( θθ , "<br />

) = ( θ,0)<br />

d


Linearization: 1-D example<br />

Taylor series expansion about ( θθ , "<br />

) = ( θd,0)<br />

<strong>and</strong> keep the linear term. Consider the 1-D example<br />

from last class:<br />

I"" θ + F sgnθ" + Fθ" − mgl sinθ<br />

= τ<br />

sinθ = sinθ<br />

d + cosθ<br />

d ( θ −θ<br />

d ) − 0.<br />

5sinθ<br />

d ( θ −θ<br />

d<br />

2<br />

)<br />

+ #<br />

Linearized system:<br />

I∆ "" θ + Fv∆θ" −mglg cosθd∆ θ = τ + mglgsinθd<br />

$%&%'<br />

∆ θ = ( θ −θ<br />

)<br />

c v g<br />

d<br />

may be cancelled or<br />

treated as a disturbance


Linearization: General Mechanical <strong>System</strong>s<br />

G<br />

M( θ ) "" ∂<br />

θ + Dθ" + ( θ )( θ − θ ) = τ − G(<br />

θ )<br />

d<br />

∂θ<br />

d d ( d<br />

cancelled or<br />

treated as<br />

disturbance<br />

⎡∂G1 ∂G1⎤<br />

⎢<br />

G θ1 θ ⎥<br />

∂ ∂ ∂ 2<br />

= ⎢ ⎥<br />

∂θ⎢∂G ∂G<br />

⎥<br />

2 2<br />

⎢<br />

θ1 θ<br />

⎥<br />

⎣∂ ∂ 2 ⎦<br />

For pan-tilt plat<strong>for</strong>m, input is motor torque ττττ (2x1), output<br />

is θθθθ (2x1).<br />

ττττ θθθθ<br />

linearized<br />

pan-tilt<br />

dynamics


Frequency<br />

Domain<br />

Description of LTI <strong>System</strong>s<br />

Input/Output<br />

(differential<br />

equation)<br />

state<br />

Input output<br />

What does LTI mean?<br />

State Space


Description of LTI <strong>System</strong>s<br />

Frequency<br />

Domain<br />

M( θ ) "" θ + Dθ" +∇ G(<br />

θ )( θ − θ ) = τ<br />

d θ d d<br />

Input/Output<br />

(differential<br />

equation)<br />

∆ θ = θ + +∇ θ τ<br />

$%%%%%&%%%%%'<br />

2 −1<br />

() s ( s M( d) Ds θG(<br />

d))<br />

() s<br />

G( s)<br />

State Space<br />

⎡ 0 I ⎤ ⎡ 0 ⎤<br />

x" = ⎢ x+<br />

τ<br />

−1 −1 −1<br />

−M ∇G −M<br />

D<br />

⎥ ⎢<br />

M<br />

⎥<br />

⎣$%%%&%%%' ⎦ $&' ⎣ ⎦<br />

[ 0] 0(<br />

y = I x+<br />

$&'<br />

C<br />

A B<br />

D<br />

x<br />

τ<br />

⎡x⎤ ⎡θ −θd⎤<br />

⎢ ⎥ ⎢<br />

θ"<br />

⎥<br />

⎣ ⎦ ⎣ ⎦<br />

1<br />

= =<br />

x2


<strong>MATLAB</strong> Description of LTI<br />

Each LTI is treated as an object with a variety of<br />

possible description:<br />

transfer function: tf(num,den) (numerator <strong>and</strong><br />

denominator polynomials)<br />

pole/zero/gain: zpk(z,p,k) (zeros, poles, gain)<br />

state space: ss(A,B,C,D) (state space parameters)<br />

Take a look of pantilt_init.m on the webpage


Open Loop Linear <strong>System</strong> Response<br />

Impulse response:<br />

y=impulse(G)<br />

step response:<br />

y=step(G)<br />

general response:<br />

y=lsim(G,u,t)<br />

Bode plot:<br />

y=bode(G)<br />

poles/zeros/dampings<br />

pole(G),zero(G), damp(G)<br />

pole/zero plot:<br />

pzmap(G)<br />

gain/phase margin<br />

(robustness):<br />

margin(G)


Incorporation of <strong>Control</strong><br />

Interconnection of LTI systems:<br />

F<br />

+<br />

-<br />

K<br />

ττττ θθθθ<br />

G<br />

H<br />

Gcl = feedback(G*K,H)*F


<strong>Simulink</strong><br />

Instead of comm<strong>and</strong> line entries, it may be easier to use<br />

a block diagram programming tool:<br />

LTI block<br />

Take a look of pantiltlinear.mdl <strong>for</strong> linearized<br />

pan-tilt under PID control


Effect of Sampling<br />

Most control systems these days are digital in nature so<br />

sampling is inherent (through A/D <strong>for</strong> sensor, which<br />

contains a sampler, <strong>and</strong> D/A <strong>for</strong> actuators, which<br />

contains a zero-order-hold).<br />

To analyze the effect of sampling, we can find the<br />

equivalent discrete time system:<br />

Gd = c2d(G,ts);%ts=sampling period (sec)<br />

Gd is also an LTI object <strong>and</strong> the comm<strong>and</strong>s <strong>for</strong> LTI may<br />

be applied.


Adding Sampling to <strong>Simulink</strong> Diagram<br />

To add sampling to your continuous time simulation,<br />

just add a zero-order-hold block (in the discrete time<br />

system library) to the input, then set the sampling time.


Nonlinear <strong>System</strong> <strong>Simulation</strong><br />

G(s) may be replaced by a nonlinear block


What You Need to Do<br />

Turn your qualitative spec into more quantitative spec<br />

in terms of speed <strong>and</strong> precision, ability to reject<br />

disturbance, etc.<br />

Develop a <strong>Simulink</strong> diagram <strong>for</strong> your design iteration.<br />

• Use the <strong>Simulink</strong> diagram on-line as a starting<br />

template.<br />

• Add motor <strong>and</strong> gear parameters to the pan-tilt<br />

skeleton (generate composite m, I, p <strong>for</strong> each body).<br />

• Use your design parameters <strong>for</strong> simulation.<br />

• Desired input should be based on your spec.<br />

• You need to tweak the controllers also (e.g., gravity<br />

compensation, removing the mass matrix coupling,<br />

tune gains <strong>for</strong> each axis, avoid saturation, etc.)


Today at 5pm, Next Tuesday, 2/4 (5pm),<br />

Next Wednesday 2/5 (5pm)<br />

• Work on your project proposal (include preliminary<br />

design using <strong>MATLAB</strong>/<strong>Simulink</strong>)<br />

Next Wednesday, 2/5 (9am)<br />

• Components of control systems: amplifier, encoder,<br />

motor

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!