Exemplo n.º 1
0
    def solve(self, *args, validate_barker=True, verbose=False, **kwargs):
        "Solves Lambert's problem for the requested transfer."

        # departure and arrival epochs
        dep_t = pk.epoch(self.dep_t, 'mjd')
        arr_t = pk.epoch(self.arr_t, 'mjd')

        # departure and arrival positions & velocities
        #		/-> (could obtain `dep_ast_eph` in `lambert_optimize_dt` and pass it as
        #		|   argument to avoid having it being repeatedly calculated here)
        #		r1, v1 = self.dep_ast.eph(dep_t) if dep_ast_eph is None else dep_ast_eph
        r1, v1 = self.dep_ast.eph(dep_t)
        r2, v2 = self.arr_ast.eph(arr_t)

        # Barker equation used to skip useless Lambert computations
        # https://en.wikipedia.org/wiki/Parabolic_trajectory#Barker.27s_equation
        if validate_barker and self.dT < pk.barker(r1, r2, MU_SUN) * SEC2DAY:
            if verbose:
                print(self.dT, 'Fails Barker:', self.dT,
                      pk.barker(r1, r2, MU_SUN) * SEC2DAY)
            self.fail()
            return None

        l = pk.lambert_problem(r1, r2, self.dT * DAY2SEC, MU_SUN)
        # don't compute any multi-rev solutions:
        #l = pk.lambert_problem(r1, r2, self.dT * DAY2SEC, MU_SUN, False, 0)

        return l, v1, v2
Exemplo n.º 2
0
def lambert_leg(P1, P2, i, j, t1, t2, tof, vrel=None, dv_launch=0.):
    """Compute a lambert leg from planet to planet.
    Arguments:
    p1 -- starting planet (str or PyKEP.planet object)
    p2 -- final planet (str or PyKEP.planet object)
    t0 -- start time of leg in MJD2000
    tof -- time of flight in days
    
    Keyword arguments:
    vrel -- caresian coordinates of the relative velocity before the flyby at p1
    dv_launch -- dv discounted at lunch (i.e. if vrel is None)
    rendezvous -- add final dv
    Returns:
    dV, vrel_out, where vrel_out is the relative velocity at the end of the leg at p2
    """

    ast1 = ASTEROIDS[P1]
    ast2 = ASTEROIDS[P2]

    r1 = state_asteroids.EPH[i][t1][0]
    v1 = state_asteroids.EPH[i][t1][1]
    r2 = state_asteroids.EPH[j][t2][0]
    v2 = state_asteroids.EPH[j][t2][1]

    lambert = kep.lambert_problem(r1, r2, tof * kep.DAY2SEC, ast1.mu_central_body, False, 0)

    vrel_in = tuple(map(lambda x, y: x - y, lambert.get_v1()[0], v1))
    vrel_out = tuple(map(lambda x, y: x - y, lambert.get_v2()[0], v2))

    dv_lambert = np.linalg.norm(vrel_out) + np.linalg.norm(vrel_in)

    a, _, _, dv_damon = kep.damon(vrel_in, vrel_out, tof*kep.DAY2SEC)
    m_star = kep.max_start_mass(np.linalg.norm(a), dv_damon, T_max, Isp)
    
    return dv_lambert, dv_damon, m_star
Exemplo n.º 3
0
Arquivo: main.py Projeto: tobspm/TS
def search_min_dv_to_body(body, departure_date, departure_position, host_velocity, min_time_of_flight, time_delta, number):
    time_range = [min_time_of_flight + time_delta*i for i in xrange(number)]
    body_positions = [body.eph(time + departure_date.mjd2000)[0] for time in time_range]
    departure_velocities = [pk.lambert_problem(departure_position, pos, time*pk.DAY2SEC, pk.MU_SUN, False, 0).get_v1()[0] for pos, time in zip(body_positions, time_range)]
    deltaV = [np.linalg.norm(np.array(velocity)-host_velocity) for velocity in departure_velocities]
    index_min = np.array(deltaV).argmin()
    return index_min, departure_velocities[index_min]
Exemplo n.º 4
0
def lamberts(x1, x2, traj):
    '''
    Takes two position points - numpy arrays with time,x,y,z as elements
    and produces two vectors with the state vector for both positions using Lamberts solution

    Args:
        x1(numpy array): time and position for point 1 [time1,x1,y1,z1]
        x2(numpy array): time and position for point 2 [time2,x2,y2,z2]

    Returns:
        numpy array: velocity vector for point 1 (vx, vy, vz)
    '''

    x1_new = [1, 1, 1]
    x1_new[:] = x1[1:4]
    x2_new = [1, 1, 1]
    x2_new[:] = x2[1:4]
    time = x2[0] - x1[0]

    # traj = orbit_trajectory(x1_new, x2_new, time)

    l = pkp.lambert_problem(x1_new, x2_new, time, 398600.4405, traj)

    v1 = l.get_v1()
    v1 = np.asarray(v1)
    v1 = np.reshape(v1, 3)

    return v1
