Skip to content

Commit

Permalink
move function CalcAngularVelocityMatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMochizuki committed May 22, 2024
1 parent 1f64ba6 commit c2f09e9
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 63 deletions.
23 changes: 23 additions & 0 deletions src/dynamics/attitude/attitude.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,26 @@ void Attitude::CalcAngularMomentum(void) {

kinetic_energy_J_ = 0.5 * libra::InnerProduct(angular_momentum_spacecraft_b_Nms_, angular_velocity_b_rad_s_);
}

libra::Matrix<4, 4> Attitude::CalcAngularVelocityMatrix(libra::Vector<3> angular_velocity_b_rad_s) {
libra::Matrix<4, 4> angular_velocity_matrix;

angular_velocity_matrix[0][0] = 0.0f;
angular_velocity_matrix[0][1] = angular_velocity_b_rad_s[2];
angular_velocity_matrix[0][2] = -angular_velocity_b_rad_s[1];
angular_velocity_matrix[0][3] = angular_velocity_b_rad_s[0];
angular_velocity_matrix[1][0] = -angular_velocity_b_rad_s[2];
angular_velocity_matrix[1][1] = 0.0f;
angular_velocity_matrix[1][2] = angular_velocity_b_rad_s[0];
angular_velocity_matrix[1][3] = angular_velocity_b_rad_s[1];
angular_velocity_matrix[2][0] = angular_velocity_b_rad_s[1];
angular_velocity_matrix[2][1] = -angular_velocity_b_rad_s[0];
angular_velocity_matrix[2][2] = 0.0f;
angular_velocity_matrix[2][3] = angular_velocity_b_rad_s[2];
angular_velocity_matrix[3][0] = -angular_velocity_b_rad_s[0];
angular_velocity_matrix[3][1] = -angular_velocity_b_rad_s[1];
angular_velocity_matrix[3][2] = -angular_velocity_b_rad_s[2];
angular_velocity_matrix[3][3] = 0.0f;

return angular_velocity_matrix;
}
17 changes: 12 additions & 5 deletions src/dynamics/attitude/attitude.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ class Attitude : public ILoggable, public SimulationObject {
virtual void SetParameters(const MonteCarloSimulationExecutor& mc_simulator);

protected:
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]
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]

const libra::Matrix<3, 3>& inertia_tensor_kgm2_; //!< Inertia tensor of the spacecraft [kg m^2]

Expand All @@ -134,6 +134,13 @@ class Attitude : public ILoggable, public SimulationObject {
* @brief Calculate angular momentum
*/
void CalcAngularMomentum(void);

/**
* @fn CalcAngularVelocityMatrix
* @brief Generate angular velocity matrix for kinematics calculation
* @param [in] angular_velocity_b_rad_s: Angular velocity [rad/s]
*/
libra::Matrix<4, 4> CalcAngularVelocityMatrix(libra::Vector<3> angular_velocity_b_rad_s);
};

#endif // S2E_DYNAMICS_ATTITUDE_ATTITUDE_HPP_
23 changes: 0 additions & 23 deletions src/dynamics/attitude/attitude_rk4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,6 @@ void AttitudeRk4::Propagate(const double end_time_s) {
CalcAngularMomentum();
}

libra::Matrix<4, 4> AttitudeRk4::CalcAngularVelocityMatrix(libra::Vector<3> angular_velocity_b_rad_s) {
libra::Matrix<4, 4> angular_velocity_matrix;

angular_velocity_matrix[0][0] = 0.0f;
angular_velocity_matrix[0][1] = angular_velocity_b_rad_s[2];
angular_velocity_matrix[0][2] = -angular_velocity_b_rad_s[1];
angular_velocity_matrix[0][3] = angular_velocity_b_rad_s[0];
angular_velocity_matrix[1][0] = -angular_velocity_b_rad_s[2];
angular_velocity_matrix[1][1] = 0.0f;
angular_velocity_matrix[1][2] = angular_velocity_b_rad_s[0];
angular_velocity_matrix[1][3] = angular_velocity_b_rad_s[1];
angular_velocity_matrix[2][0] = angular_velocity_b_rad_s[1];
angular_velocity_matrix[2][1] = -angular_velocity_b_rad_s[0];
angular_velocity_matrix[2][2] = 0.0f;
angular_velocity_matrix[2][3] = angular_velocity_b_rad_s[2];
angular_velocity_matrix[3][0] = -angular_velocity_b_rad_s[0];
angular_velocity_matrix[3][1] = -angular_velocity_b_rad_s[1];
angular_velocity_matrix[3][2] = -angular_velocity_b_rad_s[2];
angular_velocity_matrix[3][3] = 0.0f;

return angular_velocity_matrix;
}

