Вы находитесь на странице: 1из 22

Using MATLAB and Simulink for Control System Simulation and Design

1/29/03

Outline
Overview (and review) of MATLAB and Simulink Using MATLAB and Simulink for dynamical system analysis and simulation, and control design Nonlinear vs. linear simulation and analysis Application to Pan-Tilt platform

Last Time
Equation of motion for dynamical systems:

"" + ( B + NB ) " = N + mg ! sin 1-link: ( I ! + N 2 I m ) m m c ! ! ! !


"" + B( ") + C ( , ") " + G ( ) = General: M ( )
As a control system, we may regard is the input, l is the output. Today, we will see how to use MATLAB and Simulink to simulate the response of the system for a given input trajectory.

MATLAB
A powerful package with built-in math functions, array and matrix manipulation capabilities, plotting and lots of add-on toolboxes (e.g., control, image processing, symbolic manipulation, block diagram programming, i.e., Simulink, etc.)

MATLAB
Vectors: theta=[theta_1;theta_2]; Matrices: M=[M11 M12; M21 M22]; Polynomials: p=[a3 a2 a1 a0]; Transfer functions: G=tf(num,den); Linear simulation: step response: step(G); impulse response: impulse(G); general response: y=lsim(G,u,t);

MATLAB (Cont.)
" = f (t , x) Solving ODE x [t,x]=ode23(func,[0 tf],xinit); f=func(t,x) Plotting: plot(t,x1,t,x2);xlabel(time (sec));ylabel(theta (deg)); title(theta(t)); legend(\theta_1,\theta_2); Printing (to printer or file) print -f -d<device type> <file name> Using m-files in MATLAB use any editor (or MATLAB built-in editor, just type in edit) function f=func(t,x) ... Getting help in MATLAB: help <function name> or just help
on-line tutorial: http://www.engin.umich.edu/group/ctm/

Application to Pan-Tilt Platform


pantilt.m gives the symbolic expression for M (2x2 mass matrix) C (2x1 coriolis/centrifugal torque) G (2x1 gravity vector) For numerical computation, take a look of pantiltmodel.m: set up I, p, m for the two bodies

M ( ) ")" coriolis.m calculates C ( ,


massmatrix.m calculates gravity.m G ( )

Simulation
Consider input as the motor torques (2x1) and output as the joint angles (link) (2x1). Simulation involves find the output response for a given input trajectory. You will use a high fidelity simulation to validate your design (including nonlinearity, friction, saturation, etc.). For your control design, you will need to use a linearized model.

pan-tilt dynamics

Linearization
Equation of motion is nonlinear (M, C, G are nonlinear functions of ). To facilitate control system design, ") = ( , 0) we first linearize about an operating point ( , d

Linearization: 1-D example


") = ( , 0) Taylor series expansion about ( , d and keep the linear term. Consider the 1-D example from last class:

"" + F sgn " + F " mgl sin = I c v g


sin = sin d + cos d ( d ) 0.5 sin d ( d ) 2 + #

Linearized system: "" + F " mgl cos = + mgl sin I v g d g d $% &% '
may be cancelled or treated as a disturbance

= ( d )

Linearization: General Mechanical Systems


G "" " ( d )( d ) = G ( d ) M ( d ) + D + ( cancelled or
G1 G 1 = G2 1 G1 2 G2 2
treated as disturbance

For pan-tilt platform, input is motor torque (2x1), output is (2x1).

linearized pan-tilt dynamics

Description of LTI Systems


Input/Output (differential equation) What does LTI mean?

Frequency Domain
state

State Space

Input

output

Description of LTI Systems


"" + D " + G ( )( ) = M ( d ) d d
Input/Output (differential equation)
x1 d x= = " x2

I 0 0 "= x x + 1 1 1 M M G M D 2 1 $%%%&%%%' $ & ' ( s ) = ( s M ( d ) + Ds + G ( d )) ( s ) A B $%%%% % &%%%%% ' G(s) y = [ I 0] x + 0 ( $ & '
C D

Frequency Domain

State Space

MATLAB Description of LTI


Each LTI is treated as an object with a variety of possible description: transfer function: tf(num,den) (numerator and denominator polynomials) pole/zero/gain: zpk(z,p,k) (zeros, poles, gain) state space: ss(A,B,C,D) (state space parameters)

Take a look of pantilt_init.m on the webpage

Open Loop Linear System Response


Impulse response: y=impulse(G) step response: y=step(G) general response: y=lsim(G,u,t) Bode plot: y=bode(G) poles/zeros/dampings pole(G),zero(G), damp(G) pole/zero plot: pzmap(G) gain/phase margin (robustness): margin(G)

Incorporation of Control
Interconnection of LTI systems:

+ -

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

Simulink
Instead of command line entries, it may be easier to use a block diagram programming tool: LTI block Take a look of pantiltlinear.mdl for linearized pan-tilt under PID control

Effect of Sampling
Most control systems these days are digital in nature so sampling is inherent (through A/D for sensor, which contains a sampler, and D/A for actuators, which contains a zero-order-hold). To analyze the effect of sampling, we can find the equivalent discrete time system: Gd = c2d(G,ts);%ts=sampling period (sec) Gd is also an LTI object and the commands for LTI may be applied.

Adding Sampling to Simulink Diagram


To add sampling to your continuous time simulation, just add a zero-order-hold block (in the discrete time system library) to the input, then set the sampling time.

Nonlinear System Simulation


G(s) may be replaced by a nonlinear block

What You Need to Do


! Turn your qualitative spec into more quantitative spec in terms of speed and precision, ability to reject disturbance, etc. ! Develop a Simulink diagram for your design iteration. Use the Simulink diagram on-line as a starting template. Add motor and gear parameters to the pan-tilt skeleton (generate composite m, I, p for each body). Use your design parameters for simulation. Desired input should be based on your spec. You need to tweak the controllers also (e.g., gravity compensation, removing the mass matrix coupling, tune gains for each axis, avoid saturation, etc.)

Today at 5pm, Next Tuesday, 2/4 (5pm), Next Wednesday 2/5 (5pm)
Work on your project proposal (include preliminary design using MATLAB/Simulink)

Next Wednesday, 2/5 (9am)


Components of control systems: amplifier, encoder, motor

Вам также может понравиться