Exemplo n.º 1
0
def solution(infile='./data/RV2.txt', outfile='./data/RV2_solution.txt'):
    """Generate the solution that students should be able to match

    """
    mu = constants.earth.mu

    output_string = ''
    with open(infile, 'r') as f:
        line = f.readline().split()
        while line:
            r_in = np.array([float(i) for i in line[0:3]])
            v_in = np.array([float(i) for i in line[3:6]])
            dt = float(line[6])

            # convert to coe
            p, a, ecc, inc, raan, arg_p, nu, _, _, _, _ = kepler.rv2coe(
                r_in, v_in, mu)

            # propagate forward
            E_f, M_f, nu_f = kepler.tof_delta_t(p, ecc, mu, nu, dt)

            # compute elements at future time
            prop_string = kepler.orbit_el(p, ecc, inc, raan, arg_p, nu_f, mu)

            output_string += prop_string

            line = f.readline().split()

    with open(outfile, 'w') as f:
        f.write(output_string)
Exemplo n.º 2
0
# initial orbit parameters
a_1 =6*re2km
ecc_1 = .5
nu_0 = 0
p_1 = a_1*(1-ecc_1**2)


# desired orbit altitude - location of manuever
r_1 = 7.6*re2km
# find intersection of original orbit and desired orbit - true anomaly
nu_1 = kepler.nu_solve(p_1, ecc_1, r_1)

# conditions of orbit just prior to burn
print('Initial Orbit prior to manuever')
kepler.orbit_el(p_1, ecc_1, 0, 0, 0, nu_1[0], mu, 'True')
_,_, r1_pqw, v1_pqw= kepler.coe2rv(p_1, ecc_1, 0, 0, 0, nu_1[0], mu)
fpa1 = kepler.fpa_solve(nu_1[0], ecc_1)

# properties of desired orbit at manuever point
r_2 = r_1
ecc_2 = 0
_,_, r2_pqw, v2_pqw= kepler.coe2rv(r_2, ecc_2, 0, 0, 0, nu_1[0], mu)

delta_v, alpha, beta = manuever.delta_v_solve_planar(np.linalg.norm(v1_pqw),
                                                     np.linalg.norm(v2_pqw),
                                                     fpa1, 0)
print('Delta V: {} km/sec'.format(delta_v))
print('Alpha: {} deg, Beta: {} deg'.format(np.rad2deg(alpha), np.rad2deg(beta)))
# final orbit properties
print('Final Orbit after manuever')
Exemplo n.º 3
0
from astro import kepler, constants
import numpy as np
import matplotlib.pyplot as plt

# define orbital elements
a = 3 * constants.earth.radius
ecc = 0.4
p = kepler.semilatus_rectum(a, ecc)
inc = np.deg2rad(28.5)
raan = np.deg2rad(45)
argp = np.deg2rad(90)
nu = np.deg2rad(235)

mu = constants.earth.mu
re = constants.earth.radius
output = kepler.orbit_el(p, ecc, inc, raan, argp, nu, mu, True)

# generate a plot of orbit plane
# plot the orbit
state_eci, state_pqw, state_lvlh, state_sat_eci, state_sat_pqw, state_sat_lvlh = kepler.conic_orbit(
    p, ecc, inc, raan, argp, nu, nu)

fig, ax = plt.subplots()
ax.plot(state_pqw[:, 0], state_pqw[:, 1])
ax.plot(re * np.cos(np.linspace(0, 2 * np.pi)),
        re * np.sin(np.linspace(0, 2 * np.pi)))
