Browse Source

add circularize impulse types

main
cinnaboot 4 years ago
parent
commit
986574a73a
  1. 25
      src/game.cpp
  2. 4
      src/game.h
  3. 19
      src/main.cpp
  4. 11
      src/orbits.cpp
  5. 4
      src/orbits.h

25
src/game.cpp

@ -139,7 +139,6 @@ getFreeManeuver(GameState* gs)
return nullptr; return nullptr;
} }
// TODO: appendManeuver(orbit, node) would be better
bool bool
addManeuver(GameState* gs, addManeuver(GameState* gs,
GameOrbit* orbit, GameOrbit* orbit,
@ -152,7 +151,10 @@ addManeuver(GameState* gs,
return false; return false;
} }
if (impulse_delta_v == 0.f) { if (impulse_type != ImpulseType::CIRCULARIZE_RAISING
&& impulse_type != ImpulseType::CIRCULARIZE_LOWERING
&& impulse_delta_v == 0.f)
{
LOGF(Warning, "refusing to add maneuver with 0 dv\n"); LOGF(Warning, "refusing to add maneuver with 0 dv\n");
return false; return false;
} }
@ -172,9 +174,12 @@ addManeuver(GameState* gs,
node->impulse_type = impulse_type; node->impulse_type = impulse_type;
// TODO: thrust calculations // TODO: thrust calculations
//double flight_path_angle = orbit->system.sat.gamma; //double flight_path_angle = orbit->system.sat.gamma;
//node.impulse_vector.x = ... //node->impulse_vector.x = ...
if (node->impulse_type == ImpulseType::PROGRADE) { if (node->impulse_type == ImpulseType::PROGRADE
|| node->impulse_type == ImpulseType::CIRCULARIZE_RAISING
|| node->impulse_type == ImpulseType::CIRCULARIZE_LOWERING)
{
node->true_anomaly = true_anomaly; node->true_anomaly = true_anomaly;
node->impulse_delta_v = impulse_delta_v; node->impulse_delta_v = impulse_delta_v;
node->active = true; node->active = true;
@ -222,8 +227,16 @@ applyManeuver(GameOrbit* orbit, ManeuverNode* maneuver)
TwoBodySystem& sys = orbit->system; TwoBodySystem& sys = orbit->system;
assert(maneuver); assert(maneuver);
// FIXME: assuming prograde impulse vector // TODO: other impulse types
assert(maneuver->impulse_type == ImpulseType::PROGRADE); assert(maneuver->impulse_type == ImpulseType::PROGRADE
|| maneuver->impulse_type != ImpulseType::CIRCULARIZE_RAISING
|| maneuver->impulse_type != ImpulseType::CIRCULARIZE_LOWERING);
if (maneuver->impulse_type == ImpulseType::CIRCULARIZE_RAISING) {
maneuver->impulse_delta_v = orbitGetCircVelocity(orbit->system);
} else if (maneuver->impulse_type == ImpulseType::CIRCULARIZE_LOWERING) {
maneuver->impulse_delta_v = orbitGetCircVelocity(orbit->system, false);
}
// re-calculate state vectors at the maneuver node // re-calculate state vectors at the maneuver node
double theta = maneuver->true_anomaly; double theta = maneuver->true_anomaly;

4
src/game.h

@ -27,6 +27,8 @@ enum struct ImpulseType
NONE, NONE,
PROGRADE, PROGRADE,
RETROGRADE, RETROGRADE,
CIRCULARIZE_RAISING,
CIRCULARIZE_LOWERING,
INCLINATION_CHANGE, INCLINATION_CHANGE,
GENERAL_PLANE_CHANGE, GENERAL_PLANE_CHANGE,
OTHER, OTHER,
@ -96,7 +98,7 @@ bool addManeuver(GameState* gs,
GameOrbit* orbit, GameOrbit* orbit,
ImpulseType impulse_type, ImpulseType impulse_type,
double true_anomaly, double true_anomaly,
double impulse_delta_v); double impulse_delta_v = 0.f);
bool testManeuverStep(ManeuverNode* maneuver, bool testManeuverStep(ManeuverNode* maneuver,
double previous_theta, double previous_theta,

19
src/main.cpp

@ -251,19 +251,22 @@ loadScene(GameState* gs, RenderState* rs)
gs->coord_overlay = addCoordinateOverlay(rs); gs->coord_overlay = addCoordinateOverlay(rs);
OrbitalElements el1 = orbitInit(8000, 0, 0, 0, 0, DEG2RAD(-90)); OrbitalElements el1 = orbitInit(8000, 0, 0, 0, 0, DEG2RAD(-90));
GameOrbit* go_1 = loadOrbit(gs, rs, body, el1, rg, "sat_01"); loadOrbit(gs, rs, body, el1, rg, "sat_01");
//GameOrbit* go_1 = loadOrbit(gs, rs, body, el1, rg, "sat_01");
OrbitalElements el2 = orbitInit(20000, 0, 0, 0, 0, 0); OrbitalElements el2 = orbitInit(20000, 0, 0, 0, 0, 0);
loadOrbit(gs, rs, body, el2, rg, "sat_02"); //loadOrbit(gs, rs, body, el2, rg, "sat_02");
//GameOrbit* go_2 = loadOrbit(gs, rs, body, el2, rg, "sat_02"); GameOrbit* go_2 = loadOrbit(gs, rs, body, el2, rg, "sat_02");
#if 0
double v_transfer = orbitGetTransferVelocity(go_1->system, el2); double v_transfer = orbitGetTransferVelocity(go_1->system, el2);
addManeuver(gs, go_1, ImpulseType::PROGRADE, DEG2RAD(180), v_transfer); addManeuver(gs, go_1, ImpulseType::PROGRADE, DEG2RAD(180), v_transfer);
// FIXME: can't get circularization here unless we simulate the transfer addManeuver(gs, go_1, ImpulseType::CIRCULARIZE_RAISING, DEG2RAD(180));
// orbit ahead of time, eg) applyManeuver to a dummy orbit #else
// could also add a ImpulseType::CIRCULARIZE and calculate in double v_transfer = orbitGetTransferVelocity(go_2->system, el1);
// applyManeuver() addManeuver(gs, go_2, ImpulseType::PROGRADE, DEG2RAD(180), v_transfer);
addManeuver(gs, go_1, ImpulseType::PROGRADE, DEG2RAD(180), 0.500); addManeuver(gs, go_2, ImpulseType::CIRCULARIZE_LOWERING, DEG2RAD(0));
#endif
return true; return true;
} }

11
src/orbits.cpp

@ -343,6 +343,17 @@ orbitGetTransferVelocity(const TwoBodySystem& sys,
return vt - v1; return vt - v1;
} }
double
orbitGetCircVelocity(const TwoBodySystem& sys, bool raise_apoapse)
{
double r = (raise_apoapse) ? sys.r_apoapsis : sys.r_periapsis;
double mu = sys.body.mu;
double epsilon_target = orbitGetSpecificEnergy(r, mu);
double v = orbitGetVelocity(epsilon_target, mu, r);
return v - sys.sat.v;
}
// internal // internal

4
src/orbits.h

@ -258,3 +258,7 @@ orbitGetTimeOfFlight(TwoBodySystem sys, double theta_begin, double theta_end);
// NOTE return impulse magnitute for Hohmann transfer orbit // NOTE return impulse magnitute for Hohmann transfer orbit
double orbitGetTransferVelocity(const TwoBodySystem& sys, double orbitGetTransferVelocity(const TwoBodySystem& sys,
const OrbitalElements& target); const OrbitalElements& target);
// NOTE: return impulse magnitude for orbit circularization
double
orbitGetCircVelocity(const TwoBodySystem& sys, bool raise_apoapse = true);

Loading…
Cancel
Save