Part 13.1:
Integrating STK with MATLAB
STK Pro, STK Premium (Air), STK Premium (Space), or STK Enterprise
You can obtain the necessary licenses for this tutorial by contacting AGI Support at support@agi.com or 1-800-924-7244.
You need to install MATLAB on your computer to complete this tutorial. Version R2023a was used in this tutorial. Your version might have different tools and procedures.
Capabilities covered
This lesson covers the following STK capabilities:
- STK Pro
- STK Integration
Problem statement
If you are a developer, engineer, or operator, you need to do the following tasks quickly and easily:
- Automate repetitive tasks from outside of the STK application
- Integrate STK with other applications, such as MATLAB, Microsoft Excel, and Python
- Develop custom applications
- Leverage the AGI Object Model collection of COM libraries from other applications
You want to be able to create, drive, and extract data from an STK scenario using MATLAB. To do so, you need to understand access to the following Application Programming Interfaces (API): the STK Object Model and Connect. You also need a basic understanding of the structure and contents of the STK Programming Help.
Solution
Using STK, including the STK Integration capability, and MATLAB, create a new instance of STK and expose the object root. Next, build a new scenario, populating it with a Satellite () object and a Target () object. Create an access between the Satellite object and the Target object, extracting access times from STK and moving them into MATLAB. Use the correct data providers, both groups and elements, to determine a precision pass value at a specific time in the scenario. Learn the benefits of the STK Programming Help.
What you will learn
Upon completion of this tutorial, you will have a basic understanding the following:
- STK Programming Help
- STK Object Model
- Connect
- MATLAB code snippets
- MATLAB Connect code snippets
- Data providers
You should shut down STK and MATLAB prior to starting this tutorial. This tutorial isn't designed to teach you how to use MATLAB. It's an introduction to integrating MATLAB with STK and pulling data from STK into MATLAB. It's also an introduction to the STK Programming Help and how important it is to be able to intelligently browse these help pages.
Video guidance
Watch the following video. Then follow the steps below, which incorporate the systems and missions you work on (sample inputs provided).
Accessing the STK Programming Help
The STK Programming Help offers a wide variety of options to automate and customize STK and to integrate its technology into other applications. This tutorial covers only a small portion of the STK Programming Help, but you get a great starting point from which to branch out.
- Open your preferred internet browser.
- Go to help.agi.com.
- Click STK Programming Help.
Integrating with other applications
STK’s Integration capability enables you to automate repetitive tasks from outside the STK application, integrate STK with other applications such as MATLAB and Microsoft Excel, develop custom applications, and leverage the AGI Object Model collection of COM libraries from other applications. Follow these steps to learn more about these possibilities.
- Click Select the Right Technology in the table of contents of the STK Programming Help.
- Select Integrate Technologies.
- Select clickable decision tree on the Integrate With Other Applications topic page.
- Take some time to view the page and click some of the icons.
There are many clickable decision trees available in STK Programming Help. You can use the trees to quickly locate help pages that you need to be successful when integrating with STK.
Automating repetitive tasks
To automate repetitive tasks in STK, you can use HTML, Connect, and STK Objects to build tools that are accessible from within STK. You can find more information on this in the STK Programming Help by following these steps:
- Under Select the Right Technology, click Automate Tasks.
- Select clickable decision tree on the Automate Repetitive Tasks topic page.
- Take some time to view the page and click some of the icons.
Extending AGI products
AGI provides a variety of ways to extend its products. These extensibility mechanisms come under two distinct categories: user interface extensibility and engine extensibility. You can find more information on these in the STK Programming Help by following these steps:
- Under Select the Right Technology, click Extend AGI Products.
- Click clickable decision tree on the Extend AGI Products Using Plugins and Custom User Interfaces topic page.
- Take some time to view the page and click some of the icons.
There are other links throughout that aren't covered here. Take some time later on to become familiar with them.
Visualizing in STK
STK X enables developers to add advanced STK 2D and 3D visualization and analytical capabilities to applications with little effort. You can find more information on this in the STK Programming Help by following these steps:
- In the table of contents, go to Library Reference > Controls > STK X.
- Take some time to familiarize yourself with the contents of this page.
Using core libraries
The STK API consists of two major subsystems: Connect and the STK Object Model.
Core Libraries
- In the STK Programming Help, click Using Core Libraries in the table of contents.
- Note the advantages and disadvantages of using the Connect and Object Model libraries.
Choosing either Connect or Object Model should be driven by the requirements of the application and your needs as a developer. However, this need not be an exclusive choice. You can use Connect commands in a COM application side by side with Object Model code.
Learning STK Object Model naming conventions
The STK Object Model contains naming conventions for classes, interfaces, and enumerations.
Naming Conventions
- In the STK Programming Help, go to Library Reference > STK Object Model > Naming Conventions.
- Note the various naming conventions described in the Naming Conventions Used in the Various Core Libraries topic.
- Click the certain abbreviations link.
- Note the abbreviations most commonly used in the names of classes, interfaces, and other types in the STK Object Model.
Using model diagrams
As a serious programmer, you can use diagrams to see how the STK traffic flow is connected. That way, you know what's to the right, left, above, and below, all while deep linking to the individual IAg interface pages.
- In the STK Programming Help, go to Using Core Libraries > STK Object Model > STK Objects > Diagrams.
- Click STK Object Model Diagram (PDF) in the STK Objects Object Model Diagrams topic.
- Zoom in closer to the page for clarification.
- Take some time to look at the STK 10.0 Object Model Diagrams PDF.
- STK Objects
- STK X
- STK VGT (Analysis Workbench)
- STK Util
- STK Astrogator
- Close the STK Object Model Diagram (PDF) when finished.
- Keep the STK Programming Help open.
A Diagrams topic (with PDF links) exists for each of the following topic folders in the Using Core Libraries folder:
Launching MATLAB
MATLAB is a programming and numeric computing platform used by millions of engineers and scientists to analyze data, develop algorithms, and create models.
- Launch MATLAB.
- Select the Home tab when MATLAB opens.
- Click Layout in the MATLAB Toolstrip.
- Select Default in the Select Layout menu. This makes it easier to follow the tutorial. If you're familiar with MATLAB and have a setup you prefer, keep it.
Creating a new script
MATLAB script files are program files with the .m extension. In these files, you can write groups of commands that you want to execute together. Scripts do not accept inputs and do not return any outputs. They operate on data in the workspace. Scripts are the simplest kind of program file because they have no input or output arguments. After creating a script file for this tutorial, you can use it later to practice with.
- Select the Home tab in the MATLAB Toolstrip.
- Click New Script.
- Select the Editor tab in the MATLAB Toolstrip.
- Open the Save drop-down menu.
- Select Save As....
- Browse to the folder where you will save the .m file (e.g., C:\Users\username\Documents\MATLAB).
- Type STK_Matlab in the File name field.
- Ensure Save as type is set to MATLAB Code files (UTF-8) (*.m).
- Click .
Writing comments in your script
Write comments by preceding the line with the % symbol.
- In the MATLAB Editor, type or copy and paste the following comment onto line 1:
- Press Enter on your keyboard.
%Task1 |
Locating STK Object Model and MATLAB code snippets
Code snippets demonstrate tasks that are commonly encountered when working with the STK Object Model.
- Return to the STK Programming Help.
- Go to Using Core Libraries > STK Object Model > MATLAB Code Snippets.
Creating an STK instance
The AgStkObjectRoot Object is the top-level object in the Object Model hierarchy. The AgStkObjectRoot object provides methods and properties to load scenarios, create new ones, and access the Object Model Unit preferences. From the AgStkObjectRoot object, you can access all other objects and collections exposed by the Object Model.
- Locate Initialization under the subheading "How do I ..." on the MATLAB Code Snippets topic page.
- Select Start STK and get a reference to IAgStkObjectRoot.
- Type or copy and paste the following code to the STK_Matlab.m script onto lines 2 through 4.
- Press Enter.
- Place your cursor in front of %Task1.
- Click Section Break in the MATLAB Toolstrip.
- Place your cursor before %Task1.
- Click Run and Advance in the MATLAB Toolstrip.
- Look at the MATLAB Workspace.
You created a variable called uiApplication and started an instance of STK. You also made the STK splash screen visible.
- AGI recommends that you save your MATLAB script after completing each task section.
You won't use the exact MATLAB snippets as seen in STK Programming Help. When using snippets to create scripts, you need to edit the code to build your custom scenario. You can compare the edited code in this tutorial to the snippet code in STK Programming Help.
% Create an instance of STK uiApplication = actxserver('STK12.Application'); uiApplication.Visible = 1; |
Task 1 Example
Using MATLAB IntelliSense and STK Programming Help
The second part of the Start STK and get a reference to IAgStkObjectRoot snippet shows an example of how to expose the STK object root. Manually enter this information in the MATLAB Command Window for familiarization. MATLAB can work with STK using IntelliSense.
Selecting a root of the Application Model
Use IntelliSense to select an application root of the STK Object Model.
- Put your cursor in the Command Window.
- Type the following: root = uiApplication.; make sure to include the period (.).
- Press the Tab key on your keyboard after the period (.). IntelliSense will show you possible selections.
- Return to the STK Programming Help.
- Type or paste IAgUiApplication in the search field located in the upper-right corner. Case doesn't matter.
- Press Enter.
- Select AgUiApplicationLib~IAgUiApplication in the search results. IAgUiApplication represents a root of the Application Model.
IntelliSense Selections
Exposing the STK object root
Looking at the IAgUiApplication page, most of what you see in IntelliSense matches the Public Methods and Properties.
- Scroll down the IAgUiApplication Interface help topic page to Public Properties.
- Select Personality2, which returns a new instance of the root object of the STK Object Model.
- Return to the Command Window.
- Press the Tab while the cursor is just after the period (.) of the root = uiApplication. command.
- Select Personality2 in IntelliSense.
- Press Enter.
- Place a semicolon after Personality2.
- Press Enter.
- Add this whole line (root=uiApplication.Personality2;) to your MATLAB script on line 6.
- Look at the MATLAB Workspace. You've exposed the STK object root, so you can start creating a scenario.
You could have searched for any of the IntelliSense selections. Searching for Personality2 would have taken you directly to the help page and its description.
Scripting for a new scenario
You will use your MATLAB script to interact with STK. You've launched STK via the MATLAB interface. Now create a new scenario, set the scenario time period, and reset the animation time.
- In the STK_Matlab.m script, type or copy and paste the following comment on lines 7 and 8:
- Press Enter. This adds a section break and the task identifier at the same time. You will do this for all subsequent tasks.
- Return to MATLAB Code Snippets under Using Core Libraries > STK Object Model in the STK Programming Help.
- Locate SCENARIO MANAGEMENT (under Scenario) on the MATLAB Code Snippets topic page.
- Select Create a new Scenario.
- In MATLAB, type or copy and paste the following to the STK_Matlab.m script onto lines 9 and 10.
- Press Enter.
%% %Task2 |
% IAgStkObjectRoot root: STK Object Model Root root.NewScenario('Example_Scenario'); |
Using the IAgStkObjectRoot Interface
IAgStkObjectRoot Interface represents the automation interface supported by the root object of the Automation Object Model.
- Return to the STK Programming Help.
- Type or copy and paste "IAgStkObjectRoot" in the Search field.
- Press Enter.
- Select STKObjects~IAgStkObjectRoot in the search results.
- Select NewScenario in the Public Methods list.
Creating a new scenario
The NewScenario Method creates a new scenario.
- There is no syntax specifically for MATLAB, so look at the syntax for [Visual Basic .NET].
- Select ScenarioName in the Visual Basic .NET syntax.
Syntax
The NewScenario method expects a string that is the scenario name. In the line you added to Task 2, you set the scenario name as Example_Scenario.
Set the analysis start and stop times
- Return to MATLAB Code Snippets.
- Locate SCENARIO MANAGEMENT on the MATLAB Code Snippets topic page.
- Select Change scenario time period.
- Type or copy and paste the following to the STK_Matlab.m script onto lines 11 and 12.
- Press Enter.
- CurrentScenario Property (IAgStkObjectRoot) returns a scenario object or null if you have not loaded a scenario yet.
- SetTimePeriod Method (IAgScenario) sets the scenario time period. It expects a start time and stop time of the scenario period.
% IAgStkObjectRoot root: STK Object Model Root root.CurrentScenario.SetTimePeriod('Today', 'Tomorrow'); |
You are only using the first two lines of code from the snippet. STK automatically sets the scenario epoch time to match your analysis start time.
Resetting the scenario animation time
- Return to MATLAB Code Snippets.
- Locate SCENARIO MANAGEMENT on the MATLAB Code Snippets topic page.
- Select Reset the scenario time.
- Type or copy and paste the following to the STK_Matlab.m script onto lines 13 and 14:
- Press Enter. You are using Rewind Method (IAgAnimation) to stop and reset the animation.
- Place your cursor in front of %Task2.
- Click Run and Advance in the MATLAB Toolstrip.
% IAgStkObjectRoot root: STK Object Model Root root.Rewind; |
Task 2 Example
Looking at STK, a new scenario named Example_Scenario () is open and the time has been reset in the Current Scenario Time field of the Animation toolbar.
Inserting a Target object
To create a new object such as a Target () object, use AgESTKObjectType Enumeration. Not every object in STK has an associated snippet, so you might need to do some editing. Target (), Place (), and Facility () objects contain the same properties. They're seen as different object classes. In this instance, since there isn't a snippet to insert a new Target object into the scenario, use the Facility object code and make some simple changes to the code.
- Return to your MATLAB script.
- Type or copy and paste the following comments onto lines 15 and 16:
- Press Enter.
- Return to MATLAB Code Snippets.
- Locate FACILITY on the MATLAB Code Snippets topic page.
- Select Create a facility (on the current scenario central body).
- Type or copy and paste the following to the STK_Matlab.m script onto lines 17 and 18.
- Press Enter.
%% %Task3 |
% IAgStkObjectRoot root: STK Object Model Root target = root.CurrentScenario.Children.New('eTarget', 'MyTarget'); |
The snippet code is: facility = root.CurrentScenario.Children.New('eFacility', 'MyFacility');. You are swapping out the variable eFacility for eTarget and changing the name to 'My Target'.
Retrieving the current scenario
The CurrentScenario property returns a Scenario () object or null if no scenario has been loaded yet.
- Return to the STK Programming Help.
- Enter "CurrentScenario" in the Search field.
- Press Enter.
- Select STKObjects~IAgStkObjectRoot~CurrentScenario in the search results.
- Go to Visual Basic.NET syntax in the CurrentScenario Property (IAgStkObjectRoot) topic page.
- Select IAgStkObject.
VB.NET IAgStkObject
Retrieving children of an object
IAgStkObject Interface represents the instance of an STK object. Children Property (IAgStkObject) returns a collection of direct descendants of the current object.
- Go to Public Properties on the IAgStkObject Interface topic page.
- Select Children.
- Go to Visual Basic.NET syntax in the Children Property (IAgStkObject) topic page.
- Click IAgStkObjectCollection.
Retrieving a collection of STK objects
IAgStkObjectCollection Interface represents a collection of STK objects.
- Go to Public Methods in the IAgStkObjectCollection Interface topic page.
- Select New.
Creating an STK object
New Method (IAgStkObjectCollection) creates an STK object using a specified class and instance name.
- Go to the Visual Basic.NET syntax on the New Method (IAgStkObjectCollection) topic page.
- Click AgESTKObjectType.
AgESTKObjectType Enumeration
The AgESTKObjectType Enumeration topic page shows STK objects (members) with their values and descriptions. When using the AgESTKObjectType Enumeration to insert a new Target () object, you can use the member name eTarget or the value 23. In this case, you are using eTarget and setting the Target object's name to MyTarget. This is another way to use the STK Programming Help. On your own, you might have to take some time working your way through the pages to find what you're looking for.
Placing the Target object
Place the Target object at a specific location.
Assigning the location
Use a MATLAB code snippet to assign the location of the Target.
- Return to MATLAB Code Snippets.
- Locate FACILITY in the MATLAB Code Snippets page.
- Click Set the geodetic position of the facility.
- Type or copy and paste the following to the STK_Matlab.m script onto lines 19 through 21.
- Press Enter.
- Position Property (IAgTarget) gets the position of the target.
- IAgPosition Interface provides access to the position of the object.
- AssignGeodetic Method (IAgLLAPosition) assigns the position using geodetic representation.
- In the script, place your cursor in front of %Task3.
- Click Run and Advance in the MATLAB Toolstrip.
% IAgTarget Interface provides access to the properties and methods used in defining a target object. % Latitude, Longitude, Altitude target.Position.AssignGeodetic(50, 100, 0) |
Task 3
Checking the location in STK
- Bring STK to the front to view MyTarget () in the 2D and 3D Graphics windows.
- Right-click MyTarget () in the Object Browser.
- Select Properties ().
- Note the Latitude, Longitude, and Altitude on the Basic > Position page.
- Click to close MyTarget's properties ().
If you have an Internet connection and are using Terrain Server, Altitude will have a value higher than 0 km. That's because you placed the Target object on the surface of the terrain. If you are not using the Terrain Server, the Target object will be on the surface of the WGS84 ellipsoid.
Inserting a Satellite object
- Return to your MATLAB script.
- Type or copy and paste the following comments onto lines 22 and 23:
- Press Enter.
- Return to MATLAB Code Snippets.
- Locate SATELLITE in the MATLAB Code Snippets page.
- Select Create a satellite (on the current scenario central body).
- Return to your MATLAB script.
- Type or copy and paste the following to the STK_Matlab.m script onto lines 24 and 25.
- Press Enter.
%% %Task4 |
% IAgStkObjectRoot root: STK Object Model Root satellite = root.CurrentScenario.Children.New('eSatellite', 'MySatellite'); |
Learning about Connect
The Connect module provides you with an easy way to connect with STK and work in a client-server environment. You can use the library shipped with Connect to build applications that communicate with STK. This library contains functions, constants, and other messaging capabilities that you can use to connect third-party applications to STK.
- Return to the STK Programming Help.
- Go to Using Core Libraries > Connect.
This is a great place to learn about Connect. Take some time to become familiar with the links on this page.
Propagating your satellite via Connect
Just like you did while using the STK Object Model and MATLAB Code Snippets, you can use the MATLAB Connect Code Snippets help topic to become familiar with Connect. Use Connect to propagate your Satellite () object.There are several propagators in STK (e.g., Two-Body, J2 Perturbation, J4 Perturbation, SGP4, etc.).
- Go to Using Core Libraries > Connect > Connect Code Snippets.
- Locate Satellite in the MATLAB Connect Code Snippets topic page.
- Select Set initial state of satellite and propagate.
- Return to your MATLAB script.
- Type or copy and paste the following to the STK_Matlab.m script onto lines 26 and 27.
- Press Enter.
- ExecuteCommand Method executes a custom Connect action.
- Units_Set sets units of measure. You're using Units_Set because Connect's distance unit defaults to meters and you require kilometers.
root.ExecuteCommand('Units_Set * Connect Distance "Kilometers"'); %Default Connect Units are meters root.ExecuteCommand('SetState */Satellite/MySatellite Classical TwoBody "UseAnalysisStartTime" "UseAnalysisStopTime" 60 ICRF "UseAnalysisStartTime" 6678.14 0 28 180 0 180'); |
This is an instance where the Connect Command has changed but the snippet uses an old command. In the snippets, the code is root.ExecuteCommand('SetUnits / km'). SetUnits is an obsolete command. If you have a set of commands and upgrade to a new version of STK and the command no longer works, go to Deprecated Commands. You will find both deprecated commands and obsolete commands. Locate the bad command and you will find the command that has replaced it.
Setting the Satellite state
Learning about the SetState Connect command
Look at the Alphabetical Listing of Connect Commands to get information on the SetState command.
- Return to the STK Programming Help.
- Go to Library Reference > Connect Command Library.
- Note the links in the Connect Command Listings page.
- Select Alphabetical Listing of Connect Commands. The Alphabetical listing includes all Connect commands, regardless of their groupings.
- Click "S" at the top of the Alphabetical Listing page.
- Locate and select the SetState Classical command.
- Scroll through the SetState Classical page and note the following:
- Syntax will help you understand the input values of your SetState command.
- The description chart explains each input and its associated unit.
- In the Examples section, there are several examples that you can copy and edit for your particular scenario.
Using MATLAB to set the Satellite state
- Return to your MATLAB script.
- Using SetState syntax, set the following values in the SetState Connect command that you entered into your MATLAB script.
- Place your cursor in front of %Task4.
- Click Run and Advance in the MATLAB Toolstrip.
- Bring STK to the front to view MySatellite in the 2D and 3D Graphics windows.
- Open MySatellite's () properties ().
- Note and match the property settings and values to your SetState Connect command.
- Click when finished.
Option | Value |
---|---|
SemiMajorAxis | 7200 |
Eccentricity | 0 |
Inclination | 90 |
ArgOfPerigee | 0 |
RAAN | 0 |
MeanAnom | 0 |
The SetState command in MATLAB should match the following:
root.ExecuteCommand('SetState */Satellite/MySatellite Classical TwoBody "UseAnalysisStartTime" "UseAnalysisStopTime" 60 ICRF "UseAnalysisStartTime" 7200 0 90 0 0 0'); |
Task 4
Creating access intervals between MySatellite and MyTarget
Use the STK Object Model to create access intervals from MySatellite () to MyTarget ().
Entering the access commands into MATLAB
Use your MATLAB script to enter access computation commands.
- Return to your MATLAB script.
- Type or copy and paste the following comments onto lines 28 and 29:
- Press Enter.
- Return to STK Programming Help.
- Go to Using Core Libraries > STK Object Model > MATLAB Code Snippets.
- Locate ACCESS on the MATLAB Code Snippets topic page.
- Select Compute an access between two STK Objects (using IAgStkObject interface).
- Return to your MATLAB script.
- Type or copy and paste the following to the STK_Matlab.m file onto lines 30 through 33.
- Press Enter.
%% %Task5 |
% Get access by STK Object access = satellite.GetAccessToObject(target); % Compute access access.ComputeAccess(); |
Computing and checking the access intervals
Run the latest MATLAB commands and check the access calculation results in STK.
- GetAccessToObject Method (IAgStkObject) returns an IAgStkAccess object. In this instance, you're creating an access from the Satellite object to the Target object.
- ComputeAccess Method (IAgStkAccess) recomputes the access between two objects.
- In the script, place your cursor in front of %Task5.
- Click Run and Advance in the MATLAB Toolstrip.
- Bring STK to the front. You can see access lines over Asia in the 2D Graphics window.
Task 5
Retrieve the access data
You created access intervals between the Satellite () object and the Target () object. An easy way to extract and see those times is to create an interval collection of access start and stop times.
Scripting access interval retrieval in MATLAB
Write a MATLAB script task to get the access interval times from STK.
- Return to your MATLAB script.
- Type or copy and paste the following comments onto lines 34 and 35:
- Press Enter.
- Return to MATLAB Code Snippets.
- Locate ACCESS in the MATLAB Code Snippets page.
- Select Compute and extract access interval times.
- Return to your MATLAB script.
- Type or copy and paste the following to the STK_Matlab.m script onto lines 36 through 40.
- Press Enter.
- ComputedAccessIntervalTimes Property (IAgStkAccess) returns a list of the computed access interval times.
- IntervalCollections Property (IAgCrdnIntervalsVectorResult) is a collection of interval collections.
- ToArray Method (IAgIntervalCollection) returns a two-dimensional array of intervals beginning at a given position and having a specified number of rows.
- SpecifyAccessIntervals Method (IAgStkAccess) specifies a list of intervals to use for the access calculation.
%% %Task6 |
% IAgStkAccess access: Access calculation % Get and display the Computed Access Intervals intervalCollection = access.ComputedAccessIntervalTimes; % Set the intervals to use to the Computed Access Intervals computedIntervals = intervalCollection.ToArray(0, -1); |
Retrieving the access interval times
Run Task 6 of your MATLAB script to retrieve the access inteval times.
- In the script, place your cursor in front of %Task6.
- Click Run and Advance in the MATLAB Toolstrip.
- In the MATLAB Workspace, double-click computedIntervals.
- When the computedIntervals cell opens, expand column 1 and column 2 so you can read the access data; your data will have different values. Column 1 shows the start times of the accesses and column 2 shows the stop times.
- When finished, close the cell.
Task 6
Investigating data providers
STK generates reports and graphs using selected data providers for the specific report or graph style. You can view data providers, both groups and individual elements, when using the Report & Graph Manager inside of STK. The STK Programming Help contains details of data provider groups, individual elements, and report and graph styles.
- Type or copy and paste the following to the STK_Matlab.m script onto lines 41 and 42:
- Press Enter.
- Return to STK Programming Help.
- Go to Library Reference > Data Providers Reference.
%% %Task7 |
In the Data Providers by Object page, you can spend a lot of time looking at an object's data providers, both groups and elements.
Extracting data providers
Your scenario is 24 hours long. The Satellite () object data provider group named "Passes" contains extensive data about the satellite's orbit for each pass. The data provider group "Precision Passes" contains, for specific times, the following:
- Precision pass number - This number has two parts: the integer pass number for the given time and the fraction of the orbit from the ascending node for that time.
- Precision path number - This is the satellite's orbit path number, which will remain at the value of 1 until the ground track repeats, at which time the number will increase to 2, and so on..
Use MATLAB to extract these data.
- Go to Using Core Libraries > STK Object Model > MATLAB Code Snippets in the STK Programming Help.
- Locate DATA PROVIDERS on the MATLAB Code Snippets topic page.
- Select Getting Data for a Single Point in Time.
- Return to your MATLAB script.
- Type or copy and paste the following to the STK_Matlab.m file onto lines 43 through 48
- Press Enter.
% IAgStkObjectRoot root: STK Object Model root % IAgSatellite satellite: Satellite object % Change DateFormat dimension to epoch seconds to make the data easier to handle in MATLAB root.UnitPreferences.Item('DateFormat').SetCurrentUnit('EpSec'); satPassDP = satellite.DataProviders.Item('Precision Passes').ExecSingle(2600); pass = cell2mat(satPassDP.DataSets.GetDataSetByName('Precision Pass Number').GetValues); |
Task 7
Setting date format and elements
- Look at the code from line 46: root.UnitPreferences.Item('DateFormat').SetCurrentUnit('EpSec');
- UnitPreferences Property (IAgStkObjectRoot) provides access to the Global Unit table.
- Item Property (IAgUnitPrefsDimCollection) returns IAgUnitPrefsDim, for which you give a dimension name or an index. The data provider is DateFormat.
- SetCurrentUnit Method (IAgUnitPrefsDimCollection) sets unit preferences. You are using epoch seconds, or EpSec.
- Return to the STK Programming Help.
- Go to Using Core Libraries > STK Object Model > STK Util > Dimensions and Units.
- Scroll down to DateFormat in the STK Object Model Unit Preferences page.
- Look at Available Units. The Epoch Seconds element is EpSec.
Your scenario's default date format is Gregorian UTC (UTCG). As stated in the code snippet, changing the DateFormat dimension to epoch seconds to makes the data easier to handle in MATLAB. Since your scenario is 24 hours long, STK expresses the scenario end time as 86400 EpSec. Thus, a scenario UTCG time of 30 Jun 2023 08:11:49.699 will now appear as 15109.699 EpSec. This is easier to read and use in MATLAB.
Selecting satellite data providers
- Return to your MATLAB script.
- Look at the code from line 47: satPassDP = satellite.DataProviders.Item('Precision Passes').ExecSingle(2600);
- DataProviders Property (IAgStkObject) returns the object representing a list of available data providers for the object. In this case, it is a Satellite () object.
- ExecSingle Method (IAgDataPrvTimeVar) computes the data given a specific time. SingleTime uses the DateFormat Dimension, which you set to EpSec.
- Return to STK Programming Help.
- Go to Library Reference > Data Providers Reference.
- Select Satellite in the Data Providers by Object page.
- Select Precision Passes in the Available Data Providers chart.
Retrieving the Precision Pass data
- Return to your MATLAB script.
- Look at the code from line 48: pass = cell2mat(satPassDP.DataSets.GetDataSetByName('Precision Pass Number').GetValues);
- cell2mat converts a cell array into an ordinary array in MATLAB.
- DataSets Property (IAgDrResult) returns a collection of datasets.
- GetDataSetByName Method (IAgDrDataSetCollection) returns the element for a given name, which in this case is the Precision Passes data provider element Precision Pass Number.
- GetValues Method (IAgDrDataSet) retrieves an array of values of the elements in the dataset.
- Place your cursor in front of %Task7.
- Click Run and Advance in the MATLAB Toolstrip.
- Look at the pass value (e.g., 1.4276) in the MATLAB Workspace.
Precision Pass Value
The Precision Pass Number of the satellite at the analysis start time (0 epoch seconds) is 1.0000. For the above example, a Precision Passes value of 1.4276 indicates that the Satellite object has orbited the central body almost one-half of an orbit based on the given scenario time of 2600 epoch seconds. With a 24-hour analysis period, any value from 0 through 86400 epoch seconds will work. You can change this value and rerun task 7 to determine precision pass numbers throughout the 24-hour analysis period.
Summary
You began by viewing a small portion of the STK Programming Help pages. Next, using MATLAB code snippets, you performed the following:
- Created a connection between MATLAB and the STK Application
- Exposed the STK object root
- Created a new scenario
- Inserted and positioned a Target object
- Inserted and propagated a Satellite object
- Calculated accesses between the Satellite object and the Target object
- Extracted access data from STK into MATLAB
- Used data providers to changes time units from UTCG to EpSec
- Extracted a satellite precision pass value from STK into MATLAB
On your own
Throughout the tutorial, hyperlinks were provided that pointed to in-depth information concerning the STK Object Model and Connect. Now is a good time to go back through this tutorial and view that information. Obviously, there is a lot to learn. However, this tutorial should have provided some familiarization on how to use STK Programming Help. Explore!
The STK Programming Help provides tutorials designed to help you become more familiar with the STK Object Model and Connect.
AGI maintains a GitHub repository of code samples to help you get started with the STK Object Model.