Main Content

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:

  • The Select Target Position action node represents the target position of the robot in the grid.

  • The Plan Path action node computes the robot path based on the target position from Select Target Position node and its initial position from Compute Self Position node.

  • The merge node checks whether the computed path is feasible with respect to the planned path and remaining robot battery life.

    • If the path is feasible, then 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, then 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");

RobotActivity activity diagram with action nodes, pins, and flow lines.

First, the robot software calculates the path distance. 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.

The plot with target position, self position, data1, data 2. The robot follows the path to reach its destination.

Note

An activity diagram simulation ends in one of two scenarios: when 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.

animation control

Animate the activity diagram of the robot. The animation highlights the action nodes and pins with border colors that represent their state at that time during the simulation.

Animations for action node have two types of border colors:

  • Dark gray — Action node has completed its run.

  • Green — Action node is running.

Animations for pins have two types of border colors:

  • Orange — Some tokens have arrived at the pin, but the pin does not meet the requirements set by token multiplicity to run.

  • Green — All the requirements regarding the tokens are satisfied, and the pin is waiting for other pins or an action to be executed.

Animation

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.

Log Selected Signals option

In the activity diagram of the robot, in the Follow Path action node, log the issued commands.

In the Follow Path Action node, the token flow line has the symbol to indicate that the data is logged.

Simulate the diagram. In the toolstrip, on the Simulation tab, click Data Inspector. The Simulation Data Inspector displays the logged data.

Simulation Data Inspector displaying the issued commands that are logged

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.

Pin value display is enabled for the activity diagram representing the robot. The token data is displayed on the flow lines.

Step Through 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

To be able to step through time steps, you need to specify a nonzero duration of your nodes in your activity diagram. Otherwise, the simulation will end in one time step.

Step through debugging

Inspect Tokens Using Token Inspector

You can inspect the contents of a pin or parameter node during simulation using the token inspector. When you pause the simulation and select a pin or a parameter node, the token inspector displays information such as the number of tokens and, for each token, the token ID and token payload. Use the token inspector to debug issues with queuing and blocking behavior of tokens.

You can only access token inspector for one pin or parameter node at a time.

To display token inspector, step through the simulation and click the pin that you want to inspect. The tokens in the pin buffer are displayed along with their token IDs. Each token ID is unique and autogenerated. You can use a token ID to track a token through the simulation.

Token Inspector Image

See Also

Functions

Tools

Blocks

Related Topics