using matlab and simulink for control system...
TRANSCRIPT
![Page 1: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/1.jpg)
Using MATLAB and Simulink for Control System Simulation and Design
1/29/03
![Page 2: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/2.jpg)
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
![Page 3: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/3.jpg)
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θ θ θ θ θ θ θ τ+ + + ="" " " "
![Page 4: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/4.jpg)
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.)
![Page 5: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/5.jpg)
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);
![Page 6: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/6.jpg)
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="
![Page 7: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/7.jpg)
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 θ
![Page 8: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/8.jpg)
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
![Page 9: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/9.jpg)
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θ θ θ="
![Page 10: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/10.jpg)
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θ θ θ="
![Page 11: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/11.jpg)
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
![Page 12: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/12.jpg)
Description of LTI Systems
Input/Output (differential equation)
Frequency Domain State Space
What does LTI mean?
Input output
state
![Page 13: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/13.jpg)
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θ θ
θ−
= = "
![Page 14: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/14.jpg)
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
![Page 15: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/15.jpg)
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)
![Page 16: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/16.jpg)
Incorporation of Control
Interconnection of LTI systems:
ττττ θθθθG
H
KFr
-
+
Gcl = feedback(G*K,H)*F
![Page 17: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/17.jpg)
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
![Page 18: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/18.jpg)
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.
![Page 19: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/19.jpg)
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.
![Page 20: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/20.jpg)
Nonlinear System Simulation
G(s) may be replaced by a nonlinear block
![Page 21: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/21.jpg)
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.)
![Page 22: Using MATLAB and Simulink for Control System …cats-fs.rpi.edu/~wenj/ECSE4962S03/session03_012903.pdfUsing MATLAB and Simulink for Control System Simulation and Design 1/29/03 Outline](https://reader033.vdocuments.site/reader033/viewer/2022051106/5ae066187f8b9a1c248d238c/html5/thumbnails/22.jpg)
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