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

# Example 1 Fig.4. illustrates the SIMULINK diagram of a continuous control system.

The blocks have been dragged from the Sources, Linear, Nonlinear and Sinks libraries respectively. The input signal is a unit step starting at t!". The simulation time #as \$%& the simulation step %.". 'unge Kutta integration algorithm #as chosen from the Simulation menu. Fig. 5. and 6. sho#s the course of the output signals as displayed in the Graph #indo#s. (oth of the output signals transported to M)TL)( #orkspaces can also be plotted by M)TL)( plot*t&+", and plot*t&y, command. It is seen& that the y output signal tracks the reference input signal #ithout steady state error due to its integrating characteristics. The dead time causes the \$ seconds delay bet#een the changing of the output and the input signal. The +" control signal on the plot sho#s an overshoot& #hich has a ma+imum value of ".\$. The minimum and ma+imum value of the output signal can be determined by matlab- min*y,!%& ma+*y,!".%.".

"

## Fig. %a The effect of saturation on the output signal

Fig. %& The control signal #ith saturation at S!\$ and S!"%%

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

Fig. '.

3. Levels of use There are three different #ays to use SIMULINK& the most interactive #ay is to control the simulation from the menu bar& and to vie# the behavior of the system #ith the Scopes or 2raphs. This method is simple to use& 3uick to learn& and can provide fast results. The second #ay is to use the built in simulation and analysis function from the command line. This method is not as interactive as the first method but provides greater fle+ibility. 2etting the results of simulation into the M)TL)( #orkspace allo#s further analysis and data visuali/ation using M)TL)(4s built in graphics tools. The most comple+ and fle+ible #ay to use SIMULINK is to access a model4s S function directly. 5very SIMULINK model is available in M)TL)( as an S function that 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 integration algorithms for the simulation of such e3uations. The appropriate choice of method and the careful selection of simulation parameters are important considerations for obtaining accurate results. ) simulation can be started from either the command line or the 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 displayed by selecting Parameters from the Simulation menu. The 6ontrol 7anel dialog bo+ has fields in #hich you can enter numbers or any legal M)TL)( e+pression& for e+ample& the variables tstart, t#inal, minstep, maxstep, and #inal #hich can be defined in the M)TL)( #orkspace. The return variables 8t&+&y9 are used to put the time& state& and output tra:ectories into M)TL)( #orkspace. The start and stop times for the simulation are set in variables tstart and t#inal. The integration parameters #inal, minstep and maxstep control the relative local error& minimum step si/e& and ma+imum step si/e of the simulation. 6ertain operations can be performed interactively during the simulation. ;or e+ample the parameters of a block can be changed provided this does 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< the simulation algorithm can be changed< for discrete blocks you can change the sampling time. =ou can click on a line to see its output on a floating scope. )n unconnected scope is called a floating scope.

>

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,< #here model is the name of the block diagram system. Initial conditions are defined in the vector +%. These conditions override the initial conditions set in the blocks. Specifying no lefthand arguments automatically plots the outputs or the state tra:ectories. ) simulation can be run from an m file allo#ing parameters in the blocks to be iteratively changed. )ll of the integration algorithms have identical calling synta+ *e.g. instead of linsim euler& rk1>& rk.\$& adams or gear respectively,. *ie+ing output tra,ectories The output tra:ectories from SIMULINK can be plotted by Scope or 2raph blocks& or by return variables and the M)TL)( plotting commands& or by To 0orkspace blocks and M)TL)( plotting commands. 4. Changing parameters of SIMULINK bloc s from M!"L!# @setAparamB is used to set SIMULINK block parameters from the M)TL)( command line. Its synta+ is or setAparam*name& parameter& value, setAparam*name& parameter& value&parameter1&value1C,

Specific block parameters vary #ith each type of block. The names and effects of each block4s 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.

