generated from ut-issl/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 3
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 #79 from ut-issl/feature/add_relative_attitude_sensor
Add relative attitude sensor
- Loading branch information
Showing
8 changed files
with
186 additions
and
0 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
12 changes: 12 additions & 0 deletions
12
s2e-ff/data/initialize_files/components/relative_attitude_sensor.ini
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,12 @@ | ||
[RELATIVE_ATTITUDE_SENSOR] | ||
// Prescaler with respect to the component update period | ||
prescaler = 1 | ||
|
||
// Target satellite ID | ||
target_sat_id = 1 | ||
|
||
// When this value is negative, reference_sat_id is automatically set as the mounting satellite ID | ||
reference_sat_id = -1 | ||
|
||
// Standard deviation of force direction error [deg] | ||
error_angle_standard_deviation_deg = 1.0 |
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,85 @@ | ||
/** | ||
* @file relative_attitude_sensor.cpp | ||
* @brief Relative attitude sensor | ||
*/ | ||
|
||
#include "relative_attitude_sensor.hpp" | ||
|
||
#include <components/base/initialize_sensor.hpp> | ||
#include <library/initialize/initialize_file_access.hpp> | ||
|
||
RelativeAttitudeSensor::RelativeAttitudeSensor(const int prescaler, ClockGenerator* clock_gen, const int target_sat_id, const int reference_sat_id, | ||
const RelativeInformation& rel_info, const double standard_deviation_rad) | ||
: Component(prescaler, clock_gen), | ||
target_sat_id_(target_sat_id), | ||
reference_sat_id_(reference_sat_id), | ||
rel_info_(rel_info), | ||
angle_noise_(0.0, standard_deviation_rad) { | ||
direction_noise_.SetParameters(0.0, 1.0); | ||
} | ||
|
||
RelativeAttitudeSensor::~RelativeAttitudeSensor() {} | ||
|
||
void RelativeAttitudeSensor::MainRoutine(int count) { | ||
UNUSED(count); | ||
// Error calculation | ||
libra::Vector<3> random_direction; | ||
random_direction[0] = direction_noise_; | ||
random_direction[1] = direction_noise_; | ||
random_direction[2] = direction_noise_; | ||
random_direction = random_direction.CalcNormalizedVector(); | ||
|
||
double error_angle_rad = angle_noise_; | ||
libra::Quaternion error_quaternion(random_direction, error_angle_rad); | ||
|
||
// Get true value | ||
measured_quaternion_rb2tb_ = rel_info_.GetRelativeAttitudeQuaternion(target_sat_id_, reference_sat_id_); | ||
measured_quaternion_rb2tb_ = error_quaternion * measured_quaternion_rb2tb_; | ||
measured_euler_angle_rb2tb_rad_ = measured_quaternion_rb2tb_.ConvertToEuler(); | ||
} | ||
|
||
std::string RelativeAttitudeSensor::GetLogHeader() const { | ||
std::string str_tmp = ""; | ||
std::string head = "RelativeAttitudeSensor_"; | ||
|
||
const std::string frame_name = std::to_string(reference_sat_id_) + "to" + std::to_string(target_sat_id_); | ||
str_tmp += WriteQuaternion(head + "quaternion", frame_name); | ||
str_tmp += WriteVector(head + "euler_angle", frame_name, "rad", 3); | ||
|
||
return str_tmp; | ||
} | ||
|
||
std::string RelativeAttitudeSensor::GetLogValue() const { | ||
std::string str_tmp = ""; | ||
|
||
str_tmp += WriteQuaternion(measured_quaternion_rb2tb_); | ||
str_tmp += WriteVector(measured_euler_angle_rb2tb_rad_); | ||
|
||
return str_tmp; | ||
} | ||
|
||
RelativeAttitudeSensor InitializeRelativeAttitudeSensor(ClockGenerator* clock_gen, const std::string file_name, const double compo_step_time_s, | ||
const RelativeInformation& rel_info, const int reference_sat_id_input) { | ||
// General | ||
IniAccess ini_file(file_name); | ||
char section[30] = "RELATIVE_ATTITUDE_SENSOR"; | ||
|
||
// CompoBase | ||
int prescaler = ini_file.ReadInt(section, "prescaler"); | ||
if (prescaler <= 1) prescaler = 1; | ||
|
||
double error_angle_standard_deviation_deg = ini_file.ReadDouble(section, "error_angle_standard_deviation_deg"); | ||
double error_angle_standard_deviation_rad = libra::deg_to_rad * error_angle_standard_deviation_deg; | ||
|
||
// RelativeAttitudeSensor | ||
int target_sat_id = ini_file.ReadInt(section, "target_sat_id"); | ||
int reference_sat_id = ini_file.ReadInt(section, "reference_sat_id"); | ||
if (reference_sat_id < 0) { | ||
reference_sat_id = reference_sat_id_input; | ||
} | ||
|
||
RelativeAttitudeSensor relative_attitude_sensor(prescaler, clock_gen, target_sat_id, reference_sat_id, rel_info, | ||
error_angle_standard_deviation_rad); | ||
|
||
return relative_attitude_sensor; | ||
} |
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,78 @@ | ||
/** | ||
* @file relative_attitude_sensor.hpp | ||
* @brief Relative attitude sensor | ||
*/ | ||
|
||
#ifndef S2E_COMPONENTS_AOCS_RELATIVE_ATTITUDE_SENSOR_HPP_ | ||
#define S2E_COMPONENTS_AOCS_RELATIVE_ATTITUDE_SENSOR_HPP_ | ||
|
||
#include <components/base/component.hpp> | ||
#include <library/logger/logger.hpp> | ||
#include <library/randomization/normal_randomization.hpp> | ||
#include <simulation/multiple_spacecraft/relative_information.hpp> | ||
|
||
/** | ||
* @class RelativeAttitudeSensor | ||
* @brief Relative attitude sensor | ||
*/ | ||
class RelativeAttitudeSensor : public Component, public ILoggable { | ||
public: | ||
/** | ||
* @fn RelativeAttitudeSensor | ||
* @brief Constructor | ||
*/ | ||
RelativeAttitudeSensor(const int prescaler, ClockGenerator* clock_gen, const int target_sat_id, const int reference_sat_id, | ||
const RelativeInformation& rel_info, const double standard_deviation_rad); | ||
/** | ||
* @fn ~RelativeAttitudeSensor | ||
* @brief Destructor | ||
*/ | ||
~RelativeAttitudeSensor(); | ||
|
||
// ComponentBase override function | ||
/** | ||
* @fn MainRoutine | ||
* @brief Main routine | ||
*/ | ||
void MainRoutine(int count); | ||
|
||
// Override ILoggable | ||
/** | ||
* @fn GetLogHeader | ||
* @brief Override GetLogHeader function of ILoggable | ||
*/ | ||
virtual std::string GetLogHeader() const; | ||
/** | ||
* @fn GetLogValue | ||
* @brief Override GetLogValue function of ILoggable | ||
*/ | ||
virtual std::string GetLogValue() const; | ||
|
||
// Getter | ||
inline libra::Quaternion GetMeasuredQuaternion_rb2tb() const { return measured_quaternion_rb2tb_; } | ||
inline libra::Vector<3> GetMeasuredEulerAngle_rb2tb_rad() const { return measured_euler_angle_rb2tb_rad_; } | ||
|
||
// Setter | ||
void SetTargetSatId(const int target_sat_id) { target_sat_id_ = target_sat_id; } | ||
|
||
protected: | ||
int target_sat_id_; //!< Target satellite ID | ||
const int reference_sat_id_; //!< Reference satellite ID | ||
|
||
// Measured value | ||
libra::Quaternion measured_quaternion_rb2tb_ = {0.0, 0.0, 0.0, 1.0}; //!< Measured quaternion of target body from reference body | ||
libra::Vector<3> measured_euler_angle_rb2tb_rad_{ | ||
0.0}; //!< Measured Euler angle of target body in BODY frame [rad], 3-2-1 Euler angle (1: roll, 2: pitch, 3: yaw order) | ||
|
||
// Noises | ||
libra::NormalRand angle_noise_; //!< Normal random for magnitude noise | ||
libra::NormalRand direction_noise_; //!< Normal random for direction noise | ||
|
||
// References | ||
const RelativeInformation& rel_info_; //!< Relative information | ||
}; | ||
|
||
RelativeAttitudeSensor InitializeRelativeAttitudeSensor(ClockGenerator* clock_gen, const std::string file_name, const double compo_step_time_s, | ||
const RelativeInformation& rel_info, const int reference_sat_id_input = -1); | ||
|
||
#endif // S2E_COMPONENTS_AOCS_RELATIVE_ATTITUDE_SENSOR_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
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