ax.plot([0, state_sat_pqw[0]], [0, state_sat_pqw[1]], 'b-', linewidth=3)
ax.plot(state_sat_pqw[0], state_sat_pqw[1], 'b.', markersize=20)
ax.set_xlabel(r'$\hat p$')
ax.set_ylabel(r'$\hat q$')
plt.axis('equal')
Exemplo n.º 4
0
    # get RV vector
    sat.tle_update(epoch, mu=constants.earth.mu)

    (a, h, period, sme, fpa, r_per, r_apo, r_ijk, v_ijk, r_pqw, v_pqw, r_lvlh,
     v_lvlh, r, v, v_circ, v_esc, E, M,
     n) = kepler.elp_orbit_el(sat.coe.p, sat.coe.ecc, sat.coe.inc,
                              sat.coe.raan, sat.coe.argp, sat.coe.nu,
                              constants.earth.mu)

    ofile.write(
        '{:10.6f} {:10.6f} {:10.6f} {:10.6f} {:10.6f} {:10.6f}\n'.format(
            r_lvlh[0], r_lvlh[1], r_lvlh[2], v_lvlh[0], v_lvlh[1], v_lvlh[2]))

    # get orbital paramters
    param_string = kepler.orbit_el(sat.coe.p, sat.coe.ecc, sat.coe.inc,
                                   sat.coe.raan, sat.coe.argp, sat.coe.nu,
                                   constants.earth.mu)

    answer_file.write('\n{} {}\n{}'.format(sat.satname, sat.satnum,
                                           param_string))

    print(sat.satname, sat.satnum)
    print(param_string)

    # create the plot of the orbit in the PQW reference frame
    pos_eci, sat_eci, pos_pqw, sat_pqw = kepler.conic_orbit(
        sat.coe.p, sat.coe.ecc, sat.coe.inc, sat.coe.raan, sat.coe.argp,
        sat.coe.nu, sat.coe.nu)

    fig, ax = plt.subplots()
    ax.plot(pos_pqw[:, 0], pos_pqw[:, 1])
Exemplo n.º 5
0
times = np.linspace(etOne, etTwo, 5000)
state = np.zeros((len(times), 6))
for ii, et in enumerate(times):
    state[ii, :], _ = spice.spkezr('Cassini', et, 'J2000', 'None',
                                   'SATURN BARYCENTER')

initial_state = state[0, :]
# comppute position/velocity in the orbital plane
print('Cassini pos: {} km'.format(initial_state[0:3]))
print('Cassini vel: {} km/sec'.format(initial_state[3:6]))

# compute some orbital elements of the vehicle
mu = constants.saturn.mu
p, a, ecc, inc, raan, arg_p, nu, m, arglat, truelon, lonper = kepler.rv2coe(
    initial_state[0:3], initial_state[3:6], mu)
kepler.orbit_el(p, ecc, inc, raan, arg_p, nu, mu, print_flag=True)

# students should generate a plot of the orbit (conic equation)
pos_inertial, sat_inertial, pos_pqw, sat_pqw = kepler.conic_orbit(
    p, ecc, inc, raan, arg_p, nu, nu)
rsaturn = constants.saturn.radius
pqw_fig, pqw_ax = plt.subplots()
pqw_ax.plot(pos_pqw[:, 0] / rsaturn, pos_pqw[:, 1] / rsaturn)
pqw_ax.plot(sat_pqw[0] / rsaturn, sat_pqw[1] / rsaturn, 'bo', markersize=10)
pqw_ax.plot(0, 0, 'bo', markersize=20)
pqw_ax.set_xlabel(r'$\hat p (r_{\saturn})$')
pqw_ax.set_ylabel(r'$\hat q (r_{\saturn})$')
pqw_ax.set_title(r'Cassini Orbit in Perifocal Reference Frame')
pqw_ax.grid()

fig = plt.figure()
Exemplo n.º 6
0
au2km = constants.au2km
a = au2km * 17.834144  # au
ecc = 0.9671429
p = kepler.semilatus_rectum(a, ecc)
inc = np.deg2rad(162.262690579161)
raan = np.deg2rad(58.42008097656843)
argp = np.deg2rad(111.3324851045177)
M = np.deg2rad(38.3842644764388)

E, nu, _ = kepler.kepler_eq_E(M, ecc)
mu = constants.sun.mu

# properties at perihelion
print('Properties at Perihelion')
output = 'Properties at Perihelion\n'
output += kepler.orbit_el(p, ecc, inc, raan, argp, 0, mu, True)

# properties at next observation occurs at nu = 260 deg
print('Properties at next Observations Window')
output += "\nProperties at Next OBS window\n"
output += kepler.orbit_el(p, ecc, inc, raan, argp, nu_obs, mu, True)

# compute time to go from last perihelion to nu = 260 and then to perihelion
dt_obs_window = kepler.tof_nu(p, ecc, 0, nu_obs, mu)
jd_obs_window = jd_per + dt_obs_window * constants.sec2day
date_obs_window = time.jd2date(jd_obs_window)

# time to get from obs window to perihelion
dt_obs2peri = kepler.tof_nu(p, ecc, nu_obs, 2 * np.pi - 1e-6, mu)

