generated from ut-issl/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #511 from ut-issl/feature/add-moon-rotation
Add moon rotation
- Loading branch information
Showing
13 changed files
with
316 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* @file moon_rotation.cpp | ||
* @brief Class to calculate the moon rotation | ||
*/ | ||
|
||
#include "moon_rotation.hpp" | ||
|
||
#include <SpiceUsr.h> | ||
|
||
#include <library/math/constants.hpp> | ||
#include <library/planet_rotation/moon_rotation_utilities.hpp> | ||
|
||
MoonRotation::MoonRotation(const CelestialInformation& celestial_information, MoonRotationMode mode) | ||
: mode_(mode), celestial_information_(celestial_information) { | ||
dcm_j2000_to_mcmf_ = libra::MakeIdentityMatrix<3>(); | ||
} | ||
|
||
void MoonRotation::Update(const SimulationTime& simulation_time) { | ||
if (mode_ == MoonRotationMode::kSimple) { | ||
libra::Vector<3> moon_position_eci_m = celestial_information_.GetPositionFromSelectedBody_i_m("MOON", "EARTH"); | ||
libra::Vector<3> moon_velocity_eci_m_s = celestial_information_.GetVelocityFromSelectedBody_i_m_s("MOON", "EARTH"); | ||
dcm_j2000_to_mcmf_ = CalcDcmEciToPrincipalAxis(moon_position_eci_m, moon_velocity_eci_m_s); | ||
} else if (mode_ == MoonRotationMode::kIauMoon) { | ||
ConstSpiceChar from[] = "J2000"; | ||
ConstSpiceChar to[] = "IAU_MOON"; | ||
SpiceDouble et = simulation_time.GetCurrentEphemerisTime(); | ||
SpiceDouble state_transition_matrix[6][6]; | ||
sxform_c(from, to, et, state_transition_matrix); | ||
for (size_t i = 0; i < 3; i++) { | ||
for (size_t j = 0; j < 3; j++) { | ||
dcm_j2000_to_mcmf_[i][j] = state_transition_matrix[i][j]; | ||
} | ||
} | ||
} else { | ||
dcm_j2000_to_mcmf_ = libra::MakeIdentityMatrix<3>(); | ||
} | ||
} | ||
|
||
MoonRotationMode ConvertMoonRotationMode(const std::string mode) { | ||
MoonRotationMode rotation_mode; | ||
if (mode == "IDLE") { | ||
rotation_mode = MoonRotationMode::kIdle; | ||
} else if (mode == "SIMPLE") { | ||
rotation_mode = MoonRotationMode::kSimple; | ||
} else if (mode == "IAU_MOON") { | ||
rotation_mode = MoonRotationMode::kIauMoon; | ||
} else // if rotation_mode is neither Idle, Simple, nor Full, set rotation_mode to Idle | ||
{ | ||
rotation_mode = MoonRotationMode::kIdle; | ||
} | ||
|
||
return rotation_mode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* @file moon_rotation.hpp | ||
* @brief Class to calculate the moon rotation | ||
*/ | ||
|
||
#ifndef S2E_ENVIRONMENT_GLOBAL_MOON_ROTATION_HPP_ | ||
#define S2E_ENVIRONMENT_GLOBAL_MOON_ROTATION_HPP_ | ||
|
||
#include "celestial_information.hpp" | ||
#include "library/math/matrix.hpp" | ||
#include "library/math/vector.hpp" | ||
#include "simulation_time.hpp" | ||
|
||
class CelestialInformation; | ||
|
||
/** | ||
* @enum MoonRotationMode | ||
* @brief Definition of calculation mode of moon rotation | ||
*/ | ||
enum class MoonRotationMode { | ||
kIdle, //!< No rotation | ||
kSimple, //!< Mean Earth and Principal Axis calculation | ||
kIauMoon, //!< IAU_MOON frame given by SPICE | ||
}; | ||
/** | ||
* @fn ConvertMoonRotationMode | ||
* @brief Convert string to MoonRotationMode | ||
* @param[in] mode: mode name in string | ||
*/ | ||
MoonRotationMode ConvertMoonRotationMode(const std::string mode); | ||
|
||
/** | ||
* @class MoonRotation | ||
* @brief Class to calculate the moon rotation | ||
*/ | ||
class MoonRotation { | ||
public: | ||
/** | ||
* @fn MoonRotation | ||
* @brief Constructor | ||
*/ | ||
MoonRotation(const CelestialInformation &celestial_information, MoonRotationMode mode = MoonRotationMode::kIdle); | ||
|
||
/** | ||
* @fn Update | ||
* @brief Update rotation | ||
* @param [in] simulation_time: simulation_time | ||
*/ | ||
void Update(const SimulationTime &simulation_time); | ||
|
||
/** | ||
* @fn GetDcmJ2000ToMcmf | ||
* @brief Return the DCM between J2000 inertial frame and the Moon Centered Moon Fixed frame | ||
* @note Because this is just a DCM, users need to consider the origin of the vector, which you want to convert with this matrix. | ||
*/ | ||
inline const libra::Matrix<3, 3> GetDcmJ2000ToMcmf() const { return dcm_j2000_to_mcmf_; }; | ||
|
||
private: | ||
MoonRotationMode mode_; //!< Rotation mode | ||
libra::Matrix<3, 3> dcm_j2000_to_mcmf_; //!< Direction Cosine Matrix J2000 to MCMF (Moon Centered Moon Fixed) | ||
|
||
const CelestialInformation &celestial_information_; //!< Celestial Information to get moon orbit | ||
}; | ||
|
||
#endif // S2E_ENVIRONMENT_GLOBAL_MOON_ROTATION_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.