024 - MathWorks Automotive Advisory Board Control Algorithm
024 - MathWorks Automotive Advisory Board Control Algorithm
R2012a
How to Contact MathWorks
www.mathworks.com Web
comp.soft-sys.matlab Newsgroup
www.mathworks.com/contact_TS.html Technical Support
508-647-7000 (Phone)
508-647-7001 (Fax)
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
March 2009 Online only New for Version 2.0 (Release 2009a)
September 2009 Online only Revised for Version 2.1 (Release 2009b)
March 2010 Online only Rereleased for Version 2.1 (Release 2010a)
September 2010 Online only Rereleased for Version 2.1 (Release 2010b)
April 2011 Online only Rereleased for Version 2.1 (Release 2011a)
September 2011 Online only Rereleased for Version 2.1 (Release 2011b)
March 2012 Online only Rereleased for Version 2.2 (Release 2012a)
Contents
Introduction
1
Presentation of Guidelines Hosted by MathWorks . . . . 1-2
Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
Naming Conventions
2
General Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
v
Model Architecture
3
Simulink and Stateflow Partitioning . . . . . . . . . . . . . . . . 3-2
Simulink
5
Diagram Appearance .............................. 5-2
vi Contents
Stateflow
6
Chart Appearance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2
Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-42
Guideline Writing
B
Flowchart Reference
C
vii
Signals and Signal Labels . . . . . . . . . . . . . . . . . . . . . . . . . . D-3
MAAB Glossary
viii Contents
1
Introduction
1-2
Motivation
Motivation
The MathWorks Automotive Advisory Board (MAAB) guidelines are
important for project success and teamwork—both in-house and when
cooperating with partners or subcontractors. Observing the guidelines is one
key prerequisite to achieving:
1-3
1 Introduction
Version 2.2 of the MAAB Style Guide does not provide guidelines for the
use of Model or MATLAB Function blocks (formerly referred to as Model
Reference and Embedded MATLAB blocks, respectively). However, several
of the updated guidelines provide information for using Model or MATLAB
blocks, if internal company guidelines support their use.
Future versions of the MAAB guidelines will address the use of Model and
MATLAB Function blocks.
1-4
Guideline Template
Guideline Template
In this section...
“Guideline ID” on page 1-6
“Guideline Title” on page 1-6
“Priority” on page 1-7
“Scope” on page 1-8
“MATLAB Versions” on page 1-9
“Prerequisites” on page 1-9
“Description” on page 1-9
“Rationale” on page 1-10
“Last Change” on page 1-11
“Model Advisor Check” on page 1-11
1-5
1 Introduction
Note The elements of this template are the minimum required items for
understanding and exchanging guidelines. You can add project or vendor
fields to this template as long as their meaning does not overlap with existing
fields. Such additions are encouraged if they help to integrate other guideline
templates and lead to a wider acceptance of the core template.
Guideline ID
• The guideline ID is built out of two lowercase letters (representing the
origin of the rule) and a four-digit number, separated by an underscore.
• Once a new guideline has an ID, the ID does not change.
• The ID is used for references to guidelines.
• The two letter prefixes na, jp, jc and eu are reserved for future MAAB
committee rules.
• Legacy prefixes, db, jm, hd, and ar, are reserved. The MAAB committee
will not use these prefixes for new rules.
• No new rules are to be written with these legacy prefixes.
Guideline Title
• The title should be a short, but unique description of the guidelines area of
application (for example, length of names)
• The title is used for the Prerequisites field and for custom checker tools.
• The title text should appear with a hyperlink that links to the guideline.
1-6
Guideline Template
Note The title should not be a redundant short description of the guidelines
content, because while the latter may change over time, the title should
remain stable.
Priority
Each guideline must be rated with one of the following priorities:
• Mandatory
• Strongly recommended
• Recommended
The priority describes the importance of the guideline and determines the
consequences of violations.
1-7
1 Introduction
Scope
The scope of a guideline may be set to one of the following:
Scope Description
MAAB (MathWorks Automotive A group of automotive manufacturers
Advisory Board) and suppliers that work closely
together with MathWorks®. MAAB
includes the subgroups J-MAAB and
NA-MAAB.
J-MAAB (Japan MAAB) A subgroup of MAAB that includes
automotive manufacturers and
suppliers in Japan and works
closely with MathWorks. Rules with
J-MAAB scope are local to Japan.
NA-MAAB (North American MAAB) A subgroup of MAAB that includes
automotive manufacturers and
suppliers in the United States and
Europe and works closely with
MathWorks. Rules with NA-MAAB
scope are local to the United States
and Europe.
1-8
Guideline Template
MATLAB Versions
The guidelines support all versions of the MATLAB and Simulink products. If
the rule applies to specific versions, the versions are identified in the MATLAB
versions field. The version information is in one of the following formats.
Format Definition
All All versions of MATLAB
Prerequisites
• The Prerequisite field is for links to other guidelines that are prerequisites
for this guideline (logical conjunction).
• Use the guideline ID (for consistency) and the title (for readability) for
the links.
• The Prerequisites field should not contain any other text.
Description
• This field contains a detailed description of the guideline.
• If needed, add images and tables.
1-9
1 Introduction
Rationale
This field lists the reasons that apply for a given guideline. You can
recommend guidelines for one or more of the following reasons:
Rationale Description
Readability Easily understood algorithms
• Readable models
• Uniform appearance of models, code, and
documentation
• Clean interfaces
• Professional documentation
Workflow Effective development process and workflow
• Ease of maintenance
• Rapid model changes
• Reusable components
• Problem-free exchange of models
• Model portability
Simulation Efficient simulation and analysis
• Simulation speed
• Simulation memory
• Model instrumentation
Verification and Ability to verify and validate a model and generated
validation code with:
• Requirements traceability
• Testing
• Problem-free system integration
• Clean interfaces
Code generation Generation of code that is efficient and effective for
embedded systems
• Fast software changes
• Robustness of generated code
1-10
Guideline Template
Last Change
The Last change field contains the document version number.
For a list of available Model Advisor checks for the MAAB guidelines, see
“MathWorks Automotive Advisory Board Checks” in the Simulink Verification
and Validation documentation. For information on using the Model Advisor,
see “Consulting the Model Advisor” in the Simulink documentation.
1-11
1 Introduction
Document Usage
• Chapter 2, “Naming Conventions” and Chapter 3, “Model Architecture”
provide basic guidelines that apply to all types of models.
• Chapter 5, “Simulink” and Chapter 6, “Stateflow” provide specific rules for
those environments.
• Some guidelines are dependent on other guidelines and are explicitly listed
throughout the document.
1-12
2
Naming Conventions
General Guidelines
• ar_0001: Filenames
• ar_0002: Directory names
2-2
ar_0001: Filenames
Priority Mandatory
Scope MAAB
MATLAB All
Versions
Prerequisites None
Form
filename = name.extension
Uniqueness
Allowed Characters
name:
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789_
extension:
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789
Underscores
name:
2-3
ar_0001: Filenames
extension:
Should not use underscores
Rationale • Readability
• Workflow
Last V1.0
Changed
2-4
ar_0002: Directory names
Priority Mandatory
Scope MAAB
MATLAB All
Versions
Prerequisites None
Uniqueness
All directory names within the parent project directory
Allowed characters
name:
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789_
Underscores
name:
Rationale • Readability
• Workflow
2-5
ar_0002: Directory names
Last V1.0
Changed
2-6
ar_0002: Directory names
Model Content
• jc_0201: Usable characters for Subsystem names
• jc_0211: Usable characters for Inport blocks and Outport
blocks
• jc_0221: Usable characters for signal line names
• jc_0231: Usable characters for block names
• na_0014: Use of local language in Simulink and Stateflow
2-7
jc_0201: Usable characters for Subsystem names
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description The names of all Subsystem blocks should conform to the following
constraints:
Form
name:
2-8
jc_0201: Usable characters for Subsystem names
Rationale • Readability
• Workflow
• Code generation
Last V2.2
Changed
2-9
jc_0211: Usable characters for Inport blocks and
Outport blocks
ID: Title jc_0211: Usable characters for Inport blocks and Outport blocks
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description The names of all Inport blocks and Output blocks should conform to
the following constraints:
Form
name:
2-10
jc_0211: Usable characters for Inport blocks and
Outport blocks
Rationale • Readability
• Workflow
• Code generation
Last V2.2
Changed
2-11
jc_0221: Usable characters for signal line names
Scope MAAB
MATLAB All
Versions
Prerequisites None
Form
name:
Allowed Characters
name:
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789_
Underscores
name:
2-12
jc_0221: Usable characters for signal line names
Rationale • Readability
• Workflow
• Code generation
Last V2.2
Changed
2-13
jc_0231: Usable characters for block names
Scope MAAB
MATLAB All
Versions
Description The names of all blocks should conform to the following constraints:
Form
name:
Rationale • Readability
• Workflow
• Code generation
2-14
jc_0231: Usable characters for block names
Last V2.0
Changed
2-15
na_0014: Use of local language in Simulink and
Stateflow
Scope J-MAAB
MATLAB All
Versions
Prerequisites None
Description The local language should be used in descriptive fields only. Descriptive
fields are text entry points that do not affect code generation or
simulation. Examples of descriptive fields include the Description
field in the Block Properties dialog box.
Simulink Examples
2-16
na_0014: Use of local language in Simulink and
Stateflow
Stateflow Examples
2-17
na_0014: Use of local language in Simulink and
Stateflow
2-18
na_0014: Use of local language in Simulink and
Stateflow
Rationale • Readability
• Workflow
Last V2.0
Changed
2-19
na_0014: Use of local language in Simulink and
Stateflow
2-20
3
Model Architecture
This document uses the term basic blocks to refer to blocks built into
the Simulink block libraries. “Basic Blocks” on page D-2 in Appendix D,
“Background Information on Basic Blocks and Signals” lists some examples of
basic blocks.
3 Model Architecture
3-2
na_0006: Guidelines for mixed use of Simulink and
Stateflow
ID: Title na_0006: Guidelines for mixed use of Simulink and Stateflow
Scope MAAB
MATLAB All
Versions
Prerequisites None
Specifics
3-3
na_0006: Guidelines for mixed use of Simulink and
Stateflow
3-4
na_0006: Guidelines for mixed use of Simulink and
Stateflow
3-5
na_0006: Guidelines for mixed use of Simulink and
Stateflow
3-6
na_0006: Guidelines for mixed use of Simulink and
Stateflow
3-7
na_0006: Guidelines for mixed use of Simulink and
Stateflow
Incorrect
3-8
na_0006: Guidelines for mixed use of Simulink and
Stateflow
Correct
3-9
na_0006: Guidelines for mixed use of Simulink and
Stateflow
Incorrect
Correct
Rationale • Readability
• Workflow
3-10
na_0006: Guidelines for mixed use of Simulink and
Stateflow
• Simulation
• Verification and Validation
• Code Generation
Last V2.0
Changed
3-11
na_0007: Guidelines for use of Flow Charts, Truth Tables
and State Machines
ID: Title na_0007: Guidelines for use of Flow Charts, Truth Tables and State
Machines
Scope MAAB
MATLAB All
Versions
Description Within Stateflow, the choice of whether to use a flow chart or a state
chart to model a given portion of the control algorithm functionality
should be driven by the nature of the behavior being modeled.
Specifics
If the primary nature of a function segment is to calculate modes or
states, but if-then-else statements are required, add a flow chart to a
state within the state chart. (See “Flowchart Patterns” on page 6-53.)
Rationale • Readability
• Workflow
3-12
na_0007: Guidelines for use of Flow Charts, Truth
Tables and State Machines
• Simulation
• Verification and Validation
• Code Generation
Last V2.0
Changed
3-13
na_0007: Guidelines for use of Flow Charts, Truth Tables
and State Machines
Subsystem Hierarchies
• db_0143: Similar block types on the model levels
• db_0144: Use of Subsystems
• db_0040: Model hierarchy
3-14
db_0143: Similar block types on the model levels
Scope NA-MAAB
MATLAB All
Versions
Prerequisites None
Description To allow partitioning of the model into discreet units, every level of a
model must be designed with building blocks of the same type (i.e. only
Subsystems or only “Basic Blocks”). The blocks listed in this guideline
are used for signal routing. You can place them at any level of the model.
Block Example
Action port1
Bus Creator
Bus Selector
Case
3-15
db_0143: Similar block types on the model levels
Block Example
Demux
Enable2
From
Function-Call
Generator
Function-Call Split
Goto
3-16
db_0143: Similar block types on the model levels
Block Example
Ground
If
Inport
Merge
Mux
Outport
Rate Transition
Selector
Terminator
3-17
db_0143: Similar block types on the model levels
Block Example
Trigger3
Unit Delay
1
Action ports are not allowed at the root level of a model.
2
Starting in R2011b, the Enable block is allowed at the root level of
the model.
3
Starting in R2009a, the Trigger block is allowed at the root level of
the model.
Note If the Trigger or Enable blocks are placed at the root level of
the model, then the model will not simulate in a standalone mode.
The model must be referenced using the Model block.
Rationale • Readability
• Workflow
• Verification and Validation
Last V2.2
Changed
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor for mixing basic blocks and subsystems”
Check
3-18
db_0144: Use of Subsystems
Scope MAAB
MATLAB All
Versions
Prerequisites None
Rationale • Readability
• Workflow
• Verification and Validation
• Code Generation
Last V2.2
Changed
3-19
db_0040: Model hierarchy
Scope MAAB
MATLAB All
Versions
Prerequisites None
Rationale • Readability
• Workflow
• Verification and Validation
• Code Generation
Last V2.0
Changed
3-20
db_0040: Model hierarchy
3-21
jc_0301: Controller model
Priority Mandatory
Scope J-MAAB
MATLAB All
Versions
Prerequisites None
Description Control models are organized using the following hierarchical structure.
Details on each layer are provided in corresponding rules.
3-22
jc_0301: Controller model
Controller Model
Rationale Workflow
Last V2.0
Changed
3-23
jc_0311: Top layer/root level
Priority Mandatory
Scope J-MAAB
MATLAB All
Versions
Prerequisites None
Rationale Workflow
Last V2.0
Changed
3-24
jc_0311: Top layer/root level
3-25
jc_0321: Trigger layer
Priority Mandatory
Scope J-MAAB
MATLAB All
Versions
Prerequisites None
Rationale • Readability
• Workflow
• Code Generation
3-26
jc_0321: Trigger layer
Last V2.0
Changed
3-27
jc_0331: Structure layer
Priority Mandatory
Scope J-MAAB
MATLAB All
Versions
Prerequisites None
Description • Describe a structure layer like the following structure layer example.
- In the case of Type B, specify sample time at an Inport block or a
Subsystem block to define task time of the subsystem.
- In the case of Type B, use a block annotation at an Inport block
or a Subsystem block and display sample time to clarify task time
of the subsystem.
• A subsystem of a structure layer should be an atomic subsystem.
3-28
jc_0331: Structure layer
Rationale • Readability
• Workflow
• Code Generation
Last V2.0
Changed
3-29
jc_0341: Data flow layer
Priority Mandatory
Scope J-MAAB
MATLAB All
Versions
Prerequisites None
Description Describe a data flow layer as in the following example. In the case of
Type A, use a block annotation at an Inport block and display its sample
time to clarify execution timing of the signal.
Rationale Workflow
Last V2.0
Changed
3-30
4
Model Configuration
Options
4 Model Configuration Options
4-2
jc_0011: Optimization parameters for Boolean data
types
ID: Title jc_0011: Optimization parameters for Boolean data types
Scope MAAB
MATLAB All
Versions
Description The optimization option for Boolean data types must be enabled (on).
In the Configuration Parameters dialog box, on the Optimization
pane, under Simulation and code generation, select Implement
logic signals as Boolean data (vs. double).
Rationale • Workflow
• Code Generation
Last V2.2
Changed
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor Implement logic signals as Boolean data (vs. double)”
Check
4-3
jc_0021: Model diagnostic settings
Scope MAAB
MATLAB All
Versions
Prerequisites None
• Algebraic loop
• Minimize algebraic loop
Sample Time Diagnostics
4-4
jc_0021: Model diagnostic settings
Rationale • Workflow
• Code Generation
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Model Configuration
Advisor Options > “Check model diagnostic parameters”
Check
4-5
jc_0021: Model diagnostic settings
4-6
5
Simulink
Diagram Appearance
• na_0004: Simulink model appearance
• db_0043: Simulink font and font size
• db_0042: Port block in Simulink models
• na_0005: Port block name visibility in Simulink models
• jc_0081: Icon display for Port block
• jm_0002: Block resizing
• db_0142: Position of block names
• jc_0061: Display of block names
• db_0146: Triggered, enabled, conditional Subsystems
• db_0140: Display of basic block parameters
• db_0032: Simulink signal appearance
• db_0141: Signal flow in Simulink models
• jc_0171: Maintaining signal flow when using Goto and From
blocks
• jm_0010: Port block names in Simulink models
• jc_0281: Naming of Trigger Port block and Enable Port block
5-2
na_0004: Simulink model appearance
Priority Recommended
Scope MAAB
MATLAB All
Versions
Prerequisites None
5-3
na_0004: Simulink model appearance
Rationale • Readability
• Workflow
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor for Simulink diagrams using nonstandard display attributes”
Check
5-4
db_0043: Simulink font and font size
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description All text elements (block names, block annotations, and signal labels)
except free text annotations within a model, must have the same font
style and font size. Select font style and font size for legibility.
Note The selected font should be portable (for example, the Simulink
and Stateflow default font) or convertible between platforms (for
example, Arial or Helvetica 12pt).
Rationale • Readability
• Workflow
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor font formatting”
Check
5-5
db_0042: Port block in Simulink models
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description In a Simulink model, ports must comply with the following rules:
• Place Inport blocks on the left side of the diagram; you may move
them to prevent signal crossings.
• Place Outport blocks on the right side of the diagram; you may move
them to prevent signal crossings.
• You may use duplicate Inport blocks at the subsystem level, if
required, but avoid doing so, if possible.
- Do not use duplicate Inport blocks at the root level.
5-6
db_0042: Port block in Simulink models
Correct
Incorrect
5-7
db_0042: Port block in Simulink models
Rationale Readability
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor positioning and configuration of ports”
Check
5-8
na_0005: Port block name visibility in Simulink
models
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description While for some items, it is not possible to define a single approach that
may apply to all organizations’ internal processes, it is important that,
at least within a given organization, a single consistent approach is
followed. An organization applying the guidelines must enforce one of
the following alternatives.
Apply one of the following practices:
5-9
na_0005: Port block name visibility in Simulink models
Rationale Readability
Last V2.2
Changed
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor visibility of block port names”
Check
5-10
jc_0081: Icon display for Port block
Priority Recommended
Scope MAAB
Prerequisites None
Description The Icon display setting should be set to Port number for Inport and
Outport blocks.
Correct
Incorrect
Incorrect
Rationale Readability
5-11
jc_0081: Icon display for Port block
Last V2.2
Changed
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor for unconnected ports and signal lines”
Check
5-12
jm_0002: Block resizing
Priority Mandatory
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description All blocks in a model must be sized such that the icon is completely
visible and recognizable. In particular, any displayed text (for example,
tunable parameters, file names, or equations) in the icon must be
readable.
This guideline requires that you resize blocks with variable icons or
blocks with a variable number of inputs and outputs. In some cases, it
may not be practical or desirable to resize the icon of a subsystem block
so that all of the input and output names within it are readable. In such
cases, you may hide the names in the icon by using a mask or by hiding
the names in the subsystem associated with the icon. If you do this,
the signal lines coming into and out of the subsystem block should be
clearly labeled in close proximity to the block.
Correct
5-13
jm_0002: Block resizing
Incorrect
Rationale Readability
Last V2.0
Changed
5-14
db_0142: Position of block names
Scope MAAB
MATLAB All
Versions
Prerequisites None
Correct
Incorrect
Rationale • Readability
• Workflow
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor whether block names appear below blocks”
Check
5-15
jc_0061: Display of block names
Priority Recommended
Scope MAAB
MATLAB All
Versions
Prerequisites None
Rationale Readability
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor the display attributes of block names”
Check
5-16
db_0146: Triggered, enabled, conditional Subsystems
Scope MAAB
MATLAB All
Versions
Prerequisites None
• Action Port
• Enable
• For Iterator
• Switch Case Action
• Trigger
• While Iterator
Note The Action Port is associated with the If and Case blocks. The
Trigger port is also the function-call block.
5-17
db_0146: Triggered, enabled, conditional Subsystems
Correct
Incorrect
Rationale • Readability
• Workflow
• Verification and Validation
Last V2.2
Changed
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor position of Trigger and Enable blocks”
Check
5-18
db_0140: Display of basic block parameters
Priority Recommended
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description Important block parameters modified from the default values should
be displayed.
Correct
5-19
db_0140: Display of basic block parameters
Rationale • Readability
• Verification and Validation
Last V2.2
Changed
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor for nondefault block attributes”
Check
5-20
db_0032: Simulink signal appearance
Scope MAAB
MATLAB All
Versions
Prerequisites None
Correct
5-21
db_0032: Simulink signal appearance
Incorrect
Rationale • Readability
• Workflow
Last V2.0
Changed
5-22
db_0141: Signal flow in Simulink models
Scope MAAB
Versions All
Prerequisites None
Rationale • Readability
• Workflow
5-23
db_0141: Signal flow in Simulink models
Last V2.0
Changed
5-24
jc_0171: Maintaining signal flow when using Goto
and From blocks
ID: Title jc_0171: Maintaining signal flow when using Goto and From blocks
Scope MAAB
MATLAB All
Versions
Prerequisites None
5-25
jc_0171: Maintaining signal flow when using Goto and
From blocks
Correct
Incorrect
Rationale • Readability
• Workflow
• Verification and Validation
Last V2.2
Changed
5-26
jc_0171: Maintaining signal flow when using Goto
and From blocks
5-27
jm_0010: Port block names in Simulink models
Scope MAAB
MATLAB All
Versions
Description For some items, though you may not be able to define a single approach
for internal processes of all organizations, within a given organization,
try to follow a single, consistent approach. An organization applying the
guidelines must enforce one of the following options:
5-28
jm_0010: Port block names in Simulink models
Rationale • Readability
• Workflow
• Simulation
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor for matching port and signal names”
Check
5-29
jc_0281: Naming of Trigger Port block and Enable Port
block
ID: Title jc_0281: Naming of Trigger Port block and Enable Port block
Scope J-MAAB
MATLAB All
Versions
Prerequisites None
Description For Trigger and Enable port blocks, match the block name of the signal
triggering the subsystem.
Rationale Readability
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor Trigger and Enable block names”
Check
5-30
jc_0281: Naming of Trigger Port block and Enable
Port block
Signals
• na_0008: Display of labels on signals
• na_0009: Entry versus propagation of signal labels
• db_0097: Position of labels for signals and busses
• db_0081: Unconnected signals, block inputs and block
outputs
5-31
na_0008: Display of labels on signals
Priority Recommended
Scope MAAB
MATLAB All
Versions
Prerequisites None
5-32
na_0008: Display of labels on signals
- Mux block
- Subsystem block
- Chart block
Correct
Incorrect
Rationale • Readability
• Workflow
• Verification and Validation
• Code Generation
Last V2.2
Changed
5-33
na_0008: Display of labels on signals
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor signal line labels”
Check
5-34
na_0009: Entry versus propagation of signal labels
Scope MAAB
MATLAB All
Versions
Description If a label is present on a signal, the following rules define whether that
label is created there (entered directly on the signal) or propagated from
its true source (inherited from elsewhere in the model by using the less
than (<) character).
5-35
na_0009: Entry versus propagation of signal labels
Rationale • Readability
• Workflow
• Verification and Validation
• Code Generation
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor for propagated signal labels”
Check
5-36
db_0097: Position of labels for signals and busses
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description The labels must be visually associated with the corresponding signal
and not overlap other labels, signals, or blocks.
Labels should be located consistently below horizontal lines and close to
the corresponding source or destination block.
Rationale • Readability
• Workflow
Last V2.0
Changed
5-37
db_0081: Unconnected signals, block inputs and block
outputs
ID: Title db_0081: Unconnected signals, block inputs and block outputs
Priority Mandatory
Scope MAAB
MATLAB All
Versions
Prerequisites None
In addition:
Rationale • Readability
• Workflow
• Verification and Validation
Last V2.0
Changed
5-38
db_0081: Unconnected signals, block inputs and block
outputs
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor for unconnected ports and signal lines”
Check
5-39
db_0081: Unconnected signals, block inputs and block
outputs
Block Usage
• na_0003: Simple logical expressions in If Condition
block
• na_0002: Appropriate implementation of fundamental
logical and numerical operations
• jm_0001: Prohibited Simulink standard blocks inside
controllers
• hd_0001: Prohibited Simulink sinks
• na_0011: Scope of Goto and From blocks
• jc_0141: Use of the Switch block
• jc_0121: Use of the Sum block
• jc_0131: Use of Relational Operator block
• jc_0161: Use of Data Store Read/Write/Memory blocks
5-40
na_0003: Simple logical expressions in If Condition
block
ID: Title na_0003: Simple logical expressions in If Condition block
Priority Mandatory
Scope MAAB
MATLAB All
Versions
Prerequisites None
• An input
• A constant
• A constant parameter
• A parenthesized expression containing no operators except zero or
one instance of the following operators: < , <= , >, >=, ~=, ==, ~. (See
the following examples.)
Exception
A logical expression may contain more than two primary expressions
if both of the following are true:
• u1 || u2 || u3 ||u4 || u5
• u1 && u2 && u3 && u4
5-41
na_0003: Simple logical expressions in If Condition
block
• u1
• 5
• K
• (u1 > 0)
• (u1 <= G)
• (u1 > U2)
• (~u1)
• (EngineState.ENGINE_RUNNING)
• u1 || u2
• (u1 > 0) && (u1 < 20)
• (u1 > 0) && (u2 < u3)
• (u1 > 0) && (~u2)
• (EngineState.ENGINE_RUNNING > 0) && (PRNDLState.PRNDL_PARK)
5-42
na_0003: Simple logical expressions in If Condition
block
(u1 > 0) && (u1 < 20) && (u2 > 5) (too many primary expressions
that are not inputs)
(u1 > 0) && ((2*u2) > 6) (unacceptable operator within
primary expression)
Rationale • Readability
• Workflow
Last V2.2
Changed
5-43
na_0002: Appropriate implementation of fundamental
logical and numerical operations
Priority Mandatory
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description • Blocks that are intended to perform numerical operations must not
be used to perform logical operations.
Incorrect
5-44
na_0002: Appropriate implementation of fundamental
logical and numerical operations
Incorrect
Incorrect
Rationale • Readability
• Workflow
Last V2.0
Changed
5-45
jm_0001: Prohibited Simulink standard blocks inside
controllers
Priority Mandatory
Scope MAAB
MATLAB All
Versions
Prerequisites None
Band-Limited Random
White Noise Number
Uniform
Pulse
Random
Generator
Number
Sine Wave
5-46
jm_0001: Prohibited Simulink standard blocks inside
controllers
The following additional blocks are not allowed. The MAAB Style guide
group recommends not using the following blocks. The list may be
extended by individual companies.
Real-Imag to
Slider Gain
Complex
Interpreted
Complex to
MATLAB
Magnitude-Angle
Function1
Complex to
Probe
Real-Imag
1
In R2011a, the MATLAB Fnc block was renamed the Interpreted
MATLAB Function block.
Rationale • Readability
• Workflow
• Code Generation
Last V2.2
Changed
5-47
jm_0001: Prohibited Simulink standard blocks inside
controllers
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor for prohibited blocks in discrete controllers”
Check
5-48
hd_0001: Prohibited Simulink sinks
Scope MAAB
MATLAB All
Versions
Prerequisites None
To File Stop
Simulation
To
Workspace
Note Simulink Scope and Display blocks are allowed in the model
diagram. Consider using Simulink Signal logging and Signal and Scope
Manager for data logging and viewing requirements.
Rationale • Readability
• Workflow
Last V2.2
Changed
5-49
hd_0001: Prohibited Simulink sinks
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor for prohibited sink blocks”
Check
5-50
na_0011: Scope of Goto and From blocks
Scope MAAB
MATLAB All
Versions
Prerequisites None
• Function-call generators
• If and Case blocks
• Function call outputs from MATLAB and Stateflow blocks
Control flow signals are identified as dashed lines in the model after
updating a Simulink model.
5-51
na_0011: Scope of Goto and From blocks
Rationale • Readability
• Workflow
• Code Generation
Last V2.2
Changed
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor scope of From and Goto blocks”
Check
5-52
jc_0141: Use of the Switch block
Scope MAAB
MATLAB All
Versions
Prerequisites None
5-53
jc_0141: Use of the Switch block
Correct
Incorrect
5-54
jc_0141: Use of the Switch block
Rationale • Readability
• Workflow
Last V2.2
Changed
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor use of Switch blocks”
Check
5-55
jc_0121: Use of the Sum block
Priority Recommended
Scope MAAB
MATLAB All
Versions
Prerequisites None
Correct
5-56
jc_0121: Use of the Sum block
Incorrect
Correct
5-57
jc_0121: Use of the Sum block
Incorrect
Correct
Incorrect
5-58
jc_0121: Use of the Sum block
Rationale Readability
Last V2.0
Changed
5-59
jc_0131: Use of Relational Operator block
Priority Recommended
Scope J-MAAB
MATLAB All
Versions
Prerequisites None
Correct
Incorrect
Rationale • Readability
• Code Generation
5-60
jc_0131: Use of Relational Operator block
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor configuration of Relational Operator blocks”
Check
5-61
jc_0161: Use of Data Store Read/Write/Memory blocks
Scope J-MAAB
MATLAB All
Versions
Description Data Store Memory, Data Store Read, and Data Store Write blocks are
Rationale • Readability
• Workflow
Last V2.0
Changed
5-62
jc_0161: Use of Data Store Read/Write/Memory
blocks
Block Parameters
• db_0112: Indexing
• na_0010: Grouping data flows into signals
• db_0110: Tunable parameters in basic blocks
5-63
db_0112: Indexing
Scope MAAB
MATLAB All
Versions
Prerequisites None
Rationale • Readability
• Workflow
• Code Generation
Last V2.2
Changed
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor for indexing in blocks”
Check
5-64
na_0010: Grouping data flows into signals
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description Vectors
The individual scalar signals composing a vector must have common
functionality, data types, dimensions, and units. The most common
example of a vector signal is sensor or actuator data that is grouped into
an array indexed by location. The output of a Mux block must always be
a vector. The inputs to a Mux block must always be scalars.
Busses
Signals that do not meet criteria for use as a vector, as previously
described, must only be grouped into bus signals. Use Bus Selector
blocks only with a bus signal input; do not use them to extract scalar
signals from vector signals.
Examples
Some examples of vector signals include:
5-65
na_0010: Grouping data flows into signals
Rationale • Readability
• Workflow
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor for signal bus and Mux block usage”
Check
5-66
db_0110: Tunable parameters in basic blocks
Scope MAAB
MATLAB All
Versions
Prerequisites None
Correct
Incorrect
Rationale • Readability
• Workflow
• Code Generation
Last V2.2
Changed
5-67
db_0110: Tunable parameters in basic blocks
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor use of tunable parameters in blocks”
Check
5-68
db_0110: Tunable parameters in basic blocks
Simulink Patterns
• na_0012: Use of Switch vs. If-Then-Else Action
Subsystem
• db_0114: Simulink patterns for If-then-else-if
constructs
• db_0115: Simulink patterns for case constructs
• db_0116: Simulink patterns for logical constructs with
logical blocks
• db_0117: Simulink patterns for vector signals
• jc_0351: Methods of initialization
• jc_0111: Direction of Subsystem
5-69
na_0012: Use of Switch vs. If-Then-Else Action
Subsystem
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description The Switch block should be used for modeling simple if-then-else
structures, if the associated then and else actions involve only the
assignment of constant values.
5-70
na_0012: Use of Switch vs. If-Then-Else Action
Subsystem
In other cases, the degree of complexity of the then and/or else action
computations and the intelligence of the Simulink simulation and code
generation engines determine the appropriate construct.
These statements also apply to more complicated nested and cascaded
if-then-else structures and case structure implementations.
Rationale • Readability
• Workflow
Last V2.0
Changed
5-71
db_0114: Simulink patterns for If-then-else-if constructs
Scope MAAB
MATLAB All
Versions
Prerequisites None
if (If_Condition) {
output_signal = If_Value;
}
else if (Else_If_Condition) {
output_signal =
Else_If_Value;
}
else {
output_signal =
Else_Value;
}
5-72
db_0114: Simulink patterns for If-then-else-if
constructs
if(Fault_1_Active &
Fault_2_Active)
{
ErrMsg = SaftyCrit;
}
else if (Fault_1_Active |
Fault_2_Active)
{
ErrMsg = DriveWarn;
}
else
{
ErrMsg = NoFaults;
}
Rationale • Readability
• Workflow
• Code Generation
Last V2.0
Changed
5-73
db_0115: Simulink patterns for case constructs
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description Use the following patterns for case constructs within a Simulink model:
switch (PRNDL_Enum)
{
case 1
TqEstimate = ParkV;
break;
case 2
TqEstimae = RevV;
break;
default
TqEstimate = NeutralV;
break;
}
Rationale • Readability
• Workflow
Last V2.2
Changed
5-74
db_0115: Simulink patterns for case constructs
5-75
db_0116: Simulink patterns for logical constructs with
logical blocks
ID: Title db_0116: Simulink patterns for logical constructs with logical blocks
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description Use the following patterns for logical combinations within Simulink:
5-76
db_0116: Simulink patterns for logical constructs with
logical blocks
Rationale • Readability
5-77
db_0116: Simulink patterns for logical constructs with
logical blocks
• Workflow
• Verification and Validation
Last V1.0
Changed
5-78
db_0117: Simulink patterns for vector signals
Scope MAAB
MATLAB All
Versions
Prerequisites None
for (i=0;
i>input_vector_size; i++)
{
output_vector(i) =
input_vector(i) *
tunable_parameter_value;
}
Vector loop
for (i=0;
i>input_vector_size; i++)
{
output_vector(i) =
input_vector(i) *
tunable_parameter_vector(i);
}
5-79
db_0117: Simulink patterns for vector signals
output_signal = 1;
for (i=0;
i>input_vector_size; i++)
{
output_signal =
output_signal *
input_vector(i);
}
Vector loop
output_signal = 1;
for (i=0;
i>input_vector_size; i++)
{
output_signal =
output_signal /
input_vector(i);
}
Vector loop
for (i=0;
i>input_vector_size; i++)
{
output_vector(i) =
input_vector(i) +
tunable_parameter_value;
}
5-80
db_0117: Simulink patterns for vector signals
for (i=0;
i>input_vector_size; i++)
{
output_vector(i) =
input_vector(i) +
tunable_parameter_vector(i);
}
Vector loop:
output_signal = 0;
for (i=0;
i>input_vector_size; i++)
{
output_signal =
output_signal +
input_vector(i);
}
Vector loop:
output_signal = 0;
for (i=0;
i>input_vector_size; i++)
{
output_signal =
output_signal -
input_vector(i);
}
5-81
db_0117: Simulink patterns for vector signals
Rationale • Readability
• Workflow
• Verification and Validation
• Code Generation
5-82
db_0117: Simulink patterns for vector signals
Last V2.2
Changed
5-83
jc_0351: Methods of initialization
Priority Recommended
Scope MAAB
MATLAB All
Versions
• Blocks such as Unit Delay, which have an initial value field, can be
used to set simple initial values.
• To determine if the initial value needs to be displayed, see MAAB
Guideline db_0140: Display of basic block parameters.
Example
5-84
jc_0351: Methods of initialization
Example A
Example B
Or
5-85
jc_0351: Methods of initialization
Rationale Workflow
Last V2.2
Changed
5-86
jc_0111: Direction of Subsystem
Scope J-MAAB
MATLAB All
Versions
Prerequisites None
Correct
Incorrect
5-87
jc_0111: Direction of Subsystem
Rationale Readability
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Simulink > “Check
Advisor orientation of Subsystem blocks”
Check
5-88
6
Stateflow
Chart Appearance
• db_0123: Stateflow port names
• db_0129: Stateflow transition appearance
• db_0137: States in state machines
• db_0133: Use of patterns for Flowcharts
• db_0132: Transitions in Flowcharts
• jc_0501: Format of entries in a State block
• jc_0511: Setting the return value from a graphical function
• jc_0531: Placement of the default transition
• jc_0521: Use of the return value from graphical functions
6-2
db_0123: Stateflow port names
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description The name of a Stateflow input or output should be the same as the
corresponding signal.
Exception: Reusable Stateflow blocks may have different port names.
Rationale • Readability
• Workflow
Last V1.0
Changed
Model By Task > Modeling Standards for MAAB > Stateflow > “Check
Advisor for mismatches between names of Stateflow ports and
Check associated signals”
6-3
db_0129: Stateflow transition appearance
Scope MAAB
MATLAB All
Versions
Prerequisites None
6-4
db_0129: Stateflow transition appearance
Correct
6-5
db_0129: Stateflow transition appearance
Rationale • Readability
• Workflow
Last V2.2
Changed
6-6
db_0137: States in state machines
Priority Mandatory
Scope MAAB
MATLAB All
Versions
Rationale • Readability
• Workflow
• Verification and Validation
Last V2.2
Changed
Model By Task > Modeling Standards for MAAB > Sstateflow > “Check
Advisor usage of exclusive and default states in state machines”
Check
6-7
db_0133: Use of patterns for Flowcharts
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description A Flowchart is built with the help of Flowchart patterns (for example,
if-then-else, for loop, and so on):
Rationale • Readability
• Workflow
• Verification and Validation
Last V2.2
Changed
6-8
db_0132: Transitions in Flowcharts
Scope MAAB
MATLAB All
Versions
Prerequisites None
6-9
db_0132: Transitions in Flowcharts
Empty Transition
Transition Action
At every junction, except for the last junction of a flow diagram, exactly
one unconditional transition begins. Every decision point (junction)
must have a default path.
6-10
db_0132: Transitions in Flowcharts
Rationale • Readability
• Workflow
• Verification and Validation
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Stateflow > “Check
Advisor Transition orientations in flowcharts”
Check
6-11
jc_0501: Format of entries in a State block
Priority Recommended
Scope MAAB
MATLAB All
Versions
Prerequisites None
• Start after the entry (en), during (du), and exit (ex) statements.
Correct
6-12
jc_0501: Format of entries in a State block
Incorrect
Incorrect
Rationale Readability
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Stateflow > “Check
Advisor entry formatting in State blocks in Stateflow charts”
Check
6-13
jc_0511: Setting the return value from a graphical
function
ID: Title jc_0511: Setting the return value from a graphical function
Priority Mandatory
Scope J-MAAB
MATLAB All
Versions
Prerequisites None
Description The return value from a graphical function must be set in only one place.
Correct
6-14
jc_0511: Setting the return value from a graphical
function
Incorrect
Rationale • Workflow
• Code Generation
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Stateflow > “Check
Advisor return value assignments of graphical functions in Stateflow
Check charts”
6-15
jc_0531: Placement of the default transition
Priority Recommended
Scope J-MAAB
MATLAB All
Versions
Prerequisites None
Correct
6-16
jc_0531: Placement of the default transition
Incorrect
Rationale Readability
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Stateflow > “Check
Advisor default transition placement in Stateflow charts”
Check
6-17
jc_0521: Use of the return value from graphical
functions
ID: Title jc_0521: Use of the return value from graphical functions
Priority Recommended
Scope J-MAAB
MATLAB All
Versions
Prerequisites None
Description The return value from a graphical function should not be used directly
in a comparison operation.
Correct
6-18
jc_0521: Use of the return value from graphical
functions
Incorrect
Rationale Readability
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Stateflow > “Check
Advisor usage of return values from a graphical function in Stateflow
Check charts”
6-19
jc_0521: Use of the return value from graphical
functions
6-20
na_0001: Bitwise Stateflow operators
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description The bitwise Stateflow operators (&, |, and ^) should not be used in
Stateflow charts unless you want bitwise operations:
To enable bitwise operations,
Correct
Use && and || for Boolean operation.
6-21
na_0001: Bitwise Stateflow operators
Incorrect
Use & and | for Boolean operation.
Rationale • Simulation
• Code Generation
6-22
na_0001: Bitwise Stateflow operators
Last V2.2
Changed
Model By Task > Modeling Standards for MAAB > Stateflow > “Check
Advisor for bitwise operations in Stateflow charts”
Check
6-23
jc_0451: Use of unary minus on unsigned integers in
Stateflow
Priority Recommended
Scope MAAB
MATLAB All
Versions
Prerequisites None
Correct
Incorrect
Rationale • Readability
• Workflow
• Code Generation
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Stateflow > “Check
Advisor for unary minus operations on unsigned integers in Stateflow
Check charts”
6-24
na_0013: Comparison operation in Stateflow
Priority Recommended
Scope MAAB
MATLAB All
Versions
Prerequisites None
Correct
Incorrect
6-25
na_0013: Comparison operation in Stateflow
Correct
Incorrect
Rationale • Workflow
• Code Generation
Last V2.1
Changed
Model By Task > Modeling Standards for MAAB > Stateflow > “Check
Advisor for comparison operations in Stateflow charts”
Check
6-26
db_0122: Stateflow and Simulink interface signals
and parameters
ID: Title db_0122: Stateflow and Simulink interface signals and parameters
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description A Chart uses strong data typing with Simulink and requires that you
select the Use Strong Data Typing with Simulink I/O parameter.
Rationale • Readability
• Workflow
• Verification and Validation
6-27
db_0122: Stateflow and Simulink interface signals and
parameters
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Stateflow > “Check
Advisor for Strong Data Typing with Simulink I/O”
Check
6-28
db_0125: Scope of internal signals and local auxiliary
variables
ID: Title db_0125: Scope of internal signals and local auxiliary variables
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description Internal signals and local auxiliary variables are "Local data" in
Stateflow:
• All local data of a Stateflow block must be defined on the chart level
or below the Object Hierarchy.
• No local variables may exist on the machine level (that is, no
interaction should occur between local data in different charts).
• Parameters and constants are allowed at the machine level.
Correct
6-29
db_0125: Scope of internal signals and local auxiliary
variables
Incorrect
Rationale • Readability
• Workflow
• Verification and Validation
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Stateflow > “Check
Advisor for Strong Data Typing with Simulink I/O”
Check
6-30
jc_0481: Use of hard equality comparisons for floating
point numbers in Stateflow
ID: Title jc_0481: Use of hard equality comparisons for floating point numbers
in Stateflow
Priority Recommended
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description • Do not use hard equality comparisons (Var1 == Var2) with two
floating-point numbers.
• If a hard comparison is required, a margin of error should be defined
and used in the comparison (LIMIT, in the example).
• Hard equality comparisons may be done between two integer data
types.
Correct
6-31
jc_0481: Use of hard equality comparisons for floating
point numbers in Stateflow
Incorrect
Rationale • Workflow
• Verification and Validation
• Code Generation
Last V2.0
Changed
Model By Task > Modeling Standards for MAAB > Stateflow > “Check
Advisor for equality operations between floating-point expressions in
Check Stateflow charts”
6-32
jc_0491: Reuse of variables within a single Stateflow
scope
Priority Recommended
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description The same variable should not have multiple meanings (usages) within a
single Stateflow state.
Correct
Variable of loop counter must not be used other than loop counter.
6-33
jc_0491: Reuse of variables within a single Stateflow
scope
Incorrect
The meaning of the variable i changes from the index of the loop
counter to the sum of a+b.
6-34
jc_0491: Reuse of variables within a single Stateflow
scope
Correct
Rationale • Readability
• Workflow
• Code Generation
Last V2.2
Changed
6-35
jc_0491: Reuse of variables within a single Stateflow
scope
6-36
jc_0541: Use of tunable parameters in Stateflow
Scope MAAB
MATLAB All
Versions
Prerequisites None
6-37
jc_0541: Use of tunable parameters in Stateflow
Stateflow® Chart
Rationale • Readability
• Workflow
• Code Generation
Last V2.2
Changed
6-38
db_0127: MATLAB commands in Stateflow
Priority Mandatory
Scope MAAB
MATLAB All
Versions
Prerequisites None
Correct
Incorrect
6-39
db_0127: MATLAB commands in Stateflow
Rationale • Readability
• Workflow
• Verification and Validation
• Code Generation
Last V2.2
Changed
Model By Task > Modeling Standards for MAAB > Stateflow > “Check
Advisor for MATLAB expressions in Stateflow charts”
Check
6-40
jm_0011: Pointers in Stateflow
Scope MAAB
MATLAB All
Versions
Prerequisites None
Rationale • Readability
• Workflow
• Verification and Validation
• Code Generation
Last V1.0
Changed
Model By Task > Modeling Standards for MAAB > Stateflow > “Check
Advisor for pointers in Stateflow charts”
Check
6-41
jm_0011: Pointers in Stateflow
Events
• db_0126: Scope of events
• jm_0012: Event broadcasts
6-42
db_0126: Scope of events
Priority Mandatory
Scope MAAB
Prerequisites None
Specifics
Rationale • Readability
• Workflow
• Verification and Validation
Last V2.2
Changed
6-43
jm_0012: Event broadcasts
Scope MAAB
MATLAB All
Versions
6-44
jm_0012: Event broadcasts
Rationale • Readability
6-45
jm_0012: Event broadcasts
• Workflow
• Verification and Validation
• Code Generation
Last V2.2
Changed
Model By Task > Modeling Standards for MAAB > Stateflow > “Check
Advisor for event broadcasts in Stateflow charts”
Check
6-46
jm_0012: Event broadcasts
Statechart Patterns
• db_0150: State machine patterns for conditions
• db_0151: State machine patterns for transition actions
6-47
db_0150: State machine patterns for conditions
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description The following patterns are used for conditions within Stateflow state
machines:
(condition)
6-48
db_0150: State machine patterns for conditions
(condition1 &&
condition2)
(condition1 ||
condition2)
Two or more conditions,
multiline form:
A subcondition is a set of
logical operations, all of
the same type, enclosed
in parentheses.
(The use of different
operators in this form
is not allowed. Use
subconditions instead.)
(condition1 ...
&& condition2 ...
&& condition3)
(condition1 ...
|| condition2 ...
|| condition3)
Rationale • Readability
6-49
db_0150: State machine patterns for conditions
Last V2.2
Changed
6-50
db_0151: State machine patterns for transition actions
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description The following patterns are used for transition actions within Stateflow
state machines:
action;
action1;
action2;
action3;
6-51
db_0151: State machine patterns for transition actions
Rationale • Readability
Last V2.2
Changed
Model By Task > Modeling Standards for MAAB > Stateflow > “Check
Advisor transition actions in Stateflow charts”
Check
6-52
db_0151: State machine patterns for transition actions
Flowchart Patterns
• db_0148: Flowchart patterns for conditions
• db_0149: Flowchart patterns for condition actions
• db_0134: Flowchart patterns for If constructs
• db_0159: Flowchart patterns for case constructs
• db_0135: Flowchart patterns for loop constructs
6-53
db_0148: Flowchart patterns for conditions
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description Use the following patterns for conditions within Stateflow Flowcharts:
[condition]
[condition1
&& condition2
&& condition3]
[condition1
|| condition2
|| condition3]
6-54
db_0148: Flowchart patterns for conditions
[condition1 ...
&& condition2 ...
&& condition3]
[condition1 ...
|| condition2 ...
|| condition3]
Conditions with subconditions:
(The use of different
logical operators to connect
subconditions is not allowed.
The use of brackets is
mandatory.)
[(condition1a
|| condition1b) ...
&& (condition2a
|| condition2b) ...
&& (condition3)]
[(condition1a
&& condition1b) ...
|| (condition2a
&& condition2b) ...
|| (condition3)]
6-55
db_0148: Flowchart patterns for conditions
[condition1
&& condition2]
[condition1
|| condition2]
Rationale • Readability
• Workflow
• Verification and Validation
Last V2.2
Changed
6-56
db_0149: Flowchart patterns for condition actions
Scope MAAB
MATLAB All
Versions
Prerequisites None
Description You should use the following patterns for condition actions within
Stateflow Flowcharts:
6-57
db_0149: Flowchart patterns for condition actions
action;
action1; ...
action2; ...
action3; ...
action1a;
action1b;
action2;
action3;
6-58
db_0149: Flowchart patterns for condition actions
Rationale • Readability
• Workflow
• Verification and Validation
Last V2.2
Changed
6-59
db_0134: Flowchart patterns for If constructs
Scope MAAB
MATLAB All
Versions
Description Use the following patterns for If constructs within Stateflow Flowcharts:
if then
if (condition){ action;
}
6-60
db_0134: Flowchart patterns for If constructs
if then else
if (condition){ action1;
}
else {
action2;
}
if then else if
if (condition1){ action1;
}
else if (condition2) { action2;
}
else if (condition3){
__action3;
}
else {
action4;
}
6-61
db_0134: Flowchart patterns for If constructs
Cascade of if then
if (condition1){ action1;
if (condition2){ action2;
if (condition3){ action3;
}
}
}
Rationale • Readability
• Workflow
• Verification and Validation
Last V1.0
Changed
6-62
db_0159: Flowchart patterns for case constructs
Scope MAAB
MATLAB All
Versions
6-63
db_0159: Flowchart patterns for case constructs
Description Use the following patterns must be used for case constructs within
Stateflow Flowcharts:
selection = ...;
switch (selection)
{
case 1:
action1;
break;
case 2:
action2;
break;
case 3:
action3;
break;
default:
action4;
}
6-64
db_0159: Flowchart patterns for case constructs
c1 = condition1;
c2 = condition2;
c3 = condition3;
if (c1 && !c2 && !c3)
{
action1;
}
elseif (!c1 && c2 && !c3)
{
action2;
}
elseif (!c1 && !c2 && c3)
{
action3;
}
else
{
action4;
}
Rationale • Readability
• Workflow
• Verification and Validation
Last V1.0
Changed
6-65
db_0159: Flowchart patterns for case constructs
6-66
db_0135: Flowchart patterns for loop constructs
Priority Recommended
Scope MAAB
MATLAB All
Versions
6-67
db_0135: Flowchart patterns for loop constructs
Description Use the following patterns to create Loops within Stateflow Flowcharts:
for (index=0;
index<number_of_loops;
index++)
{
action;
}
while loop
while (condition)
{
action;
}
do while loop
do
{
action;
}
while (condition);
6-68
db_0135: Flowchart patterns for loop constructs
Rationale • Readability
• Workflow
• Verification and Validation
Last V1.0
Changed
6-69
db_0135: Flowchart patterns for loop constructs
6-70
A
Recommendations for
Automation Tools
These recommendations are for companies who develop tools that automate
checking of the style guidelines. The MathWorks Automotive Advisory Board
(MAAB) developed these recommendations for tool vendors who create tools
developed with MathWorks tools that check models against these guidelines.
To provide maximum information to potential users of the tools, the MAAB
strongly recommends that tool vendors provide a compliance matrix that
is easily accessible while the tool is running. This information should be
available without a need to purchase the tool.
• Version of the guidelines that are checked – shall include the complete
title, as found on the title page of this document.
Include the MAAB Style Guidelines Title and Version document number.
• Table consisting of the following information for each guideline:
- Guideline ID
- Guideline title
- Level of compliance
- Detail
The guideline ID and title shall be exactly as included in this document. The
level of compliance shall be one of the following:
A Recommendations for Automation Tools
A-2
B
Guideline Writing
B-2
C
Flowchart Reference
Use the patterns that appear in this appendix for if-then-else-if constructs
within Stateflow Flowcharts.
C Flowchart Reference
Straight Line Flow Chart Pattern Curved Line Flow Chart Pattern
if then
if then else
C-2
Flowchart Reference
Straight Line Flow Chart Pattern Curved Line Flow Chart Pattern
if then else if
Cascade of if then
C-3
C Flowchart Reference
The following patterns are used for case constructs within Stateflow
Flowcharts:
Straight Line Flow Chart Pattern Curved Line Flow Chart Pattern
case with exclusive selection
C-4
Flowchart Reference
Straight Line Flow Chart Pattern Curved Line Flow Chart Pattern
case with exclusive conditions
C-5
C Flowchart Reference
The following patterns are used for for loops within Stateflow Flowcharts:
Straight Line Flow Chart Pattern Curved Line Flow Chart Pattern
for loop
Straight Line Flow Chart Pattern Curved Line Flow Chart Pattern
while loop
C-6
Flowchart Reference
Straight Line Flow Chart Pattern Curved Line Flow Chart Pattern
do while loop
C-7
C Flowchart Reference
Straight Line Flow Chart Pattern Alternate Straight Line Flow Chart Pattern
if then else if
C-8
Flowchart Reference
Straight Line Flow Chart Pattern Alternate Straight Line Flow Chart Pattern
Cascade of if then
C-9
C Flowchart Reference
C-10
D
Background Information on
Basic Blocks and Signals
Basic Blocks
This document uses the term basic blocks to refer to blocks built into the
Simulink block libraries. The following table lists some examples of basic
blocks.
Basic Blocks
Block Example
Inport
Constant
Gain
Sum
Switch
Saturation
Abs
D-2
Signals and Signal Labels
You use signal labels to make model functionality more understandable from
the Simulink diagram. You can also use them to control the variable names
used in simulation and code generation. Enter signal names only once (at
the point of signal origination). Often, you may want to also display the
signal name elsewhere in the model. In these cases, the signal name should
be inherited until the signal is functionally transformed. (Passing a signal
through an integrator is functionally transforming. Passing a signal through
an Inport into a nested subsystem is not.) Once a named signal is functionally
transformed, associate a new name with it.
D-3
D Background Information on Basic Blocks and Signals
D-4
Glossary
MAAB Glossary
Actions
Actions are part of Stateflow diagram execution. The action can be
executed as part of a transition from one state to another, or depending
on the activity status of a state. Transitions can have condition actions
and transition actions. For example,
States can have entry, during, exit, and, on event_name actions. For
example,
The action language defines the categories of actions you can specify
and their associated notations. An action can be a function call, an
event to be broadcast, a variable to be assigned a value, and so on.
Glossary-1
MAAB Glossary
Action Language
Sometimes you want actions to take place as part of Stateflow diagram
execution. The action can be executed as part of a transition from one
state to another, or it can depend on the activity status of a state.
Transitions can have condition actions and transition actions. States
can have entry, during, exit, and, on event_name actions. An action
can be a function call, an event to be broadcast, a variable to be assigned
a value, etc.
The action language defines the categories of actions you can specify and
their associated notations. Violations of the action language notation
are flagged as errors by the parser. This section describes the action
language notation rules.
Chart Instance
A chart instance is a link from a Stateflow model to a chart stored
in a Simulink library. A chart in a library can have many chart
instances. Updating the chart in the library automatically updates all
the instances of that chart.
Condition
A condition is a Boolean expression to specify that a transition occur,
given that the specified expression is true. For example,
Connective Junction
Connective junctions are decision points in the system. A connective
junction is a graphical object that simplifies Stateflow diagram
Glossary-2
MAAB Glossary
Glossary-3
MAAB Glossary
Data
Data objects store numerical values for reference in the Stateflow
diagram.
Defining Data
A state machine can store and retrieve data that resides internally in
its own workspace. It can also access data that resides externally in the
Simulink model or application that embeds the state machine. When
creating a Stateflow model, you must define any internal or external
data referenced by the state machine’s actions.
Data Dictionary
The data dictionary is a database where Stateflow diagram information
is stored. When you create Stateflow diagram objects, the information
about those objects is stored in the data dictionary, once you save the
Stateflow diagram.
Decomposition
A state has decomposition when it consists of one or more substates.
A Stateflow diagram that contains at least one state also has
decomposition. Representing hierarchy necessitates some rules around
how states can be grouped in the hierarchy. A superstate has either
parallel (AND) or exclusive (OR) decomposition. All substates at a
particular level in the hierarchy must be of the same decomposition.
Glossary-4
MAAB Glossary
Default Transition
Default transitions are primarily used to specify which exclusive (OR)
state is to be entered when there is ambiguity among two or more
neighboring exclusive (OR) states. For example, default transitions
specify which substate of a superstate with exclusive (OR) decomposition
the system enters by default in the absence of any other information.
Default transitions are also used to specify that a junction should be
entered by default. A default transition is represented by selecting the
default transition object from the toolbar and then dropping it to attach
to a destination object. The default transition object is a transition with
a destination but no source object.
Events
Events drive the Stateflow diagram execution. Define all events that
affect the Stateflow diagram. The occurrence of an event causes the
status of the states in the Stateflow diagram to be evaluated. The
broadcast of an event can trigger a transition to occur and/or can trigger
an action to be executed. Events are broadcast in a top-down manner
starting from the event’s parent in the hierarchy.
Glossary-5
MAAB Glossary
Flow Graph
A flow graph is the set of Flowcharts that start from a transition
segment that, in turn, starts from a state or a default transition
segment.
Flow Subgraph
A flow subgraph is the set of Flowcharts that start on the same
transition segment.
Hierarchy
Using hierarchy you can organize complex systems by placing states
within other higher-level states. A hierarchical design usually reduces
the number of transitions and produces neat, more manageable
diagrams.
History Junction
A History Junction specifies the destination substate of a transition
based on historical information. If a superstate has a History Junction,
the transition to the destination substate is defined to be the substate
that was most recently visited. The History Junction applies to the level
of the hierarchy in which it appears.
Inner Transitions
An inner transition is a transition that does not exit the source state.
Inner transitions are most powerful when defined for superstates with
XOR decomposition. Use of inner transitions can greatly simplify a
Stateflow diagram.
Glossary-6
MAAB Glossary
Library Link
A library link is a link to a chart that is stored in a library model in
a Simulink block library.
Library Model
A Stateflow library model is a Stateflow model that is stored in a
Simulink library. You can include charts from a library in your model
by copying them. When you copy a chart from a library into your model,
Stateflow does not physically include the chart in your model. Instead,
it creates a link to the library chart. You can create multiple links to a
single chart. Each link is called a chart instance. When you include a
chart from a library in your model, you also include its state machine.
A Stateflow model that includes links to library charts has multiple
state machines. When Stateflow simulates a model that includes charts
from a library model, it includes all charts from the library model even
if there are links to only some of its models. However, when Stateflow
generates a stand-alone or Simulink Coder™ target, it includes only
those charts for which there are links. A model that includes links to a
library model can be simulated only if all charts in the library model are
free of parse and compile errors.
Machine
A machine is the collection of all Stateflow blocks defined by a Simulink
model exclusive of chart instances (library links). If a model includes
any library links, it also includes the state machines defined by the
models from which the links originate.
Nonvirtual Block
Blocks that perform a calculation, such as a Gain block.
Notation
A notation defines a set of objects and the rules that govern the
relationships between those objects. Stateflow notation provides a
common language to communicate the design information conveyed by a
Stateflow diagram. Stateflow notation consists of:
Glossary-7
MAAB Glossary
Parallelism
A system with parallelism can have two or more states that can be
active at the same time. The activity of parallel states is independent.
Parallelism is represented with a parallel (AND) state decomposition.
Real-Time System
A system that uses actual hardware to implement algorithms, for
example, digital signal processing or control applications.
Simulink Coder
Simulink Coder software includes an automatic C language code
generator for Simulink. It produces C code directly from Simulink block
diagram models and automatically builds programs that can be run in
real-time in a variety of environments.
S-function
A customized Simulink block written in C or MATLAB-code. S-functions
written in C can be inlined in the Simulink Coder software. When using
Simulink together with Stateflow for simulation, Stateflow generates
an S-function (MEX-file) for each Stateflow machine to support model
simulation. This generated code is a simulation target and is called
the S-Fun target within Stateflow.
Signal propagation
Process used by Simulink to determine attributes of signals and blocks,
such as data types, labels, sample time, dimensionality, and so on, that
are determined by connectivity.
Signal source
The signal source is the block of origin for a signal. The signal source
may or may not be the true source.
Simulink
Simulink is a software package for modeling, simulating, and analyzing
dynamic systems. It supports linear and nonlinear systems, modeled
in continuous time, sampled time, or a hybrid of the two. Systems can
Glossary-8
MAAB Glossary
also be multirate, that is, have different parts that are sampled or
updated at different rates.
State
A state describes a mode of a reactive system. A reactive system has
many possible states. States in a Stateflow diagram represent these
modes. The activity or inactivity of the states dynamically changes
based on events and conditions.
Stateflow Block
The Stateflow block is a masked Simulink model and is equivalent to an
empty, untitled Stateflow diagram. Use the Stateflow block to include a
Stateflow diagram in a Simulink model.
Glossary-9
MAAB Glossary
Stateflow Debugger
Use the Stateflow Debugger to debug and animate your Stateflow
diagrams. Each state in the Stateflow diagram simulation is evaluated
for overall code coverage. This coverage analysis is done automatically
when the target is compiled and built with the debug options. The
Debugger can also be used to perform dynamic checking. The Debugger
operates on the Stateflow machine.
Stateflow Diagram
Using Stateflow, you create Stateflow diagrams. A Stateflow diagram is
also a graphical representation of a finite state machine where states
and transitions form the basic building blocks of the system.
Stateflow Explorer
Use the Stateflow Explorer to add, remove, and modify data, event,
and target objects.
Stateflow Finder
Use the Finder to display a list of objects based on search criteria that
you specify. You can directly access the properties dialog box of any
object in the search output display by clicking on that object.
Substate
A state is a substate if it is contained by a superstate.
Glossary-10
MAAB Glossary
Superstate
A state is a superstate if it contains other states, called substates.
Target
An executable program built from code generated by Stateflow or
Simulink Coder software.
Top-down Processing
Top-down processing refers to the way in which Stateflow processes
states. In particular, Stateflow processes superstates before states.
Stateflow processes a state only if its superstate is activated first.
Transition
A transition describes the circumstances under which the system moves
from one state to another. Either end of a transition can be attached to
a source and a destination object. The source is where the transition
begins and the destination is where the transition ends. It is often the
occurrence of some event that causes a transition to take place.
Transition Path
A transition path is a Flowchart that starts and ends on a state.
Glossary-11
MAAB Glossary
Transition Segment
A transition segment is a single directed edge on a Stateflow diagram.
Transition segments are sometimes loosely referred to as transitions.
Tunable parameters
A tunable parameter is a parameter that can be adjusted in the model
and in generated code.
True Source
The true source is the block which creates a signal. The true source is
different from the signal source because the signal source may be a
simple routing block such as a Demux block.
Virtual Block
When creating models, be aware that Simulink blocks fall into two
basic categories: nonvirtual and virtual blocks. Nonvirtual blocks play
an active role in the simulation of a system. If you add or remove a
nonvirtual block, you change the model’s behavior. Virtual blocks, by
contrast, play no active role in the simulation. They help to organize
a model graphically. Some Simulink blocks can be virtual in some
circumstances and nonvirtual in others. Such blocks are called
conditionally virtual blocks. The following table lists Simulinks virtual
and conditionally virtual blocks.
Glossary-12
MAAB Glossary
Virtual Scrollbar
Using a virtual scrollbar, you can set a value by scrolling through a list
of choices. When you move the mouse over a menu item with a virtual
scrollbar, the cursor changes to a line with a double arrowhead. Virtual
scrollbars are either vertical or horizontal. The direction is indicated by
the positioning of the arrowheads. Drag the mouse either horizontally
or vertically to change the value.
Glossary-13