Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add orbit namespace #658

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dynamics/orbit/encke_orbit_propagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ void EnckeOrbitPropagation::Initialize(double current_time_jd, math::Vector<3> r
// reference orbit
reference_position_i_m_ = reference_position_i_m;
reference_velocity_i_m_s_ = reference_velocity_i_m_s;
OrbitalElements oe_ref(gravity_constant_m3_s2_, current_time_jd, reference_position_i_m, reference_velocity_i_m_s);
reference_kepler_orbit = KeplerOrbit(gravity_constant_m3_s2_, oe_ref);
orbit::OrbitalElements oe_ref(gravity_constant_m3_s2_, current_time_jd, reference_position_i_m, reference_velocity_i_m_s);
reference_kepler_orbit = orbit::KeplerOrbit(gravity_constant_m3_s2_, oe_ref);

// difference orbit
difference_position_i_m_.FillUp(0.0);
Expand Down
2 changes: 1 addition & 1 deletion src/dynamics/orbit/encke_orbit_propagation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class EnckeOrbitPropagation : public Orbit, public math::OrdinaryDifferentialEqu
// reference orbit
math::Vector<3> reference_position_i_m_; //!< Reference orbit position in the inertial frame [m]
math::Vector<3> reference_velocity_i_m_s_; //!< Reference orbit velocity in the inertial frame [m/s]
KeplerOrbit reference_kepler_orbit; //!< Reference Kepler orbital element
orbit::KeplerOrbit reference_kepler_orbit; //!< Reference Kepler orbital element

// difference orbit
math::Vector<3> difference_position_i_m_; //!< Difference orbit position in the inertial frame [m]
Expand Down
16 changes: 8 additions & 8 deletions src/dynamics/orbit/initialize_orbit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ Orbit* InitOrbit(const CelestialInformation* celestial_information, std::string
// initialize orbit for relative dynamics of formation flying
RelativeOrbit::RelativeOrbitUpdateMethod update_method =
(RelativeOrbit::RelativeOrbitUpdateMethod)(conf.ReadInt(section_, "relative_orbit_update_method"));
RelativeOrbitModel relative_dynamics_model_type = (RelativeOrbitModel)(conf.ReadInt(section_, "relative_dynamics_model_type"));
StmModel stm_model_type = (StmModel)(conf.ReadInt(section_, "stm_model_type"));
orbit::RelativeOrbitModel relative_dynamics_model_type = (orbit::RelativeOrbitModel)(conf.ReadInt(section_, "relative_dynamics_model_type"));
orbit::StmModel stm_model_type = (orbit::StmModel)(conf.ReadInt(section_, "stm_model_type"));

math::Vector<3> init_relative_position_lvlh;
conf.ReadVector<3>(section_, "initial_relative_position_lvlh_m", init_relative_position_lvlh);
Expand All @@ -62,15 +62,15 @@ Orbit* InitOrbit(const CelestialInformation* celestial_information, std::string
init_relative_velocity_lvlh, update_method, relative_dynamics_model_type, stm_model_type, relative_information);
} else if (propagate_mode == "KEPLER") {
// initialize orbit for Kepler propagation
OrbitalElements oe;
orbit::OrbitalElements oe;
// TODO: init_mode_kepler should be removed in the next major update
if (initialize_mode == OrbitInitializeMode::kInertialPositionAndVelocity) {
// initialize with position and velocity
math::Vector<3> init_pos_m;
conf.ReadVector<3>(section_, "initial_position_i_m", init_pos_m);
math::Vector<3> init_vel_m_s;
conf.ReadVector<3>(section_, "initial_velocity_i_m_s", init_vel_m_s);
oe = OrbitalElements(gravity_constant_m3_s2, current_time_jd, init_pos_m, init_vel_m_s);
oe = orbit::OrbitalElements(gravity_constant_m3_s2, current_time_jd, init_pos_m, init_vel_m_s);
} else {
// initialize with orbital elements
double semi_major_axis_m = conf.ReadDouble(section_, "semi_major_axis_m");
Expand All @@ -79,9 +79,9 @@ Orbit* InitOrbit(const CelestialInformation* celestial_information, std::string
double raan_rad = conf.ReadDouble(section_, "raan_rad");
double arg_perigee_rad = conf.ReadDouble(section_, "argument_of_perigee_rad");
double epoch_jday = conf.ReadDouble(section_, "epoch_jday");
oe = OrbitalElements(epoch_jday, semi_major_axis_m, eccentricity, inclination_rad, raan_rad, arg_perigee_rad);
oe = orbit::OrbitalElements(epoch_jday, semi_major_axis_m, eccentricity, inclination_rad, raan_rad, arg_perigee_rad);
}
KeplerOrbit kepler_orbit(gravity_constant_m3_s2, oe);
orbit::KeplerOrbit kepler_orbit(gravity_constant_m3_s2, oe);
orbit = new KeplerOrbitPropagation(celestial_information, current_time_jd, kepler_orbit);
} else if (propagate_mode == "ENCKE") {
// initialize orbit for Encke's method
Expand Down Expand Up @@ -130,8 +130,8 @@ math::Vector<6> InitializePosVel(std::string initialize_file, double current_tim
double raan_rad = conf.ReadDouble(section_, "raan_rad");
double arg_perigee_rad = conf.ReadDouble(section_, "argument_of_perigee_rad");
double epoch_jday = conf.ReadDouble(section_, "epoch_jday");
OrbitalElements oe(epoch_jday, semi_major_axis_m, eccentricity, inclination_rad, raan_rad, arg_perigee_rad);
KeplerOrbit kepler_orbit(gravity_constant_m3_s2, oe);
orbit::OrbitalElements oe(epoch_jday, semi_major_axis_m, eccentricity, inclination_rad, raan_rad, arg_perigee_rad);
orbit::KeplerOrbit kepler_orbit(gravity_constant_m3_s2, oe);

kepler_orbit.CalcOrbit(current_time_jd);
position_i_m = kepler_orbit.GetPosition_i_m();
Expand Down
4 changes: 2 additions & 2 deletions src/dynamics/orbit/kepler_orbit_propagation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @class KeplerOrbitPropagation
* @brief Class to propagate spacecraft orbit with Kepler equation
*/
class KeplerOrbitPropagation : public Orbit, public KeplerOrbit {
class KeplerOrbitPropagation : public Orbit, public orbit::KeplerOrbit {
public:
// Initialize with orbital elements
/**
Expand All @@ -23,7 +23,7 @@ class KeplerOrbitPropagation : public Orbit, public KeplerOrbit {
* @param [in] current_time_jd: Current Julian day [day]
* @param [in] kepler_orbit: Kepler orbit
*/
KeplerOrbitPropagation(const CelestialInformation* celestial_information, const double current_time_jd, KeplerOrbit kepler_orbit);
KeplerOrbitPropagation(const CelestialInformation* celestial_information, const double current_time_jd, orbit::KeplerOrbit kepler_orbit);
/**
* @fn ~KeplerOrbitPropagation
* @brief Destructor
Expand Down
17 changes: 9 additions & 8 deletions src/dynamics/orbit/relative_orbit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

RelativeOrbit::RelativeOrbit(const CelestialInformation* celestial_information, double gravity_constant_m3_s2, double time_step_s,
int reference_spacecraft_id, math::Vector<3> relative_position_lvlh_m, math::Vector<3> relative_velocity_lvlh_m_s,
RelativeOrbitUpdateMethod update_method, RelativeOrbitModel relative_dynamics_model_type, StmModel stm_model_type,
RelativeInformation* relative_information)
RelativeOrbitUpdateMethod update_method, orbit::RelativeOrbitModel relative_dynamics_model_type,
orbit::StmModel stm_model_type, RelativeInformation* relative_information)
: Orbit(celestial_information),
math::OrdinaryDifferentialEquation<6>(time_step_s),
gravity_constant_m3_s2_(gravity_constant_m3_s2),
Expand Down Expand Up @@ -66,12 +66,12 @@ void RelativeOrbit::InitializeState(math::Vector<3> relative_position_lvlh_m, ma
TransformEcefToGeodetic();
}

void RelativeOrbit::CalculateSystemMatrix(RelativeOrbitModel relative_dynamics_model_type, const Orbit* reference_sat_orbit,
void RelativeOrbit::CalculateSystemMatrix(orbit::RelativeOrbitModel relative_dynamics_model_type, const Orbit* reference_sat_orbit,
double gravity_constant_m3_s2) {
switch (relative_dynamics_model_type) {
case RelativeOrbitModel::kHill: {
case orbit::RelativeOrbitModel::kHill: {
double reference_sat_orbit_radius = reference_sat_orbit->GetPosition_i_m().CalcNorm();
system_matrix_ = CalcHillSystemMatrix(reference_sat_orbit_radius, gravity_constant_m3_s2);
system_matrix_ = orbit::CalcHillSystemMatrix(reference_sat_orbit_radius, gravity_constant_m3_s2);
}
default: {
// NOT REACHED
Expand All @@ -80,11 +80,12 @@ void RelativeOrbit::CalculateSystemMatrix(RelativeOrbitModel relative_dynamics_m
}
}

void RelativeOrbit::CalculateStm(StmModel stm_model_type, const Orbit* reference_sat_orbit, double gravity_constant_m3_s2, double elapsed_sec) {
void RelativeOrbit::CalculateStm(orbit::StmModel stm_model_type, const Orbit* reference_sat_orbit, double gravity_constant_m3_s2,
double elapsed_sec) {
switch (stm_model_type) {
case StmModel::kHcw: {
case orbit::StmModel::kHcw: {
double reference_sat_orbit_radius = reference_sat_orbit->GetPosition_i_m().CalcNorm();
stm_ = CalcHcwStm(reference_sat_orbit_radius, gravity_constant_m3_s2, elapsed_sec);
stm_ = orbit::CalcHcwStm(reference_sat_orbit_radius, gravity_constant_m3_s2, elapsed_sec);
}
default: {
// NOT REACHED
Expand Down
14 changes: 7 additions & 7 deletions src/dynamics/orbit/relative_orbit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class RelativeOrbit : public Orbit, public math::OrdinaryDifferentialEquation<6>
*/
RelativeOrbit(const CelestialInformation* celestial_information, double gravity_constant_m3_s2, double time_step_s, int reference_spacecraft_id,
math::Vector<3> relative_position_lvlh_m, math::Vector<3> relative_velocity_lvlh_m_s, RelativeOrbitUpdateMethod update_method,
RelativeOrbitModel relative_dynamics_model_type, StmModel stm_model_type, RelativeInformation* relative_information);
orbit::RelativeOrbitModel relative_dynamics_model_type, orbit::StmModel stm_model_type, RelativeInformation* relative_information);
/**
* @fn ~RelativeOrbit
* @brief Destructor
Expand Down Expand Up @@ -80,10 +80,10 @@ class RelativeOrbit : public Orbit, public math::OrdinaryDifferentialEquation<6>
math::Vector<3> relative_position_lvlh_m_; //!< Relative position in the LVLH frame
math::Vector<3> relative_velocity_lvlh_m_s_; //!< Relative velocity in the LVLH frame

RelativeOrbitUpdateMethod update_method_; //!< Update method
RelativeOrbitModel relative_dynamics_model_type_; //!< Relative dynamics model type
StmModel stm_model_type_; //!< State Transition Matrix model type
RelativeInformation* relative_information_; //!< Relative information
RelativeOrbitUpdateMethod update_method_; //!< Update method
orbit::RelativeOrbitModel relative_dynamics_model_type_; //!< Relative dynamics model type
orbit::StmModel stm_model_type_; //!< State Transition Matrix model type
RelativeInformation* relative_information_; //!< Relative information

/**
* @fn InitializeState
Expand All @@ -102,7 +102,7 @@ class RelativeOrbit : public Orbit, public math::OrdinaryDifferentialEquation<6>
* @param [in] reference_sat_orbit: Orbit information of reference satellite
* @param [in] gravity_constant_m3_s2: Gravity constant of the center body [m3/s2]
*/
void CalculateSystemMatrix(RelativeOrbitModel relative_dynamics_model_type, const Orbit* reference_sat_orbit, double gravity_constant_m3_s2);
void CalculateSystemMatrix(orbit::RelativeOrbitModel relative_dynamics_model_type, const Orbit* reference_sat_orbit, double gravity_constant_m3_s2);
/**
* @fn CalculateStm
* @brief Calculate State Transition Matrix
Expand All @@ -111,7 +111,7 @@ class RelativeOrbit : public Orbit, public math::OrdinaryDifferentialEquation<6>
* @param [in] gravity_constant_m3_s2: Gravity constant of the center body [m3/s2]
* @param [in] elapsed_sec: Elapsed time [sec]
*/
void CalculateStm(StmModel stm_model_type, const Orbit* reference_sat_orbit, double gravity_constant_m3_s2, double elapsed_sec);
void CalculateStm(orbit::StmModel stm_model_type, const Orbit* reference_sat_orbit, double gravity_constant_m3_s2, double elapsed_sec);
/**
* @fn PropagateRk4
* @brief Propagate relative orbit with RK4
Expand Down
2 changes: 1 addition & 1 deletion src/environment/global/gnss_satellites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void GnssSatellites::Initialize(const std::vector<Sp3FileReader>& sp3_files, con
reference_time_ = EpochTime(initial_sp3_file.GetEpochData(reference_interpolation_id_));

// Initialize orbit
orbit_.assign(number_of_calculated_gnss_satellites_, InterpolationOrbit(kNumberOfInterpolation));
orbit_.assign(number_of_calculated_gnss_satellites_, orbit::InterpolationOrbit(kNumberOfInterpolation));

// Initialize clock
std::vector<double> temp;
Expand Down
4 changes: 2 additions & 2 deletions src/environment/global/gnss_satellites.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class GnssSatellites : public ILoggable {
size_t reference_interpolation_id_ = 0; //!< Reference epoch ID of the interpolation
EpochTime current_epoch_time_; //!< The last updated time

std::vector<InterpolationOrbit> orbit_; //!< GNSS satellite orbit with interpolation
std::vector<math::Interpolation> clock_; //!< GNSS satellite clock offset with interpolation
std::vector<orbit::InterpolationOrbit> orbit_; //!< GNSS satellite orbit with interpolation
std::vector<math::Interpolation> clock_; //!< GNSS satellite clock offset with interpolation

// References
const EarthRotation& earth_rotation_; //!< Earth rotation
Expand Down
16 changes: 8 additions & 8 deletions src/math_physics/numerical_integration/test_runge_kutta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ TEST(NUMERICAL_INTEGRATION, Integrate2dTwoBodyOrbitSmallEccentricity) {
initial_position[1] = initial_state[1];
initial_velocity[0] = initial_state[2];
initial_velocity[1] = initial_state[3];
OrbitalElements oe(1.0, 0.0, initial_position, initial_velocity);
KeplerOrbit kepler(1.0, oe);
orbit::OrbitalElements oe(1.0, 0.0, initial_position, initial_velocity);
orbit::KeplerOrbit kepler(1.0, oe);
kepler.CalcOrbit((double)(step_num * step_width_s) / (24.0 * 60.0 * 60.0));

double error_tolerance = 2e-4;
Expand Down Expand Up @@ -486,8 +486,8 @@ TEST(NUMERICAL_INTEGRATION, Integrate2dTwoBodyOrbitLargeEccentricity) {
initial_position[1] = initial_state[1];
initial_velocity[0] = initial_state[2];
initial_velocity[1] = initial_state[3];
OrbitalElements oe(1.0, 0.0, initial_position, initial_velocity);
KeplerOrbit kepler(1.0, oe);
orbit::OrbitalElements oe(1.0, 0.0, initial_position, initial_velocity);
orbit::KeplerOrbit kepler(1.0, oe);
kepler.CalcOrbit((double)(step_num * step_width_s) / (24.0 * 60.0 * 60.0));

double error_tolerance = 2e-1;
Expand Down Expand Up @@ -551,8 +551,8 @@ TEST(NUMERICAL_INTEGRATION, Interpolation2dTwoBodyOrbitSmallEccentricity) {
initial_position[1] = initial_state[1];
initial_velocity[0] = initial_state[2];
initial_velocity[1] = initial_state[3];
OrbitalElements oe(1.0, 0.0, initial_position, initial_velocity);
KeplerOrbit kepler(1.0, oe);
orbit::OrbitalElements oe(1.0, 0.0, initial_position, initial_velocity);
orbit::KeplerOrbit kepler(1.0, oe);
kepler.CalcOrbit((double)(step_num * step_width_s) / (24.0 * 60.0 * 60.0));

double error_tolerance = 5e-2;
Expand Down Expand Up @@ -646,8 +646,8 @@ TEST(NUMERICAL_INTEGRATION, Interpolation2dTwoBodyOrbitLargeEccentricity) {
initial_position[1] = initial_state[1];
initial_velocity[0] = initial_state[2];
initial_velocity[1] = initial_state[3];
OrbitalElements oe(1.0, 0.0, initial_position, initial_velocity);
KeplerOrbit kepler(1.0, oe);
orbit::OrbitalElements oe(1.0, 0.0, initial_position, initial_velocity);
orbit::KeplerOrbit kepler(1.0, oe);
kepler.CalcOrbit((double)(step_num * step_width_s) / (24.0 * 60.0 * 60.0));

double error_tolerance = 1e-5;
Expand Down
4 changes: 4 additions & 0 deletions src/math_physics/orbit/interpolation_orbit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "interpolation_orbit.hpp"

namespace orbit {

InterpolationOrbit::InterpolationOrbit(const size_t degree) {
std::vector<double> time;
time.assign(degree, -1.0);
Expand Down Expand Up @@ -34,3 +36,5 @@ math::Vector<3> InterpolationOrbit::CalcPositionWithTrigonometric(const double t
}
return output_position;
}

} // namespace orbit
4 changes: 4 additions & 0 deletions src/math_physics/orbit/interpolation_orbit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <math_physics/math/vector.hpp>
#include <vector>

namespace orbit {

/**
* @class InterpolationOrbit
* @brief Orbit calculation with mathematical interpolation
Expand Down Expand Up @@ -69,4 +71,6 @@ class InterpolationOrbit {
std::vector<math::Interpolation> interpolation_position_; // 3D vector of interpolation
};

} // namespace orbit

#endif // S2E_LIBRARY_ORBIT_INTERPOLATION_ORBIT_HPP_
4 changes: 4 additions & 0 deletions src/math_physics/orbit/kepler_orbit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "../math/matrix_vector.hpp"
#include "../math/s2e_math.hpp"

namespace orbit {

KeplerOrbit::KeplerOrbit() {}
// Initialize with orbital elements
KeplerOrbit::KeplerOrbit(const double gravity_constant_m3_s2, const OrbitalElements oe) : gravity_constant_m3_s2_(gravity_constant_m3_s2), oe_(oe) {
Expand Down Expand Up @@ -97,3 +99,5 @@ double KeplerOrbit::SolveKeplerNewtonMethod(const double eccentricity, const dou
}
return u_rad;
}

} // namespace orbit
4 changes: 4 additions & 0 deletions src/math_physics/orbit/kepler_orbit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "../math/vector.hpp"
#include "./orbital_elements.hpp"

namespace orbit {

/**
* @class KeplerOrbit
* @brief Class to calculate Kepler orbit calculation
Expand Down Expand Up @@ -87,4 +89,6 @@ class KeplerOrbit {
double SolveKeplerNewtonMethod(const double eccentricity, const double mean_anomaly_rad, const double angle_limit_rad, const int iteration_limit);
};

} // namespace orbit

#endif // S2E_LIBRARY_ORBIT_KEPLER_ORBIT_HPP_
4 changes: 4 additions & 0 deletions src/math_physics/orbit/orbital_elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include "../math/s2e_math.hpp"

namespace orbit {

OrbitalElements::OrbitalElements() {}

// initialize with OE
Expand Down Expand Up @@ -85,3 +87,5 @@ void OrbitalElements::CalcOeFromPosVel(const double gravity_constant_m3_s2, cons
double dt_s = (u_rad - eccentricity_ * sin(u_rad)) / n_rad_s;
epoch_jday_ = time_jday - dt_s / (24.0 * 60.0 * 60.0);
}

} // namespace orbit
4 changes: 4 additions & 0 deletions src/math_physics/orbit/orbital_elements.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "../math/vector.hpp"

namespace orbit {

/**
* @class OrbitalElements
* @brief Class for classical orbital elements
Expand Down Expand Up @@ -104,4 +106,6 @@ class OrbitalElements {
const math::Vector<3> velocity_i_m_s);
};

} // namespace orbit

#endif // S2E_LIBRARY_ORBIT_ORBITAL_ELEMENTS_HPP_
4 changes: 4 additions & 0 deletions src/math_physics/orbit/relative_orbit_models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
#include "relative_orbit_models.hpp"

namespace orbit {

math::Matrix<6, 6> CalcHillSystemMatrix(double orbit_radius_m, double gravity_constant_m3_s2) {
math::Matrix<6, 6> system_matrix;

Expand Down Expand Up @@ -91,3 +93,5 @@ math::Matrix<6, 6> CalcHcwStm(double orbit_radius_m, double gravity_constant_m3_
stm[5][5] = cos(n * t);
return stm;
}

} // namespace orbit
4 changes: 4 additions & 0 deletions src/math_physics/orbit/relative_orbit_models.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "../math/matrix.hpp"
#include "../math/vector.hpp"

namespace orbit {

/**
* @enum RelativeOrbitModel
* @brief Relative orbit model
Expand Down Expand Up @@ -42,4 +44,6 @@ math::Matrix<6, 6> CalcHillSystemMatrix(const double orbit_radius_m, const doubl
*/
math::Matrix<6, 6> CalcHcwStm(const double orbit_radius_m, const double gravity_constant_m3_s2, const double elapsed_time_s);

} // namespace orbit

#endif // S2E_LIBRARY_ORBIT_RELATIVE_ORBIT_MODEL_HPP_
2 changes: 2 additions & 0 deletions src/math_physics/orbit/test_interpolation_orbit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "interpolation_orbit.hpp"

using namespace orbit;

/**
* @brief Test for Constructor function
*/
Expand Down
Loading