Part 13: Integrating STK with MATLAB

STK Pro, STK Premium (Air), STK Premium (Space), or STK Enterprise
You can obtain the necessary licenses for this training by contacting AGI Support at support@agi.com or 1-800-924-7244.

Capabilities Covered

This lesson covers the following STK Capabilities:

  • STK Pro
  • STK Integration

Integrating STK and MATLAB

Watch the following video. Then follow the steps below, which incorporate the systems and missions you work on (sample inputs provided).

STK's Integration capability enables you to control STK from an external application, such as MATLAB. There are several options for how to integrate STK and MATLAB, although the most common method is using Microsoft COM. Using the COM interface, you can connect to STK's Object model and Connect interfaces.

You can easily explore the Object Model using the .get and .invoke commands from the MATLAB prompt. Additionally, there are code snippets in the STK Help for the STK Object Model.

There are several MATLAB code samples installed with STK. They are in C:\Program Files\AGI\STK 12\CodeSamples\Automation.

The STK Programming Interface help has many object-specific MATLAB code snippets to assist you.

A recorded PowerPoint Presentation and MATLAB script accompanies this lesson. It is recommended that you follow the presentation while performing the tasks. If you don't want to use the MATLAB Script, you can type the commands right in the MATLAB Command Window.

Create a New Instance of STK from Inside MATLAB

Let's use MATLAB to create a new instance of STK.

  1. Launch MATLAB.
  2. Select the Home tab.
  3. Click the Open button.
  4. Browse to the location of the saved script file.
  5. Open the STK_MATLAB_Script.m file (Typically in, <STK Install Folder>\Data\Resources\stktraining\scripts).

MATLAB is up and running. You can use the MATLAB script file to build a simple STK scenario from which you will extract data into MATLAB.

When connected to STK via MATLAB, while creating your variable, using the Tab key after periods enables Intellisense, which displays all of the options available off of the current object. Try it. Create a new instance of STK12 in MATLAB.

  1. In MATLAB, type the following code into the Command window:
  2. app = actxserver('STK12.application')

    app.UserControl = 1

    app.Visible = 1

    To suppress the output message you can add a semicolon (;) at the end of each line.

  3. Grab a handle on the STK application root.
  4. root = app.Personality2

Create a New STK Scenario from Inside MATLAB

Now that you have launched STK via the MATLAB interface, let's see if we can create a new scenario, set the time period via MATLAB, and reset the animation time.

  1. In MATLAB, place your cursor to the left of the percentage sign for Task 2.
  2. Select CTRL + Enter to run all of the MATLAB code in Task 2.
  3. %Task 2

  4. Create a new scenario:
  5. scenario = root.Children.New('eScenario','Matlab_Starter')

  6. Set the analytical time period:
  7. scenario.SetTimePeriod('Today','+24hr')

  8. Reset the Animation Time:
  9. root.ExecuteCommand('Animate * Reset')

  10. Click on your STK scenario and see the name of the scenario, scenario analysis period, and the animation time have been updated.

Insert and Configure Objects

With a new scenario created, it's time to populate the scenario with objects. Take a moment to create a target and a LEO satellite using MATLAB.

  1. In MATLAB, place your cursor to the left of the percentage sign for Task 3.
  2. Select CTRL + Enter to run all of the MATLAB code in Task 3.
  3. %%
    %Task 3

  4. Add a target object to the scenario.
  5. target = scenario.Children.New('eTarget','GroundTarget');

  6. Move the Target object to a desired location.
  7. target.Position.AssignGeodetic(50,-100,0)

  8. Add a satellite and configure its properties.
  9. satellite = scenario.Children.New('eSatellite','LeoSat')

  10. Propagate the satellite object's orbit.
  11. root.ExecuteCommand(['SetState */Satellite/LeoSat Classical TwoBody "',scenario.StartTime,'" "',scenario.StopTime,'" 60 ICRF "',scenario.StartTime,'" 7200000.0 0.0 90 0.0 0.0 0.0'])

  12. Click on the STK scenario and look at the added Ground Target at )50, -100) and the Propagated LeoSat.

Compute Access Between Objects

You have a scenario with a target object and a satellite object. You can determine when the satellite object can access the target object.

  1. Browse to the STK Programming Interface Help files.
  2. Locate and manually enter code into MATLAB to compute an access between two STK Objects using the IAgStkObject interface. The access is between the satellite object and the target object.Closed
    1. The location of the required code snippets is STK Programming Interface -> Using Core Libraries -> STK Object Model -> MATLAB Code Snippets.
    2. Locate the Compute an access between two STK Objects (using IAgStkObject interface) page.
    3. Type the following code
    4. access = satellite.GetAccessToObject(target)
      access.ComputeAccess

    5. Bring the STK scenario to the front and look for the access ground tracks in the 2D Graphics window.
  3. Retrieve access interval start/stop times.
  4. In MATLAB, place your cursor to the left of the percentage sign for Task 4.
  5. Select CTRL + Enter to run all of the MATLAB code in Task 4.
  6. accessDP = access.DataProviders.Item('Access Data').Exec(scenario.StartTime,scenario.StopTime);
    accessStartTimes = accessDP.DataSets.GetDataSetByName('Start Time').GetValues
    accessStopTimes = accessDP.DataSets.GetDataSetByName('Stop Time').GetValues

  7. Scroll through the MATLAB Command Window to see the access start and stop times.

Generating the Start & Stop times in MATLAB can also be done using the following lines of code.

accessIntervals = access.ComputedAccessIntervalTimes

accessDataProvider = access.DataProviders.Item('Access Data')

for i = 1:1:accessIntervals.Count

	[start, stop]   = accessIntervals.GetInterval(i-1)

end

More information available in STK Object Model Tutorial.

Retrieve Satellite Altitude During Access

  1. Retrieve and view the altitude of the satellite during an access interval.
  2. In MATLAB, place your cursor to the left of the percentage sign for Task 5.
  3. Select CTRL + Enter to run all of the MATLAB code in Task 5.
  4. %%
    %Task 5

    satelliteDP = satellite.DataProviders.Item('LLA State').Group.Item('Fixed').ExecElements(accessStartTimes{1},accessStopTimes{1},60,{'Time';'Alt'});
    satellitealtitude = satelliteDP.DataSets.GetDataSetByName('Alt').GetValues

  5. Scroll through the MATLAB Command Window to see the altitude data output.

After the analysis, enter the following code in the Command window to save the scenario. First create a folder where you would like to save the scenario.

% Enter the file path of where you would like to save the materials
filePath = ['Your File Path' scenario.InstanceName]
%Create a new scenario folder in that location
mkdir(filePath);
%save the scenario
root.SaveScenarioAs([filePath '\MatlabStarter.sc']);

After you save, you can also close out of your scenario:

root.CloseScenario();

Don't forget to save your work!

For additional MATLAB training with STK, refer to: Using MATLAB for STK Automation (PDF).