Fig.1.. Simulink block diagram of Ddtime4 system Follo+ing (/0L/1 program sho+s ho+ to change the controller denominator #rom the (/0L/1 +indo+2
for i=4:2:10 den=[i 0]; %we set the controllers integrating time constant %to different values (1 4s!!!1 10s" set#\$aram(%dtime controller%&%'enominator%&%den%"; %sets dtime s(stem& controller \$art& 'enominator value to den [t&)&(]=r*2+(%dtime%&,0"; %,0 sec simulation for each denominator value (au)=)(:&2"; %2nd column of ) gives the out\$ut signal \$lot(t&(au)"&grid hold on shg \$ause end

Fig.11.

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 the damping factor is %.1 and plots the output signals in the same diagram*Fig. 1-., The system is stable& but an oscillating transient is present in the outputs due to the small value of the damping factor. If #e increase the damping factor& the output signal becomes aperiodic. The second part of the M)TL)( program sho#s the output signal at different values of the damping factor*Fig. 14.,.
for i=1:+ -=i; set#\$aram(%set\$ar -ain%&%-ain%&%-%"; set#\$aram(%set\$ar .ransfer /cn%&%'enominator%&%[1 0!4 1]%"; % 0hange the gain [t&)]=linsim(%set\$ar%&+0"; % 1ntegration algorithm for simulation& final time=+0 (=)(:&2"; % .he out\$ut is the second state varia2le for 3=1:(length(t"" (((3&i"=((3"; end end \$lot(t&((&%w%"&grid \$ause % 0hange 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

## Fig. 14. 6hanging the damping factor

\$. S%functions 0hen creating a SIMULINK model in a graphical #ay& a ne# function& called S function 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(el is the name of the function. 3lag controls 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& str makes possible evaluating a string& parameters are optional. The flag options areflag!% S function returns si/es of parameters and initial conditions as sys*", 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 finding algebraic loops, sys*F, is " for sampled systems. S function returns the discrete state +*nG",. S function returns the output vector y. S function returns the ne+t time interval for a discrete update.

## SIMULINK figures out the flag options from the diagram.

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

can build up our o#n user sub library. 6 or ;H'T')N subroutines #ritten in given format can also be converted to SIMULINK blocks. \$.0 4+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 function bet#een the control signal and the error signal5 * 4 " , = 4 4" "* 4 , =k u* 4, 4 "

or by the difference e3uation v*nh,!kIu*nh, kI/"Iu**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)( m function can be #ritten by any te+t processor& e.g. by Notepad. The function pialg1 #ith parameters and 70 is the follo#ingfunction -s&s*+.*str*ts/'pialg1)t*+*u*flag* *70*(t*vmin*vma+, Jdiscrete 7I algorithm Jv*nh,!kIu*nh, kI/"Iu**n ",h,Gv**n ",h, J dt sampling time& the same as h. if abs*flag,!!1 sys*",!kI*" /",IuG+*",< elseif flag!!> v!kIuG+*",< if vKvma+ v!vma+< elseif vLvmin v!vmin< else v!v< end sys*",!v< Joutput signal elseif flag!!. sys*",!tGdt< t!sys*",< elseif flag!!% sys*",!%< Jnumber of continuous states sys*1,!"< Jnumber of discrete states sys*>,!"< Jnumber of outputs sys*.,!"< Jnumber of inputs sys*\$,!%< sys*E,!%< sys*F,!"< +*",!%< ts!8dt&%9<
M

else sys!89< end \$.0.1 Converting the S%function to a SIMULINK bloc Hpen a ne# SIMULINK file from the SIMULINK #indo#. (ring here the S function block from the Nonlinear sub library& and open it giving the name of the function *pialg, and the parameters& separated by comma& as

## Fig. 15. 6arametri4ation o# the S7#unction

Fig. 16. Masking the 7I controller block Then save the block in your o#n sub library made available for M)TL)( adding it to matlabpath in file matlabrc.m . Then the block can be dragged in a SIMULINK diagram& as e.g. creating a simulation environment sho#n in Fig. 1\$.

## Fig.1\$. Using the block in SIMULINK environment

"%

(y double clicking to our 7I block #e can give its parameters. ;or e+ample k!" and /"!%.\$. The output signal of the controller is sho#n in Fig. 1%.

Fig. 1%. Step response of the 7I controller The 7I controller can be built in a control loop as sho#n in Fig. 1'.

Fig. 1'. 6ontrol loop #ith the 7I controller 0ith k!%.. and /"!%.\$ the output signal is sho#n in Fig. .. It has to be mentioned that calculations start in the first sample.

Fig. .. Step response of the discrete control loop Fig. 1. sho#s a hybrid control circuit #hen a continuous plant given by its transfer function is controlled by the discrete 7I controller. In this case it is not necessary to put a /ero order hold element bet#een the controller and the plant as SIMULINK recogni/es this situation and keeps the control signal during the sampling time. The simulation step may be less then the control step defined in S function pialg.
""

Fig.

## . 6ontrol and output signals in the hybrid control circuit

Fig. . illustrates the output and the control signal for k!%.M and /"!%.\$. The control step #as " sec #hile the simulation step #as %.".

"1