Belajar Simulink
Belajar Simulink
Belajar Simulink
PHONE
FAX
508-647-7000 508-647-7001 The MathWorks, Inc. 24 Prime Park Way Natick, MA 01760-1500
http://www.mathworks.com
u
MAIL
INTERNET
ftp.mathworks.com comp.soft-sys.matlab
Web Anonymous FTP server Newsgroup Technical support Product enhancement suggestions Bug reports Documentation error reports Subscribing user registration Order status, license renewals, passcodes Sales, pricing, and general information
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Loading SIMULINK 1.3 Models . . . . . . . . . . . . . . . . . . . . . . . . . . Updating SIMULINK 1.3 Models . . . . . . . . . . . . . . . . . . . . . . . Loading Models Containing Reset Integrator Blocks . . . . . . . . Changes to the SIMULINK User Interface . . . . . . . . . . . . . . . . . Improved Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating a Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Starting SIMULINK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Model and Block Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Working with Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Changes to the Block Libraries . . . . . . . . . . . . . . . . . . . . . . . . . The Extras Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Demos Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Changes to Block Dialog Boxes . . . . . . . . . . . . . . . . . . . . . . . . . Block Callback Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Moving a Block Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Additional Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Working with Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Drawing Lines Between Blocks . . . . . . . . . . . . . . . . . . . . . . . . . Labeling Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Signal Label Propagation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Labeling Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Copying a Model to the PC Clipboard . . . . . . . . . . . . . . . . . . . . . . Running a Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Expanded Simulation Parameters Dialog Box . . . . . . . . . . . . . . . State-of-the-Art Integrators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Running a Simulation from the Command Line . . . . . . . . . . . . .
1 1 1 2 2 2 3 3 3 3 3 4 4 4 4 4 4 5 5 5 5 5 5 6 6 6 7
Using Masks to Customize Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Executing a Callback Routine when Opening a Masked Block . . 8
Conditionally Executed Subsystems . . . . . . . . . . . . . . . . . . . . . . . . 9 S-Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 SIMULINK Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Online Block Reference Browser . . . . . . . . . . . . . . . . . . . . . . . . . Revised Block Dialog Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Vectorization of Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . New, Enhanced, and Renamed Blocks . . . . . . . . . . . . . . . . . . . . Obsoleted Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11 11 11 11 12 17
Additional Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Algebraic Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Zero Crossing Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Model Construction Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Model File Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
ii
Contents
Introduction
Introduction
This document provides a brief description of many of the significant new features included in SIMULINK 2. The organization of the manual reflects the order of topics in Using SIMULINK.
where sys is the model name. For each out-of-date block, SIMULINK asks whether you want to update it.
Improved Documentation
Using SIMULINK has been completely rewritten and has been improved in many ways: The new manual combines the previous edition of the SIMULINK Users Guide and the SIMULINK Version 1.3 Release Notes into a single book. An expanded chapter on building models provides clearer and more complete instructions. A useful table of keyboard shortcuts offers a quick guide for more experienced users. Additional chapters and appendices provide information not previously available.
Creating a Model
Creating a Model
For more information about the features discussed in this section, see Chapter 3 of Using SIMULINK.
Starting SIMULINK
You can start SIMULINK 2 in these ways: Enter a model file name to display the block diagram for that model (the same way you did using SIMULINK 1.3). Enter simulink in the MATLAB command window to display the SIMULINK block library. Microsoft Windows and Macintosh users can click on the SIMULINK toolbar button to display the SIMULINK block library and get a new model window. The toolbar button looks like this:
Additional Colors
SIMULINK 2 provides more colors for the screen background and the block background and foreground. The new colors are light blue, dark green, orange, and gray.
Creating a Model
Labeling Signals
In SIMULINK 2, you can label signals to annotate your model. Signal labels can be located at either end or at the center of one or more line segments. Labels remain attached to lines as they are moved. Labels themselves can be copied or moved using drag-and-drop techniques.
Labeling Ports
SIMULINK 2 labels ports on Subsystem blocks using the Inport and Outport block names in the underlying subsystem.
Running a Simulation
SIMULINK 2 provides many improvements in this area. All features discussed in this section are described in detail in Chapter 4 of Using SIMULINK.
State-of-the-Art Integrators
SIMULINK 2 incorporates the set of integration algorithms developed for the MATLAB ODE suite. These solvers provide faster, more accurate simulation results. The ODE suite includes variable-order and fixed-step nonstiff and stiff solvers. Selecting the appropriate solver is easier with the improved Simulation Parameters dialog box. An important additional benefit of the new solvers is that it is no longer necessary, or even advisable, to adjust step size to get better granularity in the simulation results. The variable-step solvers automatically set step sizes to provide accurate results. Also, because SIMULINK 2 provides fixed-step solvers, it is no longer necessary to set minimum and maximum step sizes to the same value to force the use of a fixed-step solver.
Running a Simulation
This table indicates, for each integration method supported in SIMULINK 1.3, the corresponding solver provided in SIMULINK 2.
Table 1: SIMULINK 1.3 Integrators and SIMULINK 2 Solvers If you used this integrator in SIMULINK 1.3 linsim rk23 rk45 adams gear euler Consider using this solver in SIMULINK 2 ode45 (nonstiff) or ode15s (stiff) ode23 ode45 ode113 ode15s ode1
Triggered subsystem
Conditionally executed subsystems are useful in a variety of applications. For example, in the automotive industry, triggered subsystems can be used to model the dynamics of an internal combustion engine. In the aerospace industry, enabled subsystems can be used to model complex flight control laws, where different controllers are enabled during different flight regimes.
S-Functions
If you are writing C MEX-file S-functions and place an S-function in an enabled subsystem configured to reset its states, the mdlInitializeConditions function is called upon reset. To figure out if mdlInitializeConditions is called from a reset or at simulation start, use the ssIsFirstInitCond(S) macro. It is now possible to write variable step S-functions. An optional function,
mdlGetTimeOfNextVarHit, provides the time of the next hit for the S-Function
block. Otherwise, S-functions work as they did in SIMULINK 1.3. For more information about S-functions, see Chapter 8 of Using SIMULINK.
10
SIMULINK Blocks
SIMULINK Blocks
This section discusses new, revised, and obsoleted blocks. All blocks are described in Chapter 9 of Using SIMULINK.
Vectorization of Blocks
A vectorized block can accept a vector input signal or generate a vector output signal, or both. In SIMULINK 2, almost all blocks are vectorized. To find out whether a block is vectorized, consult the online Block Browser or check the reference page for the block in the manual. At the end of each block reference page a table provides information about block characteristics, including whether the block is vectorized.
11
Algebraic Constraint
The Algebraic Constraint block constrains the input signal f(z) to zero and outputs an algebraic state z. The block outputs the value necessary to produce a zero at the input. The output must affect the input through some feedback path. This enables you to specify algebraic equations for index 1 differential/ algebraic systems (DAEs).
Backlash
The Backlash block no longer has an Initial input parameter. The initial center of the deadband width is defined by the Initial output parameter.
Data Store Memory, Data Store Read, and Data Store Write
The Data Store Memory, Data Store Read, and Data Store Write blocks enable the model to write and read data to and from a memory region during a simulation.
Discrete-Time Integrator
The Discrete-Time Integrator block enables you to define limits on the integration, which provides the capabilities of the (obsoleted) Discrete-Time Limited Integrator. The block supports these integration methods: Forward Euler, Backward Euler, and Trapezoidal.
Display
The Display block shows the value of its input signal. You can control the display format and the frequency of the display. You can use the block as a floating Display to probe different signals during a simulation.
Elementary Math
The Elementary Math block performs numerous common mathematical functions. The block output is the result of applying the selected function to the input.
12
SIMULINK Blocks
Enable
The Enable block is used with conditionally executed subsystems. Adding an Enable block to a subsystem creates an enabled subsystem. Adding both an Enable and a Trigger block creates a triggered and enabled subsystem. For more information about conditionally executed subsystems, see page 9 of this book or Chapter 7 of Using SIMULINK.
Fcn
The rules of precedence for operations for the SIMULINK 1.3 Fcn block did not conform to the C language standard. The SIMULINK 2 Fcn block conforms to these standards.
Filter
The Filter block has been renamed Discrete Filter.
From
The From block, when used with a Goto block, provides a convenient way to pass a signal from one block to another without physically connecting the blocks.
Goto
The Goto block, when used with a From block, provides a convenient way to pass a signal from one block to another without physically connecting the blocks.
Ground
Connecting a Ground block to a blocks input port prevents SIMULINK from issuing a warning message about the blocks unconnected port. The block outputs a zero-valued signal.
Hit Crossing
A rewritten Hit Crossing block accurately enables you to detect when the input signal crosses a particular value.
13
IC
The IC block enables you to define an initial value for a signal. You can also use the IC block to provide an initial guess to the algebraic loop solver, described on page 18.
Inner Product
The Inner Product block has been renamed Dot Product.
Integrator
The revised Integrator block now combines features included in the now obsoleted Limited Integrator and Reset Integrator blocks. In addition, you can add a port on the block to output the state. Also, you can specify the absolute tolerance for the blocks state.
Memory
You can choose whether or not the Memory blocks sample time is inherited from its driving block. The block dialog box contains a check box labeled Inherit sample time. If the check box is selected, the block inherits its sample time from the driving block. If the box is not selected, the blocks sample time is continuous. All Memory blocks in existing models have a sample time of continuous, although the default for Memory blocks copied from the Nonlinear library have a sample time of inherited. For Memory blocks to work as they did in SIMULINK 1.3 (with continuous sample time), make sure the check box described above is not selected.
MinMax
The MinMax block detects either the minimum or maximum of its input signal(s).
Multiport Switch
The Multiport Switch block chooses a block input from among multiple inputs. An integer-valued control input determines which input to pass through to the output port.
14
SIMULINK Blocks
Note
The Note block has been removed. You can provide model annotations by creating an annotation, described in Chapter 3 of Using SIMULINK. SIMULINK automatically converts Note blocks to annotations in existing models.
Outport
The Outport block adds an option that, when used in a conditionally executed subsystem, allows the block to control whether its output is reset to an initial value or held at its most recent value while the subsystem is disabled.
Pulse Generator
The Pulse Generator block parameters have changed: The Pulse period parameter is now Period, the Pulse width parameter is now Duty cycle, the Pulse height parameter is now Amplitude, and the Pulse start time parameter is now Start time. You can use slupdate to replace old Pulse Generator blocks. slupdate converts the Pulse width parameter the Duty cycle parameter.
Ramp
The Ramp block provides a signal that starts at a specified time and value and changes by a specified rate.
Rate Limiter
The Rising slew rate and Falling slew rate parameters now accept values of inf and inf, respectively. These values pass the input through the block without applying limits.
Relay
The Relay block Input for on and Input for off parameters have been renamed to Switch on point and Switch off point.
Scope
An enhanced oscilloscope-like Scope block provides vastly improved graphical display of signals. The Scope block allows you to zoom in on the block input in the x (time) direction, y direction, or both directions; display all the input to the block; limit the data displayed; and save the signal data to the workspace at the end of simulation.
15
Selector
The Selector block acts like a patch panel for cross wiring of input vector elements. You enter a vector parameter that indicates the input vector elements that make up the block output.
Signal Generator
The Signal Generators dialog box has been rearranged to simplify choosing a wave form and defining signal parameters. The default frequency is now Hertz.
Step Fcn
The Step Fcn block has been renamed Step.
Terminator
Connecting a blocks output port to a Terminator block prevents SIMULINK from issuing warning messages about unconnected ports. The block does not process the signal.
To File
The To File block provides Decimation and Sample time parameters to limit the amount of data written to the file.
To Workspace
The To Workspace block provides Decimation and Sample time parameters to limit the amount of data written to the workspace variable.
Trigger
The Trigger block is used with conditionally executed subsystems. Adding a Trigger block to a subsystem creates a triggered subsystem. Adding both an Enable and a Trigger block creates a triggered and enabled subsystem. These special subsystems are described in Chapter 7 of Using SIMULINK.
16
SIMULINK Blocks
Width
The Width block generates as output the width of the input vector.
Obsoleted Blocks
Several blocks are no longer available. The functions they perform are included in other blocks: The Discrete-Time Limited Integrator block has been replaced by the Discrete-Time Integrator block. The Limited Integrator block has been replaced by the Integrator block. The Note block has been replaced by the model annotation feature. The Reset Integrator block has been replaced by the Integrator block. In addition, the renamed blocks: Filter, Inner Product, Step Fcn, and 2-D Look-Up Table, are no longer available.
17
Additional Topics
Algebraic Loops
The algebraic loop solver has been improved for SIMULINK 2 and is able to solve a larger class of algebraic loops. It can now attempt to solve algebraic loops that have multirate components, as well as loops containing blocks with nonsmooth outputs (such as the Abs, Saturation, or Quantizer blocks). Algebraic loops and the algebraic loop solver are described in Chapter 10 of Using SIMULINK.
18
returns a structure array of all the lines in the model named sys. The form of each structure in the array is: Handle is the handle to the line Name is the lines name Parent is the handle to the subsystem or block diagram owning the line SrcBlock is the handle to the source block driving the line SrcPort is the port number of the source block driving the line DstBlock is the handle to the block being driven by the line DstPort is the port number of the destination block Points is the array of points describing the line Branch is the structure array of any branch lines on this line
19
20