-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSwARM.m
2549 lines (1933 loc) · 98.8 KB
/
SwARM.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function varargout = SwARM(varargin)
% SWARM MATLAB code for SwARM.fig
% SWARM, by itself, creates a new SWARM or raises the existing
% singleton*.
%
% H = SWARM returns the handle to a new SWARM or the handle to
% the existing singleton*.
%
% SWARM('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SWARM.M with the given input arguments.
%
% SWARM('Property','Value',...) creates a new SWARM or raises
% the existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before SwARM_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to SwARM_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help SwARM
% Last Modified by GUIDE v2.5 01-Apr-2018 17:46:06
% Begin initialization code - DO NOT EDIT
% Author: Bharat Mahajan (https://github.com/princemahajan)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @SwARM_OpeningFcn, ...
'gui_OutputFcn', @SwARM_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before SwARM is made visible.
function SwARM_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to SwARM (see VARARGIN)
% Choose default command line output for SwARM
handles.output = hObject;
% Display Logo
% Initialize with the saved settings
% SwARM Configuration file. It MUST EXIST WITH PROPER FORMAT
handles.SwarmConfFile = 'SwARMConf.mat';
handles.SwarmConfStruct = 'SwARMConf';
% Load SwARM Settings Data Structure
load(handles.SwarmConfFile,handles.SwarmConfStruct);
% save configuration in GUIDE handle
handles.SwarmConf = SwARMConf;
% Init Swarm Run structure
%handles.SwarmRun.MJD_EPOCH = 2400000.5;
handles.SwarmRun.GMAT_MJD_EPOCH = 2430000.0; % See GMAT documentation
handles.SwarmRun.ResultsAvailable = false; % no results at this time
% Initially turn off formation ICs update status
handles.SwarmRun.DepModified = false;
% GMAT
handles.SwarmRun.GMATChStatesFile = strcat(SwARMConf.GMAT.ExePath, '\\output\\ChiefStates.txt');
handles.SwarmRun.GMATDepStatesFile = strcat(SwARMConf.GMAT.ExePath, '\\output\\DeputyStates.txt');
handles.SwarmRun.GMATChElemFile = strcat(SwARMConf.GMAT.ExePath, '\\output\\ChiefOE.txt');
handles.SwarmRun.GMATDepElemFile = strcat(SwARMConf.GMAT.ExePath, '\\output\\DepOE.txt');
handles.SwarmRun.GMATFuncFile = strcat(SwARMConf.GMAT.ExePath, '\\userfunctions\\gmat\\GetCDStates.gmf');
% Initualize the GUI with saved settings
handles = LoadGUI(handles);
% all buttons and plots disable except Init
set(handles.button_Prop,'Enable','off');
set(handles.button_Save,'Enable','off');
set(handles.button_Results,'Enable','off');
set(handles.button_UpdateFF,'Enable','off');
set(handles.AbsMenu,'Enable','off');
set(handles.RelMenu,'Enable','off');
% Update handles structure
guidata(hObject, handles);
initialize_gui(hObject, handles, false);
% UIWAIT makes SwARM wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = SwARM_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes during object creation, after setting all properties.
function text_coefffile_CreateFcn(hObject, eventdata, handles)
% hObject handle to text_coefffile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function text_coefffile_Callback(hObject, eventdata, handles)
% hObject handle to text_coefffile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of text_coefffile as text
% str2double(get(hObject,'String')) returns contents of text_coefffile as a double
% % --- Executes during object creation, after setting all properties.
% function volume_CreateFcn(hObject, eventdata, handles)
% % hObject handle to volume (see GCBO)
% % eventdata reserved - to be defined in a future version of MATLAB
% % handles empty - handles not created until after all CreateFcns called
%
% % Hint: popupmenu controls usually have a white background on Windows.
% % See ISPC and COMPUTER.
% if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
% set(hObject,'BackgroundColor','white');
% end
% function volume_Callback(hObject, eventdata, handles)
% % hObject handle to volume (see GCBO)
% % eventdata reserved - to be defined in a future version of MATLAB
% % handles structure with handles and user data (see GUIDATA)
%
% % Hints: get(hObject,'String') returns contents of volume as text
% % str2double(get(hObject,'String')) returns contents of volume as a double
% volume = str2double(get(hObject, 'String'));
% if isnan(volume)
% set(hObject, 'String', 0);
% errordlg('Input must be a number','Error');
% end
% % Save the new volume value
% handles.metricdata.volume = volume;
% guidata(hObject,handles)
% --- Executes on button press in button_Init.
function button_Init_Callback(hObject, eventdata, handles)
% hObject handle to button_Init (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Read all the settings and generate initial conditions and other stuff for
% numerical as well as analytical propagation
% Disable all the buttons until initialization is done
set(handles.button_Init,'Enable','off');
set(handles.button_Prop,'Enable','off');
set(handles.button_Save,'Enable','off');
set(handles.button_Results,'Enable','off');
set(handles.button_UpdateFF,'Enable','off');
% Disable Results section
set(handles.AbsMenu,'Enable','off');
set(handles.RelMenu,'Enable','off');
% No results available until Generate Results button is used
handles.SwarmRun.ResultsAvailable = false;
% set progress bar 0 %
set(handles.progressbar,'Value',0);
drawnow;
% Read the GUI
SwarmConf = ReadGUI(handles);
% Use the new Swarm configuration from now on
handles.SwarmConf = SwarmConf;
% turn off this flag
handles.SwarmRun.DepModified = false;
% Swarm run data structure
lunit = handles.SwarmConf.GravModel.Re ;
tunit = sqrt(handles.SwarmConf.GravModel.Re^3/handles.SwarmConf.GravModel.mu);
vunit = lunit/tunit;
mu = 1;
Re = 1;
% Greenwich Mean Sidereal Time and Earth rotational speed at given UTC JD
JDUTCt0 = handles.SwarmConf.Time.MJDUTCt0 + handles.SwarmRun.GMAT_MJD_EPOCH;
[GMST0, we_d] = JD2GMST( JDUTCt0 );
we = we_d/1*tunit;
% Unnormalize C and S coefficients
[Clm,Slm] = DenormCS(handles.SwarmConf.GravCoeffFN, max([2, handles.SwarmConf.GravModel.IC.n, ...
handles.SwarmConf.GravModel.AST.n,...
handles.SwarmConf.GravModel.NP.n]));
C20 = Clm(3,1);
% set progress bar 25 %
set(handles.progressbar,'Value',0.25);
drawnow;
% Compute Chief initial osculating states
sma = SwarmConf.ChiefIC.SMA/lunit;
ecc = SwarmConf.ChiefIC.ECC;
inc = deg2rad(SwarmConf.ChiefIC.INC);
raan = deg2rad(SwarmConf.ChiefIC.RAAN);
aop = deg2rad(SwarmConf.ChiefIC.AOP);
ma = deg2rad(SwarmConf.ChiefIC.M);
ChiefEq0 = [sma; ma+raan+aop; tan(inc/2)*cos(raan); tan(inc/2)*sin(raan);ecc*cos(aop+raan); ecc*sin(aop+raan)];
JacobianOn = 0;
if strcmpi(handles.SwarmConf.STMType, 'None') ~= 1
JacobianOn = 1;
end
% Compute Absolute Initial Mean States for Chief
[EqCMX0,~, iD0,~] = EqMean2Osc2(ChiefEq0, GMST0, mu, Re, we, handles.SwarmConf.GravModel.IC.n, handles.SwarmConf.GravModel.IC.m, ...
Clm, Slm, handles.SwarmConf.tol, handles.SwarmConf.quadtol, ...
true, handles.SwarmConf.J2MEXON, JacobianOn, false, handles.SwarmConf.GravModel.AST.QuadTesseralsOn );
% Chief Initial States (osculating)
ChX0 = Eqn2RV(ChiefEq0, mu, handles.SwarmConf.tol, false);
% set progress bar 50%
set(handles.progressbar,'Value',0.5);
drawnow;
% Deputy Initial Conditions
DepX0 = 0;
if JacobianOn == 1
rhox = SwarmConf.RM.RHOX/lunit;
rhoy = SwarmConf.RM.RHOY/lunit;
rhoz = SwarmConf.RM.RHOZ/lunit;
alphax = deg2rad(SwarmConf.RM.ALPHAX);
alphaz = deg2rad(SwarmConf.RM.ALPHAZ);
dMEqn0 = FormationdEqn(rhox, rhoy, rhoz, alphax, alphaz, EqCMX0,...
handles.SwarmConf.RM.DriftCond, mu, Re, -Clm(2:end,1), handles.SwarmConf.tol);
[EqDOX0,~, ~,~] = EqMean2Osc2(EqCMX0 + dMEqn0, GMST0, mu, Re, we, handles.SwarmConf.GravModel.IC.n, handles.SwarmConf.GravModel.IC.m, ...
Clm, Slm, handles.SwarmConf.tol, handles.SwarmConf.quadtol, ...
false, handles.SwarmConf.J2MEXON, false, false, handles.SwarmConf.GravModel.AST.QuadTesseralsOn );
DepX0 = Eqn2RV(EqDOX0, mu, handles.SwarmConf.tol, false);
end
% Build time vector
tp = 2*pi*sqrt(sma^3/mu);
t_data = handles.SwarmConf.Time.NumOrbits*tp;
numpoints = handles.SwarmConf.Time.PointsPerOrbit*handles.SwarmConf.Time.NumOrbits;
StartTime = handles.SwarmConf.Time.DataStartTime/tunit;
if StartTime > 0
tspan = [0,linspace(StartTime, StartTime + t_data, numpoints)];
else
tspan = linspace(0,t_data, numpoints);
end
% Numerical Simulation
if strcmpi(handles.SwarmConf.NumPropType, 'None') ~= 1
% Set up GMAT
if strcmpi(handles.SwarmConf.NumPropType, 'GMAT') == 1
% GMAT Command
handles.SwarmRun.GMATcmd = sprintf('%s --run --exit "%s"',...
strcat(handles.SwarmConf.GMAT.ExePath,'\\bin\\GMAT'), ...
handles.SwarmConf.GMAT.ScriptFN);
% Save parameters for GMAT simulation
GPropTime = tspan(end)*tunit;
GChiefOE = ChX0*lunit;
GChiefOE(4:6) = GChiefOE(4:6)/tunit;
if JacobianOn ~= 1
GDepOE = GChiefOE;
else
GDepOE = DepX0*lunit;
GDepOE(4:6) = GDepOE(4:6)/tunit;
end
% Create GMAT function and save it
GMATFuncFID = fopen(handles.SwarmRun.GMATFuncFile,'w');
if GMATFuncFID == -1
disp(strcat('SwARM: check GMAT function folder path ', handles.SwarmRun.GMATFuncFile));
end
fprintf(GMATFuncFID,strcat(' function [ChX, DepX, TOF] = GetCDStates \n\n Create Array ChX[6,1] DepX[6,1]; \n\n',...
' Create Variable TOF;\n\n BeginMissionSequence \n\n',...
' ChX(1,1) = %3.12f; \n ChX(2,1) = %3.12f; \n ChX(3,1) = %3.12f;',...
'\n ChX(4,1) = %3.12f; \n ChX(5,1) = %3.12f; \n ChX(6,1) = %3.12f; \n\n',...
' DepX(1,1) = %3.12f; \n DepX(2,1) = %3.12f; \n DepX(3,1) = %3.12f; \n',...
' DepX(4,1) = %3.12f; \n DepX(5,1) = %3.12f; \n DepX(6,1) = %3.12f; \n\n',...
' TOF = %3.12f; \n'),GChiefOE(1),GChiefOE(2),GChiefOE(3),GChiefOE(4),GChiefOE(5),GChiefOE(6),...
GDepOE(1),GDepOE(2),GDepOE(3),GDepOE(4),GDepOE(5),GDepOE(6),GPropTime);
% close GMAT function file
fclose(GMATFuncFID);
end
end
% set progress bar 75%
set(handles.progressbar,'Value',0.75);
drawnow;
% Compute GMST for future computations
GMSTarr = zeros(length(tspan),1);
for ctr = 1:length(tspan)
[GMST, ~] = JD2GMST( JDUTCt0 + (tspan(ctr)-tspan(1))*tunit/86400);
GMSTarr(ctr) = GMST;
end
% Compute Initial geometric transformation for STM
iSig0 = 0;
if JacobianOn == 1
% Geometric Transformation for propagation
Sig0 = DiffEq2Curv(ChiefEq0, GMST0, handles.SwarmConf.GravModel.IC.n, handles.SwarmConf.GravModel.IC.m, ...
true, mu, Re, Clm, Slm, handles.SwarmConf.tol);
iSig0 = Sig0^-1;
end
% Update Swarm Run
handles.SwarmRun.lunit = lunit;
handles.SwarmRun.tunit = tunit;
handles.SwarmRun.vunit = vunit;
handles.SwarmRun.mu = mu;
handles.SwarmRun.Re = Re;
handles.SwarmRun.we = we;
handles.SwarmRun.GMST0 = GMST0;
handles.SwarmRun.tspan = tspan;
handles.SwarmRun.Clm = Clm;
handles.SwarmRun.Slm = Slm;
handles.SwarmRun.C20 = C20;
handles.SwarmRun.JDUTCt0 = JDUTCt0;
handles.SwarmRun.GMSTarr = GMSTarr;
handles.SwarmRun.EqCOX0 = ChiefEq0;
handles.SwarmRun.EqCMX0 = EqCMX0;
handles.SwarmRun.ChX0 = ChX0;
handles.SwarmRun.DepX0 = DepX0;
handles.SwarmRun.iD0 = iD0;
handles.SwarmRun.iSig0 = iSig0;
disp('SwARM: Init Completed...');
% set progress bar 100 %
set(handles.progressbar,'Value',1);
% Reenable all the buttons except results and update button
set(handles.button_Init,'Enable','on');
set(handles.button_Prop,'Enable','on');
set(handles.button_Save,'Enable','on');
set(handles.button_Results,'Enable','off');
set(handles.button_UpdateFF,'Enable','off');
% Update handles structure
guidata(hObject, handles);
% --- Executes on button press in button_Prop.
function button_Prop_Callback(hObject, eventdata, handles)
% hObject handle to button_Prop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Disable all the buttons until propagation is done
set(handles.button_Init,'Enable','off');
set(handles.button_Prop,'Enable','off');
set(handles.button_Save,'Enable','off');
set(handles.button_Results,'Enable','off');
set(handles.button_UpdateFF,'Enable','off');
% Disable Results section
set(handles.AbsMenu,'Enable','off');
set(handles.RelMenu,'Enable','off');
% set progressbar to 0%
set(handles.progressbar,'Value',0);
drawnow;
tspan = handles.SwarmRun.tspan;
nPoints = length(tspan);
if strcmpi(handles.SwarmConf.STMType,'None') ~= 1
STM_on = 1;
else
STM_on = 0;
end
tic;
% Numerical Propagation - GMAT or MATLAB if needed
if strcmpi(handles.SwarmConf.NumPropType,'GMAT') == 1
% Run GMAT
status = system(handles.SwarmRun.GMATcmd);
disp(['SwARM: GMAT call status = ' num2str(status)]);
% Load Chief and Deputy States and nondimensionalize
ChStates = dlmread(handles.SwarmRun.GMATChStatesFile);
ChElems = dlmread(handles.SwarmRun.GMATChElemFile);
GT = ChStates(:,1)/handles.SwarmRun.tunit;
GORV = [ChStates(:,2:4)/handles.SwarmRun.lunit, ChStates(:,5:7)/handles.SwarmRun.vunit];
GChElem = [ChElems(:,2)/handles.SwarmRun.lunit,ChElems(:,3),deg2rad(ChElems(:,4:7))];
% Interpolate states at specified times using cubic splines
ORV = zeros(nPoints,6);
NumCOE = ORV;
for ctr = 1:nPoints
ORV(ctr,:) = spline(GT',GORV',handles.SwarmRun.tspan(ctr))';
NumCOE(ctr,:) = spline(GT',GChElem',handles.SwarmRun.tspan(ctr))';
end
% Deputy Numerical states
ODRV = 0;
NumDOE = 0;
if STM_on == 1
DepStates = dlmread(handles.SwarmRun.GMATDepStatesFile);
DepElems = dlmread(handles.SwarmRun.GMATDepElemFile);
GODRV = [DepStates(:,2:4)/handles.SwarmRun.lunit, DepStates(:,5:7)/handles.SwarmRun.vunit];
GDepElem = [DepElems(:,2)/handles.SwarmRun.lunit,DepElems(:,3),deg2rad(DepElems(:,4:7))];
ODRV = zeros(nPoints,6);
NumDOE = ODRV;
for ctr = 1:nPoints
ODRV(ctr,:) = spline(GT',GODRV',handles.SwarmRun.tspan(ctr))';
NumDOE(ctr,:) = spline(GT',GDepElem',handles.SwarmRun.tspan(ctr))';
end
end
handles.SwarmRun.NumCRV = ORV;
handles.SwarmRun.NumCOE = NumCOE;
handles.SwarmRun.NumDRV = ODRV;
handles.SwarmRun.NumDOE = NumDOE;
elseif strcmpi(handles.SwarmConf.NumPropType,'MATLAB') == 1
% Run Matlab Numerical Propagator
optn = odeset('RelTol',handles.SwarmConf.tol,'AbsTol',handles.SwarmConf.tol*1e-3);
tspan = handles.SwarmRun.tspan;
n = handles.SwarmConf.GravModel.NP.n;
m = handles.SwarmConf.GravModel.NP.m;
% Chief
[~,ORV] = ode113(@(T, ORV) GravAcc(T, ORV, tspan(1), handles.SwarmRun.GMST0,handles.SwarmRun.we, ...
n, m, handles.SwarmRun.mu,handles.SwarmRun.Re,handles.SwarmRun.Clm,handles.SwarmRun.Slm),...
tspan,handles.SwarmRun.ChX0,optn);
% compute Chief classical elements
nPoints = length(handles.SwarmRun.tspan);
NumCOE = zeros(nPoints,6);
for ctr = 1:nPoints
oe = OrbitElem(ORV(ctr,1:3)',ORV(ctr,4:6)',handles.SwarmRun.mu);
NumCOE(ctr,:) = [oe(2:6),oe(end)];
end
ODRV = 0;
NumDOE = 0;
if STM_on == 1
% Deputy
[~,ODRV] = ode113(@(T, ODRV) GravAcc(T, ODRV, tspan(1), handles.SwarmRun.GMST0,handles.SwarmRun.we, ...
n, m, handles.SwarmRun.mu,handles.SwarmRun.Re,handles.SwarmRun.Clm,handles.SwarmRun.Slm),...
tspan,handles.SwarmRun.DepX0,optn);
NumDOE = zeros(nPoints,6);
for ctr = 1:nPoints
oe = OrbitElem(ODRV(ctr,1:3)',ODRV(ctr,4:6)',handles.SwarmRun.mu);
NumDOE(ctr,:) = [oe(2:6),oe(end)];
end
end
handles.SwarmRun.NumCRV = ORV;
handles.SwarmRun.NumCOE = NumCOE;
handles.SwarmRun.NumDRV = ODRV;
handles.SwarmRun.NumDOE = NumDOE;
end
np_time = toc;
set(handles.text_nptime,'String',np_time);
disp('SwARM: Numerical Propagation done...');
% set progress bar 25 %
set(handles.progressbar,'Value',0.25);
drawnow;
tic;
% Propagate Mean Elements
EqCMX = zeros(nPoints, 6);
mPhi = zeros(6,6,nPoints);
Jcoeff = -handles.SwarmRun.Clm(2:end,1);
for ctr = 1:nPoints
[OEm, phi] = EqZonalMeanProp(tspan(ctr)-tspan(1), handles.SwarmRun.EqCMX0, ...
handles.SwarmConf.GravModel.AST.n, handles.SwarmRun.mu, handles.SwarmRun.Re, Jcoeff);
EqCMX(ctr,:) = OEm';
mPhi(:,:,ctr) = phi;
end
mean_time = toc;
set(handles.text_meantime,'String',mean_time);
disp('SwARM: Chief Mean Propagation Done...');
% set progress bar 35 %
set(handles.progressbar,'Value',0.35);
drawnow;
tic;
% propagate chief osculating elements
EqCOX = zeros(nPoints, 6);
Darr = zeros(6,6,nPoints);
USE_MEX = handles.SwarmConf.J2MEXON;
% update progress 4 times
pbupdate = fix(nPoints/4);
for ctr = 1:nPoints
[EqCOX(ctr,:),~,D,~] = EqMean2Osc2(EqCMX(ctr,:)', handles.SwarmRun.GMSTarr(ctr), handles.SwarmRun.mu, handles.SwarmRun.Re, ...
handles.SwarmRun.we, handles.SwarmConf.GravModel.AST.n,handles.SwarmConf.GravModel.AST.m,...
handles.SwarmRun.Clm, handles.SwarmRun.Slm, handles.SwarmConf.tol, handles.SwarmConf.quadtol,...
false, USE_MEX, STM_on, false , handles.SwarmConf.GravModel.AST.QuadTesseralsOn);
Darr(:,:,ctr) = D;
if mod(ctr,pbupdate) == 0
disp(['Chief M2O: ' num2str(ctr)]);
% set progress bar
set(handles.progressbar,'Value',ctr/nPoints*50/100 + 0.35);
drawnow;
end
end
m2o_time = toc;
set(handles.text_m2otime,'String',m2o_time);
disp('SwARM: Chief Absolute Motion Propagation Done...' );
% Generate Relative Motion STM for Deputy
STM = 0;
if STM_on == true
STM = zeros(6,6,nPoints);
for ctr = 1:nPoints
% Differential Element STM
STM(:,:,ctr) = Darr(:,:,ctr)*mPhi(:,:,ctr)*handles.SwarmRun.iD0;
if strcmpi(handles.SwarmConf.STMType,'Relative States') == 1
% Relative states STM
Sig = DiffEq2Curv(EqCOX(ctr,:)', handles.SwarmRun.GMSTarr(ctr), ...
handles.SwarmConf.GravModel.AST.n, handles.SwarmConf.GravModel.AST.m, true,...
handles.SwarmRun.mu, handles.SwarmRun.Re, handles.SwarmRun.Clm, handles.SwarmRun.Slm, handles.SwarmConf.tol);
STM(:,:,ctr) = Sig*STM(:,:,ctr)*handles.SwarmRun.iSig0;
end
end
disp('SwARM: Relative Motion STM Generated...' );
end
% Save Data
handles.SwarmRun.EqCMX = EqCMX;
handles.SwarmRun.EqCOX = EqCOX;
handles.SwarmRun.STM = STM;
% set progress bar 100 %
set(handles.progressbar,'Value',1);
drawnow;
% Reenable all the buttons now
set(handles.button_Init,'Enable','on');
set(handles.button_Prop,'Enable','on');
set(handles.button_Save,'Enable','on');
set(handles.button_Results,'Enable','on');
set(handles.button_UpdateFF,'Enable','on');
% Update handles structure
guidata(hObject, handles);
% --- Executes when selected object changed in unitgroup.
function unitgroup_SelectionChangedFcn(hObject, eventdata, handles)
% hObject handle to the selected object in unitgroup
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% if (hObject == handles.english)
% set(handles.text4, 'String', 'lb/cu.in');
% set(handles.text5, 'String', 'cu.in');
% set(handles.text6, 'String', 'lb');
% else
% set(handles.text4, 'String', 'kg/cu.m');
% set(handles.text5, 'String', 'cu.m');
% set(handles.text6, 'String', 'kg');
% end
% --------------------------------------------------------------------
function initialize_gui(fig_handle, handles, isreset)
% If the metricdata field is present and the button_Prop flag is false, it means
% we are we are just re-initializing a GUI by calling it from the cmd line
% while it is up. So, bail out as we dont want to button_Prop the data.
disp('**********************************');
disp('************* SwARM **************');
disp('**********************************');
function text_degreeIC_Callback(hObject, eventdata, handles)
% hObject handle to text_degreeIC (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of text_degreeIC as text
% str2double(get(hObject,'String')) returns contents of text_degreeIC as a double
% --- Executes during object creation, after setting all properties.
function text_degreeIC_CreateFcn(hObject, eventdata, handles)
% hObject handle to text_degreeIC (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function text_degree_Callback(hObject, eventdata, handles)
% hObject handle to text_degree (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of text_degree as text
% str2double(get(hObject,'String')) returns contents of text_degree as a double
% --- Executes during object creation, after setting all properties.
function text_degree_CreateFcn(hObject, eventdata, handles)
% hObject handle to text_degree (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit6_Callback(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit6 as text
% str2double(get(hObject,'String')) returns contents of edit6 as a double
% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in radio_np_gmat.
function radio_np_gmat_Callback(hObject, eventdata, handles)
% hObject handle to radio_np_gmat (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radio_np_gmat
% --- Executes on button press in radio_np_matlab.
function radio_np_matlab_Callback(hObject, eventdata, handles)
% hObject handle to radio_np_matlab (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radio_np_matlab
function text_scriptfile_Callback(hObject, eventdata, handles)
% hObject handle to text_scriptfile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of text_scriptfile as text
% str2double(get(hObject,'String')) returns contents of text_scriptfile as a double
% --- Executes during object creation, after setting all properties.
function text_scriptfile_CreateFcn(hObject, eventdata, handles)
% hObject handle to text_scriptfile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function text_gmatpath_Callback(hObject, eventdata, handles)
% hObject handle to text_gmatpath (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of text_gmatpath as text
% str2double(get(hObject,'String')) returns contents of text_gmatpath as a double
% --- Executes during object creation, after setting all properties.
function text_gmatpath_CreateFcn(hObject, eventdata, handles)
% hObject handle to text_gmatpath (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in radio_stm_de.
function radio_stm_de_Callback(hObject, eventdata, handles)
% hObject handle to radio_stm_de (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radio_stm_de
% --- Executes on button press in radio_stm_relstate.
function radio_stm_relstate_Callback(hObject, eventdata, handles)
% hObject handle to radio_stm_relstate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radio_stm_relstate
% --- Executes on button press in english.
function english_Callback(hObject, eventdata, handles)
% hObject handle to english (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of english
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over english.
function english_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to english (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on key press with focus on english and none of its controls.
function english_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to english (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
function edit10_Callback(hObject, eventdata, handles)
% hObject handle to edit10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit10 as text
% str2double(get(hObject,'String')) returns contents of edit10 as a double
% --- Executes during object creation, after setting all properties.
function edit10_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit11_Callback(hObject, eventdata, handles)
% hObject handle to edit11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit11 as text
% str2double(get(hObject,'String')) returns contents of edit11 as a double
% --- Executes during object creation, after setting all properties.
function edit11_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit12_Callback(hObject, eventdata, handles)
% hObject handle to edit12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit12 as text
% str2double(get(hObject,'String')) returns contents of edit12 as a double
% --- Executes during object creation, after setting all properties.
function edit12_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit13_Callback(hObject, eventdata, handles)
% hObject handle to edit13 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit13 as text
% str2double(get(hObject,'String')) returns contents of edit13 as a double
% --- Executes during object creation, after setting all properties.
function edit13_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit13 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit14_Callback(hObject, eventdata, handles)
% hObject handle to edit14 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit14 as text
% str2double(get(hObject,'String')) returns contents of edit14 as a double
% --- Executes during object creation, after setting all properties.
function edit14_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit14 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit15_Callback(hObject, eventdata, handles)
% hObject handle to edit15 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit15 as text
% str2double(get(hObject,'String')) returns contents of edit15 as a double
% --- Executes during object creation, after setting all properties.
function edit15_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit15 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function text_rhox_Callback(hObject, eventdata, handles)
% hObject handle to text_rhox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of text_rhox as text
% str2double(get(hObject,'String')) returns contents of text_rhox as a double
% --- Executes during object creation, after setting all properties.
function text_rhox_CreateFcn(hObject, eventdata, handles)
% hObject handle to text_rhox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function text_rhoy_Callback(hObject, eventdata, handles)
% hObject handle to text_rhoy (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of text_rhoy as text
% str2double(get(hObject,'String')) returns contents of text_rhoy as a double
% --- Executes during object creation, after setting all properties.
function text_rhoy_CreateFcn(hObject, eventdata, handles)
% hObject handle to text_rhoy (see GCBO)