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.
- Launch MATLAB.
- Select the Home tab.
- Click the Open button.
- Browse to the location of the saved script file.
- 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.
- In MATLAB, type the following code into the Command window:
- Grab a handle on the STK application root.
app = actxserver('STK11.application')
app.UserControl = 1
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.
- In MATLAB, place your cursor to the left of the percentage sign for Task 2.
- Select CTRL + Enter to run all of the MATLAB code in Task 2.
- Create a new scenario:
- Set the analytical time period:
- Reset the Animation Time:
- Click on your STK scenario and see the name of the scenario, scenario analysis period, and the animation time have been updated.
%Task 2
scenario = root.Children.New('eScenario','Matlab_Starter')
scenario.SetTimePeriod('Today','+24hr')
root.ExecuteCommand('Animate * Reset')
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.
- In MATLAB, place your cursor to the left of the percentage sign for Task 3.
- Select CTRL + Enter to run all of the MATLAB code in Task 3.
- Add a target object to the scenario.
- Move the Target object to a desired location.
- Add a satellite and configure its properties.
- Propagate the satellite object's orbit.
- Click on the STK scenario and look at the added Ground Target at )50, -100) and the Propagated LeoSat.
%%
%Task 3
target = scenario.Children.New('eTarget','GroundTarget');
target.Position.AssignGeodetic(50,-100,0)
satellite = scenario.Children.New('eSatellite','LeoSat')
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'])
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.
- Browse to the The STK Programming Interface help files.
- 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.
- Retrieve access interval start/stop times.
- In MATLAB, place your cursor to the left of the percentage sign for Task 4.
- Select CTRL + Enter to run all of the MATLAB code in Task 4.
- Scroll through the MATLAB Command Window to see the access start and stop times.
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
Retrieve Satellite Altitude During Access
- Retrieve and view the altitude of the satellite during an access interval.
- In MATLAB, place your cursor to the left of the percentage sign for Task 5.
- Select CTRL + Enter to run all of the MATLAB code in Task 5.
- Scroll through the MATLAB Command Window to see the altitude data output.
%%
%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
Don't forget to save your work!
For additional MATLAB training with STK, refer to Using MATLAB for STK Automation (PDF)