Using MATLAB and Simulink For

Embed Size (px)

Citation preview

  • 7/30/2019 Using MATLAB and Simulink For

    1/22

  • 7/30/2019 Using MATLAB and Simulink For

    2/22

    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

  • 7/30/2019 Using MATLAB and Simulink For

    3/22

    Last Time

    Equation of motion for dynamical systems:

    1-link:

    General:

    As a control system, we may regard is the input, lis

    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 c

    I N I B NB N mg + + + = +! ! ! ! !

    "" " !

    ( ) ( ) ( , ) ( )M B C G + + + ="" " " "

  • 7/30/2019 Using MATLAB and Simulink For

    4/22

    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.)

  • 7/30/2019 Using MATLAB and Simulink For

    5/22

    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);

  • 7/30/2019 Using MATLAB and Simulink For

    6/22

    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 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 or just help

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

    ( , )x f t x="

  • 7/30/2019 Using MATLAB and Simulink For

    7/22

  • 7/30/2019 Using MATLAB and Simulink For

    8/22

    Simulation

    Considerinput 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

  • 7/30/2019 Using MATLAB and Simulink For

    9/22

    Linearization

    Equation of motion is nonlinear (M, C, Gare nonlinear

    functions of). To facilitate control system design,

    we first linearize about an operating point( , ) ( ,0)d ="

  • 7/30/2019 Using MATLAB and Simulink For

    10/22

    Linearization: 1-D example

    Taylor series expansion about

    and keep the linear term. Consider the 1-D example

    from last class:

    #++= 2)(sin5.0)(cossinsinddddd

    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 ="

  • 7/30/2019 Using MATLAB and Simulink For

    11/22

    Linearization: General Mechanical Systems

    (

    cancelled or

    treated asdisturbance

    ( ) ( )( ) ( )d d d d G

    M D G

    + + =

    "" "

    1 1

    1 2

    2 2

    1 2

    G G

    G

    G G

    =

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

    linearized

    pan-tilt

    dynamics

  • 7/30/2019 Using MATLAB and Simulink For

    12/22

    Description of LTI Systems

    Input/Output

    (differentialequation)

    Frequency

    Domain State Space

    What does LTI mean?

    Input output

    state

  • 7/30/2019 Using MATLAB and Simulink For

    13/22

    Description of LTI Systems

    Input/Output(differentialequation)

    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

    dxxx

    = =

    "

  • 7/30/2019 Using MATLAB and Simulink For

    14/22

    MATLAB Description of LTI

    Each LTI is treated as an objectwith 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 ofpantilt_init.mon the webpage

  • 7/30/2019 Using MATLAB and Simulink For

    15/22

    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)

  • 7/30/2019 Using MATLAB and Simulink For

    16/22

    Incorporation of Control

    Interconnection of LTI systems:

    G

    H

    KFr

    -

    +

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

  • 7/30/2019 Using MATLAB and Simulink For

    17/22

    Simulink

    Instead of command line entries, it may be easier to use

    a block diagram programming tool:

    LTI block

    Take a look ofpantiltlinear.mdl for linearizedpan-tilt under PID control

  • 7/30/2019 Using MATLAB and Simulink For

    18/22

    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, whichcontains 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 maybe applied.

  • 7/30/2019 Using MATLAB and Simulink For

    19/22

    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.

  • 7/30/2019 Using MATLAB and Simulink For

    20/22

    Nonlinear System Simulation

    G(s) may be replaced by a nonlinear block

  • 7/30/2019 Using MATLAB and Simulink For

    21/22

    What You Need to Do

    !Turn your qualitative spec into more quantitative specin 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-tiltskeleton (generate composite m, I, pfor 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.)

  • 7/30/2019 Using MATLAB and Simulink For

    22/22

    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