Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,886 changes: 1,886 additions & 0 deletions StkAutomation/Matlab/RealTime Propagation/FighterAttitude.txt

Large diffs are not rendered by default.

1,884 changes: 1,884 additions & 0 deletions StkAutomation/Matlab/RealTime Propagation/FighterPosition.txt

Large diffs are not rendered by default.

6,003 changes: 6,003 additions & 0 deletions StkAutomation/Matlab/RealTime Propagation/MissileAttitude.txt

Large diffs are not rendered by default.

6,003 changes: 6,003 additions & 0 deletions StkAutomation/Matlab/RealTime Propagation/MissilePosition.txt

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions StkAutomation/Matlab/RealTime Propagation/ReadMe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MATLAB scripts contained in this folder are simple demonstrations of how
to pass real-time data into STK. All scripts will read position and attitude data
from simple text files, then pass those values into STK in simulated realtime. No
setup is required for the scripts, simply open and run. The script will grab an
existing instance of STK12 or create a new one if necessary. It will then create
a new scenario, add the realtime object, and send the position/attitude data.

realtimeSatellite.m - creates a satellite and passes position and attitude data.

realtimeSatellite_MatlabClock.m - creates a satellite and passes position and
attitude data. This script uses the MATLAB timer function to update the current
time in STK. This demonstrates the ability to have MATLAB control the clock in STK.

realtimeAircraftExample.m - creates an aircraft and passes position and attitude
data. Note line 61 where the model file for the aircraft is changed to the f-18
that is installed with STK. Make sure the file path is correct for your installation

realtimeMissileWithArticulation.m - creates a missile and passes position and attitude
data, as well as commands stage separation articulations at 60 second intervals. This
shows how model articulations can be sent in realtime.
3,001 changes: 3,001 additions & 0 deletions StkAutomation/Matlab/RealTime Propagation/SatelliteAttitude.txt

Large diffs are not rendered by default.

3,001 changes: 3,001 additions & 0 deletions StkAutomation/Matlab/RealTime Propagation/SatellitePosition.txt

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions StkAutomation/Matlab/RealTime Propagation/get_attitude_data.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function [epsec, q1, q2, q3, q4] = get_attitude_data(fid)


att_line = fgetl(fid);

spLine = regexp(att_line, '\s', 'split');

epsec = spLine{1};
q1 = spLine{2};
q2 = spLine{3};
q3 = spLine{4};
q4 = spLine{5};
16 changes: 16 additions & 0 deletions StkAutomation/Matlab/RealTime Propagation/get_posvel_data.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function [epsec, x_pos, y_pos, z_pos, x_vel, y_vel, z_vel] = get_posvel_data(fid)

data_line = fgetl(fid);

spLine = regexp(data_line, '\s', 'split');

epsec = spLine{1};
x_pos = spLine{2};
y_pos = spLine{3};
z_pos = spLine{4};
x_vel = spLine{5};
y_vel = spLine{6};
z_vel = spLine{7};



127 changes: 127 additions & 0 deletions StkAutomation/Matlab/RealTime Propagation/realtimeAircraft.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
close all
clear all
clc

%Initialize
%Establish the connection
try
% Grab an existing instance of STK
uiapp = actxGetRunningServer('STK12.application');
catch
% STK is not running, launch new instance
% Launch a new instance of STK and grab it
uiapp = actxserver('STK12.application');
end

%get the root from the personality
%it has two... get the second, its the newer STK Object Model Interface as
%documented in the STK Help
root = uiapp.Personality2;

% set visible to true (show STK GUI)
uiapp.visible = 1;

%%From the STK Object Root you can command every aspect of the STK GUI

%close current scenario or open new one
try
root.CloseScenario();
root.NewScenario('RealTimeTest');
catch
root.NewScenario('RealTimeTest');
end

%get the scenario root, its of type IAgScenario
scenObj = root.CurrentScenario;

%set the object model to expect all dates in Local Gregorian
root.UnitPreferences.Item('DateFormat').SetCurrentUnit('LCLG');
%set the Connect module to expect all dates in Local Gregorian
root.ExecuteCommand(['SetUnits / GregorianLOCAL']);

%Get the system clock time and use that to set up the scenario's start and
%stop time.
tomorrow_date = datestr((now+1), 'dd mmm yyyy HH:MM:SS.FFF');
current_date = datestr((now), 'dd mmm yyyy HH:MM:SS.FFF');

scenObj.Epoch = current_date;
scenObj.StopTime = tomorrow_date;
scenObj.StartTime = current_date;

%set the scenario's animation properties to animate in realtime mode
scAnimation = scenObj.Animation;
scAnimation.AnimStepType = 'eScRealTime';

%create a new satellite object named "Satellite1"
aircraft = scenObj.Children.New('eAircraft', 'Aircraft1');
aircraft.VO.Model.ModelData.Filename = 'C:\Program Files\AGI\STK 12\STKData\VO\Models\Air\f-18c_hornet.mdl';