print('Time to go nu=260 to perihelion: {} sec = {} days'.format(
Exemplo n.º 7
0
import numpy as np
from astro import kepler, constants

mu = constants.earth.mu
p = 0.23 * constants.earth.radius
e = 0.82
inc = np.pi / 2
raan = np.deg2rad(180)
arg_p = np.deg2rad(260)
nu = np.deg2rad(190)

string = kepler.orbit_el(p, e, inc, raan, arg_p, nu, mu, False)
print(string)
Exemplo n.º 8
0
hr2sec = constants.hr2sec

# orbital parameters
mag_r = 4 * re2km
mag_v = 4.54 # km/sec
fpa = np.deg2rad(-40)
tof = 8.5 * hr2sec

delta_v = 1.2
alpha = np.deg2rad(30)
beta = np.pi - alpha

# colculate some elements
a, p, ecc, nu = manuever.rvfpa2orbit_el(mag_r, mag_v, fpa, mu)
print('Initial Orbital Elements')
kepler.orbit_el(p, ecc, 0, 0, 0, nu, mu, True)

# propogate to a new point in the orbit
Ef, Mf, nuf = kepler.tof_delta_t(p, ecc, mu, nu, tof)

# orbital elements just before the burn
print('Orbital Elements just before burn')
kepler.orbit_el(p, ecc, 0, 0, 0, nuf, mu, True)
out = kepler.elp_orbit_el(p, ecc, 0, 0, 0, nuf, mu)
r1 = np.linalg.norm(out[7])
v1 = np.linalg.norm(out[8])
fpa1 = out[4]

# compute burn
rf, vf, fpaf = manuever.single_impulse(r1, v1, fpa1, delta_v, alpha)
an, pn, eccn, nun = manuever.rvfpa2orbit_el(rf, vf, fpaf, mu)
Exemplo n.º 9
0
def solution(meas_file='./data/COMFIX_tle_measurement.txt',
             outfile='./data/COMFIX_tle_solution.txt'):
    # read in the measurement data
    fout = open(outfile, 'w')

    with open(meas_file, 'r') as f:
        l0 = f.readline().split()
        l0 = [float(x) for x in l0]
        while l0:
            l1 = f.readline().split()
            l1 = [float(x) for x in l1]
            latgd, lon, alt, jd = np.deg2rad(l0[0]), np.deg2rad(
                l0[1]), l0[2] / 1e3, l0[3]
            satnum, rho, az, el, drho, daz, dele = l1[0], l1[1], np.deg2rad(
                l1[2]), np.deg2rad(l1[3]), l1[4], np.deg2rad(
                    l1[5]), np.deg2rad(l1[6])

            # GST, LST
            gst, lst = time.gstlst(jd, lon)
            # find satellite vector in SEZ
            rho_sez, drho_sez = geodetic.rhoazel2sez(rho, az, el, drho, daz,
                                                     dele)
            R_eci2ecef = geodetic.eci2ecef(jd)
            R_ecef2eci = geodetic.ecef2eci(jd)
            R_sez2ecef = transform.dcm_sez2ecef(latgd, lon, alt)

            # find  site vector in ECEF/ECI
            site_ecef = geodetic.lla2ecef(latgd, lon, alt)
            site_eci = R_ecef2eci.dot(site_ecef)

            # transform satellite vector from SEZ to ECI
            rho_ecef = R_sez2ecef.dot(rho_sez)
            rho_eci = R_ecef2eci.dot(rho_ecef)

            drho_ecef = R_sez2ecef.dot(drho_sez)
            drho_eci = R_ecef2eci.dot(drho_ecef)

            pos_eci = site_eci + rho_eci
            vel_eci = drho_eci + np.cross(
                np.array([0, 0, constants.earth.omega]), pos_eci)
            # find orbital elements
            p, a, ecc, inc, raan, arg_p, nu, _, _, _, _ = kepler.rv2coe(
                pos_eci, vel_eci, constants.earth.mu)

            # compute orbit properties
            prop_string = kepler.orbit_el(p, ecc, inc, raan, arg_p, nu,
                                          constants.earth.mu)

            l0 = f.readline().split()
            l0 = [float(x) for x in l0]
            # output to text file
            fout.write(
                '#################### COMFIX SATELLITE {:g} ####################################\n\n'
                .format(satnum))
            fout.write(
                '------------------------ INPUT DATA -------------------------------------------\n\n'
            )
            fout.write('LAT (deg)    LON (deg)     ALT (m)       JD\n')
            fout.write(
                '{:<9.4f}    {:<9.4f}     {:<9.4f}      {:<16.6f}\n\n'.format(
                    np.rad2deg(latgd), np.rad2deg(lon), alt * 1e3, jd))
            fout.write(
                'RHO (km)     AZ (deg)    EL (deg)   DRHO (km/s)   DAZ (deg/s)   DEL (deg/s)\n'
            )
            fout.write(
                '{:<9.4f}     {:<6.4f}    {:<6.4f}     {:<6.4f}     {:<6.4f}        {:<6.4f}\n'
                .format(rho, np.rad2deg(az), np.rad2deg(el), drho,
                        np.rad2deg(daz), np.rad2deg(dele)))

            fout.write(
                '------------------------- WORKING DATA ----------------------------------------\n\n'
            )
            fout.write('LAT (rad)    LON (rad)     ALT (m)       JD\n')
            fout.write(
                '{:<9.4f}    {:<9.4f}     {:<9.4f}      {:<16.6f}\n\n'.format(
                    latgd, lon, alt, jd))
            fout.write(
                'RHO (km)     AZ (rad)    EL (rad)   DRHO (km/s)   DAZ (rad/s)   DEL (rad/s)\n'
            )
            fout.write(
                '{:<9.4f}     {:<6.4f}    {:<6.4f}     {:<6.4f}     {:<6.4f}        {:<6.4f}\n\n'
                .format(rho, az, el, drho, daz, dele))
            fout.write('GST  = {:16.9f} rad = {:16.9f} deg\n'.format(
                gst, np.rad2deg(gst)))
            fout.write('LST  = {:16.9f} rad = {:16.9f} deg\n\n'.format(
                lst, np.rad2deg(lst)))

            fout.write(
                '---------------------------- VECTORS ------------------------------------------\n'
            )
            fout.write(
                '{:9s} = {:13.4f} S {:13.4f} E {:13.4f} Z MAG = {:7.4f} km\n'.
                format('rho_sez', rho_sez[0], rho_sez[1], rho_sez[2],
                       np.linalg.norm(rho_sez)))
            fout.write(
                '{:9s} = {:13.4f} I {:13.4f} J {:13.4f} K MAG = {:7.4f} km\n'.
                format('rho_ecef', rho_ecef[0], rho_ecef[1], rho_ecef[2],
                       np.linalg.norm(rho_ecef)))
            fout.write(
                '{:9s} = {:13.4f} I {:13.4f} J {:13.4f} K MAG = {:7.4f} km\n'.
                format('rho_eci', rho_eci[0], rho_eci[1], rho_eci[2],
                       np.linalg.norm(rho_eci)))
            fout.write(
                '{:9s} = {:13.4f} S {:13.4f} E {:13.4f} Z MAG = {:7.4f} km/s\n'
                .format('drho_sez', drho_sez[0], drho_sez[1], drho_sez[2],
                        np.linalg.norm(drho_sez)))
            fout.write(
                '{:9s} = {:13.4f} I {:13.4f} J {:13.4f} K MAG = {:7.4f} km/s\n'
                .format('drho_ecef', drho_ecef[0], drho_ecef[1], drho_ecef[2],
                        np.linalg.norm(drho_ecef)))
            fout.write(
                '{:9s} = {:13.4f} I {:13.4f} J {:13.4f} K MAG = {:7.4f} km/s\n'
                .format('drho_eci', drho_eci[0], drho_eci[1], drho_eci[2],
                        np.linalg.norm(drho_eci)))
            fout.write(
                '{:9s} = {:13.4f} I {:13.4f} J {:13.4f} K MAG = {:7.4f} km\n'.
                format('site_ecef', site_ecef[0], site_ecef[1], site_ecef[2],
                       np.linalg.norm(site_ecef)))
            fout.write(
                '{:9s} = {:13.4f} I {:13.4f} J {:13.4f} K MAG = {:7.4f} km\n'.
                format('site_eci', site_eci[0], site_eci[1], site_eci[2],
                       np.linalg.norm(site_eci)))
            fout.write(
                '{:9s} = {:13.4f} I {:13.4f} J {:13.4f} K MAG = {:7.4f} km\n'.
                format('pos_eci', pos_eci[0], pos_eci[1], pos_eci[2],
                       np.linalg.norm(pos_eci)))
            fout.write(
                '{:9s} = {:13.4f} I {:13.4f} J {:13.4f} K MAG = {:7.4f} km/s\n'
                .format('vel_eci', vel_eci[0], vel_eci[1], vel_eci[2],
                        np.linalg.norm(vel_eci)))

            fout.write(prop_string + '\n')
    fout.close()
Exemplo n.º 10
0
import matplotlib.pyplot as plt

re = constants.earth.radius
mu_e = constants.earth.mu

r_p = 1000 + re
ecc = 1.05
nu = np.deg2rad(90)
nu_1 = np.deg2rad(90)
nu_2 = np.deg2rad(150)

a, p = kepler.hyp_per2sma(r_p, ecc)
# compute orbit properties
print("Properties at nu=90")
output = "Properties at nu=90 deg\n"
output += kepler.orbit_el(p, ecc, 0, 0, 0, nu, mu_e, True)

# plot the orbit
state_eci, state_pqw, state_lvlh, state_sat_eci, state_sat_pqw, state_sat_lvlh = kepler.conic_orbit(
    p, ecc, 0, 0, 0, -np.deg2rad(135), np.deg2rad(135))

# orbit properties at second nu
print("Properties at nu=150")
output += "Properties at nu=150 deg\n"
output += kepler.orbit_el(p, ecc, 0, 0, 0, np.deg2rad(150), mu_e, True)

# time of flight
tof = kepler.tof_nu(p, ecc, nu_1, nu_2, mu_e)
print('Time of flight from 90 to 150 deg: {} sec = {} hrs'.format(
    tof, tof / 3600))
output += 'Time of flight from 90 to 150 deg: {} sec = {} hrs'.format(
Exemplo n.º 11
0
# initial orbit
ecc_i = .4
a_i = 6 * re2km
nu_i = 90 * deg2rad

p_i = kepler.semilatus_rectum(a_i, ecc_i)
inc_i = 0
raan_i = 0
arg_p_i = 0

mag_dv = 0.75
alpha = -60 * deg2rad

# calculate orbital elements
print('Initial Orbit')
kepler.orbit_el(p_i, ecc_i, inc_i, raan_i, arg_p_i, nu_i, mu, 'True')
_, _, rpqw_i, vpqw_i = kepler.coe2rv(p_i, ecc_i, inc_i, raan_i, arg_p_i, nu_i,
                                     mu)
fpa_i = kepler.fpa_solve(nu_i, ecc_i)

# convert delta v and alpha into various reference frames
(dv_vnc, dv_lvlh) = maneuver.delta_v_vnc(mag_dv, alpha, 0, fpa_i)
# transform delta v to pqw frame
R_lvlh2pqw = transform.dcm_lvlh2pqw(nu_i)
dv_pqw = R_lvlh2pqw.dot(dv_lvlh)

print('DV : {} V {} C {} N km/sec'.format(dv_vnc[0], dv_vnc[1], dv_vnc[2]))
print('DV : {} R {} T {} H km/sec'.format(dv_lvlh[0], dv_lvlh[1], dv_lvlh[2]))
print('DV : {} P {} Q {} W km/sec'.format(dv_pqw[0], dv_pqw[1], dv_pqw[2]))

# properties of new orbit
Exemplo n.º 12
0
r_mars = constants.mars.radius
mu = constants.mars.mu
deg2rad = constants.deg2rad
rad2deg = constants.rad2deg

# initial orbit elements
a = 5*r_mars
ecc =.5
p = kepler.semilatus_rectum(a, ecc)
inc = 30*deg2rad
raan = 45*deg2rad
arg_p = -60*deg2rad
nu = 120*deg2rad

print('Initial Mars Orbit')
kepler.orbit_el(p,ecc,inc,raan,arg_p,nu,mu,'True')
r_inertial, v_inertial, _, _ = kepler.coe2rv(p, ecc, inc, raan, arg_p, nu, mu)
fpa = kepler.fpa_solve(nu, ecc)
# delta v in inertial coordinates
dv_inertial = np.array([0.1,-0.25,0.2])

# form rotation matrix to go from mars inertial frame to LVLH frame
dcm_mci2pqw = transform.dcm_eci2pqw_coe(raan, inc, arg_p)
dcm_pqw2lvlh = transform.dcm_pqw2lvlh(nu)

dv_lvlh = dcm_pqw2lvlh.dot(dcm_mci2pqw).dot(dv_inertial)
print('Delta V : {} rhat {} that {} hhat km/sec'.format(dv_lvlh[0], dv_lvlh[1], dv_lvlh[2]))
mag_dv = np.linalg.norm(dv_lvlh)

mag_dv_outofplane = dv_lvlh[2]
mag_dv_inplane = np.linalg.norm(dv_lvlh[0:1])