class TestConicOrbitEquatorial(): p = 7000 # km ecc = 0.0 inc = 0.0 raan = 0.0 arg_p = 0.0 nu_i = 0.0 nu_f = 0.0 mu = constants.earth.mu (state_eci, state_pqw, state_lvlh, state_sat_eci, state_sat_pqw, state_sat_lvlh) = kepler.conic_orbit(p, ecc, inc, raan, arg_p, nu_i, nu_f, mu) def test_x_axis(self): np.testing.assert_allclose(self.state_sat_eci[0], self.p) def test_y_axis(self): np.testing.assert_allclose(self.state_sat_eci[1], 0) def test_z_axis(self): np.testing.assert_allclose(self.state_sat_eci[2], 0) def test_circular_orbit(self): np.testing.assert_allclose(np.linalg.norm(self.state_eci[:, 0:3], axis=1), self.p) def test_lvlh_radial_velocity(self): np.testing.assert_allclose(self.state_lvlh[:, 3], 0) def test_lvlh_tangential_velocity(self): np.testing.assert_allclose(self.state_lvlh[:, 4], np.sqrt(self.mu/self.p))
class TestConicOrbitParabolic(): p = 10000 # km ecc = 1.0 inc = 0.0 raan = 0.0 arg_p = 0.0 nu_i = 0.0 nu_f = 0.0 (state_eci, state_pqw, state_lvlh, state_sat_eci, state_sat_pqw, state_sat_lvlh) = kepler.conic_orbit(p, ecc, inc, raan, arg_p, nu_i, nu_f) def test_x_axis(self): np.testing.assert_allclose(self.state_sat_eci[0], self.p/2) def test_y_axis(self): np.testing.assert_allclose(self.state_sat_eci[1], 0) def test_z_axis(self): np.testing.assert_allclose(self.state_sat_eci[2], 0)
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') kepler.orbit_el(r_2, ecc_2, 0, 0, 0, nu_1[0], mu, 'True') # create the plot # generate a plot of the orbit _, state_pqw1, _, _, sat_pqw1, _ = kepler.conic_orbit(p_1, ecc_1, 0, 0, 0, nu_1[0], nu_1[0], mu) _, state_pqw2, _, _, sat_pqw2, _ = kepler.conic_orbit(r_2, ecc_2, 0, 0, 0, 0, 0, mu) # rotate the second orbit by the change in argument of perigee fig, ax = plt.subplots() ax.plot(state_pqw1[:, 0], state_pqw1[:, 1], label='Initial') ax.plot(state_pqw2[:, 0], state_pqw2[:, 1], label='Final') ax.plot([0, sat_pqw1[0]], [0, sat_pqw1[1]], 'b.-', markersize=10) ax.set_title('Single Impulse Manuever') ax.set_xlabel(r'$\hat p$') ax.set_ylabel(r'$\hat q$') plt.legend() plt.show()
# 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') plt.show() with open('prob3_sol.txt', 'w') as f: f.write(output)
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]) ax.plot(sat_pqw[0], sat_pqw[1], 'bo', markersize=9) ax.plot(0, 0, 'ko', markersize=20) ax.set_title(sat.satname) ax.set_xlabel(r'$ \hat p (km)$') ax.set_ylabel(r'$ \hat q (km)$') plt.axis('equal') plt.grid() plt.savefig(str(sat.satnum) + '.pdf') ofile.close() answer_file.close()
print('V1 : {} km/sec'.format(va1)) print('DV1 : {} km/sec'.format(np.absolute(dva1))) print('TOF : {} sec = {} hr'.format(toft, toft / 3600)) print('\nPhasing Orbit') print('Period Phasing : {} sec'.format(phasing_period)) print('Phasing orbit : a = {} km, ecc = {}'.format(a_p, ecc_p)) print('\nTransfer from hohmann ellipse to phasing orbit') print('DV2 : {} km/sec'.format(dvb1)) print('\nTransfer from phasing orbit to final orbit') print('DV3 : {} km/sec'.format(dvb2)) # generate a plot of the orbit _, state_pqw1, _, _, sat_pqw1, _ = kepler.conic_orbit(np.absolute(p_h), ecc_h, 0, 0, 0, -np.deg2rad(10), np.deg2rad(10), mu) _, state_pqw2, _, _, sat_pqw2, _ = kepler.conic_orbit(p_t, ecc_t, 0, 0, 0, 0, 0, mu) _, state_pqw3, _, _, sat_pqw3, _ = kepler.conic_orbit(rb, 0, 0, 0, 0, 0, 0, mu) _, state_pqw4, _, _, sat_pqw4, _ = kepler.conic_orbit(p_p, ecc_p, 0, 0, 0, 0, 0, mu) # rotate new orbit fig, ax = plt.subplots() ax.plot(state_pqw1[:, 0], state_pqw1[:, 1], label='Initial') ax.plot(state_pqw2[:, 0], state_pqw2[:, 1], label='Transfer') ax.plot(state_pqw3[:, 0], state_pqw3[:, 1], label='Final') ax.plot(state_pqw4[:, 0], state_pqw4[:, 1], label='Phasing')
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) delta_arg_p = nuf - nun print('Orbital Elements after burn') kepler.orbit_el(pn, eccn, 0, 0, delta_arg_p, nun, mu, True) # generate a plot of the orbit _, state_pqw1, _, _, sat_pqw1, _ = kepler.conic_orbit(p, ecc, 0, 0, 0, nuf, nuf, mu) _, state_pqw2, _, _, sat_pqw2, _ = kepler.conic_orbit(pn, eccn, 0, 0, 0, nun, nun, mu) # rotate the second orbit by the change in argument of perigee rot_old2new = attitude.rot3(delta_arg_p) state_pqw2 = rot_old2new.dot(state_pqw2[:, 0:3].T).T sat_pqw2 = rot_old2new.dot(sat_pqw2[0:3]) fig, ax = plt.subplots() ax.plot(state_pqw1[:, 0], state_pqw1[:, 1], label='Initial') ax.plot(state_pqw2[:, 0], state_pqw2[:, 1], label='Final') ax.plot([0, sat_pqw2[0]], [0, sat_pqw2[1]], 'b.-', markersize=10) ax.set_title('Single Impulse Manuever') ax.set_xlabel(r'$\hat p$') ax.set_ylabel(r'$\hat q$')
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() ax = fig.add_subplot(111, projection='3d') ax.plot(state[:, 0] / rsaturn, state[:, 1] / rsaturn, state[:, 2] / rsaturn, 'b-') ax.set_title(r'Cassini Sep 15, 2004 to Sep 15, 2005')
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( tof, tof / 3600) fig, ax = plt.subplots() ax.plot(state_pqw[:, 0], state_pqw[:, 1])
# properties of new orbit rf, vf, fpaf = maneuver.single_impulse(np.linalg.norm(rpqw_i), np.linalg.norm(vpqw_i), fpa_i, mag_dv, alpha) nu_f = maneuver.nu_solve(rf, vf, fpaf, mu) print('V2 : {} km/sec'.format(vf)) print('FPAf : {} deg'.format(np.rad2deg(fpaf))) delta_arg_p = nu_i - nu_f print('Final orbit after maneuver') a_f, p_f, ecc_f, nu_f = maneuver.rvfpa2orbit_el(rf, vf, fpaf, mu) kepler.orbit_el(p_f, ecc_f, inc_i, raan_i, arg_p_i, nu_f, mu, 'True') # generate a plot of the orbit _, state_pqw1, _, _, sat_pqw1, _ = kepler.conic_orbit(p_i, ecc_i, 0, 0, 0, nu_i, nu_i, mu) _, state_pqw2, _, _, sat_pqw2, _ = kepler.conic_orbit(p_f, ecc_f, 0, 0, 0, nu_f, nu_f, mu) rot_old2new = attitude.rot3(delta_arg_p) state_pqw2 = rot_old2new.dot(state_pqw2[:, 0:3].T).T sat_pqw2 = rot_old2new.dot(sat_pqw2[0:3]) # rotate new orbit fig, ax = plt.subplots() ax.plot(state_pqw1[:, 0], state_pqw1[:, 1], label='Initial') ax.plot(state_pqw2[:, 0], state_pqw2[:, 1], label='Final') ax.plot([0, sat_pqw1[0]], [0, sat_pqw1[1]], 'b.', markersize=10) ax.set_title('Single Impulse - Maneuver at 90')
(dv_a, dv_b, tof, phase_angle) = maneuver.hohmann( a_e, a_n, ecc_e, ecc_n, 0, np.pi, mu) print('Initial Orbit Velocity : {} km/sec'.format(v_1)) print('Final Orbit Velocity : {} km/sec'.format(v_2)) print('Transfer SMA : {} km Eccentricity : {}'.format(a_t, ecc_t)) print('Transfer Periapsis velocity : {} km/sec'.format(vt_1)) print('Transfer Apoapsis velocity : {} km/sec'.format(vt_2)) print('Delta V1 : {} km/sec'.format(dv_a)) print('Delta V2 : {} km/sec'.format(dv_b)) print('TOF : {} sec = {} day = {} yr'.format(tof, tof/86400, tof/86400/365.25)) print('Phase : {} deg'.format(np.rad2deg(phase_angle))) # generate a plot of the orbit _, state_pqw1, _, _, sat_pqw1, _ = kepler.conic_orbit(a_e, 0, 0, 0, 0, 0, 0, mu) _, state_pqw2, _, _, sat_pqw2, _ = kepler.conic_orbit(a_n, 0, 0, 0, 0, np.pi, np.pi, mu) _, state_pqw3, _, _, sat_pqw3, _ = kepler.conic_orbit(p_t, ecc_t, 0, 0, 0, 0, np.pi, mu) fig, ax = plt.subplots() ax.plot(state_pqw1[:, 0], state_pqw1[:, 1], label='Earth') ax.plot(state_pqw2[:, 0], state_pqw2[:, 1], label='Neptune') ax.plot(state_pqw3[:, 0], state_pqw3[:, 1], label='Transfer') ax.set_title('Hohmann Transfer') ax.set_xlabel(r'$\hat p$') ax.set_ylabel(r'$\hat q$') plt.axis('equal') plt.legend() plt.show()
rp, = ax.plot(roadster_ecliptic[0], roadster_ecliptic[1], marker='o', color='r') mcp, = ax.plot(mercury_ecliptic[0], mercury_ecliptic[1], marker='o', color='c') vp, = ax.plot(venus_ecliptic[0], venus_ecliptic[1], marker='o', color='m') ep, = ax.plot(earth_ecliptic[0], earth_ecliptic[1], marker='o', color='g') mp, = ax.plot(mars_ecliptic[0], mars_ecliptic[1], marker='x', color='b') # draw conic orbits mercury_inertial, _, _, _, _, _ = kepler.conic_orbit(mercury_coe.p, mercury_coe.ecc, mercury_coe.inc, mercury_coe.raan, mercury_coe.argp, 0, 2 * np.pi, mu=constants.sun.mu) venus_inertial, _, _, _, _, _ = kepler.conic_orbit(venus_coe.p, venus_coe.ecc, venus_coe.inc, venus_coe.raan, venus_coe.argp, 0, 2 * np.pi, mu=constants.sun.mu) earth_inertial, _, _, _, _, _ = kepler.conic_orbit(earth_coe.p, earth_coe.ecc, earth_coe.inc, earth_coe.raan,
print('Alpha (angle from Vhat) : {} deg'.format(np.rad2deg(alpha))) r_initial = r_inertial v_initial = v_inertial r_final = r_initial v_final = dv_inertial+v_initial # find orbital elements of new orbit ( p_n,a_n,ecc_n,inc_n,raan_n,arg_p_n,nu_n,_,_,_,_) = kepler.rv2coe(r_final,v_final, mu) print('Final Orbit') kepler.orbit_el(p_n,ecc_n,inc_n,raan_n,arg_p_n,nu_n,mu,'True') # generate a plot of the orbit state_mci1, state_pqw1, _, sat_mci1, _, _ = kepler.conic_orbit(p, ecc, inc, raan, arg_p, nu, nu, mu) state_mci2, state_pqw2, _, sat_mci2,_, _ = kepler.conic_orbit(p_n, ecc_n, inc_n, raan_n, arg_p_n, nu_n, nu_n, mu) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot(state_mci1[:, 0],state_mci1[:, 1], state_mci1[:, 2], label='Initial') ax.plot(state_mci2[:, 0],state_mci2[:, 1], state_mci2[:, 2], label='Final') ax.plot([0, sat_mci1[0]], [0, sat_mci1[1]], [0, sat_mci1[2]], 'b.-', markersize=10) ax.scatter(0, 0, 0,s=1000) ax.set_title('Single Impulse Manuever') ax.set_xlabel(r'$\hat x$') ax.set_ylabel(r'$\hat y$') ax.set_zlabel(r'$\hat z$') plt.axis('equal') plt.legend()