Professional Documents
Culture Documents
MATLAB
MATLAB
MATLAB
Automated Transformation of
MATLAB Simulink and Stateflow Models
Ingo Strmer1, Dietrich Travkin2
1
Model Engineering Solutions, Berlin, stuermer@model-engineers.com
2
University of Paderborn, travkin@uni-paderborn.de
57
2
1
Experiences with model reviews are discussed in [5].
58
3
the Model Advisor. The report includes the sug-
gested repair operation Cascade (bottom of the
figure), which can be applied by clicking on the link.
These repair operations and other operations are also
applicable via context menu as shown in figure 1.
Product blocks with more than two operands, for
example (see figure 1, highlighted block), can auto-
matically be transformed into a cascade of product
blocks with two operands. If the Simulink model is
to be used for fixed-point code generation, this modi-
fication is necessary to determine scaling informa-
Figure 3: If-then-else modeling pattern (left) tion for intermediate results [12, 6, 7]. Since most
and corresponding pseudo-code (right) guideline violations can be fixed fully automatically,
or at least with few user interactions, such repair
operations can reduce the input required to repair the
3. Model Transformations model enormously.
MATE provides different kinds of operations that
modify a MATLAB Simulink and Stateflow model. 3.2 Layout Operations
In this section, we discuss (1) model repair opera- While modeling a system a developer has the option
tions, (2) layout operations, and (3) design pattern of applying beautifying model transformations via
instantiation. context menu. For example, it is possible to align
Simulink blocks horizontally or vertically with each
3.1 Model Repair Operations
other, or to avoid line intersections by changing the
After detecting guideline violations during a model port order (see figure 2; on the left the signal lines of
analysis phase (cf. [6, 10] for more details on analy- the Product block are crossing). Such model trans-
sis techniques), all applicable, predefined repair formations improve the arrangement of the model
operations are suggested to eliminate the reported elements, thus easing model comprehension without
violations. Figure 1 shows the analysis results of a significantly delaying the modeling process.
Simulink diagram using the report functionality of
59
4
outPorts
:Outport
inPorts
sourcePort
targetPorts :Inport
block
...
... :Product no = 1
line
... name = Product1 line block
:Line targets
:Product
block outPorts ...
:Constant line targets
name = Product2 :Outport
:Line
name = Constant3 line block
type = int16
targetPorts :Inport
value = 4
block sourcePort no = 2
inPorts
outPorts
:Outport
CascadeProductBlocksTransformationWithPorts::execute(): void
this
arguments[product]
product: Product
[success]
[failure]
targets
l1: Line
destroy
targets outports sourcePort
l2: Line product pOut: Outport
destroy
destroy inports
targetPorts create
l3: Line ip: Inport sourcePort
destroy create lOut: Line
targetPorts
newOut: Line
create create
targetPorts create
create sourcePort
inPorts
newIn1: Inport
create create
outPorts
newProduct: Product newOut: Outport
create create
newIn2: Inport
create
create inPorts
60
5
Element
handle: String
ChartBlock Although the model is incomplete (many block
qualifiedName: String
... MathOperation
types are missing) the provided abstractions enable
to traverse any Simulink model. The class Block for
ports
System
containedBlocks
Port Product
example can be used for any currently unknown
Sum
RootSystem
Block block type. Otherwise the concrete classes like
blockType: String Constant
Subsystem name: String targetBlock ChartBlock are used.
... BusCreator
subsystem BusSelector
Specifying transformations using graph transfor-
Line
SubsystemBlock
sourceBlock
... mation rules has many advantages. In particular, this
simplifies traversal and modification of object struc-
Figure 8: Excerpt from the simulink meta-model tures. In some cases, however, graph transformation
rules may also become complex, for example when
specifying complex layout algorithms. Using our
The abstract syntax graph is an object structure. In Simulink and Stateflow meta-model, it is also possi-
this context each object represents an element in a ble to specify model analysis and transformation
Simulink or Stateflow diagram (i.e. concrete syntax). operations by implementing them manually in Java
The links between objects represent element rela- and integrating them into MATE. The modeler thus
tions, e.g. containment. Figure 6 illustrates a part of has two alternative ways of specifying the desired
an abstract syntax graph representing the two pro- model operations.
duct blocks and a connected constant block shown in
figure 5. Each product block in the Simulink diagram
5. Related Work
is represented by an object of type Product, each
signal line by a Line object, etc. Attributes name, Well-known examples of other MATLAB Simulink
type, value and others (not illustrated) contain addi- and Stateflow analysis tools are MathWorks Model
tional information about the elements. Advisor [1] and MINT [2]. Both rely on the execu-
A graph transformation rule modifies the abstract tion of MATLAB M-scripts to identify modeling
syntax graph, i.e. it creates or removes objects, adds, rule violations. Other tools like MESA [8] enable the
removes or reconnects links, or changes attribute specification and verification of OCL constraints.
values. However, none of these tools provide support for
Figure 7 illustrates an exemplary graphic specifi- repairing a model, improving its layout, and instanti-
cation of a model transformation. The transformation ating design patterns. MATE, in contrast, in addition
is specified using story diagrams [9], a type of UML to the possibility of specifying guideline violation
activity diagrams with nested collaboration dia- patterns, which can be automatically detected in a
grams. Given a Product object, i.e. a product block, model (see [6] for more details), supports model
as a starting point, this transformation tries to find transformations.
the specified object structure in the abstract syntax Furthermore, the implementation of guideline
graph, then it removes all the elements marked with checks in M-script is a great deal more complex than
destroy and adds all the elements marked with implementing them with the MATE approach. With
create. In this case the transformation replaces MATE, the rules are specified on a higher level of
product blocks with more than two operands by a abstraction using graph transformation rules. The
cascade of product blocks with only two operands. rule implementation is generated from this high-level
With a graphic specification of a transformation, specification. Moreover, MATE uses an object-
i.e. a story diagram, MATE offers the option of gen- oriented model of Simulink and Stateflow diagrams,
erating Java code. The code can be nested into the which acts as a further layer of abstraction. It hides
Model Advisor framework so that the specified the Simulink and Stateflow API operations (M-
transformation can be applied to Simulink and script) behind a uniform, consistent interface for
Stateflow models. querying and modifying all model elements.
The Simulink and Stateflow models are traversed The MESA project [8] also focuses on the appli-
and modified using M-script commands, but these cation of a high-level analysis specification language
are encapsulated in the access methods of an object- with code generation support. However MESA does
oriented meta-model for Simulink and Stateflow not rely on graph and rule-based specification tech-
diagrams. A small excerpt from this model is shown niques like MATE. Instead it uses the textual and
in figure 8. logic-based Object Constraint Language (OCL) of
OMG. This makes descriptions of object structures
61
6
not as easy to understand as the graph transformation [5] Ingo Strmer, Mirko Conrad, Ines Fey, Heiko
rules used by MATE. Drr: Experiences with Model and Autocode
Reviews in Model-based Software Develop-
A comparable approach to MATE is aquintos
ment. Proc. of 3rd International ICSE Work-
PREEvision tool suite, which also uses graphic shop on Software Engineering for Automotive
specifications for model analysis and transforma- Systems (SEAS06), pp. 45-51, 2006.
tions. However in contrast to MATE, PREEvision is
[6] Ingo Strmer, Ingo Kreuz, Wilhelm Schfer,
aimed towards model-to-model transformation tech- Andy Schrr: The MATE Approach: Enhanced
niques (e.g. transformation of a Simulink and Simulink and Stateflow Model Transfor-
Stateflow model into an ASCET/SD model) instead mation, Proc. of MathWorks Automotive Con-
of model modifications. PREEvision does not focus ference (MAC), 2007.
directly on the analysis of modeling guideline viola- [7] Ingo Strmer, Heiko Drr, Holger Giese, Udo
tions and does not support model repair functional- Kelter, Andy Schrr, Albert Zndorf: Das
ities with user feedback or pattern instantiation. MATE Projekt visuelle Spezifikation von
There are further research approaches that support MATLAB/Simulink/Stateflow Analysen und
Transformationen, Proc. of Dagstuhl Work-
model analysis and transformation [13, 14], but these
shop Modell-basierte Entwicklung eingebette-
focus on UML and Statechart diagrams. ter Systeme III (MBEES 2007), pp. 83-93,
2007.
6. Conclusion [8] Tibor Farkas, Christian Hein, Tom Ritter:
Automatic Evaluation of Modelling Rules and
Adopting modeling guidelines for the design of auto-
Design Guidelines, Proc. of 2nd Workshop
motive controller models is vital. The huge number From code centric to model centric software
of modeling rules and patterns that the developer engineering: Practices, Implications and
must keep in mind calls for tool support in order to ROI, Bilbao, Spain, 2006.
create, check, and repair controller models with re- [9] Thorsten Fischer, Jrg Niere, Lars Torunski,
gard to guideline compliancy. Furthermore, the and Albert Zndorf: Story Diagrams: A new
equally large number of violated guidelines makes Graph Rewrite Language based on the Unified
model reworking cumbersome and prone to error. Modeling Language, Proc. of the 6th Interna-
MATE supports developers in analyzing MATLAB tional Workshop on Theory and Application of
Graph Transformation (TAGT), Paderborn,
Simulink and Stateflow models and automatically or
Germany (G. Engels and G. Rozenberg, eds.),
interactively transforming such models into guide- LNCS 1764, pp. 296--309, Springer Verlag,
line-compliant ones. In addition, MATE provides November 1998.
high-level editor functions, which help developers to
[10] Jrg Niere, Wilhelm Schfer, Jrg P. Wadsack,
design guideline-compliant models by generating Lothar Wendehals, and Jim Welsh, Towards
predefined and configurable modeling patterns or Pattern-Based Design Recovery, Proc. of the
using layout operations. 24th International Conference on Software
Engineering (ICSE), Orlando, Florida, USA,
References pp. 338--348, ACM Press, May 2002.
[11] aquintos GmbH: PREEVision,
[1] The MathWorks, Inc.: MATLAB Model Advi- http://www.aquintos.info/de/produkte/
sor, http://www.mathworks.com/products/ index_preevision.php, 2007
matlab/, http://www.mathworks.com/access/
helpdesk/help/toolbox/simulink/, 2006. [12] dSPACE GmbH: Modeling Guidelines for
MATLAB/Simulink/Stateflow and TargetLink,
[2] Ricardo, Inc., MINT, p. 37, V2.0.
http:/www.ricardo.com/mint, 2006.
[13] M. Huhn, M. Mutz, K. Diethers, B. Florentz,
[3] The Mathworks, Inc.: The MathWorks Automo- M. Daginnus: Applications of Static Analysis
tive Advisory Board (MAAB: Control Algo- on UML Models in the Automotive Domain,
rithm Modeling Guidelines Using MATLAB, Proc. of Formal Methods for Automation and
Simulink, and Stateflow. Version 2.0, Safety in Railway and Automotive Systems,
http://www.mathworks.com/industries/auto/ 2004
maab.html, 2007.
[14] M. Huhn, M. Mutz, B. Florentz: A Lightweigth
[4] Model Engineering Solutions: e-Guidelines Approach to Critical Embedded Systems De-
Server, http://www.model-engineers.com/ sign using UML, Proc. of 3rd International
products-services/products/e-guidelinesbr- Workshop on Critical Systems Development
server.html, 2007. with UML, 2004.
62