-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC3
206 lines (154 loc) · 6.67 KB
/
C3
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
__author__ = 'martin'
import py.AsteroidDB as asteroidDB
import numpy as np
from PyKEP import epoch, DAY2SEC, SEC2DAY, AU, DEG2RAD, MU_SUN, lambert_problem, propagate_lagrangian, \
fb_vel, planet
from py.jdutil import *
from PyKEP import epoch, DAY2SEC, SEC2DAY, AU, DEG2RAD, MU_SUN, planet, lambert_problem, propagate_lagrangian
def planet_planet(start_planet, arrive_planet, tlaunch, tarrive, rev, N):
# Create PyKEP epoch objects and calculate flight time
t1 = epoch(tlaunch)
t2 = epoch(tarrive)
dt = (tarrive - tlaunch) * DAY2SEC
OBJ1 = planet.jpl_lp(start_planet)
OBJ2 = planet.jpl_lp(arrive_planet) # Calculate location of objects in flight path
r1, v1 = OBJ1.eph(t1)
r2, v2 = OBJ2.eph(t2)
# Find trajectory
l = lambert_problem(r1, r2, dt, MU_SUN)
#extract relevant information from solution
r = l.get_r1()
v = l.get_v1()[0]
mu = l.get_mu()
#define the integration time
dtn = dt / (N - 1)
dtn_days = dtn * SEC2DAY
#alocate the cartesian components for r
t = np.array([0.0] * N)
x = np.array([0.0] * N)
y = np.array([0.0] * N)
z = np.array([0.0] * N)
#calculate the spacecraft position at each dt
for i in range(N):
t[i] = tlaunch + dtn_days * i
x[i] = r[0] / AU
y[i] = r[1] / AU
z[i] = r[2] / AU
r, v = propagate_lagrangian(r, v, dtn, mu)
#traj = [t, x, y, z]
vin = l.get_v1()[rev]
vout = l.get_v2()[rev]
#dV=fb_vel(vin,vout,planet.jpl_lp(arrive_planet))
#dV=np.sqrt( np.square(vin[0]/vout[0])+np.square(vin[1]/vout[1])+np.square(vin[2]/vout[2]))
#dV=np.sqrt( np.square(vin[0]-v1[0])+np.square(v1[1]-vin[1])+np.square(v1[2]-vin[2]))
#dV=np.sqrt( np.square(v2[0]-vout[0])+np.square(v2[1]-vout[1])+np.square(v2[2]-vout[2]))
#dV=np.sqrt( np.square(v1[0]/vin[0])+np.square(v1[1]/vin[1])+np.square(v1[2]/vin[2]))
C3_launch = (np.sqrt(np.square(vin[0] - v1[0]) + np.square(vin[1] - v1[1]) + np.square(vin[2] - v1[2]))) ** 2
C3_arrive = (np.sqrt(np.square(vout[0] - v2[0]) + np.square(vout[1] - v2[1]) + np.square(vout[2] - v2[2]))) ** 2
C3 = np.sqrt((C3_arrive ** 2) + (C3_launch ** 2))
return C3
def planet_asteroid(start_planet, target_name, tlaunch, tarrive, rev, N):
# Create PyKEP epoch objects and calculate flight time
t1 = epoch(tlaunch)
t2 = epoch(tarrive)
dt = (tarrive - tlaunch) * DAY2SEC
import py.AsteroidDB as asteroidDB
neo_db = asteroidDB.neo
target = (item for item in neo_db if item["name"] == target_name).next()
ep = epoch(target["epoch_mjd"], epoch.epoch_type.MJD)
a = target["a"] * AU
e = target["e"]
i = target["i"] * DEG2RAD
om = target["om"] * DEG2RAD
w = target["w"] * DEG2RAD
ma = target["ma"] * DEG2RAD
as_mu = 1E17 * 6.67384E-11 # maybe need to calculate actual mass from density and radius
r = (target["diameter"] / 2) * 1000
sr = r * 1.1
OBJ2 = planet(ep, (a, e, i, om, w, ma), MU_SUN, as_mu, r, sr)
OBJ1 = planet.jpl_lp(start_planet) # Calculate location of objects in flight path
r1, v1 = OBJ1.eph(t1)
r2, v2 = OBJ2.eph(t2)
# Find trajectory
l = lambert_problem(r1, r2, dt, MU_SUN)
#extract relevant information from solution
r = l.get_r1()
v = l.get_v1()[rev]
mu = l.get_mu()
#define the integration time
dtn = dt / (N - 1)
dtn_days = dtn * SEC2DAY
#alocate the cartesian components for r
t = np.array([0.0] * N)
x = np.array([0.0] * N)
y = np.array([0.0] * N)
z = np.array([0.0] * N)
#calculate the spacecraft position at each dt
for i in range(N):
t[i] = tlaunch + dtn_days * i
x[i] = r[0] / AU
y[i] = r[1] / AU
z[i] = r[2] / AU
r, v = propagate_lagrangian(r, v, dtn, mu)
#traj = [t, x, y, z]
vin = l.get_v1()[rev]
vout = l.get_v2()[rev]
#dV=fb_vel(vin,vout,planet.jpl_lp(arrive_planet))
#dV=np.sqrt( np.square(vin[0]/vout[0])+np.square(vin[1]/vout[1])+np.square(vin[2]/vout[2]))
#dV=np.sqrt( np.square(vin[0]-v1[0])+np.square(v1[1]-vin[1])+np.square(v1[2]-vin[2]))
#dV=np.sqrt( np.square(v2[0]-vout[0])+np.square(v2[1]-vout[1])+np.square(v2[2]-vout[2]))
#dV=np.sqrt( np.square(v1[0]/vin[0])+np.square(v1[1]/vin[1])+np.square(v1[2]/vin[2]))
C3_launch = (np.sqrt(np.square(vin[0] - v1[0]) + np.square(vin[1] - v1[1]) + np.square(vin[2] - v1[2]))) ** 2
C3_arrive = (np.sqrt(np.square(vout[0] - v2[0]) + np.square(vout[1] - v2[1]) + np.square(vout[2] - v2[2]))) ** 2
C3 = np.sqrt((C3_arrive ** 2) + (C3_launch ** 2))
return C3
def traj_planet_asteroid(start_planet, target_name, tlaunch, tarrive, rev, N):
t1 = epoch(tlaunch)
t2 = epoch(tarrive)
dt = (tarrive - tlaunch) * DAY2SEC
import py.AsteroidDB as asteroidDB
neo_db = asteroidDB.neo
target = (item for item in neo_db if item["name"] == target_name).next()
ep = epoch(target["epoch_mjd"], epoch.epoch_type.MJD)
a = target["a"] * AU
e = target["e"]
i = target["i"] * DEG2RAD
om = target["om"] * DEG2RAD
w = target["w"] * DEG2RAD
ma = target["ma"] * DEG2RAD
as_mu = 1E17 * 6.67384E-11 # maybe need to calculate actual mass from density and radius
r = (target["diameter"] / 2) * 1000
sr = r * 1.1
OBJ2 = planet(ep, (a, e, i, om, w, ma), MU_SUN, as_mu, r, sr)
OBJ1 = planet.jpl_lp(start_planet)
# Calculate location of objects in flight path
r1, v1 = OBJ1.eph(t1)
r2, v2 = OBJ2.eph(t2)
#Find trajectory
l = lambert_problem(r1, r2, dt, MU_SUN)
#extract relevant information from solution
r = l.get_r1()
v = l.get_v1()[0]
mu = l.get_mu() #define the integration time
dtn = dt / (N - 1)
dtn_days = dtn * SEC2DAY
#alocate the cartesian components for r
t = np.array([0.0] * N)
x = np.array([0.0] * N)
y = np.array([0.0] * N)
z = np.array([0.0] * N)
#calculate the spacecraft position at each dt
for i in range(N):
t[i] = tlaunch + dtn_days * i
x[i] = r[0] / AU
y[i] = r[1] / AU
z[i] = r[2] / AU
r, v = propagate_lagrangian(r, v, dtn, mu)
traj = [t, x, y, z]
return traj
#junk:
#search_string=str(target["id"])+" "+str(target["H"]) +" "+str(target["G"])+" "+str(mjd_to_iau(target["epoch"]))+" "+str(target["ma"])+" "+str(target["w"])+" "+str(target["om"])+" "+str(target["i"])+" "+str(target["e"])+" "+str(target["n"])+" "+str(target["a"])+" "+str(target["rms"])
# search_string2="04581 20.7 0.15 K145N 189.78193 255.30141 180.29876 4.91898 0.3570250 0.95339205 1.0224020 0 MPO270214 144 5 1989-2013 "
# #non essential components: 0.54 M-v 3Eh MPCW (4581) Asclepius 20130822
# print search_string
# print search_string2