Simulating Simultaneous Behaviors with Composite States

Overview

In order to simulate simultaneous behaviors within a state machine, you must use a composite state. A composite state is a single state divided into orthogonal regions, each of which contains substates that represent that region's behavior. The substates are only mutually exclusive within each region, not across regions, so that all of the regions can execute at the same time. In this section, you will use a composite state to simulate the computer interacting simultaneously with both the power system and the flight controller.

This section covers the following concepts:

Figure A1: A composite state

Prerequisites

Prerequisite Description
Moxie Installation You must have installed Moxie.
Tutorial Project You must start this section with the Moxie simulation project from the previous section. If you did not complete the previous section, you can use the following project from the Moxie installation: \documentation\tutorialFiles\02\TimeEvents.mdzip
Recommended Reading Before completing this section, you may want to read the following help topic:

Instructions

Create a block for the flight controller

For the computer to instruct the flight controller to arm its motors, you will need to create a block, instance specification, and state machine to represent the flight controller and its properties and behavior.

  1. Open the project from the previous section.
  2. In the System Definition (the BDD), select the Thing block, click the downward-pointing Generalization button () on the context toolbar, and then click anywhere on the canvas to add a new block.
  3. Select the new block on the diagram and enter FlightController as its name.
  4. Select the UAV block, click the Directed Composition button () on the context toolbar, and then click the FlightController block.
  5. In the toolbar to the left of the BDD canvas, select Directed Association, click the Computer block, and then click the FlightController block.

Create an instance specification for the flight controller

  1. Right-click the FlightController block and select Tools > Create Instance....
  2. In the 1. Select parts page, click Next >.
  3. In the 2. Select a package page, select the Simulation package and click Next >.
  4. In the 3. Create a diagram page, clear the Create a new diagram checkbox and click Finish.
  5. In the Containment Tree, rename the new Simulation > flightController instance specification to uav.flightController.
  6. Open the Instance Specification Diagram.
  7. Drag the Simulation > uav.flightController instance specification from the Containment Tree into the uav instance specification on the diagram and click OK.
  8. (Optional) Click the Link button () on the context toolbar next to the uav.flightController instance specification. Then click on the uav instance specification to add the link. Click OK on both pages of the dialog window.
  9. Double-click the uav.computer instance specification and select Slots from the left pane of the specification window.
  10. In the center pane, select the flightController slot and click Create Value.
  11. Select the Simulation > uav.flightController instance specification; then click OK and then Close.

Create a state machine for the flight controller

  1. In the Containment Tree, right-click the Structure > FlightController block and select Create Diagram (or press CtrlShiftD).
  2. Select SysML State Machine Diagram and enter FlightController State Machine as its name. You may need to click the Expert button in the lower left of the dialog in order to find SysML State Machine Diagram.
  3. Select the state on the diagram and enter Idle as its name.
  4. Click the Transition button () on the context toolbar, click anywhere on the canvas to add a new state, and then enter ReadyForTakeoff as its name.
  5. Open the Simulation Dashboard.
  6. Drag the Structure > FlightController > FlightController State Machine > FlightController State Machine diagram onto the dashboard and click the Show Diagram Overview Content button () to display the state machine.

Figure B1: The flight controller state machine

Add a composite state to the computer state machine

Since you need to create additional behavior that will run at the same time as the computer's existing behavior, you need to nest the states describing both behaviors inside a composite superstate.

  1. In the Computer State Machine diagram, select Composite State from the toolbar to the left of the canvas and then click anywhere on the canvas to add a composite state.
  2. Select the rest of the state machine elements and drag them into the body of the composite state.
  3. Select the composite state and click the Create Region button () on the upper-right corner of the state.
  4. In the toolbar to the left of the state machine canvas, select Initial and click in the new region of the composite state to add an initial pseudostate.
  5. Click the Transition button () on the context toolbar, right-click in the region and select State, and then enter Idle as its name.
  6. Click the Transition button () on the context toolbar again, right-click in the region and select State, and then enter ReadyForTakeoff as its name.
  7. In the toolbar to the left of the state machine canvas, select Initial and click anywhere on the canvas to add an initial pseudostate.
  8. Click the Transition button () on the context toolbar. Then click the composite state.
  9. Run () the simulation and observe that both regions of the composite state execute simultaneously.

    Figure A1: The computer composite state

  10. Save your work before continuing.

Though both regions execute simultaneously, they do not yet interact with the flight controller state machine. You will add this interaction in the next section using a call event.

Next Section >