using matlab and simulink for control system...
TRANSCRIPT
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:
1-link:
General:
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.
2( ) ( ) sinm m m cI N I B NB N mgθ θ τ θ+ + + = +! ! ! ! !"" " !
( ) ( ) ( , ) ( )M B C Gθ θ θ θ θ θ θ τ+ + + ="" " " "
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.)
• Solving ODE [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 MATLABuse 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/
( , )x f t x="
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 ofpantiltmodel.m: set up I, p, m for the two bodies
massmatrix.m calculates
coriolis.m calculates gravity.m
( , )C θ θ θ" "
( )G θ
( )M θ
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, we first linearize about an operating point ( , ) ( ,0)dθ θ θ="
Linearization: 1-D exampleTaylor series expansion about and keep the linear term. Consider the 1-D example
from last class:
#+−−−+= 2)(sin5.0)(cossinsin ddddd θθθθθθθθ
may be cancelled ortreated as a disturbance
Linearized system:cos sin
( )
v g d g d
d
I F mgl mglθ θ θ θ τ θ
θ θ θ
∆ + ∆ − ∆ = +
∆ = −
"" "$%&%'
sgn sinc v gI F F mglθ θ θ θ τ+ + − ="" " "
( , ) ( ,0)dθ θ θ="
Linearization: General Mechanical Systems
(cancelled ortreated as disturbance
( ) ( )( ) ( )d d d dGM D Gθ θ θ θ θ θ τ θθ
∂+ + − = −∂
"" "
1 1
1 2
2 2
1 2
G GG
G Gθ θ
θθ θ
∂ ∂ ∂ ∂∂ =∂ ∂∂
∂ ∂
For pan-tilt platform, input is motor torque ττττ (2x1), output is θθθθ (2x1).
ττττ θθθθlinearizedpan-tilt
dynamics
Description of LTI Systems
Input/Output (differential equation)
Frequency Domain State Space
What does LTI mean?
Input output
state
Description of LTI Systems
Input/Output (differential equation)
Frequency Domain State Space
( ) ( )( )d d dM D Gθθ θ θ θ θ θ τ+ + ∇ − ="" "
2 1
( )
( ) ( ( ) ( )) ( )d d
G s
s s M Ds G sθθ θ θ τ−∆ = + + ∇$%%%%%&%%%%%'[ ] (
1 1 1
0 0
0 0A B
DC
Ix x
M G M D M
y I x
τ
τ
− − −
= + − ∇ −
= +
"$%%%&%%%' $&'
$&'
1
2
dxx
xθ θ
θ−
= = "
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:
ττττ θθθθG
H
KFr
-
+
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