Scheduling Transitions with Time Events

Overview

Most complex simulations require the execution of behaviors at specific times, which you can do with either absolute or relative time events. Absolute time events allow you to specify a precise moment in time to trigger a transition, while relative time events allow you to specify a time duration to wait before triggering a transition. In this section, you will use time events to specify the simulation time at which the computer should turn on the power system, and how long to wait before checking whether or not the power system successfully turned on.

This section covers the following concept:

Figure A1: Absolute and relative time events

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\CallEvents.mdzip
Recommended Reading Before completing this section, you may want to read the following help topics:

Instructions

Add startup time and wait duration properties

For absolute time events, Moxie requires the specific moments in time to derive from Moxie-Base::Structure::TimeInstant. Similarly, for relative time events, Moxie requires the durations to derive from Moxie-Base::Structure::TimeDuration.

  1. Open the project from the previous section.
  2. In the Containment Tree, right-click the Structure > Computer block and select Specification (or press Enter).
  3. Select Properties from the left pane of the window and click Create > Part Property.
  4. Set the Name to the string startupTime, set the Type to Iso8601TimeInstant, and click Back.
  5. Click Create > Part Property again.
  6. Set the Name to the string startupWaitDuration, set the Type to FixedDuration, and click Close.

Create instance specifications for the properties

  1. In the Containment Tree, select both Moxie-Base > Structure > Iso8601TimeInstant and FixedDuration blocks. Then right-click them and select Tools > Create Instance....
  2. In the 1. Select parts page, set the Iso8601TimeInstant > time value to 2022-02-22T22:22:22.222222Z and the FixedDuration > seconds value to 30. Then 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 iso8601TimeInstant instance specification to startupTime and the new fixedDuration instance specification to startupWaitDuration.

Assign the instance specifications to the computer

  1. Open the Instance Specification Diagram.
  2. Drag the Simulation > startupTime instance specification from the Containment Tree into the uav.computer instance specification on the diagram and click OK.
  3. (Optional) Click the Link button () on the context toolbar next to the startupTime instance specification. Then click on the uav.computer instance specification to add the link.
  4. Drag the Simulation > startupWaitDuration instance specification from the Containment Tree into the uav.computer instance specification on the diagram and click OK.
  5. (Optional) Click the Link button () on the context toolbar next to the startupWaitDuration instance specification. Then click on the uav.computer instance specification to add the link.

Figure B1: The computer instance specification

Add time events to the computer state machine

The times and durations specified by events always refer to the simulation time, not real time. So when executing a simulation, Moxie jumps the simulation time to each next event, rather than waiting for a specific moment or delay in real time. Jumping the simulation time also allows Moxie to model time continuously instead of in discrete steps, which is very important when integrating external analysis into your simulation.

  1. In the Computer State Machine diagram, double-click the transition from Standby to PoweringOn.
  2. In the Trigger category, set the Event Type to TimeEvent.
  3. Set When to the string startupTime, (optionally) add a line break at the start of the Effect Body and Language, and click Close.
  4. Double-click the transition from the PoweringOn state to the choice pseudostate.
  5. In the Trigger category, set the Event Type to TimeEvent.
  6. Set When to the string startupWaitDuration, set Is Relative to true, and click Close.

Figure B2: The computer time events

Examine the simulation state history log

  1. Run () the simulation.
  2. Select Moxie > Open Log File Directory in File Explorer (or press CtrlAltShiftL).
  3. Open moxie_simulation.json in a text editor.
  4. Notice that the simulationTime for exiting the computer Standby state is 2022-02-22T22:22:22.222222Z, as specified by the absolute time event.
  5. Notice that the simulationTime for exiting the computer PoweringOn state is 2022-02-22T22:22:52.222222Z, as expected due to the 30-second delay of the relative time event.
  6. Save your work before continuing.

Next Section >