Exemplo n.º 5
0
def orbit_trajectory(x1_new, x2_new, time):
    '''
    Tool for checking if the motion of the sallite is retrogade or counter - clock wise
    
    Args:
        x1 (numpy array): time and position for point 1 [time1,x1,y1,z1]
        x2 (numpy array): time and position for point 2 [time2,x2,y2,z2]
        time (float): time difference between the 2 points
        
    Returns:
        bool: true if we want to keep retrogade, False if we want counter-clock wise
    '''

    l = pkp.lambert_problem(x1_new, x2_new, time, 398600.4405, False)

    v1 = l.get_v1()
    v1 = np.asarray(v1)
    v1 = np.reshape(v1, 3)
    x1_new = np.asarray(x1_new)

    kep1 = state_kep.state_kep(x1_new, v1)

    if kep1[0] < 0.0:
        traj = True
    elif kep1[1] > 1.0:
        traj = True
    else:
        traj = False

    return traj
Exemplo n.º 6
0
def search_min_dv_to_body(body, departure_date, departure_position,
                          host_velocity, min_time_of_flight, time_delta,
                          number):
    time_range = [min_time_of_flight + time_delta * i for i in xrange(number)]
    body_positions = [
        body.eph(time + departure_date.mjd2000)[0] for time in time_range
    ]
    departure_velocities = [
        pk.lambert_problem(departure_position, pos, time * pk.DAY2SEC,
                           pk.MU_SUN, False, 0).get_v1()[0]
        for pos, time in zip(body_positions, time_range)
    ]
    deltaV = [
        np.linalg.norm(np.array(velocity) - host_velocity)
        for velocity in departure_velocities
    ]
    index_min = np.array(deltaV).argmin()
    return index_min, departure_velocities[index_min]
Exemplo n.º 7
0
def lambert_leg(P1, P2, t0, tof):
    
    ast1 = ASTEROIDS[P1]
    ast2 = ASTEROIDS[P2]

    r1, v1 = ast1.eph(kep.epoch(t0))
    r2, v2 = ast2.eph(kep.epoch(t0 + tof))

    lambert = kep.lambert_problem(r1, r2, tof * kep.DAY2SEC, ast1.mu_central_body)

    vrel_in = tuple(map(lambda x, y: -x + y, lambert.get_v1()[0], v1))
    vrel_out = tuple(map(lambda x, y: -x + y, lambert.get_v2()[0], v2))

    dv_lambert = np.linalg.norm(vrel_out) + np.linalg.norm(vrel_in)

    a, _, _, dv_damon = kep.damon(vrel_in, vrel_out, tof*kep.DAY2SEC)
    m_star = kep.max_start_mass(np.linalg.norm(a), dv_damon, T_max, Isp)
    
    return dv_lambert, dv_damon, m_star
Exemplo n.º 8
0
def lambert_leg(P1, P2, i, j, t1, t2, tof, vrel=None, dv_launch=0., rendezvous=False):
    """Compute a lambert leg from planet to planet.

    Arguments:
    p1 -- starting planet (str or PyKEP.planet object)
    p2 -- final planet (str or PyKEP.planet object)
    t0 -- start time of leg in MJD2000
    tof -- time of flight in days
    
    Keyword arguments:
    vrel -- caresian coordinates of the relative velocity before the flyby at p1
    dv_launch -- dv discounted at lunch (i.e. if vrel is None)
    rendezvous -- add final dv

    Returns:
    dV, vrel_out, where vrel_out is the relative velocity at the end of the leg at p2
    """

    p1 = PLANETS[str(P1)]
    p2 = PLANETS[str(P2)]

    r1 = state_rosetta.EPH[i][t1][0]
    v1 = state_rosetta.EPH[i][t1][1]
    r2 = state_rosetta.EPH[j][t2][0]
    v2 = state_rosetta.EPH[j][t2][1]

    lambert = kep.lambert_problem(r1, r2, tof * kep.DAY2SEC, p1.mu_central_body, False, 0)

    vrel_in = tuple(map(lambda x, y: x - y, lambert.get_v1()[0], v1))
    vrel_out = tuple(map(lambda x, y: x - y, lambert.get_v2()[0], v2))

    if vrel is None:
        # launch
        dv = max(np.linalg.norm(vrel_in) - dv_launch, 0)
    else:
        # flyby
        #print p1.name, p2.name, np.linalg.norm(vrel_in), np.linalg.norm(vrel_out)
        dv = kep.fb_vel(vrel, vrel_in, p1)

    if rendezvous:
        dv += np.linalg.norm(vrel_out)
        
    return dv, vrel_out
Exemplo n.º 9
0
def lambert_leg(P1, P2, i, j, t1, t2, tof):
    
    ast1 = ASTEROIDS[P1]
    ast2 = ASTEROIDS[P2]

    r1 = state_asteroids.EPH[i][t1][0]
    v1 = state_asteroids.EPH[i][t1][1]
    r2 = state_asteroids.EPH[j][t2][0]
    v2 = state_asteroids.EPH[j][t2][1]

    lambert = kep.lambert_problem(r1, r2, tof * kep.DAY2SEC, ast1.mu_central_body)

    vrel_in = tuple(map(lambda x, y: -x + y, lambert.get_v1()[0], v1))
    vrel_out = tuple(map(lambda x, y: -x + y, lambert.get_v2()[0], v2))

    dv_lambert = np.linalg.norm(vrel_out) + np.linalg.norm(vrel_in)

    a, _, _, dv_damon = kep.damon(vrel_in, vrel_out, tof*kep.DAY2SEC)
    m_star = kep.max_start_mass(np.linalg.norm(a), dv_damon, T_max, Isp)
    
    return dv_lambert, dv_damon, m_star