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

Refactor dynamics #332

Merged
merged 63 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
e122460
clean include files
200km Feb 23, 2023
2161a67
Fix function argument names
200km Feb 23, 2023
ecdea90
Move to inline functions
200km Feb 23, 2023
3c64e4b
Remove unnecesarry Get function
200km Feb 23, 2023
1a8d1b6
Move to inline functions
200km Feb 23, 2023
453c1db
Rename public functions
200km Feb 23, 2023
5aae154
Remove TODO
200km Feb 23, 2023
da88fdd
Fix TODO
200km Feb 23, 2023
610cbe9
Integrate private functions
200km Feb 23, 2023
6a4e817
Fix function arguments
200km Feb 23, 2023
b2c7c47
Remove unnecessary public functions
200km Feb 23, 2023
b9843d1
Fix private variables
200km Feb 23, 2023
40dc740
Fix private functions
200km Feb 23, 2023
1b9e32e
Fix function argument
200km Feb 23, 2023
9800bf0
Remove unused public functions
200km Feb 23, 2023
a290f83
Rename AttitudeRK4 to AttitudeRk4
200km Feb 23, 2023
308ebf2
Fix private variables and function argument names
200km Feb 23, 2023
710935a
Fix public function
200km Feb 23, 2023
f306995
Fix local function variables
200km Feb 23, 2023
7981b25
Fix enum name
200km Feb 23, 2023
c60dba9
Fix local function internal variable name
200km Feb 23, 2023
a1d70e5
Fix function arguments
200km Feb 23, 2023
ffcedb3
Remove using
200km Feb 23, 2023
2289076
Fix private variable names
200km Feb 23, 2023
bc655ea
Fix private variable names
200km Feb 23, 2023
295c54f
Fix private function name
200km Feb 23, 2023
d0d53c0
Fix function argument names
200km Feb 23, 2023
497cccd
Delete unused public functions
200km Feb 23, 2023
44464d6
Fix local function variables
200km Feb 23, 2023
18ff49d
Fix public function name
200km Feb 23, 2023
12e51ca
Add const
200km Feb 23, 2023
ed94b1d
Add libra::
200km Feb 23, 2023
8719723
Fix private variables
200km Feb 23, 2023
d47e194
Fix function argument
200km Feb 23, 2023
3d16742
Fix function argument names
200km Feb 23, 2023
eb4725d
Fix private variables
200km Feb 23, 2023
c1a51f6
Add libra::
200km Feb 23, 2023
88703ef
Fix private function names
200km Feb 23, 2023
f3e7ec3
Fix unnecessary private variables
200km Feb 23, 2023
e56bd09
Remove unused public functions
200km Feb 23, 2023
4cd96db
Fix function argument name
200km Feb 23, 2023
d9f8a88
Fix function argument name
200km Feb 23, 2023
9aa77e1
Remove using
200km Feb 23, 2023
80599a6
Remove unused public function
200km Feb 23, 2023
28c4ed9
Fix private variables
200km Feb 23, 2023
e0df5a6
Add const
200km Feb 23, 2023
f9e67f4
Fix function argument names
200km Feb 23, 2023
e263a6c
Fix local function variables
200km Feb 23, 2023
0b84bed
Merge branch 'feature/refactor-environment' into feature/refactor-dyn…
200km Feb 23, 2023
abc8d3a
Merge branch 'feature/refactor-environment' into feature/refactor-dyn…
200km Feb 24, 2023
9fd6b32
Merge branch 'feature/refactor-environment' into feature/refactor-dyn…
200km Feb 24, 2023
f19e74f
Add libra::
200km Feb 24, 2023
4462329
Merge branch 'feature/refactor-environment' into feature/refactor-dyn…
200km Feb 24, 2023
8a45282
Add libra::
200km Feb 24, 2023
e8835fa
Add libra::
200km Feb 24, 2023
3144074
Add libra::
200km Feb 24, 2023
ce47dfa
Merge branch 'feature/major-update-v6.0.0' into feature/refactor-dyna…
200km Feb 25, 2023
5272a42
Fix MACRO to const value
200km Feb 25, 2023
ffa9b6f
Fix mu to gravity constant
200km Feb 25, 2023
9a4a702
Fix mu to gravity constant
200km Feb 25, 2023
f4d584e
Fix mu to gravity constant
200km Feb 25, 2023
edd7ba5
Fix format
200km Feb 25, 2023
ca62654
Merge
200km Feb 25, 2023
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/components/ideal/force_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void ForceGenerator::MainRoutine(int count) {

// Convert frame
libra::Quaternion q_i2b = dynamics_->GetAttitude().GetQuaternion_i2b();
libra::Quaternion q_i2rtn = dynamics_->GetOrbit().CalcQuaternionI2LVLH();
libra::Quaternion q_i2rtn = dynamics_->GetOrbit().CalcQuaternion_i2lvlh();
generated_force_i_N_ = q_i2b.frame_conv_inv(generated_force_b_N_);
generated_force_rtn_N_ = q_i2rtn.frame_conv(generated_force_i_N_);
}
Expand All @@ -55,7 +55,7 @@ void ForceGenerator::SetForce_i_N(const libra::Vector<3> force_i_N) {

void ForceGenerator::SetForce_rtn_N(const libra::Vector<3> force_rtn_N) {
libra::Quaternion q_i2b = dynamics_->GetAttitude().GetQuaternion_i2b();
libra::Quaternion q_i2rtn = dynamics_->GetOrbit().CalcQuaternionI2LVLH();
libra::Quaternion q_i2rtn = dynamics_->GetOrbit().CalcQuaternion_i2lvlh();

libra::Vector<3> force_i_N = q_i2rtn.frame_conv_inv(force_rtn_N);
ordered_force_b_N_ = q_i2b.frame_conv(force_i_N);
Expand Down
8 changes: 4 additions & 4 deletions src/components/real/aocs/gnss_receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ GNSSReceiver::GNSSReceiver(const int prescaler, ClockGenerator* clock_gen, Power
void GNSSReceiver::MainRoutine(int count) {
UNUSED(count);

Vector<3> pos_true_eci_ = dynamics_->GetOrbit().GetSatPosition_i();
Quaternion q_i2b = dynamics_->GetQuaternion_i2b();
Vector<3> pos_true_eci_ = dynamics_->GetOrbit().GetPosition_i_m();
Quaternion q_i2b = dynamics_->GetAttitude().GetQuaternion_i2b();

CheckAntenna(pos_true_eci_, q_i2b);

if (is_gnss_sats_visible_ == 1) { // Antenna of GNSS-R can detect GNSS signal
position_ecef_ = dynamics_->GetOrbit().GetSatPosition_ecef();
position_ecef_ = dynamics_->GetOrbit().GetPosition_ecef_m();
position_llh_ = dynamics_->GetOrbit().GetLatLonAlt();
velocity_ecef_ = dynamics_->GetOrbit().GetSatVelocity_ecef();
velocity_ecef_ = dynamics_->GetOrbit().GetVelocity_ecef_m_s();
AddNoise(pos_true_eci_, position_ecef_);

utc_ = simtime_->GetCurrentUtc();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ double GScalculator::CalcCn0OnGs(const Dynamics& dynamics, const Antenna& sc_tx_
}

// Free space path loss
Vector<3> sc_pos_i = dynamics.GetOrbit().GetSatPosition_i();
Vector<3> sc_pos_i = dynamics.GetOrbit().GetPosition_i_m();
Vector<3> gs_pos_i = ground_station.GetGSPosition_i();
double dist_sc_gs_km = norm(sc_pos_i - gs_pos_i) / 1000.0;
double loss_space_dB = -20.0 * log10(4.0 * libra::pi * dist_sc_gs_km / (300.0 / sc_tx_ant.GetFrequency() / 1000.0));
Expand All @@ -79,7 +79,7 @@ double GScalculator::CalcCn0OnGs(const Dynamics& dynamics, const Antenna& sc_tx_
double phi_on_sc_ant_rad = acos(gs_direction_on_sc_frame[0] / sin(theta_on_sc_ant_rad));

// SC direction on GS RX antenna frame
Vector<3> gs_to_sc_ecef = dynamics.GetOrbit().GetSatPosition_ecef() - ground_station.GetGSPosition_ecef();
Vector<3> gs_to_sc_ecef = dynamics.GetOrbit().GetPosition_ecef_m() - ground_station.GetGSPosition_ecef();
gs_to_sc_ecef = libra::normalize(gs_to_sc_ecef);
Quaternion q_ecef_to_gs_ant = gs_rx_ant.GetQuaternion_b2c() * ground_station.GetGSPosition_geo().GetQuaternionXcxfToLtc();
Vector<3> sc_direction_on_gs_frame = q_ecef_to_gs_ant.frame_conv(gs_to_sc_ecef);
Expand Down
2 changes: 1 addition & 1 deletion src/disturbances/air_drag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ AirDrag::AirDrag(const vector<Surface>& surfaces, const libra::Vector<3>& center

void AirDrag::Update(const LocalEnvironment& local_environment, const Dynamics& dynamics) {
double air_density_kg_m3 = local_environment.GetAtmosphere().GetAirDensity_kg_m3();
Vector<3> velocity_b_m_s = dynamics.GetOrbit().GetSatVelocity_b();
Vector<3> velocity_b_m_s = dynamics.GetOrbit().GetVelocity_b_m_s();
CalcTorqueForce(velocity_b_m_s, air_density_kg_m3);
}

Expand Down
4 changes: 2 additions & 2 deletions src/disturbances/geopotential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ void GeoPotential::Update(const LocalEnvironment &local_environment, const Dynam
#ifdef DEBUG_GEOPOTENTIAL
chrono::system_clock::time_point start, end;
start = chrono::system_clock::now();
debug_pos_ecef_m_ = spacecraft.dynamics_->orbit_->GetSatPosition_ecef();
debug_pos_ecef_m_ = spacecraft.dynamics_->orbit_->GetPosition_ecef_m();
#endif

CalcAccelerationEcef(dynamics.GetOrbit().GetSatPosition_ecef());
CalcAccelerationEcef(dynamics.GetOrbit().GetPosition_ecef_m());
#ifdef DEBUG_GEOPOTENTIAL
end = chrono::system_clock::now();
time_ms_ = static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0);
Expand Down
6 changes: 3 additions & 3 deletions src/disturbances/gravity_gradient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
GravityGradient::GravityGradient(const bool is_calculation_enabled)
: GravityGradient(environment::earth_gravitational_constant_m3_s2, is_calculation_enabled) {}

GravityGradient::GravityGradient(const double mu_m3_s2, const bool is_calculation_enabled)
: SimpleDisturbance(is_calculation_enabled), mu_m3_s2_(mu_m3_s2) {}
GravityGradient::GravityGradient(const double gravity_constant_m3_s2, const bool is_calculation_enabled)
: SimpleDisturbance(is_calculation_enabled), gravity_constant_m3_s2_(gravity_constant_m3_s2) {}

void GravityGradient::Update(const LocalEnvironment& local_environment, const Dynamics& dynamics) {
// TODO: use structure information to get inertia tensor
Expand All @@ -27,7 +27,7 @@ libra::Vector<3> GravityGradient::CalcTorque_b_Nm(const libra::Vector<3> earth_p
libra::Vector<3> u_b = earth_position_from_sc_b_m; // TODO: make undestructive normalize function for Vector
u_b /= r_norm_m;

double coeff = 3.0 * mu_m3_s2_ / pow(r_norm_m, 3.0);
double coeff = 3.0 * gravity_constant_m3_s2_ / pow(r_norm_m, 3.0);
torque_b_Nm_ = coeff * outer_product(u_b, inertia_tensor_b_kgm2 * u_b);
return torque_b_Nm_;
}
Expand Down
6 changes: 3 additions & 3 deletions src/disturbances/gravity_gradient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class GravityGradient : public SimpleDisturbance {
/**
* @fn GeoPotential
* @brief Constructor
* @param [in] mu_m3_s2: Gravitational constant [m3/s2]
* @param [in] gravity_constant_m3_s2: Gravitational constant [m3/s2]
* @param [in] is_calculation_enabled: Calculation flag
*/
GravityGradient(const double mu_m3_s2, const bool is_calculation_enabled = true);
GravityGradient(const double gravity_constant_m3_s2, const bool is_calculation_enabled = true);

/**
* @fn Update
Expand All @@ -56,7 +56,7 @@ class GravityGradient : public SimpleDisturbance {
virtual std::string GetLogValue() const;

private:
double mu_m3_s2_; //!< Gravitational constant [m3/s2]
double gravity_constant_m3_s2_; //!< Gravitational constant [m3/s2]

/**
* @fn CalcTorque
Expand Down
4 changes: 2 additions & 2 deletions src/disturbances/initialize_disturbances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ GravityGradient InitGravityGradient(const std::string initialize_file_path) {
return gg_disturbance;
}

GravityGradient InitGravityGradient(const std::string initialize_file_path, const double mu_m3_s2) {
GravityGradient InitGravityGradient(const std::string initialize_file_path, const double gravity_constant_m3_s2) {
auto conf = IniAccess(initialize_file_path);
const char* section = "GRAVITY_GRADIENT";

const bool is_calc_enable = conf.ReadEnable(section, CALC_LABEL);
GravityGradient gg_disturbance(mu_m3_s2, is_calc_enable);
GravityGradient gg_disturbance(gravity_constant_m3_s2, is_calc_enable);
gg_disturbance.IsLogEnabled = conf.ReadEnable(section, LOG_LABEL);

return gg_disturbance;
Expand Down
4 changes: 2 additions & 2 deletions src/disturbances/initialize_disturbances.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ GravityGradient InitGravityGradient(const std::string initialize_file_path);
* @fn InitGravityGradient
* @brief Initialize GravityGradient class with earth gravitational constant
* @param [in] initialize_file_path: Initialize file path
* @param [in] mu_m3_s2: Gravitational constant [m3/s2]
* @param [in] gravity_constant_m3_s2: Gravitational constant [m3/s2]
*/
GravityGradient InitGravityGradient(const std::string initialize_file_path, const double mu_m3_s2);
GravityGradient InitGravityGradient(const std::string initialize_file_path, const double gravity_constant_m3_s2);

/**
* @fn InitMagneticDisturbance
Expand Down
2 changes: 1 addition & 1 deletion src/disturbances/third_body_gravity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ThirdBodyGravity::~ThirdBodyGravity() {}
void ThirdBodyGravity::Update(const LocalEnvironment& local_environment, const Dynamics& dynamics) {
acceleration_i_m_s2_ = libra::Vector<3>(0.0); // initialize

libra::Vector<3> sc_position_i_m = dynamics.GetOrbit().GetSatPosition_i();
libra::Vector<3> sc_position_i_m = dynamics.GetOrbit().GetPosition_i_m();
for (auto third_body : third_body_list_) {
libra::Vector<3> third_body_position_from_sc_i_m = local_environment.GetCelestialInformation().GetPositionFromSpacecraft_i_m(third_body.c_str());
libra::Vector<3> third_body_pos_i_m = sc_position_i_m + third_body_position_from_sc_i_m;
Expand Down
40 changes: 20 additions & 20 deletions src/dynamics/attitude/attitude.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

#include <library/logger/log_utility.hpp>

Attitude::Attitude(const std::string& sim_object_name) : SimulationObject(sim_object_name) {
omega_b_rad_s_ = libra::Vector<3>(0.0);
Attitude::Attitude(const std::string& simulation_object_name) : SimulationObject(simulation_object_name) {
angular_velocity_b_rad_s_ = libra::Vector<3>(0.0);
quaternion_i2b_ = libra::Quaternion(0.0, 0.0, 0.0, 1.0);
torque_b_Nm_ = libra::Vector<3>(0.0);
h_sc_b_Nms_ = libra::Vector<3>(0.0);
h_rw_b_Nms_ = libra::Vector<3>(0.0);
h_total_b_Nms_ = libra::Vector<3>(0.0);
h_total_i_Nms_ = libra::Vector<3>(0.0);
h_total_Nms_ = 0.0;
k_sc_J_ = 0.0;
angular_momentum_spacecraft_b_Nms_ = libra::Vector<3>(0.0);
angular_momentum_reaction_wheel_b_Nms_ = libra::Vector<3>(0.0);
angular_momentum_total_b_Nms_ = libra::Vector<3>(0.0);
angular_momentum_total_i_Nms_ = libra::Vector<3>(0.0);
angular_momentum_total_Nms_ = 0.0;
kinetic_energy_J_ = 0.0;
}

std::string Attitude::GetLogHeader() const {
Expand All @@ -33,23 +33,23 @@ std::string Attitude::GetLogHeader() const {
std::string Attitude::GetLogValue() const {
std::string str_tmp = "";

str_tmp += WriteVector(omega_b_rad_s_);
str_tmp += WriteVector(angular_velocity_b_rad_s_);
str_tmp += WriteQuaternion(quaternion_i2b_);
str_tmp += WriteVector(torque_b_Nm_);
str_tmp += WriteScalar(h_total_Nms_);
str_tmp += WriteScalar(k_sc_J_);
str_tmp += WriteScalar(angular_momentum_total_Nms_);
str_tmp += WriteScalar(kinetic_energy_J_);

return str_tmp;
}

void Attitude::SetParameters(const MCSimExecutor& mc_sim) { GetInitParameterQuaternion(mc_sim, "Q_i2b", quaternion_i2b_); }
void Attitude::SetParameters(const MCSimExecutor& mc_simulator) { GetInitParameterQuaternion(mc_simulator, "Q_i2b", quaternion_i2b_); }

void Attitude::CalcAngMom(void) {
h_sc_b_Nms_ = inertia_tensor_kgm2_ * omega_b_rad_s_;
h_total_b_Nms_ = h_rw_b_Nms_ + h_sc_b_Nms_;
Quaternion q_b2i = quaternion_i2b_.conjugate();
h_total_i_Nms_ = q_b2i.frame_conv(h_total_b_Nms_);
h_total_Nms_ = norm(h_total_i_Nms_);
}
void Attitude::CalcAngularMomentum(void) {
angular_momentum_spacecraft_b_Nms_ = inertia_tensor_kgm2_ * angular_velocity_b_rad_s_;
angular_momentum_total_b_Nms_ = angular_momentum_reaction_wheel_b_Nms_ + angular_momentum_spacecraft_b_Nms_;
libra::Quaternion q_b2i = quaternion_i2b_.conjugate();
angular_momentum_total_i_Nms_ = q_b2i.frame_conv(angular_momentum_total_b_Nms_);
angular_momentum_total_Nms_ = norm(angular_momentum_total_i_Nms_);

void Attitude::CalcSatRotationalKineticEnergy(void) { k_sc_J_ = 0.5 * libra::inner_product(h_sc_b_Nms_, omega_b_rad_s_); }
kinetic_energy_J_ = 0.5 * libra::inner_product(angular_momentum_spacecraft_b_Nms_, angular_velocity_b_rad_s_);
}
102 changes: 30 additions & 72 deletions src/dynamics/attitude/attitude.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class Attitude : public ILoggable, public SimulationObject {
/**
* @fn Attitude
* @brief Constructor
* @param [in] sim_object_name: Simulation object name for Monte-Carlo simulation
* @param [in] simulation_object_name: Simulation object name for Monte-Carlo simulation
*/
Attitude(const std::string& sim_object_name = "Attitude");
Attitude(const std::string& simulation_object_name = "Attitude");
/**
* @fn ~Attitude
* @brief Destructor
Expand All @@ -35,105 +35,66 @@ class Attitude : public ILoggable, public SimulationObject {
* @fn GetPropStep
* @brief Return propagation step [sec]
*/
inline double GetPropStep() const { return prop_step_s_; }
inline double GetPropStep() const { return propagation_step_s_; }
/**
* @fn GetOmega_b
* @brief Return angular velocity of spacecraft body-fixed frame with respect to the inertial frame [rad/s]
*/
inline libra::Vector<3> GetOmega_b() const { return omega_b_rad_s_; }
inline libra::Vector<3> GetOmega_b() const { return angular_velocity_b_rad_s_; }
/**
* @fn GetQuaternion_i2b
* @brief Return attitude quaternion from the inertial frame to the body fixed frame
*/
inline libra::Quaternion GetQuaternion_i2b() const { return quaternion_i2b_; }
/**
* @fn GetDCM_b2i
* @brief Return attitude direction cosine matrix from the body fixed frame to the inertial frame
* @note TODO: Check correctness i2b? b2i?
*/
inline libra::Matrix<3, 3> GetDCM_b2i() const { return quaternion_i2b_.toDCM(); }
/**
* @fn GetDCM_i2b
* @brief Return attitude direction cosine matrix from the inertial frame to the body fixed frame
* @note TODO: Check correctness i2b? b2i?
*/
inline libra::Matrix<3, 3> GetDCM_i2b() const {
libra::Matrix<3, 3> DCM_b2i = quaternion_i2b_.toDCM();
return transpose(DCM_b2i);
}
/**
* @fn GetTotalAngMomNorm
* @brief Return norm of total angular momentum of the spacecraft [Nms]
*/
inline double GetTotalAngMomNorm() const { return libra::norm(h_total_b_Nms_); }
inline double GetTotalAngMomNorm() const { return libra::norm(angular_momentum_total_b_Nms_); }
/**
* @fn GetEnergy
* @brief Return rotational Kinetic Energy of Spacecraft [J]
* @note TODO: Consider to use k_sc_J_
*/
inline double GetEnergy() const { return 0.5f * libra::inner_product(omega_b_rad_s_, inertia_tensor_kgm2_ * omega_b_rad_s_); }
inline double GetEnergy() const { return kinetic_energy_J_; }
/**
* @fn GetInertiaTensor
* @brief Return inertia tensor [kg m^2]
*/
inline libra::Matrix<3, 3> GetInertiaTensor() const { return inertia_tensor_kgm2_; }
/**
* @fn GetInvInertiaTensor
* @brief Return inverse matrix of inertia tensor
*/
inline libra::Matrix<3, 3> GetInvInertiaTensor() const { return inv_inertia_tensor_; }

// Setter
/**
* @fn SetPropStep
* @brief Set propagation step [sec]
*/
inline void SetPropStep(double set) { prop_step_s_ = set; }
/**
* @fn SetOmega_b
* @brief Set angular velocity of the body fixed frame with respect to the inertial frame [rad/s]
*/
inline void SetOmega_b(const libra::Vector<3> set) { omega_b_rad_s_ = set; }
inline void SetOmega_b(const libra::Vector<3> omega_b_rad_s) { angular_velocity_b_rad_s_ = omega_b_rad_s; }
/**
* @fn SetQuaternion_i2b
* @brief Set attitude quaternion from the inertial frame to the body frame
*/
inline void SetQuaternion_i2b(const libra::Quaternion set) { quaternion_i2b_ = set; }
/**
* @fn AddQuaternionOffset
* @brief Add quaternion offset rotation
*/
inline void AddQuaternionOffset(const libra::Quaternion offset) { quaternion_i2b_ = quaternion_i2b_ * offset; }
inline void SetQuaternion_i2b(const libra::Quaternion quaternion_i2b) { quaternion_i2b_ = quaternion_i2b; }
/**
* @fn SetTorque_b
* @brief Set torque acting on the spacecraft on the body fixed frame [Nm]
*/
inline void SetTorque_b(const libra::Vector<3> set) { torque_b_Nm_ = set; }
inline void SetTorque_b(const libra::Vector<3> torque_b_Nm) { torque_b_Nm_ = torque_b_Nm; }
/**
* @fn AddTorque_b
* @fn AddTorque_b_Nm
* @brief Add torque acting on the spacecraft on the body fixed frame [Nm]
*/
inline void AddTorque_b(const libra::Vector<3> set) { torque_b_Nm_ += set; }
inline void AddTorque_b_Nm(const libra::Vector<3> torque_b_Nm) { torque_b_Nm_ += torque_b_Nm; }
/**
* @fn SetAngMom_rw
* @brief Set angular momentum of reaction wheel in the body fixed frame [Nms]
*/
inline void SetAngMom_rw(const libra::Vector<3> set) { h_rw_b_Nms_ = set; }
/**
* @fn SetInertiaTensor
* @brief Set inertia tensor of the spacecraft [kg m2]
*/
inline void SetInertiaTensor(const Matrix<3, 3>& set) {
inertia_tensor_kgm2_ = set;
inv_inertia_tensor_ = libra::invert(inertia_tensor_kgm2_);
}
inline void SetAngMom_rw(const libra::Vector<3> angular_momentum_rw_b_Nms) { angular_momentum_reaction_wheel_b_Nms_ = angular_momentum_rw_b_Nms; }

/**
* @fn Propagate
* @brief Pure virtual function of attitude propagation
* @param [in] endtime_s: Propagation endtime [sec]
* @param [in] end_time_s: Propagation endtime [sec]
*/
virtual void Propagate(const double endtime_s) = 0;
virtual void Propagate(const double end_time_s) = 0;

// Override ILoggable
/**
Expand All @@ -148,33 +109,30 @@ class Attitude : public ILoggable, public SimulationObject {
virtual std::string GetLogValue() const;

// SimulationObject for McSim
virtual void SetParameters(const MCSimExecutor& mc_sim);
virtual void SetParameters(const MCSimExecutor& mc_simulator);

protected:
bool is_calc_enabled_ = true; //!< Calculation flag
double prop_step_s_; //!< Propagation step [sec] TODO: consider is it really need here
libra::Vector<3> omega_b_rad_s_; //!< Angular velocity of spacecraft body fixed frame with respect to the inertial frame [rad/s]
libra::Quaternion quaternion_i2b_; //!< Attitude quaternion from the inertial frame to the body fixed frame
libra::Vector<3> torque_b_Nm_; //!< Torque in the body fixed frame [Nm]
bool is_calc_enabled_ = true; //!< Calculation flag
double propagation_step_s_; //!< Propagation step [sec]
libra::Vector<3> angular_velocity_b_rad_s_; //!< Angular velocity of spacecraft body fixed frame with respect to the inertial frame [rad/s]
libra::Quaternion quaternion_i2b_; //!< Attitude quaternion from the inertial frame to the body fixed frame
libra::Vector<3> torque_b_Nm_; //!< Torque in the body fixed frame [Nm]

libra::Matrix<3, 3> inertia_tensor_kgm2_; //!< Inertia tensor of the spacecraft [kg m^2] TODO: Move to Structure
libra::Matrix<3, 3> inv_inertia_tensor_; //!< Inverse matrix of the inertia tensor
libra::Vector<3> h_sc_b_Nms_; //!< Angular momentum of spacecraft in the body fixed frame [Nms]
libra::Vector<3> h_rw_b_Nms_; //!< Angular momentum of reaction wheel in the body fixed frame [Nms]
libra::Vector<3> h_total_b_Nms_; //!< Total angular momentum of spacecraft in the body fixed frame [Nms]
libra::Vector<3> h_total_i_Nms_; //!< Total angular momentum of spacecraft in the inertial frame [Nms]
double h_total_Nms_; //!< Norm of total angular momentum [Nms]
double k_sc_J_; //!< Rotational Kinetic Energy of Spacecraft [J]

libra::Vector<3> angular_momentum_spacecraft_b_Nms_; //!< Angular momentum of spacecraft in the body fixed frame [Nms]
libra::Vector<3> angular_momentum_reaction_wheel_b_Nms_; //!< Angular momentum of reaction wheel in the body fixed frame [Nms]
libra::Vector<3> angular_momentum_total_b_Nms_; //!< Total angular momentum of spacecraft in the body fixed frame [Nms]
libra::Vector<3> angular_momentum_total_i_Nms_; //!< Total angular momentum of spacecraft in the inertial frame [Nms]
double angular_momentum_total_Nms_; //!< Norm of total angular momentum [Nms]
double kinetic_energy_J_; //!< Rotational Kinetic Energy of Spacecraft [J]

/**
* @fn CalcAngMom
* @fn CalcAngularMomentum
* @brief Calculate angular momentum
*/
void CalcAngMom(void);
/**
* @fn CalcSatRotationalKineticEnergy
* @brief Calculate rotational Kinetic Energy of Spacecraft
*/
void CalcSatRotationalKineticEnergy(void);
void CalcAngularMomentum(void);
};

#endif // S2E_DYNAMICS_ATTITUDE_ATTITUDE_HPP_
Loading