Connecting to STK from Delegates

Overview

You will only be able to fully follow along in this tutorial if you acquired Behavior Execution Engine as part of STK Enterprise.

Behavior Execution Engine uses analysis tool controllers to communicate with external tools like STK. At the start of a simulation, an analysis tool controller instantiates all of the delegates associated with it, injecting dependencies from the external tool into the delegates for them to use. You can implement custom analysis tool controllers for other tools, but since the UAV mission only requires STK, you will just use Behavior Execution Engine's STK controller in this tutorial. In this section, you will set up the STK controller and its STK toolbox dependency, initialize the STK object data, and use a SysML stereotype to configure the simulation to start the STK scenario when the simulation starts.

This section covers the following concepts:

public UAVDelegate( ...
        @InjectByName("stkToolbox") StkToolbox stkToolbox,
        @InjectByName("stkEarth") StkEarth stkEarth,
         ... ) {
    super(stkToolbox, stkEarth, timeProvider);
    mStkToolbox = stkToolbox;
     ...
    mStkToolbox.sendConnectCommand("Units_SetConnect / Internal");
}

public void initializeStkObject() {
    //Attach to the STK object.
    this.updateFromStkObject(stkObjectPathProperty().getValue());
    mStkUavObject = this.getStkObject();
}

Figure A1: Connecting to an STK object from a delegate

Prerequisites

Prerequisite Description
Behavior Execution Engine Installation You must have installed Behavior Execution Engine and have the prerequisites for developing delegates for Behavior Execution Engine.
STK Installation You must have installed STK 12.9 or later.
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 Behavior Execution Engine installation: \documentation\tutorialFiles\03\SignalEvents, but you may still need to configure the delegate module for your environment.

You also need the UAV Mission STK scenario from the Behavior Execution Engine installation: \documentation\tutorialFiles\03\UAVMission.vdf.

Recommended Reading Before completing this section, you may want to read the following help topics:

Instructions

Replace the analysis tool controller

A delegate provider registers the module with Behavior Execution Engine by providing a delegate module descriptor that contains the analysis tool controller and the list of delegates. Since you will be integrating your simulation with STK, you should replace the BuiltInAnalysisToolController with the StkController, which includes dependencies for interacting with STK in addition to including all of the same built-in dependencies.

  1. In the UAVMissionDelegateProvider class, remove the following import statement:
    import com.agi.moxie.api.analysistools.BuiltInAnalysisToolController;
  2. Add the following import statement:
    import com.agi.moxie.stk.delegates.core.StkController;
  3. In the return statement of the provideDescriptor() method, replace the BuiltInAnalysisToolController.class argument with StkController.class.

Add the STK toolbox dependency

The StkToolbox dependency is the primary means of interacting with STK from Behavior Execution Engine. In the next section, you will use this dependency to control the STK scenario.

  1. In the UAVDelegate class, add the following import statement:
    import com.agi.moxie.stk.utilities.toolbox.StkToolbox;
  2. Add the following private field declaration:
    private StkToolbox mStkToolbox;
  3. In the constructor, add the following dependency injection and field initialization:
    public UAVDelegate( ...
            @InjectByName("stkToolbox") StkToolbox stkToolbox,
             ... ) {
        mStkToolbox = stkToolbox;
         ...
    }
  4. At the end of the constructor, add the following code to set the units when using STK Connect commands:
    mStkToolbox.sendConnectCommand("Units_SetConnect / Internal");
  5. Repeat the previous steps to add the StkToolbox dependency to the ComputerDelegate and the SensorPayloadDelegate.

Add the STK object initialization

Behavior Execution Engine provides the StkObjectSpatialEntity delegate to facilitate STK object references in your custom delegates.

  1. In the UAVDelegate class, add the following import statements:
    import agi.stkobjects.IAgStkObject;
    import com.agi.moxie.stk.delegates.core.StkEarth;
    import com.agi.moxie.stk.delegates.core.StkObjectSpatialEntity;
  2. In the class declaration, add extends StkObjectSpatialEntity as follows:
    public abstract class UAVDelegate extends StkObjectSpatialEntity implements UAV
  3. Add the following private field declaration:
    private IAgStkObject mStkUavObject;
  4. In the constructor, add the following dependency injection and parent constructor call:
    public UAVDelegate( ...
            @InjectByName("stkEarth") StkEarth stkEarth,
             ... ) {
        super(stkToolbox, stkEarth, timeProvider);
         ...
    }
  5. In the initializeStkObject() method, add the following code to attach to the STK object:
    //Attach to the STK object.
    this.updateFromStkObject(stkObjectPathProperty().getValue());
    mStkUavObject = this.getStkObject();
  6. Repeat the previous steps to initialize the STK object data in the SensorPayloadDelegate, but replace mStkUavObject with mStkSensorObject in the private field declaration and the initializeStkObject() method.

Add an STK simulation configuration

Behavior Execution Engine provides several SysML stereotypes that enable you to configure how your simulation runs. You can use one of these stereotypes to automatically launch the STK scenario for the UAV Mission when the simulation starts.

  1. Copy the STK delegate module (\delegates\com.agi.moxie.stk) from the Behavior Execution Engine installation into your delegate module home directory (e.g., C:\BehaviorExecutionEngine\DelegateHome\com.agi.moxie.stk).
  2. Open the UAVMission.mdzip project from the previous section.
  3. In your No Magic modeling tool, select Options > Project Usages and click Use Project.
  4. In the Use Project dialog box shown in Figure B1, select From file system. If you copied the BEE model libraries to the No Magic modeling tool folders as part of installing BEE, you may find the libraries there by selecting From predefined location.
  5. In the Paths to used projects box, navigate to your BEE installation directory and select <BEE_Install>\modelDependencies.
  6. In the list of MDZIP files, select Moxie-STK.mdzip and click Finish.

    Figure B1: Importing the Behavior Execution Engine STK stereotypes

  7. Close the Used Projects window.
  8. In the Containment Tree, double-click the Simulation > simulation instance specification.
  9. Click the cell to the right of Applied Stereotype and then click the ... button in the upper-right corner of the cell.
  10. Search for and select MoxieStkScenarioFromFile and then click Apply.
  11. Select Tags from the left pane of the specification window, select the scenarioFilePath from the center pane, and click Create Value.
  12. Enter the path to the STK scenario specified in the prerequisites for this section (e.g., ..\UAVMission.vdf) and click Close.
  13. Save your work and reinstall the delegate module.
  14. Execute the simulation and observe that the STK scenario starts up alongside the SysML simulation and that the scenario time advances as the simulation time does.

    Notice that the UAV in the scenario takes off immediately instead of waiting for the startup procedures in the SysML. You will fix this in the next section by syncing the UAV's behavior between the SysML and STK.

  15. Close STK without saving.

Next Section >