Coordinating State Machines with Signal Events
Overview
Similarly to call events, which you learned about in the previous tutorial, signal events enable state machines to interact with each other. Signal events, however, are less direct: they trigger in response to a signal from another state machine instead of being called directly by that state machine. Additionally, these signals can only be sent in a Moxie simulation from within the delegate code. In this section, you will replace the ground station's call to shutdown the UAV with a signal event.
This section covers the following concepts:
- Signal events
- The Moxie StateMachineRemoteControl
public void sendShutDownSignal(UAV target) {
mStateMachineRemoteControl.sendSignalEvent("Simulation::ShutDown", target);
}
Figure A1: Sending a signal event from a delegate
Prerequisites
Prerequisite | Description |
---|---|
Moxie Installation | You must have installed Moxie and have the prerequisites for developing delegates for Moxie. |
Tutorial Project | You must start this section with the UAV Mission simulation project and delegate module project from the previous section. If you did not complete the previous section, you can use the files from the Moxie installation: \documentation\tutorialFiles\03\LoggingAndDebugging, but you may still need to configure the delegate module for your environment. |
Recommended Reading |
Before completing this section, you may want to read the following help topic:
|
Instructions
Replace the call event with the signal event
- Open the UAVMission.mdzip project from the previous section.
- In the Containment Tree, right-click the Simulation package and select Create Element (or press ).
-
Select Signal
and enter
ShutDown
as its name. -
In the UAV State Machine diagram,
double-click the transition going from the
TransmittingData
state to the final pseudostate. - In the Trigger category, set the Event Type to SignalEvent.
- Set the Signal to ShutDown and click .
Replace the call with the signal
-
In the System Definition (the BDD),
select the
GroundStation
block, click the Create Element button () on the upper-right corner of the block, and select Operation. -
Enter
sendShutDownSignal( target : UAV )
as the operation's name and parameter. - Double-click the new operation, set the Visibility to private, and click .
-
In the GroundStation State Machine diagram,
double-click the transition going from the
ReceivingSensorData
state to the final pseudostate. -
In the Effect category,
set the Body and Language to the string
sendShutDownSignal(uav);
, (optionally) add a line break beforesendShutDownSignal(uav);
, and click .
Add the supporting delegate code
You can use the StateMachineRemoteControl
dependency from the analysis tool controller
to send a signal to another state machine,
triggering any signal events that expect that signal.
-
In the GroundStationDelegate class,
add the following import statement:
import com.agi.moxie.api.StateMachineRemoteControl;
-
Add the following private field:
private StateMachineRemoteControl mStateMachineRemoteControl;
-
Add the following dependency injection and field initialization in the constructor:
public GroundStationDelegate( ...
@InjectByName("stateMachineRemoteControl") StateMachineRemoteControl stateMachineRemoteControl,
... ) {
mStateMachineRemoteControl = stateMachineRemoteControl;
...
} -
Create the following public method:
public void sendShutDownSignal(UAV target) {
mStateMachineRemoteControl.sendSignalEvent("Simulation::ShutDown", target);
} - Save your work and re-install the delegate module.
- Run () the simulation and observe that the UAV still shuts down at the end of the simulation.
Next Section >