Simulate, Visualize, and Validate Activity Diagrams
After you describe your system as an activity diagram, you can visualize the flow of your tokens and track the execution of activities. To validate that your activity diagram satisfies your design goals, simulate your model, use animations to validate diagram behavior, and visualize the output of your model using Simulation Data Inspector. For more information about activity diagrams, see Describe System Behavior Using Activity Diagrams.
In this example, the activity diagram represents a mobile robot path planning algorithm. The activity diagram has:
Select Target Position
action node to represent the target position of the robot in the grid.Plan Path
action node to compute the robot path based on the target position fromSelect Target Position
node and its initial position fromCompute Self Position
node.The decision node to check whether the computed path is feasible with respect to the planned path and remaining robot battery life.
If the path is feasible, in the
Follow Path
action node, the robot issues proper commands and implement them to reach the target position.If the path is not feasible, the diagram errors out.
For more information about creating this activity diagram, see Author Activity Diagrams.
Open Activity Diagram for Mobile Robot Functional Flow
This example shows a functional flow diagram for modeling a mobile robot architecture that travels between a randomized starting point and destination.
Open the project.
openProject("scMobileRobotExample");
Open the activity diagram.
systemcomposer.openModel("RobotActivity");
First, the robot software calculates the path distance, and if the distance exceeds robot battery life to traverse the distance, the token flows to Error out
and the activity terminates, otherwise, the robot follows the path.
Simulate Activity Diagram and Review Results
To simulate activity diagrams, in the System Composer™ toolstrip, on the Modeling tab, use the Simulate section.
After you simulate the activity diagram, observe that the robot follows the path and
reaches its destination when a path is feasible. In this simple path planning algorithm,
the robot first moves in the horizontal axis to align its x
coordinate with the target and then moves in the vertical axis to align its
y
coordinate with the target position. Then, the robot aligns its
orientation with the target position.
Observe that the simulation ends when a token arrives at the Activity Final Node node.
Note
An activity diagram simulation ends in two scenarios, if a token reaches an Activity Final node or due to the final simulation time.
Validate Activity Diagram Behavior Using Animations
To track the flow of your tokens and the execution of activities, use animations.
Animations highlight the flow of your tokens and the sequence of actions in your
activity diagram. To specify the speed of your animation, in the System Composer toolstrip, on the Debug tab, select the
animation speed as Lightning Fast
,
Fast
, Medium
,
Slow
, or None
.
If the animation is on, to stop the animation during simulation, press
Ctrl+C or set the animation speed to
None
.
Animate the activity diagram representation of the robot. Observe that the animation highlights the action nodes with colors that represent the state of the action node at that time of the simulation.
In an animation, there are two types of colors, fill colors and border colors.
Fill colors:
Light Grey — Action node is in idle mode.
Dark Grey — Action node completed its run.
Green — Action node is running. When an action node is running, its main color is green but its boundary can have three different colors to represent its token status:
Border colors when the fill color is green:
Orange — Some tokens arrived at the node, but the node does not meet all the requirements to run.
Green — All the requirements regarding the tokens are satisfied and the node is running.
Grey — All the output tokens have not yet departed the node.
Log Data from Activity Diagram Using Simulation Data Inspector
To visualize the output tokens from a node and the data, right-click an object flow line, log your signal, and use the Simulation Data Inspector.
In the activity diagram of the robot, in the Follow Path
action
node, log the issued commands.
Simulate the diagram. In the toolstrip, on the Simulation tab, select Data Inspector and observe that Simulation Data Inspector displays the logged data.
View Token Data Using Pin Value Display
You can display the values and the structure of token data at the output pin of a node as a label that floats over the flow line in the diagram. The value in the label is updated when a token departs an output pin. You can add and remove pin value labels throughout your model before and during simulation. You can use pin value labels along with other visualization options to understand, analyze, and debug your diagram.
To display token data, in the robot example, right-click flow lines and select Show Port Value Label on Selected Signal. Observe that during and after animation, the pin values are displayed.
Step Through the Simulation
You can step through major time steps of a simulation to analyze and debug the behavior of your diagram. In the toolstrip, on the Debug tab, use the Step Forward and Step Back buttons. Observe that the simulation pauses on every major time step.
Note
You need to specify a nonzero duration of your nodes in your activity diagram to be able to step through time steps. Otherwise, the simulation will end in one time step.
See Also
Functions
Tools
Blocks
- Initial Node | Action Node | Decision or Merge Node | Join or Fork Node | Flow Final Node | Activity Final Node