Skip to content

Commit

Permalink
Merge pull request #493 from ut-issl/feature/remove-initialize-for-co…
Browse files Browse the repository at this point in the history
…mponents

Remove initialize source files for components
  • Loading branch information
200km authored Oct 2, 2023
2 parents df05948 + 1a9ba0b commit cada2dc
Show file tree
Hide file tree
Showing 71 changed files with 1,245 additions and 1,600 deletions.
16 changes: 0 additions & 16 deletions src/components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,22 @@ 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
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
Expand All @@ -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
Expand Down
26 changes: 0 additions & 26 deletions src/components/base/initialize_sensor.hpp

This file was deleted.

53 changes: 0 additions & 53 deletions src/components/base/initialize_sensor_template_functions.hpp

This file was deleted.

13 changes: 13 additions & 0 deletions src/components/base/sensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <size_t N>
Sensor<N> 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_
43 changes: 43 additions & 0 deletions src/components/base/sensor_template_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#ifndef S2E_COMPONENTS_BASE_SENSOR_TEMPLATE_FUNCTIONS_HPP_
#define S2E_COMPONENTS_BASE_SENSOR_TEMPLATE_FUNCTIONS_HPP_

#include <library/initialize/initialize_file_access.hpp>
#include <library/randomization/global_randomization.hpp>

template <size_t N>
Expand Down Expand Up @@ -74,4 +75,46 @@ void Sensor<N>::RangeCheck(void) {
}
}

template <size_t N>
Sensor<N> 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<N * N> scale_factor_vector;
ini_file.ReadVector(section.c_str(), "scale_factor_c", scale_factor_vector);
libra::Matrix<N, N> 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<N> constant_bias_c;
key_name = "constant_bias_c_" + unit;
ini_file.ReadVector(section.c_str(), key_name.c_str(), constant_bias_c);
libra::Vector<N> 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<N> 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<N> 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<N> 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<N> range_to_zero_c{range_to_zero};

Sensor<N> 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_
19 changes: 19 additions & 0 deletions src/components/ideal/force_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "force_generator.hpp"

#include <cfloat>
#include <library/initialize/initialize_file_access.hpp>

// Constructor
ForceGenerator::ForceGenerator(const int prescaler, ClockGenerator* clock_generator, const double magnitude_error_standard_deviation_N,
Expand Down Expand Up @@ -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;
}
9 changes: 9 additions & 0 deletions src/components/ideal/force_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_
25 changes: 0 additions & 25 deletions src/components/ideal/initialize_force_generator.cpp

This file was deleted.

20 changes: 0 additions & 20 deletions src/components/ideal/initialize_force_generator.hpp

This file was deleted.

26 changes: 0 additions & 26 deletions src/components/ideal/initialize_torque_generator.cpp

This file was deleted.

20 changes: 0 additions & 20 deletions src/components/ideal/initialize_torque_generator.hpp

This file was deleted.

20 changes: 20 additions & 0 deletions src/components/ideal/torque_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "torque_generator.hpp"

#include <cfloat>
#include <library/initialize/initialize_file_access.hpp>

// Constructor
TorqueGenerator::TorqueGenerator(const int prescaler, ClockGenerator* clock_generator, const double magnitude_error_standard_deviation_Nm,
Expand Down Expand Up @@ -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;
}
9 changes: 9 additions & 0 deletions src/components/ideal/torque_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Loading

0 comments on commit cada2dc

Please sign in to comment.