%set the satellite to expect realtime position and attitude data
root.ExecuteCommand('Realtime */Aircraft/Aircraft1 SetProp')
root.ExecuteCommand('Realtime */Aircraft/Aircraft1 SetLookAhead HoldCBFPosition 3600 60 3600')
root.ExecuteCommand('SetAttitude */Aircraft/Aircraft1 RealTime Hold 3600 3600')
root.ExecuteCommand('SetAttitude */Aircraft/Aircraft1 DataReference Fixed Quat 0 0 0 1 "CentralBody/Earth Fixed"');

%reset the VO window and then begin playing the animation (in realtime)
root.Rewind
root.PlayForward

%find the J2000 Position and Velocity data display
for i = 0:aircraft.VO.DataDisplay.Count-1
if (strcmp(aircraft.VO.DataDisplay.Item(i).Name, 'LLA Position'))
posDD = aircraft.VO.DataDisplay.Item(i);
posDD.IsVisible = 1;
posDD.FontColor = '000255000';
elseif (strcmp(aircraft.VO.DataDisplay.Item(i).Name, 'Velocity Heading'))
attDD = aircraft.VO.DataDisplay.Item(i);
attDD.IsVisible = 1;
attDD.Y = 200;
attDD.FontColor = '255255000';
end
end


%open the file with all positional data (this wouldn't be necessary in a
%realworld application where you'd be getting the realtime data from an
%outside application.

fid = fopen('FighterPosition.txt','r');
%fid = fopen('FighterPosition_0.1sec.csv','r')
fseek(fid, 0, 'eof');
eof_byte = ftell(fid);
fseek(fid, 0, 'bof');

%do the same thing for the attitude data
fid2 = fopen('FighterAttitude.txt','r');
%fid2 = fopen('FighterAttitude_0.1sec.csv','r')
fseek(fid2, 0, 'eof');
eof_byte2 = ftell(fid2);
fseek(fid2, 0, 'bof');

%loop through each line of the position and attitude files and pass the
%data into STK. The data in the files was generated with a 1 second time
%step, so i put a pause command at the bottom of the loop to simulate that
%we actually receive the data every one second. This is not precise.
primID = 1;
while ftell(fid) < eof_byte

%call the functions to read the data lines from the file and pass back
%the position and attitude data
[epsec, x_pos, y_pos, z_pos, x_vel, y_vel, z_vel] = get_posvel_data(fid);
[epsec, q1, q2, q3, q4] = get_attitude_data(fid2);

%check what the current system clock time is, use this as the time
%stamp for the data to be passed into STK
curTime = datestr((now), 'dd mmm yyyy HH:MM:SS.FFF');
root.ExecuteCommand(['SetPosition */Aircraft/Aircraft1 ECF "' curTime '" ' x_pos ' ' y_pos ' ' z_pos ' ' x_vel ' ' y_vel ' ' z_vel]);
root.ExecuteCommand(['AddAttitude */Aircraft/Aircraft1 Quat "' curTime '" ' q1 ' ' q2 ' ' q3 ' ' q4]);

% %output the time, quat, position to the matlab screen
disp(sprintf(['Time: ' curTime '\nPosition: ' x_pos ' ' y_pos ' ' z_pos ...
'\nAttitude: ' q1 ' ' q2 ' ' q3 ' ' q4 '\n']));
pause(0.08)
end




Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
close all
clear all
clc

%Initialize
%Establish the connection
try
% Grab an existing instance of STK
uiapp = actxGetRunningServer('STK12.application');
catch
% STK is not running, launch new instance
% Launch a new instance of STK and grab it
uiapp = actxserver('STK12.application');
end

%get the root from the personality
%it has two... get the second, its the newer STK Object Model Interface as
%documented in the STK Help
root = uiapp.Personality2;

% set visible to true (show STK GUI)
uiapp.visible = 1;

%%From the STK Object Root you can command every aspect of the STK GUI

%close current scenario or open new one
try
root.CloseScenario();
root.NewScenario('RealTimeTest');
catch
root.NewScenario('RealTimeTest');
end

%get the scenario root, its of type IAgScenario
scenObj = root.CurrentScenario;

%set the object model to expect all dates in Local Gregorian
root.UnitPreferences.Item('DateFormat').SetCurrentUnit('UTCG');
%set the Connect module to expect all dates in Local Gregorian
root.ExecuteCommand(['SetUnits / EpSec']);

%set the scenario times so that the attitude data is properly synced
scenObj.Epoch = '22 May 2013 23:00:00.000';
scenObj.StartTime = '22 May 2013 23:00:00.000';
scenObj.StopTime = '23 May 2013 04:00:00.000';

%set the scenario's animation properties to animate in realtime mode
scAnimation = scenObj.Animation;
scAnimation.AnimStepType = 'eScXRealTime';

%reset the VO window and then begin playing the animation (in realtime)
root.Rewind

%create a new missile object named "missile1"
missile = scenObj.Children.New('eMissile', 'Missile1');
missile.VO.Model.ModelData.Filename = 'C:\Program Files\AGI\STK 12\STKData\VO\Models\Missiles\taepodong-2.mdl';


%set the missile to expect realtime position and attitude data
root.ExecuteCommand('Realtime */Missile/Missile1 SetProp');
root.ExecuteCommand('Realtime */Missile/Missile1 SetLookAhead HoldCBFPosition 3600 60 3600');
root.ExecuteCommand('SetAttitude */Missile/Missile1 RealTime Extrapolate 3600 3600');

%find the J2000 Position and Velocity data display
for i = 0:missile.VO.DataDisplay.Count-1
if (strcmp(missile.VO.DataDisplay.Item(i).Name, 'J2000 Position Velocity'))
posDD = missile.VO.DataDisplay.Item(i);
posDD.IsVisible = 1;
posDD.FontColor = '000255000';
elseif (strcmp(missile.VO.DataDisplay.Item(i).Name, 'Attitude Quaternions'))
attDD = missile.VO.DataDisplay.Item(i);
attDD.IsVisible = 1;
attDD.Y = 200;
attDD.FontColor = '255255000';
end
end

%open the file with all positional data (this wouldn't be necessary in a
%realworld application where you'd be getting the realtime data from an
%outside application.
fid = fopen('MissilePosition.txt','r');
fseek(fid, 0, 'eof');
eof_byte = ftell(fid);
fseek(fid, 0, 'bof');

%do the same thing for the attitude data
fid2 = fopen('MissileAttitude.txt','r');
fseek(fid2, 0, 'eof');
eof_byte2 = ftell(fid2);
fseek(fid2, 0, 'bof');

root.PlayForward;
%loop through each line of the position and attitude files and pass the
%data into STK. The data in the files was generated with a 0.1 second time
%step, this seems to give a consistant stream of data which keeps up with
%real-time. This is not precise.
while ftell(fid) < eof_byte

%call the functions to read the data lines from the file and pass back
%the position and attitude data
[epsec, x_pos, y_pos, z_pos, x_vel, y_vel, z_vel] = get_posvel_data(fid);
[epsec, q1, q2, q3, q4] = get_attitude_data(fid2);

if str2double(epsec) == 0
%send the first couple of articulation commands
root.ExecuteCommand(['VO */Missile/Missile1 Articulate "' num2str(root.CurrentTime + 1) '" 2 Stage1Flame Size 0 1']);
elseif str2double(epsec) == 30.0
root.ExecuteCommand(['VO */Missile/Missile1 Articulate "' num2str(root.CurrentTime + 1) '" 2 Stage1Flame Size 1 0']);
root.ExecuteCommand(['VO */Missile/Missile1 Articulate "' num2str(root.CurrentTime + 1) '" 2 Stage2Flame Size 0 1']);
root.ExecuteCommand(['VO */Missile/Missile1 Articulate "' num2str(root.CurrentTime + 1) '" 25 Stage1 MoveX 0 -900']);
elseif str2double(epsec) == 45.0
root.ExecuteCommand(['VO */Missile/Missile1 Articulate "' num2str(root.CurrentTime + 1) '" 0.1 Stage1 Size 1 0']);
elseif str2double(epsec) == 60.0
root.ExecuteCommand(['VO */Missile/Missile1 Articulate "' num2str(root.CurrentTime + 1) '" 2 Stage2Flame Size 1 0']);
root.ExecuteCommand(['VO */Missile/Missile1 Articulate "' num2str(root.CurrentTime + 1) '" 2 Stage3Flame Size 0 1']);
root.ExecuteCommand(['VO */Missile/Missile1 Articulate "' num2str(root.CurrentTime + 1) '" 25 Stage2 MoveX 0 -900']);
elseif str2double(epsec) == 75.0
root.ExecuteCommand(['VO */Missile/Missile1 Articulate "' num2str(root.CurrentTime + 1) '" 0.1 Stage2 Size 1 0']);
end

%check what the current system clock time is, use this as the time
%stamp for the data to be passed into STK
root.ExecuteCommand(['SetPosition */Missile/Missile1 ECF "' epsec '" ' x_pos ' ' y_pos ' ' z_pos ' ' x_vel ' ' y_vel ' ' z_vel]);
root.ExecuteCommand(['AddAttitude */Missile/Missile1 Quat "' epsec '" ' q1 ' ' q2 ' ' q3 ' ' q4]);

%output the time, quat, position to the matlab screen
disp(sprintf(['Time: ' epsec '\nPosition: ' x_pos ' ' y_pos ' ' z_pos ...
'\nAttitude: ' q1 ' ' q2 ' ' q3 ' ' q4 '\n']));
end




Loading