Use MATLAB to change and report on STM components in Astrogator

« Go Back

Information

 
Notes/Code
With STK 11.4 there is now the ability to report out the state transition matrix components for an astrogator propagate segment.  You must first create a custom propagator in the component browser and add the State Transition Matrix as a propagator function.  Then, for any propagate segment that uses a propagator with the STM added, you can report out the components.  In the component browser there are already template components for the STM under Calculation Objects > Cartesian STM.  If you are orbiting Earth, these components will work just fine, but if you are at a different central body, you will need to duplicate each of these components and set the reference frame to a frame for the central body that you are orbiting.  

The attached zip file contains a MATLAB script (also shown below) that connects to the included scenario with a satellite orbiting Mars.  The satellite is already configured with a propagate segment that uses a custom propagator called Mars HPOP with STM that has the state transition matrix added to it.  The script creates duplicates of all the STM components and changes the reference frame to Mars J2000.  It then reports out the STM at a given instant in time.
 
close all; clear all; clc
format long  g

% Get reference to running STK instance
uiApplication = actxGetRunningServer('STK11.application');

% Get our IAgStkObjectRoot interface
root = uiApplication.Personality2;

% Get handle for scenario
scenario = root.CurrentScenario;

%Get handle for satellite
SatPath = '*/Satellite/MarsSat';
Sat = root.GetObjectFromPath(SatPath);

% Duplicate and modify STM components for Mars
%Get the calc objs Folder
compBrowser = scenario.ComponentDirectory.GetComponents('eComponentAstrogator').GetFolder('Calculation Objects');
%Get the cartesian STM Folder
STM = compBrowser.GetFolder('Cartesian STM');

FinalVarList = ['PosX'; 'PosY'; 'PosZ'; 'VelX'; 'VelY'; 'VelZ'];
InitVarList = ['PosX'; 'PosY'; 'PosZ'; 'VelX'; 'VelY'; 'VelZ'];

for ff = 1:length(FinalVarList)
    for ii = 1:length(InitVarList)
        
        string = ['STM',FinalVarList(ff,:),InitVarList(ii,:)];
        
        try STM.Item([string,'Mars']); %this checks if it already exists
        catch %if it does not exist, create it below
            %Grab the STM component
            STMComponent = STM.Item(string);
            %Make a copy of the Model to Edit it
            STMComponentClone = STMComponent.CloneObject;
            
            %Grab a handle of the new STM Component and edit properties
            NewSTMComponent = STM.Item([string,'1']);
            NewSTMComponent.Name = [string,'Mars'];
            NewSTMComponent.CoordSystemName = 'CentralBody/Mars J2000';
        end
        
    end
end

%Change DateFormat dimension to epoch seconds to make the data easier to handle in
%MATLAB
root.UnitPreferences.Item('DateFormat').SetCurrentUnit('EpSec');


%Extract STM components at a single time
time = 0; %EpSec
STMDP = Sat.DataProviders.Item('Astrogator Values').Group.Item('Cartesian STM').ExecSingle(time);

STMMatrix = zeros(6,6);
for ff = 1:length(FinalVarList)
    for ii = 1:length(InitVarList)
        
        string = ['STM',FinalVarList(ff,:),InitVarList(ii,:),'Mars'];
        STMMatrix(ff,ii) = cell2mat(STMDP.DataSets.GetDataSetByName(string).GetValues);
        
    end
end