For this example we walk through the creation of a SysPhS model of a room humidifier to illustrate the use of signal flows and StateMachines. The signals in this example reflect physical quantities, but differ from the physical interaction in the sense of physical substances with flow rates and potentials.
The complete humidifier example is a complex set of SysML models, but it contains a section that requires the use of MATLAB's Stateflow for simulation. We will use this section of the example to work through the use of the SysML StateMachine and view how this is configured and run in MATLAB using Stateflow, as well as in Modelica.
Running this simulation requires either:
- OpenModelica or
- MATLAB's Simulink and StateFlow
The complete simulation example is available in the WebEA model. See the links under Learn More at the end of this topic.
The SysML StateMachine diagram is:
For MATLAB the Stateflow diagram generated consists of:
For Modelica the generated diagram looks like this:
Create SysML StateMachine Model
This table shows how we can build the SysML StateMachine model to represent the switching states.
Note: The full SysML StateMachine features are only partially supported in MATLAB's Stateflow and Modelica. Therefore, in order to create State diagrams for simulation in these products, it is necessary for the connector-types and object-types used in Enterprise Architect's StateMachine model to only contain the corresponding features supported in Stateflow and Modelica.
In SysML, using SysPhS, the core humidifier components are represented by Blocks. For this example, where we are creating a StateMachine simulation, the focus is on the 'Control' Block. The Block Definition diagram (BDD) called 'Humidifier Components', which includes the 'Control' Block, is only one in a list of BDDs defining the humidifier.
The 'Control' Block has the StateMachine 'ControlStateMachine' as a Composite diagram under it; this is illustrated in the first diagram in the Overview section at the start of this topic.
The 'Control' Block is where Ports and a PhS constant for the humidifier control are defined. The Ports are of type RealInSignal, which are signal flows.
As a starter for all SysPhS models, you need to ensure that the SysPhS common types are loaded in the repository, and referenced in the new model using the Package 'Import' connector. For more information see the Referencing SysPhS Libraries Help topic.
The Value Types used for the Ports are pre-defined in the SysPhS Simulation Libraries. The key type used is the RealInSignal ValueType (RealInSignalElement). This can be dragged onto the Block as a Port and then renamed.
As an example of setting a Port on the Block, in this case the fanPowerOut Port, you drag a RealInSignalElement onto the Block and define it as a Port.
Creating the StateMachine
To define a StateMachine as a Composite child-diagram to the Block:
Creating the States and Transitions
In the child StateMachine diagram, you add the Initial element, four States and a Final element. Then name these appropriately.
Note: By pressing the when the diagram is selected, you can select an Initial object from the context menu, and then use the Quicklinker to add the remaining objects.
The Transitions between the States contain conditions in their Guards. These conditions are defined in the Properties window 'Constraints' tab.
The variables used are the 'Control' Block's Phs constant and Ports. See the image in the earlier Blocks row.
Each State contains a script defining the mode and status of the fan. These scripts are set in the 'Entry' operation.
To edit the script for this, select the root StateMachine and pressing .
Configure Simulation Behavior
This table shows the detailed steps in the configuration of SysMLSim.
Create a SysMLSimConfiguration Artifact
Set the Package
Set Modelica or Simulink
In the top drop-down, select which simulation tool to use:
For more details on these settings, see the Configure SysML Simulation Help topic.
Set the Block to Simulate
Select Properties to Plot
You can now select the properties to be plotted:
In the 'Simulation' page, click on the. This shows an example of the plot generated in:
Note: The output in Simulink looks different due to the default precision for Simulink models not being sufficient for this specific example. Simulink settings can be modified by opening the generated file directly in Simulink.
View the Model in Modelica or Simulink
To view the generated model in the external applications, Modelica or Simulink, see the View the Model in Modelica or Simulink Help topic, which includes tips for debugging any issues in the generated code.
- Modeling for Stateflows
- Referencing SysPhS Libraries
- Using the SysPhS Patterns
- Configure SysML Simulation
- View the Model in Modelica or Simulink
- Creating Modelica Specific Blocks
- Creating Simulink specific blocks
- Demo: Matlab Stateflow in Enterprise Architect
- WebEA: Humidifier Example
- WebEA: Humidifier IBD
- WebEA: ControlStateMachine