The script sets up an initial spacecraft state and uses GMAT to propagate it forward for 1 day, then extracts the new state for further processing within MATLAB.
This was created to answer a question I was getting along these lines; if there is a problem with this method, please let me know.
- Code: Select all
% 1. Open GMAT and MATLAB.
% 2. Make sure your MATLAB path includes the GMAT matlab folder and all its
% subfolders.
% 3. Start GMAT's MATLAB server and keep it running in the background.
% 4. Run this function from MATLAB.
function driver()
state = [
-4453.783586
-5038.203756
-426.384456
3.831888
-2.887221
-6.018232
];
nextState = prop(state);
nextState
end
function nextState = prop(state)
%% Initialize GMAT
OpenGMAT();
ClearGMAT();
%% Set up the scenario
Create Spacecraft ISS;
GMAT ISS.J2000BodyName = Earth;
GMAT ISS.Epoch.UTCGregorian = 01 Jun 2004 12:00:00.000;
GMAT ISS.DisplayStateType = Cartesian;
GMAT ISS.CoordinateSystem = EarthMJ2000Eq;
GMAT(['ISS.X = ' num2str(state(1), '%f')]);
GMAT(['ISS.Y = ' num2str(state(2), '%f')]);
GMAT(['ISS.Z = ' num2str(state(3), '%f')]);
GMAT(['ISS.VX = ' num2str(state(4), '%f')]);
GMAT(['ISS.VY = ' num2str(state(5), '%f')]);
GMAT(['ISS.VZ = ' num2str(state(6), '%f')]);
GMAT ISS.Cd = 2.2;
GMAT ISS.Cr = 1.2;
GMAT ISS.DragArea = 20;
GMAT ISS.SRPArea = 20;
GMAT ISS.DryMass = 1000;
GMAT ISS.TotalMass = 1000;
Create ForceModel Earth2Body;
GMAT Earth2Body.PrimaryBodies = {Earth};
GMAT Earth2Body.Drag = None;
GMAT Earth2Body.SRP = Off;
GMAT Earth2Body.Gravity.Earth.Model = JGM2;
GMAT Earth2Body.Gravity.Earth.Degree = 0;
GMAT Earth2Body.Gravity.Earth.Order = 0;
GMAT Earth2Body.PointMasses = {};
Create Propagator RKV89;
GMAT RKV89.FM = Earth2Body;
GMAT RKV89.Type = RungeKutta89;
GMAT RKV89.InitialStepSize = 5;
GMAT RKV89.Accuracy = 1e-013;
GMAT RKV89.MinStep = 5;
GMAT RKV89.MaxStep = 5;
GMAT RKV89.MaxStepAttempts = 50;
Propagate(['RKV89(ISS) {ISS.ElapsedSecs = ' num2str(60*60*24) '}']);
%% Run the scenario
BuildRunGMAT();
%% Get result back out
sc = GetGMATObject('ISS');
nextState = [
sc.X
sc.Y
sc.Z
sc.VX
sc.VY
sc.VZ
];
end