Пример #1
0
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_ss(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_ss(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
Пример #2
0
def traj_planet_asteroid(source, dest, tlaunch, tarrive, rev, N):
    t1 = epoch(tlaunch)
    t2 = epoch(tarrive)
    dt = (tarrive - tlaunch) * DAY2SEC

    target = source['orbit']

    ep = epoch(jd_to_mjd(tlaunch), 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 = (10 / 2) * 1000
    sr = r * 1.1

    OBJ1 = planet(ep, (a, e, i, om, w, ma), MU_SUN, as_mu, r, sr)

    target = dest['orbit']

    ep = epoch(jd_to_mjd(tarrive), 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 = (10 / 2) * 1000
    sr = r * 1.1

    OBJ2 = planet(ep, (a, e, i, om, w, ma), MU_SUN, as_mu, r, sr)

    # 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.tolist(), x.tolist(), y.tolist(), z.tolist()]

    return traj
Пример #3
0
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_ss(
        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_ss(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
Пример #4
0
def traj_planet_asteroid(source, dest, tlaunch, tarrive, rev, N):
    t1 = epoch(tlaunch)
    t2 = epoch(tarrive)
    dt = (tarrive - tlaunch) * DAY2SEC

    target = source['orbit']

    ep = epoch(jd_to_mjd(tlaunch), 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 = (10 / 2) * 1000
    sr = r * 1.1

    OBJ1 = planet(ep, (a, e, i, om, w, ma), MU_SUN, as_mu, r, sr)

    target = dest['orbit']

    ep = epoch(jd_to_mjd(tarrive), 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 = (10 / 2) * 1000
    sr = r * 1.1

    OBJ2 = planet(ep, (a, e, i, om, w, ma), MU_SUN, as_mu, r, sr)

    # 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.tolist(), x.tolist(), y.tolist(), z.tolist()]

    return traj
Пример #5
0
def getTraj(K1, K2, tlaunch, tarrive, N):
    '''
	Finds a trajectory between two objects orbiting the Sun
		
	USAGE: traj = getTraj(K1, K2, tlaunch, tarrive)
		K:  		array of object parameters.
		epoch:		epoch of Keplerian orbital elements (JD)
		a:  	 	semimajor axis (AU)
		e:  	 	eccentricity (none)
		i:  	 	inclination (deg)
		om: 	 	longitude of the ascending node (deg)
		w:  	 	argument of perihelion (deg)
		ma: 	 	mean anomaly at epoch (deg)
		mass: 	 	mass of object (kg)  
		r: 	 	radius of object (m)
		sr:	 	safe radius to approach object (m)
		K1: 	 	[epoch1,a1,e1,i1,om1,w1,ma1,mass1,r1,sr1]
		K2: 	 	[epoch2,a2,e2,i2,om2,w2,ma2,mass2,r2,sr2]
		tlaunch: 	launch time (JD)
		tarrive: 	arrival time (JD)
		N:		number of points in calculated trajectory
	
	'''
    import numpy as np
    from PyKEP import epoch, DAY2SEC, SEC2DAY, AU, DEG2RAD, MU_SUN, planet, lambert_problem, propagate_lagrangian

    #Create PyKEP epoch objects and calculate flight time
    t1 = epoch(tlaunch, epoch.epoch_type.JD)
    t2 = epoch(tarrive, epoch.epoch_type.JD)
    dt = (t2.mjd2000 - t1.mjd2000) * DAY2SEC

    #First object
    K1[0] = epoch(K1[0],
                  epoch.epoch_type.JD)  #convert epoch to PyKEP epoch object
    K1[1] = K1[1] * AU  #convert AU to meters
    K1[3] = K1[3] * DEG2RAD  #convert angles from degrees to radians
    K1[4] = K1[4] * DEG2RAD
    K1[5] = K1[5] * DEG2RAD
    K1[6] = K1[6] * DEG2RAD
    K1[7] = K1[7] * 6.67384E-11  #convert mass to gravitational parameter mu
    OBJ1 = planet(K1[0], K1[1:7], MU_SUN, K1[7], K1[8], K1[9])

    #Second object
    K2[0] = epoch(K2[0],
                  epoch.epoch_type.JD)  #convert epoch to PyKEP epoch object
    K2[1] = K2[1] * AU  #convert AU to meters
    K2[3] = K2[3] * DEG2RAD  #convert angles from degrees to radians
    K2[4] = K2[4] * DEG2RAD
    K2[5] = K2[5] * DEG2RAD
    K2[6] = K2[6] * DEG2RAD
    K2[7] = K2[7] * 6.67384E-11  #convert mass to gravitational parameter mu
    OBJ2 = planet(K2[0], K2[1:7], MU_SUN, K2[7], K2[8], K2[9])

    #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
Пример #6
0
def getTraj(K1, K2, tlaunch, tarrive, N):
	'''
	Finds a trajectory between two objects orbiting the Sun
		
	USAGE: traj = getTraj(K1, K2, tlaunch, tarrive)
		K:  		array of object parameters.
		epoch:		epoch of Keplerian orbital elements (JD)
		a:  	 	semimajor axis (AU)
		e:  	 	eccentricity (none)
		i:  	 	inclination (deg)
		om: 	 	longitude of the ascending node (deg)
		w:  	 	argument of perihelion (deg)
		ma: 	 	mean anomaly at epoch (deg)
		mass: 	 	mass of object (kg)  
		r: 	 	radius of object (m)
		sr:	 	safe radius to approach object (m)
		K1: 	 	[epoch1,a1,e1,i1,om1,w1,ma1,mass1,r1,sr1]
		K2: 	 	[epoch2,a2,e2,i2,om2,w2,ma2,mass2,r2,sr2]
		tlaunch: 	launch time (JD)
		tarrive: 	arrival time (JD)
		N:		number of points in calculated trajectory
	
	'''
	import numpy as np
	from PyKEP import epoch, DAY2SEC, SEC2DAY, AU, DEG2RAD, MU_SUN, planet, lambert_problem, propagate_lagrangian

	#Create PyKEP epoch objects and calculate flight time 
	t1 = epoch(tlaunch,epoch.epoch_type.JD)
	t2 = epoch(tarrive,epoch.epoch_type.JD)
	dt = (t2.mjd2000 - t1.mjd2000) * DAY2SEC
	
	#First object
	K1[0] 	= epoch(K1[0],epoch.epoch_type.JD)	#convert epoch to PyKEP epoch object		
	K1[1] 	= K1[1] * AU 				#convert AU to meters       
	K1[3]   = K1[3] * DEG2RAD 			#convert angles from degrees to radians
	K1[4]	= K1[4] * DEG2RAD
	K1[5]	= K1[5] * DEG2RAD
	K1[6]	= K1[6] * DEG2RAD	
	K1[7] 	= K1[7] * 6.67384E-11			#convert mass to gravitational parameter mu
	OBJ1 	= planet(K1[0], K1[1:7], MU_SUN, K1[7], K1[8], K1[9])
	
	#Second object
	K2[0] 	= epoch(K2[0],epoch.epoch_type.JD)	#convert epoch to PyKEP epoch object		
	K2[1] 	= K2[1] * AU 				#convert AU to meters       
	K2[3]   = K2[3] * DEG2RAD 			#convert angles from degrees to radians
	K2[4]	= K2[4] * DEG2RAD
	K2[5]	= K2[5] * DEG2RAD
	K2[6]	= K2[6] * DEG2RAD	
	K2[7] 	= K2[7] * 6.67384E-11			#convert mass to gravitational parameter mu
	OBJ2 	= planet(K2[0], K2[1:7], MU_SUN, K2[7], K2[8], K2[9])
	
	#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