-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlow_thrust_trajectories.m
368 lines (281 loc) · 13.6 KB
/
low_thrust_trajectories.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
clearDeleteAdd; % --> !!! ONLY CALL IT ONCE FOR SPEED
%% TEST CASE 1: Earth-Mars (this is very fast)
close all; clc;
% --> parameters
idcentral = 1; % --> 1) central body is the Sun
Tmax = 0.5; % --> max. thrust [N]
Isp = 2000; % --> specific impulse [s]
m0 = 1000; % --> initial mass [kg]
g0 = 9.80665; % --> Earth acceleration at sea level [m/s]
useParallel = false; % --> if true, uses parallel for fsolve
tof = 348.795 * 86400; % --> time of flight [sec]
state1 = [ -140699693 -51614428 980 9.774596 -28.07828 4.337725e-4 ]; % --> initial state [km],[km/s]
state2 = [ -172682023 176959469 7948912 -16.427384 -14.860506 9.21486e-4 ]; % --> final state [km],[km/s]
Nrev = 0; % --> number of revolutions
% --> initialise the parameters
param = processDataAndWriteParam(m0, tof, state1, state2, Tmax, Isp, g0, Nrev, idcentral, useParallel);
% --> you might want to overwrite some of those (some examples below)
param.plot = true; % --> this plots the thrust evolution over time for different rho (default is false)
param.rhoLim = 0.0001;
param.rho = 1;
param.gamma = 0.1;
param.fsolveoptions.MaxFunctionEvaluations = 10e3;
param.fsolveoptions.MaxIterations = 10e3;
% --> solve the problem
LTsol = wrapSolveFopt( param );
% --> if you do not want to wait... UNCOMMENT the following code with the
% solution. The solution is contained in the structure LTsol.
% load('./results/low_thrust/LTsol_mars.mat');
% --> plot the solution
transfer = LTsol.transfer;
[figTRAJ, figMASS, figTHRmag] = plotLT( transfer, param );
% --> add Mars and Earth orbits to the plot
figure(figTRAJ);
plotPLTS_tt([3 4], 0, 3*365.25, idcentral, 1);
%% TEST CASE 2: Asteroid-to-asteroid (this is very fast)
close all; clc;
% --> parameters
idcentral = 1; % --> 1) central body is the Sun
Tmax = 0.6; % --> max. thrust [N]
Isp = 4000; % --> specific impulse [s]
g0 = 9.80665; % --> Earth acceleration at sea level [m/s]
% --> this uses the ESA database
row = 8872;
if ~exist('data', 'var')
fprintf( "\n Loading ESA database... \n" );
data = readmatrix('fuel_optimal_db.csv');
fprintf( "\n Done! \n" );
end
% --> extract the data
m0 = data(row, 13); % [kg]
mf = data(row, 15); % [kg]
tof = data(row, 14) * 86400; % [s]
state1 = data(row, 1:6)./1000; % [km],[km/s]
state2 = data(row, 7:12)./1000; % [km],[km/s]
useParallel = true; % --> if true, uses parallel for fsolve
Nrev = 0; % --> number of revolutions
% --> initialise the parameters
param = processDataAndWriteParam(m0, tof, state1, state2, Tmax, Isp, g0, Nrev, idcentral, useParallel);
% --> you might want to overwrite some of those (some examples below)
param.plot = true; % --> this plots the thrust evolution over time for different rho (default is false)
param.rhoLim = 0.00001;
param.rho = 1;
param.gamma = 0.1;
param.fsolveoptions.MaxFunctionEvaluations = 10e3;
param.fsolveoptions.MaxIterations = 10e3;
% --> solve the problem
LTsol = wrapSolveFopt( param );
% --> if you do not want to wait... UNCOMMENT the following code with the
% solution. The solution is contained in the structure LTsol.
% load('./results/low_thrust/LTsol_ESA_DB_row_8872.mat');
% --> check that the solution converged to the one from ESA database
mf_ESA_db = mf;
mf_fsolve = LTsol.mf;
if abs(mf_fsolve - mf_ESA_db) < 10
fprintf( 'Solutions found and compatible with ESA database \n' );
fprintf( 'Difference with ESA solution: %f kg \n', mf_fsolve - mf_ESA_db );
end
% --> plot the solution
transfer = LTsol.transfer;
[figTRAJ, figMASS, figTHRmag] = plotLT( transfer, param );
%% TEST CASE 3: Mercury leveraging (this might require some time...)
close all; clc;
% --> parameters
idcentral = 1; % --> 1) central body is the Sun
Tmax = 0.32; % --> max. thrust [N]
Isp = 3000; % --> specific impulse [s]
m0 = 4000; % --> initial mass [kg]
g0 = 9.80665; % --> Earth acceleration at sea level [m/s]
useParallel = false; % --> if true, uses parallel for fsolve
% --> initialise the parameters
tof = 358.928459543061 * 86400; % --> time of flight [sec]
state1 = [38757039.7499878;28387323.0458716;-1250921.63423610;-43.6721929563112;40.8343207785050;7.27240226499759]'; % --> initial state [km],[km/s]
state2 = [8402883.04356492;45138449.3894568;2904559.88399718;-60.9850713035465;11.3696258548873;6.51410611494519]'; % --> final state [km],[km/s]
Nrev = 3; % --> number of revolutions
% --> initialise the parameters
param = processDataAndWriteParam(m0, tof, state1, state2, Tmax, Isp, g0, Nrev, idcentral, useParallel);
% --> you might want to overwrite some of those (some examples below)
param.plot = true; % --> this plots the thrust evolution over time for different rho (default is false)
param.rhoLim = 1e-8;
param.rho = 1;
param.gamma = 0.5;
param.fsolveoptions.MaxFunctionEvaluations = 5e3;
param.fsolveoptions.MaxIterations = 5e3;
% --> solve the problem
LTsol = wrapSolveFopt( param );
% --> if you do not want to wait... UNCOMMENT the following code with the
% solution. The solution is contained in the structure LTsol.
% load('./results/low_thrust/LTsol_mercury.mat');
% --> plot the solution
transfer = LTsol.transfer;
[figTRAJ, figMASS, figTHRmag] = plotLT( transfer, param );
% --> add Mercury orbit to the plot
figure(figTRAJ);
plotPLTS_tt(1, 0, 2*365.25, idcentral, 1);
%% TEST CASE 4: Asteroid-to-asteroid (this might require some time...)
close all; clc;
% --> parameters
idcentral = 1; % --> 1) central body is the Sun
Tmax = 0.6; % --> max. thrust [N]
Isp = 4000; % --> specific impulse [s]
g0 = 9.80665; % --> Earth acceleration at sea level [m/s]
% --> this uses the ESA database
row = 1327460;
if ~exist('data', 'var')
fprintf( "\n Loading ESA database... \n" );
data = readmatrix('fuel_optimal_db.csv');
fprintf( "\n Done! \n" );
end
% --> extract the data
m0 = data(row, 13); % [kg]
mf = data(row, 15); % [kg]
tof = data(row, 14) * 86400; % [s]
state1 = data(row, 1:6)./1000; % [km],[km/s]
state2 = data(row, 7:12)./1000; % [km],[km/s]
useParallel = true; % --> if true, uses parallel for fsolve
Nrev = 1; % --> number of revolutions
% --> initialise the parameters
param = processDataAndWriteParam(m0, tof, state1, state2, Tmax, Isp, g0, Nrev, idcentral, useParallel);
% --> you might want to overwrite some of those (some examples below)
param.plot = true; % --> this plots the thrust evolution over time for different rho (default is false)
param.rhoLim = 0.00001;
param.rho = 1;
param.gamma = 0.5;
param.fsolveoptions.MaxFunctionEvaluations = 10e3;
param.fsolveoptions.MaxIterations = 10e3;
% --> solve the problem
LTsol = wrapSolveFopt( param );
% --> if you do not want to wait... UNCOMMENT the following code with the
% solution. The solution is contained in the structure LTsol.
% load('./results/low_thrust/LTsol_ESA_DB_row_1327460.mat');
% --> check that the solution converged to the one from ESA database
mf_ESA_db = mf;
mf_fsolve = LTsol.mf;
if abs(mf_fsolve - mf_ESA_db) < 10
fprintf( 'Solutions found and compatible with ESA database \n' );
fprintf( 'Difference with ESA solution: %f kg \n', mf_fsolve - mf_ESA_db );
end
% --> plot the solution
transfer = LTsol.transfer;
[figTRAJ, figMASS, figTHRmag] = plotLT( transfer, param );
%% TEST CASE 5: Earth-Dionysus (this has many revolutions)
close all; clc;
% --> parameters
idcentral = 1; % --> 1) central body is the Sun
Tmax = 0.32; % --> max. thrust [N]
Isp = 3000; % --> specific impulse [s]
m0 = 4000; % --> initial mass [kg]
g0 = 9.80665; % --> Earth acceleration at sea level [m/s]
% --> initialise the parameters
param = writeParamLT( Tmax, Isp, m0, g0, idcentral, true );
% --> Earth-to-Dionysus
tStart = 0;
tEnd = 3534; % --> please note that in this case the tof is in [days] as this is already scaled!!!
initState = [ 0.999316, -0.004023, 0.015873, -1.623e-5, 1.667e-5, 1.59491 ];
finState = [ 1.555261 0.152514 -0.519189 0.016353 0.117461 2.36696 ];
param.tStart = tStart;
param.tEnd = tEnd;
param.x0 = initState;
param.xf = finState;
param.plot = true;
param.rhoLim = 0.0001;
param.rho = 1;
param.gamma = 0.1;
param.iterMax = 5;
param.tol = 1e-8;
while param.xf(end) < param.x0(end)
param.xf(end) = param.xf(end) + 2*pi;
end
Nrev = 5;
param.xf(end) = param.xf(end) + 2*Nrev*pi;
NrevCheck = floor(( param.xf(end) - param.x0(end) )/(2*pi));
% --> solve the problem
LTsol = wrapSolveFopt( param );
% --> if you do not want to wait... UNCOMMENT the following code with the
% solution. The solution is contained in the structure LTsol.
% load('./results/low_thrust/LTsol_dionysus.mat');
% --> plot the solution
transfer = LTsol.transfer;
[figTRAJ, figMASS, figTHRmag] = plotLT( transfer, param );
%% TEST CASE 7: Earth-to-Tempel1
close all; clc;
% --> parameters
idcentral = 1; % --> 1) central body is the Sun
Tmax = 0.6; % --> max. thrust [N]
Isp = 3000; % --> specific impulse [s]
m0 = 1000; % --> initial mass [kg]
g0 = 9.80665; % --> Earth acceleration at sea level [m/s]
% --> initialise the parameters
param = writeParamLT( Tmax, Isp, m0, g0, idcentral, true );
% --> Earth-to-Tempel
tStart = 0;
tEnd = 420; % --> please note that in this case the tof is in [days] as this is already scaled!!!
initState = [ 1.000064, -0.003764, 0.015791, -1.211e-5, -4.514e-6, 5.51356 ];
finState = [2.328616, -0.191235, -0.472341, 0.033222, 0.085426, 4.96395];
param.tStart = tStart;
param.tEnd = tEnd;
param.x0 = initState;
param.xf = finState;
param.plot = true;
param.rhoLim = 0.00001;
param.rho = 1;
param.gamma = 0.1;
param.iterMax = 5;
param.tol = 1e-8;
while param.xf(end) < param.x0(end)
param.xf(end) = param.xf(end) + 2*pi;
end
NrevCheckBefore = floor(( param.xf(end) - param.x0(end) )/(2*pi));
LTsol = wrapSolveFopt( param );
% --> if you do not want to wait... UNCOMMENT the following code with the
% solution. The solution is contained in the structure LTsol.
% load('./results/low_thrust/LTsol_tempel.mat');
% --> plot the solution
transfer = LTsol.transfer;
[figTRAJ, figMASS, figTHRmag] = plotLT( transfer, param );
%% TEST CASE 8: Asteroid-to-Asteroid (HARD: high mass, high TOF, multi-rev.)
close all; clc;
% --> parameters
idcentral = 1; % --> 1) central body is the Sun
Tmax = 0.6; % --> max. thrust [N]
Isp = 4000; % --> specific impulse [s]
g0 = 9.80665; % --> Earth acceleration at sea level [m/s]
% --> this uses the ESA database
row = 1327515;
if ~exist('data', 'var')
fprintf( "\n Loading ESA database... \n" );
data = readmatrix('fuel_optimal_db.csv');
fprintf( "\n Done! \n" );
end
% --> extract the data
m0 = data(row, 13); % [kg]
mf = data(row, 15); % [kg]
tof = data(row, 14) * 86400; % [s]
state1 = data(row, 1:6)./1000; % [km],[km/s]
state2 = data(row, 7:12)./1000; % [km],[km/s]
useParallel = true; % --> if true, uses parallel for fsolve
Nrev = 1; % --> number of revolutions
% --> initialise the parameters
param = processDataAndWriteParam(m0, tof, state1, state2, Tmax, Isp, g0, Nrev, idcentral, useParallel);
% --> you might want to overwrite some of those (some examples below)
param.plot = true; % --> this plots the thrust evolution over time for different rho (default is false)
param.rhoLim = 0.01; % --> this is high (0.01), but still the solution is very close to optimal one...
param.rho = 1;
param.gamma = 0.7;
param.fsolveoptions.MaxFunctionEvaluations = 100e3;
param.fsolveoptions.MaxIterations = 100e3;
% --> solve the problem
LTsol = wrapSolveFopt( param );
% --> if you do not want to wait... UNCOMMENT the following code with the
% solution. The solution is contained in the structure LTsol.
% load('./results/low_thrust/LTsol_ESA_DB_row_1327515.mat');
% --> check that the solution converged to the one from ESA database
mf_ESA_db = mf;
mf_fsolve = LTsol.mf;
if abs(mf_fsolve - mf_ESA_db) < 10
fprintf( 'Solutions found and compatible with ESA database \n' );
fprintf( 'Difference with ESA solution: %f kg \n', mf_fsolve - mf_ESA_db );
end
% --> plot the solution
transfer = LTsol.transfer;
[figTRAJ, figMASS, figTHRmag] = plotLT( transfer, param );