MAAB Control Algorithm Modeling Guidelines Using MATLAB Simulink and Stateflow
MAAB Control Algorithm Modeling Guidelines Using MATLAB Simulink and Stateflow
MAAB Control Algorithm Modeling Guidelines Using MATLAB Simulink and Stateflow
R2015a
How to Contact MathWorks
Phone: 508-647-7000
Introduction
1
Presentation of Guidelines Hosted by MathWorks . . . . . . . . 1-2
Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
Software Environment
2
General Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
v
Naming Conventions
3
General Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
Model Architecture
4
Simulink and Stateflow Partitioning . . . . . . . . . . . . . . . . . . . 4-2
Simulink
6
Diagram Appearance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2
Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-40
vi Contents
Stateflow
7
Chart Appearance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2
Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-56
Enumerated Data
8
General Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
MATLAB Functions
9
MATLAB Function Appearance . . . . . . . . . . . . . . . . . . . . . . . . 9-2
vii
Recommendations for Automation Tools
A
Guideline Writing
B
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
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-6
“Scope” on page 1-7
“MATLAB Versions” on page 1-8
“Prerequisites” on page 1-8
“Description” on page 1-9
“Rationale” on page 1-9
“Last Change” on page 1-10
“Model Advisor Check” on page 1-10
Guideline descriptions are documented, using the following template. Companies that
want to create additional guidelines are encouraged to use the same template.
1-5
1 Introduction
Model Title of and link to the corresponding Model Advisor check, if a check
Advisor exists
Check
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.
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:
1-6
Guideline Template
• Mandatory
• Strongly recommended
• Recommended
The priority describes the importance of the guideline and determines the consequences
of violations.
Scope
The scope of a guideline may be set to one of the following:
Scope Description
MAAB (MathWorks Automotive Advisory A group of automotive manufacturers and
Board) suppliers that work closely together with
1-7
1 Introduction
Scope Description
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.
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
RX, RY, or RZ A specific version of MATLAB
RX and earlier Versions of MATLAB until version RX
RX and later Versions of MATLAB from version RX to the current version
RX through RY Versions of MATLAB between RX and RY
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.
1-8
Guideline Template
Description
• This field contains a detailed description of the guideline.
• If needed, add images and tables.
Note: If formal notation (math, regular expression, syntax diagrams, and exact numbers/
limits) is available, use it to unambiguously describe a guideline and specify an
automated check. However, a human, understandable, informal description must always
be provided for daily reference.
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
1-9
1 Introduction
Rationale Description
Verification and Ability to verify and validate a model and generated code
validation with:
• Requirements traceability
• Testing
• Problem-free system integration
• Clean interfaces
Code generation Generation of code that is efficient and effective for
embedded systems
Last Change
The Last change field contains the document version number.
For a list of available Model Advisor checks for the MAAB guidelines, see “Model Advisor
Checks for MAAB Guidelines” on page 1-12. For information on using the Model
Advisor, see “Run Model Checks” in the Simulink documentation.
1-10
Document Usage
Document Usage
• Name Conventions and Model Architecture provide basic guidelines that apply to all
types of models.
• Simulink and Stateflow® provide specific rules for those environments.
• Some guidelines are dependent on other guidelines and are explicitly listed
throughout the document.
• If users do not view the content of masked subsystems with a model, the guidelines
for readability are not applicable.
1-11
1 Introduction
The MAAB guidelines and corresponding Model Advisor checks are summarized in the
following table. Not all guidelines have Model Advisor checks. For some of the guidelines
without Model Advisor checks, it is not possible to automate checking of the guideline.
Guidelines without a corresponding check are noted as not applicable. For information on
using the Model Advisor, see “Run Model Checks” in the Simulink documentation.
1-12
Model Advisor Checks for MAAB Guidelines
1-13
1 Introduction
1-14
Model Advisor Checks for MAAB Guidelines
1-15
1 Introduction
1-16
Model Advisor Checks for MAAB Guidelines
1-17
1 Introduction
1-18
Model Advisor Checks for MAAB Guidelines
1-19
1 Introduction
1-20
Model Advisor Checks for MAAB Guidelines
1-21
2
Software Environment
2 Software Environment
General Guidelines
• na_0026: Consistent software environment
• na_0027: Use of only standard library blocks
2-2
na_0026: Consistent software environment
ID: Title
na_0026: Consistent software environment
Priority
Recommended
Scope
NA-MAAB
MATLAB Versions
See description
Prerequisites
None
Description
During software development, it is recommended that a consistent software environment
is used across the project. Software includes, but is not limited, to:
• MATLAB
• Simulink
• C Compiler (for simulation)
2-3
2 Software Environment
Consistent software environment implies that the same version of the software is used
across the full project. The version number applies to any patches or extensions to the
software used by a group.
Rationale
• Readability
• Code Generation
See Also
• jh_0042: Required software
Last Changed
V3.0
2-4
na_0027: Use of only standard library blocks
ID: Title
na_0027: Use of only standard library blocks
Priority
Recommended
Scope
NA-MAAB
MATLAB Versions
All
Prerequisites
None
Description
Companies should specify a subset of Simulink blocks for use when developing models.
The block list can include custom block libraries developed by the company or third
parties. Models should be built only from these blocks.
Non-compliant blocks can be used during development. If non-compliant blocks are used,
they should be marked either with a color, icon and / or annotation. These blocks must be
removed prior to use in production code generation.
2-5
2 Software Environment
Rationale
• Readability
• Verification and Validation
• Code Generation
• Simulation
See Also
• hyl_0201: Use of standard library blocks only
Last Changed
V3.0
2-6
3
Naming Conventions
General Guidelines
• ar_0001: Filenames
• ar_0002: Directory names
• na_0035: Adoption of naming conventions
3-2
ar_0001: Filenames
ar_0001: Filenames
ID: Title
ar_0001: Filenames
Priority
Mandatory
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
A file name conforms to the following constraints:
Form
filename = name.extension
3-3
3 Naming Conventions
• extension: no blanks
Uniqueness
All file names within the parent project directory
Allowed Characters
name:
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789_
extension:
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789
Underscores
name:
extension:
Rationale
• Readability
• Workflow
• Code Generation
• Simulation
3-4
ar_0001: Filenames
Last Changed
V3.0
3-5
3 Naming Conventions
Priority
Mandatory
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
A directory name conforms to the following constraints:
Form
directory name = name
Uniqueness
All directory names within the parent project directory
3-6
ar_0002: Directory names
Allowed characters
name:
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789_
Underscores
name:
Rationale
• Readability
• Workflow
• Code Generation
• Simulation
Last Changed
V1.0
3-7
3 Naming Conventions
ID: Title
na_0035: Adoption of naming conventions
Priority
Recommended
Scope
NA-MAAB
MATLAB Versions
All
Prerequisites
None
Description
Adoption of a naming convention is recommended. A naming convention provides
guidance for naming blocks, signals, parameters and data types. Naming conventions
frequently cover issues such as:
• Length
3-8
na_0035: Adoption of naming conventions
• Use of symbols
• Readability
• Use of underscores
• Use of capitalization
• Encoding information
Rationale
• Readability
• Workflow
• Code Generation
• Simulation
Last Changed
V3.0
3-9
3 Naming Conventions
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
• na_0030: Usable characters for Simulink Bus names
• jc_0231: Usable characters for block names
• na_0014: Use of local language in Simulink and Stateflow
3-10
jc_0201: Usable characters for Subsystem names
ID: Title
jc_0201: Usable characters for Subsystem
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
The names of all Subsystem blocks should conform to the following constraints:
Form
name:
3-11
3 Naming Conventions
Allowed Characters
name:
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789_
Underscores
name:
Rationale
• Readability
Last Changed
V2.2
3-12
jc_0211: Usable characters for Inport blocks and Outport blocks
ID: Title
jc_0211: Usable characters for Inport blocks and Outport blocks
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
The names of all Inport blocks and Output blocks should conform to the following
constraints:
Form
name:
3-13
3 Naming Conventions
Allowed Characters
name:
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789_
Underscores
name:
Rationale
• Readability
Last Changed
V2.2
3-14
jc_0221: Usable characters for signal line names
ID: Title
jc_0221: Usable characters for signal line names
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
Identifies named signals constraints
Form
name:
3-15
3 Naming Conventions
Allowed Characters
name:
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789_
Underscores
name:
Rationale
• Readability
Last Changed
V2.2
3-16
na_0030: Usable characters for Simulink Bus names
ID: Title
na_0030: Usable characters for Simulink Bus names
Priority
Strongly recommended
Scope
NA-MAAB
MATLAB Versions
All
Prerequisites
None
Description
All Simulink Bus names should conform to the following constraints:
Form
name:
3-17
3 Naming Conventions
Allowed Characters
name:
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789_
Underscores
name:
Rationale
• Readability
See Also
• jh_0040: Usable characters for Simulink Bus Names
Last Changed
V3.0
3-18
jc_0231: Usable characters for block names
ID: Title
jc_0231: Usable characters for block names
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
jc_0201: Usable characters for Subsystem names
Description
The names of all blocks should conform to the following constraints:
Form
name:
3-19
3 Naming Conventions
Allowed Characters
name:
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789_
Rationale
• Readability
Last Changed
V2.0
3-20
na_0014: Use of local language in Simulink and Stateflow
ID: Title
na_0014: Use of local language in Simulink and Stateflow
Priority
Strongly recommended
Scope
J-MAAB
MATLAB Versions
All
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.
3-21
3 Naming Conventions
Simulink Examples
• The Description field in the Block Properties dialog box
Stateflow Examples
• The Description field of chart and state Properties
3-22
na_0014: Use of local language in Simulink and Stateflow
3-23
3 Naming Conventions
Note: It is possible that Simulink cannot open a model that includes local language
on different character encoding systems. Therefore, pay attention when using local
characters for exchanging models between countries.
Rationale
• Readability
Last Changed
V2.0
3-24
4
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 lists some examples of basic
blocks.
4 Model Architecture
4-2
na_0006: Guidelines for mixed use of Simulink and Stateflow
ID: Title
na_0006: Guidelines for mixed use of Simulink and Stateflow
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
The choice of whether to use Simulink or Stateflow to model a given portion of the control
algorithm functionality should be driven by the nature of the behavior being modeled.
4-3
4 Model Architecture
Use Stateflow diagrams to implement modal logic, where the control function to be
performed at the current time depends on a combination of past and present logical
conditions.
• If the function primarily involves numerical operations, use Simulink features.
Specifics
• If the primary nature of the function is logical, but some simple numerical
calculations are done to support the logic, implement the simple numerical functions
using the Stateflow action language.
• If the primary nature of the function is numeric, but some simple logical operations
are done to support the arithmetic, implement the simple logical functions with
Simulink blocks.
4-4
na_0006: Guidelines for mixed use of Simulink and Stateflow
• If the primary nature of the function is logical, and some complicated numerical
calculations must be done to support the logic, use a Simulink subsystem to
implement the numerical calculations. The Stateflow software should invoke the
execution of the subsystem, using a function call.
4-5
4 Model Architecture
4-6
na_0006: Guidelines for mixed use of Simulink and Stateflow
• Use the Stateflow product to implement modal logic, where the control function
to be performed at the current time depends on a combination of past and present
logical conditions. (If there is a need to store the result of a logical condition test in a
Simulink model, for example, by storing a flag, this is an indicator of the presence of
modal logic, which should be modeled with Stateflow software.)
4-7
4 Model Architecture
Incorrect
4-8
na_0006: Guidelines for mixed use of Simulink and Stateflow
Correct
• Use Simulink to implement numerical expressions containing continuously-valued
states, such as: difference equations, integrals, derivatives, and filters.
4-9
4 Model Architecture
Incorrect
Correct
4-10
na_0006: Guidelines for mixed use of Simulink and Stateflow
Rationale
• Readability
• Workflow
• Simulation
• Verification and Validation
• Code Generation
See Also
• “Driving Function Call Subsystems and Charts from Stateflow® Using Function Call
Outputs”
Last Changed
V2.0
4-11
4 Model Architecture
ID: Title
na_0007: Guidelines for use of Flow Charts, Truth Tables and State Machines
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
na_0006: Guidelines for mixed use of Simulink and Stateflow
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.
4-12
na_0007: Guidelines for use of Flow Charts, Truth Tables and State Machines
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 “Flow Chart Patterns” on page 7-71.)
Rationale
• Readability
• Workflow
• Simulation
• Verification and Validation
• Code Generation
Last Changed
V2.0
4-13
4 Model Architecture
Subsystem Hierarchies
• db_0143: Similar block types on the model levels
• db_0144: Use of Subsystems
• db_0040: Model hierarchy
• na_0037: Use of single variable variant conditionals
• na_0020: Number of inputs to variant subsystems
• na_0036: Default variant
4-14
db_0143: Similar block types on the model levels
ID: Title
db_0143: Similar block types on the model levels
Priority
Strongly recommended
Scope
NA-MAAB
MATLAB Versions
All
Prerequisites
None
Description
To allow partitioning of the model into discrete 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.
4-15
4 Model Architecture
Block Example
Action port1
Bus Creator
Bus Selector
Case
Demux
Enable2
From
Function-Call Generator
4-16
db_0143: Similar block types on the model levels
Block Example
Function-Call Split
Goto
Ground
If
Inport
Merge
Mux
Outport
Rate Transition
Selector
Terminator
4-17
4 Model Architecture
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 Changed
V2.2
For check details, see “Check for mixing basic blocks and subsystems”.
4-18
db_0144: Use of Subsystems
ID: Title
db_0144: Use of Subsystems
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
Blocks in a Simulink diagram should be grouped together into subsystems based on
functional decomposition of the algorithm, or portion thereof, represented in the diagram.
Grouping blocks into subsystems primarily for the purpose of saving space in the
diagram should be avoided. Each subsystem in the diagram should represent a unit of
functionality required to accomplish the purpose of the model or submodel. Blocks can
also be grouped together based on behavioral variants or timing.
4-19
4 Model Architecture
Rationale
• Readability
• Workflow
• Verification and Validation
• Code Generation
Last Changed
V2.2
4-20
db_0040: Model hierarchy
ID: Title
db_0040: Model hierarchy
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
The model hierarchy should correspond to the functional structure of the control system.
Rationale
• Readability
4-21
4 Model Architecture
• Workflow
• Verification and Validation
• Code Generation
Last Changed
V2.0
4-22
na_0037: Use of single variable variant conditionals
ID: Title
na_0037: Use of single variable variant conditionals
Priority
Recommended
Scope
NA-MAAB
MATLAB Versions
All
Prerequisites
None
Description
Variant conditional expressions should be composed using either a single variable with
compound conditions or multiple variables with a single condition. The default variant is
an exception to the second rule.
Correct: Multiple variables (INLINE / FUNCTION with single condition per line
4-23
4 Model Architecture
Note
Use of enumerated variables is preferred in the Condition expressions. To improve the
readability of the screenshots used in the examples, numerical values were used.
Rationale
• Readability
• Code Generation
• Simulation
See Also
• na_0036: Default variant
4-24
na_0037: Use of single variable variant conditionals
Last Changed
V3.0
4-25
4 Model Architecture
ID: Title
na_0020: Number of inputs to variant subsystems
Priority
Recommended
Scope
NA-MAAB
MATLAB Versions
All
Prerequisites
None
Description
Simulink requires variant subsystems to have the same number of inputs. However,
the variant subsystem might not use all of the inputs. In these instances, terminate the
unused inputs with the Terminator block.
Rationale
• Readability
4-26
na_0020: Number of inputs to variant subsystems
• Code Generation
• Simulation
Last Changed
V3.0
4-27
4 Model Architecture
ID: Title
na_0036: Default variant
Priority
Recommended
Scope
NA-MAAB
MATLAB Versions
All
Prerequisites
na_0037: Use of single variable variant conditionals
Description
All Variant subsystems and models should be configured so that one subsystem is always
selected. This can be achieved by doing one of the following:
4-28
na_0036: Default variant
Correct
Rationale
• Readability
• Code Generation
• Simulation
Last Changed
V3.0
4-29
4 Model Architecture
4-30
jc_0301: Controller model
ID: Title
jc_0301: Controller model
Priority
Mandatory
Scope
J-MAAB
MATLAB Versions
All
Prerequisites
None
Description
Control models are organized using the following hierarchical structure. Details on each
layer are provided in corresponding rules.
4-31
4 Model Architecture
Use of the Trigger level is optional. In the following figure, Type A shows the use of a
trigger level while Type B shows a model without a trigger level.
Controller Model
Rationale
Workflow
Last Changed
V2.0
4-32
jc_0311: Top layer/root level
ID: Title
jc_0311: Top layer/root level
Priority
Mandatory
Scope
J-MAAB
MATLAB Versions
All
Prerequisites
None
Description
Items to describe in a top layer are as follows:
4-33
4 Model Architecture
Rationale
Workflow
Last Changed
V2.0
4-34
jc_0321: Trigger layer
ID: Title
jc_0321: Trigger layer
Priority
Mandatory
Scope
J-MAAB
MATLAB Versions
All
Prerequisites
None
Description
A trigger layer indicates the processing timing by using Triggered Subsystem or
Function-Call Subsystem blocks.
4-35
4 Model Architecture
Rationale
• Readability
• Workflow
• Code Generation
Last Changed
V2.0
4-36
jc_0331: Structure layer
ID: Title
jc_0331: Structure layer
Priority
Mandatory
Scope
J-MAAB
MATLAB Versions
All
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.
4-37
4 Model Architecture
Rationale
• Readability
4-38
jc_0331: Structure layer
• Workflow
• Code Generation
Last Changed
V2.0
4-39
4 Model Architecture
ID: Title
jc_0341: Data flow layer
Priority
Mandatory
Scope
J-MAAB
MATLAB Versions
All
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.
4-40
jc_0341: Data flow layer
Rationale
Workflow
Last Changed
V2.0
4-41
5
5-2
jc_0011: Optimization parameters for Boolean data types
ID: Title
jc_0011: Optimization parameters for Boolean data types
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
na_0002: Appropriate implementation of fundamental logical and numerical operations
Description
The optimization option for Boolean data types must be enabled (on).
5-3
5 Model Configuration Options
Rationale
• Workflow
• Code Generation
Last Changed
V2.2
For check details, see “Check Implement logic signals as Boolean data (vs. double)”.
5-4
jc_0021: Model diagnostic settings
ID: Title
jc_0021: Model diagnostic settings
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
The following diagnostics must be enabled. An enabled diagnostic is set to warning or
error. Setting the diagnostic option to none is not permitted. Diagnostics that are not
listed may be set to any value (none, warning, or error).
Solver Diagnostics
• Algebraic loop
5-5
5 Model Configuration Options
Connectivity
• Unconnected block input ports
• Unconnected block output ports
• Unconnected line
• Unspecified bus object at root Outport block
• Mux blocks used to create bus signals
• Invalid function-call connection
• Element name mismatch
Rationale
• Workflow
• Code Generation
Last Changed
V2.0
5-6
jc_0021: Model diagnostic settings
5-7
6
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
• na_0032: Use of merge blocks
• jm_0010: Port block names in Simulink models
• jc_0281: Naming of Trigger Port block and Enable Port block
6-2
na_0004: Simulink model appearance
ID: Title
na_0004: Simulink model appearance
Priority
Recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
The model appearance settings should conform to the following guidelines when the
model is released. You can change the settings during the development process.
6-3
6 Simulink
Rationale
• Readability
Last Changed
V2.0
6-4
na_0004: Simulink model appearance
For check details, see “Check for Simulink diagrams using nonstandard display
attributes”.
6-5
6 Simulink
ID: Title
db_0043: Simulink font and font size
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
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).
6-6
db_0043: Simulink font and font size
Rationale
• Readability
Last Changed
V2.0
6-7
6 Simulink
ID: Title
db_0042: Port block in Simulink models
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
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.
6-8
db_0042: Port block in Simulink models
• You may use duplicate Inport blocks at the subsystem level, if required, but avoid
doing so, if possible.
Correct
Incorrect
• Inport 2 should be moved in so it does not cross the feedback loop lines.
• Outport 1 should be moved to the right side of the diagram.
6-9
6 Simulink
Rationale
Readability
Last Changed
V2.0
6-10
na_0005: Port block name visibility in Simulink models
ID: Title
na_0005: Port block name visibility in Simulink models
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
For some items it is not possible to define a single approach that is applicable to
all organizations’ internal processes. However, it is important that within a given
organization, a single consistent approach is followed. An organization applying the
guidelines must enforce one of the following alternatives.
6-11
6 Simulink
• The name of an Inport or Outport block is not hidden. (Format > Hide Name is not
allowed.)
• The name of an Inport or Outport block must be hidden. (Format > Hide Name is
used.)
Rationale
Readability
Last Changed
V2.0
6-12
na_0005: Port block name visibility in Simulink models
6-13
6 Simulink
ID: Title
jc_0081: Icon display for Port block
Priority
Recommended
Scope
MAAB
MATLAB Versions
R14 and later
Prerequisites
None
Description
The Icon display setting should be set to Port number for Inport and Outport blocks.
Correct
6-14
jc_0081: Icon display for Port block
Incorrect
Incorrect
Rationale
Readability
Last Changed
V2.2
6-15
6 Simulink
ID: Title
jm_0002: Block resizing
Priority
Mandatory
Scope
MAAB
MATLAB Versions
All
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
6-16
jm_0002: Block resizing
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
Incorrect
Rationale
Readability
Last Changed
V2.0
6-17
6 Simulink
ID: Title
db_0142: Position of block names
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
If shown, place the name of a block below the block.
Correct
6-18
db_0142: Position of block names
Incorrect
Rationale
• Readability
Last Changed
V2.0
For check details, see “Check whether block names appear below blocks”.
6-19
6 Simulink
ID: Title
jc_0061: Display of block names
Priority
Recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
• Display a block name when it provides descriptive information.
• Do not display a block name if the block function is known and understood from the
block appearance.
Rationale
Readability
6-20
jc_0061: Display of block names
Last Changed
V2.0
For check details, see “Check the display attributes of block names”.
6-21
6 Simulink
ID: Title
db_0146: Triggered, enabled, conditional Subsystems
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
The blocks that define subsystems as either conditional or iterative should be located at a
consistent location at the top of the subsystem diagram. These blocks are:
• Action Port
• Enable
• For Iterator
6-22
db_0146: Triggered, enabled, conditional Subsystems
Note: The Action Port is associated with the If and Case blocks. The Trigger port is also
the function-call block.
Correct
Incorrect
Rationale
• Readability
Last Changed
V2.2
6-23
6 Simulink
For check details, see “Check position of Trigger and Enable blocks”.
6-24
db_0140: Display of basic block parameters
ID: Title
db_0140: Display of basic block parameters
Priority
Recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
Important block parameters modified from the default values should be displayed.
Note: The attribute string is one method to support the display of block parameters. The
block annotation tab allows you to add the desired attribute information. As of R2011b,
masking basic blocks is a supported method for displaying the information. This method
is allowed if the base icon is distinguishable.
6-25
6 Simulink
Correct
Rationale
• Readability
Last Changed
V2.2
6-26
db_0032: Simulink signal appearance
ID: Title
db_0032: Simulink signal appearance
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
Signal lines
6-27
6 Simulink
• Should not split into more than two sublines at a single branching point
Correct
Incorrect
Rationale
• Readability
Last Changed
V2.0
6-28
db_0141: Signal flow in Simulink models
ID: Title
db_0141: Signal flow in Simulink models
Priority
Strongly recommended
Scope
MAAB
Versions
All
Prerequisites
None
Description
The signal flow in a model is from left to right.
6-29
6 Simulink
Rationale
• Readability
Last Changed
V2.0
6-30
jc_0171: Maintaining signal flow when using Goto and From blocks
ID: Title
jc_0171: Maintaining signal flow when using Goto and From blocks
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
• You must maintain visual depiction of signal flow between subsystems.
• You can use Goto and From blocks if:
6-31
6 Simulink
Correct
6-32
jc_0171: Maintaining signal flow when using Goto and From blocks
Incorrect
Rationale
• Readability
Last Changed
V2.2
6-33
6 Simulink
ID: Title
na_0032: Use of merge blocks
Priority
Strongly recommended
Scope
NA-MAAB
MATLAB Versions
All
Prerequisites
None
Description
When using Merge blocks:
• Signals entering a merge block must not branch off to other blocks
• With buses:
• Number of elements
6-34
na_0032: Use of merge blocks
• Element names
• Element order
• Element data type
• Element size
• Buses must be either all virtual or all nonvirtual
• Bus lines entering a merge block must not branch off to other blocks.
Rationale
• Workflow
• Code Generation
Last Changed
V3.0
6-35
6 Simulink
ID: Title
jm_0010: Port block names in Simulink models
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
• db_0042: Port block in Simulink models
• na_0005: Port block name visibility in Simulink models
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:
6-36
jm_0010: Port block names in Simulink models
Exceptions:
• When any combination of an Inport block, an Outport block, and any other block
have the same block name, use a suffix or prefix on the Inport and Outport blocks.
• One common suffix / prefix is _in for Inport blocks and _out for Outport blocks.
• You may use any suffix or prefix on the ports, however, the prefix that you select
must be consistent.
• Library blocks and reusable subsystems that encapsulate generic functionality.
• When names of Inport and Outport blocks are hidden, apply a consistent
naming practice for the blocks. Suggested practices include leaving the default
names (for example, Out1), giving them the same name as the associated signal, or
giving them a shortened or mangled version of the name of the associated signal.
Rationale
• Readability
• Workflow
• Code Generation
• Simulation
Last Changed
V2.0
For check details, see “Check for matching port and signal names”.
6-37
6 Simulink
ID: Title
jc_0281: Naming of Trigger Port block and Enable Port block
Priority
Strongly recommended
Scope
J-MAAB
MATLAB Versions
All
Prerequisites
None
Description
For Trigger and Enable port blocks, match the block name of the signal triggering the
subsystem.
6-38
jc_0281: Naming of Trigger Port block and Enable Port block
Rationale
• Readability
• Code Generation
Last Changed
V2.0
For check details, see “Check Trigger and Enable block names”.
6-39
6 Simulink
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
The preceding guidelines apply to signals and signal labels. For background information,
see “Signals and Signal Labels” on page D-3.
Some of the preceding guidelines refer to basic blocks. For an explanation of the meaning
and some examples, see “Basic Blocks” on page D-2.
6-40
na_0008: Display of labels on signals
ID: Title
na_0008: Display of labels on signals
Priority
Recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
• A label must be displayed on a signal originating from the following blocks:
• Inport block
• From block (block icon exception applies – see the following Note
• Subsystem block or Stateflow chart block (block icon exception applies)
• Bus Selector block (the tool forces this to happen)
6-41
6 Simulink
• Demux block
• Selector block
• Data Store Read block (block icon exception applies)
• Constant block (block icon exception applies)
• A label must be displayed on any signal connected to the following destination blocks
(directly or by way of a basic block that performs a nontransformative operation):
• Outport block
• Goto block
• Data Store Write block
• Bus Creator block
• Mux block
• Subsystem block
• Chart block
Note: Block icon exception (applicable only where called out): If the signal label
is visible in the originating block icon display, the connected signal does not need
to have the label displayed, unless the signal label is needed elsewhere due to a
destination-based rule.
Correct
Incorrect
6-42
na_0008: Display of labels on signals
Rationale
• Readability
• Verification and Validation
• Workflow
• Verification and Validation
• Code Generation
Last Changed
V2.2
6-43
6 Simulink
ID: Title
na_0009: Entry versus propagation of signal labels
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
na_0008: Display of labels on signals
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).
6-44
na_0009: Entry versus propagation of signal labels
• Originate from a basic block that performs a transformative operation (For the
purpose of interpreting this rule only, the Bus Creator block, Mux block, and
Selector block are considered to be included among the blocks that perform
transformative operations.)
• Any displayed signal label must be propagated for signals that:
Rationale
• Readability
• Verification and Validation
6-45
6 Simulink
• Workflow
• Verification and Validation
• Code Generation
Last Changed
V2.0
6-46
db_0097: Position of labels for signals and busses
ID: Title
db_0097: Position of labels for signals and busses
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
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.
6-47
6 Simulink
Rationale
• Readability
Last Changed
V2.0
6-48
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 Versions
All
Prerequisites
None
Description
A system must not have any:
6-49
6 Simulink
In addition:
Rationale
• Readability
• Workflow
• Verification and Validation
Last Changed
V2.0
For check details, see “Check for unconnected ports and signal lines”.
6-50
Block Usage
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
Some of the preceding guidelines refer to basic blocks. For an explanation of the meaning
and some examples, see “Basic Blocks” on page D-2.
6-51
6 Simulink
ID: Title
na_0003: Simple logical expressions in If Condition block
Priority
Mandatory
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
A logical expression may be implemented within an If Condition block instead of building
it up with logical operation blocks, if the expression contains two or fewer primary
expressions. A primary expression is defined as one of the following:
• An input
6-52
na_0003: Simple logical expressions in If Condition block
• 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
• u1 || u2
• (u1 > 0) && (u1 < 20)
6-53
6 Simulink
Rationale
• Readability
• Workflow
• Code Generation
Last Changed
V2.2
6-54
na_0002: Appropriate implementation of fundamental logical and numerical operations
ID: Title
na_0002: Appropriate implementation of fundamental logical and numerical operations
Priority
Mandatory
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
• Blocks that are intended to perform numerical operations must not be used to perform
logical operations.
6-55
6 Simulink
Incorrect
• A logical output should never be connected directly to the input of blocks that operate
on numerical inputs.
• The result of a logical expression fragment should never be operated on by a
numerical operator.
Incorrect
• Blocks that are intended to perform logical operations must not be used to perform
numerical operations.
• A numerical output should never be connected to the input of blocks that operate on
logical inputs.
6-56
na_0002: Appropriate implementation of fundamental logical and numerical operations
Incorrect
Rationale
• Readability
• Verification and Validation
• Workflow
• Code Generation
Last Changed
V3.0
6-57
6 Simulink
ID: Title
jm_0001: Prohibited Simulink standard blocks inside controllers
Priority
Mandatory
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
• Controller models must be designed from discrete blocks.
• MathWorks “Simulink Block Data Type Support” table provides a list of blocks that
support production code generation. See “Simulink Block Data Type Support”.
6-58
jm_0001: Prohibited Simulink standard blocks inside controllers
Band-Limited White
Random Number
Noise
Uniform Random
Pulse Generator
Number
Sine Wave
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
Complex to Interpreted
Magnitude-Angle MATLAB Function
Magnitude-Angle to
Goto Tag Visibility
Complex
Complex to Real-
Probe
Imag
6-59
6 Simulink
Rationale
• Readability
• Verification and Validation
• Workflow
• Code Generation
• Simulation
Last Changed
V2.2
For check details, see “Check for blocks not recommended for C/C++ production code
deployment”.
• By Task > Modeling Standards for MAAB > Simulink > Check for blocks that
are not discrete
For check details, see “Check for prohibited blocks in discrete controllers”.
6-60
hd_0001: Prohibited Simulink sinks
ID: Title
hd_0001: Prohibited Simulink sinks
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
Controller models must be designed from discrete blocks.
To File Stop
Simulation
6-61
6 Simulink
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
• Verification and Validation
• Code Generation
• Simulation
Last Changed
V2.2
6-62
na_0011: Scope of Goto and From blocks
ID: Title
na_0011: Scope of Goto and From blocks
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
For signal flows, the following rules apply:
6-63
6 Simulink
• 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.
Rationale
• Readability
• Verification and Validation
• Workflow
• Code Generation
• Simulation
Last Changed
V2.2
6-64
na_0011: Scope of Goto and From blocks
For check details, see “Check scope of From and Goto blocks”.
6-65
6 Simulink
ID: Title
jc_0141: Use of the Switch block
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
• The switch condition, input 2, must be a Boolean value.
• The block parameter, Criteria for passing first input, should be set to u2~=0.
6-66
jc_0141: Use of the Switch block
Correct
Incorrect
Rationale
• Readability
• Verification and Validation
• Workflow
6-67
6 Simulink
• Code Generation
Last Changed
V2.2
6-68
jc_0121: Use of the Sum block
ID: Title
jc_0121: Use of the Sum block
Priority
Recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
Sum blocks should:
6-69
6 Simulink
Correct
Incorrect
6-70
jc_0121: Use of the Sum block
Correct
Incorrect
6-71
6 Simulink
Correct
Incorrect
Rationale
Readability
Last Changed
V2.0
6-72
jc_0131: Use of Relational Operator block
ID: Title
jc_0131: Use of Relational Operator block
Priority
Recommended
Scope
J-MAAB
MATLAB Versions
All
Prerequisites
None
Description
When the relational operator is used to compare a signal to a constant value, the
constant input should be the second (lower) input signal.
6-73
6 Simulink
Correct
Incorrect
Rationale
• Readability
Last Changed
V2.0
6-74
jc_0161: Use of Data Store Read/Write/Memory blocks
ID: Title
jc_0161: Use of Data Store Read/Write/Memory blocks
Priority
Strongly recommended
Scope
J-MAAB
MATLAB Versions
All
Prerequisites
jc_0341: Data flow layer
Description
Data Store Memory, Data Store Read, and Data Store Write blocks are
6-75
6 Simulink
Rationale
• Readability
• Workflow
Last Changed
V2.0
6-76
Block Parameters
Block Parameters
• db_0112: Indexing
• na_0010: Grouping data flows into signals
• db_0110: Tunable parameters in basic blocks
Some of the preceding guidelines refer to basic blocks. For an explanation of the meaning
and some examples, see “Basic Blocks” on page D-2.
6-77
6 Simulink
db_0112: Indexing
ID: Title
db_0112: Indexing
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
Use a consistent vector indexing method for all blocks.
When possible, use zero-based indexing to improve code efficiency. However, since
MATLAB blocks do not support zero-based indexing, one-based indexing can be used for
models containing MATLAB blocks.
6-78
db_0112: Indexing
See Also
• “cgsl_0101: Zero-based indexing”
• “hisl_0021: Consistent vector indexing method”
Rationale
• Readability
• Verification and Validation
• Code Generation
Last Changed
V2.2
6-79
6 Simulink
ID: Title
na_0010: Grouping data flows into signals
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
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.
6-80
na_0010: Grouping data flows into signals
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:
6-81
6 Simulink
Rationale
• Readability
• Code Generation
Last Changed
V2.0
For check details, see “Check usage of buses and Mux blocks”.
6-82
db_0110: Tunable parameters in basic blocks
ID: Title
db_0110: Tunable parameters in basic blocks
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
To ensure that a parameter is tunable, enter it in a block dialog field:
6-83
6 Simulink
Correct
Incorrect
Rationale
• Readability
• Verification and Validation
• Workflow
• Code Generation
• Simulation
Last Changed
V2.2
6-84
Simulink Patterns
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
• na_0028: Use of If-Then-Else Action Subsystem to Replace Multiple Switches
• 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
The preceding guidelines illustrate sample patterns used in Simulink diagrams. As such,
the patterns normally would be part of a much larger Simulink diagram.
Some of the preceding guidelines refer to basic blocks. For an explanation of the meaning
and some examples, see “Basic Blocks” on page D-2.
6-85
6 Simulink
ID: Title
na_0012: Use of Switch vs. If-Then-Else Action Subsystem
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
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.
6-86
na_0012: Use of Switch vs. If-Then-Else Action Subsystem
• Should be used for modeling if-then-else structures, if the associated then and/or else
actions require complicated computations. This maximizes simulation efficiency and
the efficiency of generated code. (Note that even a basic block, for example a table
lookup, may require fairly complicated computations.)
• Must be used for modeling if-then-else structures, if the purpose of the construct is to
avoid an undesirable numerical computation, such as division by zero.
• Should be used for modeling if-then-else structures, if the explicit or implied then or
the else action is just to hold the associated output values.
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.
6-87
6 Simulink
Rationale
• Readability
• Verification and Validation
• Workflow
Last Changed
V2.0
6-88
db_0114: Simulink patterns for If-then-else-if constructs
ID: Title
db_0114: Simulink patterns for If-then-else-if constructs
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
Use the following patterns for If-then-else-if constructs within a Simulink model:
6-89
6 Simulink
if (If_Condition) {
output_signal = If_Value;
}
else if (Else_If_Condition) {
output_signal =
Else_If_Value;
}
else {
output_signal =
Else_Value;
}
if(Fault_1_Active &
Fault_2_Active)
{
ErrMsg = SaftyCrit;
}
else if (Fault_1_Active |
Fault_2_Active)
{
ErrMsg = DriveWarn;
}
else
{
ErrMsg = NoFaults;
}
Rationale
• Readability
Last Changed
V2.0
6-90
db_0114: Simulink patterns for If-then-else-if constructs
6-91
6 Simulink
ID: Title
db_0115: Simulink patterns for case constructs
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
Use the following patterns for case constructs within a Simulink model:
6-92
db_0115: Simulink patterns for case constructs
switch (PRNDL_Enum)
{
case 1
TqEstimate = ParkV;
break;
case 2
TqEstimae = RevV;
break;
default
TqEstimate = NeutralV;
break;
}
Rationale
• Readability
Last Changed
V2.2
6-93
6 Simulink
ID: Title
na_0028: Use of If-Then-Else Action Subsystem to Replace Multiple Switches
Priority
Recommended
Scope
NA-MAAB
MATLAB Versions
All
Prerequisites
• na_0012: Use of Switch vs. If-Then-Else Action Subsystem
• db_0144: Use of Subsystems
Description
The use of switch constructs should be limited, typically to 3 levels. Replace switch
constructs that have more than 3 levels with an If-Then-Else action subsystem construct.
6-94
na_0028: Use of If-Then-Else Action Subsystem to Replace Multiple Switches
Incorrect
6-95
6 Simulink
Rationale
• Readability
Last Changed
V3.0
6-96
db_0116: Simulink patterns for logical constructs with logical blocks
ID: Title
db_0116: Simulink patterns for logical constructs with logical blocks
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
Use the following patterns for logical combinations within Simulink:
6-97
6 Simulink
Rationale
• Readability
6-98
db_0116: Simulink patterns for logical constructs with logical blocks
Last Changed
V1.0
6-99
6 Simulink
ID: Title
db_0117: Simulink patterns for vector signals
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
Simulink is a vectorizable modeling language allowing for the direct processing of vector
data. Use the following patterns for vector signals within a Simulink model:
6-100
db_0117: Simulink patterns for vector signals
6-101
6 Simulink
6-102
db_0117: Simulink patterns for vector signals
Rationale
• Readability
• Verification and Validation
• Code Generation
Last Changed
V2.2
6-103
6 Simulink
6-104
jc_0351: Methods of initialization
ID: Title
jc_0351: Methods of initialization
Priority
Recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
db_0140: Display of basic block parameters
Description
Simple Initialization
• Blocks such as Unit Delay, which have an initial value field, can be used to set simple
initial values.
6-105
6 Simulink
• To determine if the initial value needs to be displayed, see MAAB Guideline db_0140:
Display of basic block parameters.
Example
Complex initialization may be done at a local level (Example A), at a global level
(Example B), or a combination of local and global.
Example A
6-106
jc_0351: Methods of initialization
Example B
Or
Rationale
• Readability
• Code Generation
Last Changed
V2.2
6-107
6 Simulink
6-108
jc_0111: Direction of Subsystem
ID: Title
jc_0111: Direction of Subsystem
Priority
Strongly recommended
Scope
J-MAAB
MATLAB Versions
All
Prerequisites
None
Description
Subsystem must not be reversed.
6-109
6 Simulink
Correct
Incorrect
Rationale
Readability
Last Changed
V2.0
6-110
jc_0111: Direction of Subsystem
6-111
7
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 flow charts
• db_0132: Transitions in flow charts
• 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
7-2
db_0123: Stateflow port names
ID: Title
db_0123: Stateflow port names
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
The name of a Stateflow input or output should be the same as the corresponding signal.
Rationale
• Readability
7-3
7 Stateflow
• Code Generation
Last Changed
V1.0
For check details, see “Check for mismatches between names of Stateflow ports and
associated signals”.
7-4
db_0129: Stateflow transition appearance
ID: Title
db_0129: Stateflow transition appearance
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
Transitions in Stateflow:
7-5
7 Stateflow
Correct
7-6
db_0129: Stateflow transition appearance
Incorrect: Transitions cross each other and transition crosses through state
Rationale
• Readability
Last Changed
V2.2
7-7
7 Stateflow
ID: Title
db_0137: States in state machines
Priority
Mandatory
Scope
MAAB
MATLAB Versions
All
Prerequisites
db_0149: Flow chart patterns for condition actions
Description
For all levels in a state machine, including the root level, for states with exclusive
decomposition the following rules apply:
7-8
db_0137: States in state machines
Rationale
• Readability
• Workflow
• Code Generation
• Verification and Validation
Last Changed
V3.0
For check details, see “Check usage of exclusive and default states in state machines”.
7-9
7 Stateflow
ID: Title
db_0133: Use of patterns for flow charts
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
A flow chart is built with the help of flow chart patterns (for example, if-then-else,
for loop, and so on):
7-10
db_0133: Use of patterns for flow charts
Rationale
• Readability
Last Changed
V2.2
7-11
7 Stateflow
ID: Title
db_0132: Transitions in flow charts
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
The following rules apply to transitions in flow charts:
7-12
db_0132: Transitions in flow charts
Empty Transition
Transition actions are not used in flow charts. Transition actions are only valid when
used in transitions between states in a state machine, otherwise they are not activated
because of the inherent dependency on a valid state to state transition to activate them.
Transition Action
7-13
7 Stateflow
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.
Rationale
• Readability
Last Changed
V2.0
7-14
db_0132: Transitions in flow charts
7-15
7 Stateflow
ID: Title
jc_0501: Format of entries in a State block
Priority
Recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
A new line should:
• Start after the entry (en), during (du), and exit (ex) statements.
• Start after the completion of an assignment statement “;”.
7-16
jc_0501: Format of entries in a State block
Correct
Incorrect
7-17
7 Stateflow
Incorrect
Failed to start a new line after the completion of an assignment statement “;”.
Rationale
Readability
Last Changed
V2.0
For check details, see “Check entry formatting in State blocks in Stateflow charts”.
7-18
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 Versions
All
Prerequisites
None
Description
The return value from a graphical function must be set in only one place.
7-19
7 Stateflow
Correct
Incorrect
Rationale
• Readability
• Verification and Validation
• Code Generation
7-20
jc_0511: Setting the return value from a graphical function
Last Changed
V2.0
For check details, see “Check return value assignments of graphical functions in
Stateflow charts”.
7-21
7 Stateflow
ID: Title
jc_0531: Placement of the default transition
Priority
Recommended
Scope
J-MAAB
MATLAB Versions
All
Prerequisites
None
Description
• Default transition is connected at the top of the state.
• The destination state of the default transition is put above the other states in the
same hierarchy.
7-22
jc_0531: Placement of the default transition
Correct
Incorrect
7-23
7 Stateflow
Rationale
Readability
Last Changed
V2.0
For check details, see “Check default transition placement in Stateflow charts”.
7-24
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 Versions
All
Prerequisites
None
Description
The return value from a graphical function should not be used directly in a comparison
operation.
7-25
7 Stateflow
Correct
Incorrect
Rationale
• Readability
• Verification and Validation
• Code Generation
Last Changed
V2.0
7-26
jc_0521: Use of the return value from graphical functions
For check details, see “Check usage of return values from a graphical function in
Stateflow charts”.
7-27
7 Stateflow
7-28
na_0001: Bitwise Stateflow operators
ID: Title
na_0001: Bitwise Stateflow operators
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
The bitwise Stateflow operators (&, |, and ^) should not be used in Stateflow charts
unless you want bitwise operations:
7-29
7 Stateflow
Correct
Use && and || for Boolean operation.
7-30
na_0001: Bitwise Stateflow operators
Incorrect
Use & and | for Boolean operation.
Rationale
• Readability
• Verification and Validation
• Code Generation
Last Changed
V2.2
For check details, see “Check for bitwise operations in Stateflow charts”.
7-31
7 Stateflow
ID: Title
jc_0451: Use of unary minus on unsigned integers in Stateflow
Priority
Recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
Do not perform unary minus on unsigned integers.
Correct
7-32
jc_0451: Use of unary minus on unsigned integers in Stateflow
Incorrect
Rationale
• Verification and Validation
• Code Generation
Last Changed
V2.0
For check details, see “Check for unary minus operations on unsigned integers in
Stateflow charts”.
7-33
7 Stateflow
ID: Title
na_0013: Comparison operation in Stateflow
Priority
Recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
• Comparisons should be made only between variables of the same data type.
• If comparisons are made between variables of different data types, the variables need
to be explicitly type cast to matching data types.
7-34
na_0013: Comparison operation in Stateflow
Correct
Incorrect
Correct
Incorrect
7-35
7 Stateflow
Rationale
• Verification and Validation
• Code Generation
• Simulation
Last Changed
V2.1
For check details, see “Check for comparison operations in Stateflow charts”.
7-36
db_0122: Stateflow and Simulink interface signals and parameters
ID: Title
db_0122: Stateflow and Simulink interface signals and parameters
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
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.
7-37
7 Stateflow
Rationale
• Verification and Validation
• Code Generation
• Simulation
Last Changed
V2.0
For check details, see “Check for Strong Data Typing with Simulink I/O”.
7-38
db_0125: Scope of internal signals and local auxiliary variables
ID: Title
db_0125: Scope of internal signals and local auxiliary variables
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
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).
7-39
7 Stateflow
Correct
Incorrect
Rationale
• Readability
• Code Generation
Last Changed
V2.0
7-40
db_0125: Scope of internal signals and local auxiliary variables
For check details, see “Check Stateflow data objects with local scope”.
7-41
7 Stateflow
ID: Title
jc_0481: Use of hard equality comparisons for floating point numbers in Stateflow
Priority
Recommended
Scope
MAAB
MATLAB Versions
All
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.
7-42
jc_0481: Use of hard equality comparisons for floating point numbers in Stateflow
Correct
Incorrect
Rationale
• Verification and Validation
7-43
7 Stateflow
• Code Generation
Last Changed
V2.0
For check details, see “Check for equality operations between floating-point expressions
in Stateflow charts”.
7-44
jc_0491: Reuse of variables within a single Stateflow scope
ID: Title
jc_0491: Reuse of variables within a single Stateflow scope
Priority
Recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
The same variable should not have multiple meanings (usages) within a single Stateflow
state.
7-45
7 Stateflow
Correct
Variable of loop counter must not be used other than loop counter.
Incorrect
7-46
jc_0491: Reuse of variables within a single Stateflow scope
The meaning of the variable i changes from the index of the loop counter to the sum of a
+b.
Correct
Rationale
• Readability
• Verification
• Code Generation
7-47
7 Stateflow
Last Changed
V2.2
7-48
jc_0541: Use of tunable parameters in Stateflow
ID: Title
jc_0541: Use of tunable parameters in Stateflow
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
Create tunable parameters in Stateflow charts in one of the following ways:
• Define the parameters in the Stateflow chart and corresponding parameters in the
base workspace.
• Include the tunable parameters an input into the Stateflow chart. The parameters
must be defined in the base workspace.
7-49
7 Stateflow
Stateflow Chart
Rationale
• Verification
• Code Generation
Last Changed
V2.2
7-50
db_0127: MATLAB commands in Stateflow
ID: Title
db_0127: MATLAB commands in Stateflow
Priority
Mandatory
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
In Stateflow charts, do not use the .ml syntax.
Individual companies should decide on the use of MATLAB functions. If they are
permitted, then MATLAB functions should only be accessed through the MATLAB
function block.
7-51
7 Stateflow
Correct
Incorrect
Rationale
• Verification and Validation
• Code Generation
• Simulation
Note: Code generation supports a limited subset of the MATLAB functions. For a
complete list of the supported function, see the MathWorks documentation.
Last Changed
V2.2
7-52
db_0127: MATLAB commands in Stateflow
For check details, see “Check for MATLAB expressions in Stateflow charts”.
7-53
7 Stateflow
ID: Title
jm_0011: Pointers in Stateflow
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
In a Stateflow diagram, pointers to custom code variables are not allowed.
Rationale
• Readability
7-54
jm_0011: Pointers in Stateflow
Last Changed
V1.0
7-55
7 Stateflow
Events
• db_0126: Scope of events
• jm_0012: Event broadcasts
7-56
db_0126: Scope of events
ID: Title
db_0126: Scope of events
Priority
Mandatory
Scope
MAAB
MATLAB Versions
Pre R2009b
Prerequisites
None
Description
The following rules apply to events in Stateflow:
Specifics
7-57
7 Stateflow
Rationale
• Readability
• Verification and Validation
• Workflow
• Code Generation
• Verification and Validation
Last Changed
V2.2
7-58
jm_0012: Event broadcasts
ID: Title
jm_0012: Event broadcasts
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
db_0126: Scope of events
Description
The following rules apply to event broadcasts in Stateflow:
• Directed event broadcasts are the only type of event broadcasts allowed.
• The send syntax or qualified event names are used to direct the event to a particular
state.
• Multiple send statements should be used to direct an event to more than one state.
7-59
7 Stateflow
7-60
jm_0012: Event broadcasts
Rationale
• Readability
• Workflow
• Verification and Validation
• Code Generation
• Simulation
Last Changed
V2.2
7-61
7 Stateflow
For check details, see “Check for event broadcasts in Stateflow charts”.
7-62
State Chart Patterns
7-63
7 Stateflow
ID: Title
db_0150: State machine patterns for conditions
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
The following patterns are used for conditions within Stateflow state machines:
7-64
db_0150: State machine patterns for conditions
7-65
7 Stateflow
Rationale
• Readability
Last Changed
V2.2
7-66
db_0150: State machine patterns for conditions
7-67
7 Stateflow
ID: Title
db_0151: State machine patterns for transition actions
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
The following patterns are used for transition actions within Stateflow state machines:
7-68
db_0151: State machine patterns for transition actions
7-69
7 Stateflow
Rationale
• Readability
• Workflow
• Verification and Validation
• Code Generation
• Simulation
Last Changed
V2.2
7-70
Flow Chart Patterns
The preceding guidelines illustrate sample patterns used in flow charts. As such, they
would normally be part of a much larger Stateflow diagram.
7-71
7 Stateflow
ID: Title
db_0148: Flow chart patterns for conditions
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
Use the following patterns for conditions within Stateflow flow charts:
7-72
db_0148: Flow chart patterns for conditions
7-73
7 Stateflow
Rationale
• Readability
7-74
db_0148: Flow chart patterns for conditions
Last Changed
V2.2
7-75
7 Stateflow
ID: Title
db_0149: Flow chart patterns for condition actions
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
None
Description
You should use the following patterns for condition actions within Stateflow flow charts:
7-76
db_0149: Flow chart patterns for condition actions
7-77
7 Stateflow
Rationale
• Readability
Last Changed
V2.2
7-78
db_0134: Flow chart patterns for If constructs
ID: Title
db_0134: Flow chart patterns for If constructs
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
db_0148: Flow chart patterns for conditions
Description
Use the following patterns for If constructs within Stateflow flow charts:
7-79
7 Stateflow
if (condition){ action;
}
if (condition){ action1;
}
else {
action2;
}
7-80
db_0134: Flow chart patterns for If constructs
if (condition1){ action1;
}
else if (condition2) { action2;
}
else if (condition3){
__action3;
}
else {
action4;
}
if (condition1){ action1;
if (condition2){ action2;
if (condition3){ action3;
}
}
}
7-81
7 Stateflow
Rationale
• Readability
• Verification and Validation
• Workflow
• Code Generation
• Simulation
Last Changed
V1.0
7-82
db_0159: Flow chart patterns for case constructs
ID: Title
db_0159: Flow chart patterns for case constructs
Priority
Strongly recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
db_0148: Flow chart patterns for conditions
7-83
7 Stateflow
Description
Use the following patterns must be used for case constructs within Stateflow flow charts:
selection = ...;
switch (selection)
{
case 1:
action1;
break;
case 2:
action2;
break;
case 3:
action3;
break;
default:
action4;
}
7-84
db_0159: Flow chart 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
Last Changed
V1.0
7-85
7 Stateflow
ID: Title
db_0135: Flow chart patterns for loop constructs
Priority
Recommended
Scope
MAAB
MATLAB Versions
All
Prerequisites
db_0148: Flow chart patterns for conditions
Description
Use the following patterns to create Loops within Stateflow flow charts:
7-86
db_0135: Flow chart patterns for loop constructs
for (index=0;
index<number_of_loops;
index++)
{
action;
}
while loop
while (condition)
{
action;
}
do while loop
do
{
action;
}
while (condition);
7-87
7 Stateflow
Rationale
• Readability
Last Changed
V1.0
7-88
State Chart Architecture
7-89
7 Stateflow
ID: Title
na_0038: Levels in Stateflow charts
Priority
Recommended
Scope
NA-MAAB
MATLAB Versions
All
Description
The number of nested States should be limited, typically 3 per level. If additional levels
are required, use sub-charts.
7-90
na_0038: Levels in Stateflow charts
7-91
7 Stateflow
Rationale
• Readability
Last Changed
V3.0
7-92
na_0039: Use of Simulink in Stateflow charts
ID: Title
na_0039: Use of Simulink in Stateflow charts
Priority
Recommended
Scope
NA-MAAB
MATLAB Versions
R2010b and later
Description
Do not nest Stateflow charts inside Simulink functions that are included in Stateflow
charts.
Incorrect
Rationale
• Readability
7-93
7 Stateflow
Last Changed
V3.0
7-94
na_0040: Number of states per container
ID: Title
na_0040: Number of states per container
Priority
Recommended
Scope
NA-MAAB
MATLAB Versions
All
Description
The number of viewable States per container should be limited, typically to 6 to 10 states
per container. The number is based on the visible states in the diagram.
Correct
7-95
7 Stateflow
Note
A container is either a State, Box or root level chart.
Rationale
• Readability
• Verification and Validation
• Code Generation
Last Changed
V3.0
7-96
na_0040: Number of states per container
7-97
7 Stateflow
ID: Title
na_0041: Selection of function type
Priority
Recommended
Scope
NA-MAAB
MATLAB Versions
All
Description
Stateflow supports three types of functions: Graphical, MATLAB and Simulink. The
appropriate function depends on the type of operations required:
• Simulink
• Transfer functions
• Integrators
• Table look-ups
• MATLAB
• Complex equations
• If / then / else logic
7-98
na_0041: Selection of function type
• Graphical functions
Rationale
• Workflow
• Code Generation
Last Changed
V3.0
7-99
7 Stateflow
ID: Title
na_0042: Location of Simulink functions
Priority
Recommended
Scope
NA-MAAB
MATLAB Versions
All
Prerequisites
na_0039: Use of Simulink in Stateflow charts
Description
When deciding whether to embed Simulink functions inside a Stateflow chart, the
following conditions make embedding the preferred option. If the Simulink functions
OR
• Use a mixture of local Chart data and inputs from Simulink. OR
7-100
na_0042: Location of Simulink functions
OR
• Are called from multiple locations within the chart.
OR
• Are not called every time step.
Rationale
• Readability
• Workflow
Last Changed
V3.0
7-101
8
Enumerated Data
8 Enumerated Data
General Guidelines
• na_0033: Enumerated Types Usage
• na_0031: Definition of default enumerated value
8-2
na_0033: Enumerated Types Usage
ID: Title
na_0033: Enumerated Types Usage
Priority
Recommended
Scope
NA-MAAB
MATLAB Versions
R2010b and later
Prerequisites
None
Description
An enumerated data type should be used when a signal or parameter can take on a finite
set of integer values, and those values are associated with a set of named items. The
names, called literals, have meaning in the context of the algorithm or the domain in
which it operates. Typically, these literals represent an operating mode, signal status,
build variation, or some other discrete property that the quantity represented by the
variable can take on. A typical automotive example of this is the modes of a transmission:
Park, Reverse Neutral, Drive, Low.
8-3
8 Enumerated Data
Rationale
• Readability
• Verification and Validation
• Workflow
• Code Generation
• Simulation
See Also
• dm_0002: Enumerated type usage
Last Changed
V3.0
8-4
na_0031: Definition of default enumerated value
ID: Title
na_0031: Definition of default enumerated value
Priority
Recommended
Scope
NA-MAAB
MATLAB Versions
R2010b and later
Prerequisites
None
Description
The default value of the enumeration should always be explicitly defined for the
enumerated type.
Rationale
• Readability
8-5
8 Enumerated Data
Last Changed
V3.0
8-6
9
MATLAB Functions
9-2
na_0018: Number of nested if/else and case statement
ID: Title
na_0018: Number of nested if/else and case statement
Priority
Strongly recommended
Scope
NA-MAAB
MATLAB Versions
All
Prerequisites
None
Description
The number of levels of nested if / else and case statements should be limited, typically to
3 levels.
Rationale
• Readability
9-3
9 MATLAB Functions
• Code Generation
See Also
• jr_0002: Number of nested if/else and case statement blocks
Last Changed
V3.0
9-4
na_0019: Restricted Variable Names
ID: Title
na_0019: Restricted Variable Names
Priority
Mandatory
Scope
NA-MAAB
MATLAB Versions
All
Prerequisites
None
Description
To improve the readability of the MATLAB code, avoid using reserved C variable names.
For example, avoid using const, const, TRUE, FALSE, infinity, nil, double, single,
or enum.
Avoid using variable names that conflict with MATLAB Functions, for example conv.
9-5
9 MATLAB Functions
Note
Reserved keywords are defined in the Simulink Coder™ documentation.
Rationale
• Readability
• Verification and Validation
See Also
• Derived from jh_0042: Required software
Last Changed
V3.0
9-6
na_0025: MATLAB Function Header
ID: Title
na_0025: MATLAB Function Header
Priority
Strongly recommended
Scope
NA-MAAB
MATLAB Versions
All
Prerequisites
None
Description
MATLAB Functions must have a descriptive header. Header content may include, but is
not limited to, the following types of information:
• Function name
• Description of function
• Assumptions and limitations
9-7
9 MATLAB Functions
Example:
%% Function Name: NA_0025_Example_Header
%
% Assumptions: None
%
% Inputs:
% List of input arguments
%
% Outputs:
% List of output arguments
%
% $Date: August 27, 2012
% ________________________________________
Rationale
• Readability
• Verification and Validation
• Workflow
• Code Generation
See Also
• jh_0073: eML Header version
Last Changed
V3.0
9-8
MATLAB Function Data and Operations
9-9
9 MATLAB Functions
ID: Title
na_0034:MATLAB Function block input/output settings
Priority
Strongly recommended
Scope
NA-MAAB
MATLAB Versions
All
Prerequisites
None
Description
All inputs and outputs to MATLAB function blocks should have the data type explicitly
defined, either in the Model Explorer or at the start of the function. This provides a more
rigorous data type check for MATLAB Function blocks and prevents the need for using
assert statements.
9-10
na_0034: MATLAB Function block input/output settings
Rationale
• Readability
• Verification and Validation
• Workflow
• Code Generation
Last Changed
V3.0
For check details, see “Check input and output settings of MATLAB Functions”.
9-11
9 MATLAB Functions
ID: Title
na_0024: Global Variables
Priority
Strongly recommended
Scope
NA-MAAB
MATLAB Versions
All
Prerequisites
None
Description
The preferred method for accessing common data is by signal lines. However, if required,
Data Store Memory can be used to emulate global memory.
Example:
9-12
na_0024: Global Variables
function EngineFaultEvaluation(EngineData)
%# codegen
global ErrorFlag_DataStore
if (EngineData.RPM_HIGH)
ErrorFlag_DataStore = bitor(ErrorFlag_DataStore, HIGHRPMFAULT);
end
if (EngineData.RPM_LOW)
ErrorFlag_DataStore = bitor(ErrorFlag_DataStore, LOWRPMFAULT);
end
end
function WheelFaultEvaluation(WheelData)
%# codegen
global ErrorFlag_DataStore
if (WheelData.SlipHigh)
ErrorFlag_DataStore = bitor(ErrorFlag_DataStore, WHEELSLIP);
end
if (WheelData.SlipHigh)
ErrorFlag_DataStore = bitor(ErrorFlag_DataStore, LOWRPMFAULT);
end
end
Rationale
• Readability
• Verification and Validation
• Code Generation
• Simulation
See Also
• ek_0003: Global Variables
Last Changed
V3.0
9-13
9 MATLAB Functions
For check details, see “Check MATLAB code for global variables”.
9-14
MATLAB Function Patterns
9-15
9 MATLAB Functions
ID: Title
na_0022: Recommended patterns for Switch/Case statements
Priority
Mandatory
Scope
NA-MAAB
MATLAB Versions
All
Prerequisites
None
Description
Switch / Case statements must use constant values for the Case arguments. Input
variables cannot be used in the Case arguments.
Correct:
function outVar = NA_0022_Pass(SwitchVar)
%# codegen
switch SwitchVar
9-16
na_0022: Recommended patterns for Switch/Case statements
Rationale
• Verification and Validation
• Code Generation
• Simulation
See Also
• jh_0026: Switch / Case statement
Last Changed
V3.0
9-17
9 MATLAB Functions
9-18
na_0016: Source lines of MATLAB Functions
ID: Title
na_0016: Source lines of MATLAB Functions
Priority
Mandatory
Scope
NA-MAAB
MATLAB Versions
See description
Prerequisites
None
Description
The length of MATLAB functions should be limited, with a recommended limit of 60 lines
of code. This restriction applies to MATLAB Functions that reside in the Simulink block
diagram and external MATLAB files with a .m extension.
If sub-functions are used, they may use additional lines of code. Also limit the length of
sub-functions to 60 lines of code.
9-19
9 MATLAB Functions
Rationale
• Readability
• Verification and Validation
• Workflow
• Code Generation
See Also
• IM_0008: Source lines of eML
Last Changed
V3.0
9-20
na_0017: Number of called function levels
ID: Title
na_0017: Number of called function levels
Priority
Mandatory
Scope
NA-MAAB
MATLAB Versions
All
Prerequisites
None
Description
The number of levels of sub-functions should be limited, typically to 3 levels. MATLAB
Function blocks that reside at the Simulink block diagram level count as the first level,
unless it is simply a wrapper for an external MATLAB file with a .m extension.
This includes functions that are defined within the MATLAB block and those in the
separate .m files.
9-21
9 MATLAB Functions
Note
Standard utility functions, such as built-in functions like sqrt or log, are not include in
the number of levels. Likewise, commonly used custom utility functions can be excluded
from the number of levels.
Rationale
• Readability
• Verification and Validation
Last Changed
V3.0
9-22
na_0021: Strings
na_0021: Strings
ID: Title
na_0021: Strings
Priority
Strongly recommended
Scope
NA-MAAB
MATLAB Versions
All
Prerequisites
None
Description
The use of strings is not recommended. MATLAB Functions store strings as character
arrays. The arrays cannot be re-sized to accommodate a string value of different length,
due to lack of dynamic memory allocation. Strings are not a supported data type in
Simulink, so MATLAB Function blocks cannot pass the string data outside the block.
9-23
9 MATLAB Functions
Note
If the string is being used for switch / case behavior, consider using enumerated data
types
Rationale
• Verification and Validation
• Workflow
• Code Generation
See Also
• jh_0024: Strings
Last Changed
V3.0
9-24
A
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:
None The tool does not check the guideline. The MAAB recommends that the
vendor provide a recommendation of how to manually check guidelines
that the tool does not check.
A-2
B
Guideline Writing
Guidelines with the following characteristics are easier to understand and use. At a
minimum, when writing a new guideline, it should be
B-2
C
Use the patterns that appear in this appendix for if-then-else-if constructs within
Stateflow flow charts.
C Flow Chart Reference
Straight Line Flow Chart Pattern Curved Line Flow Chart Pattern
if then
if then else
C-2
Flow Chart Reference
Straight Line Flow Chart Pattern Curved Line Flow Chart Pattern
if then else if
Cascade of if then
C-3
C Flow Chart Reference
The following patterns are used for case constructs within Stateflow flow charts:
Straight Line Flow Chart Pattern Curved Line Flow Chart Pattern
case with exclusive selection
C-4
Flow Chart Reference
Straight Line Flow Chart Pattern Curved Line Flow Chart Pattern
C-5
C Flow Chart Reference
The following patterns are used for for loops within Stateflow flow charts:
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
Flow Chart Reference
Straight Line Flow Chart Pattern Curved Line Flow Chart Pattern
do while loop
C-7
C Flow Chart Reference
The following patterns are alternately used for If-then-else-if constructs within Stateflow
flow charts:
Straight Line Flow Chart Pattern Alternate Straight Line Flow Chart Pattern
if then else if
Straight Line Flow Chart Pattern Alternate Straight Line Flow Chart Pattern
Cascade of if then
C-8
Flow Chart Reference
Straight Line Flow Chart Pattern Alternate Straight Line Flow Chart Pattern
C-9
D
Basic Blocks
This document uses the term basic blocks to refer to blocks built into the “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.
Unless explicitly stated otherwise, the guidelines in “Signals” on page 6-40 apply to all
types of signals.
For more information about the representation of signals in Simulink models, see “Signal
Basics” in the Simulink documentation.
D-3
Glossary
Glossary-2
Glossary
Glossary-3
Glossary
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.
Glossary-4
Glossary
Glossary-5
Glossary
Flow Graph A flow graph is the set of flow charts 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 flow charts that start on the
same transition segment.
Glossary-6
Glossary
Glossary-7
Glossary
Simulink Coder Target An executable built from code generated by the Simulink
Coder product.
Signal source The signal source is the block of origin for a signal. The
signal source may or may not be the true source.
Glossary-8
Glossary
Glossary-9
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 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.
Glossary-10
Glossary
Transition Path A transition path is a flow chart that starts and ends on a
state.
Glossary-11
Glossary
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
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