Part 16: Integrating STK with MATLAB

Integrating STK and MATLAB

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

The STK Integration module allows 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, MATLAB users can connect to STK's Object model and Connect interfaces.

The Object Model can easily be explored 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 can be found in C:\Program Files (x86)\AGI\STK 11\CodeSamples\Automation.

The STK Programming Interface help system has several 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.

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 STK11 in MATLAB.

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

    app.UserControl = 1

  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 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.

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.

Don't forget to save your work!

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