diff --git a/src/components/CMakeLists.txt b/src/components/CMakeLists.txt index 3395e35db..becc7c7c6 100644 --- a/src/components/CMakeLists.txt +++ b/src/components/CMakeLists.txt @@ -9,21 +9,14 @@ base/i2c_target_communication_with_obc.cpp base/gpio_connection_with_obc.cpp real/aocs/gyro_sensor.cpp -real/aocs/initialize_gyro_sensor.cpp real/aocs/magnetometer.cpp -real/aocs/initialize_magnetometer.cpp real/aocs/magnetorquer.cpp -real/aocs/initialize_magnetorquer.cpp real/aocs/reaction_wheel_ode.cpp real/aocs/reaction_wheel.cpp -real/aocs/initialize_reaction_wheel.cpp real/aocs/reaction_wheel_jitter.cpp real/aocs/star_sensor.cpp -real/aocs/initialize_star_sensor.cpp real/aocs/sun_sensor.cpp -real/aocs/initialize_sun_sensor.cpp real/aocs/gnss_receiver.cpp -real/aocs/initialize_gnss_receiver.cpp real/aocs/mtq_magnetometer_interference.cpp real/cdh/on_board_computer.cpp @@ -31,9 +24,7 @@ real/cdh/on_board_computer_with_c2a.cpp real/communication/antenna.cpp real/communication/antenna_radiation_pattern.cpp -real/communication/initialize_antenna.cpp real/communication/ground_station_calculator.cpp -real/communication/initialize_ground_station_calculator.cpp examples/example_change_structure.cpp examples/example_serial_communication_with_obc.cpp @@ -42,24 +33,17 @@ examples/example_i2c_controller_for_hils.cpp examples/example_i2c_target_for_hils.cpp ideal/force_generator.cpp -ideal/initialize_force_generator.cpp ideal/torque_generator.cpp -ideal/initialize_torque_generator.cpp real/mission/telescope.cpp -real/mission/initialize_telescope.cpp real/power/power_control_unit.cpp real/power/battery.cpp -real/power/initialize_battery.cpp real/power/pcu_initial_study.cpp -real/power/initialize_pcu_initial_study.cpp real/power/solar_array_panel.cpp -real/power/initialize_solar_array_panel.cpp real/power/csv_scenario_interface.cpp real/propulsion/simple_thruster.cpp -real/propulsion/initialize_simple_thruster.cpp ports/gpio_port.cpp ports/power_port.cpp diff --git a/src/components/base/initialize_sensor.hpp b/src/components/base/initialize_sensor.hpp deleted file mode 100644 index 573e9557d..000000000 --- a/src/components/base/initialize_sensor.hpp +++ /dev/null @@ -1,26 +0,0 @@ -/** - * @file initialize_sensor.hpp - * @brief Initialize functions for Sensor class - */ - -#ifndef S2E_COMPONENTS_BASE_INITIALIZE_SENSOR_HPP_ -#define S2E_COMPONENTS_BASE_INITIALIZE_SENSOR_HPP_ - -#include "sensor.hpp" - -/** - * @fn ReadSensorInformation - * @brief Read information from initialize file for Sensor class - * @note It is recommended to use this function for all sensors inherits the Sensor class - * @param [in] file_name: Path to the initialize file - * @param [in] step_width_s: Step width of component update [sec] - * @param [in] component_name: Component name - * @param [in] unit: Unit of the sensor - */ -template -Sensor ReadSensorInformation(const std::string file_name, const double step_width_s, const std::string component_name, - const std::string unit = ""); - -#include "initialize_sensor_template_functions.hpp" - -#endif // S2E_COMPONENTS_BASE_INITIALIZE_SENSOR_HPP_ diff --git a/src/components/base/initialize_sensor_template_functions.hpp b/src/components/base/initialize_sensor_template_functions.hpp deleted file mode 100644 index 6e0c275b4..000000000 --- a/src/components/base/initialize_sensor_template_functions.hpp +++ /dev/null @@ -1,53 +0,0 @@ -/** - * @file initialize_sensor_template_functions.hpp - * @brief Initialize functions for Sensor class (template functions) - */ - -#ifndef S2E_COMPONENTS_BASE_INITIALIZE_SENSOR_TEMPLATE_FUNCTIONS_HPP_ -#define S2E_COMPONENTS_BASE_INITIALIZE_SENSOR_TEMPLATE_FUNCTIONS_HPP_ - -#include "library/initialize/initialize_file_access.hpp" - -template -Sensor ReadSensorInformation(const std::string file_name, const double step_width_s, const std::string component_name, const std::string unit) { - IniAccess ini_file(file_name); - std::string section = "SENSOR_BASE_" + component_name; - - libra::Vector scale_factor_vector; - ini_file.ReadVector(section.c_str(), "scale_factor_c", scale_factor_vector); - libra::Matrix scale_factor_c; - for (size_t i = 0; i < N; i++) { - for (size_t j = 0; j < N; j++) { - scale_factor_c[i][j] = scale_factor_vector[i * N + j]; - } - } - - std::string key_name; - libra::Vector constant_bias_c; - key_name = "constant_bias_c_" + unit; - ini_file.ReadVector(section.c_str(), key_name.c_str(), constant_bias_c); - libra::Vector normal_random_standard_deviation_c; - key_name = "normal_random_standard_deviation_c_" + unit; - ini_file.ReadVector(section.c_str(), key_name.c_str(), normal_random_standard_deviation_c); - libra::Vector random_walk_standard_deviation_c; - key_name = "random_walk_standard_deviation_c_" + unit; - ini_file.ReadVector(section.c_str(), key_name.c_str(), random_walk_standard_deviation_c); - libra::Vector random_walk_limit_c; - key_name = "random_walk_limit_c_" + unit; - ini_file.ReadVector(section.c_str(), key_name.c_str(), random_walk_limit_c); - - key_name = "range_to_constant_" + unit; - double range_to_const = ini_file.ReadDouble(section.c_str(), key_name.c_str()); - libra::Vector range_to_const_c{range_to_const}; - - key_name = "range_to_zero_" + unit; - double range_to_zero = ini_file.ReadDouble(section.c_str(), key_name.c_str()); - libra::Vector range_to_zero_c{range_to_zero}; - - Sensor sensor_base(scale_factor_c, range_to_const_c, range_to_zero_c, constant_bias_c, normal_random_standard_deviation_c, step_width_s, - random_walk_standard_deviation_c, random_walk_limit_c); - - return sensor_base; -} - -#endif // S2E_COMPONENTS_BASE_INITIALIZE_SENSOR_TEMPLATE_FUNCTIONS_HPP_ diff --git a/src/components/base/sensor.hpp b/src/components/base/sensor.hpp index 16944b2de..111e71226 100644 --- a/src/components/base/sensor.hpp +++ b/src/components/base/sensor.hpp @@ -72,6 +72,19 @@ class Sensor { void RangeCheck(void); }; +/** + * @fn ReadSensorInformation + * @brief Read information from initialize file for Sensor class + * @note It is recommended to use this function for all sensors inherits the Sensor class + * @param [in] file_name: Path to the initialize file + * @param [in] step_width_s: Step width of component update [sec] + * @param [in] component_name: Component name + * @param [in] unit: Unit of the sensor information + */ +template +Sensor ReadSensorInformation(const std::string file_name, const double step_width_s, const std::string component_name, + const std::string unit = ""); + #include "./sensor_template_functions.hpp" #endif // S2E_COMPONENTS_BASE_SENSOR_HPP_ diff --git a/src/components/base/sensor_template_functions.hpp b/src/components/base/sensor_template_functions.hpp index 8b680992a..b3fb2744c 100644 --- a/src/components/base/sensor_template_functions.hpp +++ b/src/components/base/sensor_template_functions.hpp @@ -6,6 +6,7 @@ #ifndef S2E_COMPONENTS_BASE_SENSOR_TEMPLATE_FUNCTIONS_HPP_ #define S2E_COMPONENTS_BASE_SENSOR_TEMPLATE_FUNCTIONS_HPP_ +#include #include template @@ -74,4 +75,46 @@ void Sensor::RangeCheck(void) { } } +template +Sensor ReadSensorInformation(const std::string file_name, const double step_width_s, const std::string component_name, const std::string unit) { + IniAccess ini_file(file_name); + std::string section = "SENSOR_BASE_" + component_name; + + libra::Vector scale_factor_vector; + ini_file.ReadVector(section.c_str(), "scale_factor_c", scale_factor_vector); + libra::Matrix scale_factor_c; + for (size_t i = 0; i < N; i++) { + for (size_t j = 0; j < N; j++) { + scale_factor_c[i][j] = scale_factor_vector[i * N + j]; + } + } + + std::string key_name; + libra::Vector constant_bias_c; + key_name = "constant_bias_c_" + unit; + ini_file.ReadVector(section.c_str(), key_name.c_str(), constant_bias_c); + libra::Vector normal_random_standard_deviation_c; + key_name = "normal_random_standard_deviation_c_" + unit; + ini_file.ReadVector(section.c_str(), key_name.c_str(), normal_random_standard_deviation_c); + libra::Vector random_walk_standard_deviation_c; + key_name = "random_walk_standard_deviation_c_" + unit; + ini_file.ReadVector(section.c_str(), key_name.c_str(), random_walk_standard_deviation_c); + libra::Vector random_walk_limit_c; + key_name = "random_walk_limit_c_" + unit; + ini_file.ReadVector(section.c_str(), key_name.c_str(), random_walk_limit_c); + + key_name = "range_to_constant_" + unit; + double range_to_const = ini_file.ReadDouble(section.c_str(), key_name.c_str()); + libra::Vector range_to_const_c{range_to_const}; + + key_name = "range_to_zero_" + unit; + double range_to_zero = ini_file.ReadDouble(section.c_str(), key_name.c_str()); + libra::Vector range_to_zero_c{range_to_zero}; + + Sensor sensor_base(scale_factor_c, range_to_const_c, range_to_zero_c, constant_bias_c, normal_random_standard_deviation_c, step_width_s, + random_walk_standard_deviation_c, random_walk_limit_c); + + return sensor_base; +} + #endif // S2E_COMPONENTS_BASE_SENSOR_TEMPLATE_FUNCTIONS_HPP_ diff --git a/src/components/ideal/force_generator.cpp b/src/components/ideal/force_generator.cpp index 0adbea835..9490b1c2f 100644 --- a/src/components/ideal/force_generator.cpp +++ b/src/components/ideal/force_generator.cpp @@ -6,6 +6,7 @@ #include "force_generator.hpp" #include +#include // Constructor ForceGenerator::ForceGenerator(const int prescaler, ClockGenerator* clock_generator, const double magnitude_error_standard_deviation_N, @@ -103,3 +104,21 @@ libra::Quaternion ForceGenerator::GenerateDirectionNoiseQuaternion(libra::Vector libra::Quaternion error_quaternion(rotation_axis, error_angle_rad); return error_quaternion; } + +ForceGenerator InitializeForceGenerator(ClockGenerator* clock_generator, const std::string file_name, const Dynamics* dynamics) { + // General + IniAccess ini_file(file_name); + + // CompoBase + int prescaler = ini_file.ReadInt("COMPONENT_BASE", "prescaler"); + if (prescaler <= 1) prescaler = 1; + + // ForceGenerator + char section[30] = "FORCE_GENERATOR"; + double force_magnitude_standard_deviation_N = ini_file.ReadDouble(section, "force_magnitude_standard_deviation_N"); + double force_direction_standard_deviation_deg = ini_file.ReadDouble(section, "force_direction_standard_deviation_deg"); + double force_direction_standard_deviation_rad = libra::deg_to_rad * force_direction_standard_deviation_deg; + ForceGenerator force_generator(prescaler, clock_generator, force_magnitude_standard_deviation_N, force_direction_standard_deviation_rad, dynamics); + + return force_generator; +} diff --git a/src/components/ideal/force_generator.hpp b/src/components/ideal/force_generator.hpp index 6439f4d10..8e1a7d1e6 100644 --- a/src/components/ideal/force_generator.hpp +++ b/src/components/ideal/force_generator.hpp @@ -115,4 +115,13 @@ class ForceGenerator : public Component, public ILoggable { const Dynamics* dynamics_; //!< Spacecraft dynamics information }; +/** + * @fn InitializeForceGenerator + * @brief Initialize function for ForceGenerator + * @param [in] clock_generator: Clock generator + * @param [in] file_name: Path to initialize file + * @param [in] dynamics: Dynamics information + */ +ForceGenerator InitializeForceGenerator(ClockGenerator* clock_generator, const std::string file_name, const Dynamics* dynamics); + #endif // S2E_COMPONENTS_IDEAL_FORCE_GENERATOR_HPP_ diff --git a/src/components/ideal/initialize_force_generator.cpp b/src/components/ideal/initialize_force_generator.cpp deleted file mode 100644 index 4a26019a0..000000000 --- a/src/components/ideal/initialize_force_generator.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * @file initialize_force_generator.cpp - * @brief Initialize function for ForceGenerator - */ -#include "initialize_force_generator.hpp" - -#include - -ForceGenerator InitializeForceGenerator(ClockGenerator* clock_generator, const std::string file_name, const Dynamics* dynamics) { - // General - IniAccess ini_file(file_name); - - // CompoBase - int prescaler = ini_file.ReadInt("COMPONENT_BASE", "prescaler"); - if (prescaler <= 1) prescaler = 1; - - // ForceGenerator - char section[30] = "FORCE_GENERATOR"; - double force_magnitude_standard_deviation_N = ini_file.ReadDouble(section, "force_magnitude_standard_deviation_N"); - double force_direction_standard_deviation_deg = ini_file.ReadDouble(section, "force_direction_standard_deviation_deg"); - double force_direction_standard_deviation_rad = libra::deg_to_rad * force_direction_standard_deviation_deg; - ForceGenerator force_generator(prescaler, clock_generator, force_magnitude_standard_deviation_N, force_direction_standard_deviation_rad, dynamics); - - return force_generator; -} diff --git a/src/components/ideal/initialize_force_generator.hpp b/src/components/ideal/initialize_force_generator.hpp deleted file mode 100644 index d853a6cf4..000000000 --- a/src/components/ideal/initialize_force_generator.hpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - * @file initialize_force_generator.hpp - * @brief Initialize function for ForceGenerator - */ - -#ifndef S2E_COMPONENTS_IDEAL_INITIALIZE_FORCE_GENERATOR_HPP_ -#define S2E_COMPONENTS_IDEAL_INITIALIZE_FORCE_GENERATOR_HPP_ - -#include "force_generator.hpp" - -/** - * @fn InitializeForceGenerator - * @brief Initialize function for ForceGenerator - * @param [in] clock_generator: Clock generator - * @param [in] file_name: Path to initialize file - * @param [in] dynamics: Dynamics information - */ -ForceGenerator InitializeForceGenerator(ClockGenerator* clock_generator, const std::string file_name, const Dynamics* dynamics); - -#endif // S2E_COMPONENTS_IDEAL_INITIALIZE_FORCE_GENERATOR_HPP_ diff --git a/src/components/ideal/initialize_torque_generator.cpp b/src/components/ideal/initialize_torque_generator.cpp deleted file mode 100644 index b0df1771a..000000000 --- a/src/components/ideal/initialize_torque_generator.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * @file initialize_torque_generator.cpp - * @brief Initialize function for TorqueGenerator - */ -#include "initialize_torque_generator.hpp" - -#include - -TorqueGenerator InitializeTorqueGenerator(ClockGenerator* clock_generator, const std::string file_name, const Dynamics* dynamics) { - // General - IniAccess ini_file(file_name); - - // CompoBase - int prescaler = ini_file.ReadInt("COMPONENT_BASE", "prescaler"); - if (prescaler <= 1) prescaler = 1; - - // TorqueGenerator - char section[30] = "TORQUE_GENERATOR"; - double torque_magnitude_standard_deviation_Nm = ini_file.ReadDouble(section, "torque_magnitude_standard_deviation_Nm"); - double torque_direction_standard_deviation_deg = ini_file.ReadDouble(section, "torque_direction_standard_deviation_deg"); - double torque_direction_standard_deviation_rad = libra::deg_to_rad * torque_direction_standard_deviation_deg; - TorqueGenerator torque_generator(prescaler, clock_generator, torque_magnitude_standard_deviation_Nm, torque_direction_standard_deviation_rad, - dynamics); - - return torque_generator; -} diff --git a/src/components/ideal/initialize_torque_generator.hpp b/src/components/ideal/initialize_torque_generator.hpp deleted file mode 100644 index 0484d0a1d..000000000 --- a/src/components/ideal/initialize_torque_generator.hpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - * @file initialize_torque_generator.hpp - * @brief Initialize function for TorqueGenerator - */ - -#ifndef S2E_COMPONENTS_IDEAL_INITIALIZE_TORQUE_GENERATOR_HPP_ -#define S2E_COMPONENTS_IDEAL_INITIALIZE_TORQUE_GENERATOR_HPP_ - -#include "torque_generator.hpp" - -/** - * @fn InitializeTorqueGenerator - * @brief Initialize function for TorqueGenerator - * @param [in] clock_generator: Clock generator - * @param [in] file_name: Path to initialize file - * @param [in] dynamics: Dynamics information - */ -TorqueGenerator InitializeTorqueGenerator(ClockGenerator* clock_generator, const std::string file_name, const Dynamics* dynamics); - -#endif // S2E_COMPONENTS_IDEAL_INITIALIZE_TORQUE_GENERATOR_HPP_ diff --git a/src/components/ideal/torque_generator.cpp b/src/components/ideal/torque_generator.cpp index 8762ad37a..4eba2adf8 100644 --- a/src/components/ideal/torque_generator.cpp +++ b/src/components/ideal/torque_generator.cpp @@ -6,6 +6,7 @@ #include "torque_generator.hpp" #include +#include // Constructor TorqueGenerator::TorqueGenerator(const int prescaler, ClockGenerator* clock_generator, const double magnitude_error_standard_deviation_Nm, @@ -76,3 +77,22 @@ libra::Quaternion TorqueGenerator::GenerateDirectionNoiseQuaternion(libra::Vecto libra::Quaternion error_quaternion(rotation_axis, error_angle_rad); return error_quaternion; } + +TorqueGenerator InitializeTorqueGenerator(ClockGenerator* clock_generator, const std::string file_name, const Dynamics* dynamics) { + // General + IniAccess ini_file(file_name); + + // CompoBase + int prescaler = ini_file.ReadInt("COMPONENT_BASE", "prescaler"); + if (prescaler <= 1) prescaler = 1; + + // TorqueGenerator + char section[30] = "TORQUE_GENERATOR"; + double torque_magnitude_standard_deviation_Nm = ini_file.ReadDouble(section, "torque_magnitude_standard_deviation_Nm"); + double torque_direction_standard_deviation_deg = ini_file.ReadDouble(section, "torque_direction_standard_deviation_deg"); + double torque_direction_standard_deviation_rad = libra::deg_to_rad * torque_direction_standard_deviation_deg; + TorqueGenerator torque_generator(prescaler, clock_generator, torque_magnitude_standard_deviation_Nm, torque_direction_standard_deviation_rad, + dynamics); + + return torque_generator; +} diff --git a/src/components/ideal/torque_generator.hpp b/src/components/ideal/torque_generator.hpp index db75006ad..78474917b 100644 --- a/src/components/ideal/torque_generator.hpp +++ b/src/components/ideal/torque_generator.hpp @@ -93,4 +93,13 @@ class TorqueGenerator : public Component, public ILoggable { const Dynamics* dynamics_; //!< Spacecraft dynamics information }; +/** + * @fn InitializeTorqueGenerator + * @brief Initialize function for TorqueGenerator + * @param [in] clock_generator: Clock generator + * @param [in] file_name: Path to initialize file + * @param [in] dynamics: Dynamics information + */ +TorqueGenerator InitializeTorqueGenerator(ClockGenerator* clock_generator, const std::string file_name, const Dynamics* dynamics); + #endif // S2E_COMPONENTS_IDEAL_TORQUE_GENERATOR_HPP_ diff --git a/src/components/real/aocs/gnss_receiver.cpp b/src/components/real/aocs/gnss_receiver.cpp index 93f44f9f8..47c138410 100644 --- a/src/components/real/aocs/gnss_receiver.cpp +++ b/src/components/real/aocs/gnss_receiver.cpp @@ -6,6 +6,7 @@ #include "gnss_receiver.hpp" #include +#include #include #include @@ -235,3 +236,67 @@ std::string GnssReceiver::GetLogValue() const // For logs return str_tmp; } + +typedef struct _gnssrecever_param { + int prescaler; + AntennaModel antenna_model; + libra::Vector<3> antenna_pos_b; + libra::Quaternion quaternion_b2c; + double half_width_rad; + std::string gnss_id; + int max_channel; + libra::Vector<3> noise_standard_deviation_m; +} GnssReceiverParam; + +GnssReceiverParam ReadGnssReceiverIni(const std::string file_name, const GnssSatellites* gnss_satellites, const int component_id) { + GnssReceiverParam gnss_receiver_param; + + IniAccess gnssr_conf(file_name); + const char* sensor_name = "GNSS_RECEIVER_"; + const std::string section_name = sensor_name + std::to_string(static_cast(component_id)); + const char* GSection = section_name.c_str(); + + int prescaler = gnssr_conf.ReadInt(GSection, "prescaler"); + if (prescaler <= 1) prescaler = 1; + gnss_receiver_param.prescaler = prescaler; + + gnss_receiver_param.antenna_model = static_cast(gnssr_conf.ReadInt(GSection, "antenna_model")); + if (!gnss_satellites->IsCalcEnabled() && gnss_receiver_param.antenna_model == AntennaModel::kCone) { + std::cout << "Calculation of GNSS SATELLITES is DISABLED, so the antenna " + "model of GNSS Receiver is automatically set to SIMPLE model." + << std::endl; + gnss_receiver_param.antenna_model = AntennaModel::kSimple; + } + + gnssr_conf.ReadVector(GSection, "antenna_position_b_m", gnss_receiver_param.antenna_pos_b); + gnssr_conf.ReadQuaternion(GSection, "quaternion_b2c", gnss_receiver_param.quaternion_b2c); + gnss_receiver_param.half_width_rad = gnssr_conf.ReadDouble(GSection, "antenna_half_width_deg"); + gnss_receiver_param.gnss_id = gnssr_conf.ReadString(GSection, "gnss_id"); + gnss_receiver_param.max_channel = gnssr_conf.ReadInt(GSection, "maximum_channel"); + gnssr_conf.ReadVector(GSection, "white_noise_standard_deviation_eci_m", gnss_receiver_param.noise_standard_deviation_m); + + return gnss_receiver_param; +} + +GnssReceiver InitGnssReceiver(ClockGenerator* clock_generator, int component_id, const std::string file_name, const Dynamics* dynamics, + const GnssSatellites* gnss_satellites, const SimulationTime* simulation_time) { + GnssReceiverParam gr_param = ReadGnssReceiverIni(file_name, gnss_satellites, component_id); + + GnssReceiver gnss_r(gr_param.prescaler, clock_generator, component_id, gr_param.gnss_id, gr_param.max_channel, gr_param.antenna_model, + gr_param.antenna_pos_b, gr_param.quaternion_b2c, gr_param.half_width_rad, gr_param.noise_standard_deviation_m, dynamics, + gnss_satellites, simulation_time); + return gnss_r; +} + +GnssReceiver InitGnssReceiver(ClockGenerator* clock_generator, PowerPort* power_port, int component_id, const std::string file_name, + const Dynamics* dynamics, const GnssSatellites* gnss_satellites, const SimulationTime* simulation_time) { + GnssReceiverParam gr_param = ReadGnssReceiverIni(file_name, gnss_satellites, component_id); + + // PowerPort + power_port->InitializeWithInitializeFile(file_name); + + GnssReceiver gnss_r(gr_param.prescaler, clock_generator, power_port, component_id, gr_param.gnss_id, gr_param.max_channel, gr_param.antenna_model, + gr_param.antenna_pos_b, gr_param.quaternion_b2c, gr_param.half_width_rad, gr_param.noise_standard_deviation_m, dynamics, + gnss_satellites, simulation_time); + return gnss_r; +} diff --git a/src/components/real/aocs/gnss_receiver.hpp b/src/components/real/aocs/gnss_receiver.hpp index b8c5847c4..1a5ac4e35 100644 --- a/src/components/real/aocs/gnss_receiver.hpp +++ b/src/components/real/aocs/gnss_receiver.hpp @@ -219,4 +219,30 @@ class GnssReceiver : public Component, public ILoggable { void ConvertJulianDayToGPSTime(const double julian_day); }; +/** + * @fn InitGnssReceiver + * @brief Initialize functions for GNSS Receiver without power port + * @param [in] clock_generator: Clock generator + * @param [in] component_id: Sensor ID + * @param [in] file_name: Path to the initialize file + * @param [in] dynamics: Dynamics information + * @param [in] gnss_satellites: GNSS satellites information + * @param [in] simulation_time: Simulation time information + */ +GnssReceiver InitGnssReceiver(ClockGenerator* clock_generator, int component_id, const std::string file_name, const Dynamics* dynamics, + const GnssSatellites* gnss_satellites, const SimulationTime* simulation_time); +/** + * @fn InitGnssReceiver + * @brief Initialize functions for GNSS Receiver with power port + * @param [in] clock_generator: Clock generator + * @param [in] component_id: Sensor ID + * @param [in] power_port: Power port + * @param [in] file_name: Path to the initialize file + * @param [in] dynamics: Dynamics information + * @param [in] gnss_satellites: GNSS satellites information + * @param [in] simulation_time: Simulation time information + */ +GnssReceiver InitGnssReceiver(ClockGenerator* clock_generator, PowerPort* power_port, int component_id, const std::string file_name, + const Dynamics* dynamics, const GnssSatellites* gnss_satellites, const SimulationTime* simulation_time); + #endif // S2E_COMPONENTS_REAL_AOCS_GNSS_RECEIVER_HPP_ diff --git a/src/components/real/aocs/gyro_sensor.cpp b/src/components/real/aocs/gyro_sensor.cpp index 289810b17..b22f99e1f 100644 --- a/src/components/real/aocs/gyro_sensor.cpp +++ b/src/components/real/aocs/gyro_sensor.cpp @@ -5,6 +5,8 @@ #include "gyro_sensor.hpp" +#include + GyroSensor::GyroSensor(const int prescaler, ClockGenerator* clock_generator, Sensor& sensor_base, const unsigned int sensor_id, const libra::Quaternion& quaternion_b2c, const Dynamics* dynamics) : Component(prescaler, clock_generator), Sensor(sensor_base), sensor_id_(sensor_id), quaternion_b2c_(quaternion_b2c), dynamics_(dynamics) {} @@ -42,3 +44,47 @@ std::string GyroSensor::GetLogValue() const { return str_tmp; } + +GyroSensor InitGyroSensor(ClockGenerator* clock_generator, int sensor_id, const std::string file_name, double component_step_time_s, + const Dynamics* dynamics) { + IniAccess gyro_conf(file_name); + const char* sensor_name = "GYRO_SENSOR_"; + const std::string section_name = sensor_name + std::to_string(static_cast(sensor_id)); + const char* GSection = section_name.c_str(); + + libra::Quaternion quaternion_b2c; + gyro_conf.ReadQuaternion(GSection, "quaternion_b2c", quaternion_b2c); + int prescaler = gyro_conf.ReadInt(GSection, "prescaler"); + if (prescaler <= 1) prescaler = 1; + + // Sensor + Sensor sensor_base = + ReadSensorInformation(file_name, component_step_time_s * (double)(prescaler), GSection, "rad_s"); + + GyroSensor gyro(prescaler, clock_generator, sensor_base, sensor_id, quaternion_b2c, dynamics); + + return gyro; +} + +GyroSensor InitGyroSensor(ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const std::string file_name, + double component_step_time_s, const Dynamics* dynamics) { + IniAccess gyro_conf(file_name); + const char* sensor_name = "GYRO_SENSOR_"; + const std::string section_name = sensor_name + std::to_string(static_cast(sensor_id)); + const char* GSection = section_name.c_str(); + + libra::Quaternion quaternion_b2c; + gyro_conf.ReadQuaternion(GSection, "quaternion_b2c", quaternion_b2c); + int prescaler = gyro_conf.ReadInt(GSection, "prescaler"); + if (prescaler <= 1) prescaler = 1; + + // Sensor + Sensor sensor_base = + ReadSensorInformation(file_name, component_step_time_s * (double)(prescaler), GSection, "rad_s"); + + // PowerPort + power_port->InitializeWithInitializeFile(file_name); + + GyroSensor gyro(prescaler, clock_generator, power_port, sensor_base, sensor_id, quaternion_b2c, dynamics); + return gyro; +} diff --git a/src/components/real/aocs/gyro_sensor.hpp b/src/components/real/aocs/gyro_sensor.hpp index 6e1c894b9..f391b2d6e 100644 --- a/src/components/real/aocs/gyro_sensor.hpp +++ b/src/components/real/aocs/gyro_sensor.hpp @@ -86,4 +86,28 @@ class GyroSensor : public Component, public Sensor, public ILogg const Dynamics* dynamics_; //!< Dynamics information }; +/** + * @fn InitGyroSensor + * @brief Initialize functions for gyro sensor without power port + * @param [in] clock_generator: Clock generator + * @param [in] sensor_id: Sensor ID + * @param [in] component_step_time_s: Component step time [sec] + * @param [in] file_name: Path to the initialize file + * @param [in] dynamics: Dynamics information + */ +GyroSensor InitGyroSensor(ClockGenerator* clock_generator, int sensor_id, const std::string file_name, double component_step_time_s, + const Dynamics* dynamics); +/** + * @fn InitGyroSensor + * @brief Initialize functions for gyro sensor with power port + * @param [in] clock_generator: Clock generator + * @param [in] power_port: Power port + * @param [in] sensor_id: Sensor ID + * @param [in] component_step_time_s: Component step time [sec] + * @param [in] file_name: Path to the initialize file + * @param [in] dynamics: Dynamics information + */ +GyroSensor InitGyroSensor(ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const std::string file_name, + double component_step_time_s, const Dynamics* dynamics); + #endif // S2E_COMPONENTS_REAL_AOCS_GYRO_SENSOR_HPP_ diff --git a/src/components/real/aocs/initialize_gnss_receiver.cpp b/src/components/real/aocs/initialize_gnss_receiver.cpp deleted file mode 100644 index c06bf0bfc..000000000 --- a/src/components/real/aocs/initialize_gnss_receiver.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/** - * @file initialize_gnss_receiver.cpp - * @brief Initialize functions for GNSS Receiver - */ -#include "initialize_gnss_receiver.hpp" - -#include - -#include "library/initialize/initialize_file_access.hpp" - -typedef struct _gnssrecever_param { - int prescaler; - AntennaModel antenna_model; - libra::Vector<3> antenna_pos_b; - libra::Quaternion quaternion_b2c; - double half_width_rad; - std::string gnss_id; - int max_channel; - libra::Vector<3> noise_standard_deviation_m; -} GnssReceiverParam; - -GnssReceiverParam ReadGnssReceiverIni(const std::string file_name, const GnssSatellites* gnss_satellites, const int component_id) { - GnssReceiverParam gnss_receiver_param; - - IniAccess gnssr_conf(file_name); - const char* sensor_name = "GNSS_RECEIVER_"; - const std::string section_name = sensor_name + std::to_string(static_cast(component_id)); - const char* GSection = section_name.c_str(); - - int prescaler = gnssr_conf.ReadInt(GSection, "prescaler"); - if (prescaler <= 1) prescaler = 1; - gnss_receiver_param.prescaler = prescaler; - - gnss_receiver_param.antenna_model = static_cast(gnssr_conf.ReadInt(GSection, "antenna_model")); - if (!gnss_satellites->IsCalcEnabled() && gnss_receiver_param.antenna_model == AntennaModel::kCone) { - std::cout << "Calculation of GNSS SATELLITES is DISABLED, so the antenna " - "model of GNSS Receiver is automatically set to SIMPLE model." - << std::endl; - gnss_receiver_param.antenna_model = AntennaModel::kSimple; - } - - gnssr_conf.ReadVector(GSection, "antenna_position_b_m", gnss_receiver_param.antenna_pos_b); - gnssr_conf.ReadQuaternion(GSection, "quaternion_b2c", gnss_receiver_param.quaternion_b2c); - gnss_receiver_param.half_width_rad = gnssr_conf.ReadDouble(GSection, "antenna_half_width_deg"); - gnss_receiver_param.gnss_id = gnssr_conf.ReadString(GSection, "gnss_id"); - gnss_receiver_param.max_channel = gnssr_conf.ReadInt(GSection, "maximum_channel"); - gnssr_conf.ReadVector(GSection, "white_noise_standard_deviation_eci_m", gnss_receiver_param.noise_standard_deviation_m); - - return gnss_receiver_param; -} - -GnssReceiver InitGnssReceiver(ClockGenerator* clock_generator, int component_id, const std::string file_name, const Dynamics* dynamics, - const GnssSatellites* gnss_satellites, const SimulationTime* simulation_time) { - GnssReceiverParam gr_param = ReadGnssReceiverIni(file_name, gnss_satellites, component_id); - - GnssReceiver gnss_r(gr_param.prescaler, clock_generator, component_id, gr_param.gnss_id, gr_param.max_channel, gr_param.antenna_model, - gr_param.antenna_pos_b, gr_param.quaternion_b2c, gr_param.half_width_rad, gr_param.noise_standard_deviation_m, dynamics, - gnss_satellites, simulation_time); - return gnss_r; -} - -GnssReceiver InitGnssReceiver(ClockGenerator* clock_generator, PowerPort* power_port, int component_id, const std::string file_name, - const Dynamics* dynamics, const GnssSatellites* gnss_satellites, const SimulationTime* simulation_time) { - GnssReceiverParam gr_param = ReadGnssReceiverIni(file_name, gnss_satellites, component_id); - - // PowerPort - power_port->InitializeWithInitializeFile(file_name); - - GnssReceiver gnss_r(gr_param.prescaler, clock_generator, power_port, component_id, gr_param.gnss_id, gr_param.max_channel, gr_param.antenna_model, - gr_param.antenna_pos_b, gr_param.quaternion_b2c, gr_param.half_width_rad, gr_param.noise_standard_deviation_m, dynamics, - gnss_satellites, simulation_time); - return gnss_r; -} diff --git a/src/components/real/aocs/initialize_gnss_receiver.hpp b/src/components/real/aocs/initialize_gnss_receiver.hpp deleted file mode 100644 index d2b04bba6..000000000 --- a/src/components/real/aocs/initialize_gnss_receiver.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/** - * @file initialize_gnss_receiver.hpp - * @brief Initialize functions for GNSS Receiver - */ - -#ifndef S2E_COMPONENTS_REAL_AOCS_INITIALIZE_GNSS_RECEIVER_HPP_ -#define S2E_COMPONENTS_REAL_AOCS_INITIALIZE_GNSS_RECEIVER_HPP_ - -#include - -/** - * @fn InitGnssReceiver - * @brief Initialize functions for GNSS Receiver without power port - * @param [in] clock_generator: Clock generator - * @param [in] component_id: Sensor ID - * @param [in] file_name: Path to the initialize file - * @param [in] dynamics: Dynamics information - * @param [in] gnss_satellites: GNSS satellites information - * @param [in] simulation_time: Simulation time information - */ -GnssReceiver InitGnssReceiver(ClockGenerator* clock_generator, int component_id, const std::string file_name, const Dynamics* dynamics, - const GnssSatellites* gnss_satellites, const SimulationTime* simulation_time); -/** - * @fn InitGnssReceiver - * @brief Initialize functions for GNSS Receiver with power port - * @param [in] clock_generator: Clock generator - * @param [in] component_id: Sensor ID - * @param [in] power_port: Power port - * @param [in] file_name: Path to the initialize file - * @param [in] dynamics: Dynamics information - * @param [in] gnss_satellites: GNSS satellites information - * @param [in] simulation_time: Simulation time information - */ -GnssReceiver InitGnssReceiver(ClockGenerator* clock_generator, PowerPort* power_port, int component_id, const std::string file_name, - const Dynamics* dynamics, const GnssSatellites* gnss_satellites, const SimulationTime* simulation_time); - -#endif // S2E_COMPONENTS_REAL_AOCS_INITIALIZE_GNSS_RECEIVER_HPP_ diff --git a/src/components/real/aocs/initialize_gyro_sensor.cpp b/src/components/real/aocs/initialize_gyro_sensor.cpp deleted file mode 100644 index 588ebe587..000000000 --- a/src/components/real/aocs/initialize_gyro_sensor.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/** - * @file initialize_gyro_sensor.cpp - * @brief Initialize functions for gyro sensor - */ -#include "initialize_gyro_sensor.hpp" - -#include - -#include "../../base/initialize_sensor.hpp" - -GyroSensor InitGyroSensor(ClockGenerator* clock_generator, int sensor_id, const std::string file_name, double component_step_time_s, - const Dynamics* dynamics) { - IniAccess gyro_conf(file_name); - const char* sensor_name = "GYRO_SENSOR_"; - const std::string section_name = sensor_name + std::to_string(static_cast(sensor_id)); - const char* GSection = section_name.c_str(); - - libra::Quaternion quaternion_b2c; - gyro_conf.ReadQuaternion(GSection, "quaternion_b2c", quaternion_b2c); - int prescaler = gyro_conf.ReadInt(GSection, "prescaler"); - if (prescaler <= 1) prescaler = 1; - - // Sensor - Sensor sensor_base = - ReadSensorInformation(file_name, component_step_time_s * (double)(prescaler), GSection, "rad_s"); - - GyroSensor gyro(prescaler, clock_generator, sensor_base, sensor_id, quaternion_b2c, dynamics); - - return gyro; -} - -GyroSensor InitGyroSensor(ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const std::string file_name, - double component_step_time_s, const Dynamics* dynamics) { - IniAccess gyro_conf(file_name); - const char* sensor_name = "GYRO_SENSOR_"; - const std::string section_name = sensor_name + std::to_string(static_cast(sensor_id)); - const char* GSection = section_name.c_str(); - - libra::Quaternion quaternion_b2c; - gyro_conf.ReadQuaternion(GSection, "quaternion_b2c", quaternion_b2c); - int prescaler = gyro_conf.ReadInt(GSection, "prescaler"); - if (prescaler <= 1) prescaler = 1; - - // Sensor - Sensor sensor_base = - ReadSensorInformation(file_name, component_step_time_s * (double)(prescaler), GSection, "rad_s"); - - // PowerPort - power_port->InitializeWithInitializeFile(file_name); - - GyroSensor gyro(prescaler, clock_generator, power_port, sensor_base, sensor_id, quaternion_b2c, dynamics); - return gyro; -} diff --git a/src/components/real/aocs/initialize_gyro_sensor.hpp b/src/components/real/aocs/initialize_gyro_sensor.hpp deleted file mode 100644 index bb0db7a6e..000000000 --- a/src/components/real/aocs/initialize_gyro_sensor.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/** - * @file initialize_gyro_sensor.hpp - * @brief Initialize functions for gyro sensor - */ - -#ifndef S2E_COMPONENTS_REAL_AOCS_INITIALIZE_GYRO_SENSOR_HPP_ -#define S2E_COMPONENTS_REAL_AOCS_INITIALIZE_GYRO_SENSOR_HPP_ - -#include - -/** - * @fn InitGyroSensor - * @brief Initialize functions for gyro sensor without power port - * @param [in] clock_generator: Clock generator - * @param [in] sensor_id: Sensor ID - * @param [in] component_step_time_s: Component step time [sec] - * @param [in] file_name: Path to the initialize file - * @param [in] dynamics: Dynamics information - */ -GyroSensor InitGyroSensor(ClockGenerator* clock_generator, int sensor_id, const std::string file_name, double component_step_time_s, - const Dynamics* dynamics); -/** - * @fn InitGyroSensor - * @brief Initialize functions for gyro sensor with power port - * @param [in] clock_generator: Clock generator - * @param [in] power_port: Power port - * @param [in] sensor_id: Sensor ID - * @param [in] component_step_time_s: Component step time [sec] - * @param [in] file_name: Path to the initialize file - * @param [in] dynamics: Dynamics information - */ -GyroSensor InitGyroSensor(ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const std::string file_name, - double component_step_time_s, const Dynamics* dynamics); - -#endif // S2E_COMPONENTS_REAL_AOCS_INITIALIZE_GYRO_SENSOR_HPP_ diff --git a/src/components/real/aocs/initialize_magnetometer.cpp b/src/components/real/aocs/initialize_magnetometer.cpp deleted file mode 100644 index f0a8e3c49..000000000 --- a/src/components/real/aocs/initialize_magnetometer.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/** - * @file initialize_magnetometer.cpp - * @brief Initialize functions for magnetometer - */ -#include "initialize_magnetometer.hpp" - -#include "../../base/initialize_sensor.hpp" -#include "library/initialize/initialize_file_access.hpp" - -Magnetometer InitMagnetometer(ClockGenerator* clock_generator, int sensor_id, const std::string file_name, double component_step_time_s, - const GeomagneticField* geomagnetic_field) { - IniAccess magsensor_conf(file_name); - const char* sensor_name = "MAGNETOMETER_"; - const std::string section_name = sensor_name + std::to_string(static_cast(sensor_id)); - const char* MSSection = section_name.c_str(); - - int prescaler = magsensor_conf.ReadInt(MSSection, "prescaler"); - if (prescaler <= 1) prescaler = 1; - - libra::Quaternion quaternion_b2c; - magsensor_conf.ReadQuaternion(MSSection, "quaternion_b2c", quaternion_b2c); - - // Sensor - Sensor sensor_base = - ReadSensorInformation(file_name, component_step_time_s * (double)(prescaler), MSSection, "nT"); - - Magnetometer magsensor(prescaler, clock_generator, sensor_base, sensor_id, quaternion_b2c, geomagnetic_field); - return magsensor; -} - -Magnetometer InitMagnetometer(ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const std::string file_name, - double component_step_time_s, const GeomagneticField* geomagnetic_field) { - IniAccess magsensor_conf(file_name); - const char* sensor_name = "MAGNETOMETER_"; - const std::string section_name = sensor_name + std::to_string(static_cast(sensor_id)); - const char* MSSection = section_name.c_str(); - - int prescaler = magsensor_conf.ReadInt(MSSection, "prescaler"); - if (prescaler <= 1) prescaler = 1; - - libra::Quaternion quaternion_b2c; - magsensor_conf.ReadQuaternion(MSSection, "quaternion_b2c", quaternion_b2c); - - // Sensor - Sensor sensor_base = - ReadSensorInformation(file_name, component_step_time_s * (double)(prescaler), MSSection, "nT"); - - // PowerPort - power_port->InitializeWithInitializeFile(file_name); - - Magnetometer magsensor(prescaler, clock_generator, power_port, sensor_base, sensor_id, quaternion_b2c, geomagnetic_field); - return magsensor; -} diff --git a/src/components/real/aocs/initialize_magnetometer.hpp b/src/components/real/aocs/initialize_magnetometer.hpp deleted file mode 100644 index 1d1762587..000000000 --- a/src/components/real/aocs/initialize_magnetometer.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/** - * @file initialize_magnetometer.hpp - * @brief Initialize functions for magnetometer - */ - -#ifndef S2E_COMPONENTS_REAL_AOCS_INITIALIZE_MAGNETOMETER_HPP_ -#define S2E_COMPONENTS_REAL_AOCS_INITIALIZE_MAGNETOMETER_HPP_ - -#include - -/** - * @fn InitMagnetometer - * @brief Initialize functions for magnetometer without power port - * @param [in] clock_generator: Clock generator - * @param [in] sensor_id: Sensor ID - * @param [in] file_name: Path to the initialize file - * @param [in] component_step_time_s: Component step time [sec] - * @param [in] geomagnetic_field: Geomegnetic environment - */ -Magnetometer InitMagnetometer(ClockGenerator* clock_generator, int sensor_id, const std::string file_name, double component_step_time_s, - const GeomagneticField* geomagnetic_field); -/** - * @fn InitMagnetometer - * @brief Initialize functions for magnetometer with power port - * @param [in] clock_generator: Clock generator - * @param [in] power_port: Power port - * @param [in] sensor_id: Sensor ID - * @param [in] file_name: Path to the initialize file - * @param [in] component_step_time_s: Component step time [sec] - * @param [in] geomagnetic_field: Geomegnetic environment - */ -Magnetometer InitMagnetometer(ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const std::string file_name, - double component_step_time_s, const GeomagneticField* geomagnetic_field); - -#endif // S2E_COMPONENTS_REAL_AOCS_INITIALIZE_MAGNETOMETER_HPP_ diff --git a/src/components/real/aocs/initialize_magnetorquer.cpp b/src/components/real/aocs/initialize_magnetorquer.cpp deleted file mode 100644 index b446edfc1..000000000 --- a/src/components/real/aocs/initialize_magnetorquer.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/** - * @file initialize_magnetorquer.cpp - * @brief Initialize functions for magnetorquer - */ -#include "initialize_magnetorquer.hpp" - -#include "library/initialize/initialize_file_access.hpp" - -Magnetorquer InitMagnetorquer(ClockGenerator* clock_generator, int actuator_id, const std::string file_name, double component_step_time_s, - const GeomagneticField* geomagnetic_field) { - IniAccess magtorquer_conf(file_name); - const char* sensor_name = "MAGNETORQUER_"; - const std::string section_name = sensor_name + std::to_string(static_cast(actuator_id)); - const char* MTSection = section_name.c_str(); - - int prescaler = magtorquer_conf.ReadInt(MTSection, "prescaler"); - if (prescaler <= 1) prescaler = 1; - - libra::Vector sf_vec; - magtorquer_conf.ReadVector(MTSection, "scale_factor_c", sf_vec); - libra::Matrix scale_factor; - for (size_t i = 0; i < kMtqDimension; i++) { - for (size_t j = 0; j < kMtqDimension; j++) { - scale_factor[i][j] = sf_vec[i * kMtqDimension + j]; - } - } - - libra::Quaternion quaternion_b2c; - magtorquer_conf.ReadQuaternion(MTSection, "quaternion_b2c", quaternion_b2c); - - libra::Vector max_magnetic_moment_c_Am2; - magtorquer_conf.ReadVector(MTSection, "max_output_magnetic_moment_c_Am2", max_magnetic_moment_c_Am2); - - libra::Vector min_magnetic_moment_c_Am2; - magtorquer_conf.ReadVector(MTSection, "min_output_magnetic_moment_c_Am2", min_magnetic_moment_c_Am2); - - libra::Vector bias_noise_c_Am2; - magtorquer_conf.ReadVector(MTSection, "constant_bias_noise_c_Am2", bias_noise_c_Am2); - - double random_walk_step_width_s = component_step_time_s * (double)prescaler; - libra::Vector random_walk_standard_deviation_c_Am2; - magtorquer_conf.ReadVector(MTSection, "random_walk_standard_deviation_c_Am2", random_walk_standard_deviation_c_Am2); - libra::Vector random_walk_limit_c_Am2; - magtorquer_conf.ReadVector(MTSection, "random_walk_limit_c_Am2", random_walk_limit_c_Am2); - libra::Vector normal_random_standard_deviation_c_Am2; - magtorquer_conf.ReadVector(MTSection, "white_noise_standard_deviation_c_Am2", normal_random_standard_deviation_c_Am2); - - Magnetorquer magtorquer(prescaler, clock_generator, actuator_id, quaternion_b2c, scale_factor, max_magnetic_moment_c_Am2, min_magnetic_moment_c_Am2, - bias_noise_c_Am2, random_walk_step_width_s, random_walk_standard_deviation_c_Am2, random_walk_limit_c_Am2, - normal_random_standard_deviation_c_Am2, geomagnetic_field); - return magtorquer; -} - -Magnetorquer InitMagnetorquer(ClockGenerator* clock_generator, PowerPort* power_port, int actuator_id, const std::string file_name, - double component_step_time_s, const GeomagneticField* geomagnetic_field) { - IniAccess magtorquer_conf(file_name); - const char* sensor_name = "MAGNETORQUER_"; - const std::string section_name = sensor_name + std::to_string(static_cast(actuator_id)); - const char* MTSection = section_name.c_str(); - - int prescaler = magtorquer_conf.ReadInt(MTSection, "prescaler"); - if (prescaler <= 1) prescaler = 1; - - libra::Vector sf_vec; - magtorquer_conf.ReadVector(MTSection, "scale_factor_c", sf_vec); - libra::Matrix scale_factor; - for (size_t i = 0; i < kMtqDimension; i++) { - for (size_t j = 0; j < kMtqDimension; j++) { - scale_factor[i][j] = sf_vec[i * kMtqDimension + j]; - } - } - - libra::Quaternion quaternion_b2c; - magtorquer_conf.ReadQuaternion(MTSection, "quaternion_b2c", quaternion_b2c); - - libra::Vector max_magnetic_moment_c_Am2; - magtorquer_conf.ReadVector(MTSection, "max_output_magnetic_moment_c_Am2", max_magnetic_moment_c_Am2); - - libra::Vector min_magnetic_moment_c_Am2; - magtorquer_conf.ReadVector(MTSection, "min_output_magnetic_moment_c_Am2", min_magnetic_moment_c_Am2); - - libra::Vector bias_noise_c_Am2; - magtorquer_conf.ReadVector(MTSection, "constant_bias_noise_c_Am2", bias_noise_c_Am2); - - double random_walk_step_width_s = component_step_time_s * (double)prescaler; - libra::Vector random_walk_standard_deviation_c_Am2; - magtorquer_conf.ReadVector(MTSection, "random_walk_standard_deviation_c_Am2", random_walk_standard_deviation_c_Am2); - libra::Vector random_walk_limit_c_Am2; - magtorquer_conf.ReadVector(MTSection, "random_walk_limit_c_Am2", random_walk_limit_c_Am2); - libra::Vector normal_random_standard_deviation_c_Am2; - magtorquer_conf.ReadVector(MTSection, "white_noise_standard_deviation_c_Am2", normal_random_standard_deviation_c_Am2); - - // PowerPort - power_port->InitializeWithInitializeFile(file_name); - - Magnetorquer magtorquer(prescaler, clock_generator, power_port, actuator_id, quaternion_b2c, scale_factor, max_magnetic_moment_c_Am2, - min_magnetic_moment_c_Am2, bias_noise_c_Am2, random_walk_step_width_s, random_walk_standard_deviation_c_Am2, - random_walk_limit_c_Am2, normal_random_standard_deviation_c_Am2, geomagnetic_field); - return magtorquer; -} diff --git a/src/components/real/aocs/initialize_magnetorquer.hpp b/src/components/real/aocs/initialize_magnetorquer.hpp deleted file mode 100644 index c45f1aa47..000000000 --- a/src/components/real/aocs/initialize_magnetorquer.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/** - * @file initialize_magnetorquer.hpp - * @brief Initialize functions for magnetorquer - */ - -#ifndef S2E_COMPONENTS_REAL_AOCS_INITIALIZE_MAGNETORQUER_HPP_ -#define S2E_COMPONENTS_REAL_AOCS_INITIALIZE_MAGNETORQUER_HPP_ - -#include - -/** - * @fn InitMagnetorquer - * @brief Initialize functions for magnetometer without power port - * @param [in] clock_generator: Clock generator - * @param [in] actuator_id: Actuator ID - * @param [in] file_name: Path to the initialize file - * @param [in] component_step_time_s: Component step time [sec] - * @param [in] geomagnetic_field: Geomegnetic environment - */ -Magnetorquer InitMagnetorquer(ClockGenerator* clock_generator, int actuator_id, const std::string file_name, double component_step_time_s, - const GeomagneticField* geomagnetic_field); -/** - * @fn InitMagnetorquer - * @brief Initialize functions for magnetometer with power port - * @param [in] clock_generator: Clock generator - * @param [in] power_port: Power port - * @param [in] actuator_id: Actuator ID - * @param [in] file_name: Path to the initialize file - * @param [in] component_step_time_s: Component step time [sec] - * @param [in] geomagnetic_field: Geomegnetic environment - */ -Magnetorquer InitMagnetorquer(ClockGenerator* clock_generator, PowerPort* power_port, int actuator_id, const std::string file_name, - double component_step_time_s, const GeomagneticField* geomagnetic_field); - -#endif // S2E_COMPONENTS_REAL_AOCS_INITIALIZE_MAGNETORQUER_HPP_ diff --git a/src/components/real/aocs/initialize_reaction_wheel.cpp b/src/components/real/aocs/initialize_reaction_wheel.cpp deleted file mode 100644 index e3ae9d357..000000000 --- a/src/components/real/aocs/initialize_reaction_wheel.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/** - * @file initialize_reaction_wheel.cpp - * @brief Initialize functions for Reaction Wheel - */ -#include "initialize_reaction_wheel.hpp" - -#include - -#include "library/initialize/initialize_file_access.hpp" - -// In order to share processing among initialization functions, variables should also be shared. These variables have internal linkages and cannot be -// referenced from the outside. -namespace { -int prescaler; -int fast_prescaler; -double step_width_s; -double main_routine_time_step_s; -double jitter_update_interval_s; -double rotor_inertia_kgm2; -double max_torque_Nm; -double max_velocity; -libra::Quaternion quaternion_b2c; -libra::Vector<3> position_b_m; -double dead_time_s; -libra::Vector<3> ordinary_lag_coef(1.0); -libra::Vector<3> coasting_lag_coefficients(1.0); -bool is_calc_jitter_enabled; -bool is_log_jitter_enabled; -std::vector> radial_force_harmonics_coefficients; -std::vector> radial_torque_harmonics_coefficients; -double structural_resonance_frequency_Hz; -double damping_factor; -double bandwidth; -bool considers_structural_resonance; -bool drive_flag; -double init_velocity_rad_s; - -void InitParams(int actuator_id, std::string file_name, double prop_step, double compo_update_step) { - // Access Parameters - IniAccess rwmodel_conf(file_name); - const std::string st_actuator_num = std::to_string(static_cast(actuator_id)); - const char* cs = st_actuator_num.data(); - std::string section_tmp = "REACTION_WHEEL_"; - section_tmp += cs; - const char* RWsection = section_tmp.data(); - - // Read ini file - prescaler = rwmodel_conf.ReadInt(RWsection, "prescaler"); - if (prescaler <= 1) prescaler = 1; - fast_prescaler = rwmodel_conf.ReadInt(RWsection, "fast_prescaler"); - if (fast_prescaler <= 1) fast_prescaler = 1; - rotor_inertia_kgm2 = rwmodel_conf.ReadDouble(RWsection, "moment_of_inertia_kgm2"); - max_torque_Nm = rwmodel_conf.ReadDouble(RWsection, "max_output_torque_Nm"); - max_velocity = rwmodel_conf.ReadDouble(RWsection, "max_angular_velocity_rpm"); - - std::string direction_determination_mode; - direction_determination_mode = rwmodel_conf.ReadString(RWsection, "direction_determination_mode"); - if (direction_determination_mode == "QUATERNION") { - rwmodel_conf.ReadQuaternion(RWsection, "quaternion_b2c", quaternion_b2c); - } else // direction_determination_mode == "DIRECTION" - { - libra::Vector<3> direction_b; - rwmodel_conf.ReadVector(RWsection, "direction_b", direction_b); - libra::Vector<3> direction_c(0.0); - direction_c[2] = 1.0; - libra::Quaternion q(direction_b, direction_c); - quaternion_b2c = q.Conjugate(); - } - - rwmodel_conf.ReadVector(RWsection, "position_b_m", position_b_m); - dead_time_s = rwmodel_conf.ReadDouble(RWsection, "dead_time_s"); - // rwmodel_conf.ReadVector(RWsection, "first_order_lag_coefficient", ordinary_lag_coef); // TODO: Fix bug - // rwmodel_conf.ReadVector(RWsection, "coasting_lag_coefficient", coasting_lag_coefficients); // TODO: Fix bug - - is_calc_jitter_enabled = rwmodel_conf.ReadEnable(RWsection, "jitter_calculation"); - is_log_jitter_enabled = rwmodel_conf.ReadEnable(RWsection, "jitter_logging"); - - std::string radial_force_harmonics_coef_path = rwmodel_conf.ReadString(RWsection, "radial_force_harmonics_coefficient_file"); - std::string radial_torque_harmonics_coef_path = rwmodel_conf.ReadString(RWsection, "radial_torque_harmonics_coefficient_file"); - int harmonics_degree = rwmodel_conf.ReadInt(RWsection, "harmonics_degree"); - IniAccess conf_radial_force_harmonics(radial_force_harmonics_coef_path); - IniAccess conf_radial_torque_harmonics(radial_torque_harmonics_coef_path); - conf_radial_force_harmonics.ReadCsvDouble(radial_force_harmonics_coefficients, harmonics_degree); - conf_radial_torque_harmonics.ReadCsvDouble(radial_torque_harmonics_coefficients, harmonics_degree); - - structural_resonance_frequency_Hz = rwmodel_conf.ReadDouble(RWsection, "structural_resonance_frequency_Hz"); - damping_factor = rwmodel_conf.ReadDouble(RWsection, "damping_factor"); - bandwidth = rwmodel_conf.ReadDouble(RWsection, "bandwidth"); - considers_structural_resonance = rwmodel_conf.ReadEnable(RWsection, "considers_structural_resonance"); - - drive_flag = rwmodel_conf.ReadBoolean(RWsection, "initial_motor_drive_flag"); - init_velocity_rad_s = rwmodel_conf.ReadDouble(RWsection, "initial_angular_velocity_rad_s"); - - // Calc periods - step_width_s = prop_step; - main_routine_time_step_s = prescaler * compo_update_step; - jitter_update_interval_s = fast_prescaler * compo_update_step; -} -} // namespace - -ReactionWheel InitReactionWheel(ClockGenerator* clock_generator, int actuator_id, std::string file_name, double prop_step, double compo_update_step) { - InitParams(actuator_id, file_name, prop_step, compo_update_step); - - ReactionWheel rwmodel(prescaler, fast_prescaler, clock_generator, actuator_id, step_width_s, main_routine_time_step_s, jitter_update_interval_s, - rotor_inertia_kgm2, max_torque_Nm, max_velocity, quaternion_b2c, position_b_m, dead_time_s, ordinary_lag_coef, - coasting_lag_coefficients, is_calc_jitter_enabled, is_log_jitter_enabled, radial_force_harmonics_coefficients, - radial_torque_harmonics_coefficients, structural_resonance_frequency_Hz, damping_factor, bandwidth, - considers_structural_resonance, drive_flag, init_velocity_rad_s); - - return rwmodel; -} - -ReactionWheel InitReactionWheel(ClockGenerator* clock_generator, PowerPort* power_port, int actuator_id, std::string file_name, double prop_step, - double compo_update_step) { - InitParams(actuator_id, file_name, prop_step, compo_update_step); - - power_port->InitializeWithInitializeFile(file_name); - - ReactionWheel rwmodel(prescaler, fast_prescaler, clock_generator, power_port, actuator_id, step_width_s, main_routine_time_step_s, - jitter_update_interval_s, rotor_inertia_kgm2, max_torque_Nm, max_velocity, quaternion_b2c, position_b_m, dead_time_s, - ordinary_lag_coef, coasting_lag_coefficients, is_calc_jitter_enabled, is_log_jitter_enabled, - radial_force_harmonics_coefficients, radial_torque_harmonics_coefficients, structural_resonance_frequency_Hz, damping_factor, - bandwidth, considers_structural_resonance, drive_flag, init_velocity_rad_s); - - return rwmodel; -} diff --git a/src/components/real/aocs/initialize_reaction_wheel.hpp b/src/components/real/aocs/initialize_reaction_wheel.hpp deleted file mode 100644 index 2e00ef137..000000000 --- a/src/components/real/aocs/initialize_reaction_wheel.hpp +++ /dev/null @@ -1,34 +0,0 @@ -/** - * @file initialize_reaction_wheel.hpp - * @brief Initialize functions for Reaction Wheel - */ - -#ifndef S2E_COMPONENTS_REAL_AOCS_INITIALIZE_REACTION_WHEEL_HPP_ -#define S2E_COMPONENTS_REAL_AOCS_INITIALIZE_REACTION_WHEEL_HPP_ - -#include - -/** - * @fn InitReactionWheel - * @brief Initialize functions for reaction wheel without power port - * @param [in] clock_generator: Clock generator - * @param [in] actuator_id: Actuator ID - * @param [in] file_name: Path to the initialize file - * @param [in] prop_step: Propagation step for RW dynamics [sec] - * @param [in] compo_update_step: Component step time [sec] - */ -ReactionWheel InitReactionWheel(ClockGenerator* clock_generator, int actuator_id, std::string file_name, double prop_step, double compo_update_step); -/** - * @fn InitReactionWheel - * @brief Initialize functions for reaction wheel with power port - * @param [in] clock_generator: Clock generator - * @param [in] power_port: Power port - * @param [in] actuator_id: Actuator ID - * @param [in] file_name: Path to the initialize file - * @param [in] prop_step: Propagation step for RW dynamics [sec] - * @param [in] compo_update_step: Component step time [sec] - */ -ReactionWheel InitReactionWheel(ClockGenerator* clock_generator, PowerPort* power_port, int actuator_id, std::string file_name, double prop_step, - double compo_update_step); - -#endif // S2E_COMPONENTS_REAL_AOCS_INITIALIZE_REACTION_WHEEL_HPP_ diff --git a/src/components/real/aocs/initialize_star_sensor.cpp b/src/components/real/aocs/initialize_star_sensor.cpp deleted file mode 100644 index 84f5b9016..000000000 --- a/src/components/real/aocs/initialize_star_sensor.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/** - * @file initialize_star_sensor.cpp - * @brief Initialize functions for star sensor - */ -#include "initialize_star_sensor.hpp" - -#include - -#include "library/initialize/initialize_file_access.hpp" - -using namespace std; - -StarSensor InitStarSensor(ClockGenerator* clock_generator, int sensor_id, const string file_name, double component_step_time_s, - const Dynamics* dynamics, const LocalEnvironment* local_environment) { - IniAccess STT_conf(file_name); - const char* sensor_name = "STAR_SENSOR_"; - const std::string section_name = sensor_name + std::to_string(static_cast(sensor_id)); - const char* STTSection = section_name.c_str(); - - int prescaler = STT_conf.ReadInt(STTSection, "prescaler"); - if (prescaler <= 1) prescaler = 1; - double step_time_s = component_step_time_s * prescaler; - libra::Quaternion quaternion_b2c; - STT_conf.ReadQuaternion(STTSection, "quaternion_b2c", quaternion_b2c); - double standard_deviation_orthogonal_direction = STT_conf.ReadDouble(STTSection, "standard_deviation_orthogonal_direction_rad"); - double standard_deviation_sight_direction = STT_conf.ReadDouble(STTSection, "standard_deviation_sight_direction_rad"); - double output_delay_sec = STT_conf.ReadDouble(STTSection, "output_delay_s"); - int output_delay = max(int(output_delay_sec / step_time_s), 1); - double output_interval_sec = STT_conf.ReadDouble(STTSection, "output_interval_s"); - int output_interval = max(int(output_interval_sec / step_time_s), 1); - double sun_forbidden_angle_deg = STT_conf.ReadDouble(STTSection, "sun_exclusion_angle_deg"); - double sun_forbidden_angle_rad = sun_forbidden_angle_deg * libra::pi / 180.0; - double earth_forbidden_angle_deg = STT_conf.ReadDouble(STTSection, "earth_exclusion_angle_deg"); - double earth_forbidden_angle_rad = earth_forbidden_angle_deg * libra::pi / 180.0; - double moon_forbidden_angle_deg = STT_conf.ReadDouble(STTSection, "moon_exclusion_angle_deg"); - double moon_forbidden_angle_rad = moon_forbidden_angle_deg * libra::pi / 180.0; - double capture_rate_deg_s = STT_conf.ReadDouble(STTSection, "angular_rate_limit_deg_s"); - double capture_rate_rad_s = capture_rate_deg_s * libra::pi / 180.0; - - StarSensor stt(prescaler, clock_generator, sensor_id, quaternion_b2c, standard_deviation_orthogonal_direction, standard_deviation_sight_direction, - step_time_s, output_delay, output_interval, sun_forbidden_angle_rad, earth_forbidden_angle_rad, moon_forbidden_angle_rad, - capture_rate_rad_s, dynamics, local_environment); - return stt; -} - -StarSensor InitStarSensor(ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const string file_name, double component_step_time_s, - const Dynamics* dynamics, const LocalEnvironment* local_environment) { - IniAccess STT_conf(file_name); - const char* sensor_name = "STAR_SENSOR_"; - const std::string section_name = sensor_name + std::to_string(static_cast(sensor_id)); - const char* STTSection = section_name.c_str(); - - int prescaler = STT_conf.ReadInt(STTSection, "prescaler"); - if (prescaler <= 1) prescaler = 1; - double step_time_s = component_step_time_s * prescaler; - - libra::Quaternion quaternion_b2c; - STT_conf.ReadQuaternion(STTSection, "quaternion_b2c", quaternion_b2c); - double standard_deviation_orthogonal_direction = STT_conf.ReadDouble(STTSection, "standard_deviation_orthogonal_direction_rad"); - double standard_deviation_sight_direction = STT_conf.ReadDouble(STTSection, "standard_deviation_sight_direction_rad"); - double output_delay_sec = STT_conf.ReadDouble(STTSection, "output_delay_s"); - int output_delay = max(int(output_delay_sec / step_time_s), 1); - double output_interval_sec = STT_conf.ReadDouble(STTSection, "output_interval_s"); - int output_interval = max(int(output_interval_sec / step_time_s), 1); - double sun_forbidden_angle_deg = STT_conf.ReadDouble(STTSection, "sun_exclusion_angle_deg"); - double sun_forbidden_angle_rad = sun_forbidden_angle_deg * libra::pi / 180.0; - double earth_forbidden_angle_deg = STT_conf.ReadDouble(STTSection, "earth_exclusion_angle_deg"); - double earth_forbidden_angle_rad = earth_forbidden_angle_deg * libra::pi / 180.0; - double moon_forbidden_angle_deg = STT_conf.ReadDouble(STTSection, "moon_exclusion_angle_deg"); - double moon_forbidden_angle_rad = moon_forbidden_angle_deg * libra::pi / 180.0; - double capture_rate_deg_s = STT_conf.ReadDouble(STTSection, "angular_rate_limit_deg_s"); - double capture_rate_rad_s = capture_rate_deg_s * libra::pi / 180.0; - - power_port->InitializeWithInitializeFile(file_name); - - StarSensor stt(prescaler, clock_generator, power_port, sensor_id, quaternion_b2c, standard_deviation_orthogonal_direction, - standard_deviation_sight_direction, step_time_s, output_delay, output_interval, sun_forbidden_angle_rad, earth_forbidden_angle_rad, - moon_forbidden_angle_rad, capture_rate_rad_s, dynamics, local_environment); - return stt; -} diff --git a/src/components/real/aocs/initialize_star_sensor.hpp b/src/components/real/aocs/initialize_star_sensor.hpp deleted file mode 100644 index 6a3652d35..000000000 --- a/src/components/real/aocs/initialize_star_sensor.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/** - * @file initialize_star_sensor.hpp - * @brief Initialize functions for star sensor - */ - -#ifndef S2E_COMPONENTS_REAL_AOCS_INITIALIZE_STAR_SENSOR_HPP_ -#define S2E_COMPONENTS_REAL_AOCS_INITIALIZE_STAR_SENSOR_HPP_ - -#include - -/** - * @fn InitStarSensor - * @brief Initialize functions for StarSensor without power port - * @param [in] clock_generator: Clock generator - * @param [in] sensor_id: Sensor ID - * @param [in] file_name: Path to the initialize file - * @param [in] component_step_time_s: Component step time [sec] - * @param [in] dynamics: Dynamics information - * @param [in] local_environment: Local environment information - */ -StarSensor InitStarSensor(ClockGenerator* clock_generator, int sensor_id, const std::string file_name, double component_step_time_s, - const Dynamics* dynamics, const LocalEnvironment* local_environment); -/** - * @fn InitStarSensor - * @brief Initialize functions for StarSensor with power port - * @param [in] clock_generator: Clock generator - * @param [in] power_port: Power port - * @param [in] sensor_id: Sensor ID - * @param [in] file_name: Path to the initialize file - * @param [in] component_step_time_s: Component step time [sec] - * @param [in] dynamics: Dynamics information - * @param [in] local_environment: Local environment information - */ -StarSensor InitStarSensor(ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const std::string file_name, - double component_step_time_s, const Dynamics* dynamics, const LocalEnvironment* local_environment); - -#endif // S2E_COMPONENTS_REAL_AOCS_INITIALIZE_STAR_SENSOR_HPP_ diff --git a/src/components/real/aocs/initialize_sun_sensor.cpp b/src/components/real/aocs/initialize_sun_sensor.cpp deleted file mode 100644 index e9028e6e6..000000000 --- a/src/components/real/aocs/initialize_sun_sensor.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/** - * @file initialize_sun_sensor.cpp - * @brief Initialize functions for sun sensor - */ -#include "initialize_sun_sensor.hpp" - -#include - -#include - -#include "library/initialize/initialize_file_access.hpp" - -SunSensor InitSunSensor(ClockGenerator* clock_generator, int ss_id, std::string file_name, const SolarRadiationPressureEnvironment* srp_environment, - const LocalCelestialInformation* local_celestial_information) { - IniAccess ss_conf(file_name); - const char* sensor_name = "SUN_SENSOR_"; - const std::string section_tmp = sensor_name + std::to_string(static_cast(ss_id)); - const char* Section = section_tmp.c_str(); - - int prescaler = ss_conf.ReadInt(Section, "prescaler"); - if (prescaler <= 1) prescaler = 1; - - libra::Quaternion quaternion_b2c; - ss_conf.ReadQuaternion(Section, "quaternion_b2c", quaternion_b2c); - - double detectable_angle_deg = 0.0, detectable_angle_rad = 0.0; - detectable_angle_deg = ss_conf.ReadDouble(Section, "field_of_view_deg"); - detectable_angle_rad = libra::pi / 180.0 * detectable_angle_deg; - - double nr_stddev = 0.0; - nr_stddev = ss_conf.ReadDouble(Section, "white_noise_standard_deviation_deg"); - nr_stddev *= libra::pi / 180.0; - - double nr_bias_stddev = 0.0; - nr_bias_stddev = ss_conf.ReadDouble(Section, "bias_standard_deviation_deg"); - nr_bias_stddev *= libra::pi / 180.0; - - double intensity_lower_threshold_percent; - intensity_lower_threshold_percent = ss_conf.ReadDouble(Section, "intensity_lower_threshold_percent"); - - SunSensor ss(prescaler, clock_generator, ss_id, quaternion_b2c, detectable_angle_rad, nr_stddev, nr_bias_stddev, intensity_lower_threshold_percent, - srp_environment, local_celestial_information); - return ss; -} - -SunSensor InitSunSensor(ClockGenerator* clock_generator, PowerPort* power_port, int ss_id, std::string file_name, - const SolarRadiationPressureEnvironment* srp_environment, const LocalCelestialInformation* local_celestial_information) { - IniAccess ss_conf(file_name); - const char* sensor_name = "SUN_SENSOR_"; - const std::string section_tmp = sensor_name + std::to_string(static_cast(ss_id)); - const char* Section = section_tmp.c_str(); - - int prescaler = ss_conf.ReadInt(Section, "prescaler"); - if (prescaler <= 1) prescaler = 1; - - libra::Quaternion quaternion_b2c; - ss_conf.ReadQuaternion(Section, "quaternion_b2c", quaternion_b2c); - - double detectable_angle_deg = 0.0, detectable_angle_rad = 0.0; - detectable_angle_deg = ss_conf.ReadDouble(Section, "field_of_view_deg"); - detectable_angle_rad = libra::pi / 180.0 * detectable_angle_deg; - - double nr_stddev = 0.0; - nr_stddev = ss_conf.ReadDouble(Section, "white_noise_standard_deviation_deg"); - nr_stddev *= libra::pi / 180.0; - - double nr_bias_stddev = 0.0; - nr_bias_stddev = ss_conf.ReadDouble(Section, "bias_standard_deviation_deg"); - nr_bias_stddev *= libra::pi / 180.0; - - double intensity_lower_threshold_percent; - intensity_lower_threshold_percent = ss_conf.ReadDouble(Section, "intensity_lower_threshold_percent"); - - power_port->InitializeWithInitializeFile(file_name); - - SunSensor ss(prescaler, clock_generator, power_port, ss_id, quaternion_b2c, detectable_angle_rad, nr_stddev, nr_bias_stddev, - intensity_lower_threshold_percent, srp_environment, local_celestial_information); - return ss; -} diff --git a/src/components/real/aocs/initialize_sun_sensor.hpp b/src/components/real/aocs/initialize_sun_sensor.hpp deleted file mode 100644 index b162f498e..000000000 --- a/src/components/real/aocs/initialize_sun_sensor.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/** - * @file initialize_sun_sensor.hpp - * @brief Initialize functions for sun sensor - */ - -#ifndef S2E_COMPONENTS_REAL_AOCS_INITIALIZE_SUN_SENSOR_HPP_ -#define S2E_COMPONENTS_REAL_AOCS_INITIALIZE_SUN_SENSOR_HPP_ - -#include - -/** - * @fn InitSunSensor - * @brief Initialize functions for sun sensor without power port - * @param [in] clock_generator: Clock generator - * @param [in] sensor_id: Sensor ID - * @param [in] file_name: Path to the initialize file - * @param [in] srp_environment: Solar radiation pressure environment - * @param [in] local_environment: Local environment information - */ -SunSensor InitSunSensor(ClockGenerator* clock_generator, int sensor_id, const std::string file_name, - const SolarRadiationPressureEnvironment* srp_environment, const LocalCelestialInformation* local_celestial_information); -/** - * @fn InitSunSensor - * @brief Initialize functions for sun sensor with power port - * @param [in] clock_generator: Clock generator - * @param [in] power_port: Power port - * @param [in] sensor_id: Sensor ID - * @param [in] file_name: Path to the initialize file - * @param [in] srp_environment: Solar radiation pressure environment - * @param [in] local_environment: Local environment information - */ -SunSensor InitSunSensor(ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const std::string file_name, - const SolarRadiationPressureEnvironment* srp_environment, const LocalCelestialInformation* local_celestial_information); - -#endif // S2E_COMPONENTS_REAL_AOCS_INITIALIZE_SUN_SENSOR_HPP_ diff --git a/src/components/real/aocs/magnetometer.cpp b/src/components/real/aocs/magnetometer.cpp index ecc4410c4..d6e44b9d1 100644 --- a/src/components/real/aocs/magnetometer.cpp +++ b/src/components/real/aocs/magnetometer.cpp @@ -4,6 +4,7 @@ */ #include "magnetometer.hpp" +#include #include Magnetometer::Magnetometer(int prescaler, ClockGenerator* clock_generator, Sensor& sensor_base, const unsigned int sensor_id, @@ -45,3 +46,48 @@ std::string Magnetometer::GetLogValue() const { return str_tmp; } + +Magnetometer InitMagnetometer(ClockGenerator* clock_generator, int sensor_id, const std::string file_name, double component_step_time_s, + const GeomagneticField* geomagnetic_field) { + IniAccess magsensor_conf(file_name); + const char* sensor_name = "MAGNETOMETER_"; + const std::string section_name = sensor_name + std::to_string(static_cast(sensor_id)); + const char* MSSection = section_name.c_str(); + + int prescaler = magsensor_conf.ReadInt(MSSection, "prescaler"); + if (prescaler <= 1) prescaler = 1; + + libra::Quaternion quaternion_b2c; + magsensor_conf.ReadQuaternion(MSSection, "quaternion_b2c", quaternion_b2c); + + // Sensor + Sensor sensor_base = + ReadSensorInformation(file_name, component_step_time_s * (double)(prescaler), MSSection, "nT"); + + Magnetometer magsensor(prescaler, clock_generator, sensor_base, sensor_id, quaternion_b2c, geomagnetic_field); + return magsensor; +} + +Magnetometer InitMagnetometer(ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const std::string file_name, + double component_step_time_s, const GeomagneticField* geomagnetic_field) { + IniAccess magsensor_conf(file_name); + const char* sensor_name = "MAGNETOMETER_"; + const std::string section_name = sensor_name + std::to_string(static_cast(sensor_id)); + const char* MSSection = section_name.c_str(); + + int prescaler = magsensor_conf.ReadInt(MSSection, "prescaler"); + if (prescaler <= 1) prescaler = 1; + + libra::Quaternion quaternion_b2c; + magsensor_conf.ReadQuaternion(MSSection, "quaternion_b2c", quaternion_b2c); + + // Sensor + Sensor sensor_base = + ReadSensorInformation(file_name, component_step_time_s * (double)(prescaler), MSSection, "nT"); + + // PowerPort + power_port->InitializeWithInitializeFile(file_name); + + Magnetometer magsensor(prescaler, clock_generator, power_port, sensor_base, sensor_id, quaternion_b2c, geomagnetic_field); + return magsensor; +} diff --git a/src/components/real/aocs/magnetometer.hpp b/src/components/real/aocs/magnetometer.hpp index 1b621c27e..c352b0553 100644 --- a/src/components/real/aocs/magnetometer.hpp +++ b/src/components/real/aocs/magnetometer.hpp @@ -105,4 +105,28 @@ class Magnetometer : public Component, public Sensor, pu const GeomagneticField* geomagnetic_field_; //!< Geomagnetic environment }; +/** + * @fn InitMagnetometer + * @brief Initialize functions for magnetometer without power port + * @param [in] clock_generator: Clock generator + * @param [in] sensor_id: Sensor ID + * @param [in] file_name: Path to the initialize file + * @param [in] component_step_time_s: Component step time [sec] + * @param [in] geomagnetic_field: Geomegnetic environment + */ +Magnetometer InitMagnetometer(ClockGenerator* clock_generator, int sensor_id, const std::string file_name, double component_step_time_s, + const GeomagneticField* geomagnetic_field); +/** + * @fn InitMagnetometer + * @brief Initialize functions for magnetometer with power port + * @param [in] clock_generator: Clock generator + * @param [in] power_port: Power port + * @param [in] sensor_id: Sensor ID + * @param [in] file_name: Path to the initialize file + * @param [in] component_step_time_s: Component step time [sec] + * @param [in] geomagnetic_field: Geomegnetic environment + */ +Magnetometer InitMagnetometer(ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const std::string file_name, + double component_step_time_s, const GeomagneticField* geomagnetic_field); + #endif // S2E_COMPONENTS_REAL_AOCS_MAGNETOMETER_HPP_ diff --git a/src/components/real/aocs/magnetorquer.cpp b/src/components/real/aocs/magnetorquer.cpp index 7cbc1540a..ab47dc6d1 100644 --- a/src/components/real/aocs/magnetorquer.cpp +++ b/src/components/real/aocs/magnetorquer.cpp @@ -5,6 +5,7 @@ #include "magnetorquer.hpp" +#include #include #include #include @@ -109,3 +110,96 @@ std::string Magnetorquer::GetLogValue() const { return str_tmp; } + +Magnetorquer InitMagnetorquer(ClockGenerator* clock_generator, int actuator_id, const std::string file_name, double component_step_time_s, + const GeomagneticField* geomagnetic_field) { + IniAccess magtorquer_conf(file_name); + const char* sensor_name = "MAGNETORQUER_"; + const std::string section_name = sensor_name + std::to_string(static_cast(actuator_id)); + const char* MTSection = section_name.c_str(); + + int prescaler = magtorquer_conf.ReadInt(MTSection, "prescaler"); + if (prescaler <= 1) prescaler = 1; + + libra::Vector sf_vec; + magtorquer_conf.ReadVector(MTSection, "scale_factor_c", sf_vec); + libra::Matrix scale_factor; + for (size_t i = 0; i < kMtqDimension; i++) { + for (size_t j = 0; j < kMtqDimension; j++) { + scale_factor[i][j] = sf_vec[i * kMtqDimension + j]; + } + } + + libra::Quaternion quaternion_b2c; + magtorquer_conf.ReadQuaternion(MTSection, "quaternion_b2c", quaternion_b2c); + + libra::Vector max_magnetic_moment_c_Am2; + magtorquer_conf.ReadVector(MTSection, "max_output_magnetic_moment_c_Am2", max_magnetic_moment_c_Am2); + + libra::Vector min_magnetic_moment_c_Am2; + magtorquer_conf.ReadVector(MTSection, "min_output_magnetic_moment_c_Am2", min_magnetic_moment_c_Am2); + + libra::Vector bias_noise_c_Am2; + magtorquer_conf.ReadVector(MTSection, "constant_bias_noise_c_Am2", bias_noise_c_Am2); + + double random_walk_step_width_s = component_step_time_s * (double)prescaler; + libra::Vector random_walk_standard_deviation_c_Am2; + magtorquer_conf.ReadVector(MTSection, "random_walk_standard_deviation_c_Am2", random_walk_standard_deviation_c_Am2); + libra::Vector random_walk_limit_c_Am2; + magtorquer_conf.ReadVector(MTSection, "random_walk_limit_c_Am2", random_walk_limit_c_Am2); + libra::Vector normal_random_standard_deviation_c_Am2; + magtorquer_conf.ReadVector(MTSection, "white_noise_standard_deviation_c_Am2", normal_random_standard_deviation_c_Am2); + + Magnetorquer magtorquer(prescaler, clock_generator, actuator_id, quaternion_b2c, scale_factor, max_magnetic_moment_c_Am2, min_magnetic_moment_c_Am2, + bias_noise_c_Am2, random_walk_step_width_s, random_walk_standard_deviation_c_Am2, random_walk_limit_c_Am2, + normal_random_standard_deviation_c_Am2, geomagnetic_field); + return magtorquer; +} + +Magnetorquer InitMagnetorquer(ClockGenerator* clock_generator, PowerPort* power_port, int actuator_id, const std::string file_name, + double component_step_time_s, const GeomagneticField* geomagnetic_field) { + IniAccess magtorquer_conf(file_name); + const char* sensor_name = "MAGNETORQUER_"; + const std::string section_name = sensor_name + std::to_string(static_cast(actuator_id)); + const char* MTSection = section_name.c_str(); + + int prescaler = magtorquer_conf.ReadInt(MTSection, "prescaler"); + if (prescaler <= 1) prescaler = 1; + + libra::Vector sf_vec; + magtorquer_conf.ReadVector(MTSection, "scale_factor_c", sf_vec); + libra::Matrix scale_factor; + for (size_t i = 0; i < kMtqDimension; i++) { + for (size_t j = 0; j < kMtqDimension; j++) { + scale_factor[i][j] = sf_vec[i * kMtqDimension + j]; + } + } + + libra::Quaternion quaternion_b2c; + magtorquer_conf.ReadQuaternion(MTSection, "quaternion_b2c", quaternion_b2c); + + libra::Vector max_magnetic_moment_c_Am2; + magtorquer_conf.ReadVector(MTSection, "max_output_magnetic_moment_c_Am2", max_magnetic_moment_c_Am2); + + libra::Vector min_magnetic_moment_c_Am2; + magtorquer_conf.ReadVector(MTSection, "min_output_magnetic_moment_c_Am2", min_magnetic_moment_c_Am2); + + libra::Vector bias_noise_c_Am2; + magtorquer_conf.ReadVector(MTSection, "constant_bias_noise_c_Am2", bias_noise_c_Am2); + + double random_walk_step_width_s = component_step_time_s * (double)prescaler; + libra::Vector random_walk_standard_deviation_c_Am2; + magtorquer_conf.ReadVector(MTSection, "random_walk_standard_deviation_c_Am2", random_walk_standard_deviation_c_Am2); + libra::Vector random_walk_limit_c_Am2; + magtorquer_conf.ReadVector(MTSection, "random_walk_limit_c_Am2", random_walk_limit_c_Am2); + libra::Vector normal_random_standard_deviation_c_Am2; + magtorquer_conf.ReadVector(MTSection, "white_noise_standard_deviation_c_Am2", normal_random_standard_deviation_c_Am2); + + // PowerPort + power_port->InitializeWithInitializeFile(file_name); + + Magnetorquer magtorquer(prescaler, clock_generator, power_port, actuator_id, quaternion_b2c, scale_factor, max_magnetic_moment_c_Am2, + min_magnetic_moment_c_Am2, bias_noise_c_Am2, random_walk_step_width_s, random_walk_standard_deviation_c_Am2, + random_walk_limit_c_Am2, normal_random_standard_deviation_c_Am2, geomagnetic_field); + return magtorquer; +} diff --git a/src/components/real/aocs/magnetorquer.hpp b/src/components/real/aocs/magnetorquer.hpp index d06d22931..e4be7361f 100644 --- a/src/components/real/aocs/magnetorquer.hpp +++ b/src/components/real/aocs/magnetorquer.hpp @@ -146,4 +146,28 @@ class Magnetorquer : public Component, public ILoggable { libra::Vector CalcOutputTorque(void); }; +/** + * @fn InitMagnetorquer + * @brief Initialize functions for magnetometer without power port + * @param [in] clock_generator: Clock generator + * @param [in] actuator_id: Actuator ID + * @param [in] file_name: Path to the initialize file + * @param [in] component_step_time_s: Component step time [sec] + * @param [in] geomagnetic_field: Geomegnetic environment + */ +Magnetorquer InitMagnetorquer(ClockGenerator* clock_generator, int actuator_id, const std::string file_name, double component_step_time_s, + const GeomagneticField* geomagnetic_field); +/** + * @fn InitMagnetorquer + * @brief Initialize functions for magnetometer with power port + * @param [in] clock_generator: Clock generator + * @param [in] power_port: Power port + * @param [in] actuator_id: Actuator ID + * @param [in] file_name: Path to the initialize file + * @param [in] component_step_time_s: Component step time [sec] + * @param [in] geomagnetic_field: Geomegnetic environment + */ +Magnetorquer InitMagnetorquer(ClockGenerator* clock_generator, PowerPort* power_port, int actuator_id, const std::string file_name, + double component_step_time_s, const GeomagneticField* geomagnetic_field); + #endif // S2E_COMPONENTS_REAL_AOCS_MAGNETORQUER_HPP_ diff --git a/src/components/real/aocs/reaction_wheel.cpp b/src/components/real/aocs/reaction_wheel.cpp index 9327ede53..835edcc79 100644 --- a/src/components/real/aocs/reaction_wheel.cpp +++ b/src/components/real/aocs/reaction_wheel.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -17,7 +18,7 @@ static double rpm2angularVelocity(double rpm) { return rpm * libra::tau / 60.0; static double angularVelocity2rpm(double angular_velocity) { return angular_velocity * 60.0 / libra::tau; } -ReactionWheel::ReactionWheel(const int prescaler, const int fast_prescaler, ClockGenerator *clock_generator, const int component_id, +ReactionWheel::ReactionWheel(const int prescaler, const int fast_prescaler, ClockGenerator* clock_generator, const int component_id, const double step_width_s, const double main_routine_time_step_s, const double jitter_update_interval_s, const double rotor_inertia_kgm2, const double max_torque_Nm, const double max_velocity_rpm, const libra::Quaternion quaternion_b2c, const libra::Vector<3> position_b_m, const double dead_time_s, @@ -48,7 +49,7 @@ ReactionWheel::ReactionWheel(const int prescaler, const int fast_prescaler, Cloc Initialize(); } -ReactionWheel::ReactionWheel(const int prescaler, const int fast_prescaler, ClockGenerator *clock_generator, PowerPort *power_port, +ReactionWheel::ReactionWheel(const int prescaler, const int fast_prescaler, ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, const double step_width_s, const double main_routine_time_step_s, const double jitter_update_interval_s, const double rotor_inertia_kgm2, const double max_torque_Nm, const double max_velocity_rpm, const libra::Quaternion quaternion_b2c, const libra::Vector<3> position_b_m, @@ -220,3 +221,120 @@ std::string ReactionWheel::GetLogValue() const { return str_tmp; } + +// In order to share processing among initialization functions, variables should also be shared. These variables have internal linkages and cannot be +// referenced from the outside. +namespace { +int prescaler; +int fast_prescaler; +double step_width_s; +double main_routine_time_step_s; +double jitter_update_interval_s; +double rotor_inertia_kgm2; +double max_torque_Nm; +double max_velocity; +libra::Quaternion quaternion_b2c; +libra::Vector<3> position_b_m; +double dead_time_s; +libra::Vector<3> ordinary_lag_coef(1.0); +libra::Vector<3> coasting_lag_coefficients(1.0); +bool is_calc_jitter_enabled; +bool is_log_jitter_enabled; +std::vector> radial_force_harmonics_coefficients; +std::vector> radial_torque_harmonics_coefficients; +double structural_resonance_frequency_Hz; +double damping_factor; +double bandwidth; +bool considers_structural_resonance; +bool drive_flag; +double init_velocity_rad_s; + +void InitParams(int actuator_id, std::string file_name, double prop_step, double compo_update_step) { + // Access Parameters + IniAccess rwmodel_conf(file_name); + const std::string st_actuator_num = std::to_string(static_cast(actuator_id)); + const char* cs = st_actuator_num.data(); + std::string section_tmp = "REACTION_WHEEL_"; + section_tmp += cs; + const char* RWsection = section_tmp.data(); + + // Read ini file + prescaler = rwmodel_conf.ReadInt(RWsection, "prescaler"); + if (prescaler <= 1) prescaler = 1; + fast_prescaler = rwmodel_conf.ReadInt(RWsection, "fast_prescaler"); + if (fast_prescaler <= 1) fast_prescaler = 1; + rotor_inertia_kgm2 = rwmodel_conf.ReadDouble(RWsection, "moment_of_inertia_kgm2"); + max_torque_Nm = rwmodel_conf.ReadDouble(RWsection, "max_output_torque_Nm"); + max_velocity = rwmodel_conf.ReadDouble(RWsection, "max_angular_velocity_rpm"); + + std::string direction_determination_mode; + direction_determination_mode = rwmodel_conf.ReadString(RWsection, "direction_determination_mode"); + if (direction_determination_mode == "QUATERNION") { + rwmodel_conf.ReadQuaternion(RWsection, "quaternion_b2c", quaternion_b2c); + } else // direction_determination_mode == "DIRECTION" + { + libra::Vector<3> direction_b; + rwmodel_conf.ReadVector(RWsection, "direction_b", direction_b); + libra::Vector<3> direction_c(0.0); + direction_c[2] = 1.0; + libra::Quaternion q(direction_b, direction_c); + quaternion_b2c = q.Conjugate(); + } + + rwmodel_conf.ReadVector(RWsection, "position_b_m", position_b_m); + dead_time_s = rwmodel_conf.ReadDouble(RWsection, "dead_time_s"); + // rwmodel_conf.ReadVector(RWsection, "first_order_lag_coefficient", ordinary_lag_coef); // TODO: Fix bug + // rwmodel_conf.ReadVector(RWsection, "coasting_lag_coefficient", coasting_lag_coefficients); // TODO: Fix bug + + is_calc_jitter_enabled = rwmodel_conf.ReadEnable(RWsection, "jitter_calculation"); + is_log_jitter_enabled = rwmodel_conf.ReadEnable(RWsection, "jitter_logging"); + + std::string radial_force_harmonics_coef_path = rwmodel_conf.ReadString(RWsection, "radial_force_harmonics_coefficient_file"); + std::string radial_torque_harmonics_coef_path = rwmodel_conf.ReadString(RWsection, "radial_torque_harmonics_coefficient_file"); + int harmonics_degree = rwmodel_conf.ReadInt(RWsection, "harmonics_degree"); + IniAccess conf_radial_force_harmonics(radial_force_harmonics_coef_path); + IniAccess conf_radial_torque_harmonics(radial_torque_harmonics_coef_path); + conf_radial_force_harmonics.ReadCsvDouble(radial_force_harmonics_coefficients, harmonics_degree); + conf_radial_torque_harmonics.ReadCsvDouble(radial_torque_harmonics_coefficients, harmonics_degree); + + structural_resonance_frequency_Hz = rwmodel_conf.ReadDouble(RWsection, "structural_resonance_frequency_Hz"); + damping_factor = rwmodel_conf.ReadDouble(RWsection, "damping_factor"); + bandwidth = rwmodel_conf.ReadDouble(RWsection, "bandwidth"); + considers_structural_resonance = rwmodel_conf.ReadEnable(RWsection, "considers_structural_resonance"); + + drive_flag = rwmodel_conf.ReadBoolean(RWsection, "initial_motor_drive_flag"); + init_velocity_rad_s = rwmodel_conf.ReadDouble(RWsection, "initial_angular_velocity_rad_s"); + + // Calc periods + step_width_s = prop_step; + main_routine_time_step_s = prescaler * compo_update_step; + jitter_update_interval_s = fast_prescaler * compo_update_step; +} +} // namespace + +ReactionWheel InitReactionWheel(ClockGenerator* clock_generator, int actuator_id, std::string file_name, double prop_step, double compo_update_step) { + InitParams(actuator_id, file_name, prop_step, compo_update_step); + + ReactionWheel rwmodel(prescaler, fast_prescaler, clock_generator, actuator_id, step_width_s, main_routine_time_step_s, jitter_update_interval_s, + rotor_inertia_kgm2, max_torque_Nm, max_velocity, quaternion_b2c, position_b_m, dead_time_s, ordinary_lag_coef, + coasting_lag_coefficients, is_calc_jitter_enabled, is_log_jitter_enabled, radial_force_harmonics_coefficients, + radial_torque_harmonics_coefficients, structural_resonance_frequency_Hz, damping_factor, bandwidth, + considers_structural_resonance, drive_flag, init_velocity_rad_s); + + return rwmodel; +} + +ReactionWheel InitReactionWheel(ClockGenerator* clock_generator, PowerPort* power_port, int actuator_id, std::string file_name, double prop_step, + double compo_update_step) { + InitParams(actuator_id, file_name, prop_step, compo_update_step); + + power_port->InitializeWithInitializeFile(file_name); + + ReactionWheel rwmodel(prescaler, fast_prescaler, clock_generator, power_port, actuator_id, step_width_s, main_routine_time_step_s, + jitter_update_interval_s, rotor_inertia_kgm2, max_torque_Nm, max_velocity, quaternion_b2c, position_b_m, dead_time_s, + ordinary_lag_coef, coasting_lag_coefficients, is_calc_jitter_enabled, is_log_jitter_enabled, + radial_force_harmonics_coefficients, radial_torque_harmonics_coefficients, structural_resonance_frequency_Hz, damping_factor, + bandwidth, considers_structural_resonance, drive_flag, init_velocity_rad_s); + + return rwmodel; +} diff --git a/src/components/real/aocs/reaction_wheel.hpp b/src/components/real/aocs/reaction_wheel.hpp index 17a372339..85634ce55 100644 --- a/src/components/real/aocs/reaction_wheel.hpp +++ b/src/components/real/aocs/reaction_wheel.hpp @@ -54,7 +54,7 @@ class ReactionWheel : public Component, public ILoggable { * @param [in] drive_flag: RW drive flag * @param [in] init_velocity_rad_s: Initial value of angular velocity of RW */ - ReactionWheel(const int prescaler, const int fast_prescaler, ClockGenerator *clock_generator, const int component_id, const double step_width_s, + ReactionWheel(const int prescaler, const int fast_prescaler, ClockGenerator* clock_generator, const int component_id, const double step_width_s, const double main_routine_time_step_s, const double jitter_update_interval_s, const double rotor_inertia_kgm2, const double max_torque_Nm, const double max_velocity_rpm, const libra::Quaternion quaternion_b2c, const libra::Vector<3> position_b_m, const double dead_time_s, const libra::Vector<3> driving_lag_coefficients, @@ -93,7 +93,7 @@ class ReactionWheel : public Component, public ILoggable { * @param [in] drive_flag: RW drive flag * @param [in] init_velocity_rad_s: Initial value of angular velocity of RW [rad/s] */ - ReactionWheel(const int prescaler, const int fast_prescaler, ClockGenerator *clock_generator, PowerPort *power_port, const int component_id, + ReactionWheel(const int prescaler, const int fast_prescaler, ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, const double step_width_s, const double main_routine_time_step_s, const double jitter_update_interval_s, const double rotor_inertia_kgm2, const double max_torque_Nm, const double max_velocity_rpm, const libra::Quaternion quaternion_b2c, const libra::Vector<3> position_b_m, const double dead_time_s, const libra::Vector<3> driving_lag_coefficients, @@ -239,4 +239,27 @@ class ReactionWheel : public Component, public ILoggable { void Initialize(); }; +/** + * @fn InitReactionWheel + * @brief Initialize functions for reaction wheel without power port + * @param [in] clock_generator: Clock generator + * @param [in] actuator_id: Actuator ID + * @param [in] file_name: Path to the initialize file + * @param [in] prop_step: Propagation step for RW dynamics [sec] + * @param [in] compo_update_step: Component step time [sec] + */ +ReactionWheel InitReactionWheel(ClockGenerator* clock_generator, int actuator_id, std::string file_name, double prop_step, double compo_update_step); +/** + * @fn InitReactionWheel + * @brief Initialize functions for reaction wheel with power port + * @param [in] clock_generator: Clock generator + * @param [in] power_port: Power port + * @param [in] actuator_id: Actuator ID + * @param [in] file_name: Path to the initialize file + * @param [in] prop_step: Propagation step for RW dynamics [sec] + * @param [in] compo_update_step: Component step time [sec] + */ +ReactionWheel InitReactionWheel(ClockGenerator* clock_generator, PowerPort* power_port, int actuator_id, std::string file_name, double prop_step, + double compo_update_step); + #endif // S2E_COMPONENTS_REAL_AOCS_REACTION_WHEEL_HPP_ diff --git a/src/components/real/aocs/star_sensor.cpp b/src/components/real/aocs/star_sensor.cpp index ea02f0be5..15c4033f6 100644 --- a/src/components/real/aocs/star_sensor.cpp +++ b/src/components/real/aocs/star_sensor.cpp @@ -6,6 +6,7 @@ #include "star_sensor.hpp" #include +#include #include #include #include @@ -211,3 +212,72 @@ void StarSensor::MainRoutine(const int time_count) { Measure(&(local_environment_->GetCelestialInformation()), &(dynamics_->GetAttitude())); } + +StarSensor InitStarSensor(ClockGenerator* clock_generator, int sensor_id, const string file_name, double component_step_time_s, + const Dynamics* dynamics, const LocalEnvironment* local_environment) { + IniAccess STT_conf(file_name); + const char* sensor_name = "STAR_SENSOR_"; + const std::string section_name = sensor_name + std::to_string(static_cast(sensor_id)); + const char* STTSection = section_name.c_str(); + + int prescaler = STT_conf.ReadInt(STTSection, "prescaler"); + if (prescaler <= 1) prescaler = 1; + double step_time_s = component_step_time_s * prescaler; + libra::Quaternion quaternion_b2c; + STT_conf.ReadQuaternion(STTSection, "quaternion_b2c", quaternion_b2c); + double standard_deviation_orthogonal_direction = STT_conf.ReadDouble(STTSection, "standard_deviation_orthogonal_direction_rad"); + double standard_deviation_sight_direction = STT_conf.ReadDouble(STTSection, "standard_deviation_sight_direction_rad"); + double output_delay_sec = STT_conf.ReadDouble(STTSection, "output_delay_s"); + int output_delay = max(int(output_delay_sec / step_time_s), 1); + double output_interval_sec = STT_conf.ReadDouble(STTSection, "output_interval_s"); + int output_interval = max(int(output_interval_sec / step_time_s), 1); + double sun_forbidden_angle_deg = STT_conf.ReadDouble(STTSection, "sun_exclusion_angle_deg"); + double sun_forbidden_angle_rad = sun_forbidden_angle_deg * libra::pi / 180.0; + double earth_forbidden_angle_deg = STT_conf.ReadDouble(STTSection, "earth_exclusion_angle_deg"); + double earth_forbidden_angle_rad = earth_forbidden_angle_deg * libra::pi / 180.0; + double moon_forbidden_angle_deg = STT_conf.ReadDouble(STTSection, "moon_exclusion_angle_deg"); + double moon_forbidden_angle_rad = moon_forbidden_angle_deg * libra::pi / 180.0; + double capture_rate_deg_s = STT_conf.ReadDouble(STTSection, "angular_rate_limit_deg_s"); + double capture_rate_rad_s = capture_rate_deg_s * libra::pi / 180.0; + + StarSensor stt(prescaler, clock_generator, sensor_id, quaternion_b2c, standard_deviation_orthogonal_direction, standard_deviation_sight_direction, + step_time_s, output_delay, output_interval, sun_forbidden_angle_rad, earth_forbidden_angle_rad, moon_forbidden_angle_rad, + capture_rate_rad_s, dynamics, local_environment); + return stt; +} + +StarSensor InitStarSensor(ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const string file_name, double component_step_time_s, + const Dynamics* dynamics, const LocalEnvironment* local_environment) { + IniAccess STT_conf(file_name); + const char* sensor_name = "STAR_SENSOR_"; + const std::string section_name = sensor_name + std::to_string(static_cast(sensor_id)); + const char* STTSection = section_name.c_str(); + + int prescaler = STT_conf.ReadInt(STTSection, "prescaler"); + if (prescaler <= 1) prescaler = 1; + double step_time_s = component_step_time_s * prescaler; + + libra::Quaternion quaternion_b2c; + STT_conf.ReadQuaternion(STTSection, "quaternion_b2c", quaternion_b2c); + double standard_deviation_orthogonal_direction = STT_conf.ReadDouble(STTSection, "standard_deviation_orthogonal_direction_rad"); + double standard_deviation_sight_direction = STT_conf.ReadDouble(STTSection, "standard_deviation_sight_direction_rad"); + double output_delay_sec = STT_conf.ReadDouble(STTSection, "output_delay_s"); + int output_delay = max(int(output_delay_sec / step_time_s), 1); + double output_interval_sec = STT_conf.ReadDouble(STTSection, "output_interval_s"); + int output_interval = max(int(output_interval_sec / step_time_s), 1); + double sun_forbidden_angle_deg = STT_conf.ReadDouble(STTSection, "sun_exclusion_angle_deg"); + double sun_forbidden_angle_rad = sun_forbidden_angle_deg * libra::pi / 180.0; + double earth_forbidden_angle_deg = STT_conf.ReadDouble(STTSection, "earth_exclusion_angle_deg"); + double earth_forbidden_angle_rad = earth_forbidden_angle_deg * libra::pi / 180.0; + double moon_forbidden_angle_deg = STT_conf.ReadDouble(STTSection, "moon_exclusion_angle_deg"); + double moon_forbidden_angle_rad = moon_forbidden_angle_deg * libra::pi / 180.0; + double capture_rate_deg_s = STT_conf.ReadDouble(STTSection, "angular_rate_limit_deg_s"); + double capture_rate_rad_s = capture_rate_deg_s * libra::pi / 180.0; + + power_port->InitializeWithInitializeFile(file_name); + + StarSensor stt(prescaler, clock_generator, power_port, sensor_id, quaternion_b2c, standard_deviation_orthogonal_direction, + standard_deviation_sight_direction, step_time_s, output_delay, output_interval, sun_forbidden_angle_rad, earth_forbidden_angle_rad, + moon_forbidden_angle_rad, capture_rate_rad_s, dynamics, local_environment); + return stt; +} diff --git a/src/components/real/aocs/star_sensor.hpp b/src/components/real/aocs/star_sensor.hpp index 1b85d3cd6..b2f4daef9 100644 --- a/src/components/real/aocs/star_sensor.hpp +++ b/src/components/real/aocs/star_sensor.hpp @@ -206,4 +206,30 @@ class StarSensor : public Component, public ILoggable { void Initialize(); }; +/** + * @fn InitStarSensor + * @brief Initialize functions for StarSensor without power port + * @param [in] clock_generator: Clock generator + * @param [in] sensor_id: Sensor ID + * @param [in] file_name: Path to the initialize file + * @param [in] component_step_time_s: Component step time [sec] + * @param [in] dynamics: Dynamics information + * @param [in] local_environment: Local environment information + */ +StarSensor InitStarSensor(ClockGenerator* clock_generator, int sensor_id, const std::string file_name, double component_step_time_s, + const Dynamics* dynamics, const LocalEnvironment* local_environment); +/** + * @fn InitStarSensor + * @brief Initialize functions for StarSensor with power port + * @param [in] clock_generator: Clock generator + * @param [in] power_port: Power port + * @param [in] sensor_id: Sensor ID + * @param [in] file_name: Path to the initialize file + * @param [in] component_step_time_s: Component step time [sec] + * @param [in] dynamics: Dynamics information + * @param [in] local_environment: Local environment information + */ +StarSensor InitStarSensor(ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const std::string file_name, + double component_step_time_s, const Dynamics* dynamics, const LocalEnvironment* local_environment); + #endif // S2E_COMPONENTS_REAL_AOCS_STAR_SENSOR_HPP_ diff --git a/src/components/real/aocs/sun_sensor.cpp b/src/components/real/aocs/sun_sensor.cpp index 336aceeab..c10959a9e 100644 --- a/src/components/real/aocs/sun_sensor.cpp +++ b/src/components/real/aocs/sun_sensor.cpp @@ -8,6 +8,7 @@ #include #include using libra::NormalRand; +#include #include #include @@ -149,3 +150,71 @@ string SunSensor::GetLogValue() const { return str_tmp; } + +SunSensor InitSunSensor(ClockGenerator* clock_generator, int ss_id, std::string file_name, const SolarRadiationPressureEnvironment* srp_environment, + const LocalCelestialInformation* local_celestial_information) { + IniAccess ss_conf(file_name); + const char* sensor_name = "SUN_SENSOR_"; + const std::string section_tmp = sensor_name + std::to_string(static_cast(ss_id)); + const char* Section = section_tmp.c_str(); + + int prescaler = ss_conf.ReadInt(Section, "prescaler"); + if (prescaler <= 1) prescaler = 1; + + libra::Quaternion quaternion_b2c; + ss_conf.ReadQuaternion(Section, "quaternion_b2c", quaternion_b2c); + + double detectable_angle_deg = 0.0, detectable_angle_rad = 0.0; + detectable_angle_deg = ss_conf.ReadDouble(Section, "field_of_view_deg"); + detectable_angle_rad = libra::pi / 180.0 * detectable_angle_deg; + + double nr_stddev = 0.0; + nr_stddev = ss_conf.ReadDouble(Section, "white_noise_standard_deviation_deg"); + nr_stddev *= libra::pi / 180.0; + + double nr_bias_stddev = 0.0; + nr_bias_stddev = ss_conf.ReadDouble(Section, "bias_standard_deviation_deg"); + nr_bias_stddev *= libra::pi / 180.0; + + double intensity_lower_threshold_percent; + intensity_lower_threshold_percent = ss_conf.ReadDouble(Section, "intensity_lower_threshold_percent"); + + SunSensor ss(prescaler, clock_generator, ss_id, quaternion_b2c, detectable_angle_rad, nr_stddev, nr_bias_stddev, intensity_lower_threshold_percent, + srp_environment, local_celestial_information); + return ss; +} + +SunSensor InitSunSensor(ClockGenerator* clock_generator, PowerPort* power_port, int ss_id, std::string file_name, + const SolarRadiationPressureEnvironment* srp_environment, const LocalCelestialInformation* local_celestial_information) { + IniAccess ss_conf(file_name); + const char* sensor_name = "SUN_SENSOR_"; + const std::string section_tmp = sensor_name + std::to_string(static_cast(ss_id)); + const char* Section = section_tmp.c_str(); + + int prescaler = ss_conf.ReadInt(Section, "prescaler"); + if (prescaler <= 1) prescaler = 1; + + libra::Quaternion quaternion_b2c; + ss_conf.ReadQuaternion(Section, "quaternion_b2c", quaternion_b2c); + + double detectable_angle_deg = 0.0, detectable_angle_rad = 0.0; + detectable_angle_deg = ss_conf.ReadDouble(Section, "field_of_view_deg"); + detectable_angle_rad = libra::pi / 180.0 * detectable_angle_deg; + + double nr_stddev = 0.0; + nr_stddev = ss_conf.ReadDouble(Section, "white_noise_standard_deviation_deg"); + nr_stddev *= libra::pi / 180.0; + + double nr_bias_stddev = 0.0; + nr_bias_stddev = ss_conf.ReadDouble(Section, "bias_standard_deviation_deg"); + nr_bias_stddev *= libra::pi / 180.0; + + double intensity_lower_threshold_percent; + intensity_lower_threshold_percent = ss_conf.ReadDouble(Section, "intensity_lower_threshold_percent"); + + power_port->InitializeWithInitializeFile(file_name); + + SunSensor ss(prescaler, clock_generator, power_port, ss_id, quaternion_b2c, detectable_angle_rad, nr_stddev, nr_bias_stddev, + intensity_lower_threshold_percent, srp_environment, local_celestial_information); + return ss; +} diff --git a/src/components/real/aocs/sun_sensor.hpp b/src/components/real/aocs/sun_sensor.hpp index bf61b6c4c..f1c59a670 100644 --- a/src/components/real/aocs/sun_sensor.hpp +++ b/src/components/real/aocs/sun_sensor.hpp @@ -141,4 +141,28 @@ class SunSensor : public Component, public ILoggable { void CalcSolarIlluminance(); }; +/** + * @fn InitSunSensor + * @brief Initialize functions for sun sensor without power port + * @param [in] clock_generator: Clock generator + * @param [in] sensor_id: Sensor ID + * @param [in] file_name: Path to the initialize file + * @param [in] srp_environment: Solar radiation pressure environment + * @param [in] local_environment: Local environment information + */ +SunSensor InitSunSensor(ClockGenerator* clock_generator, int sensor_id, const std::string file_name, + const SolarRadiationPressureEnvironment* srp_environment, const LocalCelestialInformation* local_celestial_information); +/** + * @fn InitSunSensor + * @brief Initialize functions for sun sensor with power port + * @param [in] clock_generator: Clock generator + * @param [in] power_port: Power port + * @param [in] sensor_id: Sensor ID + * @param [in] file_name: Path to the initialize file + * @param [in] srp_environment: Solar radiation pressure environment + * @param [in] local_environment: Local environment information + */ +SunSensor InitSunSensor(ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const std::string file_name, + const SolarRadiationPressureEnvironment* srp_environment, const LocalCelestialInformation* local_celestial_information); + #endif // S2E_COMPONENTS_REAL_AOCS_SUN_SENSOR_HPP_ diff --git a/src/components/real/communication/antenna.cpp b/src/components/real/communication/antenna.cpp index ab92c650e..6459cb947 100644 --- a/src/components/real/communication/antenna.cpp +++ b/src/components/real/communication/antenna.cpp @@ -5,7 +5,11 @@ #include "antenna.hpp" +#define _CRT_SECURE_NO_WARNINGS +#include + #include +#include #include Antenna::Antenna(const int component_id, const libra::Quaternion& quaternion_b2c, const bool is_transmitter, const bool is_receiver, @@ -101,3 +105,67 @@ AntennaGainModel SetAntennaGainModel(const std::string gain_model_name) { return AntennaGainModel::kIsotropic; } } + +Antenna InitAntenna(const int antenna_id, const std::string file_name) { + IniAccess antenna_conf(file_name); + + const std::string st_antenna_id = std::to_string(static_cast(antenna_id)); + const char* cs = st_antenna_id.data(); + + char Section[30] = "ANTENNA_"; + strcat(Section, cs); + + Quaternion quaternion_b2c; + antenna_conf.ReadQuaternion(Section, "quaternion_b2c", quaternion_b2c); + + bool is_transmitter = antenna_conf.ReadBoolean(Section, "is_transmitter"); + bool is_receiver = antenna_conf.ReadBoolean(Section, "is_receiver"); + double frequency_MHz = antenna_conf.ReadDouble(Section, "frequency_MHz"); + + double tx_bitrate_bps = antenna_conf.ReadDouble(Section, "tx_bitrate_bps"); + double tx_output_power_W = antenna_conf.ReadDouble(Section, "tx_output_W"); + double rx_system_noise_temperature_K = antenna_conf.ReadDouble(Section, "rx_system_noise_temperature_K"); + + AntennaParameters tx_parameters; + if (is_transmitter) { + tx_parameters.gain_dBi_ = antenna_conf.ReadDouble(Section, "tx_gain_dBi"); + tx_parameters.loss_feeder_dB_ = antenna_conf.ReadDouble(Section, "tx_loss_feeder_dB"); + tx_parameters.loss_pointing_dB_ = antenna_conf.ReadDouble(Section, "tx_loss_pointing_dB"); + tx_parameters.antenna_gain_model = SetAntennaGainModel(antenna_conf.ReadString(Section, "tx_antenna_gain_model")); + size_t length_theta = antenna_conf.ReadInt(Section, "tx_length_theta"); + size_t length_phi = antenna_conf.ReadInt(Section, "tx_length_phi"); + double theta_max_rad = antenna_conf.ReadDouble(Section, "tx_theta_max_rad"); + double phi_max_rad = antenna_conf.ReadDouble(Section, "tx_phi_max_rad"); + tx_parameters.radiation_pattern = AntennaRadiationPattern(antenna_conf.ReadString(Section, "tx_antenna_radiation_pattern_file"), length_theta, + length_phi, theta_max_rad, phi_max_rad); + } else { + tx_parameters.gain_dBi_ = 0.0; + tx_parameters.loss_feeder_dB_ = 0.0; + tx_parameters.loss_pointing_dB_ = 0.0; + tx_parameters.antenna_gain_model = AntennaGainModel::kIsotropic; + } + + AntennaParameters rx_parameters; + if (is_receiver) { + rx_parameters.gain_dBi_ = antenna_conf.ReadDouble(Section, "rx_gain_dBi"); + rx_parameters.loss_feeder_dB_ = antenna_conf.ReadDouble(Section, "rx_loss_feeder_dB"); + rx_parameters.loss_pointing_dB_ = antenna_conf.ReadDouble(Section, "rx_loss_pointing_dB"); + rx_parameters.antenna_gain_model = SetAntennaGainModel(antenna_conf.ReadString(Section, "rx_antenna_gain_model")); + rx_parameters.radiation_pattern = AntennaRadiationPattern(antenna_conf.ReadString(Section, "rx_antenna_radiation_pattern_file")); + size_t length_theta = antenna_conf.ReadInt(Section, "rx_length_theta"); + size_t length_phi = antenna_conf.ReadInt(Section, "rx_length_phi"); + double theta_max_rad = antenna_conf.ReadDouble(Section, "rx_theta_max_rad"); + double phi_max_rad = antenna_conf.ReadDouble(Section, "rx_phi_max_rad"); + rx_parameters.radiation_pattern = AntennaRadiationPattern(antenna_conf.ReadString(Section, "rx_antenna_radiation_pattern_file"), length_theta, + length_phi, theta_max_rad, phi_max_rad); + } else { + rx_parameters.gain_dBi_ = 0.0; + rx_parameters.loss_feeder_dB_ = 0.0; + rx_parameters.loss_pointing_dB_ = 0.0; + rx_parameters.antenna_gain_model = AntennaGainModel::kIsotropic; + } + + Antenna antenna(antenna_id, quaternion_b2c, is_transmitter, is_receiver, frequency_MHz, tx_bitrate_bps, tx_output_power_W, tx_parameters, + rx_system_noise_temperature_K, rx_parameters); + return antenna; +} diff --git a/src/components/real/communication/antenna.hpp b/src/components/real/communication/antenna.hpp index 098ef1ec2..1d487493a 100644 --- a/src/components/real/communication/antenna.hpp +++ b/src/components/real/communication/antenna.hpp @@ -158,4 +158,12 @@ class Antenna { AntennaGainModel SetAntennaGainModel(const std::string gain_model_name); +/* + * @fn InitAntenna + * @brief Initialize function for Antenna + * @param [in] antenna_id: Antenna ID + * @param [in] file_name: Path to initialize file + */ +Antenna InitAntenna(const int antenna_id, const std::string file_name); + #endif // S2E_COMPONENTS_REAL_COMMUNICATION_ANTENNA_HPP_ diff --git a/src/components/real/communication/ground_station_calculator.cpp b/src/components/real/communication/ground_station_calculator.cpp index ee3bb75dd..87a550529 100644 --- a/src/components/real/communication/ground_station_calculator.cpp +++ b/src/components/real/communication/ground_station_calculator.cpp @@ -6,6 +6,7 @@ #include "ground_station_calculator.hpp" #include +#include #include GroundStationCalculator::GroundStationCalculator(const double loss_polarization_dB, const double loss_atmosphere_dB, const double loss_rainfall_dB, @@ -115,3 +116,23 @@ std::string GroundStationCalculator::GetLogValue() const { return str_tmp; } + +GroundStationCalculator InitGsCalculator(const std::string file_name) { + IniAccess gs_conf(file_name); + + char Section[30] = "GROUND_STATION_CALCULATOR"; + + double loss_polarization_dB = gs_conf.ReadDouble(Section, "loss_polarization_dB"); + double loss_atmosphere_dB = gs_conf.ReadDouble(Section, "loss_atmosphere_dB"); + double loss_rainfall_dB = gs_conf.ReadDouble(Section, "loss_rainfall_dB"); + double loss_others_dB = gs_conf.ReadDouble(Section, "loss_others_dB"); + double ebn0_dB = gs_conf.ReadDouble(Section, "ebn0_dB"); + double hardware_deterioration_dB = gs_conf.ReadDouble(Section, "hardware_deterioration_dB"); + double coding_gain_dB = gs_conf.ReadDouble(Section, "coding_gain_dB"); + double margin_requirement_dB = gs_conf.ReadDouble(Section, "margin_requirement_dB"); + double downlink_bitrate_bps = gs_conf.ReadDouble(Section, "downlink_bitrate_bps"); + + GroundStationCalculator gs_calculator(loss_polarization_dB, loss_atmosphere_dB, loss_rainfall_dB, loss_others_dB, ebn0_dB, + hardware_deterioration_dB, coding_gain_dB, margin_requirement_dB, downlink_bitrate_bps); + return gs_calculator; +} diff --git a/src/components/real/communication/ground_station_calculator.hpp b/src/components/real/communication/ground_station_calculator.hpp index ab4ddb01b..196822295 100644 --- a/src/components/real/communication/ground_station_calculator.hpp +++ b/src/components/real/communication/ground_station_calculator.hpp @@ -136,4 +136,12 @@ class GroundStationCalculator : public ILoggable { const Antenna& ground_station_rx_antenna); }; +/* + * @fn InitGsCalculator + * @brief Initialize function for Ground Station Calculator + * @param [in] file_name: Path to initialize file + */ + +GroundStationCalculator InitGsCalculator(const std::string file_name); + #endif // S2E_COMPONENTS_REAL_COMMUNICATION_GROUND_STATION_CALCULATOR_HPP_ diff --git a/src/components/real/communication/initialize_antenna.cpp b/src/components/real/communication/initialize_antenna.cpp deleted file mode 100644 index 6ab1187c4..000000000 --- a/src/components/real/communication/initialize_antenna.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * @file initialize_antenna.cpp - * @brief Initialize function for Antenna - */ - -#define _CRT_SECURE_NO_WARNINGS -#include "initialize_antenna.hpp" - -#include - -#include - -#include "library/initialize/initialize_file_access.hpp" - -using libra::Vector; - -Antenna InitAntenna(const int antenna_id, const std::string file_name) { - IniAccess antenna_conf(file_name); - - const std::string st_antenna_id = std::to_string(static_cast(antenna_id)); - const char *cs = st_antenna_id.data(); - - char Section[30] = "ANTENNA_"; - strcat(Section, cs); - - Quaternion quaternion_b2c; - antenna_conf.ReadQuaternion(Section, "quaternion_b2c", quaternion_b2c); - - bool is_transmitter = antenna_conf.ReadBoolean(Section, "is_transmitter"); - bool is_receiver = antenna_conf.ReadBoolean(Section, "is_receiver"); - double frequency_MHz = antenna_conf.ReadDouble(Section, "frequency_MHz"); - - double tx_bitrate_bps = antenna_conf.ReadDouble(Section, "tx_bitrate_bps"); - double tx_output_power_W = antenna_conf.ReadDouble(Section, "tx_output_W"); - double rx_system_noise_temperature_K = antenna_conf.ReadDouble(Section, "rx_system_noise_temperature_K"); - - AntennaParameters tx_parameters; - if (is_transmitter) { - tx_parameters.gain_dBi_ = antenna_conf.ReadDouble(Section, "tx_gain_dBi"); - tx_parameters.loss_feeder_dB_ = antenna_conf.ReadDouble(Section, "tx_loss_feeder_dB"); - tx_parameters.loss_pointing_dB_ = antenna_conf.ReadDouble(Section, "tx_loss_pointing_dB"); - tx_parameters.antenna_gain_model = SetAntennaGainModel(antenna_conf.ReadString(Section, "tx_antenna_gain_model")); - size_t length_theta = antenna_conf.ReadInt(Section, "tx_length_theta"); - size_t length_phi = antenna_conf.ReadInt(Section, "tx_length_phi"); - double theta_max_rad = antenna_conf.ReadDouble(Section, "tx_theta_max_rad"); - double phi_max_rad = antenna_conf.ReadDouble(Section, "tx_phi_max_rad"); - tx_parameters.radiation_pattern = AntennaRadiationPattern(antenna_conf.ReadString(Section, "tx_antenna_radiation_pattern_file"), length_theta, - length_phi, theta_max_rad, phi_max_rad); - } else { - tx_parameters.gain_dBi_ = 0.0; - tx_parameters.loss_feeder_dB_ = 0.0; - tx_parameters.loss_pointing_dB_ = 0.0; - tx_parameters.antenna_gain_model = AntennaGainModel::kIsotropic; - } - - AntennaParameters rx_parameters; - if (is_receiver) { - rx_parameters.gain_dBi_ = antenna_conf.ReadDouble(Section, "rx_gain_dBi"); - rx_parameters.loss_feeder_dB_ = antenna_conf.ReadDouble(Section, "rx_loss_feeder_dB"); - rx_parameters.loss_pointing_dB_ = antenna_conf.ReadDouble(Section, "rx_loss_pointing_dB"); - rx_parameters.antenna_gain_model = SetAntennaGainModel(antenna_conf.ReadString(Section, "rx_antenna_gain_model")); - rx_parameters.radiation_pattern = AntennaRadiationPattern(antenna_conf.ReadString(Section, "rx_antenna_radiation_pattern_file")); - size_t length_theta = antenna_conf.ReadInt(Section, "rx_length_theta"); - size_t length_phi = antenna_conf.ReadInt(Section, "rx_length_phi"); - double theta_max_rad = antenna_conf.ReadDouble(Section, "rx_theta_max_rad"); - double phi_max_rad = antenna_conf.ReadDouble(Section, "rx_phi_max_rad"); - rx_parameters.radiation_pattern = AntennaRadiationPattern(antenna_conf.ReadString(Section, "rx_antenna_radiation_pattern_file"), length_theta, - length_phi, theta_max_rad, phi_max_rad); - } else { - rx_parameters.gain_dBi_ = 0.0; - rx_parameters.loss_feeder_dB_ = 0.0; - rx_parameters.loss_pointing_dB_ = 0.0; - rx_parameters.antenna_gain_model = AntennaGainModel::kIsotropic; - } - - Antenna antenna(antenna_id, quaternion_b2c, is_transmitter, is_receiver, frequency_MHz, tx_bitrate_bps, tx_output_power_W, tx_parameters, - rx_system_noise_temperature_K, rx_parameters); - return antenna; -} diff --git a/src/components/real/communication/initialize_antenna.hpp b/src/components/real/communication/initialize_antenna.hpp deleted file mode 100644 index 8d6f1c906..000000000 --- a/src/components/real/communication/initialize_antenna.hpp +++ /dev/null @@ -1,19 +0,0 @@ -/* - * @file initialize_antenna.hpp - * @brief Initialize function for Antenna - */ - -#ifndef S2E_COMPONENTS_REAL_COMMUNICATION_INITIALIZE_ANTENNA_HPP_ -#define S2E_COMPONENTS_REAL_COMMUNICATION_INITIALIZE_ANTENNA_HPP_ - -#include - -/* - * @fn InitAntenna - * @brief Initialize function for Antenna - * @param [in] antenna_id: Antenna ID - * @param [in] file_name: Path to initialize file - */ -Antenna InitAntenna(const int antenna_id, const std::string file_name); - -#endif // S2E_COMPONENTS_REAL_COMMUNICATION_INITIALIZE_ANTENNA_HPP_ diff --git a/src/components/real/communication/initialize_ground_station_calculator.cpp b/src/components/real/communication/initialize_ground_station_calculator.cpp deleted file mode 100644 index b5a6da536..000000000 --- a/src/components/real/communication/initialize_ground_station_calculator.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * @file initialize_ground_station_calculator.hpp.cpp - * @brief Initialize function for Ground Station Calculator - */ - -#define _CRT_SECURE_NO_WARNINGS -#include "initialize_ground_station_calculator.hpp" - -#include - -#include "library/initialize/initialize_file_access.hpp" - -GroundStationCalculator InitGsCalculator(const std::string file_name) { - IniAccess gs_conf(file_name); - - char Section[30] = "GROUND_STATION_CALCULATOR"; - - double loss_polarization_dB = gs_conf.ReadDouble(Section, "loss_polarization_dB"); - double loss_atmosphere_dB = gs_conf.ReadDouble(Section, "loss_atmosphere_dB"); - double loss_rainfall_dB = gs_conf.ReadDouble(Section, "loss_rainfall_dB"); - double loss_others_dB = gs_conf.ReadDouble(Section, "loss_others_dB"); - double ebn0_dB = gs_conf.ReadDouble(Section, "ebn0_dB"); - double hardware_deterioration_dB = gs_conf.ReadDouble(Section, "hardware_deterioration_dB"); - double coding_gain_dB = gs_conf.ReadDouble(Section, "coding_gain_dB"); - double margin_requirement_dB = gs_conf.ReadDouble(Section, "margin_requirement_dB"); - double downlink_bitrate_bps = gs_conf.ReadDouble(Section, "downlink_bitrate_bps"); - - GroundStationCalculator gs_calculator(loss_polarization_dB, loss_atmosphere_dB, loss_rainfall_dB, loss_others_dB, ebn0_dB, - hardware_deterioration_dB, coding_gain_dB, margin_requirement_dB, downlink_bitrate_bps); - return gs_calculator; -} diff --git a/src/components/real/communication/initialize_ground_station_calculator.hpp b/src/components/real/communication/initialize_ground_station_calculator.hpp deleted file mode 100644 index 298b459c6..000000000 --- a/src/components/real/communication/initialize_ground_station_calculator.hpp +++ /dev/null @@ -1,19 +0,0 @@ -/* - * @file initialize_ground_station_calculator.hpp.hpp - * @brief Initialize function for Ground Station Calculator - */ - -#ifndef S2E_COMPONENTS_REAL_COMMUNICATION_INITIALIZE_GROUND_STATION_CALCULATOR_HPP_ -#define S2E_COMPONENTS_REAL_COMMUNICATION_INITIALIZE_GROUND_STATION_CALCULATOR_HPP_ - -#include - -/* - * @fn InitGscalculator - * @brief Initialize function for Ground Station Calculator - * @param [in] file_name: Path to initialize file - */ - -GroundStationCalculator InitGsCalculator(const std::string file_name); - -#endif // S2E_COMPONENTS_REAL_COMMUNICATION_INITIALIZE_GROUND_STATION_CALCULATOR_HPP_ diff --git a/src/components/real/mission/initialize_telescope.cpp b/src/components/real/mission/initialize_telescope.cpp deleted file mode 100644 index 977c6c548..000000000 --- a/src/components/real/mission/initialize_telescope.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * @file initialize_telescope.cpp - * @brief Initialize function of Telescope - */ - -#include "initialize_telescope.hpp" - -#include - -#include - -#include "library/initialize/initialize_file_access.hpp" - -using namespace std; - -Telescope InitTelescope(ClockGenerator* clock_generator, int sensor_id, const string file_name, const Attitude* attitude, - const HipparcosCatalogue* hipparcos, const LocalCelestialInformation* local_celestial_information) { - using libra::pi; - - IniAccess Telescope_conf(file_name); - const string st_sensor_id = std::to_string(static_cast(sensor_id)); - const char* cs = st_sensor_id.data(); - - char TelescopeSection[30] = "TELESCOPE_"; -#ifdef WIN32 - strcat_s(TelescopeSection, cs); -#else - strcat(TelescopeSection, cs); -#endif - - libra::Quaternion quaternion_b2c; - Telescope_conf.ReadQuaternion(TelescopeSection, "quaternion_b2c", quaternion_b2c); - - double sun_forbidden_angle_deg = Telescope_conf.ReadDouble(TelescopeSection, "sun_exclusion_angle_deg"); - double sun_forbidden_angle_rad = sun_forbidden_angle_deg * pi / 180; // deg to rad - double earth_forbidden_angle_deg = Telescope_conf.ReadDouble(TelescopeSection, "earth_exclusion_angle_deg"); - double earth_forbidden_angle_rad = earth_forbidden_angle_deg * pi / 180; // deg to rad - double moon_forbidden_angle_deg = Telescope_conf.ReadDouble(TelescopeSection, "moon_exclusion_angle_deg"); - double moon_forbidden_angle_rad = moon_forbidden_angle_deg * pi / 180; // deg to rad - - int x_number_of_pix = Telescope_conf.ReadInt(TelescopeSection, "x_number_of_pixel"); - int y_number_of_pix = Telescope_conf.ReadInt(TelescopeSection, "y_number_of_pixel"); - - double x_fov_per_pix_deg = Telescope_conf.ReadDouble(TelescopeSection, "x_fov_deg_per_pixel"); - double x_fov_per_pix_rad = x_fov_per_pix_deg * pi / 180; // deg to rad - double y_fov_per_pix_deg = Telescope_conf.ReadDouble(TelescopeSection, "y_fov_deg_per_pixel"); - double y_fov_per_pix_rad = y_fov_per_pix_deg * pi / 180; // deg to rad - - int number_of_logged_stars = Telescope_conf.ReadInt(TelescopeSection, "number_of_stars_for_log"); - - Telescope telescope(clock_generator, quaternion_b2c, sun_forbidden_angle_rad, earth_forbidden_angle_rad, moon_forbidden_angle_rad, x_number_of_pix, - y_number_of_pix, x_fov_per_pix_rad, y_fov_per_pix_rad, number_of_logged_stars, attitude, hipparcos, - local_celestial_information); - return telescope; -} diff --git a/src/components/real/mission/initialize_telescope.hpp b/src/components/real/mission/initialize_telescope.hpp deleted file mode 100644 index 33b1f906b..000000000 --- a/src/components/real/mission/initialize_telescope.hpp +++ /dev/null @@ -1,24 +0,0 @@ -/* - * @file initialize_telescope.hpp - * @brief Initialize function of Telescope - */ - -#ifndef S2E_COMPONENTS_REAL_MISSION_INITIALIZE_TELESCOPE_HPP_ -#define S2E_COMPONENTS_REAL_MISSION_INITIALIZE_TELESCOPE_HPP_ - -#include "telescope.hpp" - -/* - * @fn InitTelescope - * @brief Initialize function of Telescope - * @param [in] clock_generator: Clock generator - * @param [in] sensor_id: Sensor ID - * @param [in] file_name: Path to initialize file - * @param [in] attitude: Attitude information - * @param [in] hipparcos: Star information by Hipparcos catalogue - * @param [in] local_celestial_information: Local celestial information - */ -Telescope InitTelescope(ClockGenerator* clock_generator, int sensor_id, const std::string file_name, const Attitude* attitude, - const HipparcosCatalogue* hipparcos, const LocalCelestialInformation* local_celestial_information); - -#endif // S2E_COMPONENTS_REAL_MISSION_INITIALIZE_TELESCOPE_HPP_ diff --git a/src/components/real/mission/telescope.cpp b/src/components/real/mission/telescope.cpp index 5603fa98f..462025d6c 100644 --- a/src/components/real/mission/telescope.cpp +++ b/src/components/real/mission/telescope.cpp @@ -6,6 +6,7 @@ #include "telescope.hpp" #include +#include #include using namespace std; @@ -201,3 +202,44 @@ string Telescope::GetLogValue() const { //********************************************************** return str_tmp; } + +Telescope InitTelescope(ClockGenerator* clock_generator, int sensor_id, const string file_name, const Attitude* attitude, + const HipparcosCatalogue* hipparcos, const LocalCelestialInformation* local_celestial_information) { + using libra::pi; + + IniAccess Telescope_conf(file_name); + const string st_sensor_id = std::to_string(static_cast(sensor_id)); + const char* cs = st_sensor_id.data(); + + char TelescopeSection[30] = "TELESCOPE_"; +#ifdef WIN32 + strcat_s(TelescopeSection, cs); +#else + strcat(TelescopeSection, cs); +#endif + + libra::Quaternion quaternion_b2c; + Telescope_conf.ReadQuaternion(TelescopeSection, "quaternion_b2c", quaternion_b2c); + + double sun_forbidden_angle_deg = Telescope_conf.ReadDouble(TelescopeSection, "sun_exclusion_angle_deg"); + double sun_forbidden_angle_rad = sun_forbidden_angle_deg * pi / 180; // deg to rad + double earth_forbidden_angle_deg = Telescope_conf.ReadDouble(TelescopeSection, "earth_exclusion_angle_deg"); + double earth_forbidden_angle_rad = earth_forbidden_angle_deg * pi / 180; // deg to rad + double moon_forbidden_angle_deg = Telescope_conf.ReadDouble(TelescopeSection, "moon_exclusion_angle_deg"); + double moon_forbidden_angle_rad = moon_forbidden_angle_deg * pi / 180; // deg to rad + + int x_number_of_pix = Telescope_conf.ReadInt(TelescopeSection, "x_number_of_pixel"); + int y_number_of_pix = Telescope_conf.ReadInt(TelescopeSection, "y_number_of_pixel"); + + double x_fov_per_pix_deg = Telescope_conf.ReadDouble(TelescopeSection, "x_fov_deg_per_pixel"); + double x_fov_per_pix_rad = x_fov_per_pix_deg * pi / 180; // deg to rad + double y_fov_per_pix_deg = Telescope_conf.ReadDouble(TelescopeSection, "y_fov_deg_per_pixel"); + double y_fov_per_pix_rad = y_fov_per_pix_deg * pi / 180; // deg to rad + + int number_of_logged_stars = Telescope_conf.ReadInt(TelescopeSection, "number_of_stars_for_log"); + + Telescope telescope(clock_generator, quaternion_b2c, sun_forbidden_angle_rad, earth_forbidden_angle_rad, moon_forbidden_angle_rad, x_number_of_pix, + y_number_of_pix, x_fov_per_pix_rad, y_fov_per_pix_rad, number_of_logged_stars, attitude, hipparcos, + local_celestial_information); + return telescope; +} diff --git a/src/components/real/mission/telescope.hpp b/src/components/real/mission/telescope.hpp index ec8218234..681a167e5 100644 --- a/src/components/real/mission/telescope.hpp +++ b/src/components/real/mission/telescope.hpp @@ -145,4 +145,17 @@ class Telescope : public Component, public ILoggable { //************************************************************* }; +/* + * @fn InitTelescope + * @brief Initialize function of Telescope + * @param [in] clock_generator: Clock generator + * @param [in] sensor_id: Sensor ID + * @param [in] file_name: Path to initialize file + * @param [in] attitude: Attitude information + * @param [in] hipparcos: Star information by Hipparcos catalogue + * @param [in] local_celestial_information: Local celestial information + */ +Telescope InitTelescope(ClockGenerator* clock_generator, int sensor_id, const std::string file_name, const Attitude* attitude, + const HipparcosCatalogue* hipparcos, const LocalCelestialInformation* local_celestial_information); + #endif // S2E_COMPONENTS_REAL_MISSION_TELESCOPE_HPP_P_ diff --git a/src/components/real/power/battery.cpp b/src/components/real/power/battery.cpp index 07b2cdf0c..d1e16af5d 100644 --- a/src/components/real/power/battery.cpp +++ b/src/components/real/power/battery.cpp @@ -6,6 +6,7 @@ #include "battery.hpp" #include +#include Battery::Battery(const int prescaler, ClockGenerator* clock_generator, int number_of_series, int number_of_parallel, double cell_capacity_Ah, const std::vector cell_discharge_curve_coefficients, double initial_dod, double cc_charge_c_rate, double cv_charge_voltage_V, @@ -85,3 +86,51 @@ void Battery::UpdateBatVoltage() { } battery_voltage_V_ = temp * number_of_series_; } + +Battery InitBAT(ClockGenerator* clock_generator, int bat_id, const std::string file_name, double component_step_time_s) { + IniAccess bat_conf(file_name); + + const std::string st_bat_id = std::to_string(bat_id); + const char* cs = st_bat_id.data(); + + char Section[30] = "BATTERY_"; + strcat(Section, cs); + + int prescaler = bat_conf.ReadInt(Section, "prescaler"); + if (prescaler <= 1) prescaler = 1; + + int number_of_series; + number_of_series = bat_conf.ReadInt(Section, "number_of_series"); + + int number_of_parallel; + number_of_parallel = bat_conf.ReadInt(Section, "number_of_parallel"); + + double cell_capacity_Ah; + cell_capacity_Ah = bat_conf.ReadDouble(Section, "cell_capacity_Ah"); + + int approx_order; + approx_order = bat_conf.ReadInt(Section, "approximation_order"); + + std::vector cell_discharge_curve_coefficients; + for (int i = 0; i <= approx_order; ++i) { + cell_discharge_curve_coefficients.push_back( + bat_conf.ReadDouble(Section, ("cell_discharge_curve_coefficients(" + std::to_string(i) + ")").c_str())); + } + + double initial_dod; + initial_dod = bat_conf.ReadDouble(Section, "initial_dod"); + + double cc_charge_c_rate; + cc_charge_c_rate = bat_conf.ReadDouble(Section, "constant_charge_current_A_rate_C"); + + double cv_charge_voltage_V; + cv_charge_voltage_V = bat_conf.ReadDouble(Section, "constant_voltage_charge_voltage_V"); + + double battery_resistance_Ohm; + battery_resistance_Ohm = bat_conf.ReadDouble(Section, "battery_resistance_Ohm"); + + Battery battery(prescaler, clock_generator, number_of_series, number_of_parallel, cell_capacity_Ah, cell_discharge_curve_coefficients, initial_dod, + cc_charge_c_rate, cv_charge_voltage_V, battery_resistance_Ohm, component_step_time_s); + + return battery; +} diff --git a/src/components/real/power/battery.hpp b/src/components/real/power/battery.hpp index e827e3c8c..555d87107 100644 --- a/src/components/real/power/battery.hpp +++ b/src/components/real/power/battery.hpp @@ -134,4 +134,14 @@ class Battery : public Component, public ILoggable { void UpdateBatVoltage(); }; +/* + * @fn InitBAT + * @brief Initialize function of Battery + * @param [in] clock_generator: Clock generator + * @param [in] bat_id: Battery ID + * @param [in] file_name: Path to initialize file + * @param [in] component_step_time_s: Component step time [sec] + */ +Battery InitBAT(ClockGenerator* clock_generator, int bat_id, const std::string file_name, double component_step_time_s); + #endif // S2E_COMPONENTS_REAL_POWER_BATTERY_HPP_P_ diff --git a/src/components/real/power/initialize_battery.cpp b/src/components/real/power/initialize_battery.cpp deleted file mode 100644 index 72e66f63b..000000000 --- a/src/components/real/power/initialize_battery.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * @file initialize_battery.cpp - * @brief Initialize function of Battery - */ -#define _CRT_SECURE_NO_WARNINGS -#include "initialize_battery.hpp" - -#include -#include - -#include "library/initialize/initialize_file_access.hpp" - -Battery InitBAT(ClockGenerator* clock_generator, int bat_id, const std::string file_name, double component_step_time_s) { - IniAccess bat_conf(file_name); - - const std::string st_bat_id = std::to_string(bat_id); - const char* cs = st_bat_id.data(); - - char Section[30] = "BATTERY_"; - strcat(Section, cs); - - int prescaler = bat_conf.ReadInt(Section, "prescaler"); - if (prescaler <= 1) prescaler = 1; - - int number_of_series; - number_of_series = bat_conf.ReadInt(Section, "number_of_series"); - - int number_of_parallel; - number_of_parallel = bat_conf.ReadInt(Section, "number_of_parallel"); - - double cell_capacity_Ah; - cell_capacity_Ah = bat_conf.ReadDouble(Section, "cell_capacity_Ah"); - - int approx_order; - approx_order = bat_conf.ReadInt(Section, "approximation_order"); - - std::vector cell_discharge_curve_coefficients; - for (int i = 0; i <= approx_order; ++i) { - cell_discharge_curve_coefficients.push_back( - bat_conf.ReadDouble(Section, ("cell_discharge_curve_coefficients(" + std::to_string(i) + ")").c_str())); - } - - double initial_dod; - initial_dod = bat_conf.ReadDouble(Section, "initial_dod"); - - double cc_charge_c_rate; - cc_charge_c_rate = bat_conf.ReadDouble(Section, "constant_charge_current_A_rate_C"); - - double cv_charge_voltage_V; - cv_charge_voltage_V = bat_conf.ReadDouble(Section, "constant_voltage_charge_voltage_V"); - - double battery_resistance_Ohm; - battery_resistance_Ohm = bat_conf.ReadDouble(Section, "battery_resistance_Ohm"); - - Battery battery(prescaler, clock_generator, number_of_series, number_of_parallel, cell_capacity_Ah, cell_discharge_curve_coefficients, initial_dod, - cc_charge_c_rate, cv_charge_voltage_V, battery_resistance_Ohm, component_step_time_s); - - return battery; -} diff --git a/src/components/real/power/initialize_battery.hpp b/src/components/real/power/initialize_battery.hpp deleted file mode 100644 index 7b3b4d682..000000000 --- a/src/components/real/power/initialize_battery.hpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * @file initialize_battery.hpp - * @brief Initialize function of Battery - */ - -#ifndef S2E_COMPONENTS_REAL_POWER_INITIALIZE_BATTERY_HPP_ -#define S2E_COMPONENTS_REAL_POWER_INITIALIZE_BATTERY_HPP_ - -#include - -/* - * @fn InitBAT - * @brief Initialize function of Battery - * @param [in] clock_generator: Clock generator - * @param [in] bat_id: Battery ID - * @param [in] file_name: Path to initialize file - * @param [in] component_step_time_s: Component step time [sec] - */ -Battery InitBAT(ClockGenerator* clock_generator, int bat_id, const std::string file_name, double component_step_time_s); - -#endif // S2E_COMPONENTS_REAL_POWER_INITIALIZE_BATTERY_HPP_ diff --git a/src/components/real/power/initialize_pcu_initial_study.cpp b/src/components/real/power/initialize_pcu_initial_study.cpp deleted file mode 100644 index 65c061ec0..000000000 --- a/src/components/real/power/initialize_pcu_initial_study.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * @file initialize_pcu_initial_study.cpp - * @brief Initialize function of PcuInitialStudy - */ - -#define _CRT_SECURE_NO_WARNINGS -#include "initialize_pcu_initial_study.hpp" - -#include -#include - -#include "library/initialize/initialize_file_access.hpp" - -PcuInitialStudy InitPCU_InitialStudy(ClockGenerator* clock_generator, int pcu_id, const std::string file_name, - const std::vector saps, Battery* battery, double component_step_time_s) { - IniAccess pcu_conf(file_name); - - const std::string st_pcu_id = std::to_string(pcu_id); - const char* cs = st_pcu_id.data(); - - char Section[30] = "PCU_INITIAL_STUDY_"; - strcat(Section, cs); - - int prescaler = pcu_conf.ReadInt(Section, "prescaler"); - if (prescaler <= 1) prescaler = 1; - - PcuInitialStudy pcu(prescaler, clock_generator, saps, battery, component_step_time_s); - - return pcu; -} diff --git a/src/components/real/power/initialize_pcu_initial_study.hpp b/src/components/real/power/initialize_pcu_initial_study.hpp deleted file mode 100644 index d11e0e0fa..000000000 --- a/src/components/real/power/initialize_pcu_initial_study.hpp +++ /dev/null @@ -1,24 +0,0 @@ -/* - * @file initialize_pcu_initial_study.hpp - * @brief Initialize function of PcuInitialStudy - */ - -#ifndef S2E_COMPONENTS_REAL_POWER_INITIALIZE_PCU_INITIAL_STUDY_HPP_ -#define S2E_COMPONENTS_REAL_POWER_INITIALIZE_PCU_INITIAL_STUDY_HPP_ - -#include - -/* - * @fn InitPCU_InitialStudy - * @brief Initialize function of Battery - * @param [in] clock_generator: Clock generator - * @param [in] pcu_id: Power Control Unit ID - * @param [in] file_name: Path to initialize file - * @param [in] sap: Solar Array Panel infomation - * @param [in] battery: Battery information - * @param [in] component_step_time_s: Component step time [sec] - */ -PcuInitialStudy InitPCU_InitialStudy(ClockGenerator* clock_generator, int pcu_id, const std::string file_name, - const std::vector saps, Battery* battery, double component_step_time_s); - -#endif // S2E_COMPONENTS_REAL_POWER_INITIALIZE_PCU_INITIAL_STUDY_HPP_ diff --git a/src/components/real/power/initialize_solar_array_panel.cpp b/src/components/real/power/initialize_solar_array_panel.cpp deleted file mode 100644 index 0299ac2e1..000000000 --- a/src/components/real/power/initialize_solar_array_panel.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * @file initialize_solar_array_panel.cpp - * @brief Initialize function of SolarArrayPanel (Solar Array Panel) - */ -#define _CRT_SECURE_NO_WARNINGS -#include "initialize_solar_array_panel.hpp" - -#include - -#include "library/initialize/initialize_file_access.hpp" - -SolarArrayPanel InitSAP(ClockGenerator* clock_generator, int sap_id, const std::string file_name, - const SolarRadiationPressureEnvironment* srp_environment, const LocalCelestialInformation* local_celestial_information, - double component_step_time_s) { - IniAccess sap_conf(file_name); - - const std::string st_sap_id = std::to_string(sap_id); - const char* cs = st_sap_id.data(); - - char Section[30] = "SOLAR_ARRAY_PANEL_"; - strcat(Section, cs); - - int prescaler = sap_conf.ReadInt(Section, "prescaler"); - if (prescaler <= 1) prescaler = 1; - - int number_of_series; - number_of_series = sap_conf.ReadInt(Section, "number_of_series"); - - int number_of_parallel; - number_of_parallel = sap_conf.ReadInt(Section, "number_of_parallel"); - - double cell_area_m2; - cell_area_m2 = sap_conf.ReadDouble(Section, "cell_area_m2"); - - libra::Vector<3> normal_vector; - sap_conf.ReadVector(Section, "normal_vector_b", normal_vector); - - double cell_efficiency; - cell_efficiency = sap_conf.ReadDouble(Section, "cell_efficiency"); - - double transmission_efficiency; - transmission_efficiency = sap_conf.ReadDouble(Section, "transmission_efficiency"); - - SolarArrayPanel sap(prescaler, clock_generator, sap_id, number_of_series, number_of_parallel, cell_area_m2, normal_vector, cell_efficiency, - transmission_efficiency, srp_environment, local_celestial_information, component_step_time_s); - - return sap; -} - -SolarArrayPanel InitSAP(ClockGenerator* clock_generator, int sap_id, const std::string file_name, - const SolarRadiationPressureEnvironment* srp_environment, double component_step_time_s) { - IniAccess sap_conf(file_name); - - const std::string st_sap_id = std::to_string(sap_id); - const char* cs = st_sap_id.data(); - - char Section[30] = "SOLAR_ARRAY_PANEL_"; - strcat(Section, cs); - - int prescaler = sap_conf.ReadInt(Section, "prescaler"); - if (prescaler <= 1) prescaler = 1; - - int number_of_series; - number_of_series = sap_conf.ReadInt(Section, "number_of_series"); - - int number_of_parallel; - number_of_parallel = sap_conf.ReadInt(Section, "number_of_parallel"); - - double cell_area_m2; - cell_area_m2 = sap_conf.ReadDouble(Section, "cell_area_m2"); - - libra::Vector<3> normal_vector; - sap_conf.ReadVector(Section, "normal_vector_b", normal_vector); - - double cell_efficiency; - cell_efficiency = sap_conf.ReadDouble(Section, "cell_efficiency"); - - double transmission_efficiency; - transmission_efficiency = sap_conf.ReadDouble(Section, "transmission_efficiency"); - - SolarArrayPanel sap(prescaler, clock_generator, sap_id, number_of_series, number_of_parallel, cell_area_m2, normal_vector, cell_efficiency, - transmission_efficiency, srp_environment, component_step_time_s); - - return sap; -} diff --git a/src/components/real/power/initialize_solar_array_panel.hpp b/src/components/real/power/initialize_solar_array_panel.hpp deleted file mode 100644 index e7edff7ce..000000000 --- a/src/components/real/power/initialize_solar_array_panel.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * @file initialize_solar_array_panel.hpp - * @brief Initialize function of SolarArrayPanel (Solar Array Panel) - */ - -#ifndef S2E_COMPONENTS_REAL_POWER_INITIALIZE_SOLAR_ARRAY_PANEL_HPP_ -#define S2E_COMPONENTS_REAL_POWER_INITIALIZE_SOLAR_ARRAY_PANEL_HPP_ - -#include - -/* - * @fn InitSAP - * @brief Initialize function of Battery - * @param [in] clock_generator: Clock generator - * @param [in] sap_id: SolarArrayPanel ID - * @param [in] file_name: Path to initialize file - * @param [in] srp_environment: Solar Radiation Pressure environment - * @param [in] local_celestial_information: Local celestial information - * @param [in] component_step_time_s: Component step time [sec] - */ -SolarArrayPanel InitSAP(ClockGenerator* clock_generator, int sap_id, const std::string file_name, - const SolarRadiationPressureEnvironment* srp_environment, const LocalCelestialInformation* local_celestial_information, - double component_step_time_s); - -/* - * @fn InitSAP - * @brief Initialize function of Battery - * @param [in] clock_generator: Clock generator - * @param [in] sap_id: SolarArrayPanel ID - * @param [in] file_name: Path to initialize file - * @param [in] srp_environment: Solar Radiation Pressure environment - * @param [in] component_step_time_s: Component step time [sec] - */ -SolarArrayPanel InitSAP(ClockGenerator* clock_generator, int sap_id, const std::string file_name, - const SolarRadiationPressureEnvironment* srp_environment, double component_step_time_s); - -#endif // S2E_COMPONENTS_REAL_POWER_INITIALIZE_SOLAR_ARRAY_PANEL_HPP_ diff --git a/src/components/real/power/pcu_initial_study.cpp b/src/components/real/power/pcu_initial_study.cpp index d9617c63f..c50f539b4 100644 --- a/src/components/real/power/pcu_initial_study.cpp +++ b/src/components/real/power/pcu_initial_study.cpp @@ -8,6 +8,7 @@ #include #include #include +#include PcuInitialStudy::PcuInitialStudy(const int prescaler, ClockGenerator* clock_generator, const std::vector saps, Battery* battery, double component_step_time_s) @@ -109,3 +110,21 @@ void PcuInitialStudy::UpdateChargeCurrentAndBusVoltage() { } } } + +PcuInitialStudy InitPCU_InitialStudy(ClockGenerator* clock_generator, int pcu_id, const std::string file_name, + const std::vector saps, Battery* battery, double component_step_time_s) { + IniAccess pcu_conf(file_name); + + const std::string st_pcu_id = std::to_string(pcu_id); + const char* cs = st_pcu_id.data(); + + char Section[30] = "PCU_INITIAL_STUDY_"; + strcat(Section, cs); + + int prescaler = pcu_conf.ReadInt(Section, "prescaler"); + if (prescaler <= 1) prescaler = 1; + + PcuInitialStudy pcu(prescaler, clock_generator, saps, battery, component_step_time_s); + + return pcu; +} diff --git a/src/components/real/power/pcu_initial_study.hpp b/src/components/real/power/pcu_initial_study.hpp index ebb338871..33bc65a00 100644 --- a/src/components/real/power/pcu_initial_study.hpp +++ b/src/components/real/power/pcu_initial_study.hpp @@ -82,4 +82,17 @@ class PcuInitialStudy : public Component, public ILoggable { void UpdateChargeCurrentAndBusVoltage(); }; +/* + * @fn InitPCU_InitialStudy + * @brief Initialize function of Battery + * @param [in] clock_generator: Clock generator + * @param [in] pcu_id: Power Control Unit ID + * @param [in] file_name: Path to initialize file + * @param [in] sap: Solar Array Panel infomation + * @param [in] battery: Battery information + * @param [in] component_step_time_s: Component step time [sec] + */ +PcuInitialStudy InitPCU_InitialStudy(ClockGenerator* clock_generator, int pcu_id, const std::string file_name, + const std::vector saps, Battery* battery, double component_step_time_s); + #endif // S2E_COMPONENTS_REAL_POWER_PCU_INITIAL_STUDY_HPP_ diff --git a/src/components/real/power/solar_array_panel.cpp b/src/components/real/power/solar_array_panel.cpp index 711c00447..2ed2a9698 100644 --- a/src/components/real/power/solar_array_panel.cpp +++ b/src/components/real/power/solar_array_panel.cpp @@ -7,6 +7,7 @@ #include #include +#include SolarArrayPanel::SolarArrayPanel(const int prescaler, ClockGenerator* clock_generator, int component_id, int number_of_series, int number_of_parallel, double cell_area_m2, libra::Vector<3> normal_vector, double cell_efficiency, double transmission_efficiency, @@ -112,3 +113,78 @@ void SolarArrayPanel::MainRoutine(const int time_count) { } if (power_generation_W_ < 0) power_generation_W_ = 0.0; } + +SolarArrayPanel InitSAP(ClockGenerator* clock_generator, int sap_id, const std::string file_name, + const SolarRadiationPressureEnvironment* srp_environment, const LocalCelestialInformation* local_celestial_information, + double component_step_time_s) { + IniAccess sap_conf(file_name); + + const std::string st_sap_id = std::to_string(sap_id); + const char* cs = st_sap_id.data(); + + char Section[30] = "SOLAR_ARRAY_PANEL_"; + strcat(Section, cs); + + int prescaler = sap_conf.ReadInt(Section, "prescaler"); + if (prescaler <= 1) prescaler = 1; + + int number_of_series; + number_of_series = sap_conf.ReadInt(Section, "number_of_series"); + + int number_of_parallel; + number_of_parallel = sap_conf.ReadInt(Section, "number_of_parallel"); + + double cell_area_m2; + cell_area_m2 = sap_conf.ReadDouble(Section, "cell_area_m2"); + + libra::Vector<3> normal_vector; + sap_conf.ReadVector(Section, "normal_vector_b", normal_vector); + + double cell_efficiency; + cell_efficiency = sap_conf.ReadDouble(Section, "cell_efficiency"); + + double transmission_efficiency; + transmission_efficiency = sap_conf.ReadDouble(Section, "transmission_efficiency"); + + SolarArrayPanel sap(prescaler, clock_generator, sap_id, number_of_series, number_of_parallel, cell_area_m2, normal_vector, cell_efficiency, + transmission_efficiency, srp_environment, local_celestial_information, component_step_time_s); + + return sap; +} + +SolarArrayPanel InitSAP(ClockGenerator* clock_generator, int sap_id, const std::string file_name, + const SolarRadiationPressureEnvironment* srp_environment, double component_step_time_s) { + IniAccess sap_conf(file_name); + + const std::string st_sap_id = std::to_string(sap_id); + const char* cs = st_sap_id.data(); + + char Section[30] = "SOLAR_ARRAY_PANEL_"; + strcat(Section, cs); + + int prescaler = sap_conf.ReadInt(Section, "prescaler"); + if (prescaler <= 1) prescaler = 1; + + int number_of_series; + number_of_series = sap_conf.ReadInt(Section, "number_of_series"); + + int number_of_parallel; + number_of_parallel = sap_conf.ReadInt(Section, "number_of_parallel"); + + double cell_area_m2; + cell_area_m2 = sap_conf.ReadDouble(Section, "cell_area_m2"); + + libra::Vector<3> normal_vector; + sap_conf.ReadVector(Section, "normal_vector_b", normal_vector); + + double cell_efficiency; + cell_efficiency = sap_conf.ReadDouble(Section, "cell_efficiency"); + + double transmission_efficiency; + transmission_efficiency = sap_conf.ReadDouble(Section, "transmission_efficiency"); + + SolarArrayPanel sap(prescaler, clock_generator, sap_id, number_of_series, number_of_parallel, cell_area_m2, normal_vector, cell_efficiency, + transmission_efficiency, srp_environment, component_step_time_s); + + return sap; +} diff --git a/src/components/real/power/solar_array_panel.hpp b/src/components/real/power/solar_array_panel.hpp index 4a511d627..d4db31217 100644 --- a/src/components/real/power/solar_array_panel.hpp +++ b/src/components/real/power/solar_array_panel.hpp @@ -131,4 +131,30 @@ class SolarArrayPanel : public Component, public ILoggable { void MainRoutine(const int time_count) override; }; +/* + * @fn InitSAP + * @brief Initialize function of Battery + * @param [in] clock_generator: Clock generator + * @param [in] sap_id: SolarArrayPanel ID + * @param [in] file_name: Path to initialize file + * @param [in] srp_environment: Solar Radiation Pressure environment + * @param [in] local_celestial_information: Local celestial information + * @param [in] component_step_time_s: Component step time [sec] + */ +SolarArrayPanel InitSAP(ClockGenerator* clock_generator, int sap_id, const std::string file_name, + const SolarRadiationPressureEnvironment* srp_environment, const LocalCelestialInformation* local_celestial_information, + double component_step_time_s); + +/* + * @fn InitSAP + * @brief Initialize function of Battery + * @param [in] clock_generator: Clock generator + * @param [in] sap_id: SolarArrayPanel ID + * @param [in] file_name: Path to initialize file + * @param [in] srp_environment: Solar Radiation Pressure environment + * @param [in] component_step_time_s: Component step time [sec] + */ +SolarArrayPanel InitSAP(ClockGenerator* clock_generator, int sap_id, const std::string file_name, + const SolarRadiationPressureEnvironment* srp_environment, double component_step_time_s); + #endif // S2E_COMPONENTS_REAL_POWER_SOLAR_ARRAY_PANEL_HPP_ diff --git a/src/components/real/propulsion/initialize_simple_thruster.cpp b/src/components/real/propulsion/initialize_simple_thruster.cpp deleted file mode 100644 index 2fc333a2f..000000000 --- a/src/components/real/propulsion/initialize_simple_thruster.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * @file initialize_simple_thruster.cpp - * @brief Initialize function os SimpleThruster - */ -#include "initialize_simple_thruster.hpp" - -#include - -#include "library/initialize/initialize_file_access.hpp" - -SimpleThruster InitSimpleThruster(ClockGenerator* clock_generator, int thruster_id, const std::string file_name, const Structure* structure, - const Dynamics* dynamics) { - IniAccess thruster_conf(file_name); - std::string sectionstr = "THRUSTER_" + std::to_string(thruster_id); - auto* Section = sectionstr.c_str(); - - int prescaler = thruster_conf.ReadInt(Section, "prescaler"); - if (prescaler <= 1) prescaler = 1; - - Vector<3> thruster_pos; - thruster_conf.ReadVector(Section, "thruster_position_b_m", thruster_pos); - - Vector<3> thruster_dir; - thruster_conf.ReadVector(Section, "thruster_direction_b", thruster_dir); - - double max_magnitude_N = thruster_conf.ReadDouble(Section, "thrust_magnitude_N"); - - double magnitude_standard_deviation_N; - magnitude_standard_deviation_N = thruster_conf.ReadDouble(Section, "thrust_error_standard_deviation_N"); - - double deg_err; - deg_err = thruster_conf.ReadDouble(Section, "direction_error_standard_deviation_deg") * libra::pi / 180.0; - - SimpleThruster thruster(prescaler, clock_generator, thruster_id, thruster_pos, thruster_dir, max_magnitude_N, magnitude_standard_deviation_N, - deg_err, structure, dynamics); - return thruster; -} - -SimpleThruster InitSimpleThruster(ClockGenerator* clock_generator, PowerPort* power_port, int thruster_id, const std::string file_name, - const Structure* structure, const Dynamics* dynamics) { - IniAccess thruster_conf(file_name); - std::string sectionstr = "THRUSTER_" + std::to_string(thruster_id); - auto* Section = sectionstr.c_str(); - - int prescaler = thruster_conf.ReadInt(Section, "prescaler"); - if (prescaler <= 1) prescaler = 1; - - Vector<3> thruster_pos; - thruster_conf.ReadVector(Section, "thruster_position_b_m", thruster_pos); - - Vector<3> thruster_dir; - thruster_conf.ReadVector(Section, "thruster_direction_b", thruster_dir); - - double max_magnitude_N = thruster_conf.ReadDouble(Section, "thrust_magnitude_N"); - - double magnitude_standard_deviation_N; - magnitude_standard_deviation_N = thruster_conf.ReadDouble(Section, "thrust_error_standard_deviation_N"); - - double deg_err; - deg_err = thruster_conf.ReadDouble(Section, "direction_error_standard_deviation_deg") * libra::pi / 180.0; - - power_port->InitializeWithInitializeFile(file_name); - - SimpleThruster thruster(prescaler, clock_generator, power_port, thruster_id, thruster_pos, thruster_dir, max_magnitude_N, - magnitude_standard_deviation_N, deg_err, structure, dynamics); - return thruster; -} diff --git a/src/components/real/propulsion/initialize_simple_thruster.hpp b/src/components/real/propulsion/initialize_simple_thruster.hpp deleted file mode 100644 index bdb7b5381..000000000 --- a/src/components/real/propulsion/initialize_simple_thruster.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * @file initialize_simple_thruster.hpp - * @brief Initialize function os SimpleThruster - */ - -#ifndef S2E_COMPONENTS_REAL_PROPULSION_INITIALIZE_SIMPLE_THRUSTER_HPP_ -#define S2E_COMPONENTS_REAL_PROPULSION_INITIALIZE_SIMPLE_THRUSTER_HPP_ - -#include "simple_thruster.hpp" - -/** - * @fn InitSimpleThruster - * @brief Initialize function os SimpleThruster - * @param [in] clock_generator: Clock generator - * @param [in] thruster_id: Thruster ID - * @param [in] file_name: Path to initialize file - * @param [in] structure: Spacecraft structure information - * @param [in] dynamics: Spacecraft dynamics information - */ -SimpleThruster InitSimpleThruster(ClockGenerator* clock_generator, int thruster_id, const std::string file_name, const Structure* structure, - const Dynamics* dynamics); -/** - * @fn InitSimpleThruster - * @brief Initialize function os SimpleThruster - * @param [in] clock_generator: Clock generator - * @param [in] power_port: Power port - * @param [in] thruster_id: Thruster ID - * @param [in] file_name: Path to initialize file - * @param [in] structure: Spacecraft structure information - * @param [in] dynamics: Spacecraft dynamics information - */ -SimpleThruster InitSimpleThruster(ClockGenerator* clock_generator, PowerPort* power_port, int thruster_id, const std::string file_name, - const Structure* structure, const Dynamics* dynamics); - -#endif // S2E_COMPONENTS_REAL_PROPULSION_INITIALIZE_SIMPLE_THRUSTER_HPP_ diff --git a/src/components/real/propulsion/simple_thruster.cpp b/src/components/real/propulsion/simple_thruster.cpp index c66ab1d81..dd3796698 100644 --- a/src/components/real/propulsion/simple_thruster.cpp +++ b/src/components/real/propulsion/simple_thruster.cpp @@ -5,6 +5,7 @@ #include "simple_thruster.hpp" #include +#include #include #include @@ -118,3 +119,61 @@ libra::Vector<3> SimpleThruster::CalcThrustDirection() { return thrust_dir_b_true; } + +SimpleThruster InitSimpleThruster(ClockGenerator* clock_generator, int thruster_id, const std::string file_name, const Structure* structure, + const Dynamics* dynamics) { + IniAccess thruster_conf(file_name); + std::string sectionstr = "THRUSTER_" + std::to_string(thruster_id); + auto* Section = sectionstr.c_str(); + + int prescaler = thruster_conf.ReadInt(Section, "prescaler"); + if (prescaler <= 1) prescaler = 1; + + Vector<3> thruster_pos; + thruster_conf.ReadVector(Section, "thruster_position_b_m", thruster_pos); + + Vector<3> thruster_dir; + thruster_conf.ReadVector(Section, "thruster_direction_b", thruster_dir); + + double max_magnitude_N = thruster_conf.ReadDouble(Section, "thrust_magnitude_N"); + + double magnitude_standard_deviation_N; + magnitude_standard_deviation_N = thruster_conf.ReadDouble(Section, "thrust_error_standard_deviation_N"); + + double deg_err; + deg_err = thruster_conf.ReadDouble(Section, "direction_error_standard_deviation_deg") * libra::pi / 180.0; + + SimpleThruster thruster(prescaler, clock_generator, thruster_id, thruster_pos, thruster_dir, max_magnitude_N, magnitude_standard_deviation_N, + deg_err, structure, dynamics); + return thruster; +} + +SimpleThruster InitSimpleThruster(ClockGenerator* clock_generator, PowerPort* power_port, int thruster_id, const std::string file_name, + const Structure* structure, const Dynamics* dynamics) { + IniAccess thruster_conf(file_name); + std::string sectionstr = "THRUSTER_" + std::to_string(thruster_id); + auto* Section = sectionstr.c_str(); + + int prescaler = thruster_conf.ReadInt(Section, "prescaler"); + if (prescaler <= 1) prescaler = 1; + + Vector<3> thruster_pos; + thruster_conf.ReadVector(Section, "thruster_position_b_m", thruster_pos); + + Vector<3> thruster_dir; + thruster_conf.ReadVector(Section, "thruster_direction_b", thruster_dir); + + double max_magnitude_N = thruster_conf.ReadDouble(Section, "thrust_magnitude_N"); + + double magnitude_standard_deviation_N; + magnitude_standard_deviation_N = thruster_conf.ReadDouble(Section, "thrust_error_standard_deviation_N"); + + double deg_err; + deg_err = thruster_conf.ReadDouble(Section, "direction_error_standard_deviation_deg") * libra::pi / 180.0; + + power_port->InitializeWithInitializeFile(file_name); + + SimpleThruster thruster(prescaler, clock_generator, power_port, thruster_id, thruster_pos, thruster_dir, max_magnitude_N, + magnitude_standard_deviation_N, deg_err, structure, dynamics); + return thruster; +} diff --git a/src/components/real/propulsion/simple_thruster.hpp b/src/components/real/propulsion/simple_thruster.hpp index 5fefe2fe9..37496490f 100644 --- a/src/components/real/propulsion/simple_thruster.hpp +++ b/src/components/real/propulsion/simple_thruster.hpp @@ -155,4 +155,28 @@ class SimpleThruster : public Component, public ILoggable { const Dynamics* dynamics_; //!< Spacecraft dynamics information }; +/** + * @fn InitSimpleThruster + * @brief Initialize function os SimpleThruster + * @param [in] clock_generator: Clock generator + * @param [in] thruster_id: Thruster ID + * @param [in] file_name: Path to initialize file + * @param [in] structure: Spacecraft structure information + * @param [in] dynamics: Spacecraft dynamics information + */ +SimpleThruster InitSimpleThruster(ClockGenerator* clock_generator, int thruster_id, const std::string file_name, const Structure* structure, + const Dynamics* dynamics); +/** + * @fn InitSimpleThruster + * @brief Initialize function os SimpleThruster + * @param [in] clock_generator: Clock generator + * @param [in] power_port: Power port + * @param [in] thruster_id: Thruster ID + * @param [in] file_name: Path to initialize file + * @param [in] structure: Spacecraft structure information + * @param [in] dynamics: Spacecraft dynamics information + */ +SimpleThruster InitSimpleThruster(ClockGenerator* clock_generator, PowerPort* power_port, int thruster_id, const std::string file_name, + const Structure* structure, const Dynamics* dynamics); + #endif // S2E_COMPONENTS_REAL_PROPULSION_SIMPLE_THRUSTER_HPP_ diff --git a/src/simulation_sample/ground_station/sample_ground_station_components.hpp b/src/simulation_sample/ground_station/sample_ground_station_components.hpp index 067ddd2d8..15f1632bb 100644 --- a/src/simulation_sample/ground_station/sample_ground_station_components.hpp +++ b/src/simulation_sample/ground_station/sample_ground_station_components.hpp @@ -6,8 +6,8 @@ #ifndef S2E_SIMULATION_SAMPLE_GROUND_STATION_SAMPLE_GROUND_STATION_COMPONENTS_HPP_ #define S2E_SIMULATION_SAMPLE_GROUND_STATION_SAMPLE_GROUND_STATION_COMPONENTS_HPP_ -#include -#include +#include +#include /** * @class SampleGsComponents diff --git a/src/simulation_sample/spacecraft/sample_components.hpp b/src/simulation_sample/spacecraft/sample_components.hpp index 5f16dcfd1..69f1ae82e 100644 --- a/src/simulation_sample/spacecraft/sample_components.hpp +++ b/src/simulation_sample/spacecraft/sample_components.hpp @@ -10,20 +10,20 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include +#include +#include +#include #include -#include +#include #include -#include +#include #include #include #include