Modifying All Astrogator Segments of a Specified Type

« Go Back


Often it is useful to modify all segments of a particular type for an Astrogator satellite. Examples include switching all target sequences to Run Active Profiles, changing the maneuver attitude type, and some less common task such as replacing old Design Explorer Optimizers with newer SNOPT Optimizers.

Below is an example in Matlab showing how to do all of these. There are two functions:
  • updateAllSegments - Example showing how to modify multiple Astrogator segments at once 
  • FilterSegmentsByType - Helper function to grab all segments of a specified type
Helper functions such as these were the topic of our July 2018 blog and webinar on Customizing Trajectory Design Tools:
%% updateAllSegments
% Author: Austin Claybrook
% Organization: Analytical Graphics Inc.
% Date Created: 03/22/19
% Last Modified: 03/22/19 by Austin Claybrook

% Description: An example of how to modify the properties of every segment 
% of a specified type for an Astrogator satellite. Three examples are shown:
% Changing each target sequence to Run Active Profile (or Run Nominal Sequence)
% Changing each maneuver attitude type to thrust vector 
% Replacing every Design Explorer Optimizer with a SNOPT Optimizer

% Instructions: Have STK open with an Astrogator satellite, update the
% Input Section, uncomment one of the example sections of code

% Note: This example can be used with another Code Example called FilterObjectsByType
% to do this for multiple satellites

%% Inputs:
satPath = 'Satellite/Satellite1'; % Path to existing Astrogator satellite
segType = 'TargetSequence'; % Type of Astrogator segment to modify
% segType = 'Maneuver';

%% Code
% Attach to Open STK Scenario
app = actxGetRunningServer('STK11.Application');
root = app.Personality2;

% Get a handle to an Astrogator satellite
sat = root.GetObjectFromPath(satPath);

% Get a handle to the MCS Segment Collection
segs = sat.Propagator.MainSequence;

% Get a handle to all of segments of a specified type in the MCS
segHandles = [];
[segHandles] = FilterSegmentsByType(segs,segType,segHandles);

% Append segments from AutoSequences to segHandles
for k = 1:sat.Propagator.AutoSequence.Count
    [segHandles] = FilterSegmentsByType(sat.Propagator.AutoSequence.Item(k-1).Sequence,segType,segHandles);

% Modify the properties of every segment
for j = 1:length(segHandles)
    segj = segHandles(j);
%% Uncomment to Convert All Maneuver Attitude Types to Thrust Vector. Use segType = 'Maneuver'
%     segj.Maneuver.SetAttitudeControlType('eVAAttitudeControlThrustVector'); 
%% Uncomment to Set All Target Sequences to Run Active Profiles or Run Nominal Sequence. Use segType = 'TargetSequence'
%     segj.Action = 'eVATargetSeqActionRunActiveProfiles'; % 'eVATargetSeqActionRunNominalSeq'
%% Uncomment to Replace all Design Explorer Optimizers with a SNOPT Optimizer. Use segType = 'TargetSequence'
%     for k = 1:segj.Profiles.Count
%         profile = segj.Profiles.Item(k-1);
%         if strcmp(profile.Type,'eVAProfileDEOptimizer')
%             replacementProfileType = 'SNOPT Optimizer'; % 'Differential Corrector'
%             dc = segj.Profiles.Add(replacementProfileType);
%             dc.Name = ['DEOptimizer Replaced With ',replacementProfileType];
%             dc.Mode = 'eVAProfileModeNotActive';
%             segj.Profiles.Remove(k-1);
%         end
%     end   

%% FilterSegmentsByType
% Author: Austin Claybrook
% Organization: Analytical Graphics Inc.
% Date Created: 03/20/19
% Last Modified: 03/22/19 by Austin Claybrook
% Description: For an Astrogator satellite, grabs all segments of a
% specified type and returns a list of handles to the segments.

%% Inputs:
% segs: Handle to list of Astrogator segments [IAgVAMCSSegmentCollection]
% segType: Segment type of an Astrogator satellite, i.e. TargetSequence,Maneuver, etc. [string]
% segHandles: Column vector storing the list of handles to the segments [nx1 column vector]

%% Code
function [segHandles] = FilterSegmentsByType(segs,segType,segHandles)
    for i = 1:segs.Count
        seg = segs.Item(i-1);
        if strcmp(seg.Type,'eVASegmentTypeTargetSequence') || strcmp(seg.Type,'eVASegmentTypeSequence') ||strcmp(seg.Type,'eVASegmentTypeBackwardSequence')
            if strcmp(seg.Type,['eVASegmentType',segType])
                segHandles = [segHandles;seg];
            [segHandles] = FilterSegmentsByType(seg.Segments,segType,segHandles);
        elseif strcmp(seg.Type,['eVASegmentType',segType])
            segHandles = [segHandles;seg];