Simulink_intro1

Embed Size (px)

Citation preview

  • 8/13/2019 Simulink_intro1

    1/12

  • 8/13/2019 Simulink_intro1

    2/12

    Example !n"estigating the e##ect o# saturation

    Fig..$.Nonlinear system #ith saturation

    Fig. %a The effect of saturation on theoutput signal Fig. %& The control signal #ith saturationat S!$ and S!"%%

    Fig. $. gives an overvie# on the effect of the saturation. This model sho#s thesaturating characteristics of the physically reali/able controllers. The input signal is aunit step starting at t!". If the controller saturates at $& so the output signal #ill reactslo#er because of the limited control signal *Fig. %a and %&,. 0e can make the modelmore compact by grouping the parts of the controller into one subsystem *Fig. '.,. 0ecan do this by selecting the components #ith mouse and grouping them #ith the groupcommand from the optionsmenu.

    Fig. '.

    1

  • 8/13/2019 Simulink_intro1

    3/12

    3. Levels of use

    There are three different #ays to use SIMULINK& the most interactive #ay is tocontrol the simulation from the menu bar& and to vie# the behavior of the system #iththe Scopes or 2raphs. This method is simple to use& 3uick to learn& and can providefast results.

    The second #ay is to use the builtin simulation and analysis function from thecommand line. This method is not as interactive as the first method but providesgreater fle+ibility. 2etting the results of simulation into the M)TL)( #orkspaceallo#s further analysis and data visuali/ation using M)TL)(4s builtin graphics tools.

    The most comple+ and fle+ible #ay to use SIMULINK is to access a model4s Sfunction directly. 5very SIMULINK model is available in M)TL)( as an Sfunctionthat embodies the dynamical behavior of the system.

    Simulation of SIMULINK models involves the numerical integration of sets of

    ordinary differential e3uations. SIMULINK provides a number of integrationalgorithms for the simulation of such e3uations. The appropriate choice of method andthe careful selection of simulation parameters are important considerations forobtaining accurate results. ) simulation can be started from either the command line orthe simulation menu. )ll of the methods use the same arguments and menu parameters.

    Simulation #rom the (enu

    ) simulation can be run by selecting Start from the Simulation menu. Set the

    simulation parameters in the control panel dialog bo+& #hich is displayedby selectingParameters from the Simulationmenu. The 6ontrol 7anel dialog bo+ has fields in#hich you can enter numbers or any legal M)TL)( e+pression& for e+ample& thevariables tstart, t#inal, minstep, maxstep, and #inal #hich can be defined in theM)TL)( #orkspace. The return variables 8t&+&y9 are used to put the time& state& andoutput tra:ectories into M)TL)( #orkspace. The start and stop times for thesimulation are set in variables tstart and t#inal. The integration parameters #inal,minstepand maxstepcontrol the relative local error& minimum step si/e& and ma+imumstep si/e of the simulation. 6ertain operations can be performed interactively duringthe simulation. ;or e+ample the parameters of a block can be changed provided thisdoes not cause a change in the number of states& inputs or outputs of that block< any of

    the simulation parameters can be changed & e+cept return variables and the start time

  • 8/13/2019 Simulink_intro1

    4/12

    Simulation #rom the )ommand Line

    )ny simulation run from the menu can also be run from the M)TL)( command line.;or e+ample

    8t&+&y9!linsim*?model?&8tstart&tfinal9&+%&8final&minstep&ma+step9,& rk$& adams or gear respectively,.

    *ie+ing output traectories

    The output tra:ectories from SIMULINK can be plotted by Scope or 2raph blocks& orby return variables and the M)TL)( plotting commands& or by To 0orkspace blocksand M)TL)( plotting commands.

    4. Changing parameters of SIMULINK blocs from M!"L!#

    @setAparamB is used to set SIMULINK block parameters from the M)TL)(command line. Its synta+ is

    setAparam*name& parameter& value,or setAparam*name& parameter& value&parameter1&value1C,

    Specific block parameters vary #ith each type of block. The names and effects of eachblock4s specific parameters can be found in the entry for that block.

    Example -

    The Simulink block diagram of a control system is sho# in Fig .1. The system saved#ith the name Ddtime4.

  • 8/13/2019 Simulink_intro1

    5/12

    Fig.1.Simulink blockdiagram of Ddtime4 system

    Follo+ing (/0L/ program sho+s ho+ to change the controller denominator #romthe (/0L/ +indo+2

    for i=4:2:10den=[i 0];%we set the controllers integrating time constant%to different values (14s!!!110s"

    set#$aram(dtimecontroller&'enominator&den";%sets dtime sstem& controller $art& 'enominator value to den[t&)&]=r*2+(dtime&,0";%,0 sec simulation for each denominator valueau)=)(:&2";%2ndcolumn of ) gives the out$ut signal$lot(t&au)"&gridhold onshg$ause

    end

    Fig.11.

    $

  • 8/13/2019 Simulink_intro1

    6/12

    Example 4)hanging the gain and the damping #actor in a second order s3stem

    Fig. 1. Simulink diagram of a second order system

    The gain and the damping factor of the second order system sho#n in Fig.1. changes.The program changes te gain to "& 1 and > respectively #hile thedamping factor is %.1 and plots the output signals in the samediagram*Fig. 1-.,

    The system is stable& but an oscillating transient is present in the outputs due to thesmall value of the damping factor. If #e increase the damping factor&the output signal becomes aperiodic. The second part of theM)TL)( program sho#s the output signal at different values of thedamping factor*Fig. 14.,.

    for i=1:+-=i;set#$aram(set$ar-ain&-ain&-";set#$aram(set$ar.ransfer /cn&'enominator&[1 0!4 1]";% hange the gain

    [t&)]=linsim(set$ar&+0";% ntegration algorithm for simulation& final time=+0=)(:&2";% .he out$ut is the second state variale

    for 3=1:(length(t""(3&i"=(3";end

    end$lot(t&&w"&grid$ause

    % hange the dam$ing factor

    -=1;[t1&)]=linsim(set$ar&+0";1=)(:&2";set#$aram(set$ar.ransfer /cn&'enominator&[1 4 1]";[t2&)]=linsim(set$ar&+0";2=)(:&2";$lot(t1&1&w&t2&2&w"&grid

    E

  • 8/13/2019 Simulink_intro1

    7/12

    Fig. 1-. 6hanging the gain Fig. 14. 6hanging the damping factor

    $. S%functions

    0hen creating a SIMULINK model in a graphical #ay& a ne# function& called Sfunction becomes available in M)TL)( #ith synta+

    s&s'mo(el)t*+*u*flag,or-s&s*+*str*ts/'mo(el)t*+*u*flag*parameter0*parameter1*2,

    Mo(elis the name of the function. lagcontrols the type of information returned in

    variable s&s at operating point defined by the time t& state vector +and input vector u.ts means the sampling time& strmakes possible evaluating a string& parameters areoptional.

    The flag options are-

    flag!% Sfunction returns si/es of parameters and initial conditions assys*", number of continuous states&sys*1, number of discrete states&sys*>, number of outputs&sys*, number of inputs&

    sys*$, number of discontinuous roots&sys*E, flag for direct feedthrough *used for findingalgebraic loops,

    sys*F, is " for sampled systems.flag!1 Sfunction returns the discrete state +*nG",.flag!> Sfunction returns the output vector y.flag! Sfunction returns the ne+t time interval for a discrete update.

    SIMULINK figures out the flag options from the diagram.

    0riting a M)TL)( mfile #ith the synta+ above and converting it to a SIMULINKblock our file could be used as any other blocks in the SIMULINK libraries. So #e

    F

  • 8/13/2019 Simulink_intro1

    8/12

    can build up our o#n user sublibrary.

    6 or ;H'T')N subroutines #ritten in given format can also be converted toSIMULINK blocks.

    $.0 +ample for 5riting an S%function an( converting it to a SIMULINK bloc

    Let?s #rite a discrete 7I algorithm reali/ing the follo#ing pulse transfer functionbet#een the control signal and the error signal-

    ",*

    ,*,* ""

    ==

    4

    44k

    4u

    4"45

    or by the difference e3uation

    v*nh,!ku*nh,k/"u**n",h,Gv**n",h,

    #here h denotes the sampling time and n is the actual time sample.

    $.0.0 6riting the S%function

    The M)TL)( mfunction can be #ritten by any te+t processor& e.g. by Notepad.The function pialg1#ith parameters and 70is the follo#ing-

    function -s&s*+*str*ts/'pialg1)t*+*u*flag**70*(t*vmin*vma+,Jdiscrete 7I algorithmJv*nh,!ku*nh,k/"u**n",h,Gv**n",h,

    J dt sampling time& the same as h.if abs*flag,!!1

    sys*",!k*"/",uG+*",

    v!kuG+*",