libra::Vector<7> AttitudeRk4::AttitudeDynamicsAndKinematics(libra::Vector<7> x, double t) {
UNUSED(t);

Expand Down
6 changes: 0 additions & 6 deletions src/dynamics/attitude/attitude_rk4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ class AttitudeRk4 : public Attitude {
libra::Matrix<3, 3> previous_inertia_tensor_kgm2_; //!< Previous inertia tensor [kgm2]
libra::Vector<3> torque_inertia_tensor_change_b_Nm_; //!< Torque generated by inertia tensor change [Nm]

/**
* @fn CalcAngularVelocityMatrix
* @brief Generate angular velocity matrix for kinematics calculation
* @param [in] angular_velocity_b_rad_s: Angular velocity [rad/s]
*/
libra::Matrix<4, 4> CalcAngularVelocityMatrix(libra::Vector<3> angular_velocity_b_rad_s);
/**
* @fn AttitudeDynamicsAndKinematics
* @brief Dynamics equation with kinematics
Expand Down
23 changes: 0 additions & 23 deletions src/dynamics/attitude/attitude_with_cantilever_vibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,6 @@ void AttitudeWithCantileverVibration::Propagate(const double end_time_s) {
CalcAngularMomentum();
}

libra::Matrix<4, 4> AttitudeWithCantileverVibration::CalcAngularVelocityMatrix(libra::Vector<3> angular_velocity_b_rad_s) {
libra::Matrix<4, 4> angular_velocity_matrix;

angular_velocity_matrix[0][0] = 0.0f;
angular_velocity_matrix[0][1] = angular_velocity_b_rad_s[2];
angular_velocity_matrix[0][2] = -angular_velocity_b_rad_s[1];
angular_velocity_matrix[0][3] = angular_velocity_b_rad_s[0];
angular_velocity_matrix[1][0] = -angular_velocity_b_rad_s[2];
angular_velocity_matrix[1][1] = 0.0f;
angular_velocity_matrix[1][2] = angular_velocity_b_rad_s[0];
angular_velocity_matrix[1][3] = angular_velocity_b_rad_s[1];
angular_velocity_matrix[2][0] = angular_velocity_b_rad_s[1];
angular_velocity_matrix[2][1] = -angular_velocity_b_rad_s[0];
angular_velocity_matrix[2][2] = 0.0f;
angular_velocity_matrix[2][3] = angular_velocity_b_rad_s[2];
angular_velocity_matrix[3][0] = -angular_velocity_b_rad_s[0];
angular_velocity_matrix[3][1] = -angular_velocity_b_rad_s[1];
angular_velocity_matrix[3][2] = -angular_velocity_b_rad_s[2];
angular_velocity_matrix[3][3] = 0.0f;

return angular_velocity_matrix;
}

libra::Vector<13> AttitudeWithCantileverVibration::AttitudeDynamicsAndKinematics(libra::Vector<13> x, double t) {
UNUSED(t);

Expand Down
6 changes: 0 additions & 6 deletions src/dynamics/attitude/attitude_with_cantilever_vibration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ class AttitudeWithCantileverVibration : public Attitude {
libra::Vector<3> angular_velocity_cantilever_rad_s_; //!< Angular velocity of the cantilever with respect to the body frame [rad/s]
libra::Vector<3> euler_angular_cantilever_rad_; //!< Euler angle of the cantilever with respect to the body frame [rad/s]

/**
* @fn CalcAngularVelocityMatrix
* @brief Generate angular velocity matrix for kinematics calculation
* @param [in] angular_velocity_b_rad_s: Angular velocity [rad/s]
*/
libra::Matrix<4, 4> CalcAngularVelocityMatrix(libra::Vector<3> angular_velocity_b_rad_s);
/**
* @fn AttitudeDynamicsAndKinematics
* @brief Dynamics equation with kinematics
Expand Down

0 comments on commit c2f09e9

Please sign in to comment.