diff --git a/src/components/base/component.cpp b/src/components/base/component.cpp index 82fdf14c9..469c4e981 100644 --- a/src/components/base/component.cpp +++ b/src/components/base/component.cpp @@ -5,7 +5,9 @@ #include "component.hpp" -Component::Component(const unsigned int prescaler, ClockGenerator* clock_generator, const unsigned int fast_prescaler) +namespace s2e::components { + +Component::Component(const unsigned int prescaler, environment::ClockGenerator* clock_generator, const unsigned int fast_prescaler) : clock_generator_(clock_generator) { power_port_ = new PowerPort(); clock_generator_->RegisterComponent(this); @@ -13,7 +15,8 @@ Component::Component(const unsigned int prescaler, ClockGenerator* clock_generat fast_prescaler_ = (fast_prescaler > 0) ? fast_prescaler : 1; } -Component::Component(const unsigned int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, const unsigned int fast_prescaler) +Component::Component(const unsigned int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, + const unsigned int fast_prescaler) : clock_generator_(clock_generator), power_port_(power_port) { clock_generator_->RegisterComponent(this); prescaler_ = (prescaler > 0) ? prescaler : 1; @@ -48,3 +51,5 @@ void Component::FastTick(const unsigned int fast_count) { PowerOffRoutine(); } } + +} // namespace s2e::components diff --git a/src/components/base/component.hpp b/src/components/base/component.hpp index 91432e1f3..2cfc64db5 100644 --- a/src/components/base/component.hpp +++ b/src/components/base/component.hpp @@ -12,6 +12,8 @@ #include "interface_tickable.hpp" +namespace s2e::components { + /** * @class Component * @brief Base class for component emulation. All components have to inherit this. @@ -27,7 +29,7 @@ class Component : public ITickable { * @param [in] clock_generator: Clock generator * @param [in] fast_prescaler: Frequency scale factor for fast update (used only for component faster than component update period) */ - Component(const unsigned int prescaler, ClockGenerator* clock_generator, const unsigned int fast_prescaler = 1); + Component(const unsigned int prescaler, environment::ClockGenerator* clock_generator, const unsigned int fast_prescaler = 1); /** * @fn Component * @brief Constructor with power port @@ -36,7 +38,7 @@ class Component : public ITickable { * @param [in] power_port: Power port * @param [in] fast_prescaler: Frequency scale factor for fast update (used only for component faster than component update period) */ - Component(const unsigned int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, const unsigned int fast_prescaler = 1); + Component(const unsigned int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, const unsigned int fast_prescaler = 1); /** * @fn Component * @brief Copy constructor @@ -76,16 +78,18 @@ class Component : public ITickable { * @brief Pure virtual function used to calculate high-frequency disturbances(e.g. RW jitter) * @note Override only when high-frequency disturbances need to be calculated. */ - virtual void FastUpdate(){}; + virtual void FastUpdate() {}; /** * @fn PowerOffRoutine * @brief Pure virtual function executed when the power switch is off. */ - virtual void PowerOffRoutine(){}; + virtual void PowerOffRoutine() {}; - ClockGenerator* clock_generator_; //!< Clock generator - PowerPort* power_port_; //!< Power port + environment::ClockGenerator* clock_generator_; //!< Clock generator + PowerPort* power_port_; //!< Power port }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_BASE_COMPONENT_HPP_ diff --git a/src/components/base/gpio_connection_with_obc.cpp b/src/components/base/gpio_connection_with_obc.cpp index 7a3024a66..ceae6170b 100644 --- a/src/components/base/gpio_connection_with_obc.cpp +++ b/src/components/base/gpio_connection_with_obc.cpp @@ -6,6 +6,8 @@ #include "gpio_connection_with_obc.hpp" +namespace s2e::components { + GpioConnectionWithObc::GpioConnectionWithObc(const std::vector port_id, OnBoardComputer* obc) : port_id_(port_id), obc_(obc) { for (size_t i = 0; i < port_id_.size(); i++) { obc_->GpioConnectPort(port_id_[i]); @@ -17,3 +19,5 @@ GpioConnectionWithObc::~GpioConnectionWithObc() {} bool GpioConnectionWithObc::Read(const int index) { return obc_->GpioComponentRead(port_id_[index]); } void GpioConnectionWithObc::Write(const int index, const bool is_high) { obc_->GpioComponentWrite(port_id_[index], is_high); } + +} // namespace s2e::components diff --git a/src/components/base/gpio_connection_with_obc.hpp b/src/components/base/gpio_connection_with_obc.hpp index 397456674..752d36d5b 100644 --- a/src/components/base/gpio_connection_with_obc.hpp +++ b/src/components/base/gpio_connection_with_obc.hpp @@ -9,6 +9,8 @@ #include "../real/cdh/on_board_computer.hpp" +namespace s2e::components { + /** * @class GpioConnectionWithObc * @brief Base class for GPIO communication with OBC flight software @@ -50,4 +52,6 @@ class GpioConnectionWithObc { OnBoardComputer* obc_; //!< The communication target OBC }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_BASE_GPIO_CONNECTION_WITH_OBC_HPP_ diff --git a/src/components/base/i2c_controller.cpp b/src/components/base/i2c_controller.cpp index 64e1429ba..48a6850d7 100644 --- a/src/components/base/i2c_controller.cpp +++ b/src/components/base/i2c_controller.cpp @@ -7,8 +7,10 @@ #include #include +namespace s2e::components { + I2cController::I2cController(const unsigned int hils_port_id, const unsigned int baud_rate, const unsigned int tx_buffer_size, - const unsigned int rx_buffer_size, HilsPortManager* hils_port_manager) + const unsigned int rx_buffer_size, simulation::HilsPortManager* hils_port_manager) : hils_port_id_(hils_port_id), baud_rate_(baud_rate), tx_buffer_size_(tx_buffer_size), @@ -48,3 +50,5 @@ int I2cController::SendCommand(const unsigned char length) { if (simulation_mode_ != SimulationMode::kHils) return -1; return hils_port_manager_->I2cControllerSend(hils_port_id_, &tx_buffer_.front(), 0, length); } + +} // namespace s2e::components diff --git a/src/components/base/i2c_controller.hpp b/src/components/base/i2c_controller.hpp index 62f59e480..f300a9710 100644 --- a/src/components/base/i2c_controller.hpp +++ b/src/components/base/i2c_controller.hpp @@ -9,6 +9,8 @@ #include "../../simulation/hils/hils_port_manager.hpp" #include "uart_communication_with_obc.hpp" +namespace s2e::components { + /** * @class I2cController * @brief This class simulates the I2C Controller communication with the I2C Target. @@ -28,7 +30,7 @@ class I2cController { * @param [in] hils_port_manager: HILS port manager */ I2cController(const unsigned int hils_port_id, const unsigned int baud_rate, const unsigned int tx_buffer_size, const unsigned int rx_buffer_size, - HilsPortManager* hils_port_manager); + simulation::HilsPortManager* hils_port_manager); /** * @fn ~I2cController * @brief Destructor @@ -61,7 +63,9 @@ class I2cController { unsigned int rx_buffer_size_; //!< RX (Target to Controller) buffer size SimulationMode simulation_mode_ = SimulationMode::kError; //!< Simulation mode (SILS or HILS) - HilsPortManager* hils_port_manager_; //!< HILS port manager + simulation::HilsPortManager* hils_port_manager_; //!< HILS port manager }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_BASE_I2C_CONTROLLER_HPP_ diff --git a/src/components/base/i2c_target_communication_with_obc.cpp b/src/components/base/i2c_target_communication_with_obc.cpp index a4b7cc4fe..7aefe1704 100644 --- a/src/components/base/i2c_target_communication_with_obc.cpp +++ b/src/components/base/i2c_target_communication_with_obc.cpp @@ -6,6 +6,8 @@ #include +namespace s2e::components { + I2cTargetCommunicationWithObc::I2cTargetCommunicationWithObc(const unsigned int sils_port_id, const unsigned char i2c_address, OnBoardComputer* obc) : sils_port_id_(sils_port_id), i2c_address_(i2c_address), obc_(obc) { #ifdef USE_HILS @@ -18,7 +20,7 @@ I2cTargetCommunicationWithObc::I2cTargetCommunicationWithObc(const unsigned int } I2cTargetCommunicationWithObc::I2cTargetCommunicationWithObc(const unsigned int hils_port_id, const unsigned char i2c_address, - HilsPortManager* hils_port_manager) + simulation::HilsPortManager* hils_port_manager) : hils_port_id_(hils_port_id), i2c_address_(i2c_address), hils_port_manager_(hils_port_manager) { #ifdef USE_HILS simulation_mode_ = SimulationMode::kHils; @@ -34,7 +36,7 @@ I2cTargetCommunicationWithObc::I2cTargetCommunicationWithObc(const unsigned int I2cTargetCommunicationWithObc::I2cTargetCommunicationWithObc(const unsigned int sils_port_id, const unsigned int hils_port_id, const unsigned char i2c_address, OnBoardComputer* obc, - HilsPortManager* hils_port_manager) + simulation::HilsPortManager* hils_port_manager) : sils_port_id_(sils_port_id), hils_port_id_(hils_port_id), i2c_address_(i2c_address), obc_(obc), hils_port_manager_(hils_port_manager) { #ifdef USE_HILS simulation_mode_ = SimulationMode::kHils; @@ -163,3 +165,5 @@ int I2cTargetCommunicationWithObc::StoreTelemetry(const unsigned int stored_fram } return 0; } + +} // namespace s2e::components diff --git a/src/components/base/i2c_target_communication_with_obc.hpp b/src/components/base/i2c_target_communication_with_obc.hpp index 12ff9a4ac..5fa5bf279 100644 --- a/src/components/base/i2c_target_communication_with_obc.hpp +++ b/src/components/base/i2c_target_communication_with_obc.hpp @@ -10,6 +10,8 @@ #include "../real/cdh/on_board_computer.hpp" #include "uart_communication_with_obc.hpp" +namespace s2e::components { + /** * @class I2cTargetCommunicationWithObc * @brief Base class for I2C communication as target side with OBC flight software @@ -32,7 +34,7 @@ class I2cTargetCommunicationWithObc { * @param [in] i2c_address: I2C address for the target * @param [in] hils_port_manager: HILS port manager */ - I2cTargetCommunicationWithObc(const unsigned int hils_port_id, const unsigned char i2c_address, HilsPortManager* hils_port_manager); + I2cTargetCommunicationWithObc(const unsigned int hils_port_id, const unsigned char i2c_address, simulation::HilsPortManager* hils_port_manager); /** * @fn I2cTargetCommunicationWithObc * @brief Constructor for both SILS and HILS mode @@ -43,7 +45,7 @@ class I2cTargetCommunicationWithObc { * @param [in] hils_port_manager: HILS port manager */ I2cTargetCommunicationWithObc(const unsigned int sils_port_id, const unsigned int hils_port_id, const unsigned char i2c_address, - OnBoardComputer* obc, HilsPortManager* hils_port_manager); + OnBoardComputer* obc, simulation::HilsPortManager* hils_port_manager); /** * @fn I2cTargetCommunicationWithObc * @brief Prevent double freeing of memory when this class is copied @@ -117,8 +119,10 @@ class I2cTargetCommunicationWithObc { SimulationMode simulation_mode_ = SimulationMode::kError; //!< Simulation mode - OnBoardComputer* obc_; //!< Communication target OBC - HilsPortManager* hils_port_manager_; //!< HILS port manager + OnBoardComputer* obc_; //!< Communication target OBC + simulation::HilsPortManager* hils_port_manager_; //!< HILS port manager }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_BASE_I2C_TARGET_COMMUNICATION_WITH_OBC_HPP_ diff --git a/src/components/base/interface_gpio_component.hpp b/src/components/base/interface_gpio_component.hpp index 7ed129e7b..6a5d3bb75 100644 --- a/src/components/base/interface_gpio_component.hpp +++ b/src/components/base/interface_gpio_component.hpp @@ -6,6 +6,8 @@ #ifndef S2E_COMPONENTS_BASE_CLASSES_INTERFACE_GPIO_COMPONENT_HPP_ #define S2E_COMPONENTS_BASE_CLASSES_INTERFACE_GPIO_COMPONENT_HPP_ +namespace s2e::components { + /** * @class IGPIOCompo * @brief Interface class for components which have GPIO port @@ -16,7 +18,7 @@ class IGPIOCompo { * @fn ~IGPIOCompo * @brief Destructor */ - virtual ~IGPIOCompo(){}; + virtual ~IGPIOCompo() {}; /** * @fn GpioStateChanged @@ -27,4 +29,6 @@ class IGPIOCompo { virtual void GpioStateChanged(const int port_id, const bool is_positive_edge) = 0; }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_BASE_CLASSES_INTERFACE_GPIO_COMPONENT_HPP_ diff --git a/src/components/base/interface_tickable.hpp b/src/components/base/interface_tickable.hpp index 3d7171aeb..401c5d87b 100644 --- a/src/components/base/interface_tickable.hpp +++ b/src/components/base/interface_tickable.hpp @@ -6,6 +6,8 @@ #ifndef S2E_COMPONENTS_BASE_CLASSES_INTERFACE_TICKABLE_HPP_ #define S2E_COMPONENTS_BASE_CLASSES_INTERFACE_TICKABLE_HPP_ +namespace s2e::components { + /** * @class ITickable * @brief Interface class for time update of components @@ -40,4 +42,6 @@ class ITickable { bool needs_fast_update_ = false; //!< Whether or not high-frequency disturbances need to be calculated }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_BASE_CLASSES_INTERFACE_TICKABLE_HPP_ diff --git a/src/components/base/sensor.hpp b/src/components/base/sensor.hpp index f3ab2e22b..3204a1783 100644 --- a/src/components/base/sensor.hpp +++ b/src/components/base/sensor.hpp @@ -11,6 +11,8 @@ #include #include +namespace s2e::components { + /** * @class Sensor * @brief Base class for sensor emulation to add noises @@ -56,7 +58,7 @@ class Sensor { math::Vector range_to_const_c_; //!< Output range limit to be constant output value at the component frame math::Vector range_to_zero_c_; //!< Output range limit to be zero output value at the component frame randomization::NormalRand normal_random_noise_c_[N]; //!< Normal random - RandomWalk random_walk_noise_c_; //!< Random Walk + randomization::RandomWalk random_walk_noise_c_; //!< Random Walk /** * @fn Clip @@ -85,6 +87,8 @@ template Sensor ReadSensorInformation(const std::string file_name, const double step_width_s, const std::string component_name, const std::string unit = ""); +} // namespace s2e::components + #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 247093ce2..469a3e2b1 100644 --- a/src/components/base/sensor_template_functions.hpp +++ b/src/components/base/sensor_template_functions.hpp @@ -9,6 +9,8 @@ #include #include +namespace s2e::components { + template Sensor::Sensor(const math::Matrix& scale_factor, const math::Vector& range_to_const_c, const math::Vector& range_to_zero_c, const math::Vector& bias_noise_c, const math::Vector& normal_random_standard_deviation_c, @@ -20,7 +22,7 @@ Sensor::Sensor(const math::Matrix& scale_factor, const math::Vector& range_to_zero_c_(range_to_zero_c), random_walk_noise_c_(random_walk_step_width_s, random_walk_standard_deviation_c, random_walk_limit_c) { for (size_t i = 0; i < N; i++) { - normal_random_noise_c_[i].SetParameters(0.0, normal_random_standard_deviation_c[i], global_randomization.MakeSeed()); + normal_random_noise_c_[i].SetParameters(0.0, normal_random_standard_deviation_c[i], randomization::global_randomization.MakeSeed()); } RangeCheck(); } @@ -77,7 +79,7 @@ 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); + setting_file_reader::IniAccess ini_file(file_name); std::string section = "SENSOR_BASE_" + component_name; math::Vector scale_factor_vector; @@ -121,4 +123,6 @@ Sensor ReadSensorInformation(const std::string file_name, const double step_w return sensor_base; } +} // namespace s2e::components + #endif // S2E_COMPONENTS_BASE_SENSOR_TEMPLATE_FUNCTIONS_HPP_ diff --git a/src/components/base/uart_communication_with_obc.cpp b/src/components/base/uart_communication_with_obc.cpp index 47df421d4..74a7f92e6 100644 --- a/src/components/base/uart_communication_with_obc.cpp +++ b/src/components/base/uart_communication_with_obc.cpp @@ -7,6 +7,8 @@ #include +namespace s2e::components { + UartCommunicationWithObc::UartCommunicationWithObc(const unsigned int sils_port_id, OnBoardComputer* obc) : sils_port_id_(sils_port_id), obc_(obc) { #ifdef USE_HILS simulation_mode_ = SimulationMode::kError; @@ -33,7 +35,8 @@ UartCommunicationWithObc::UartCommunicationWithObc(const unsigned int sils_port_ InitializeObcComBase(); } -UartCommunicationWithObc::UartCommunicationWithObc(const unsigned int hils_port_id, const unsigned int baud_rate, HilsPortManager* hils_port_manager) +UartCommunicationWithObc::UartCommunicationWithObc(const unsigned int hils_port_id, const unsigned int baud_rate, + simulation::HilsPortManager* hils_port_manager) : hils_port_id_(hils_port_id), baud_rate_(baud_rate), hils_port_manager_(hils_port_manager) { #ifdef USE_HILS simulation_mode_ = SimulationMode::kHils; @@ -47,7 +50,7 @@ UartCommunicationWithObc::UartCommunicationWithObc(const unsigned int hils_port_ } UartCommunicationWithObc::UartCommunicationWithObc(const unsigned int hils_port_id, const unsigned int baud_rate, const unsigned int tx_buffer_size, - const unsigned int rx_buffer_size, HilsPortManager* hils_port_manager) + const unsigned int rx_buffer_size, simulation::HilsPortManager* hils_port_manager) : hils_port_id_(hils_port_id), baud_rate_(baud_rate), tx_buffer_size_(tx_buffer_size), @@ -65,7 +68,7 @@ UartCommunicationWithObc::UartCommunicationWithObc(const unsigned int hils_port_ } UartCommunicationWithObc::UartCommunicationWithObc(const int sils_port_id, OnBoardComputer* obc, const unsigned int hils_port_id, - const unsigned int baud_rate, HilsPortManager* hils_port_manager) + const unsigned int baud_rate, simulation::HilsPortManager* hils_port_manager) : sils_port_id_(sils_port_id), hils_port_id_(hils_port_id), baud_rate_(baud_rate), obc_(obc), hils_port_manager_(hils_port_manager) { #ifdef USE_HILS simulation_mode_ = SimulationMode::kHils; @@ -173,3 +176,5 @@ int UartCommunicationWithObc::SendTelemetry(const unsigned int offset) { return -1; } } + +} // namespace s2e::components diff --git a/src/components/base/uart_communication_with_obc.hpp b/src/components/base/uart_communication_with_obc.hpp index 0db74815b..ec887a685 100644 --- a/src/components/base/uart_communication_with_obc.hpp +++ b/src/components/base/uart_communication_with_obc.hpp @@ -10,6 +10,8 @@ #include "../real/cdh/on_board_computer.hpp" +namespace s2e::components { + /** * @enum SimulationMode * @brief Simulation mode (SILS or HILS) @@ -54,7 +56,7 @@ class UartCommunicationWithObc { * @param [in] baud_rate: Baud rate of HILS communication port * @param [in] hils_port_manager: HILS port manager */ - UartCommunicationWithObc(const unsigned int hils_port_id, const unsigned int baud_rate, HilsPortManager* hils_port_manager); + UartCommunicationWithObc(const unsigned int hils_port_id, const unsigned int baud_rate, simulation::HilsPortManager* hils_port_manager); /** * @fn UartCommunicationWithObc * @brief Constructor for HILS mode @@ -65,7 +67,7 @@ class UartCommunicationWithObc { * @param [in] hils_port_manager: HILS port manager */ UartCommunicationWithObc(const unsigned int hils_port_id, const unsigned int baud_rate, const unsigned int tx_buffer_size, - const unsigned int rx_buffer_size, HilsPortManager* hils_port_manager); + const unsigned int rx_buffer_size, simulation::HilsPortManager* hils_port_manager); /** * @fn UartCommunicationWithObc * @brief Constructor for both SILS and HILS mode @@ -77,7 +79,7 @@ class UartCommunicationWithObc { * @param [in] hils_port_manager: HILS port manager */ UartCommunicationWithObc(const int sils_port_id, OnBoardComputer* obc, const unsigned int hils_port_id, const unsigned int baud_rate, - HilsPortManager* hils_port_manager); + simulation::HilsPortManager* hils_port_manager); /** * @fn ~UartCommunicationWithObc * @brief Destructor @@ -107,8 +109,8 @@ class UartCommunicationWithObc { SimulationMode simulation_mode_ = SimulationMode::kError; //!< Simulation mode - OnBoardComputer* obc_; //!< Communication target OBC - HilsPortManager* hils_port_manager_; //!< HILS port manager + OnBoardComputer* obc_; //!< Communication target OBC + simulation::HilsPortManager* hils_port_manager_; //!< HILS port manager /** * @fn InitializeObcComBase @@ -129,4 +131,6 @@ class UartCommunicationWithObc { virtual int GenerateTelemetry() = 0; }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_BASE_UART_COMMUNICATION_WITH_OBC_HPP_ diff --git a/src/components/examples/example_change_structure.cpp b/src/components/examples/example_change_structure.cpp index 87e589700..e16ca7ac4 100644 --- a/src/components/examples/example_change_structure.cpp +++ b/src/components/examples/example_change_structure.cpp @@ -7,7 +7,9 @@ #include -ExampleChangeStructure::ExampleChangeStructure(ClockGenerator* clock_generator, Structure* structure) +namespace s2e::components { + +ExampleChangeStructure::ExampleChangeStructure(environment::ClockGenerator* clock_generator, spacecraft::Structure* structure) : Component(1, clock_generator), structure_(structure) {} ExampleChangeStructure::~ExampleChangeStructure() {} @@ -18,14 +20,14 @@ void ExampleChangeStructure::MainRoutine(const int time_count) { structure_->GetToSetKinematicsParameters().SetMass_kg(100.0); // Center of gravity - Vector<3> cg(0.0); + math::Vector<3> cg(0.0); cg[0] = 0.01; cg[1] = -0.01; cg[2] = 0.02; structure_->GetToSetKinematicsParameters().SetCenterOfGravityVector_b_m(cg); // RMM - Vector<3> rmm(0.0); + math::Vector<3> rmm(0.0); rmm[0] = 0.1; rmm[1] = -0.1; rmm[2] = 0.2; @@ -54,3 +56,5 @@ std::string ExampleChangeStructure::GetLogValue() const { return str_tmp; } + +} // namespace s2e::components diff --git a/src/components/examples/example_change_structure.hpp b/src/components/examples/example_change_structure.hpp index 31d656c92..7207ebc73 100644 --- a/src/components/examples/example_change_structure.hpp +++ b/src/components/examples/example_change_structure.hpp @@ -11,11 +11,13 @@ #include "../base/component.hpp" +namespace s2e::components { + /** * @class ExampleChangeStructure * @brief Class to show an example to change satellite structure information */ -class ExampleChangeStructure : public Component, public ILoggable { +class ExampleChangeStructure : public Component, public logger::ILoggable { public: /** * @fn ExampleChangeStructure @@ -23,7 +25,7 @@ class ExampleChangeStructure : public Component, public ILoggable { * @param [in] clock_generator: Clock generator * @param [in] structure: Structure information */ - ExampleChangeStructure(ClockGenerator* clock_generator, Structure* structure); + ExampleChangeStructure(environment::ClockGenerator* clock_generator, spacecraft::Structure* structure); /** * @fn ~ChangeStructure * @brief Destructor @@ -50,7 +52,9 @@ class ExampleChangeStructure : public Component, public ILoggable { virtual std::string GetLogValue() const override; protected: - Structure* structure_; //!< Structure information + spacecraft::Structure* structure_; //!< Structure information }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_EXAMPLES_EXAMPLE_CHANGE_STRUCTURE_HPP_ diff --git a/src/components/examples/example_i2c_controller_for_hils.cpp b/src/components/examples/example_i2c_controller_for_hils.cpp index 1924ec1c8..892268768 100644 --- a/src/components/examples/example_i2c_controller_for_hils.cpp +++ b/src/components/examples/example_i2c_controller_for_hils.cpp @@ -4,9 +4,12 @@ */ #include "example_i2c_controller_for_hils.hpp" -ExampleI2cControllerForHils::ExampleI2cControllerForHils(const int prescaler, ClockGenerator* clock_generator, const unsigned int hils_port_id, - const unsigned int baud_rate, const unsigned int tx_buffer_size, - const unsigned int rx_buffer_size, HilsPortManager* hils_port_manager) +namespace s2e::components { + +ExampleI2cControllerForHils::ExampleI2cControllerForHils(const int prescaler, environment::ClockGenerator* clock_generator, + const unsigned int hils_port_id, const unsigned int baud_rate, + const unsigned int tx_buffer_size, const unsigned int rx_buffer_size, + simulation::HilsPortManager* hils_port_manager) : Component(prescaler, clock_generator), I2cController(hils_port_id, baud_rate, tx_buffer_size, rx_buffer_size, hils_port_manager) {} ExampleI2cControllerForHils::~ExampleI2cControllerForHils() {} @@ -54,3 +57,5 @@ void ExampleI2cControllerForHils::Receive() { std::cout << std::endl; return; } + +} // namespace s2e::components diff --git a/src/components/examples/example_i2c_controller_for_hils.hpp b/src/components/examples/example_i2c_controller_for_hils.hpp index 51b948708..84254633f 100644 --- a/src/components/examples/example_i2c_controller_for_hils.hpp +++ b/src/components/examples/example_i2c_controller_for_hils.hpp @@ -11,6 +11,8 @@ #include "../base/component.hpp" #include "../base/i2c_controller.hpp" +namespace s2e::components { + /** * @class ExampleI2cControllerForHils * @brief Example of component emulation for I2C controller side communication in HILS environment @@ -31,8 +33,9 @@ class ExampleI2cControllerForHils : public Component, public I2cController { * @param [in] rx_buffer_size: RX (Target to Controller) buffer size * @param [in] hils_port_manager: HILS port manager */ - ExampleI2cControllerForHils(const int prescaler, ClockGenerator* clock_generator, const unsigned int hils_port_id, const unsigned int baud_rate, - const unsigned int tx_buffer_size, const unsigned int rx_buffer_size, HilsPortManager* hils_port_manager); + ExampleI2cControllerForHils(const int prescaler, environment::ClockGenerator* clock_generator, const unsigned int hils_port_id, + const unsigned int baud_rate, const unsigned int tx_buffer_size, const unsigned int rx_buffer_size, + simulation::HilsPortManager* hils_port_manager); /** * @fn ~ExampleI2cControllerForHils * @brief Destructor @@ -65,4 +68,6 @@ class ExampleI2cControllerForHils : public Component, public I2cController { static const uint8_t kCmdFooter_ = 0x50; //!< 'P' Footer for SC18IM700 }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_EXAMPLES_EXAMPLE_I2C_CONTROLLER_FOR_HILS_HPP_ diff --git a/src/components/examples/example_i2c_target_for_hils.cpp b/src/components/examples/example_i2c_target_for_hils.cpp index 3ec63ed3e..b278d7313 100644 --- a/src/components/examples/example_i2c_target_for_hils.cpp +++ b/src/components/examples/example_i2c_target_for_hils.cpp @@ -5,9 +5,11 @@ #include "example_i2c_target_for_hils.hpp" -ExampleI2cTargetForHils::ExampleI2cTargetForHils(const int prescaler, ClockGenerator* clock_generator, const int sils_port_id, +namespace s2e::components { + +ExampleI2cTargetForHils::ExampleI2cTargetForHils(const int prescaler, environment::ClockGenerator* clock_generator, const int sils_port_id, unsigned char i2c_address, OnBoardComputer* obc, const unsigned int hils_port_id, - HilsPortManager* hils_port_manager) + simulation::HilsPortManager* hils_port_manager) : Component(prescaler, clock_generator), I2cTargetCommunicationWithObc(sils_port_id, hils_port_id, i2c_address, obc, hils_port_manager) {} ExampleI2cTargetForHils::~ExampleI2cTargetForHils() {} @@ -39,3 +41,5 @@ void ExampleI2cTargetForHils::MainRoutine(const int time_count) { return; } + +} // namespace s2e::components diff --git a/src/components/examples/example_i2c_target_for_hils.hpp b/src/components/examples/example_i2c_target_for_hils.hpp index 9c486995f..0e6faf2bd 100644 --- a/src/components/examples/example_i2c_target_for_hils.hpp +++ b/src/components/examples/example_i2c_target_for_hils.hpp @@ -11,6 +11,8 @@ #include "../base/component.hpp" #include "../base/i2c_target_communication_with_obc.hpp" +namespace s2e::components { + /** * @class ExampleI2cTargetForHils * @brief Example of component emulation for I2C target side communication in HILS environment @@ -32,8 +34,8 @@ class ExampleI2cTargetForHils : public Component, public I2cTargetCommunicationW * @param [in] hils_port_id: ID of HILS communication port * @param [in] hils_port_manager: HILS port manager */ - ExampleI2cTargetForHils(const int prescaler, ClockGenerator* clock_generator, const int sils_port_id, unsigned char i2c_address, - OnBoardComputer* obc, const unsigned int hils_port_id, HilsPortManager* hils_port_manager); + ExampleI2cTargetForHils(const int prescaler, environment::ClockGenerator* clock_generator, const int sils_port_id, unsigned char i2c_address, + OnBoardComputer* obc, const unsigned int hils_port_id, simulation::HilsPortManager* hils_port_manager); /** * @fn ~ExampleI2cTargetForHils * @brief Destructor @@ -54,4 +56,6 @@ class ExampleI2cTargetForHils : public Component, public I2cTargetCommunicationW const unsigned char kNumAlphabet = 26; //!< Number of alphabet }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_EXAMPLES_EXAMPLE_I2C_TARGET_FOR_HILS_HPP_ diff --git a/src/components/examples/example_serial_communication_for_hils.cpp b/src/components/examples/example_serial_communication_for_hils.cpp index fe0b9b3d8..f39bc91fd 100644 --- a/src/components/examples/example_serial_communication_for_hils.cpp +++ b/src/components/examples/example_serial_communication_for_hils.cpp @@ -6,9 +6,12 @@ #include -ExampleSerialCommunicationForHils::ExampleSerialCommunicationForHils(ClockGenerator* clock_generator, const int sils_port_id, OnBoardComputer* obc, - const unsigned int hils_port_id, const unsigned int baud_rate, - HilsPortManager* hils_port_manager, const int mode_id) +namespace s2e::components { + +ExampleSerialCommunicationForHils::ExampleSerialCommunicationForHils(environment::ClockGenerator* clock_generator, const int sils_port_id, + OnBoardComputer* obc, const unsigned int hils_port_id, + const unsigned int baud_rate, simulation::HilsPortManager* hils_port_manager, + const int mode_id) : Component(300, clock_generator), UartCommunicationWithObc(sils_port_id, obc, hils_port_id, baud_rate, hils_port_manager), mode_id_(mode_id) {} ExampleSerialCommunicationForHils::~ExampleSerialCommunicationForHils() {} @@ -59,3 +62,5 @@ void ExampleSerialCommunicationForHils::MainRoutine(const int time_count) { ReceiveCommand(0, kMemorySize); SendTelemetry(0); } + +} // namespace s2e::components diff --git a/src/components/examples/example_serial_communication_for_hils.hpp b/src/components/examples/example_serial_communication_for_hils.hpp index 682d4afe0..077c9fc30 100644 --- a/src/components/examples/example_serial_communication_for_hils.hpp +++ b/src/components/examples/example_serial_communication_for_hils.hpp @@ -11,6 +11,8 @@ #include "../base/component.hpp" #include "../base/uart_communication_with_obc.hpp" +namespace s2e::components { + /** * @class ExampleSerialCommunicationForHils * @brief Example of component emulation for communication in HILS environment @@ -34,8 +36,9 @@ class ExampleSerialCommunicationForHils : public Component, public UartCommunica * @param [in] hils_port_manager: HILS port manager * @param [in] mode_id: Mode ID to select sender(0) or responder(1) */ - ExampleSerialCommunicationForHils(ClockGenerator* clock_generator, const int sils_port_id, OnBoardComputer* obc, const unsigned int hils_port_id, - const unsigned int baud_rate, HilsPortManager* hils_port_manager, const int mode_id); + ExampleSerialCommunicationForHils(environment::ClockGenerator* clock_generator, const int sils_port_id, OnBoardComputer* obc, + const unsigned int hils_port_id, const unsigned int baud_rate, simulation::HilsPortManager* hils_port_manager, + const int mode_id); /** * @fn ~ExampleSerialCommunicationForHils * @brief Destructor @@ -71,4 +74,6 @@ class ExampleSerialCommunicationForHils : public Component, public UartCommunica int GenerateTelemetry() override; }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_EXAMPLES_EXAMPLE_SERIAL_COMMUNICATION_FOR_HILS_HPP_ diff --git a/src/components/examples/example_serial_communication_with_obc.cpp b/src/components/examples/example_serial_communication_with_obc.cpp index 4042fbcb1..3017ea96d 100644 --- a/src/components/examples/example_serial_communication_with_obc.cpp +++ b/src/components/examples/example_serial_communication_with_obc.cpp @@ -7,11 +7,13 @@ #include -ExampleSerialCommunicationWithObc::ExampleSerialCommunicationWithObc(ClockGenerator* clock_generator, int port_id, OnBoardComputer* obc) +namespace s2e::components { + +ExampleSerialCommunicationWithObc::ExampleSerialCommunicationWithObc(environment::ClockGenerator* clock_generator, int port_id, OnBoardComputer* obc) : Component(1000, clock_generator), UartCommunicationWithObc(port_id, obc) { Initialize(); } -ExampleSerialCommunicationWithObc::ExampleSerialCommunicationWithObc(ClockGenerator* clock_generator, int port_id, int prescaler, +ExampleSerialCommunicationWithObc::ExampleSerialCommunicationWithObc(environment::ClockGenerator* clock_generator, int port_id, int prescaler, OnBoardComputer* obc) : Component(prescaler, clock_generator), UartCommunicationWithObc(port_id, obc) { Initialize(); @@ -54,3 +56,5 @@ void ExampleSerialCommunicationWithObc::MainRoutine(const int time_count) { void ExampleSerialCommunicationWithObc::GpioStateChanged(const int port_id, const bool is_positive_edge) { printf("interrupted. port id = %d, is positive edge = %d./n", port_id, is_positive_edge); } + +} // namespace s2e::components diff --git a/src/components/examples/example_serial_communication_with_obc.hpp b/src/components/examples/example_serial_communication_with_obc.hpp index a83eb4bcf..d202fbc15 100644 --- a/src/components/examples/example_serial_communication_with_obc.hpp +++ b/src/components/examples/example_serial_communication_with_obc.hpp @@ -12,6 +12,8 @@ #include "../base/interface_gpio_component.hpp" #include "../base/uart_communication_with_obc.hpp" +namespace s2e::components { + /** * @class ExampleSerialCommunicationWithObc * @brief Example of component emulation with communication between OBC flight software @@ -35,7 +37,7 @@ class ExampleSerialCommunicationWithObc : public Component, public UartCommunica * @param [in] port_id: Port ID for communication line b/w OnBoardComputer * @param [in] obc: The communication target OBC */ - ExampleSerialCommunicationWithObc(ClockGenerator* clock_generator, int port_id, OnBoardComputer* obc); + ExampleSerialCommunicationWithObc(environment::ClockGenerator* clock_generator, int port_id, OnBoardComputer* obc); /** * @fn ExampleSerialCommunicationWithObc * @brief Constructor @@ -44,7 +46,7 @@ class ExampleSerialCommunicationWithObc : public Component, public UartCommunica * @param [in] prescaler: Frequency scale factor for update * @param [in] obc: The communication target OBC */ - ExampleSerialCommunicationWithObc(ClockGenerator* clock_generator, int port_id, int prescaler, OnBoardComputer* obc); + ExampleSerialCommunicationWithObc(environment::ClockGenerator* clock_generator, int port_id, int prescaler, OnBoardComputer* obc); /** * @fn ~SerialCommunicationWithObc * @brief Destructor @@ -89,4 +91,6 @@ class ExampleSerialCommunicationWithObc : public Component, public UartCommunica int Initialize(); }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_EXAMPLES_EXAMPLE_SERIAL_COMMUNICATION_WITH_OBC_HPP_P_ diff --git a/src/components/ideal/angular_velocity_observer.cpp b/src/components/ideal/angular_velocity_observer.cpp index 6ff33272f..3b72b890b 100644 --- a/src/components/ideal/angular_velocity_observer.cpp +++ b/src/components/ideal/angular_velocity_observer.cpp @@ -7,7 +7,10 @@ #include -AngularVelocityObserver::AngularVelocityObserver(const int prescaler, ClockGenerator* clock_generator, Sensor& sensor_base, const Attitude& attitude) +namespace s2e::components { + +AngularVelocityObserver::AngularVelocityObserver(const int prescaler, environment::ClockGenerator* clock_generator, Sensor& sensor_base, + const dynamics::attitude::Attitude& attitude) : Component(prescaler, clock_generator), Sensor(sensor_base), attitude_(attitude) {} void AngularVelocityObserver::MainRoutine(const int time_count) { @@ -19,7 +22,7 @@ std::string AngularVelocityObserver::GetLogHeader() const { std::string str_tmp = ""; std::string sensor_name = "angular_velocity_observer_"; - str_tmp += WriteVector(sensor_name + "measured_value", "b", "rad/s", 3); + str_tmp += logger::WriteVector(sensor_name + "measured_value", "b", "rad/s", 3); return str_tmp; } @@ -27,14 +30,14 @@ std::string AngularVelocityObserver::GetLogHeader() const { std::string AngularVelocityObserver::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteVector(angular_velocity_b_rad_s_); + str_tmp += logger::WriteVector(angular_velocity_b_rad_s_); return str_tmp; } -AngularVelocityObserver InitializeAngularVelocityObserver(ClockGenerator* clock_generator, const std::string file_name, double component_step_time_s, - const Attitude& attitude) { - IniAccess ini_file(file_name); +AngularVelocityObserver InitializeAngularVelocityObserver(environment::ClockGenerator* clock_generator, const std::string file_name, + double component_step_time_s, const dynamics::attitude::Attitude& attitude) { + setting_file_reader::IniAccess ini_file(file_name); int prescaler = ini_file.ReadInt("COMPONENT_BASE", "prescaler"); if (prescaler <= 1) prescaler = 1; @@ -46,3 +49,5 @@ AngularVelocityObserver InitializeAngularVelocityObserver(ClockGenerator* clock_ return observer; } + +} // namespace s2e::components diff --git a/src/components/ideal/angular_velocity_observer.hpp b/src/components/ideal/angular_velocity_observer.hpp index 3b162a36a..5f8f10e22 100644 --- a/src/components/ideal/angular_velocity_observer.hpp +++ b/src/components/ideal/angular_velocity_observer.hpp @@ -12,11 +12,13 @@ #include "../base/component.hpp" #include "../base/sensor.hpp" +namespace s2e::components { + /* * @class AngularVelocityObserver * @brief Ideal component which can observe angular velocity */ -class AngularVelocityObserver : public Component, public Sensor<3>, public ILoggable { +class AngularVelocityObserver : public Component, public Sensor<3>, public logger::ILoggable { public: /** * @fn AngularVelocityObserver @@ -26,7 +28,8 @@ class AngularVelocityObserver : public Component, public Sensor<3>, public ILogg * @param [in] sensor_base: Sensor base information * @param [in] dynamics: Dynamics information */ - AngularVelocityObserver(const int prescaler, ClockGenerator* clock_generator, Sensor& sensor_base, const Attitude& attitude); + AngularVelocityObserver(const int prescaler, environment::ClockGenerator* clock_generator, Sensor& sensor_base, + const dynamics::attitude::Attitude& attitude); /** * @fn ~AngularVelocityObserver * @brief Destructor @@ -40,15 +43,15 @@ class AngularVelocityObserver : public Component, public Sensor<3>, public ILogg */ void MainRoutine(const int time_count) override; - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const override; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const override; @@ -61,7 +64,7 @@ class AngularVelocityObserver : public Component, public Sensor<3>, public ILogg protected: math::Vector<3> angular_velocity_b_rad_s_{0.0}; //!< Observed angular velocity [rad/s] - const Attitude& attitude_; //!< Dynamics information + const dynamics::attitude::Attitude& attitude_; //!< Dynamics information }; /** @@ -72,7 +75,9 @@ class AngularVelocityObserver : public Component, public Sensor<3>, public ILogg * @param [in] component_step_time_s: Component step time [sec] * @param [in] dynamics: Dynamics information */ -AngularVelocityObserver InitializeAngularVelocityObserver(ClockGenerator* clock_generator, const std::string file_name, double component_step_time_s, - const Attitude& attitude); +AngularVelocityObserver InitializeAngularVelocityObserver(environment::ClockGenerator* clock_generator, const std::string file_name, + double component_step_time_s, const dynamics::attitude::Attitude& attitude); + +} // namespace s2e::components #endif // S2E_COMPONENTS_IDEAL_ANGULAR_VELOCITY_OBSERVER_HPP_ diff --git a/src/components/ideal/attitude_observer.cpp b/src/components/ideal/attitude_observer.cpp index 312a1930c..a77c1b429 100644 --- a/src/components/ideal/attitude_observer.cpp +++ b/src/components/ideal/attitude_observer.cpp @@ -8,8 +8,10 @@ #include #include -AttitudeObserver::AttitudeObserver(const int prescaler, ClockGenerator* clock_generator, const double standard_deviation_rad, - const Attitude& attitude) +namespace s2e::components { + +AttitudeObserver::AttitudeObserver(const int prescaler, environment::ClockGenerator* clock_generator, const double standard_deviation_rad, + const dynamics::attitude::Attitude& attitude) : Component(prescaler, clock_generator), angle_noise_(0.0, standard_deviation_rad), attitude_(attitude) { direction_noise_.SetParameters(0.0, 1.0); } @@ -34,7 +36,7 @@ std::string AttitudeObserver::GetLogHeader() const { std::string str_tmp = ""; std::string head = "attitude_observer_"; - str_tmp += WriteQuaternion(head + "quaternion", "i2b"); + str_tmp += logger::WriteQuaternion(head + "quaternion", "i2b"); return str_tmp; } @@ -42,14 +44,15 @@ std::string AttitudeObserver::GetLogHeader() const { std::string AttitudeObserver::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteQuaternion(observed_quaternion_i2b_); + str_tmp += logger::WriteQuaternion(observed_quaternion_i2b_); return str_tmp; } -AttitudeObserver InitializeAttitudeObserver(ClockGenerator* clock_generator, const std::string file_name, const Attitude& attitude) { +AttitudeObserver InitializeAttitudeObserver(environment::ClockGenerator* clock_generator, const std::string file_name, + const dynamics::attitude::Attitude& attitude) { // General - IniAccess ini_file(file_name); + setting_file_reader::IniAccess ini_file(file_name); // CompoBase int prescaler = ini_file.ReadInt("COMPONENT_BASE", "prescaler"); @@ -62,3 +65,5 @@ AttitudeObserver InitializeAttitudeObserver(ClockGenerator* clock_generator, con return attitude_observer; } + +} // namespace s2e::components diff --git a/src/components/ideal/attitude_observer.hpp b/src/components/ideal/attitude_observer.hpp index 3244dce32..410913884 100644 --- a/src/components/ideal/attitude_observer.hpp +++ b/src/components/ideal/attitude_observer.hpp @@ -13,20 +13,23 @@ #include "../base/component.hpp" +namespace s2e::components { + /* * @class AttitudeObserver * @brief Ideal component which can observe attitude */ -class AttitudeObserver : public Component, public ILoggable { +class AttitudeObserver : public Component, public logger::ILoggable { public: /** * @fn AttitudeObserver * @brief Constructor without power port * @param [in] prescaler: Frequency scale factor for update * @param [in] clock_generator: Clock generator - * @param [in] attitude: Attitude information + * @param [in] attitude: dynamics::attitude::Attitude information */ - AttitudeObserver(const int prescaler, ClockGenerator* clock_generator, const double standard_deviation_rad, const Attitude& attitude); + AttitudeObserver(const int prescaler, environment::ClockGenerator* clock_generator, const double standard_deviation_rad, + const dynamics::attitude::Attitude& attitude); /** * @fn ~AttitudeObserver @@ -41,15 +44,15 @@ class AttitudeObserver : public Component, public ILoggable { */ void MainRoutine(const int time_count) override; - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const override; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const override; @@ -65,7 +68,7 @@ class AttitudeObserver : public Component, public ILoggable { randomization::NormalRand angle_noise_; //!< Normal random for magnitude noise randomization::NormalRand direction_noise_; //!< Normal random for direction noise - const Attitude& attitude_; //!< Attitude information + const dynamics::attitude::Attitude& attitude_; //!< dynamics::attitude::Attitude information }; /** @@ -73,8 +76,11 @@ class AttitudeObserver : public Component, public ILoggable { * @brief Initialize functions for AttitudeObserver * @param [in] clock_generator: Clock generator * @param [in] file_name: Path to the initialize file - * @param [in] attitude: Attitude information + * @param [in] attitude: dynamics::attitude::Attitude information */ -AttitudeObserver InitializeAttitudeObserver(ClockGenerator* clock_generator, const std::string file_name, const Attitude& attitude); +AttitudeObserver InitializeAttitudeObserver(environment::ClockGenerator* clock_generator, const std::string file_name, + const dynamics::attitude::Attitude& attitude); + +} // namespace s2e::components #endif // S2E_COMPONENTS_IDEAL_ATTITUDE_OBSERVER_HPP_ diff --git a/src/components/ideal/force_generator.cpp b/src/components/ideal/force_generator.cpp index 833703477..2104ad4b9 100644 --- a/src/components/ideal/force_generator.cpp +++ b/src/components/ideal/force_generator.cpp @@ -8,9 +8,11 @@ #include #include +namespace s2e::components { + // Constructor -ForceGenerator::ForceGenerator(const int prescaler, ClockGenerator* clock_generator, const double magnitude_error_standard_deviation_N, - const double direction_error_standard_deviation_rad, const Dynamics* dynamics) +ForceGenerator::ForceGenerator(const int prescaler, environment::ClockGenerator* clock_generator, const double magnitude_error_standard_deviation_N, + const double direction_error_standard_deviation_rad, const dynamics::Dynamics* dynamics) : Component(prescaler, clock_generator), magnitude_noise_(0.0, magnitude_error_standard_deviation_N), direction_error_standard_deviation_rad_(direction_error_standard_deviation_rad), @@ -66,10 +68,10 @@ std::string ForceGenerator::GetLogHeader() const { std::string str_tmp = ""; std::string head = "ideal_force_generator_"; - str_tmp += WriteVector(head + "ordered_force", "b", "N", 3); - str_tmp += WriteVector(head + "generated_force", "b", "N", 3); - str_tmp += WriteVector(head + "generated_force", "i", "N", 3); - str_tmp += WriteVector(head + "generated_force", "rtn", "N", 3); + str_tmp += logger::WriteVector(head + "ordered_force", "b", "N", 3); + str_tmp += logger::WriteVector(head + "generated_force", "b", "N", 3); + str_tmp += logger::WriteVector(head + "generated_force", "i", "N", 3); + str_tmp += logger::WriteVector(head + "generated_force", "rtn", "N", 3); return str_tmp; } @@ -77,10 +79,10 @@ std::string ForceGenerator::GetLogHeader() const { std::string ForceGenerator::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteVector(ordered_force_b_N_); - str_tmp += WriteVector(generated_force_b_N_); - str_tmp += WriteVector(generated_force_i_N_); - str_tmp += WriteVector(generated_force_rtn_N_); + str_tmp += logger::WriteVector(ordered_force_b_N_); + str_tmp += logger::WriteVector(generated_force_b_N_); + str_tmp += logger::WriteVector(generated_force_i_N_); + str_tmp += logger::WriteVector(generated_force_rtn_N_); return str_tmp; } @@ -105,9 +107,10 @@ math::Quaternion ForceGenerator::GenerateDirectionNoiseQuaternion(math::Vector<3 return error_quaternion; } -ForceGenerator InitializeForceGenerator(ClockGenerator* clock_generator, const std::string file_name, const Dynamics* dynamics) { +ForceGenerator InitializeForceGenerator(environment::ClockGenerator* clock_generator, const std::string file_name, + const dynamics::Dynamics* dynamics) { // General - IniAccess ini_file(file_name); + setting_file_reader::IniAccess ini_file(file_name); // CompoBase int prescaler = ini_file.ReadInt("COMPONENT_BASE", "prescaler"); @@ -122,3 +125,5 @@ ForceGenerator InitializeForceGenerator(ClockGenerator* clock_generator, const s return force_generator; } + +} // namespace s2e::components diff --git a/src/components/ideal/force_generator.hpp b/src/components/ideal/force_generator.hpp index d7cb07f49..66fdcadea 100644 --- a/src/components/ideal/force_generator.hpp +++ b/src/components/ideal/force_generator.hpp @@ -12,11 +12,13 @@ #include #include +namespace s2e::components { + /* * @class ForceGenerator * @brief Ideal component which can generate for control algorithm test */ -class ForceGenerator : public Component, public ILoggable { +class ForceGenerator : public Component, public logger::ILoggable { public: /** * @fn ForceGenerator @@ -27,8 +29,8 @@ class ForceGenerator : public Component, public ILoggable { * @param [in] direction_error_standard_deviation_rad: Standard deviation of direction error [rad] * @param [in] dynamics: Dynamics information */ - ForceGenerator(const int prescaler, ClockGenerator* clock_generator, const double magnitude_error_standard_deviation_N, - const double direction_error_standard_deviation_rad, const Dynamics* dynamics); + ForceGenerator(const int prescaler, environment::ClockGenerator* clock_generator, const double magnitude_error_standard_deviation_N, + const double direction_error_standard_deviation_rad, const dynamics::Dynamics* dynamics); /** * @fn ~ForceGenerator * @brief Destructor @@ -47,15 +49,15 @@ class ForceGenerator : public Component, public ILoggable { */ void PowerOffRoutine(); - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; @@ -64,17 +66,17 @@ class ForceGenerator : public Component, public ILoggable { * @fn GetGeneratedForce_b_N * @brief Return generated force in the body fixed frame [N] */ - inline const Vector<3> GetGeneratedForce_b_N() const { return generated_force_b_N_; }; + inline const math::Vector<3> GetGeneratedForce_b_N() const { return generated_force_b_N_; }; /** * @fn GetGeneratedForce_i_N * @brief Return generated force in the inertial frame [N] */ - inline const Vector<3> GetGeneratedForce_i_N() const { return generated_force_i_N_; }; + inline const math::Vector<3> GetGeneratedForce_i_N() const { return generated_force_i_N_; }; /** * @fn GetGeneratedForce_rtn_N * @brief Return generated force in the RTN frame [N] */ - inline const Vector<3> GetGeneratedForce_rtn_N() const { return generated_force_rtn_N_; }; + inline const math::Vector<3> GetGeneratedForce_rtn_N() const { return generated_force_rtn_N_; }; // Setter /** @@ -112,7 +114,7 @@ class ForceGenerator : public Component, public ILoggable { */ math::Quaternion GenerateDirectionNoiseQuaternion(math::Vector<3> true_direction, const double error_standard_deviation_rad); - const Dynamics* dynamics_; //!< Spacecraft dynamics information + const dynamics::Dynamics* dynamics_; //!< Spacecraft dynamics information }; /** @@ -122,6 +124,9 @@ class ForceGenerator : public Component, public ILoggable { * @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); +ForceGenerator InitializeForceGenerator(environment::ClockGenerator* clock_generator, const std::string file_name, + const dynamics::Dynamics* dynamics); + +} // namespace s2e::components #endif // S2E_COMPONENTS_IDEAL_FORCE_GENERATOR_HPP_ diff --git a/src/components/ideal/orbit_observer.cpp b/src/components/ideal/orbit_observer.cpp index e1b91d0c7..ce68afc76 100644 --- a/src/components/ideal/orbit_observer.cpp +++ b/src/components/ideal/orbit_observer.cpp @@ -8,11 +8,13 @@ #include #include -OrbitObserver::OrbitObserver(const int prescaler, ClockGenerator* clock_generator, const NoiseFrame noise_frame, - const math::Vector<6> error_standard_deviation, const Orbit& orbit) +namespace s2e::components { + +OrbitObserver::OrbitObserver(const int prescaler, environment::ClockGenerator* clock_generator, const NoiseFrame noise_frame, + const math::Vector<6> error_standard_deviation, const dynamics::orbit::Orbit& orbit) : Component(prescaler, clock_generator), noise_frame_(noise_frame), orbit_(orbit) { for (size_t i = 0; i < 6; i++) { - normal_random_noise_[i].SetParameters(0.0, error_standard_deviation[i], global_randomization.MakeSeed()); + normal_random_noise_[i].SetParameters(0.0, error_standard_deviation[i], randomization::global_randomization.MakeSeed()); } } @@ -56,8 +58,8 @@ std::string OrbitObserver::GetLogHeader() const { std::string str_tmp = ""; std::string head = "orbit_observer_"; - str_tmp += WriteVector(head + "position", "i", "m", 3); - str_tmp += WriteVector(head + "velocity", "i", "m/s", 3); + str_tmp += logger::WriteVector(head + "position", "i", "m", 3); + str_tmp += logger::WriteVector(head + "velocity", "i", "m/s", 3); return str_tmp; } @@ -65,8 +67,8 @@ std::string OrbitObserver::GetLogHeader() const { std::string OrbitObserver::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteVector(observed_position_i_m_, 16); - str_tmp += WriteVector(observed_velocity_i_m_s_, 16); + str_tmp += logger::WriteVector(observed_position_i_m_, 16); + str_tmp += logger::WriteVector(observed_velocity_i_m_s_, 16); return str_tmp; } @@ -83,9 +85,10 @@ NoiseFrame SetNoiseFrame(const std::string noise_frame) { } } -OrbitObserver InitializeOrbitObserver(ClockGenerator* clock_generator, const std::string file_name, const Orbit& orbit) { +OrbitObserver InitializeOrbitObserver(environment::ClockGenerator* clock_generator, const std::string file_name, + const dynamics::orbit::Orbit& orbit) { // General - IniAccess ini_file(file_name); + setting_file_reader::IniAccess ini_file(file_name); // CompoBase int prescaler = ini_file.ReadInt("COMPONENT_BASE", "prescaler"); @@ -100,3 +103,5 @@ OrbitObserver InitializeOrbitObserver(ClockGenerator* clock_generator, const std return orbit_observer; } + +} // namespace s2e::components diff --git a/src/components/ideal/orbit_observer.hpp b/src/components/ideal/orbit_observer.hpp index 09437c079..17997925b 100644 --- a/src/components/ideal/orbit_observer.hpp +++ b/src/components/ideal/orbit_observer.hpp @@ -13,6 +13,8 @@ #include "../base/component.hpp" +namespace s2e::components { + /** * @enum NoiseFrame * @brief Noise definition frame @@ -26,7 +28,7 @@ enum class NoiseFrame { * @class OrbitObserver * @brief Ideal component which can observe orbit */ -class OrbitObserver : public Component, public ILoggable { +class OrbitObserver : public Component, public logger::ILoggable { public: /** * @fn OrbitObserver @@ -37,8 +39,8 @@ class OrbitObserver : public Component, public ILoggable { * @param [in] error_standard_deviation: Position and Velocity standard deviation noise [m, m/s] * @param [in] orbit: Orbit information */ - OrbitObserver(const int prescaler, ClockGenerator* clock_generator, const NoiseFrame noise_frame, const math::Vector<6> error_standard_deviation, - const Orbit& orbit); + OrbitObserver(const int prescaler, environment::ClockGenerator* clock_generator, const NoiseFrame noise_frame, + const math::Vector<6> error_standard_deviation, const dynamics::orbit::Orbit& orbit); /** * @fn ~AttitudeObserver @@ -53,15 +55,15 @@ class OrbitObserver : public Component, public ILoggable { */ void MainRoutine(const int time_count) override; - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const override; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const override; @@ -81,11 +83,11 @@ class OrbitObserver : public Component, public ILoggable { math::Vector<3> observed_position_i_m_{0.0}; //!< Observed position @ inertial frame [m] math::Vector<3> observed_velocity_i_m_s_{0.0}; //!< Observed velocity @ inertial frame [m/s] - NoiseFrame noise_frame_; //!< Noise definition frame + NoiseFrame noise_frame_; //!< Noise definition frame randomization::NormalRand normal_random_noise_[6]; //!< Position and Velocity noise [m, m/s] // Observed variables - const Orbit& orbit_; //!< Orbit information + const dynamics::orbit::Orbit& orbit_; //!< Orbit information }; /** @@ -103,6 +105,8 @@ NoiseFrame SetNoiseFrame(const std::string noise_frame); * @param [in] file_name: Path to the initialize file * @param [in] orbit: Orbit information */ -OrbitObserver InitializeOrbitObserver(ClockGenerator* clock_generator, const std::string file_name, const Orbit& orbit); +OrbitObserver InitializeOrbitObserver(environment::ClockGenerator* clock_generator, const std::string file_name, const dynamics::orbit::Orbit& orbit); + +} // namespace s2e::components #endif // S2E_COMPONENTS_IDEAL_ORBIT_OBSERVER_HPP_ diff --git a/src/components/ideal/torque_generator.cpp b/src/components/ideal/torque_generator.cpp index d090f0d34..c64478b6b 100644 --- a/src/components/ideal/torque_generator.cpp +++ b/src/components/ideal/torque_generator.cpp @@ -8,9 +8,12 @@ #include #include +namespace s2e::components { + // Constructor -TorqueGenerator::TorqueGenerator(const int prescaler, ClockGenerator* clock_generator, const double magnitude_error_standard_deviation_Nm, - const double direction_error_standard_deviation_rad, const Dynamics* dynamics) +TorqueGenerator::TorqueGenerator(const int prescaler, environment::ClockGenerator* clock_generator, + const double magnitude_error_standard_deviation_Nm, const double direction_error_standard_deviation_rad, + const dynamics::Dynamics* dynamics) : Component(prescaler, clock_generator), magnitude_noise_(0.0, magnitude_error_standard_deviation_Nm), direction_error_standard_deviation_rad_(direction_error_standard_deviation_rad), @@ -43,8 +46,8 @@ std::string TorqueGenerator::GetLogHeader() const { std::string str_tmp = ""; std::string head = "ideal_torque_generator_"; - str_tmp += WriteVector(head + "ordered_torque", "b", "Nm", 3); - str_tmp += WriteVector(head + "generated_torque", "b", "Nm", 3); + str_tmp += logger::WriteVector(head + "ordered_torque", "b", "Nm", 3); + str_tmp += logger::WriteVector(head + "generated_torque", "b", "Nm", 3); return str_tmp; } @@ -52,8 +55,8 @@ std::string TorqueGenerator::GetLogHeader() const { std::string TorqueGenerator::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteVector(ordered_torque_b_Nm_); - str_tmp += WriteVector(generated_torque_b_Nm_); + str_tmp += logger::WriteVector(ordered_torque_b_Nm_); + str_tmp += logger::WriteVector(generated_torque_b_Nm_); return str_tmp; } @@ -78,9 +81,10 @@ math::Quaternion TorqueGenerator::GenerateDirectionNoiseQuaternion(math::Vector< return error_quaternion; } -TorqueGenerator InitializeTorqueGenerator(ClockGenerator* clock_generator, const std::string file_name, const Dynamics* dynamics) { +TorqueGenerator InitializeTorqueGenerator(environment::ClockGenerator* clock_generator, const std::string file_name, + const dynamics::Dynamics* dynamics) { // General - IniAccess ini_file(file_name); + setting_file_reader::IniAccess ini_file(file_name); // CompoBase int prescaler = ini_file.ReadInt("COMPONENT_BASE", "prescaler"); @@ -96,3 +100,5 @@ TorqueGenerator InitializeTorqueGenerator(ClockGenerator* clock_generator, const return torque_generator; } + +} // namespace s2e::components diff --git a/src/components/ideal/torque_generator.hpp b/src/components/ideal/torque_generator.hpp index 6ddaf1c5d..726f7aed8 100644 --- a/src/components/ideal/torque_generator.hpp +++ b/src/components/ideal/torque_generator.hpp @@ -12,11 +12,13 @@ #include #include +namespace s2e::components { + /* * @class TorqueGenerator * @brief Ideal component which can generate for control algorithm test */ -class TorqueGenerator : public Component, public ILoggable { +class TorqueGenerator : public Component, public logger::ILoggable { public: /** * @fn TorqueGenerator @@ -27,8 +29,8 @@ class TorqueGenerator : public Component, public ILoggable { * @param [in] direction_error_standard_deviation_rad: Standard deviation of direction error [rad] * @param [in] dynamics: Dynamics information */ - TorqueGenerator(const int prescaler, ClockGenerator* clock_generator, const double magnitude_error_standard_deviation_Nm, - const double direction_error_standard_deviation_rad, const Dynamics* dynamics); + TorqueGenerator(const int prescaler, environment::ClockGenerator* clock_generator, const double magnitude_error_standard_deviation_Nm, + const double direction_error_standard_deviation_rad, const dynamics::Dynamics* dynamics); /** * @fn ~TorqueGenerator * @brief Destructor @@ -47,15 +49,15 @@ class TorqueGenerator : public Component, public ILoggable { */ void PowerOffRoutine(); - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; @@ -64,7 +66,7 @@ class TorqueGenerator : public Component, public ILoggable { * @fn GetGeneratedTorque_b_Nm * @brief Return generated torque in the body fixed frame [Nm] */ - inline const Vector<3> GetGeneratedTorque_b_Nm() const { return generated_torque_b_Nm_; }; + inline const math::Vector<3> GetGeneratedTorque_b_Nm() const { return generated_torque_b_Nm_; }; // Setter /** @@ -90,7 +92,7 @@ class TorqueGenerator : public Component, public ILoggable { */ math::Quaternion GenerateDirectionNoiseQuaternion(math::Vector<3> true_direction, const double error_standard_deviation_rad); - const Dynamics* dynamics_; //!< Spacecraft dynamics information + const dynamics::Dynamics* dynamics_; //!< Spacecraft dynamics information }; /** @@ -100,6 +102,9 @@ class TorqueGenerator : public Component, public ILoggable { * @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); +TorqueGenerator InitializeTorqueGenerator(environment::ClockGenerator* clock_generator, const std::string file_name, + const dynamics::Dynamics* dynamics); + +} // namespace s2e::components #endif // S2E_COMPONENTS_IDEAL_TORQUE_GENERATOR_HPP_ diff --git a/src/components/ports/gpio_port.cpp b/src/components/ports/gpio_port.cpp index 4a155cc57..bf91c2f8c 100644 --- a/src/components/ports/gpio_port.cpp +++ b/src/components/ports/gpio_port.cpp @@ -5,6 +5,8 @@ #include "gpio_port.hpp" +namespace s2e::components { + GpioPort::GpioPort(const unsigned int port_id, IGPIOCompo* component) : kPortId(port_id) { high_low_state_ = GPIO_LOW; component_ = component; @@ -24,3 +26,5 @@ int GpioPort::DigitalWrite(const bool is_high) { } bool GpioPort::DigitalRead() { return high_low_state_; } + +} // namespace s2e::components diff --git a/src/components/ports/gpio_port.hpp b/src/components/ports/gpio_port.hpp index b1c38bb2a..3feb8af86 100644 --- a/src/components/ports/gpio_port.hpp +++ b/src/components/ports/gpio_port.hpp @@ -8,6 +8,8 @@ #include +namespace s2e::components { + #define GPIO_HIGH true #define GPIO_LOW false @@ -51,4 +53,6 @@ class GpioPort { bool high_low_state_; //!< GPIO High/Low state }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_PORTS_GPIO_PORT_HPP_ diff --git a/src/components/ports/hils_i2c_target_port.cpp b/src/components/ports/hils_i2c_target_port.cpp index c4797e31e..6d4cd71cb 100644 --- a/src/components/ports/hils_i2c_target_port.cpp +++ b/src/components/ports/hils_i2c_target_port.cpp @@ -5,6 +5,8 @@ #include "hils_i2c_target_port.hpp" +namespace s2e::components { + // #define HILS_I2C_TARGET_PORT_SHOW_DEBUG_DATA //!< Remove comment when you want to show the debug message // FIXME: The magic number. This is depending on the converter. @@ -105,3 +107,5 @@ int HilsI2cTargetPort::Send(const unsigned char data_length) // to I2C-USB Targ } int HilsI2cTargetPort::GetStoredFrameCounter() { return stored_frame_counter_; } + +} // namespace s2e::components diff --git a/src/components/ports/hils_i2c_target_port.hpp b/src/components/ports/hils_i2c_target_port.hpp index 16bee3cd4..54cb76531 100644 --- a/src/components/ports/hils_i2c_target_port.hpp +++ b/src/components/ports/hils_i2c_target_port.hpp @@ -10,6 +10,8 @@ #include "hils_uart_port.hpp" +namespace s2e::components { + const unsigned int kDefaultCommandSize = 0xff; //!< Default command size const unsigned int kDefaultTxSize = 0xff; //!< Default TX size @@ -107,4 +109,6 @@ class HilsI2cTargetPort : public HilsUartPort { std::map command_buffer_; }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_PORTS_HILS_I2C_TARGET_PORT_HPP_ diff --git a/src/components/ports/hils_uart_port.cpp b/src/components/ports/hils_uart_port.cpp index be3d1e16c..bc811269b 100644 --- a/src/components/ports/hils_uart_port.cpp +++ b/src/components/ports/hils_uart_port.cpp @@ -8,6 +8,8 @@ #include "hils_uart_port.hpp" +namespace s2e::components { + // # define HILS_UART_PORT_SHOW_DEBUG_DATA HilsUartPort::HilsUartPort(const unsigned int port_id, const unsigned int baud_rate, const unsigned int tx_buffer_size, @@ -186,3 +188,5 @@ int HilsUartPort::DiscardOutBuffer() { } return 0; } + +} // namespace s2e::components diff --git a/src/components/ports/hils_uart_port.hpp b/src/components/ports/hils_uart_port.hpp index 1be6a9b8f..be2fc9bbd 100644 --- a/src/components/ports/hils_uart_port.hpp +++ b/src/components/ports/hils_uart_port.hpp @@ -14,6 +14,8 @@ #include +namespace s2e::components { + typedef cli::array bytearray; //!< System::Byte: an 8-bit unsigned integer /** @@ -111,4 +113,6 @@ class HilsUartPort { int DiscardOutBuffer(); }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_PORTS_HILS_UART_PORT_HPP_ diff --git a/src/components/ports/i2c_port.cpp b/src/components/ports/i2c_port.cpp index 715fd9538..3e4578a28 100644 --- a/src/components/ports/i2c_port.cpp +++ b/src/components/ports/i2c_port.cpp @@ -7,6 +7,8 @@ #include +namespace s2e::components { + I2cPort::I2cPort(void) {} I2cPort::I2cPort(const unsigned char max_register_number) : max_register_number_(max_register_number) {} @@ -93,3 +95,5 @@ unsigned char I2cPort::ReadCommand(const unsigned char i2c_address, unsigned cha } return length; } + +} // namespace s2e::components \ No newline at end of file diff --git a/src/components/ports/i2c_port.hpp b/src/components/ports/i2c_port.hpp index 57143b992..044431c0e 100644 --- a/src/components/ports/i2c_port.hpp +++ b/src/components/ports/i2c_port.hpp @@ -8,6 +8,8 @@ #include +namespace s2e::components { + /** * @class I2cPort * @brief Class to emulate I2C(Inter-Integrated Circuit) communication port @@ -108,4 +110,6 @@ class I2cPort { std::map, unsigned char> command_buffer_; }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_PORTS_I2C_PORT_HPP_ diff --git a/src/components/ports/power_port.cpp b/src/components/ports/power_port.cpp index 1a3393ec3..5671b94e9 100644 --- a/src/components/ports/power_port.cpp +++ b/src/components/ports/power_port.cpp @@ -9,6 +9,8 @@ #include #include +namespace s2e::components { + PowerPort::PowerPort() : kPortId(-1), current_limit_A_(10.0), minimum_voltage_V_(3.3), assumed_power_consumption_W_(0.0) { is_on_ = true; // power on to work the component Initialize(); @@ -66,7 +68,7 @@ void PowerPort::SubtractAssumedPowerConsumption_W(const double power_W) { } void PowerPort::InitializeWithInitializeFile(const std::string file_name) { - IniAccess initialize_file(file_name); + setting_file_reader::IniAccess initialize_file(file_name); const std::string section_name = "POWER_PORT"; double minimum_voltage_V = initialize_file.ReadDouble(section_name.c_str(), "minimum_voltage_V"); @@ -74,3 +76,5 @@ void PowerPort::InitializeWithInitializeFile(const std::string file_name) { double assumed_power_consumption_W = initialize_file.ReadDouble(section_name.c_str(), "assumed_power_consumption_W"); this->SetAssumedPowerConsumption_W(assumed_power_consumption_W); } + +} // namespace s2e::components diff --git a/src/components/ports/power_port.hpp b/src/components/ports/power_port.hpp index e890d25b5..98d0a74d6 100644 --- a/src/components/ports/power_port.hpp +++ b/src/components/ports/power_port.hpp @@ -8,6 +8,8 @@ #include +namespace s2e::components { + /** * @class PowerPort * @brief Class to emulate electrical power port @@ -133,4 +135,6 @@ class PowerPort { void Initialize(void); }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_PORTS_POWER_PORT_HPP_ diff --git a/src/components/ports/uart_port.cpp b/src/components/ports/uart_port.cpp index a2ad5303a..070bd59ad 100644 --- a/src/components/ports/uart_port.cpp +++ b/src/components/ports/uart_port.cpp @@ -5,6 +5,8 @@ #include "uart_port.hpp" +namespace s2e::components { + UartPort::UartPort() : UartPort(kDefaultBufferSize, kDefaultBufferSize) {} UartPort::UartPort(const unsigned int rx_buffer_size, const unsigned int tx_buffer_size) { @@ -12,8 +14,8 @@ UartPort::UartPort(const unsigned int rx_buffer_size, const unsigned int tx_buff unsigned int checked_tx_buffer_size = tx_buffer_size; if (rx_buffer_size <= 0) checked_rx_buffer_size = kDefaultBufferSize; if (tx_buffer_size <= 0) checked_tx_buffer_size = kDefaultBufferSize; - rx_buffer_ = new RingBuffer(checked_rx_buffer_size); - tx_buffer_ = new RingBuffer(checked_tx_buffer_size); + rx_buffer_ = new utilities::RingBuffer(checked_rx_buffer_size); + tx_buffer_ = new utilities::RingBuffer(checked_tx_buffer_size); } UartPort::~UartPort() { @@ -36,3 +38,5 @@ int UartPort::ReadTx(unsigned char* buffer, const unsigned int offset, const uns int UartPort::ReadRx(unsigned char* buffer, const unsigned int offset, const unsigned int data_length) { return rx_buffer_->Read(buffer, offset, data_length); } + +} // namespace s2e::components diff --git a/src/components/ports/uart_port.hpp b/src/components/ports/uart_port.hpp index b50f90c28..c83ddc456 100644 --- a/src/components/ports/uart_port.hpp +++ b/src/components/ports/uart_port.hpp @@ -8,6 +8,8 @@ #include +namespace s2e::components { + /** * @class UartPort * @brief Class to emulate UART communication port @@ -74,8 +76,10 @@ class UartPort { private: const static unsigned int kDefaultBufferSize = 1024; //!< Default buffer size - RingBuffer* rx_buffer_; //!< Receive buffer (Component -> OBC) - RingBuffer* tx_buffer_; //!< Transmit buffer (OBC-> Component) + utilities::RingBuffer* rx_buffer_; //!< Receive buffer (Component -> OBC) + utilities::RingBuffer* tx_buffer_; //!< Transmit buffer (OBC-> Component) }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_PORTS_UART_PORT_HPP_ diff --git a/src/components/real/aocs/gnss_receiver.cpp b/src/components/real/aocs/gnss_receiver.cpp index a07a52a0b..8acf57890 100644 --- a/src/components/real/aocs/gnss_receiver.cpp +++ b/src/components/real/aocs/gnss_receiver.cpp @@ -11,11 +11,13 @@ #include #include -GnssReceiver::GnssReceiver(const int prescaler, ClockGenerator* clock_generator, const size_t component_id, const AntennaModel antenna_model, - const math::Vector<3> antenna_position_b_m, const math::Quaternion quaternion_b2c, const double half_width_deg, - const math::Vector<3> position_noise_standard_deviation_ecef_m, - const math::Vector<3> velocity_noise_standard_deviation_ecef_m_s, const Dynamics* dynamics, - const GnssSatellites* gnss_satellites, const SimulationTime* simulation_time) +namespace s2e::components { + +GnssReceiver::GnssReceiver(const int prescaler, environment::ClockGenerator* clock_generator, const size_t component_id, + const AntennaModel antenna_model, const math::Vector<3> antenna_position_b_m, const math::Quaternion quaternion_b2c, + const double half_width_deg, const math::Vector<3> position_noise_standard_deviation_ecef_m, + const math::Vector<3> velocity_noise_standard_deviation_ecef_m_s, const dynamics::Dynamics* dynamics, + const environment::GnssSatellites* gnss_satellites, const environment::SimulationTime* simulation_time) : Component(prescaler, clock_generator), component_id_(component_id), antenna_position_b_m_(antenna_position_b_m), @@ -26,16 +28,17 @@ GnssReceiver::GnssReceiver(const int prescaler, ClockGenerator* clock_generator, gnss_satellites_(gnss_satellites), simulation_time_(simulation_time) { for (size_t i = 0; i < 3; i++) { - position_random_noise_ecef_m_[i].SetParameters(0.0, position_noise_standard_deviation_ecef_m[i], global_randomization.MakeSeed()); - velocity_random_noise_ecef_m_s_[i].SetParameters(0.0, velocity_noise_standard_deviation_ecef_m_s[i], global_randomization.MakeSeed()); + position_random_noise_ecef_m_[i].SetParameters(0.0, position_noise_standard_deviation_ecef_m[i], randomization::global_randomization.MakeSeed()); + velocity_random_noise_ecef_m_s_[i].SetParameters(0.0, velocity_noise_standard_deviation_ecef_m_s[i], + randomization::global_randomization.MakeSeed()); } } -GnssReceiver::GnssReceiver(const int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, const size_t component_id, +GnssReceiver::GnssReceiver(const int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, const size_t component_id, const AntennaModel antenna_model, const math::Vector<3> antenna_position_b_m, const math::Quaternion quaternion_b2c, const double half_width_deg, const math::Vector<3> position_noise_standard_deviation_ecef_m, - const math::Vector<3> velocity_noise_standard_deviation_ecef_m_s, const Dynamics* dynamics, - const GnssSatellites* gnss_satellites, const SimulationTime* simulation_time) + const math::Vector<3> velocity_noise_standard_deviation_ecef_m_s, const dynamics::Dynamics* dynamics, + const environment::GnssSatellites* gnss_satellites, const environment::SimulationTime* simulation_time) : Component(prescaler, clock_generator, power_port), component_id_(component_id), antenna_position_b_m_(antenna_position_b_m), @@ -46,8 +49,9 @@ GnssReceiver::GnssReceiver(const int prescaler, ClockGenerator* clock_generator, gnss_satellites_(gnss_satellites), simulation_time_(simulation_time) { for (size_t i = 0; i < 3; i++) { - position_random_noise_ecef_m_[i].SetParameters(0.0, position_noise_standard_deviation_ecef_m[i], global_randomization.MakeSeed()); - velocity_random_noise_ecef_m_s_[i].SetParameters(0.0, velocity_noise_standard_deviation_ecef_m_s[i], global_randomization.MakeSeed()); + position_random_noise_ecef_m_[i].SetParameters(0.0, position_noise_standard_deviation_ecef_m[i], randomization::global_randomization.MakeSeed()); + velocity_random_noise_ecef_m_s_[i].SetParameters(0.0, velocity_noise_standard_deviation_ecef_m_s[i], + randomization::global_randomization.MakeSeed()); } } @@ -200,19 +204,19 @@ std::string GnssReceiver::GetLogHeader() const // For logs const std::string sensor_id = std::to_string(static_cast(component_id_)); std::string sensor_name = "gnss_receiver" + sensor_id + "_"; - str_tmp += WriteScalar(sensor_name + "measured_utc_time_year"); - str_tmp += WriteScalar(sensor_name + "measured_utc_time_month"); - str_tmp += WriteScalar(sensor_name + "measured_utc_time_day"); - str_tmp += WriteScalar(sensor_name + "measured_utc_time_hour"); - str_tmp += WriteScalar(sensor_name + "measured_utc_time_min"); - str_tmp += WriteScalar(sensor_name + "measured_utc_time_sec"); - str_tmp += WriteVector(sensor_name + "measured_position", "ecef", "m", 3); - str_tmp += WriteVector(sensor_name + "measured_velocity", "ecef", "m/s", 3); - str_tmp += WriteScalar(sensor_name + "measured_latitude", "rad"); - str_tmp += WriteScalar(sensor_name + "measured_longitude", "rad"); - str_tmp += WriteScalar(sensor_name + "measured_altitude", "m"); - str_tmp += WriteScalar(sensor_name + "satellite_visible_flag"); - str_tmp += WriteScalar(sensor_name + "number_of_visible_satellites"); + str_tmp += logger::WriteScalar(sensor_name + "measured_utc_time_year"); + str_tmp += logger::WriteScalar(sensor_name + "measured_utc_time_month"); + str_tmp += logger::WriteScalar(sensor_name + "measured_utc_time_day"); + str_tmp += logger::WriteScalar(sensor_name + "measured_utc_time_hour"); + str_tmp += logger::WriteScalar(sensor_name + "measured_utc_time_min"); + str_tmp += logger::WriteScalar(sensor_name + "measured_utc_time_sec"); + str_tmp += logger::WriteVector(sensor_name + "measured_position", "ecef", "m", 3); + str_tmp += logger::WriteVector(sensor_name + "measured_velocity", "ecef", "m/s", 3); + str_tmp += logger::WriteScalar(sensor_name + "measured_latitude", "rad"); + str_tmp += logger::WriteScalar(sensor_name + "measured_longitude", "rad"); + str_tmp += logger::WriteScalar(sensor_name + "measured_altitude", "m"); + str_tmp += logger::WriteScalar(sensor_name + "satellite_visible_flag"); + str_tmp += logger::WriteScalar(sensor_name + "number_of_visible_satellites"); return str_tmp; } @@ -220,19 +224,19 @@ std::string GnssReceiver::GetLogHeader() const // For logs std::string GnssReceiver::GetLogValue() const // For logs { std::string str_tmp = ""; - str_tmp += WriteScalar(utc_.year); - str_tmp += WriteScalar(utc_.month); - str_tmp += WriteScalar(utc_.day); - str_tmp += WriteScalar(utc_.hour); - str_tmp += WriteScalar(utc_.minute); - str_tmp += WriteScalar(utc_.second); - str_tmp += WriteVector(position_ecef_m_, 10); - str_tmp += WriteVector(velocity_ecef_m_s_, 10); - str_tmp += WriteScalar(geodetic_position_.GetLatitude_rad(), 10); - str_tmp += WriteScalar(geodetic_position_.GetLongitude_rad(), 10); - str_tmp += WriteScalar(geodetic_position_.GetAltitude_m(), 10); - str_tmp += WriteScalar(is_gnss_visible_); - str_tmp += WriteScalar(visible_satellite_number_); + str_tmp += logger::WriteScalar(utc_.year); + str_tmp += logger::WriteScalar(utc_.month); + str_tmp += logger::WriteScalar(utc_.day); + str_tmp += logger::WriteScalar(utc_.hour); + str_tmp += logger::WriteScalar(utc_.minute); + str_tmp += logger::WriteScalar(utc_.second); + str_tmp += logger::WriteVector(position_ecef_m_, 10); + str_tmp += logger::WriteVector(velocity_ecef_m_s_, 10); + str_tmp += logger::WriteScalar(geodetic_position_.GetLatitude_rad(), 10); + str_tmp += logger::WriteScalar(geodetic_position_.GetLongitude_rad(), 10); + str_tmp += logger::WriteScalar(geodetic_position_.GetAltitude_m(), 10); + str_tmp += logger::WriteScalar(is_gnss_visible_); + str_tmp += logger::WriteScalar(visible_satellite_number_); return str_tmp; } @@ -259,10 +263,10 @@ typedef struct _gnss_receiver_param { math::Vector<3> velocity_noise_standard_deviation_ecef_m_s; } GnssReceiverParam; -GnssReceiverParam ReadGnssReceiverIni(const std::string file_name, const GnssSatellites* gnss_satellites, const size_t component_id) { +GnssReceiverParam ReadGnssReceiverIni(const std::string file_name, const environment::GnssSatellites* gnss_satellites, const size_t component_id) { GnssReceiverParam gnss_receiver_param; - IniAccess gnssr_conf(file_name); + setting_file_reader::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(); @@ -289,8 +293,9 @@ GnssReceiverParam ReadGnssReceiverIni(const std::string file_name, const GnssSat return gnss_receiver_param; } -GnssReceiver InitGnssReceiver(ClockGenerator* clock_generator, const size_t component_id, const std::string file_name, const Dynamics* dynamics, - const GnssSatellites* gnss_satellites, const SimulationTime* simulation_time) { +GnssReceiver InitGnssReceiver(environment::ClockGenerator* clock_generator, const size_t component_id, const std::string file_name, + const dynamics::Dynamics* dynamics, const environment::GnssSatellites* gnss_satellites, + const environment::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.antenna_model, gr_param.antenna_pos_b, gr_param.quaternion_b2c, @@ -299,8 +304,9 @@ GnssReceiver InitGnssReceiver(ClockGenerator* clock_generator, const size_t comp return gnss_r; } -GnssReceiver InitGnssReceiver(ClockGenerator* clock_generator, PowerPort* power_port, const size_t component_id, const std::string file_name, - const Dynamics* dynamics, const GnssSatellites* gnss_satellites, const SimulationTime* simulation_time) { +GnssReceiver InitGnssReceiver(environment::ClockGenerator* clock_generator, PowerPort* power_port, const size_t component_id, + const std::string file_name, const dynamics::Dynamics* dynamics, const environment::GnssSatellites* gnss_satellites, + const environment::SimulationTime* simulation_time) { GnssReceiverParam gr_param = ReadGnssReceiverIni(file_name, gnss_satellites, component_id); // PowerPort @@ -311,3 +317,5 @@ GnssReceiver InitGnssReceiver(ClockGenerator* clock_generator, PowerPort* power_ gr_param.velocity_noise_standard_deviation_ecef_m_s, dynamics, gnss_satellites, simulation_time); return gnss_r; } + +} // namespace s2e::components diff --git a/src/components/real/aocs/gnss_receiver.hpp b/src/components/real/aocs/gnss_receiver.hpp index f0fe73b06..7c1b586d0 100644 --- a/src/components/real/aocs/gnss_receiver.hpp +++ b/src/components/real/aocs/gnss_receiver.hpp @@ -16,6 +16,8 @@ #include "../../base/component.hpp" +namespace s2e::components { + /** * @enum AntennaModel * @brief Antenna pattern model to emulate GNSS antenna @@ -40,7 +42,7 @@ typedef struct _gnss_info { * @class GnssReceiver * @brief Class to emulate GNSS receiver */ -class GnssReceiver : public Component, public ILoggable { +class GnssReceiver : public Component, public logger::ILoggable { public: /** * @fn GnssReceiver @@ -58,10 +60,11 @@ class GnssReceiver : public Component, public ILoggable { * @param [in] gnss_satellites: GNSS Satellites information * @param [in] simulation_time: Simulation time information */ - GnssReceiver(const int prescaler, ClockGenerator* clock_generator, const size_t component_id, const AntennaModel antenna_model, + GnssReceiver(const int prescaler, environment::ClockGenerator* clock_generator, const size_t component_id, const AntennaModel antenna_model, const math::Vector<3> antenna_position_b_m, const math::Quaternion quaternion_b2c, const double half_width_deg, const math::Vector<3> position_noise_standard_deviation_ecef_m, const math::Vector<3> velocity_noise_standard_deviation_ecef_m_s, - const Dynamics* dynamics, const GnssSatellites* gnss_satellites, const SimulationTime* simulation_time); + const dynamics::Dynamics* dynamics, const environment::GnssSatellites* gnss_satellites, + const environment::SimulationTime* simulation_time); /** * @fn GnssReceiver * @brief Constructor with power port @@ -78,11 +81,11 @@ class GnssReceiver : public Component, public ILoggable { * @param [in] gnss_satellites: GNSS Satellites information * @param [in] simulation_time: Simulation time information */ - GnssReceiver(const int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, const size_t component_id, + GnssReceiver(const int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, const size_t component_id, const AntennaModel antenna_model, const math::Vector<3> antenna_position_b_m, const math::Quaternion quaternion_b2c, const double half_width_deg, const math::Vector<3> position_noise_standard_deviation_ecef_m, - const math::Vector<3> velocity_noise_standard_deviation_ecef_m_s, const Dynamics* dynamics, const GnssSatellites* gnss_satellites, - const SimulationTime* simulation_time); + const math::Vector<3> velocity_noise_standard_deviation_ecef_m_s, const dynamics::Dynamics* dynamics, + const environment::GnssSatellites* gnss_satellites, const environment::SimulationTime* simulation_time); // Override functions for Component /** @@ -114,15 +117,15 @@ class GnssReceiver : public Component, public ILoggable { */ inline const math::Vector<3> GetMeasuredVelocity_ecef_m_s(void) const { return velocity_ecef_m_s_; } - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; @@ -144,9 +147,9 @@ class GnssReceiver : public Component, public ILoggable { geodesy::GeodeticPosition geodetic_position_; //!< Observed position in the geodetic frame // Time observation - UTC utc_ = {2000, 1, 1, 0, 0, 0.0}; //!< Observed time in UTC [year, month, day, hour, min, sec] - unsigned int gps_time_week_ = 0; //!< Observed GPS time week part - double gps_time_s_ = 0.0; //!< Observed GPS time second part + environment::UTC utc_ = {2000, 1, 1, 0, 0, 0.0}; //!< Observed time in UTC [year, month, day, hour, min, sec] + unsigned int gps_time_week_ = 0; //!< Observed GPS time week part + double gps_time_s_ = 0.0; //!< Observed GPS time second part // Satellite visibility bool is_gnss_visible_ = false; //!< Flag for GNSS satellite is visible or not @@ -154,9 +157,9 @@ class GnssReceiver : public Component, public ILoggable { std::vector gnss_information_list_; //!< Information List of visible GNSS satellites // References - const Dynamics* dynamics_; //!< Dynamics of spacecraft - const GnssSatellites* gnss_satellites_; //!< Information of GNSS satellites - const SimulationTime* simulation_time_; //!< Simulation time + const dynamics::Dynamics* dynamics_; //!< Dynamics of spacecraft + const environment::GnssSatellites* gnss_satellites_; //!< Information of GNSS satellites + const environment::SimulationTime* simulation_time_; //!< Simulation time // Internal Functions /** @@ -224,8 +227,9 @@ AntennaModel SetAntennaModel(const std::string antenna_model); * @param [in] gnss_satellites: GNSS satellites information * @param [in] simulation_time: Simulation time information */ -GnssReceiver InitGnssReceiver(ClockGenerator* clock_generator, const size_t component_id, const std::string file_name, const Dynamics* dynamics, - const GnssSatellites* gnss_satellites, const SimulationTime* simulation_time); +GnssReceiver InitGnssReceiver(environment::ClockGenerator* clock_generator, const size_t component_id, const std::string file_name, + const dynamics::Dynamics* dynamics, const environment::GnssSatellites* gnss_satellites, + const environment::SimulationTime* simulation_time); /** * @fn InitGnssReceiver * @brief Initialize functions for GNSS Receiver with power port @@ -237,7 +241,10 @@ GnssReceiver InitGnssReceiver(ClockGenerator* clock_generator, const size_t comp * @param [in] gnss_satellites: GNSS satellites information * @param [in] simulation_time: Simulation time information */ -GnssReceiver InitGnssReceiver(ClockGenerator* clock_generator, PowerPort* power_port, const size_t component_id, const std::string file_name, - const Dynamics* dynamics, const GnssSatellites* gnss_satellites, const SimulationTime* simulation_time); +GnssReceiver InitGnssReceiver(environment::ClockGenerator* clock_generator, PowerPort* power_port, const size_t component_id, + const std::string file_name, const dynamics::Dynamics* dynamics, const environment::GnssSatellites* gnss_satellites, + const environment::SimulationTime* simulation_time); + +} // namespace s2e::components #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 20e03edc9..5a019cd5a 100644 --- a/src/components/real/aocs/gyro_sensor.cpp +++ b/src/components/real/aocs/gyro_sensor.cpp @@ -7,12 +7,14 @@ #include -GyroSensor::GyroSensor(const int prescaler, ClockGenerator* clock_generator, Sensor& sensor_base, const unsigned int sensor_id, - const math::Quaternion& quaternion_b2c, const Dynamics* dynamics) +namespace s2e::components { + +GyroSensor::GyroSensor(const int prescaler, environment::ClockGenerator* clock_generator, Sensor& sensor_base, const unsigned int sensor_id, + const math::Quaternion& quaternion_b2c, const dynamics::Dynamics* dynamics) : Component(prescaler, clock_generator), Sensor(sensor_base), sensor_id_(sensor_id), quaternion_b2c_(quaternion_b2c), dynamics_(dynamics) {} -GyroSensor::GyroSensor(const int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, Sensor& sensor_base, const unsigned int sensor_id, - const math::Quaternion& quaternion_b2c, const Dynamics* dynamics) +GyroSensor::GyroSensor(const int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, Sensor& sensor_base, + const unsigned int sensor_id, const math::Quaternion& quaternion_b2c, const dynamics::Dynamics* dynamics) : Component(prescaler, clock_generator, power_port), Sensor(sensor_base), sensor_id_(sensor_id), @@ -32,7 +34,7 @@ std::string GyroSensor::GetLogHeader() const { std::string str_tmp = ""; const std::string sensor_id = std::to_string(static_cast(sensor_id_)); std::string sensor_name = "gyro_sensor" + sensor_id + "_"; - str_tmp += WriteVector(sensor_name + "measured_angular_velocity", "c", "rad/s", kGyroDimension); + str_tmp += logger::WriteVector(sensor_name + "measured_angular_velocity", "c", "rad/s", kGyroDimension); return str_tmp; } @@ -40,14 +42,14 @@ std::string GyroSensor::GetLogHeader() const { std::string GyroSensor::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteVector(angular_velocity_c_rad_s_); + str_tmp += logger::WriteVector(angular_velocity_c_rad_s_); 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); +GyroSensor InitGyroSensor(environment::ClockGenerator* clock_generator, int sensor_id, const std::string file_name, double component_step_time_s, + const dynamics::Dynamics* dynamics) { + setting_file_reader::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(); @@ -66,9 +68,9 @@ GyroSensor InitGyroSensor(ClockGenerator* clock_generator, int sensor_id, const 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); +GyroSensor InitGyroSensor(environment::ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const std::string file_name, + double component_step_time_s, const dynamics::Dynamics* dynamics) { + setting_file_reader::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(); @@ -88,3 +90,5 @@ GyroSensor InitGyroSensor(ClockGenerator* clock_generator, PowerPort* power_port GyroSensor gyro(prescaler, clock_generator, power_port, sensor_base, sensor_id, quaternion_b2c, dynamics); return gyro; } + +} // namespace s2e::components diff --git a/src/components/real/aocs/gyro_sensor.hpp b/src/components/real/aocs/gyro_sensor.hpp index 139bf8597..ab75c929e 100644 --- a/src/components/real/aocs/gyro_sensor.hpp +++ b/src/components/real/aocs/gyro_sensor.hpp @@ -13,13 +13,15 @@ #include "../../base/component.hpp" #include "../../base/sensor.hpp" +namespace s2e::components { + const size_t kGyroDimension = 3; //!< Dimension of gyro sensor /** * @class GyroSensor * @brief Class to emulate gyro sensor */ -class GyroSensor : public Component, public Sensor, public ILoggable { +class GyroSensor : public Component, public Sensor, public logger::ILoggable { public: /** * @fn GyroSensor @@ -31,8 +33,8 @@ class GyroSensor : public Component, public Sensor, public ILogg * @param [in] quaternion_b2c: Quaternion from body frame to component frame * @param [in] dynamics: Dynamics information */ - GyroSensor(const int prescaler, ClockGenerator* clock_generator, Sensor& sensor_base, const unsigned int sensor_id, - const math::Quaternion& quaternion_b2c, const Dynamics* dynamics); + GyroSensor(const int prescaler, environment::ClockGenerator* clock_generator, Sensor& sensor_base, const unsigned int sensor_id, + const math::Quaternion& quaternion_b2c, const dynamics::Dynamics* dynamics); /** * @fn GyroSensor * @brief Constructor with power port @@ -44,8 +46,8 @@ class GyroSensor : public Component, public Sensor, public ILogg * @param [in] quaternion_b2c: Quaternion from body frame to component frame * @param [in] dynamics: Dynamics information */ - GyroSensor(const int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, Sensor& sensor_base, const unsigned int sensor_id, - const math::Quaternion& quaternion_b2c, const Dynamics* dynamics); + GyroSensor(const int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, Sensor& sensor_base, + const unsigned int sensor_id, const math::Quaternion& quaternion_b2c, const dynamics::Dynamics* dynamics); /** * @fn ~GyroSensor * @brief Destructor @@ -59,15 +61,15 @@ class GyroSensor : public Component, public Sensor, public ILogg */ void MainRoutine(const int time_count) override; - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const override; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const override; @@ -83,7 +85,7 @@ class GyroSensor : public Component, public Sensor, public ILogg unsigned int sensor_id_ = 0; //!< Sensor ID math::Quaternion quaternion_b2c_{0.0, 0.0, 0.0, 1.0}; //!< Quaternion from body frame to component frame - const Dynamics* dynamics_; //!< Dynamics information + const dynamics::Dynamics* dynamics_; //!< Dynamics information }; /** @@ -95,8 +97,8 @@ class GyroSensor : public Component, public Sensor, public ILogg * @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); +GyroSensor InitGyroSensor(environment::ClockGenerator* clock_generator, int sensor_id, const std::string file_name, double component_step_time_s, + const dynamics::Dynamics* dynamics); /** * @fn InitGyroSensor * @brief Initialize functions for gyro sensor with power port @@ -105,9 +107,11 @@ GyroSensor InitGyroSensor(ClockGenerator* clock_generator, int sensor_id, const * @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 + * @param [in] dynamics: 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); +GyroSensor InitGyroSensor(environment::ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const std::string file_name, + double component_step_time_s, const dynamics::Dynamics* dynamics); + +} // namespace s2e::components #endif // S2E_COMPONENTS_REAL_AOCS_GYRO_SENSOR_HPP_ diff --git a/src/components/real/aocs/magnetometer.cpp b/src/components/real/aocs/magnetometer.cpp index d28be5bad..0958e312c 100644 --- a/src/components/real/aocs/magnetometer.cpp +++ b/src/components/real/aocs/magnetometer.cpp @@ -7,15 +7,18 @@ #include #include -Magnetometer::Magnetometer(int prescaler, ClockGenerator* clock_generator, Sensor& sensor_base, const unsigned int sensor_id, - const math::Quaternion& quaternion_b2c, const GeomagneticField* geomagnetic_field) +namespace s2e::components { + +Magnetometer::Magnetometer(int prescaler, environment::ClockGenerator* clock_generator, Sensor& sensor_base, const unsigned int sensor_id, + const math::Quaternion& quaternion_b2c, const environment::GeomagneticField* geomagnetic_field) : Component(prescaler, clock_generator), Sensor(sensor_base), sensor_id_(sensor_id), quaternion_b2c_(quaternion_b2c), geomagnetic_field_(geomagnetic_field) {} -Magnetometer::Magnetometer(int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, Sensor& sensor_base, const unsigned int sensor_id, - const math::Quaternion& quaternion_b2c, const GeomagneticField* geomagnetic_field) +Magnetometer::Magnetometer(int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, Sensor& sensor_base, + const unsigned int sensor_id, const math::Quaternion& quaternion_b2c, + const environment::GeomagneticField* geomagnetic_field) : Component(prescaler, clock_generator, power_port), Sensor(sensor_base), sensor_id_(sensor_id), @@ -34,7 +37,7 @@ std::string Magnetometer::GetLogHeader() const { std::string str_tmp = ""; const std::string sensor_id = std::to_string(static_cast(sensor_id_)); std::string sensor_name = "magnetometer" + sensor_id + "_"; - str_tmp += WriteVector(sensor_name + "measured_magnetic_field", "c", "nT", kMagnetometerDimension); + str_tmp += logger::WriteVector(sensor_name + "measured_magnetic_field", "c", "nT", kMagnetometerDimension); return str_tmp; } @@ -42,14 +45,14 @@ std::string Magnetometer::GetLogHeader() const { std::string Magnetometer::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteVector(magnetic_field_c_nT_); + str_tmp += logger::WriteVector(magnetic_field_c_nT_); 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); +Magnetometer InitMagnetometer(environment::ClockGenerator* clock_generator, int sensor_id, const std::string file_name, double component_step_time_s, + const environment::GeomagneticField* geomagnetic_field) { + setting_file_reader::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(); @@ -68,9 +71,9 @@ Magnetometer InitMagnetometer(ClockGenerator* clock_generator, int sensor_id, co 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); +Magnetometer InitMagnetometer(environment::ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const std::string file_name, + double component_step_time_s, const environment::GeomagneticField* geomagnetic_field) { + setting_file_reader::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(); @@ -91,3 +94,5 @@ Magnetometer InitMagnetometer(ClockGenerator* clock_generator, PowerPort* power_ Magnetometer magsensor(prescaler, clock_generator, power_port, sensor_base, sensor_id, quaternion_b2c, geomagnetic_field); return magsensor; } + +} // namespace s2e::components diff --git a/src/components/real/aocs/magnetometer.hpp b/src/components/real/aocs/magnetometer.hpp index deaccf1aa..2d788b366 100644 --- a/src/components/real/aocs/magnetometer.hpp +++ b/src/components/real/aocs/magnetometer.hpp @@ -13,13 +13,15 @@ #include "../../base/component.hpp" #include "../../base/sensor.hpp" +namespace s2e::components { + const size_t kMagnetometerDimension = 3; //!< Dimension of magnetometer /** * @class Magnetometer * @brief Class to emulate magnetometer */ -class Magnetometer : public Component, public Sensor, public ILoggable { +class Magnetometer : public Component, public Sensor, public logger::ILoggable { public: /** * @fn Magnetometer @@ -31,8 +33,8 @@ class Magnetometer : public Component, public Sensor, pu * @param [in] quaternion_b2c: Quaternion from body frame to component frame * @param [in] geomagnetic_field: Geomagnetic environment */ - Magnetometer(const int prescaler, ClockGenerator* clock_generator, Sensor& sensor_base, const unsigned int sensor_id, - const math::Quaternion& quaternion_b2c, const GeomagneticField* geomagnetic_field); + Magnetometer(const int prescaler, environment::ClockGenerator* clock_generator, Sensor& sensor_base, const unsigned int sensor_id, + const math::Quaternion& quaternion_b2c, const environment::GeomagneticField* geomagnetic_field); /** * @fn Magnetometer * @brief Constructor with power port @@ -44,8 +46,8 @@ class Magnetometer : public Component, public Sensor, pu * @param [in] quaternion_b2c: Quaternion from body frame to component frame * @param [in] geomagnetic_field: Geomagnetic environment */ - Magnetometer(const int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, Sensor& sensor_base, const unsigned int sensor_id, - const math::Quaternion& quaternion_b2c, const GeomagneticField* geomagnetic_field); + Magnetometer(const int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, Sensor& sensor_base, + const unsigned int sensor_id, const math::Quaternion& quaternion_b2c, const environment::GeomagneticField* geomagnetic_field); /** * @fn ~Magnetometer * @brief Destructor @@ -59,15 +61,15 @@ class Magnetometer : public Component, public Sensor, pu */ void MainRoutine(const int time_count) override; - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const override; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const override; @@ -102,7 +104,7 @@ class Magnetometer : public Component, public Sensor, pu unsigned int sensor_id_ = 0; //!< Sensor ID math::Quaternion quaternion_b2c_{0.0, 0.0, 0.0, 1.0}; //!< Quaternion from body frame to component frame - const GeomagneticField* geomagnetic_field_; //!< Geomagnetic environment + const environment::GeomagneticField* geomagnetic_field_; //!< Geomagnetic environment }; /** @@ -114,8 +116,8 @@ class Magnetometer : public Component, public Sensor, pu * @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); +Magnetometer InitMagnetometer(environment::ClockGenerator* clock_generator, int sensor_id, const std::string file_name, double component_step_time_s, + const environment::GeomagneticField* geomagnetic_field); /** * @fn InitMagnetometer * @brief Initialize functions for magnetometer with power port @@ -126,7 +128,9 @@ Magnetometer InitMagnetometer(ClockGenerator* clock_generator, int sensor_id, co * @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); +Magnetometer InitMagnetometer(environment::ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const std::string file_name, + double component_step_time_s, const environment::GeomagneticField* geomagnetic_field); + +} // namespace s2e::components #endif // S2E_COMPONENTS_REAL_AOCS_MAGNETOMETER_HPP_ diff --git a/src/components/real/aocs/magnetorquer.cpp b/src/components/real/aocs/magnetorquer.cpp index 0f1a2bb22..0ee096e5e 100644 --- a/src/components/real/aocs/magnetorquer.cpp +++ b/src/components/real/aocs/magnetorquer.cpp @@ -11,13 +11,16 @@ #include #include -Magnetorquer::Magnetorquer(const int prescaler, ClockGenerator* clock_generator, const int component_id, const math::Quaternion& quaternion_b2c, - const math::Matrix& scale_factor, +namespace s2e::components { + +Magnetorquer::Magnetorquer(const int prescaler, environment::ClockGenerator* clock_generator, const int component_id, + const math::Quaternion& quaternion_b2c, const math::Matrix& scale_factor, const math::Vector& max_magnetic_moment_c_Am2, const math::Vector& min_magnetic_moment_c_Am2, const math::Vector& bias_noise_c_Am2_, double random_walk_step_width_s, const math::Vector& random_walk_standard_deviation_c_Am2, const math::Vector& random_walk_limit_c_Am2, - const math::Vector& normal_random_standard_deviation_c_Am2, const GeomagneticField* geomagnetic_field) + const math::Vector& normal_random_standard_deviation_c_Am2, + const environment::GeomagneticField* geomagnetic_field) : Component(prescaler, clock_generator), component_id_(component_id), quaternion_b2c_(quaternion_b2c), @@ -33,13 +36,14 @@ Magnetorquer::Magnetorquer(const int prescaler, ClockGenerator* clock_generator, } } -Magnetorquer::Magnetorquer(const int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, +Magnetorquer::Magnetorquer(const int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, const math::Quaternion& quaternion_b2c, const math::Matrix& scale_factor, const math::Vector& max_magnetic_moment_c_Am2, const math::Vector& min_magnetic_moment_c_Am2, const math::Vector& bias_noise_c_Am2_, double random_walk_step_width_s, const math::Vector& random_walk_standard_deviation_c_Am2, const math::Vector& random_walk_limit_c_Am2, - const math::Vector& normal_random_standard_deviation_c_Am2, const GeomagneticField* geomagnetic_field) + const math::Vector& normal_random_standard_deviation_c_Am2, + const environment::GeomagneticField* geomagnetic_field) : Component(prescaler, clock_generator, power_port), component_id_(component_id), quaternion_b2c_(quaternion_b2c), @@ -97,23 +101,23 @@ std::string Magnetorquer::GetLogHeader() const { const std::string actuator_id = std::to_string(static_cast(component_id_)); std::string actuator_name = "magnetorquer" + actuator_id + "_"; - str_tmp += WriteVector(actuator_name + "output_magnetic_moment", "b", "Am2", kMtqDimension); - str_tmp += WriteVector(actuator_name + "output_torque", "b", "Nm", kMtqDimension); + str_tmp += logger::WriteVector(actuator_name + "output_magnetic_moment", "b", "Am2", kMtqDimension); + str_tmp += logger::WriteVector(actuator_name + "output_torque", "b", "Nm", kMtqDimension); return str_tmp; } std::string Magnetorquer::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteVector(output_magnetic_moment_b_Am2_); - str_tmp += WriteVector(torque_b_Nm_); + str_tmp += logger::WriteVector(output_magnetic_moment_b_Am2_); + str_tmp += logger::WriteVector(torque_b_Nm_); 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); +Magnetorquer InitMagnetorquer(environment::ClockGenerator* clock_generator, int actuator_id, const std::string file_name, + double component_step_time_s, const environment::GeomagneticField* geomagnetic_field) { + setting_file_reader::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(); @@ -156,9 +160,9 @@ Magnetorquer InitMagnetorquer(ClockGenerator* clock_generator, int actuator_id, 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); +Magnetorquer InitMagnetorquer(environment::ClockGenerator* clock_generator, PowerPort* power_port, int actuator_id, const std::string file_name, + double component_step_time_s, const environment::GeomagneticField* geomagnetic_field) { + setting_file_reader::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(); @@ -203,3 +207,5 @@ Magnetorquer InitMagnetorquer(ClockGenerator* clock_generator, PowerPort* power_ random_walk_limit_c_Am2, normal_random_standard_deviation_c_Am2, geomagnetic_field); return magtorquer; } + +} // namespace s2e::components diff --git a/src/components/real/aocs/magnetorquer.hpp b/src/components/real/aocs/magnetorquer.hpp index 91b91864b..0ef0a5e4b 100644 --- a/src/components/real/aocs/magnetorquer.hpp +++ b/src/components/real/aocs/magnetorquer.hpp @@ -16,13 +16,15 @@ #include "../../base/component.hpp" +namespace s2e::components { + const size_t kMtqDimension = 3; //!< Dimension of magnetorquer /** * @class Magnetorquer * @brief Class to emulate magnetorquer */ -class Magnetorquer : public Component, public ILoggable { +class Magnetorquer : public Component, public logger::ILoggable { public: /** * @fn Magnetorquer @@ -41,12 +43,12 @@ class Magnetorquer : public Component, public ILoggable { * @param [in] normal_random_standard_deviation_c_Am2: Standard deviation for the normal random noise in the component frame [Am2] * @param [in] geomagnetic_field: Geomagnetic environment */ - Magnetorquer(const int prescaler, ClockGenerator* clock_generator, const int component_id, const math::Quaternion& quaternion_b2c, + Magnetorquer(const int prescaler, environment::ClockGenerator* clock_generator, const int component_id, const math::Quaternion& quaternion_b2c, const math::Matrix& scale_factor, const math::Vector& max_magnetic_moment_c_Am2, const math::Vector& min_magnetic_moment_c_Am2, const math::Vector& bias_noise_c_Am2_, double random_walk_step_width_s, const math::Vector& random_walk_standard_deviation_c_Am2, const math::Vector& random_walk_limit_c_Am2, const math::Vector& normal_random_standard_deviation_c_Am2, - const GeomagneticField* geomagnetic_field); + const environment::GeomagneticField* geomagnetic_field); /** * @fn Magnetorquer * @brief Constructor with power port @@ -65,12 +67,12 @@ class Magnetorquer : public Component, public ILoggable { * @param [in] normal_random_standard_deviation_c_Am2: Standard deviation for the normal random noise in the component frame [Am2] * @param [in] geomagnetic_field: Geomagnetic environment */ - Magnetorquer(const int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, + Magnetorquer(const int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, const math::Quaternion& quaternion_b2c, const math::Matrix& scale_factor, const math::Vector& max_magnetic_moment_c_Am2, const math::Vector& min_magnetic_moment_c_Am2, const math::Vector& bias_noise_c_Am2_, double random_walk_step_width_s, const math::Vector& random_walk_standard_deviation_c_Am2, const math::Vector& random_walk_limit_c_Am2, - const math::Vector& normal_random_standard_deviation_c_Am2, const GeomagneticField* geomagnetic_field); + const math::Vector& normal_random_standard_deviation_c_Am2, const environment::GeomagneticField* geomagnetic_field); // Override functions for Component /** @@ -84,15 +86,15 @@ class Magnetorquer : public Component, public ILoggable { */ void PowerOffRoutine() override; - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const override; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const override; @@ -132,11 +134,11 @@ class Magnetorquer : public Component, public ILoggable { math::Vector max_magnetic_moment_c_Am2_{100.0}; //!< Maximum magnetic moment in the component frame [Am2] math::Vector min_magnetic_moment_c_Am2_{-100.0}; //!< Minimum magnetic moment in the component frame [Am2] - math::Vector bias_noise_c_Am2_{0.0}; //!< Constant bias noise in the component frame [Am2] - RandomWalk random_walk_c_Am2_; //!< Random walk noise + math::Vector bias_noise_c_Am2_{0.0}; //!< Constant bias noise in the component frame [Am2] + randomization::RandomWalk random_walk_c_Am2_; //!< Random walk noise randomization::NormalRand random_noise_c_Am2_[kMtqDimension]; //!< Normal random noise - const GeomagneticField* geomagnetic_field_; //!< Geomagnetic environment + const environment::GeomagneticField* geomagnetic_field_; //!< Geomagnetic environment /** * @fn CalcOutputTorque @@ -155,8 +157,8 @@ class Magnetorquer : public Component, public ILoggable { * @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); +Magnetorquer InitMagnetorquer(environment::ClockGenerator* clock_generator, int actuator_id, const std::string file_name, + double component_step_time_s, const environment::GeomagneticField* geomagnetic_field); /** * @fn InitMagnetorquer * @brief Initialize functions for magnetometer with power port @@ -167,7 +169,9 @@ Magnetorquer InitMagnetorquer(ClockGenerator* clock_generator, int actuator_id, * @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); +Magnetorquer InitMagnetorquer(environment::ClockGenerator* clock_generator, PowerPort* power_port, int actuator_id, const std::string file_name, + double component_step_time_s, const environment::GeomagneticField* geomagnetic_field); + +} // namespace s2e::components #endif // S2E_COMPONENTS_REAL_AOCS_MAGNETORQUER_HPP_ diff --git a/src/components/real/aocs/mtq_magnetometer_interference.cpp b/src/components/real/aocs/mtq_magnetometer_interference.cpp index 9aa2bb1e2..c2428b15b 100644 --- a/src/components/real/aocs/mtq_magnetometer_interference.cpp +++ b/src/components/real/aocs/mtq_magnetometer_interference.cpp @@ -7,11 +7,13 @@ #include "setting_file_reader/initialize_file_access.hpp" +namespace s2e::components { + MtqMagnetometerInterference::MtqMagnetometerInterference(const std::string file_name, Magnetometer& magnetometer, const Magnetorquer& magnetorquer, const size_t initialize_id) : magnetometer_(magnetometer), magnetorquer_(magnetorquer) { // Read ini file - IniAccess ini_file(file_name); + setting_file_reader::IniAccess ini_file(file_name); std::string section = "MTQ_MAGNETOMETER_INTERFERENCE_" + std::to_string(static_cast(initialize_id)); polynomial_degree_ = (size_t)ini_file.ReadInt(section.c_str(), "polynomial_degree"); @@ -49,3 +51,5 @@ void MtqMagnetometerInterference::UpdateInterference(void) { magnetometer_.AddConstantBiasNoise_c_nT(additional_bias_c_nT); previous_added_bias_c_nT_ = additional_bias_c_nT; } + +} // namespace s2e::components diff --git a/src/components/real/aocs/mtq_magnetometer_interference.hpp b/src/components/real/aocs/mtq_magnetometer_interference.hpp index fea4824eb..67c5f0863 100644 --- a/src/components/real/aocs/mtq_magnetometer_interference.hpp +++ b/src/components/real/aocs/mtq_magnetometer_interference.hpp @@ -9,6 +9,8 @@ #include "magnetometer.hpp" #include "magnetorquer.hpp" +namespace s2e::components { + /** * @class MtqMagnetometerInterference * @brief Class for MTQ Magnetometer interference @@ -38,4 +40,6 @@ class MtqMagnetometerInterference { const Magnetorquer& magnetorquer_; //!< Magnetorquer }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_REAL_AOCS_MTQ_MAGNETOMETER_INTERFERENCE_HPP_ diff --git a/src/components/real/aocs/reaction_wheel.cpp b/src/components/real/aocs/reaction_wheel.cpp index 54ab6149e..9cdbac455 100644 --- a/src/components/real/aocs/reaction_wheel.cpp +++ b/src/components/real/aocs/reaction_wheel.cpp @@ -11,7 +11,9 @@ #include #include -ReactionWheel::ReactionWheel(const int prescaler, ClockGenerator* clock_generator, const int component_id, const double step_width_s, +namespace s2e::components { + +ReactionWheel::ReactionWheel(const int prescaler, environment::ClockGenerator* clock_generator, const int component_id, const double step_width_s, const double rotor_inertia_kgm2, const double max_torque_Nm, const double max_velocity_rpm, const math::Quaternion quaternion_b2c, const math::Vector<3> position_b_m, const double dead_time_s, const double time_constant_s, const std::vector friction_coefficients, @@ -38,7 +40,7 @@ ReactionWheel::ReactionWheel(const int prescaler, ClockGenerator* clock_generato Initialize(); } -ReactionWheel::ReactionWheel(const int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, +ReactionWheel::ReactionWheel(const int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, const double step_width_s, const double rotor_inertia_kgm2, const double max_torque_Nm, const double max_velocity_rpm, const math::Quaternion quaternion_b2c, const math::Vector<3> position_b_m, const double dead_time_s, const double time_constant_s, const std::vector friction_coefficients, @@ -196,15 +198,15 @@ std::string ReactionWheel::GetLogHeader() const { std::string str_tmp = ""; std::string component_name = "rw" + std::to_string(static_cast(component_id_)) + "_"; - str_tmp += WriteScalar(component_name + "angular_velocity", "rad/s"); - str_tmp += WriteScalar(component_name + "angular_velocity", "rpm"); - str_tmp += WriteScalar(component_name + "angular_velocity_upper_limit", "rpm"); - str_tmp += WriteScalar(component_name + "target_angular_acceleration", "rad/s2"); - str_tmp += WriteScalar(component_name + "angular_acceleration", "rad/s2"); + str_tmp += logger::WriteScalar(component_name + "angular_velocity", "rad/s"); + str_tmp += logger::WriteScalar(component_name + "angular_velocity", "rpm"); + str_tmp += logger::WriteScalar(component_name + "angular_velocity_upper_limit", "rpm"); + str_tmp += logger::WriteScalar(component_name + "target_angular_acceleration", "rad/s2"); + str_tmp += logger::WriteScalar(component_name + "angular_acceleration", "rad/s2"); if (is_logged_jitter_ && is_calculated_jitter_) { - str_tmp += WriteVector(component_name + "jitter_force", "c", "N", 3); - str_tmp += WriteVector(component_name + "jitter_torque", "c", "Nm", 3); + str_tmp += logger::WriteVector(component_name + "jitter_force", "c", "N", 3); + str_tmp += logger::WriteVector(component_name + "jitter_torque", "c", "Nm", 3); } return str_tmp; @@ -213,15 +215,15 @@ std::string ReactionWheel::GetLogHeader() const { std::string ReactionWheel::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteScalar(angular_velocity_rad_s_); - str_tmp += WriteScalar(angular_velocity_rpm_); - str_tmp += WriteScalar(velocity_limit_rpm_); - str_tmp += WriteScalar(target_acceleration_rad_s2_); - str_tmp += WriteScalar(generated_angular_acceleration_rad_s2_); + str_tmp += logger::WriteScalar(angular_velocity_rad_s_); + str_tmp += logger::WriteScalar(angular_velocity_rpm_); + str_tmp += logger::WriteScalar(velocity_limit_rpm_); + str_tmp += logger::WriteScalar(target_acceleration_rad_s2_); + str_tmp += logger::WriteScalar(generated_angular_acceleration_rad_s2_); if (is_logged_jitter_ && is_calculated_jitter_) { - str_tmp += WriteVector(rw_jitter_.GetJitterForce_c_N()); - str_tmp += WriteVector(rw_jitter_.GetJitterTorque_c_Nm()); + str_tmp += logger::WriteVector(rw_jitter_.GetJitterForce_c_N()); + str_tmp += logger::WriteVector(rw_jitter_.GetJitterTorque_c_Nm()); } return str_tmp; @@ -258,7 +260,7 @@ ReactionWheelJitter rw_jitter; void InitParams(int actuator_id, std::string file_name, double compo_update_step_s) { // Access Parameters - IniAccess rw_ini_file(file_name); + setting_file_reader::IniAccess rw_ini_file(file_name); std::string section_tmp = "REACTION_WHEEL_" + std::to_string(static_cast(actuator_id)); const char* rw_section = section_tmp.c_str(); @@ -314,8 +316,8 @@ void InitParams(int actuator_id, std::string file_name, double compo_update_step std::string radial_force_harmonics_coefficient_path = rw_ini_file.ReadString(jitter_section, "radial_force_harmonics_coefficient_file"); std::string radial_torque_harmonics_coefficient_path = rw_ini_file.ReadString(jitter_section, "radial_torque_harmonics_coefficient_file"); int harmonics_degree = rw_ini_file.ReadInt(jitter_section, "harmonics_degree"); - IniAccess conf_radial_force_harmonics(radial_force_harmonics_coefficient_path); - IniAccess conf_radial_torque_harmonics(radial_torque_harmonics_coefficient_path); + setting_file_reader::IniAccess conf_radial_force_harmonics(radial_force_harmonics_coefficient_path); + setting_file_reader::IniAccess conf_radial_torque_harmonics(radial_torque_harmonics_coefficient_path); std::vector> radial_force_harmonics_coefficients; std::vector> radial_torque_harmonics_coefficients; conf_radial_force_harmonics.ReadCsvDouble(radial_force_harmonics_coefficients, harmonics_degree); @@ -331,7 +333,7 @@ void InitParams(int actuator_id, std::string file_name, double compo_update_step } } // namespace -ReactionWheel InitReactionWheel(ClockGenerator* clock_generator, int actuator_id, std::string file_name, double compo_update_step_s) { +ReactionWheel InitReactionWheel(environment::ClockGenerator* clock_generator, int actuator_id, std::string file_name, double compo_update_step_s) { InitParams(actuator_id, file_name, compo_update_step_s); ReactionWheel rw(prescaler, clock_generator, actuator_id, step_width_s, rotor_inertia_kgm2, max_torque_Nm, max_velocity_rpm, quaternion_b2c, @@ -341,7 +343,7 @@ ReactionWheel InitReactionWheel(ClockGenerator* clock_generator, int actuator_id return rw; } -ReactionWheel InitReactionWheel(ClockGenerator* clock_generator, PowerPort* power_port, int actuator_id, std::string file_name, +ReactionWheel InitReactionWheel(environment::ClockGenerator* clock_generator, PowerPort* power_port, int actuator_id, std::string file_name, double compo_update_step_s) { InitParams(actuator_id, file_name, compo_update_step_s); @@ -353,3 +355,5 @@ ReactionWheel InitReactionWheel(ClockGenerator* clock_generator, PowerPort* powe return rw; } + +} // namespace s2e::components diff --git a/src/components/real/aocs/reaction_wheel.hpp b/src/components/real/aocs/reaction_wheel.hpp index e9cde9dd6..39965a692 100644 --- a/src/components/real/aocs/reaction_wheel.hpp +++ b/src/components/real/aocs/reaction_wheel.hpp @@ -17,12 +17,14 @@ #include "reaction_wheel_jitter.hpp" #include "reaction_wheel_ode.hpp" +namespace s2e::components { + /* * @class ReactionWheel * @brief Class to emulate Reaction Wheel * @note For one reaction wheel */ -class ReactionWheel : public Component, public ILoggable { +class ReactionWheel : public Component, public logger::ILoggable { public: /** * @fn ReactionWheel @@ -48,7 +50,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, ClockGenerator* clock_generator, const int component_id, const double step_width_s, + ReactionWheel(const int prescaler, environment::ClockGenerator* clock_generator, const int component_id, const double step_width_s, const double rotor_inertia_kgm2, const double max_torque_Nm, const double max_velocity_rpm, const math::Quaternion quaternion_b2c, const math::Vector<3> position_b_m, const double dead_time_s, const double time_constant_s, const std::vector friction_coefficients, const double stop_limit_angular_velocity_rad_s, const bool is_calc_jitter_enabled, @@ -78,9 +80,9 @@ 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, ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, const double step_width_s, - const double rotor_inertia_kgm2, const double max_torque_Nm, const double max_velocity_rpm, const math::Quaternion quaternion_b2c, - const math::Vector<3> position_b_m, const double dead_time_s, const double time_constant_s, + ReactionWheel(const int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, + const double step_width_s, const double rotor_inertia_kgm2, const double max_torque_Nm, const double max_velocity_rpm, + const math::Quaternion quaternion_b2c, const math::Vector<3> position_b_m, const double dead_time_s, const double time_constant_s, const std::vector friction_coefficients, const double stop_limit_angular_velocity_rad_s, const bool is_calc_jitter_enabled, const bool is_log_jitter_enabled, const int fast_prescaler, ReactionWheelJitter& rw_jitter, const bool drive_flag = false, const double init_velocity_rad_s = 0.0); @@ -102,15 +104,15 @@ class ReactionWheel : public Component, public ILoggable { */ void FastUpdate() override; - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const override; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const override; @@ -232,7 +234,7 @@ class ReactionWheel : public Component, public ILoggable { * @param [in] file_name: Path to the initialize file * @param [in] compo_update_step_s: Component step time [sec] */ -ReactionWheel InitReactionWheel(ClockGenerator* clock_generator, int actuator_id, std::string file_name, double compo_update_step_s); +ReactionWheel InitReactionWheel(environment::ClockGenerator* clock_generator, int actuator_id, std::string file_name, double compo_update_step_s); /** * @fn InitReactionWheel * @brief Initialize functions for reaction wheel with power port @@ -243,7 +245,9 @@ ReactionWheel InitReactionWheel(ClockGenerator* clock_generator, int actuator_id * @param [in] prop_step: Propagation step for RW dynamics [sec] * @param [in] compo_update_step_s: Component step time [sec] */ -ReactionWheel InitReactionWheel(ClockGenerator* clock_generator, PowerPort* power_port, int actuator_id, std::string file_name, +ReactionWheel InitReactionWheel(environment::ClockGenerator* clock_generator, PowerPort* power_port, int actuator_id, std::string file_name, double compo_update_step_s); +} // namespace s2e::components + #endif // S2E_COMPONENTS_REAL_AOCS_REACTION_WHEEL_HPP_ diff --git a/src/components/real/aocs/reaction_wheel_jitter.cpp b/src/components/real/aocs/reaction_wheel_jitter.cpp index 189e364f7..c7edc497f 100644 --- a/src/components/real/aocs/reaction_wheel_jitter.cpp +++ b/src/components/real/aocs/reaction_wheel_jitter.cpp @@ -9,6 +9,8 @@ #include #include +namespace s2e::components { + ReactionWheelJitter::ReactionWheelJitter(std::vector> radial_force_harmonics_coefficients, std::vector> radial_torque_harmonics_coefficients, const double update_interval_s, const math::Quaternion quaternion_b2c, const double structural_resonance_frequency_Hz, @@ -126,3 +128,5 @@ void ReactionWheelJitter::CalcCoefficients() { coefficients_[5] = 4.0 - 4.0 * damping_factor_ * update_interval_s_ * structural_resonance_angular_frequency_Hz_ + pow(update_interval_s_, 2.0) * pow(structural_resonance_angular_frequency_Hz_, 2.0); } + +} // namespace s2e::components diff --git a/src/components/real/aocs/reaction_wheel_jitter.hpp b/src/components/real/aocs/reaction_wheel_jitter.hpp index dbf2e24c5..f926754dd 100644 --- a/src/components/real/aocs/reaction_wheel_jitter.hpp +++ b/src/components/real/aocs/reaction_wheel_jitter.hpp @@ -11,6 +11,8 @@ #include #include +namespace s2e::components { + /* * @class ReactionWheelJitter * @brief Class to calculate RW high-frequency jitter effect @@ -128,4 +130,6 @@ class ReactionWheelJitter { void CalcCoefficients(); }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_REAL_AOCS_REACTION_WHEEL_JITTER_HPP_ diff --git a/src/components/real/aocs/reaction_wheel_ode.cpp b/src/components/real/aocs/reaction_wheel_ode.cpp index 48b440089..fa5b1ac69 100644 --- a/src/components/real/aocs/reaction_wheel_ode.cpp +++ b/src/components/real/aocs/reaction_wheel_ode.cpp @@ -6,6 +6,8 @@ #include +namespace s2e::components { + ReactionWheelOde::ReactionWheelOde(const double step_width_s, const double velocity_limit_rad_s, const double initial_angular_velocity_rad_s) : OrdinaryDifferentialEquation<1>(step_width_s), velocity_limit_rad_s_(velocity_limit_rad_s) { this->Setup(0.0, math::Vector<1>(initial_angular_velocity_rad_s)); @@ -28,3 +30,5 @@ void ReactionWheelOde::DerivativeFunction(double x, const math::Vector<1> &state rhs[0] = angular_acceleration_rad_s2_; } + +} // namespace s2e::components diff --git a/src/components/real/aocs/reaction_wheel_ode.hpp b/src/components/real/aocs/reaction_wheel_ode.hpp index 89bec07c3..13c0b26f2 100644 --- a/src/components/real/aocs/reaction_wheel_ode.hpp +++ b/src/components/real/aocs/reaction_wheel_ode.hpp @@ -8,6 +8,8 @@ #include +namespace s2e::components { + /* * @file ReactionWheelOde * @brief Ordinary differential equation of angular velocity of reaction wheel with first-order lag @@ -59,4 +61,6 @@ class ReactionWheelOde : public math::OrdinaryDifferentialEquation<1> { double angular_acceleration_rad_s2_ = 0.0; //!< Angular acceleration [rad/s2] }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_REAL_AOCS_REACTION_WHEEL_ODE_HPP_ diff --git a/src/components/real/aocs/star_sensor.cpp b/src/components/real/aocs/star_sensor.cpp index 60a10d7a5..1ce9315a3 100644 --- a/src/components/real/aocs/star_sensor.cpp +++ b/src/components/real/aocs/star_sensor.cpp @@ -14,19 +14,22 @@ #include using namespace std; -using namespace math; +using namespace s2e::math; -StarSensor::StarSensor(const int prescaler, ClockGenerator* clock_generator, const int component_id, const math::Quaternion& quaternion_b2c, - const double standard_deviation_orthogonal_direction, const double standard_deviation_sight_direction, - const double step_time_s, const unsigned int output_delay, const unsigned int output_interval, - const double sun_forbidden_angle_rad, const double earth_forbidden_angle_rad, const double moon_forbidden_angle_rad, - const double capture_rate_limit_rad_s, const Dynamics* dynamics, const LocalEnvironment* local_environment) +namespace s2e::components { + +StarSensor::StarSensor(const int prescaler, environment::ClockGenerator* clock_generator, const int component_id, + const math::Quaternion& quaternion_b2c, const double standard_deviation_orthogonal_direction, + const double standard_deviation_sight_direction, const double step_time_s, const unsigned int output_delay, + const unsigned int output_interval, const double sun_forbidden_angle_rad, const double earth_forbidden_angle_rad, + const double moon_forbidden_angle_rad, const double capture_rate_limit_rad_s, const dynamics::Dynamics* dynamics, + const environment::LocalEnvironment* local_environment) : Component(prescaler, clock_generator), component_id_(component_id), quaternion_b2c_(quaternion_b2c), - rotation_noise_(global_randomization.MakeSeed()), - orthogonal_direction_noise_(0.0, standard_deviation_orthogonal_direction, global_randomization.MakeSeed()), - sight_direction_noise_(0.0, standard_deviation_sight_direction, global_randomization.MakeSeed()), + rotation_noise_(randomization::global_randomization.MakeSeed()), + orthogonal_direction_noise_(0.0, standard_deviation_orthogonal_direction, randomization::global_randomization.MakeSeed()), + sight_direction_noise_(0.0, standard_deviation_sight_direction, randomization::global_randomization.MakeSeed()), buffer_position_(0), step_time_s_(step_time_s), output_delay_(output_delay), @@ -40,18 +43,18 @@ StarSensor::StarSensor(const int prescaler, ClockGenerator* clock_generator, con local_environment_(local_environment) { Initialize(); } -StarSensor::StarSensor(const int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, +StarSensor::StarSensor(const int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, const math::Quaternion& quaternion_b2c, const double standard_deviation_orthogonal_direction, const double standard_deviation_sight_direction, const double step_time_s, const unsigned int output_delay, const unsigned int output_interval, const double sun_forbidden_angle_rad, const double earth_forbidden_angle_rad, - const double moon_forbidden_angle_rad, const double capture_rate_limit_rad_s, const Dynamics* dynamics, - const LocalEnvironment* local_environment) + const double moon_forbidden_angle_rad, const double capture_rate_limit_rad_s, const dynamics::Dynamics* dynamics, + const environment::LocalEnvironment* local_environment) : Component(prescaler, clock_generator, power_port), component_id_(component_id), quaternion_b2c_(quaternion_b2c), - rotation_noise_(global_randomization.MakeSeed()), - orthogonal_direction_noise_(0.0, standard_deviation_orthogonal_direction, global_randomization.MakeSeed()), - sight_direction_noise_(0.0, standard_deviation_sight_direction, global_randomization.MakeSeed()), + rotation_noise_(randomization::global_randomization.MakeSeed()), + orthogonal_direction_noise_(0.0, standard_deviation_orthogonal_direction, randomization::global_randomization.MakeSeed()), + sight_direction_noise_(0.0, standard_deviation_sight_direction, randomization::global_randomization.MakeSeed()), buffer_position_(0), step_time_s_(step_time_s), output_delay_(output_delay), @@ -88,7 +91,8 @@ void StarSensor::Initialize() { error_flag_ = true; } -Quaternion StarSensor::Measure(const LocalCelestialInformation* local_celestial_information, const Attitude* attitude) { +Quaternion StarSensor::Measure(const environment::LocalCelestialInformation* local_celestial_information, + const dynamics::attitude::Attitude* attitude) { update(local_celestial_information, attitude); // update delay buffer if (update_count_ == 0) { int hist = buffer_position_ - output_delay_ - 1; @@ -104,7 +108,7 @@ Quaternion StarSensor::Measure(const LocalCelestialInformation* local_celestial_ return measured_quaternion_i2c_; } -void StarSensor::update(const LocalCelestialInformation* local_celestial_information, const Attitude* attitude) { +void StarSensor::update(const environment::LocalCelestialInformation* local_celestial_information, const dynamics::attitude::Attitude* attitude) { Quaternion quaternion_i2b = attitude->GetQuaternion_i2b(); // Read true value Quaternion q_stt_temp = quaternion_i2b * quaternion_b2c_; // Convert to component frame // Add noise on sight direction @@ -125,7 +129,8 @@ void StarSensor::update(const LocalCelestialInformation* local_celestial_informa buffer_position_ %= max_delay_; } -void StarSensor::AllJudgement(const LocalCelestialInformation* local_celestial_information, const Attitude* attitude) { +void StarSensor::AllJudgement(const environment::LocalCelestialInformation* local_celestial_information, + const dynamics::attitude::Attitude* attitude) { int judgement = 0; judgement = SunJudgement(local_celestial_information->GetPositionFromSpacecraft_b_m("SUN")); judgement += EarthJudgement(local_celestial_information->GetPositionFromSpacecraft_b_m("EARTH")); @@ -183,8 +188,8 @@ std::string StarSensor::GetLogHeader() const { const std::string sensor_id = std::to_string(static_cast(component_id_)); std::string sensor_name = "stt" + sensor_id + "_"; - str_tmp += WriteQuaternion(sensor_name + "measured_quaternion", "i2c"); - str_tmp += WriteScalar(sensor_name + "error_flag"); + str_tmp += logger::WriteQuaternion(sensor_name + "measured_quaternion", "i2c"); + str_tmp += logger::WriteScalar(sensor_name + "error_flag"); return str_tmp; } @@ -192,8 +197,8 @@ std::string StarSensor::GetLogHeader() const { std::string StarSensor::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteQuaternion(measured_quaternion_i2c_); - str_tmp += WriteScalar(double(error_flag_)); + str_tmp += logger::WriteQuaternion(measured_quaternion_i2c_); + str_tmp += logger::WriteScalar(double(error_flag_)); return str_tmp; } @@ -213,9 +218,9 @@ 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); +StarSensor InitStarSensor(environment::ClockGenerator* clock_generator, int sensor_id, const string file_name, double component_step_time_s, + const dynamics::Dynamics* dynamics, const environment::LocalEnvironment* local_environment) { + setting_file_reader::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(); @@ -246,9 +251,9 @@ StarSensor InitStarSensor(ClockGenerator* clock_generator, int sensor_id, const 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); +StarSensor InitStarSensor(environment::ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const string file_name, + double component_step_time_s, const dynamics::Dynamics* dynamics, const environment::LocalEnvironment* local_environment) { + setting_file_reader::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(); @@ -281,3 +286,5 @@ StarSensor InitStarSensor(ClockGenerator* clock_generator, PowerPort* power_port moon_forbidden_angle_rad, capture_rate_rad_s, dynamics, local_environment); return stt; } + +} // namespace s2e::components diff --git a/src/components/real/aocs/star_sensor.hpp b/src/components/real/aocs/star_sensor.hpp index 5965c5e9a..0f3f7e321 100644 --- a/src/components/real/aocs/star_sensor.hpp +++ b/src/components/real/aocs/star_sensor.hpp @@ -18,11 +18,13 @@ #include "../../base/component.hpp" #include "dynamics/dynamics.hpp" +namespace s2e::components { + /* * @class StarSensor * @brief Class to emulate star tracker */ -class StarSensor : public Component, public ILoggable { +class StarSensor : public Component, public logger::ILoggable { public: /** * @fn StarSensor @@ -43,11 +45,11 @@ class StarSensor : public Component, public ILoggable { * @param [in] dynamics: Dynamics information * @param [in] local_environment: Local environment information */ - StarSensor(const int prescaler, ClockGenerator* clock_generator, const int component_id, const math::Quaternion& quaternion_b2c, + StarSensor(const int prescaler, environment::ClockGenerator* clock_generator, const int component_id, const math::Quaternion& quaternion_b2c, const double standard_deviation_orthogonal_direction, const double standard_deviation_sight_direction, const double step_time_s, const unsigned int output_delay, const unsigned int output_interval, const double sun_forbidden_angle_rad, const double earth_forbidden_angle_rad, const double moon_forbidden_angle_rad, const double capture_rate_limit_rad_s, - const Dynamics* dynamics, const LocalEnvironment* local_environment); + const dynamics::Dynamics* dynamics, const environment::LocalEnvironment* local_environment); /** * @fn StarSensor * @brief Constructor with power port @@ -68,12 +70,12 @@ class StarSensor : public Component, public ILoggable { * @param [in] dynamics: Dynamics information * @param [in] local_environment: Local environment information */ - StarSensor(const int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, + StarSensor(const int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, const math::Quaternion& quaternion_b2c, const double standard_deviation_orthogonal_direction, const double standard_deviation_sight_direction, const double step_time_s, const unsigned int output_delay, const unsigned int output_interval, const double sun_forbidden_angle_rad, const double earth_forbidden_angle_rad, - const double moon_forbidden_angle_rad, const double capture_rate_limit_rad_s, const Dynamics* dynamics, - const LocalEnvironment* local_environment); + const double moon_forbidden_angle_rad, const double capture_rate_limit_rad_s, const dynamics::Dynamics* dynamics, + const environment::LocalEnvironment* local_environment); // Override functions for Component /** @@ -82,15 +84,15 @@ class StarSensor : public Component, public ILoggable { */ void MainRoutine(const int time_count) override; - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const override; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const override; @@ -136,32 +138,32 @@ class StarSensor : public Component, public ILoggable { double capture_rate_limit_rad_s_; //!< Angular rate limit to get correct attitude [rad/s] // Observed variables - const Dynamics* dynamics_; //!< Dynamics information - const LocalEnvironment* local_environment_; //!< Local environment information + const dynamics::Dynamics* dynamics_; //!< Dynamics information + const environment::LocalEnvironment* local_environment_; //!< Local environment information // Internal functions /** * @fn update * @brief Update delay buffer * @param [in] local_celestial_information: Local celestial information - * @param [in] attitude: Attitude information + * @param [in] attitude: dynamics::attitude::Attitude information */ - void update(const LocalCelestialInformation* local_celestial_information, const Attitude* attitude); + void update(const environment::LocalCelestialInformation* local_celestial_information, const dynamics::attitude::Attitude* attitude); /** * @fn Measure * @brief Calculate measured quaternion * @param [in] local_celestial_information: Local celestial information - * @param [in] attitude: Attitude information + * @param [in] attitude: dynamics::attitude::Attitude information */ - math::Quaternion Measure(const LocalCelestialInformation* local_celestial_information, const Attitude* attitude); + math::Quaternion Measure(const environment::LocalCelestialInformation* local_celestial_information, const dynamics::attitude::Attitude* attitude); /** * @fn AllJudgement * @brief Calculate all error judgement * @param [in] local_celestial_information: Local celestial information - * @param [in] attitude: Attitude information + * @param [in] attitude: dynamics::attitude::Attitude information */ - void AllJudgement(const LocalCelestialInformation* local_celestial_information, const Attitude* attitude); + void AllJudgement(const environment::LocalCelestialInformation* local_celestial_information, const dynamics::attitude::Attitude* attitude); /** * @fn SunJudgement * @brief Judge violation of sun forbidden angle @@ -216,8 +218,8 @@ class StarSensor : public Component, public ILoggable { * @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); +StarSensor InitStarSensor(environment::ClockGenerator* clock_generator, int sensor_id, const std::string file_name, double component_step_time_s, + const dynamics::Dynamics* dynamics, const environment::LocalEnvironment* local_environment); /** * @fn InitStarSensor * @brief Initialize functions for StarSensor with power port @@ -229,7 +231,9 @@ StarSensor InitStarSensor(ClockGenerator* clock_generator, int sensor_id, const * @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); +StarSensor InitStarSensor(environment::ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const std::string file_name, + double component_step_time_s, const dynamics::Dynamics* dynamics, const environment::LocalEnvironment* local_environment); + +} // namespace s2e::components #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 6b47949ae..3745d99b7 100644 --- a/src/components/real/aocs/sun_sensor.cpp +++ b/src/components/real/aocs/sun_sensor.cpp @@ -5,19 +5,21 @@ #include "sun_sensor.hpp" -#include -#include -using randomization::NormalRand; #include +#include #include +#include #include using namespace std; -SunSensor::SunSensor(const int prescaler, ClockGenerator* clock_generator, const int component_id, const math::Quaternion& quaternion_b2c, - const double detectable_angle_rad, const double random_noise_standard_deviation_rad, +namespace s2e::components { + +SunSensor::SunSensor(const int prescaler, environment::ClockGenerator* clock_generator, const int component_id, + const math::Quaternion& quaternion_b2c, const double detectable_angle_rad, const double random_noise_standard_deviation_rad, const double bias_noise_standard_deviation_rad, const double intensity_lower_threshold_percent, - const SolarRadiationPressureEnvironment* srp_environment, const LocalCelestialInformation* local_celestial_information) + const environment::SolarRadiationPressureEnvironment* srp_environment, + const environment::LocalCelestialInformation* local_celestial_information) : Component(prescaler, clock_generator), component_id_(component_id), quaternion_b2c_(quaternion_b2c), @@ -28,10 +30,11 @@ SunSensor::SunSensor(const int prescaler, ClockGenerator* clock_generator, const Initialize(random_noise_standard_deviation_rad, bias_noise_standard_deviation_rad); } -SunSensor::SunSensor(const int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, +SunSensor::SunSensor(const int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, const math::Quaternion& quaternion_b2c, const double detectable_angle_rad, const double random_noise_standard_deviation_rad, const double bias_noise_standard_deviation_rad, const double intensity_lower_threshold_percent, - const SolarRadiationPressureEnvironment* srp_environment, const LocalCelestialInformation* local_celestial_information) + const environment::SolarRadiationPressureEnvironment* srp_environment, + const environment::LocalCelestialInformation* local_celestial_information) : Component(prescaler, clock_generator, power_port), component_id_(component_id), quaternion_b2c_(quaternion_b2c), @@ -44,7 +47,7 @@ SunSensor::SunSensor(const int prescaler, ClockGenerator* clock_generator, Power void SunSensor::Initialize(const double random_noise_standard_deviation_rad, const double bias_noise_standard_deviation_rad) { // Bias - NormalRand nr(0.0, bias_noise_standard_deviation_rad, global_randomization.MakeSeed()); + randomization::NormalRand nr(0.0, bias_noise_standard_deviation_rad, randomization::global_randomization.MakeSeed()); bias_noise_alpha_rad_ += nr; bias_noise_beta_rad_ += nr; @@ -136,8 +139,8 @@ string SunSensor::GetLogHeader() const { const string sensor_id = std::to_string(static_cast(component_id_)); std::string sensor_name = "sun_sensor" + sensor_id + "_"; - str_tmp += WriteVector(sensor_name + "measured_sun_direction", "c", "-", 3); - str_tmp += WriteScalar(sensor_name + "sun_detected_flag", "-"); + str_tmp += logger::WriteVector(sensor_name + "measured_sun_direction", "c", "-", 3); + str_tmp += logger::WriteScalar(sensor_name + "sun_detected_flag", "-"); return str_tmp; } @@ -145,15 +148,16 @@ string SunSensor::GetLogHeader() const { string SunSensor::GetLogValue() const { string str_tmp = ""; - str_tmp += WriteVector(measured_sun_direction_c_); - str_tmp += WriteScalar(double(sun_detected_flag_)); + str_tmp += logger::WriteVector(measured_sun_direction_c_); + str_tmp += logger::WriteScalar(double(sun_detected_flag_)); 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); +SunSensor InitSunSensor(environment::ClockGenerator* clock_generator, int ss_id, std::string file_name, + const environment::SolarRadiationPressureEnvironment* srp_environment, + const environment::LocalCelestialInformation* local_celestial_information) { + setting_file_reader::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(); @@ -184,9 +188,10 @@ SunSensor InitSunSensor(ClockGenerator* clock_generator, int ss_id, std::string 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); +SunSensor InitSunSensor(environment::ClockGenerator* clock_generator, PowerPort* power_port, int ss_id, std::string file_name, + const environment::SolarRadiationPressureEnvironment* srp_environment, + const environment::LocalCelestialInformation* local_celestial_information) { + setting_file_reader::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(); @@ -218,3 +223,5 @@ SunSensor InitSunSensor(ClockGenerator* clock_generator, PowerPort* power_port, intensity_lower_threshold_percent, srp_environment, local_celestial_information); return ss; } + +} // namespace s2e::components diff --git a/src/components/real/aocs/sun_sensor.hpp b/src/components/real/aocs/sun_sensor.hpp index e2c9623fd..33dd9c5fd 100644 --- a/src/components/real/aocs/sun_sensor.hpp +++ b/src/components/real/aocs/sun_sensor.hpp @@ -15,11 +15,13 @@ #include "../../base/component.hpp" +namespace s2e::components { + /* * @class SunSensor * @brief Class to emulate sun sensor */ -class SunSensor : public Component, public ILoggable { +class SunSensor : public Component, public logger::ILoggable { public: /** * @fn SunSensor @@ -35,10 +37,10 @@ class SunSensor : public Component, public ILoggable { * @param [in] srp_environment: Solar Radiation Pressure environment * @param [in] local_celestial_information: Local celestial information */ - SunSensor(const int prescaler, ClockGenerator* clock_generator, const int component_id, const math::Quaternion& quaternion_b2c, + SunSensor(const int prescaler, environment::ClockGenerator* clock_generator, const int component_id, const math::Quaternion& quaternion_b2c, const double detectable_angle_rad, const double random_noise_standard_deviation_rad, const double bias_noise_standard_deviation_rad, - const double intensity_lower_threshold_percent, const SolarRadiationPressureEnvironment* srp_environment, - const LocalCelestialInformation* local_celestial_information); + const double intensity_lower_threshold_percent, const environment::SolarRadiationPressureEnvironment* srp_environment, + const environment::LocalCelestialInformation* local_celestial_information); /** * @fn SunSensor * @brief Constructor with power port @@ -54,10 +56,11 @@ class SunSensor : public Component, public ILoggable { * @param [in] srp_environment: Solar Radiation Pressure environment * @param [in] local_celestial_information: Local celestial information */ - SunSensor(const int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, + SunSensor(const int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, const math::Quaternion& quaternion_b2c, const double detectable_angle_rad, const double random_noise_standard_deviation_rad, const double bias_noise_standard_deviation_rad, const double intensity_lower_threshold_percent, - const SolarRadiationPressureEnvironment* srp_environment, const LocalCelestialInformation* local_celestial_information); + const environment::SolarRadiationPressureEnvironment* srp_environment, + const environment::LocalCelestialInformation* local_celestial_information); // Override functions for Component /** @@ -66,15 +69,15 @@ class SunSensor : public Component, public ILoggable { */ void MainRoutine(const int time_count) override; - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const override; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const override; @@ -102,12 +105,12 @@ class SunSensor : public Component, public ILoggable { // Noise parameters randomization::NormalRand random_noise_alpha_; //!< Normal random for alpha angle randomization::NormalRand random_noise_beta_; //!< Normal random for beta angle - double bias_noise_alpha_rad_ = 0.0; //!< Constant bias for alpha angle (Value is calculated by random number generator) - double bias_noise_beta_rad_ = 0.0; //!< Constant bias for beta angle (Value is calculated by random number generator) + double bias_noise_alpha_rad_ = 0.0; //!< Constant bias for alpha angle (Value is calculated by random number generator) + double bias_noise_beta_rad_ = 0.0; //!< Constant bias for beta angle (Value is calculated by random number generator) // Measured variables - const SolarRadiationPressureEnvironment* srp_environment_; //!< Solar Radiation Pressure environment - const LocalCelestialInformation* local_celestial_information_; //!< Local celestial information + const environment::SolarRadiationPressureEnvironment* srp_environment_; //!< Solar Radiation Pressure environment + const environment::LocalCelestialInformation* local_celestial_information_; //!< Local celestial information // functions /** @@ -150,8 +153,9 @@ class SunSensor : public Component, public ILoggable { * @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); +SunSensor InitSunSensor(environment::ClockGenerator* clock_generator, int sensor_id, const std::string file_name, + const environment::SolarRadiationPressureEnvironment* srp_environment, + const environment::LocalCelestialInformation* local_celestial_information); /** * @fn InitSunSensor * @brief Initialize functions for sun sensor with power port @@ -162,7 +166,10 @@ SunSensor InitSunSensor(ClockGenerator* clock_generator, int sensor_id, const st * @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); +SunSensor InitSunSensor(environment::ClockGenerator* clock_generator, PowerPort* power_port, int sensor_id, const std::string file_name, + const environment::SolarRadiationPressureEnvironment* srp_environment, + const environment::LocalCelestialInformation* local_celestial_information); + +} // namespace s2e::components #endif // S2E_COMPONENTS_REAL_AOCS_SUN_SENSOR_HPP_ diff --git a/src/components/real/cdh/c2a_communication.hpp b/src/components/real/cdh/c2a_communication.hpp index c749d90e3..ea7afef13 100644 --- a/src/components/real/cdh/c2a_communication.hpp +++ b/src/components/real/cdh/c2a_communication.hpp @@ -6,6 +6,8 @@ #ifndef C2A_COMMUNICATION_H_ #define C2A_COMMUNICATION_H_ +namespace s2e::components { + // If the character encoding of C2A is UTF-8, the following functions are not necessary, // and users can directory use SendFromObc_C2A and ReceivedByObc_C2A UART // TODO: Delete these functions since C2A is changed to use UTF-8 @@ -23,4 +25,6 @@ int OBC_C2A_I2cReadRegister(int port_id, const unsigned char i2c_address, unsign int OBC_C2A_GpioWrite(int port_id, const bool is_high); bool OBC_C2A_GpioRead(int port_id); // return false when the port_id is not used +} // namespace s2e::components + #endif // C2A_COMMUNICATION_H_ diff --git a/src/components/real/cdh/on_board_computer.cpp b/src/components/real/cdh/on_board_computer.cpp index ad23fadf4..c661fc6d6 100644 --- a/src/components/real/cdh/on_board_computer.cpp +++ b/src/components/real/cdh/on_board_computer.cpp @@ -4,14 +4,16 @@ */ #include "on_board_computer.hpp" -OnBoardComputer::OnBoardComputer(ClockGenerator* clock_generator) : Component(1, clock_generator) { Initialize(); } +namespace s2e::components { -OnBoardComputer::OnBoardComputer(int prescaler, ClockGenerator* clock_generator, PowerPort* power_port) +OnBoardComputer::OnBoardComputer(environment::ClockGenerator* clock_generator) : Component(1, clock_generator) { Initialize(); } + +OnBoardComputer::OnBoardComputer(int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port) : Component(prescaler, clock_generator, power_port) { Initialize(); } -OnBoardComputer::OnBoardComputer(int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, const double minimum_voltage_V, +OnBoardComputer::OnBoardComputer(int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, const double minimum_voltage_V, const double assumed_power_consumption_W) : Component(prescaler, clock_generator, power_port) { power_port_->SetMinimumVoltage_V(minimum_voltage_V); @@ -132,3 +134,5 @@ bool OnBoardComputer::GpioComponentRead(int port_id) { if (port == nullptr) return false; return port->DigitalRead(); } + +} // namespace s2e::components diff --git a/src/components/real/cdh/on_board_computer.hpp b/src/components/real/cdh/on_board_computer.hpp index 641f1566c..123066539 100644 --- a/src/components/real/cdh/on_board_computer.hpp +++ b/src/components/real/cdh/on_board_computer.hpp @@ -13,6 +13,8 @@ #include "../../base/component.hpp" +namespace s2e::components { + /* * @class OnBoardComputer * @brief Class to emulate on board computer @@ -25,7 +27,7 @@ class OnBoardComputer : public Component { * @brief Constructor * @param [in] clock_generator: Clock generator */ - OnBoardComputer(ClockGenerator* clock_generator); + OnBoardComputer(environment::ClockGenerator* clock_generator); /** * @fn OnBoardComputer * @brief Constructor @@ -33,7 +35,7 @@ class OnBoardComputer : public Component { * @param [in] clock_generator: Clock generator * @param [in] power_port: Power port */ - OnBoardComputer(int prescaler, ClockGenerator* clock_generator, PowerPort* power_port); + OnBoardComputer(int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port); /** * @fn OnBoardComputer * @brief Constructor @@ -43,7 +45,7 @@ class OnBoardComputer : public Component { * @param [in] minimum_voltage_V: Minimum voltage [V] * @param [in] assumed_power_consumption_W: Assumed power consumption [W] */ - OnBoardComputer(int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, const double minimum_voltage_V, + OnBoardComputer(int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, const double minimum_voltage_V, const double assumed_power_consumption_W); /** * @fn ~OnBoardComputer @@ -207,4 +209,6 @@ class OnBoardComputer : public Component { std::map gpio_ports_; //!< GPIO ports }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_REAL_CDH_OBC_HPP_ diff --git a/src/components/real/cdh/on_board_computer_with_c2a.cpp b/src/components/real/cdh/on_board_computer_with_c2a.cpp index 8deb53bec..639e87f5e 100644 --- a/src/components/real/cdh/on_board_computer_with_c2a.cpp +++ b/src/components/real/cdh/on_board_computer_with_c2a.cpp @@ -26,20 +26,22 @@ #endif // c2a-core version header #endif // USE_C2A +namespace s2e::components { + std::map ObcWithC2a::com_ports_c2a_; std::map ObcWithC2a::i2c_com_ports_c2a_; std::map ObcWithC2a::gpio_ports_c2a_; -ObcWithC2a::ObcWithC2a(ClockGenerator* clock_generator) : OnBoardComputer(clock_generator), timing_regulator_(1) { +ObcWithC2a::ObcWithC2a(environment::ClockGenerator* clock_generator) : OnBoardComputer(clock_generator), timing_regulator_(1) { // Initialize(); } -ObcWithC2a::ObcWithC2a(ClockGenerator* clock_generator, int timing_regulator) +ObcWithC2a::ObcWithC2a(environment::ClockGenerator* clock_generator, int timing_regulator) : OnBoardComputer(clock_generator), timing_regulator_(timing_regulator) { // Initialize(); } -ObcWithC2a::ObcWithC2a(int prescaler, ClockGenerator* clock_generator, int timing_regulator, PowerPort* power_port) +ObcWithC2a::ObcWithC2a(int prescaler, environment::ClockGenerator* clock_generator, int timing_regulator, PowerPort* power_port) : OnBoardComputer(prescaler, clock_generator, power_port), timing_regulator_(timing_regulator) { // Initialize(); } @@ -255,4 +257,6 @@ bool ObcWithC2a::GpioRead_C2A(int port_id) { int OBC_C2A_GpioWrite(int port_id, const bool is_high) { return ObcWithC2a::GpioWrite_C2A(port_id, is_high); } -bool OBC_C2A_GpioRead(int port_id) { return ObcWithC2a::GpioRead_C2A(port_id); } \ No newline at end of file +bool OBC_C2A_GpioRead(int port_id) { return ObcWithC2a::GpioRead_C2A(port_id); } + +} // namespace s2e::components diff --git a/src/components/real/cdh/on_board_computer_with_c2a.hpp b/src/components/real/cdh/on_board_computer_with_c2a.hpp index bc9cc22e8..4b3c043aa 100644 --- a/src/components/real/cdh/on_board_computer_with_c2a.hpp +++ b/src/components/real/cdh/on_board_computer_with_c2a.hpp @@ -11,6 +11,8 @@ #include "c2a_communication.hpp" #include "on_board_computer.hpp" +namespace s2e::components { + /* * @class ObcWithC2a * @brief Class to emulate on board computer with C2A flight software @@ -22,14 +24,14 @@ class ObcWithC2a : public OnBoardComputer { * @brief Constructor * @param [in] clock_generator: Clock generator */ - ObcWithC2a(ClockGenerator* clock_generator); + ObcWithC2a(environment::ClockGenerator* clock_generator); /** * @fn ObcWithC2a * @brief Constructor * @param [in] clock_generator: Clock generator * @param [in] timing_regulator: Timing regulator to update flight software faster than the component update */ - ObcWithC2a(ClockGenerator* clock_generator, int timing_regulator); + ObcWithC2a(environment::ClockGenerator* clock_generator, int timing_regulator); /** * @fn ObcWithC2a * @brief Constructor @@ -38,7 +40,7 @@ class ObcWithC2a : public OnBoardComputer { * @param [in] timing_regulator: Timing regulator to update flight software faster than the component update * @param [in] power_port: Power port */ - ObcWithC2a(int prescaler, ClockGenerator* clock_generator, int timing_regulator, PowerPort* power_port); + ObcWithC2a(int prescaler, environment::ClockGenerator* clock_generator, int timing_regulator, PowerPort* power_port); /** * @fn ~ObcWithC2a * @brief Destructor @@ -271,4 +273,6 @@ class ObcWithC2a : public OnBoardComputer { static std::map gpio_ports_c2a_; //!< GPIO ports }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_REAL_CDH_OBC_C2A_HPP_ diff --git a/src/components/real/communication/antenna.cpp b/src/components/real/communication/antenna.cpp index b0713a76e..9d9fec92d 100644 --- a/src/components/real/communication/antenna.cpp +++ b/src/components/real/communication/antenna.cpp @@ -11,8 +11,10 @@ #include #include +namespace s2e::components { + Antenna::Antenna(const int component_id, const math::Quaternion& quaternion_b2c, const bool is_transmitter, const bool is_receiver, - const double frequency_MHz, const Vector<5> tx_parameters, const Vector<4> rx_parameters) + const double frequency_MHz, const math::Vector<5> tx_parameters, const math::Vector<4> rx_parameters) : component_id_(component_id), is_transmitter_(is_transmitter), is_receiver_(is_receiver), frequency_MHz_(frequency_MHz) { quaternion_b2c_ = quaternion_b2c; @@ -106,11 +108,11 @@ AntennaGainModel SetAntennaGainModel(const std::string gain_model_name) { } Antenna InitAntenna(const int antenna_id, const std::string file_name) { - IniAccess antenna_conf(file_name); + setting_file_reader::IniAccess antenna_conf(file_name); const std::string section_name = "ANTENNA_" + std::to_string(static_cast(antenna_id)); - Quaternion quaternion_b2c; + math::Quaternion quaternion_b2c; antenna_conf.ReadQuaternion(section_name.c_str(), "quaternion_b2c", quaternion_b2c); bool is_transmitter = antenna_conf.ReadBoolean(section_name.c_str(), "is_transmitter"); @@ -164,3 +166,5 @@ Antenna InitAntenna(const int antenna_id, const std::string file_name) { rx_system_noise_temperature_K, rx_parameters); return antenna; } + +} // namespace s2e::components diff --git a/src/components/real/communication/antenna.hpp b/src/components/real/communication/antenna.hpp index fbdaffb0a..1d317140e 100644 --- a/src/components/real/communication/antenna.hpp +++ b/src/components/real/communication/antenna.hpp @@ -8,12 +8,12 @@ #include #include -using math::Quaternion; -using math::Vector; #include #include "./antenna_radiation_pattern.hpp" +namespace s2e::components { + /* * @enum AntennaGainModel * @brief Antenna gain model definition @@ -55,7 +55,7 @@ class Antenna { * @param [in] rx_parameters: gain, loss_feeder, loss_pointing, system_temperature for RX */ Antenna(const int component_id, const math::Quaternion& quaternion_b2c, const bool is_transmitter, const bool is_receiver, - const double frequency_MHz, const Vector<5> tx_parameters, const Vector<4> rx_parameters); + const double frequency_MHz, const math::Vector<5> tx_parameters, const math::Vector<4> rx_parameters); /** * @fn Antenna @@ -113,7 +113,7 @@ class Antenna { * @fn GetQuaternion_b2c * @brief Return quaternion from body to component */ - inline Quaternion GetQuaternion_b2c() const { return quaternion_b2c_; } + inline math::Quaternion GetQuaternion_b2c() const { return quaternion_b2c_; } /** * @fn IsTransmitter @@ -128,11 +128,11 @@ class Antenna { protected: // General info - int component_id_; //!< Antenna ID - Quaternion quaternion_b2c_; //!< Coordinate transform from body to component - bool is_transmitter_; //!< Antenna for transmitter or not - bool is_receiver_; //!< Antenna for receiver or not - double frequency_MHz_; //!< Center Frequency [MHz] + int component_id_; //!< Antenna ID + math::Quaternion quaternion_b2c_; //!< Coordinate transform from body to component + bool is_transmitter_; //!< Antenna for transmitter or not + bool is_receiver_; //!< Antenna for receiver or not + double frequency_MHz_; //!< Center Frequency [MHz] // Tx info double tx_bitrate_bps_; //!< Transmit bitrate [bps] @@ -166,4 +166,6 @@ AntennaGainModel SetAntennaGainModel(const std::string gain_model_name); */ Antenna InitAntenna(const int antenna_id, const std::string file_name); +} // namespace s2e::components + #endif // S2E_COMPONENTS_REAL_COMMUNICATION_ANTENNA_HPP_ diff --git a/src/components/real/communication/antenna_radiation_pattern.cpp b/src/components/real/communication/antenna_radiation_pattern.cpp index a82929c11..b1a3bced7 100644 --- a/src/components/real/communication/antenna_radiation_pattern.cpp +++ b/src/components/real/communication/antenna_radiation_pattern.cpp @@ -9,12 +9,14 @@ #include #include +namespace s2e::components { + AntennaRadiationPattern::AntennaRadiationPattern() { gain_dBi_.assign(length_theta_, std::vector(length_phi_, 0.0)); } AntennaRadiationPattern::AntennaRadiationPattern(const std::string file_path, const size_t length_theta, const size_t length_phi, const double theta_max_rad, const double phi_max_rad) : length_theta_(length_theta), length_phi_(length_phi), theta_max_rad_(theta_max_rad), phi_max_rad_(phi_max_rad) { - IniAccess gain_file(file_path); + setting_file_reader::IniAccess gain_file(file_path); gain_file.ReadCsvDouble(gain_dBi_, (std::max)(length_theta_, length_phi_)); } @@ -37,3 +39,5 @@ double AntennaRadiationPattern::GetGain_dBi(const double theta_rad, const double return gain_dBi_[theta_idx][phi_idx]; } + +} // namespace s2e::components diff --git a/src/components/real/communication/antenna_radiation_pattern.hpp b/src/components/real/communication/antenna_radiation_pattern.hpp index 422d168ab..a6efac136 100644 --- a/src/components/real/communication/antenna_radiation_pattern.hpp +++ b/src/components/real/communication/antenna_radiation_pattern.hpp @@ -10,6 +10,8 @@ #include #include +namespace s2e::components { + /* * @class AntennaRadiationPattern * @brief Antenna radiation pattern @@ -62,4 +64,6 @@ class AntennaRadiationPattern { std::vector> gain_dBi_; //!< Antenna gain table [dBi] }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_REAL_COMMUNICATION_ANTENNA_RADIATION_PATTERN_HPP_ diff --git a/src/components/real/communication/ground_station_calculator.cpp b/src/components/real/communication/ground_station_calculator.cpp index 01b80ff25..bec0c2fd7 100644 --- a/src/components/real/communication/ground_station_calculator.cpp +++ b/src/components/real/communication/ground_station_calculator.cpp @@ -9,6 +9,8 @@ #include #include +namespace s2e::components { + GroundStationCalculator::GroundStationCalculator(const double loss_polarization_dB, const double loss_atmosphere_dB, const double loss_rainfall_dB, const double loss_others_dB, const double ebn0_dB, const double hardware_deterioration_dB, const double coding_gain_dB, const double margin_requirement_dB, const double downlink_bitrate_bps) @@ -27,8 +29,8 @@ GroundStationCalculator::GroundStationCalculator(const double loss_polarization_ GroundStationCalculator::~GroundStationCalculator() {} -void GroundStationCalculator::Update(const Spacecraft& spacecraft, const Antenna& spacecraft_tx_antenna, const GroundStation& ground_station, - const Antenna& ground_station_rx_antenna) { +void GroundStationCalculator::Update(const spacecraft::Spacecraft& spacecraft, const Antenna& spacecraft_tx_antenna, + const ground_station::GroundStation& ground_station, const Antenna& ground_station_rx_antenna) { bool is_visible = ground_station.IsVisible(spacecraft.GetSpacecraftId()); if (is_visible) { max_bitrate_Mbps_ = CalcMaxBitrate(spacecraft.GetDynamics(), spacecraft_tx_antenna, ground_station, ground_station_rx_antenna); @@ -40,8 +42,8 @@ void GroundStationCalculator::Update(const Spacecraft& spacecraft, const Antenna } // Private functions -double GroundStationCalculator::CalcMaxBitrate(const Dynamics& dynamics, const Antenna& spacecraft_tx_antenna, const GroundStation& ground_station, - const Antenna& ground_station_rx_antenna) { +double GroundStationCalculator::CalcMaxBitrate(const dynamics::Dynamics& dynamics, const Antenna& spacecraft_tx_antenna, + const ground_station::GroundStation& ground_station, const Antenna& ground_station_rx_antenna) { double cn0_dBHz = CalcCn0OnGs(dynamics, spacecraft_tx_antenna, ground_station, ground_station_rx_antenna); double margin_for_bitrate_dB = cn0_dBHz - (ebn0_dB_ + hardware_deterioration_dB_ + coding_gain_dB_) - margin_requirement_dB_; @@ -53,40 +55,40 @@ double GroundStationCalculator::CalcMaxBitrate(const Dynamics& dynamics, const A } } -double GroundStationCalculator::CalcReceiveMarginOnGs(const Dynamics& dynamics, const Antenna& spacecraft_tx_antenna, - const GroundStation& ground_station, const Antenna& ground_station_rx_antenna) { +double GroundStationCalculator::CalcReceiveMarginOnGs(const dynamics::Dynamics& dynamics, const Antenna& spacecraft_tx_antenna, + const ground_station::GroundStation& ground_station, const Antenna& ground_station_rx_antenna) { double cn0_dB = CalcCn0OnGs(dynamics, spacecraft_tx_antenna, ground_station, ground_station_rx_antenna); double cn0_requirement_dB = ebn0_dB_ + hardware_deterioration_dB_ + coding_gain_dB_ + 10.0 * log10(spacecraft_tx_antenna.GetBitrate_bps()); return cn0_dB - cn0_requirement_dB; } -double GroundStationCalculator::CalcCn0OnGs(const Dynamics& dynamics, const Antenna& spacecraft_tx_antenna, const GroundStation& ground_station, - const Antenna& ground_station_rx_antenna) { +double GroundStationCalculator::CalcCn0OnGs(const dynamics::Dynamics& dynamics, const Antenna& spacecraft_tx_antenna, + const ground_station::GroundStation& ground_station, const Antenna& ground_station_rx_antenna) { if (!spacecraft_tx_antenna.IsTransmitter() || !ground_station_rx_antenna.IsReceiver()) { // Check compatibility of transmitter and receiver return 0.0f; } // Free space path loss - Vector<3> sc_pos_i = dynamics.GetOrbit().GetPosition_i_m(); - Vector<3> gs_pos_i = ground_station.GetPosition_i_m(); - Vector<3> pos_gs2sc_i = sc_pos_i - gs_pos_i; + math::Vector<3> sc_pos_i = dynamics.GetOrbit().GetPosition_i_m(); + math::Vector<3> gs_pos_i = ground_station.GetPosition_i_m(); + math::Vector<3> pos_gs2sc_i = sc_pos_i - gs_pos_i; double dist_sc_gs_km = pos_gs2sc_i.CalcNorm() / 1000.0; double loss_space_dB = -20.0 * log10(4.0 * math::pi * dist_sc_gs_km / (300.0 / spacecraft_tx_antenna.GetFrequency_MHz() / 1000.0)); // GS direction on SC TX antenna frame - Vector<3> sc_to_gs_i = gs_pos_i - sc_pos_i; + math::Vector<3> sc_to_gs_i = gs_pos_i - sc_pos_i; sc_to_gs_i = sc_to_gs_i.CalcNormalizedVector(); - Quaternion q_i_to_sc_ant = spacecraft_tx_antenna.GetQuaternion_b2c() * dynamics.GetAttitude().GetQuaternion_i2b(); - Vector<3> gs_direction_on_sc_frame = q_i_to_sc_ant.FrameConversion(sc_to_gs_i); + math::Quaternion q_i_to_sc_ant = spacecraft_tx_antenna.GetQuaternion_b2c() * dynamics.GetAttitude().GetQuaternion_i2b(); + math::Vector<3> gs_direction_on_sc_frame = q_i_to_sc_ant.FrameConversion(sc_to_gs_i); double theta_on_sc_antenna_rad = acos(gs_direction_on_sc_frame[2]); double phi_on_sc_antenna_rad = atan2(gs_direction_on_sc_frame[1], gs_direction_on_sc_frame[0]); // SC direction on GS RX antenna frame - Vector<3> gs_to_sc_ecef = dynamics.GetOrbit().GetPosition_ecef_m() - ground_station.GetPosition_ecef_m(); + math::Vector<3> gs_to_sc_ecef = dynamics.GetOrbit().GetPosition_ecef_m() - ground_station.GetPosition_ecef_m(); gs_to_sc_ecef = gs_to_sc_ecef.CalcNormalizedVector(); - Quaternion q_ecef_to_gs_ant = ground_station_rx_antenna.GetQuaternion_b2c() * ground_station.GetGeodeticPosition().GetQuaternionXcxfToLtc(); - Vector<3> sc_direction_on_gs_frame = q_ecef_to_gs_ant.FrameConversion(gs_to_sc_ecef); + math::Quaternion q_ecef_to_gs_ant = ground_station_rx_antenna.GetQuaternion_b2c() * ground_station.GetGeodeticPosition().GetQuaternionXcxfToLtc(); + math::Vector<3> sc_direction_on_gs_frame = q_ecef_to_gs_ant.FrameConversion(gs_to_sc_ecef); double theta_on_gs_antenna_rad = acos(sc_direction_on_gs_frame[2]); double phi_on_gs_antenna_rad = atan2(sc_direction_on_gs_frame[1], sc_direction_on_gs_frame[0]); @@ -102,8 +104,8 @@ std::string GroundStationCalculator::GetLogHeader() const { std::string str_tmp = ""; std::string component_name = "gs_calculator_"; - str_tmp += WriteScalar(component_name + "max_bitrate", "Mbps"); - str_tmp += WriteScalar(component_name + "receive_margin", "dB"); + str_tmp += logger::WriteScalar(component_name + "max_bitrate", "Mbps"); + str_tmp += logger::WriteScalar(component_name + "receive_margin", "dB"); return str_tmp; } @@ -111,14 +113,14 @@ std::string GroundStationCalculator::GetLogHeader() const { std::string GroundStationCalculator::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteScalar(max_bitrate_Mbps_); - str_tmp += WriteScalar(receive_margin_dB_); + str_tmp += logger::WriteScalar(max_bitrate_Mbps_); + str_tmp += logger::WriteScalar(receive_margin_dB_); return str_tmp; } GroundStationCalculator InitGsCalculator(const std::string file_name) { - IniAccess gs_conf(file_name); + setting_file_reader::IniAccess gs_conf(file_name); char Section[30] = "GROUND_STATION_CALCULATOR"; @@ -136,3 +138,5 @@ GroundStationCalculator InitGsCalculator(const std::string file_name) { hardware_deterioration_dB, coding_gain_dB, margin_requirement_dB, downlink_bitrate_bps); return gs_calculator; } + +} // namespace s2e::components diff --git a/src/components/real/communication/ground_station_calculator.hpp b/src/components/real/communication/ground_station_calculator.hpp index a2d5eb75a..f0192f2b1 100644 --- a/src/components/real/communication/ground_station_calculator.hpp +++ b/src/components/real/communication/ground_station_calculator.hpp @@ -13,11 +13,13 @@ #include #include +namespace s2e::components { + /* * @class GroundStationCalculator * @brief Emulation of analysis and calculation for Ground Stations */ -class GroundStationCalculator : public ILoggable { +class GroundStationCalculator : public logger::ILoggable { public: /** * @fn GroundStationCalculator @@ -49,18 +51,18 @@ class GroundStationCalculator : public ILoggable { * @param [in] ground_station: Ground station information * @param [in] ground_station_rx_antenna: Antenna mounted on ground station */ - void Update(const Spacecraft& spacecraft, const Antenna& spacecraft_tx_antenna, const GroundStation& ground_station, + void Update(const spacecraft::Spacecraft& spacecraft, const Antenna& spacecraft_tx_antenna, const ground_station::GroundStation& ground_station, const Antenna& ground_station_rx_antenna); - // Override ILoggable TODO: Maybe we don't need logabble, and this class should be used as library. + // Override logger::ILoggable TODO: Maybe we don't need logabble, and this class should be used as library. /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; @@ -109,7 +111,7 @@ class GroundStationCalculator : public ILoggable { * @param [in] ground_station_rx_antenna: Rx Antenna mounted on ground station * @return Max bitrate [Mbps] */ - double CalcMaxBitrate(const Dynamics& dynamics, const Antenna& spacecraft_tx_antenna, const GroundStation& ground_station, + double CalcMaxBitrate(const dynamics::Dynamics& dynamics, const Antenna& spacecraft_tx_antenna, const ground_station::GroundStation& ground_station, const Antenna& ground_station_rx_antenna); /** * @fn CalcReceiveMarginOnGs @@ -120,8 +122,8 @@ class GroundStationCalculator : public ILoggable { * @param [in] ground_station_rx_antenna: Rx Antenna mounted on ground station * @return Receive margin [dB] */ - double CalcReceiveMarginOnGs(const Dynamics& dynamics, const Antenna& spacecraft_tx_antenna, const GroundStation& ground_station, - const Antenna& ground_station_rx_antenna); + double CalcReceiveMarginOnGs(const dynamics::Dynamics& dynamics, const Antenna& spacecraft_tx_antenna, + const ground_station::GroundStation& ground_station, const Antenna& ground_station_rx_antenna); /** * @fn CalcCn0 @@ -132,7 +134,7 @@ class GroundStationCalculator : public ILoggable { * @param [in] ground_station_rx_antenna: Rx Antenna mounted on ground station * @return CN0 [dB] */ - double CalcCn0OnGs(const Dynamics& dynamics, const Antenna& spacecraft_tx_antenna, const GroundStation& ground_station, + double CalcCn0OnGs(const dynamics::Dynamics& dynamics, const Antenna& spacecraft_tx_antenna, const ground_station::GroundStation& ground_station, const Antenna& ground_station_rx_antenna); }; @@ -144,4 +146,6 @@ class GroundStationCalculator : public ILoggable { GroundStationCalculator InitGsCalculator(const std::string file_name); +} // namespace s2e::components + #endif // S2E_COMPONENTS_REAL_COMMUNICATION_GROUND_STATION_CALCULATOR_HPP_ diff --git a/src/components/real/communication/wings_command_sender_to_c2a.cpp b/src/components/real/communication/wings_command_sender_to_c2a.cpp index 4d04ee911..ec6c25da0 100644 --- a/src/components/real/communication/wings_command_sender_to_c2a.cpp +++ b/src/components/real/communication/wings_command_sender_to_c2a.cpp @@ -26,6 +26,8 @@ #endif // c2a-core version header #endif // USE_C2A +namespace s2e::components { + void WingsCommandSenderToC2a::MainRoutine(const int time_count) { UNUSED(time_count); if (is_enabled_ == false) return; @@ -131,9 +133,9 @@ void WingsCommandSenderToC2a::AnalyzeC2aCommand(const std::vector t #endif } -WingsCommandSenderToC2a InitWingsCommandSenderToC2a(ClockGenerator* clock_generator, const double compo_update_step_s, +WingsCommandSenderToC2a InitWingsCommandSenderToC2a(environment::ClockGenerator* clock_generator, const double compo_update_step_s, const std::string initialize_file) { - IniAccess ini_access(initialize_file); + setting_file_reader::IniAccess ini_access(initialize_file); std::string section = "WINGS_COMMAND_SENDER_TO_C2A"; bool is_enabled = ini_access.ReadEnable(section.c_str(), "command_send_enable"); @@ -148,3 +150,5 @@ WingsCommandSenderToC2a InitWingsCommandSenderToC2a(ClockGenerator* clock_genera return WingsCommandSenderToC2a(prescaler, clock_generator, step_width_s, c2a_command_data_base_file, wings_operation_file, is_enabled); } + +} // namespace s2e::components diff --git a/src/components/real/communication/wings_command_sender_to_c2a.hpp b/src/components/real/communication/wings_command_sender_to_c2a.hpp index 1ae74b1c1..167563cf9 100644 --- a/src/components/real/communication/wings_command_sender_to_c2a.hpp +++ b/src/components/real/communication/wings_command_sender_to_c2a.hpp @@ -11,6 +11,8 @@ #include "../../base/component.hpp" +namespace s2e::components { + /* * @class C2aCommandSender * @brief A component to send C2A command using WINGS operation file @@ -22,8 +24,8 @@ class WingsCommandSenderToC2a : public Component { * @brief Constructor * @param [in] */ - WingsCommandSenderToC2a(int prescaler, ClockGenerator* clock_generator, const double step_width_s, const std::string command_database_file, - const std::string operation_file, const bool is_enabled) + WingsCommandSenderToC2a(int prescaler, environment::ClockGenerator* clock_generator, const double step_width_s, + const std::string command_database_file, const std::string operation_file, const bool is_enabled) : Component(prescaler, clock_generator), c2a_command_database_(command_database_file), wings_operation_file_(operation_file), @@ -73,7 +75,9 @@ class WingsCommandSenderToC2a : public Component { * @param[in] compo_update_step_s: Component update step time [s] * @param[in] initialize_file: Initialize file name */ -WingsCommandSenderToC2a InitWingsCommandSenderToC2a(ClockGenerator* clock_generator, const double compo_update_step_s, +WingsCommandSenderToC2a InitWingsCommandSenderToC2a(environment::ClockGenerator* clock_generator, const double compo_update_step_s, const std::string initialize_file); +} // namespace s2e::components + #endif // S2E_COMPONENTS_REAL_COMMUNICATION_C2A_COMMAND_SENDER_HPP_ diff --git a/src/components/real/mission/telescope.cpp b/src/components/real/mission/telescope.cpp index 31bc2919f..cf17359e4 100644 --- a/src/components/real/mission/telescope.cpp +++ b/src/components/real/mission/telescope.cpp @@ -10,14 +10,13 @@ #include #include -using namespace std; -using namespace math; +namespace s2e::components { -Telescope::Telescope(ClockGenerator* clock_generator, const math::Quaternion& quaternion_b2c, const double sun_forbidden_angle_rad, +Telescope::Telescope(environment::ClockGenerator* clock_generator, const math::Quaternion& quaternion_b2c, const double sun_forbidden_angle_rad, const double earth_forbidden_angle_rad, const double moon_forbidden_angle_rad, const int x_number_of_pix, const int y_number_of_pix, const double x_fov_per_pix, const double y_fov_per_pix, size_t number_of_logged_stars, - const Attitude* attitude, const HipparcosCatalogue* hipparcos, const LocalCelestialInformation* local_celestial_information, - const Orbit* orbit) + const dynamics::attitude::Attitude* attitude, const environment::HipparcosCatalogue* hipparcos, + const environment::LocalCelestialInformation* local_celestial_information, const dynamics::orbit::Orbit* orbit) : Component(1, clock_generator), quaternion_b2c_(quaternion_b2c), sun_forbidden_angle_rad_(sun_forbidden_angle_rad), @@ -41,7 +40,7 @@ Telescope::Telescope(ClockGenerator* clock_generator, const math::Quaternion& qu assert(x_field_of_view_rad < math::pi_2); // Avoid the case that the field of view is over 90 degrees assert(y_field_of_view_rad < math::pi_2); - sight_direction_c_ = Vector<3>(0); + sight_direction_c_ = math::Vector<3>(0); sight_direction_c_[0] = 1; // (1,0,0) at component frame, Sight direction vector // Set 0 when t=0 @@ -116,7 +115,7 @@ void Telescope::Observe(math::Vector<2>& position_image_sensor, const math::Vect } void Telescope::ObserveStars() { - Quaternion quaternion_i2b = attitude_->GetQuaternion_i2b(); + math::Quaternion quaternion_i2b = attitude_->GetQuaternion_i2b(); star_list_in_sight.clear(); // Clear first size_t count = 0; // Counter for while loop @@ -173,7 +172,7 @@ void Telescope::ObserveGroundPositionDeviation() { return; } - Quaternion quaternion_i2b = attitude_->GetQuaternion_i2b(); + math::Quaternion quaternion_i2b = attitude_->GetQuaternion_i2b(); math::Vector<3> spacecraft_position_ecef_m = orbit_->GetPosition_ecef_m(); math::Vector<3> direction_ecef = (initial_ground_position_ecef_m_ - spacecraft_position_ecef_m).CalcNormalizedVector(); math::Matrix<3, 3> dcm_ecef_to_i = local_celestial_information_->GetGlobalInformation().GetEarthRotation().GetDcmJ2000ToEcef().Transpose(); @@ -188,69 +187,70 @@ void Telescope::ObserveGroundPositionDeviation() { ground_position_y_image_sensor_ = ground_angle_y_rad / y_fov_per_pix_; } -string Telescope::GetLogHeader() const { - string str_tmp = ""; +std::string Telescope::GetLogHeader() const { + std::string str_tmp = ""; std::string component_name = "telescope_"; - str_tmp += WriteScalar(component_name + "sun_in_exclusion_angle", ""); - str_tmp += WriteScalar(component_name + "earth_in_exclusion_angle", ""); - str_tmp += WriteScalar(component_name + "moon_in_exclusion_angle", ""); - str_tmp += WriteVector(component_name + "sun_position", "img", "pix", 2); - str_tmp += WriteVector(component_name + "earth_position", "img", "pix", 2); - str_tmp += WriteVector(component_name + "moon_position", "img", "pix", 2); - str_tmp += WriteScalar(component_name + "ground_position_x", "pix"); - str_tmp += WriteScalar(component_name + "ground_position_y", "pix"); + str_tmp += logger::WriteScalar(component_name + "sun_in_exclusion_angle", ""); + str_tmp += logger::WriteScalar(component_name + "earth_in_exclusion_angle", ""); + str_tmp += logger::WriteScalar(component_name + "moon_in_exclusion_angle", ""); + str_tmp += logger::WriteVector(component_name + "sun_position", "img", "pix", 2); + str_tmp += logger::WriteVector(component_name + "earth_position", "img", "pix", 2); + str_tmp += logger::WriteVector(component_name + "moon_position", "img", "pix", 2); + str_tmp += logger::WriteScalar(component_name + "ground_position_x", "pix"); + str_tmp += logger::WriteScalar(component_name + "ground_position_y", "pix"); // When Hipparcos Catalogue was not read, no output of ObserveStars if (hipparcos_->IsCalcEnabled) { for (size_t i = 0; i < number_of_logged_stars_; i++) { - str_tmp += WriteScalar(component_name + "hipparcos_id (" + to_string(i) + ")", " "); - str_tmp += WriteScalar(component_name + "visible_magnitude (" + to_string(i) + ")", " "); - str_tmp += WriteVector(component_name + "star_position (" + to_string(i) + ")", "img", "pix", 2); + str_tmp += logger::WriteScalar(component_name + "hipparcos_id (" + std::to_string(i) + ")", " "); + str_tmp += logger::WriteScalar(component_name + "visible_magnitude (" + std::to_string(i) + ")", " "); + str_tmp += logger::WriteVector(component_name + "star_position (" + std::to_string(i) + ")", "img", "pix", 2); } } // Debug output ********************************************** - // str_tmp += WriteScalar("angle_sun", ""); - // str_tmp += WriteScalar("angle_earth", ""); - // str_tmp += WriteScalar("angle_moon", ""); + // str_tmp += logger::WriteScalar("angle_sun", ""); + // str_tmp += logger::WriteScalar("angle_earth", ""); + // str_tmp += logger::WriteScalar("angle_moon", ""); //********************************************************** return str_tmp; } -string Telescope::GetLogValue() const { - string str_tmp = ""; - str_tmp += WriteScalar(is_sun_in_forbidden_angle); - str_tmp += WriteScalar(is_earth_in_forbidden_angle); - str_tmp += WriteScalar(is_moon_in_forbidden_angle); - str_tmp += WriteVector(sun_position_image_sensor); - str_tmp += WriteVector(earth_position_image_sensor); - str_tmp += WriteVector(moon_position_image_sensor); - str_tmp += WriteScalar(ground_position_x_image_sensor_); - str_tmp += WriteScalar(ground_position_y_image_sensor_); +std::string Telescope::GetLogValue() const { + std::string str_tmp = ""; + str_tmp += logger::WriteScalar(is_sun_in_forbidden_angle); + str_tmp += logger::WriteScalar(is_earth_in_forbidden_angle); + str_tmp += logger::WriteScalar(is_moon_in_forbidden_angle); + str_tmp += logger::WriteVector(sun_position_image_sensor); + str_tmp += logger::WriteVector(earth_position_image_sensor); + str_tmp += logger::WriteVector(moon_position_image_sensor); + str_tmp += logger::WriteScalar(ground_position_x_image_sensor_); + str_tmp += logger::WriteScalar(ground_position_y_image_sensor_); // When Hipparcos Catalogue was not read, no output of ObserveStars if (hipparcos_->IsCalcEnabled) { for (size_t i = 0; i < number_of_logged_stars_; i++) { - str_tmp += WriteScalar(star_list_in_sight[i].hipparcos_data.hipparcos_id); - str_tmp += WriteScalar(star_list_in_sight[i].hipparcos_data.visible_magnitude); - str_tmp += WriteVector(star_list_in_sight[i].position_image_sensor); + str_tmp += logger::WriteScalar(star_list_in_sight[i].hipparcos_data.hipparcos_id); + str_tmp += logger::WriteScalar(star_list_in_sight[i].hipparcos_data.visible_magnitude); + str_tmp += logger::WriteVector(star_list_in_sight[i].position_image_sensor); } } // Debug output ********************************************** - // str_tmp += WriteScalar(angle_sun); - // str_tmp += WriteScalar(angle_earth); - // str_tmp += WriteScalar(angle_moon); + // str_tmp += logger::WriteScalar(angle_sun); + // str_tmp += logger::WriteScalar(angle_earth); + // str_tmp += logger::WriteScalar(angle_moon); //********************************************************** 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, const Orbit* orbit) { +Telescope InitTelescope(environment::ClockGenerator* clock_generator, int sensor_id, const std::string file_name, + const dynamics::attitude::Attitude* attitude, const environment::HipparcosCatalogue* hipparcos, + const environment::LocalCelestialInformation* local_celestial_information, const dynamics::orbit::Orbit* orbit) { using math::pi; - IniAccess Telescope_conf(file_name); - const string st_sensor_id = std::to_string(static_cast(sensor_id)); + setting_file_reader::IniAccess Telescope_conf(file_name); + const std::string st_sensor_id = std::to_string(static_cast(sensor_id)); const char* cs = st_sensor_id.data(); char TelescopeSection[30] = "TELESCOPE_"; @@ -285,3 +285,5 @@ Telescope InitTelescope(ClockGenerator* clock_generator, int sensor_id, const st orbit); return telescope; } + +} // namespace s2e::components diff --git a/src/components/real/mission/telescope.hpp b/src/components/real/mission/telescope.hpp index dec83517b..dc663de90 100644 --- a/src/components/real/mission/telescope.hpp +++ b/src/components/real/mission/telescope.hpp @@ -17,20 +17,22 @@ #include "../../base/component.hpp" +namespace s2e::components { + /* * @struct Star * @brief Information of stars in the telescope's field of view */ struct Star { - HipparcosData hipparcos_data; //!< Hipparcos data - math::Vector<2> position_image_sensor; //!< Position of image sensor + environment::HipparcosData hipparcos_data; //!< Hipparcos data + math::Vector<2> position_image_sensor; //!< Position of image sensor }; /* * @class Telescope * @brief Component emulation: Telescope */ -class Telescope : public Component, public ILoggable { +class Telescope : public Component, public logger::ILoggable { public: /** * @fn Telescope @@ -45,15 +47,16 @@ class Telescope : public Component, public ILoggable { * @param [in] x_fov_per_pix: Field of view per pixel of X-axis in the image plane [rad/pix] * @param [in] y_fov_per_pix: Field of view per pixel of Y-axis in the image plane [rad/pix] * @param [in] number_of_logged_stars: Number of logged stars - * @param [in] attitude: Attitude Information + * @param [in] attitude: dynamics::attitude::Attitude Information * @param [in] hipparcos: Hipparcos catalogue information * @param [in] local_celestial_information: Local celestial information * @param [in] orbit: Orbit information */ - Telescope(ClockGenerator* clock_generator, const math::Quaternion& quaternion_b2c, const double sun_forbidden_angle_rad, + Telescope(environment::ClockGenerator* clock_generator, const math::Quaternion& quaternion_b2c, const double sun_forbidden_angle_rad, const double earth_forbidden_angle_rad, const double moon_forbidden_angle_rad, const int x_number_of_pix, const int y_number_of_pix, - const double x_fov_per_pix, const double y_fov_per_pix, size_t number_of_logged_stars, const Attitude* attitude, - const HipparcosCatalogue* hipparcos, const LocalCelestialInformation* local_celestial_information, const Orbit* orbit = nullptr); + const double x_fov_per_pix, const double y_fov_per_pix, size_t number_of_logged_stars, const dynamics::attitude::Attitude* attitude, + const environment::HipparcosCatalogue* hipparcos, const environment::LocalCelestialInformation* local_celestial_information, + const dynamics::orbit::Orbit* orbit = nullptr); /** * @fn ~Telescope * @brief Destructor @@ -124,25 +127,25 @@ class Telescope : public Component, public ILoggable { */ void ObserveStars(); - const Attitude* attitude_; //!< Attitude information - const HipparcosCatalogue* hipparcos_; //!< Star information - const LocalCelestialInformation* local_celestial_information_; //!< Local celestial information + const dynamics::attitude::Attitude* attitude_; //!< dynamics::attitude::Attitude information + const environment::HipparcosCatalogue* hipparcos_; //!< Star information + const environment::LocalCelestialInformation* local_celestial_information_; //!< Local celestial information /** * @fn ObserveGroundPositionDeviation * @brief Calculate the deviation of the ground position from its initial value in the image sensor */ void ObserveGroundPositionDeviation(); - const Orbit* orbit_; //!< Orbit information - // Override ILoggable + const dynamics::orbit::Orbit* orbit_; //!< Orbit information + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; @@ -162,12 +165,14 @@ class Telescope : public Component, public ILoggable { * @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] attitude: dynamics::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, - const Orbit* orbit = nullptr); +Telescope InitTelescope(environment::ClockGenerator* clock_generator, int sensor_id, const std::string file_name, + const dynamics::attitude::Attitude* attitude, const environment::HipparcosCatalogue* hipparcos, + const environment::LocalCelestialInformation* local_celestial_information, const dynamics::orbit::Orbit* orbit = nullptr); + +} // namespace s2e::components #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 f647fb940..247bf082b 100644 --- a/src/components/real/power/battery.cpp +++ b/src/components/real/power/battery.cpp @@ -8,9 +8,11 @@ #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, - double battery_resistance_Ohm, double component_step_time_s) +namespace s2e::components { + +Battery::Battery(const int prescaler, environment::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, double battery_resistance_Ohm, double component_step_time_s) : Component(prescaler, clock_generator), number_of_series_(number_of_series), number_of_parallel_(number_of_parallel), @@ -22,7 +24,7 @@ Battery::Battery(const int prescaler, ClockGenerator* clock_generator, int numbe battery_resistance_Ohm_(battery_resistance_Ohm), compo_step_time_s_(component_step_time_s) {} -Battery::Battery(ClockGenerator* clock_generator, int number_of_series, int number_of_parallel, double cell_capacity_Ah, +Battery::Battery(environment::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, double battery_resistance_Ohm) : Component(10, clock_generator), @@ -56,15 +58,15 @@ Battery::~Battery() {} std::string Battery::GetLogHeader() const { std::string str_tmp = ""; std::string component_name = "battery_"; - str_tmp += WriteScalar(component_name + "voltage", "V"); - str_tmp += WriteScalar(component_name + "dod", "%"); + str_tmp += logger::WriteScalar(component_name + "voltage", "V"); + str_tmp += logger::WriteScalar(component_name + "dod", "%"); return str_tmp; } std::string Battery::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteScalar(battery_voltage_V_); - str_tmp += WriteScalar(depth_of_discharge_percent_); + str_tmp += logger::WriteScalar(battery_voltage_V_); + str_tmp += logger::WriteScalar(depth_of_discharge_percent_); return str_tmp; } @@ -87,8 +89,8 @@ 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); +Battery InitBAT(environment::ClockGenerator* clock_generator, int bat_id, const std::string file_name, double component_step_time_s) { + setting_file_reader::IniAccess bat_conf(file_name); const std::string section_name = "BATTERY_" + std::to_string(static_cast(bat_id)); @@ -130,3 +132,5 @@ Battery InitBAT(ClockGenerator* clock_generator, int bat_id, const std::string f return battery; } + +} // namespace s2e::components diff --git a/src/components/real/power/battery.hpp b/src/components/real/power/battery.hpp index 39ee34c44..84d2edf9b 100644 --- a/src/components/real/power/battery.hpp +++ b/src/components/real/power/battery.hpp @@ -11,11 +11,13 @@ #include "../../base/component.hpp" +namespace s2e::components { + /* * @class Battery * @brief Component emulation of battery */ -class Battery : public Component, public ILoggable { +class Battery : public Component, public logger::ILoggable { public: /** * @fn Battery @@ -32,7 +34,7 @@ class Battery : public Component, public ILoggable { * @param [in] battery_resistance_Ohm: Battery internal resistance [Ohm] * @param [in] component_step_time_s: Component step time [sec] */ - Battery(const int prescaler, ClockGenerator* clock_generator, int number_of_series, int number_of_parallel, double cell_capacity_Ah, + Battery(const int prescaler, environment::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, double battery_resistance_Ohm, double component_step_time_s); /** @@ -49,7 +51,7 @@ class Battery : public Component, public ILoggable { * @param [in] cv_charge_voltage_V: Constant charge voltage [V] * @param [in] battery_resistance_Ohm: Battery internal resistance [Ohm] */ - Battery(ClockGenerator* clock_generator, int number_of_series, int number_of_parallel, double cell_capacity_Ah, + Battery(environment::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, double battery_resistance_Ohm); /** @@ -95,15 +97,15 @@ class Battery : public Component, public ILoggable { */ inline double GetCvChargeVoltage_V() const { return cv_charge_voltage_V_; } - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ std::string GetLogHeader() const override; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ std::string GetLogValue() const override; @@ -142,6 +144,8 @@ class Battery : public Component, public ILoggable { * @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); +Battery InitBAT(environment::ClockGenerator* clock_generator, int bat_id, const std::string file_name, double component_step_time_s); + +} // namespace s2e::components #endif // S2E_COMPONENTS_REAL_POWER_BATTERY_HPP_P_ diff --git a/src/components/real/power/csv_scenario_interface.cpp b/src/components/real/power/csv_scenario_interface.cpp index d0b5c1beb..54ee31a01 100644 --- a/src/components/real/power/csv_scenario_interface.cpp +++ b/src/components/real/power/csv_scenario_interface.cpp @@ -7,12 +7,14 @@ #include +namespace s2e::components { + bool CsvScenarioInterface::is_csv_scenario_enabled_; std::map CsvScenarioInterface::buffer_line_id_; std::map CsvScenarioInterface::buffers_; void CsvScenarioInterface::Initialize(const std::string file_name) { - IniAccess scenario_conf(file_name); + setting_file_reader::IniAccess scenario_conf(file_name); char Section[30] = "SCENARIO"; CsvScenarioInterface::is_csv_scenario_enabled_ = scenario_conf.ReadBoolean(Section, "is_csv_scenario_enabled"); @@ -92,3 +94,5 @@ double CsvScenarioInterface::GetValueFromBuffer(const std::string buffer_name, c output = itr->second; return output; } + +} // namespace s2e::components diff --git a/src/components/real/power/csv_scenario_interface.hpp b/src/components/real/power/csv_scenario_interface.hpp index 30f96ead1..d6c331ad9 100644 --- a/src/components/real/power/csv_scenario_interface.hpp +++ b/src/components/real/power/csv_scenario_interface.hpp @@ -11,6 +11,8 @@ #include #include +namespace s2e::components { + typedef std::map DoubleBuffer; /* @@ -78,4 +80,6 @@ class CsvScenarioInterface { static std::map buffers_; //!< Buffer }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_REAL_POWER_CSV_SCENARIO_INTERFACE_HPP_ diff --git a/src/components/real/power/pcu_initial_study.cpp b/src/components/real/power/pcu_initial_study.cpp index 77f6fda37..b1d35c2a7 100644 --- a/src/components/real/power/pcu_initial_study.cpp +++ b/src/components/real/power/pcu_initial_study.cpp @@ -10,8 +10,10 @@ #include #include -PcuInitialStudy::PcuInitialStudy(const int prescaler, ClockGenerator* clock_generator, const std::vector saps, Battery* battery, - double component_step_time_s) +namespace s2e::components { + +PcuInitialStudy::PcuInitialStudy(const int prescaler, environment::ClockGenerator* clock_generator, const std::vector saps, + Battery* battery, double component_step_time_s) : Component(prescaler, clock_generator), saps_(saps), battery_(battery), @@ -22,7 +24,7 @@ PcuInitialStudy::PcuInitialStudy(const int prescaler, ClockGenerator* clock_gene power_consumption_W_ = 0.0; } -PcuInitialStudy::PcuInitialStudy(ClockGenerator* clock_generator, const std::vector saps, Battery* battery) +PcuInitialStudy::PcuInitialStudy(environment::ClockGenerator* clock_generator, const std::vector saps, Battery* battery) : Component(10, clock_generator), saps_(saps), battery_(battery), @@ -38,15 +40,15 @@ PcuInitialStudy::~PcuInitialStudy() {} std::string PcuInitialStudy::GetLogHeader() const { std::string str_tmp = ""; std::string component_name = "pcu_initial_study_"; - str_tmp += WriteScalar(component_name + "power_consumption", "W"); - str_tmp += WriteScalar(component_name + "bus_voltage", "V"); + str_tmp += logger::WriteScalar(component_name + "power_consumption", "W"); + str_tmp += logger::WriteScalar(component_name + "bus_voltage", "V"); return str_tmp; } std::string PcuInitialStudy::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteScalar(power_consumption_W_); - str_tmp += WriteScalar(bus_voltage_V_); + str_tmp += logger::WriteScalar(power_consumption_W_); + str_tmp += logger::WriteScalar(bus_voltage_V_); return str_tmp; } @@ -111,9 +113,9 @@ void PcuInitialStudy::UpdateChargeCurrentAndBusVoltage() { } } -PcuInitialStudy InitPCU_InitialStudy(ClockGenerator* clock_generator, int pcu_id, const std::string file_name, +PcuInitialStudy InitPCU_InitialStudy(environment::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); + setting_file_reader::IniAccess pcu_conf(file_name); const std::string section_name = "PCU_INITIAL_STUDY_" + std::to_string(static_cast(pcu_id)); @@ -124,3 +126,5 @@ PcuInitialStudy InitPCU_InitialStudy(ClockGenerator* clock_generator, int pcu_id return pcu; } + +} // namespace s2e::components diff --git a/src/components/real/power/pcu_initial_study.hpp b/src/components/real/power/pcu_initial_study.hpp index f59966774..65f5eda94 100644 --- a/src/components/real/power/pcu_initial_study.hpp +++ b/src/components/real/power/pcu_initial_study.hpp @@ -13,7 +13,9 @@ #include "battery.hpp" #include "solar_array_panel.hpp" -class PcuInitialStudy : public Component, public ILoggable { +namespace s2e::components { + +class PcuInitialStudy : public Component, public logger::ILoggable { public: /** * @fn PcuInitialStudy @@ -24,7 +26,7 @@ class PcuInitialStudy : public Component, public ILoggable { * @param [in] battery: Battery * @param [in] component_step_time_s: Component step time [sec] */ - PcuInitialStudy(const int prescaler, ClockGenerator* clock_generator, const std::vector saps, Battery* battery, + PcuInitialStudy(const int prescaler, environment::ClockGenerator* clock_generator, const std::vector saps, Battery* battery, double component_step_time_s); /** * @fn PcuInitialStudy @@ -33,22 +35,22 @@ class PcuInitialStudy : public Component, public ILoggable { * @param [in] saps: Solar Array Panels * @param [in] battery: Battery */ - PcuInitialStudy(ClockGenerator* clock_generator, const std::vector saps, Battery* battery); + PcuInitialStudy(environment::ClockGenerator* clock_generator, const std::vector saps, Battery* battery); /** * @fn ~PcuInitialStudy * @brief Destructor */ ~PcuInitialStudy(); - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ std::string GetLogHeader() const override; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ std::string GetLogValue() const override; @@ -92,7 +94,9 @@ class PcuInitialStudy : public Component, public ILoggable { * @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, +PcuInitialStudy InitPCU_InitialStudy(environment::ClockGenerator* clock_generator, int pcu_id, const std::string file_name, const std::vector saps, Battery* battery, double component_step_time_s); +} // namespace s2e::components + #endif // S2E_COMPONENTS_REAL_POWER_PCU_INITIAL_STUDY_HPP_ diff --git a/src/components/real/power/power_control_unit.cpp b/src/components/real/power/power_control_unit.cpp index 055300e2c..5ed558949 100644 --- a/src/components/real/power/power_control_unit.cpp +++ b/src/components/real/power/power_control_unit.cpp @@ -4,9 +4,11 @@ */ #include "power_control_unit.hpp" -PowerControlUnit::PowerControlUnit(ClockGenerator* clock_generator) : Component(1, clock_generator) {} +namespace s2e::components { -PowerControlUnit::PowerControlUnit(int prescaler, ClockGenerator* clock_generator) : Component(prescaler, clock_generator) {} +PowerControlUnit::PowerControlUnit(environment::ClockGenerator* clock_generator) : Component(1, clock_generator) {} + +PowerControlUnit::PowerControlUnit(int prescaler, environment::ClockGenerator* clock_generator) : Component(prescaler, clock_generator) {} PowerControlUnit::~PowerControlUnit() {} @@ -52,3 +54,5 @@ std::string PowerControlUnit::GetLogValue() const { std::string str_tmp = ""; return str_tmp; } + +} // namespace s2e::components diff --git a/src/components/real/power/power_control_unit.hpp b/src/components/real/power/power_control_unit.hpp index 3e77101c2..0e16e2547 100644 --- a/src/components/real/power/power_control_unit.hpp +++ b/src/components/real/power/power_control_unit.hpp @@ -12,25 +12,27 @@ #include "../../base/component.hpp" +namespace s2e::components { + /* * @class PowerControlUnit * @brief Component emulation of Power Control Unit */ -class PowerControlUnit : public Component, public ILoggable { +class PowerControlUnit : public Component, public logger::ILoggable { public: /** * @fn PowerControlUnit * @brief Constructor * @param [in] clock_generator: Clock generator */ - PowerControlUnit(ClockGenerator* clock_generator); + PowerControlUnit(environment::ClockGenerator* clock_generator); /** * @fn PowerControlUnit * @brief Constructor * @param [in] prescaler: Frequency scale factor for update * @param [in] clock_generator: Clock generator */ - PowerControlUnit(int prescaler, ClockGenerator* clock_generator); + PowerControlUnit(int prescaler, environment::ClockGenerator* clock_generator); /** * @fn ~PowerControlUnit * @brief Destructor @@ -44,15 +46,15 @@ class PowerControlUnit : public Component, public ILoggable { */ void MainRoutine(const int time_count) override; - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ std::string GetLogHeader() const override; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ std::string GetLogValue() const override; @@ -95,4 +97,6 @@ class PowerControlUnit : public Component, public ILoggable { std::map power_ports_; //!< Power port list }; +} // namespace s2e::components + #endif // S2E_COMPONENTS_REAL_POWER_POWER_CONTROL_UNIT_HPP_ diff --git a/src/components/real/power/solar_array_panel.cpp b/src/components/real/power/solar_array_panel.cpp index 43a22afa8..2bd8632b4 100644 --- a/src/components/real/power/solar_array_panel.cpp +++ b/src/components/real/power/solar_array_panel.cpp @@ -9,10 +9,12 @@ #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, math::Vector<3> normal_vector, double cell_efficiency, double transmission_efficiency, - const SolarRadiationPressureEnvironment* srp_environment, - const LocalCelestialInformation* local_celestial_information, double component_step_time_s) +namespace s2e::components { + +SolarArrayPanel::SolarArrayPanel(const int prescaler, environment::ClockGenerator* clock_generator, int component_id, int number_of_series, + int number_of_parallel, double cell_area_m2, math::Vector<3> normal_vector, double cell_efficiency, + double transmission_efficiency, const environment::SolarRadiationPressureEnvironment* srp_environment, + const environment::LocalCelestialInformation* local_celestial_information, double component_step_time_s) : Component(prescaler, clock_generator), component_id_(component_id), number_of_series_(number_of_series), @@ -28,9 +30,10 @@ SolarArrayPanel::SolarArrayPanel(const int prescaler, ClockGenerator* clock_gene power_generation_W_ = 0.0; } -SolarArrayPanel::SolarArrayPanel(const int prescaler, ClockGenerator* clock_generator, int component_id, int number_of_series, int number_of_parallel, - double cell_area_m2, math::Vector<3> normal_vector, double cell_efficiency, double transmission_efficiency, - const SolarRadiationPressureEnvironment* srp_environment, double component_step_time_s) +SolarArrayPanel::SolarArrayPanel(const int prescaler, environment::ClockGenerator* clock_generator, int component_id, int number_of_series, + int number_of_parallel, double cell_area_m2, math::Vector<3> normal_vector, double cell_efficiency, + double transmission_efficiency, const environment::SolarRadiationPressureEnvironment* srp_environment, + double component_step_time_s) : Component(prescaler, clock_generator), component_id_(component_id), number_of_series_(number_of_series), @@ -45,10 +48,10 @@ SolarArrayPanel::SolarArrayPanel(const int prescaler, ClockGenerator* clock_gene power_generation_W_ = 0.0; } -SolarArrayPanel::SolarArrayPanel(ClockGenerator* clock_generator, int component_id, int number_of_series, int number_of_parallel, double cell_area_m2, - math::Vector<3> normal_vector, double cell_efficiency, double transmission_efficiency, - const SolarRadiationPressureEnvironment* srp_environment, - const LocalCelestialInformation* local_celestial_information) +SolarArrayPanel::SolarArrayPanel(environment::ClockGenerator* clock_generator, int component_id, int number_of_series, int number_of_parallel, + double cell_area_m2, math::Vector<3> normal_vector, double cell_efficiency, double transmission_efficiency, + const environment::SolarRadiationPressureEnvironment* srp_environment, + const environment::LocalCelestialInformation* local_celestial_information) : Component(10, clock_generator), component_id_(component_id), number_of_series_(number_of_series), @@ -85,13 +88,13 @@ SolarArrayPanel::~SolarArrayPanel() {} std::string SolarArrayPanel::GetLogHeader() const { std::string str_tmp = ""; std::string component_name = "sap" + std::to_string(component_id_) + "_"; - str_tmp += WriteScalar(component_name + "generated_power", "W"); + str_tmp += logger::WriteScalar(component_name + "generated_power", "W"); return str_tmp; } std::string SolarArrayPanel::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteScalar(power_generation_W_); + str_tmp += logger::WriteScalar(power_generation_W_); return str_tmp; } @@ -114,10 +117,10 @@ 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); +SolarArrayPanel InitSAP(environment::ClockGenerator* clock_generator, int sap_id, const std::string file_name, + const environment::SolarRadiationPressureEnvironment* srp_environment, + const environment::LocalCelestialInformation* local_celestial_information, double component_step_time_s) { + setting_file_reader::IniAccess sap_conf(file_name); const std::string section_name = "SOLAR_ARRAY_PANEL_" + std::to_string(static_cast(sap_id)); @@ -148,9 +151,9 @@ SolarArrayPanel InitSAP(ClockGenerator* clock_generator, int sap_id, const std:: 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); +SolarArrayPanel InitSAP(environment::ClockGenerator* clock_generator, int sap_id, const std::string file_name, + const environment::SolarRadiationPressureEnvironment* srp_environment, double component_step_time_s) { + setting_file_reader::IniAccess sap_conf(file_name); const std::string section_name = "SOLAR_ARRAY_PANEL_" + std::to_string(static_cast(sap_id)); @@ -180,3 +183,5 @@ SolarArrayPanel InitSAP(ClockGenerator* clock_generator, int sap_id, const std:: return sap; } + +} // namespace s2e::components diff --git a/src/components/real/power/solar_array_panel.hpp b/src/components/real/power/solar_array_panel.hpp index 7ffa91195..63e7d796f 100644 --- a/src/components/real/power/solar_array_panel.hpp +++ b/src/components/real/power/solar_array_panel.hpp @@ -13,7 +13,9 @@ #include "../../base/component.hpp" -class SolarArrayPanel : public Component, public ILoggable { +namespace s2e::components { + +class SolarArrayPanel : public Component, public logger::ILoggable { public: /** * @fn SolarArrayPanel @@ -31,10 +33,10 @@ class SolarArrayPanel : public Component, public ILoggable { * @param [in] local_celestial_information: Local celestial information * @param [in] component_step_time_s: Component step time [sec] */ - SolarArrayPanel(const int prescaler, ClockGenerator* clock_generator, int component_id, int number_of_series, int number_of_parallel, + SolarArrayPanel(const int prescaler, environment::ClockGenerator* clock_generator, int component_id, int number_of_series, int number_of_parallel, double cell_area_m2, math::Vector<3> normal_vector, double cell_efficiency, double transmission_efficiency, - const SolarRadiationPressureEnvironment* srp_environment, const LocalCelestialInformation* local_celestial_information, - double component_step_time_s); + const environment::SolarRadiationPressureEnvironment* srp_environment, + const environment::LocalCelestialInformation* local_celestial_information, double component_step_time_s); /** * @fn SolarArrayPanel * @brief Constructor with prescaler @@ -50,9 +52,9 @@ class SolarArrayPanel : public Component, public ILoggable { * @param [in] srp_environment: Solar Radiation Pressure environment * @param [in] component_step_time_s: Component step time [sec] */ - SolarArrayPanel(const int prescaler, ClockGenerator* clock_generator, int component_id, int number_of_series, int number_of_parallel, + SolarArrayPanel(const int prescaler, environment::ClockGenerator* clock_generator, int component_id, int number_of_series, int number_of_parallel, double cell_area_m2, math::Vector<3> normal_vector, double cell_efficiency, double transmission_efficiency, - const SolarRadiationPressureEnvironment* srp_environment, double component_step_time_s); + const environment::SolarRadiationPressureEnvironment* srp_environment, double component_step_time_s); /** * @fn SolarArrayPanel * @brief Constructor without prescaler @@ -68,9 +70,10 @@ class SolarArrayPanel : public Component, public ILoggable { * @param [in] srp_environment: Solar Radiation Pressure environment * @param [in] local_celestial_information: Local celestial information */ - SolarArrayPanel(ClockGenerator* clock_generator, int component_id, int number_of_series, int number_of_parallel, double cell_area_m2, + SolarArrayPanel(environment::ClockGenerator* clock_generator, int component_id, int number_of_series, int number_of_parallel, double cell_area_m2, math::Vector<3> normal_vector, double cell_efficiency, double transmission_efficiency, - const SolarRadiationPressureEnvironment* srp_environment, const LocalCelestialInformation* local_celestial_information); + const environment::SolarRadiationPressureEnvironment* srp_environment, + const environment::LocalCelestialInformation* local_celestial_information); /** * @fn SolarArrayPanel * @brief Copy constructor @@ -94,15 +97,15 @@ class SolarArrayPanel : public Component, public ILoggable { */ void SetVoltage_V(const double voltage_V) { voltage_V_ = voltage_V; } - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ std::string GetLogHeader() const override; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ std::string GetLogValue() const override; @@ -115,8 +118,8 @@ class SolarArrayPanel : public Component, public ILoggable { const double cell_efficiency_; //!< Power generation efficiency of solar cell const double transmission_efficiency_; //!< Efficiency of transmission to PCU - const SolarRadiationPressureEnvironment* const srp_environment_; //!< Solar Radiation Pressure environment - const LocalCelestialInformation* local_celestial_information_; //!< Local celestial information + const environment::SolarRadiationPressureEnvironment* const srp_environment_; //!< Solar Radiation Pressure environment + const environment::LocalCelestialInformation* local_celestial_information_; //!< Local celestial information double voltage_V_; //!< Voltage [V] double power_generation_W_; //!< Generated power [W] @@ -141,9 +144,9 @@ class SolarArrayPanel : public Component, public ILoggable { * @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); +SolarArrayPanel InitSAP(environment::ClockGenerator* clock_generator, int sap_id, const std::string file_name, + const environment::SolarRadiationPressureEnvironment* srp_environment, + const environment::LocalCelestialInformation* local_celestial_information, double component_step_time_s); /* * @fn InitSAP @@ -154,7 +157,9 @@ SolarArrayPanel InitSAP(ClockGenerator* clock_generator, int sap_id, const std:: * @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); +SolarArrayPanel InitSAP(environment::ClockGenerator* clock_generator, int sap_id, const std::string file_name, + const environment::SolarRadiationPressureEnvironment* srp_environment, double component_step_time_s); + +} // namespace s2e::components #endif // S2E_COMPONENTS_REAL_POWER_SOLAR_ARRAY_PANEL_HPP_ diff --git a/src/components/real/propulsion/simple_thruster.cpp b/src/components/real/propulsion/simple_thruster.cpp index 70c5f2a1b..e30d4b0ce 100644 --- a/src/components/real/propulsion/simple_thruster.cpp +++ b/src/components/real/propulsion/simple_thruster.cpp @@ -9,11 +9,13 @@ #include #include +namespace s2e::components { + // Constructor -SimpleThruster::SimpleThruster(const int prescaler, ClockGenerator* clock_generator, const int component_id, +SimpleThruster::SimpleThruster(const int prescaler, environment::ClockGenerator* clock_generator, const int component_id, const math::Vector<3> thruster_position_b_m, const math::Vector<3> thrust_direction_b, const double max_magnitude_N, - const double magnitude_standard_deviation_N, const double direction_standard_deviation_rad, const Structure* structure, - const Dynamics* dynamics) + const double magnitude_standard_deviation_N, const double direction_standard_deviation_rad, + const spacecraft::Structure* structure, const dynamics::Dynamics* dynamics) : Component(prescaler, clock_generator), component_id_(component_id), thruster_position_b_m_(thruster_position_b_m), @@ -25,10 +27,10 @@ SimpleThruster::SimpleThruster(const int prescaler, ClockGenerator* clock_genera Initialize(magnitude_standard_deviation_N, direction_standard_deviation_rad); } -SimpleThruster::SimpleThruster(const int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, +SimpleThruster::SimpleThruster(const int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, const math::Vector<3> thruster_position_b_m, const math::Vector<3> thrust_direction_b, const double max_magnitude_N, - const double magnitude_standard_deviation_N, const double direction_standard_deviation_rad, const Structure* structure, - const Dynamics* dynamics) + const double magnitude_standard_deviation_N, const double direction_standard_deviation_rad, + const spacecraft::Structure* structure, const dynamics::Dynamics* dynamics) : Component(prescaler, clock_generator, power_port), component_id_(component_id), thruster_position_b_m_(thruster_position_b_m), @@ -77,18 +79,18 @@ std::string SimpleThruster::GetLogHeader() const { std::string str_tmp = ""; std::string head = "simple_thruster" + std::to_string(component_id_) + "_"; - str_tmp += WriteVector(head + "output_thrust", "b", "N", 3); - str_tmp += WriteVector(head + "output_torque", "b", "Nm", 3); - str_tmp += WriteScalar(head + "output_thrust_norm", "N"); + str_tmp += logger::WriteVector(head + "output_thrust", "b", "N", 3); + str_tmp += logger::WriteVector(head + "output_torque", "b", "Nm", 3); + str_tmp += logger::WriteScalar(head + "output_thrust_norm", "N"); return str_tmp; } std::string SimpleThruster::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteVector(output_thrust_b_N_); - str_tmp += WriteVector(output_torque_b_Nm_); - str_tmp += WriteScalar(output_thrust_b_N_.CalcNorm()); + str_tmp += logger::WriteVector(output_thrust_b_N_); + str_tmp += logger::WriteVector(output_torque_b_Nm_); + str_tmp += logger::WriteScalar(output_thrust_b_N_.CalcNorm()); return str_tmp; } @@ -120,19 +122,19 @@ math::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); +SimpleThruster InitSimpleThruster(environment::ClockGenerator* clock_generator, int thruster_id, const std::string file_name, + const spacecraft::Structure* structure, const dynamics::Dynamics* dynamics) { + setting_file_reader::IniAccess thruster_conf(file_name); std::string section_str = "THRUSTER_" + std::to_string(thruster_id); auto* Section = section_str.c_str(); int prescaler = thruster_conf.ReadInt(Section, "prescaler"); if (prescaler <= 1) prescaler = 1; - Vector<3> thruster_pos; + math::Vector<3> thruster_pos; thruster_conf.ReadVector(Section, "thruster_position_b_m", thruster_pos); - Vector<3> thruster_dir; + math::Vector<3> thruster_dir; thruster_conf.ReadVector(Section, "thruster_direction_b", thruster_dir); double max_magnitude_N = thruster_conf.ReadDouble(Section, "thrust_magnitude_N"); @@ -148,19 +150,19 @@ SimpleThruster InitSimpleThruster(ClockGenerator* clock_generator, int thruster_ 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); +SimpleThruster InitSimpleThruster(environment::ClockGenerator* clock_generator, PowerPort* power_port, int thruster_id, const std::string file_name, + const spacecraft::Structure* structure, const dynamics::Dynamics* dynamics) { + setting_file_reader::IniAccess thruster_conf(file_name); std::string section_str = "THRUSTER_" + std::to_string(thruster_id); auto* Section = section_str.c_str(); int prescaler = thruster_conf.ReadInt(Section, "prescaler"); if (prescaler <= 1) prescaler = 1; - Vector<3> thruster_pos; + math::Vector<3> thruster_pos; thruster_conf.ReadVector(Section, "thruster_position_b_m", thruster_pos); - Vector<3> thruster_dir; + math::Vector<3> thruster_dir; thruster_conf.ReadVector(Section, "thruster_direction_b", thruster_dir); double max_magnitude_N = thruster_conf.ReadDouble(Section, "thrust_magnitude_N"); @@ -177,3 +179,5 @@ SimpleThruster InitSimpleThruster(ClockGenerator* clock_generator, PowerPort* po magnitude_standard_deviation_N, deg_err, structure, dynamics); return thruster; } + +} // namespace s2e::components diff --git a/src/components/real/propulsion/simple_thruster.hpp b/src/components/real/propulsion/simple_thruster.hpp index f2466fcc9..c6d1901b7 100644 --- a/src/components/real/propulsion/simple_thruster.hpp +++ b/src/components/real/propulsion/simple_thruster.hpp @@ -15,11 +15,13 @@ #include "../../base/component.hpp" +namespace s2e::components { + /* * @class SimpleThruster * @brief Component emulation of simple thruster */ -class SimpleThruster : public Component, public ILoggable { +class SimpleThruster : public Component, public logger::ILoggable { public: /** * @fn SimpleThruster @@ -35,9 +37,10 @@ class SimpleThruster : public Component, public ILoggable { * @param [in] structure: Spacecraft structure information * @param [in] dynamics: Spacecraft dynamics information */ - SimpleThruster(const int prescaler, ClockGenerator* clock_generator, const int component_id, const Vector<3> thruster_position_b_m, - const Vector<3> thrust_direction_b, const double max_magnitude_N, const double magnitude_standard_deviation_N, - const double direction_standard_deviation_rad, const Structure* structure, const Dynamics* dynamics); + SimpleThruster(const int prescaler, environment::ClockGenerator* clock_generator, const int component_id, + const math::Vector<3> thruster_position_b_m, const math::Vector<3> thrust_direction_b, const double max_magnitude_N, + const double magnitude_standard_deviation_N, const double direction_standard_deviation_rad, const spacecraft::Structure* structure, + const dynamics::Dynamics* dynamics); /** * @fn SimpleThruster * @brief Constructor with power port @@ -53,10 +56,10 @@ class SimpleThruster : public Component, public ILoggable { * @param [in] structure: Spacecraft structure information * @param [in] dynamics: Spacecraft dynamics information */ - SimpleThruster(const int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, - const Vector<3> thruster_position_b_m, const Vector<3> thrust_direction_b, const double max_magnitude_N, - const double magnitude_standard_deviation_N, const double direction_standard_deviation_rad, const Structure* structure, - const Dynamics* dynamics); + SimpleThruster(const int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, const int component_id, + const math::Vector<3> thruster_position_b_m, const math::Vector<3> thrust_direction_b, const double max_magnitude_N, + const double magnitude_standard_deviation_N, const double direction_standard_deviation_rad, const spacecraft::Structure* structure, + const dynamics::Dynamics* dynamics); /** * @fn ~SimpleThruster * @brief Destructor @@ -75,15 +78,15 @@ class SimpleThruster : public Component, public ILoggable { */ void PowerOffRoutine() override; - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const override; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const override; @@ -92,12 +95,12 @@ class SimpleThruster : public Component, public ILoggable { * @fn GetOutputThrust_b_N * @brief Return generated thrust on the body fixed frame [N] */ - inline const Vector<3> GetOutputThrust_b_N() const { return output_thrust_b_N_; }; + inline const math::Vector<3> GetOutputThrust_b_N() const { return output_thrust_b_N_; }; /** * @fn GetOutputTorque_b_Nm * @brief Return generated torque on the body fixed frame [Nm] */ - inline const Vector<3> GetOutputTorque_b_Nm() const { return output_torque_b_Nm_; }; + inline const math::Vector<3> GetOutputTorque_b_Nm() const { return output_torque_b_Nm_; }; // Setter /** @@ -109,16 +112,16 @@ class SimpleThruster : public Component, public ILoggable { protected: // parameters const int component_id_; //!< Thruster ID - Vector<3> thruster_position_b_m_{0.0}; //!< Thruster position @ body frame [m] - Vector<3> thrust_direction_b_{0.0}; //!< Thrust direction @ body frame + math::Vector<3> thruster_position_b_m_{0.0}; //!< Thruster position @ body frame [m] + math::Vector<3> thrust_direction_b_{0.0}; //!< Thrust direction @ body frame double duty_ = 0.0; //!< PWM Duty [0.0 : 1.0] double thrust_magnitude_max_N_ = 0.0; //!< Maximum thrust magnitude [N] double direction_noise_standard_deviation_rad_ = 0.0; //!< Standard deviation of thrust direction error [rad] randomization::NormalRand magnitude_random_noise_; //!< Normal random for thrust magnitude error randomization::NormalRand direction_random_noise_; //!< Normal random for thrust direction error // outputs - Vector<3> output_thrust_b_N_{0.0}; //!< Generated thrust on the body fixed frame [N] - Vector<3> output_torque_b_Nm_{0.0}; //!< Generated torque on the body fixed frame [Nm] + math::Vector<3> output_thrust_b_N_{0.0}; //!< Generated thrust on the body fixed frame [N] + math::Vector<3> output_torque_b_Nm_{0.0}; //!< Generated torque on the body fixed frame [Nm] /** * @fn CalcThrust @@ -130,7 +133,7 @@ class SimpleThruster : public Component, public ILoggable { * @brief Calculate generated torque * @param [in] center_of_mass_b_m: Center of mass_kg position at body frame [m] */ - void CalcTorque(const Vector<3> center_of_mass_b_m); + void CalcTorque(const math::Vector<3> center_of_mass_b_m); /** * @fn CalcThrustMagnitude * @brief Calculate thrust magnitude @@ -142,7 +145,7 @@ class SimpleThruster : public Component, public ILoggable { * @brief Calculate thrust direction * @return Thrust direction */ - Vector<3> CalcThrustDirection(); + math::Vector<3> CalcThrustDirection(); /** * @fn Initialize * @brief Initialize function @@ -151,8 +154,8 @@ class SimpleThruster : public Component, public ILoggable { */ void Initialize(const double magnitude_standard_deviation_N, const double direction_standard_deviation_rad); - const Structure* structure_; //!< Spacecraft structure information - const Dynamics* dynamics_; //!< Spacecraft dynamics information + const spacecraft::Structure* structure_; //!< Spacecraft structure information + const dynamics::Dynamics* dynamics_; //!< Spacecraft dynamics information }; /** @@ -164,8 +167,8 @@ class SimpleThruster : public Component, public ILoggable { * @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); +SimpleThruster InitSimpleThruster(environment::ClockGenerator* clock_generator, int thruster_id, const std::string file_name, + const spacecraft::Structure* structure, const dynamics::Dynamics* dynamics); /** * @fn InitSimpleThruster * @brief Initialize function os SimpleThruster @@ -176,7 +179,9 @@ SimpleThruster InitSimpleThruster(ClockGenerator* clock_generator, int thruster_ * @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); +SimpleThruster InitSimpleThruster(environment::ClockGenerator* clock_generator, PowerPort* power_port, int thruster_id, const std::string file_name, + const spacecraft::Structure* structure, const dynamics::Dynamics* dynamics); + +} // namespace s2e::components #endif // S2E_COMPONENTS_REAL_PROPULSION_SIMPLE_THRUSTER_HPP_ diff --git a/src/disturbances/air_drag.cpp b/src/disturbances/air_drag.cpp index d7d91cfac..2c9254070 100644 --- a/src/disturbances/air_drag.cpp +++ b/src/disturbances/air_drag.cpp @@ -12,7 +12,9 @@ #include "../logger/log_utility.hpp" -AirDrag::AirDrag(const std::vector& surfaces, const math::Vector<3>& center_of_gravity_b_m, const double wall_temperature_K, +namespace s2e::disturbances { + +AirDrag::AirDrag(const std::vector& surfaces, const math::Vector<3>& center_of_gravity_b_m, const double wall_temperature_K, const double molecular_temperature_K, const double molecular_weight_g_mol, const bool is_calculation_enabled) : SurfaceForce(surfaces, center_of_gravity_b_m, is_calculation_enabled), wall_temperature_K_(wall_temperature_K), @@ -23,7 +25,7 @@ AirDrag::AirDrag(const std::vector& surfaces, const math::Vector<3>& ce cn_.assign(num, 0.0); } -void AirDrag::Update(const LocalEnvironment& local_environment, const Dynamics& dynamics) { +void AirDrag::Update(const environment::LocalEnvironment& local_environment, const dynamics::Dynamics& dynamics) { double air_density_kg_m3 = local_environment.GetAtmosphere().GetAirDensity_kg_m3(); math::Matrix<3, 3> dcm_ecef2eci = @@ -58,7 +60,7 @@ double AirDrag::CalcFunctionChi(const double s) { return x; } -void AirDrag::CalcCnCt(const Vector<3>& velocity_b_m_s) { +void AirDrag::CalcCnCt(const math::Vector<3>& velocity_b_m_s) { double velocity_norm_m_s = velocity_b_m_s.CalcNorm(); // Re-emitting speed @@ -78,8 +80,8 @@ void AirDrag::CalcCnCt(const Vector<3>& velocity_b_m_s) { std::string AirDrag::GetLogHeader() const { std::string str_tmp = ""; - str_tmp += WriteVector("air_drag_torque", "b", "Nm", 3); - str_tmp += WriteVector("air_drag_force", "b", "N", 3); + str_tmp += logger::WriteVector("air_drag_torque", "b", "Nm", 3); + str_tmp += logger::WriteVector("air_drag_force", "b", "N", 3); return str_tmp; } @@ -87,14 +89,15 @@ std::string AirDrag::GetLogHeader() const { std::string AirDrag::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteVector(torque_b_Nm_); - str_tmp += WriteVector(force_b_N_); + str_tmp += logger::WriteVector(torque_b_Nm_); + str_tmp += logger::WriteVector(force_b_N_); return str_tmp; } -AirDrag InitAirDrag(const std::string initialize_file_path, const std::vector& surfaces, const Vector<3>& center_of_gravity_b_m) { - auto conf = IniAccess(initialize_file_path); +AirDrag InitAirDrag(const std::string initialize_file_path, const std::vector& surfaces, + const math::Vector<3>& center_of_gravity_b_m) { + auto conf = setting_file_reader::IniAccess(initialize_file_path); const char* section = "AIR_DRAG"; const double wall_temperature_K = conf.ReadDouble(section, "wall_temperature_degC") + 273.0; @@ -109,3 +112,5 @@ AirDrag InitAirDrag(const std::string initialize_file_path, const std::vector& surfaces, const math::Vector<3>& center_of_gravity_b_m, const double wall_temperature_K, + AirDrag(const std::vector& surfaces, const math::Vector<3>& center_of_gravity_b_m, const double wall_temperature_K, const double molecular_temperature_K, const double molecular_weight_g_mol, const bool is_calculation_enabled = true); /** * @fn Update * @brief Override Updates function of SimpleDisturbance * @param [in] local_environment: Local environment information - * @param [in] dynamics: Dynamics information + * @param [in] dynamics: dynamics::Dynamics information */ - virtual void Update(const LocalEnvironment& local_environment, const Dynamics& dynamics); + virtual void Update(const environment::LocalEnvironment& local_environment, const dynamics::Dynamics& dynamics); - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; @@ -96,6 +98,9 @@ class AirDrag : public SurfaceForce { * @param [in] surfaces: surface information of the spacecraft * @param [in] center_of_gravity_b_m: Center of gravity position vector at body frame [m] */ -AirDrag InitAirDrag(const std::string initialize_file_path, const std::vector& surfaces, const Vector<3>& center_of_gravity_b_m); +AirDrag InitAirDrag(const std::string initialize_file_path, const std::vector& surfaces, + const math::Vector<3>& center_of_gravity_b_m); + +} // namespace s2e::disturbances #endif // S2E_DISTURBANCES_AIR_DRAG_HPP_ diff --git a/src/disturbances/disturbance.hpp b/src/disturbances/disturbance.hpp index 6cc662728..d9de38dd9 100644 --- a/src/disturbances/disturbance.hpp +++ b/src/disturbances/disturbance.hpp @@ -9,17 +9,19 @@ #include "../environment/local/local_environment.hpp" #include "../math_physics/math/vector.hpp" +namespace s2e::disturbances { + /** * @class Disturbance * @brief Base class for a disturbance */ -class Disturbance : public ILoggable { +class Disturbance : public logger::ILoggable { public: /** * @fn Disturbance * @brief Constructor * @param [in] is_calculation_enabled: Calculation flag - * @param [in] is_attitude_dependent: Attitude dependent flag + * @param [in] is_attitude_dependent: dynamics::attitude::Attitude dependent flag */ Disturbance(const bool is_calculation_enabled = true, const bool is_attitude_dependent = true) : is_calculation_enabled_(is_calculation_enabled), is_attitude_dependent_(is_attitude_dependent) { @@ -39,7 +41,7 @@ class Disturbance : public ILoggable { * @fn UpdateIfEnabled * @brief Update calculated disturbance when the calculation flag is true */ - virtual inline void UpdateIfEnabled(const LocalEnvironment& local_environment, const Dynamics& dynamics) { + virtual inline void UpdateIfEnabled(const environment::LocalEnvironment& local_environment, const dynamics::Dynamics& dynamics) { if (is_calculation_enabled_) { Update(local_environment, dynamics); } else { @@ -54,7 +56,7 @@ class Disturbance : public ILoggable { * @fn Update * @brief Pure virtual function to define the disturbance calculation */ - virtual void Update(const LocalEnvironment& local_environment, const Dynamics& dynamics) = 0; + virtual void Update(const environment::LocalEnvironment& local_environment, const dynamics::Dynamics& dynamics) = 0; /** * @fn GetTorque_b_Nm @@ -91,4 +93,6 @@ class Disturbance : public ILoggable { math::Vector<3> acceleration_i_m_s2_; //!< Disturbance acceleration in the inertial frame [m/s2] }; +} // namespace s2e::disturbances + #endif // S2E_DISTURBANCES_DISTURBANCE_HPP_ diff --git a/src/disturbances/disturbances.cpp b/src/disturbances/disturbances.cpp index 682790896..c3e3fd018 100644 --- a/src/disturbances/disturbances.cpp +++ b/src/disturbances/disturbances.cpp @@ -15,8 +15,10 @@ #include "solar_radiation_pressure_disturbance.hpp" #include "third_body_gravity.hpp" -Disturbances::Disturbances(const SimulationConfiguration* simulation_configuration, const int spacecraft_id, const Structure* structure, - const GlobalEnvironment* global_environment) { +namespace s2e::disturbances { + +Disturbances::Disturbances(const simulation::SimulationConfiguration* simulation_configuration, const int spacecraft_id, + const spacecraft::Structure* structure, const environment::GlobalEnvironment* global_environment) { InitializeInstances(simulation_configuration, spacecraft_id, structure, global_environment); InitializeForceAndTorque(); InitializeAcceleration(); @@ -28,7 +30,8 @@ Disturbances::~Disturbances() { } } -void Disturbances::Update(const LocalEnvironment& local_environment, const Dynamics& dynamics, const SimulationTime* simulation_time) { +void Disturbances::Update(const environment::LocalEnvironment& local_environment, const dynamics::Dynamics& dynamics, + const environment::SimulationTime* simulation_time) { InitializeForceAndTorque(); InitializeAcceleration(); @@ -48,16 +51,16 @@ void Disturbances::Update(const LocalEnvironment& local_environment, const Dynam } } -void Disturbances::LogSetup(Logger& logger) { +void Disturbances::LogSetup(logger::Logger& logger) { for (auto disturbance : disturbances_list_) { logger.AddLogList(disturbance); } logger.CopyFileToLogDirectory(initialize_file_name_); } -void Disturbances::InitializeInstances(const SimulationConfiguration* simulation_configuration, const int spacecraft_id, const Structure* structure, - const GlobalEnvironment* global_environment) { - IniAccess ini_access = IniAccess(simulation_configuration->spacecraft_file_list_[spacecraft_id]); +void Disturbances::InitializeInstances(const simulation::SimulationConfiguration* simulation_configuration, const int spacecraft_id, + const spacecraft::Structure* structure, const environment::GlobalEnvironment* global_environment) { + setting_file_reader::IniAccess ini_access = setting_file_reader::IniAccess(simulation_configuration->spacecraft_file_list_[spacecraft_id]); initialize_file_name_ = ini_access.ReadString("SETTING_FILES", "disturbance_file"); GravityGradient* gg_dist = new GravityGradient( @@ -91,8 +94,10 @@ void Disturbances::InitializeInstances(const SimulationConfiguration* simulation } void Disturbances::InitializeForceAndTorque() { - total_torque_b_Nm_ = Vector<3>(0.0); - total_force_b_N_ = Vector<3>(0.0); + total_torque_b_Nm_ = math::Vector<3>(0.0); + total_force_b_N_ = math::Vector<3>(0.0); } -void Disturbances::InitializeAcceleration() { total_acceleration_i_m_s2_ = Vector<3>(0.0); } +void Disturbances::InitializeAcceleration() { total_acceleration_i_m_s2_ = math::Vector<3>(0.0); } + +} // namespace s2e::disturbances diff --git a/src/disturbances/disturbances.hpp b/src/disturbances/disturbances.hpp index 62af465ba..6e242e058 100644 --- a/src/disturbances/disturbances.hpp +++ b/src/disturbances/disturbances.hpp @@ -14,6 +14,8 @@ class Logger; +namespace s2e::disturbances { + /** * @class Disturbances * @brief Class to manage all disturbances @@ -28,8 +30,8 @@ class Disturbances { * @param [in] structure: Structure information of spacecraft * @param [in] global_environment: Global environment information */ - Disturbances(const SimulationConfiguration* simulation_configuration, const int spacecraft_id, const Structure* structure, - const GlobalEnvironment* global_environment); + Disturbances(const simulation::SimulationConfiguration* simulation_configuration, const int spacecraft_id, const spacecraft::Structure* structure, + const environment::GlobalEnvironment* global_environment); /** * @fn ~Disturbances * @brief Destructor @@ -40,16 +42,17 @@ class Disturbances { * @fn Update * @brief Update all disturbance calculation * @param [in] local_environment: Local environment information - * @param [in] dynamics: Dynamics information + * @param [in] dynamics: dynamics::Dynamics information * @param [in] simulation_time: Simulation time */ - void Update(const LocalEnvironment& local_environment, const Dynamics& dynamics, const SimulationTime* simulation_time); + void Update(const environment::LocalEnvironment& local_environment, const dynamics::Dynamics& dynamics, + const environment::SimulationTime* simulation_time); /** * @fn LogSetup * @brief log setup for all disturbances * @param [in] logger: Logger */ - void LogSetup(Logger& logger); + void LogSetup(logger::Logger& logger); /** * @fn GetTorque @@ -73,9 +76,9 @@ class Disturbances { std::string initialize_file_name_; //!< Initialization file name std::vector disturbances_list_; //!< List of disturbances - Vector<3> total_torque_b_Nm_; //!< Total disturbance torque in the body frame [Nm] - Vector<3> total_force_b_N_; //!< Total disturbance force in the body frame [N] - Vector<3> total_acceleration_i_m_s2_; //!< Total disturbance acceleration in the inertial frame [m/s2] + math::Vector<3> total_torque_b_Nm_; //!< Total disturbance torque in the body frame [Nm] + math::Vector<3> total_force_b_N_; //!< Total disturbance force in the body frame [N] + math::Vector<3> total_acceleration_i_m_s2_; //!< Total disturbance acceleration in the inertial frame [m/s2] /** * @fn InitializeInstances @@ -85,8 +88,8 @@ class Disturbances { * @param [in] structure: Structure information of spacecraft * @param [in] global_environment: Global environment information */ - void InitializeInstances(const SimulationConfiguration* simulation_configuration, const int spacecraft_id, const Structure* structure, - const GlobalEnvironment* global_environment); + void InitializeInstances(const simulation::SimulationConfiguration* simulation_configuration, const int spacecraft_id, + const spacecraft::Structure* structure, const environment::GlobalEnvironment* global_environment); /** * @fn InitializeForceAndTorque * @brief Initialize disturbance force and torque @@ -99,4 +102,6 @@ class Disturbances { void InitializeAcceleration(); }; +} // namespace s2e::disturbances + #endif // S2E_DISTURBANCES_DISTURBANCES_HPP_ diff --git a/src/disturbances/geopotential.cpp b/src/disturbances/geopotential.cpp index 70b7cb534..cb6ba222c 100644 --- a/src/disturbances/geopotential.cpp +++ b/src/disturbances/geopotential.cpp @@ -15,6 +15,8 @@ #include "../logger/log_utility.hpp" #include "../utilities/macros.hpp" +namespace s2e::disturbances { + // #define DEBUG_GEOPOTENTIAL Geopotential::Geopotential(const int degree, const std::string file_path, const bool is_calculation_enabled) @@ -68,7 +70,7 @@ bool Geopotential::ReadCoefficientsEgm96(std::string file_name) { return true; } -void Geopotential::Update(const LocalEnvironment &local_environment, const Dynamics &dynamics) { +void Geopotential::Update(const environment::LocalEnvironment &local_environment, const dynamics::Dynamics &dynamics) { #ifdef DEBUG_GEOPOTENTIAL chrono::system_clock::time_point start, end; start = chrono::system_clock::now(); @@ -92,10 +94,10 @@ std::string Geopotential::GetLogHeader() const { std::string str_tmp = ""; #ifdef DEBUG_GEOPOTENTIAL - str_tmp += WriteVector("geopotential_calculation_position_", "ecef", "m", 3); - str_tmp += WriteScalar("geopotential_calculation_time", "ms"); + str_tmp += logger::WriteVector("geopotential_calculation_position_", "ecef", "m", 3); + str_tmp += logger::WriteScalar("geopotential_calculation_time", "ms"); #endif - str_tmp += WriteVector("geopotential_acceleration", "ecef", "m/s2", 3); + str_tmp += logger::WriteVector("geopotential_acceleration", "ecef", "m/s2", 3); return str_tmp; } @@ -104,17 +106,17 @@ std::string Geopotential::GetLogValue() const { std::string str_tmp = ""; #ifdef DEBUG_GEOPOTENTIAL - str_tmp += WriteVector(debug_pos_ecef_m_, 15); - str_tmp += WriteScalar(time_ms_); + str_tmp += logger::WriteVector(debug_pos_ecef_m_, 15); + str_tmp += logger::WriteScalar(time_ms_); #endif - str_tmp += WriteVector(acceleration_ecef_m_s2_, 15); + str_tmp += logger::WriteVector(acceleration_ecef_m_s2_, 15); return str_tmp; } Geopotential InitGeopotential(const std::string initialize_file_path) { - auto conf = IniAccess(initialize_file_path); + auto conf = setting_file_reader::IniAccess(initialize_file_path); const char *section = "GEOPOTENTIAL"; const int degree = conf.ReadInt(section, "degree"); @@ -125,4 +127,6 @@ Geopotential InitGeopotential(const std::string initialize_file_path) { geopotential_disturbance.is_log_enabled_ = conf.ReadEnable(section, INI_LOG_LABEL); return geopotential_disturbance; -} \ No newline at end of file +} + +} // namespace s2e::disturbances diff --git a/src/disturbances/geopotential.hpp b/src/disturbances/geopotential.hpp index 4903cb412..13be1f20c 100644 --- a/src/disturbances/geopotential.hpp +++ b/src/disturbances/geopotential.hpp @@ -11,6 +11,9 @@ #include "../math_physics/gravity/gravity_potential.hpp" #include "../math_physics/math/vector.hpp" #include "disturbance.hpp" + +namespace s2e::disturbances { + /** * @class Geopotential * @brief Class to calculate the high-order earth gravity acceleration @@ -43,28 +46,28 @@ class Geopotential : public Disturbance { * @fn Update * @brief Override Updates function of SimpleDisturbance * @param [in] local_environment: Local environment information - * @param [in] dynamics: Dynamics information + * @param [in] dynamics: dynamics::Dynamics information */ - virtual void Update(const LocalEnvironment &local_environment, const Dynamics &dynamics); + virtual void Update(const environment::LocalEnvironment &local_environment, const dynamics::Dynamics &dynamics); - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; private: - gravity::GravityPotential geopotential_; - size_t degree_; //!< Maximum degree setting to calculate the geo-potential - std::vector> c_; //!< Cosine coefficients - std::vector> s_; //!< Sine coefficients - Vector<3> acceleration_ecef_m_s2_; //!< Calculated acceleration in the ECEF frame [m/s2] + s2e::gravity::GravityPotential geopotential_; + size_t degree_; //!< Maximum degree setting to calculate the geo-potential + std::vector> c_; //!< Cosine coefficients + std::vector> s_; //!< Sine coefficients + math::Vector<3> acceleration_ecef_m_s2_; //!< Calculated acceleration in the ECEF frame [m/s2] // debug math::Vector<3> debug_pos_ecef_m_; //!< Spacecraft position in ECEF frame [m] @@ -85,4 +88,6 @@ class Geopotential : public Disturbance { */ Geopotential InitGeopotential(const std::string initialize_file_path); +} // namespace s2e::disturbances + #endif // S2E_DISTURBANCES_GEOPOTENTIAL_HPP_ diff --git a/src/disturbances/gravity_gradient.cpp b/src/disturbances/gravity_gradient.cpp index b52b4bee5..bf1b0ff1a 100644 --- a/src/disturbances/gravity_gradient.cpp +++ b/src/disturbances/gravity_gradient.cpp @@ -11,13 +11,15 @@ #include "../logger/log_utility.hpp" +namespace s2e::disturbances { + GravityGradient::GravityGradient(const bool is_calculation_enabled) : GravityGradient(environment::earth_gravitational_constant_m3_s2, is_calculation_enabled) {} GravityGradient::GravityGradient(const double gravity_constant_m3_s2, const bool is_calculation_enabled) : Disturbance(is_calculation_enabled, true), gravity_constant_m3_s2_(gravity_constant_m3_s2) {} -void GravityGradient::Update(const LocalEnvironment& local_environment, const Dynamics& dynamics) { +void GravityGradient::Update(const environment::LocalEnvironment& local_environment, const dynamics::Dynamics& dynamics) { // TODO: use structure information to get inertia tensor CalcTorque_b_Nm(local_environment.GetCelestialInformation().GetCenterBodyPositionFromSpacecraft_b_m(), dynamics.GetAttitude().GetInertiaTensor_b_kgm2()); @@ -36,7 +38,7 @@ math::Vector<3> GravityGradient::CalcTorque_b_Nm(const math::Vector<3> earth_pos std::string GravityGradient::GetLogHeader() const { std::string str_tmp = ""; - str_tmp += WriteVector("gravity_gradient_torque", "b", "Nm", 3); + str_tmp += logger::WriteVector("gravity_gradient_torque", "b", "Nm", 3); return str_tmp; } @@ -44,13 +46,13 @@ std::string GravityGradient::GetLogHeader() const { std::string GravityGradient::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteVector(torque_b_Nm_); + str_tmp += logger::WriteVector(torque_b_Nm_); return str_tmp; } GravityGradient InitGravityGradient(const std::string initialize_file_path) { - auto conf = IniAccess(initialize_file_path); + auto conf = setting_file_reader::IniAccess(initialize_file_path); const char* section = "GRAVITY_GRADIENT"; const bool is_calc_enable = conf.ReadEnable(section, INI_CALC_LABEL); @@ -61,7 +63,7 @@ GravityGradient InitGravityGradient(const std::string initialize_file_path) { } GravityGradient InitGravityGradient(const std::string initialize_file_path, const double gravity_constant_m3_s2) { - auto conf = IniAccess(initialize_file_path); + auto conf = setting_file_reader::IniAccess(initialize_file_path); const char* section = "GRAVITY_GRADIENT"; const bool is_calc_enable = conf.ReadEnable(section, INI_CALC_LABEL); @@ -70,3 +72,5 @@ GravityGradient InitGravityGradient(const std::string initialize_file_path, cons return gg_disturbance; } + +} // namespace s2e::disturbances diff --git a/src/disturbances/gravity_gradient.hpp b/src/disturbances/gravity_gradient.hpp index be957e19c..4a5f99e65 100644 --- a/src/disturbances/gravity_gradient.hpp +++ b/src/disturbances/gravity_gradient.hpp @@ -14,6 +14,8 @@ #include "../math_physics/math/vector.hpp" #include "disturbance.hpp" +namespace s2e::disturbances { + /** * @class GravityGradient * @brief Class to calculate the gravity gradient torque @@ -39,19 +41,19 @@ class GravityGradient : public Disturbance { * @fn Update * @brief Override Updates function of SimpleDisturbance * @param [in] local_environment: Local environment information - * @param [in] dynamics: Dynamics information + * @param [in] dynamics: dynamics::Dynamics information */ - virtual void Update(const LocalEnvironment& local_environment, const Dynamics& dynamics); + virtual void Update(const environment::LocalEnvironment& local_environment, const dynamics::Dynamics& dynamics); - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; @@ -83,4 +85,6 @@ GravityGradient InitGravityGradient(const std::string initialize_file_path); */ GravityGradient InitGravityGradient(const std::string initialize_file_path, const double gravity_constant_m3_s2); +} // namespace s2e::disturbances + #endif // S2E_DISTURBANCES_GRAVITY_GRADIENT_HPP_ diff --git a/src/disturbances/lunar_gravity_field.cpp b/src/disturbances/lunar_gravity_field.cpp index bad7c5f7c..182b4472d 100644 --- a/src/disturbances/lunar_gravity_field.cpp +++ b/src/disturbances/lunar_gravity_field.cpp @@ -15,6 +15,8 @@ #include "../logger/log_utility.hpp" #include "../utilities/macros.hpp" +namespace s2e::disturbances { + // #define DEBUG_LUNAR_GRAVITY_FIELD LunarGravityField::LunarGravityField(const int degree, const std::string file_path, const bool is_calculation_enabled) @@ -86,8 +88,8 @@ bool LunarGravityField::ReadCoefficientsGrgm1200a(std::string file_name) { return true; } -void LunarGravityField::Update(const LocalEnvironment &local_environment, const Dynamics &dynamics) { - const CelestialInformation global_celestial_information = local_environment.GetCelestialInformation().GetGlobalInformation(); +void LunarGravityField::Update(const environment::LocalEnvironment &local_environment, const dynamics::Dynamics &dynamics) { + const environment::CelestialInformation global_celestial_information = local_environment.GetCelestialInformation().GetGlobalInformation(); math::Matrix<3, 3> dcm_mci2mcmf_ = global_celestial_information.GetMoonRotation().GetDcmJ2000ToMcmf(); math::Vector<3> spacecraft_position_mci_m = dynamics.GetOrbit().GetPosition_i_m(); @@ -115,10 +117,10 @@ std::string LunarGravityField::GetLogHeader() const { std::string str_tmp = ""; #ifdef DEBUG_LUNAR_GRAVITY_FIELD - str_tmp += WriteVector("lunar_gravity_calculation_position", "mcmf", "m", 3); - str_tmp += WriteScalar("lunar_gravity_calculation_time", "ms"); + str_tmp += logger::WriteVector("lunar_gravity_calculation_position", "mcmf", "m", 3); + str_tmp += logger::WriteScalar("lunar_gravity_calculation_time", "ms"); #endif - str_tmp += WriteVector("lunar_gravity_acceleration", "mcmf", "m/s2", 3); + str_tmp += logger::WriteVector("lunar_gravity_acceleration", "mcmf", "m/s2", 3); return str_tmp; } @@ -127,17 +129,17 @@ std::string LunarGravityField::GetLogValue() const { std::string str_tmp = ""; #ifdef DEBUG_LUNAR_GRAVITY_FIELD - str_tmp += WriteVector(debug_pos_mcmf_m_, 15); - str_tmp += WriteScalar(time_ms_); + str_tmp += logger::WriteVector(debug_pos_mcmf_m_, 15); + str_tmp += logger::WriteScalar(time_ms_); #endif - str_tmp += WriteVector(acceleration_mcmf_m_s2_, 15); + str_tmp += logger::WriteVector(acceleration_mcmf_m_s2_, 15); return str_tmp; } LunarGravityField InitLunarGravityField(const std::string initialize_file_path) { - auto conf = IniAccess(initialize_file_path); + auto conf = setting_file_reader::IniAccess(initialize_file_path); const char *section = "LUNAR_GRAVITY_FIELD"; const int degree = conf.ReadInt(section, "degree"); @@ -150,3 +152,5 @@ LunarGravityField InitLunarGravityField(const std::string initialize_file_path) return lunar_gravity_field; } + +} // namespace s2e::disturbances diff --git a/src/disturbances/lunar_gravity_field.hpp b/src/disturbances/lunar_gravity_field.hpp index f1fa27c57..04727d670 100644 --- a/src/disturbances/lunar_gravity_field.hpp +++ b/src/disturbances/lunar_gravity_field.hpp @@ -11,6 +11,9 @@ #include "../math_physics/gravity/gravity_potential.hpp" #include "../math_physics/math/vector.hpp" #include "disturbance.hpp" + +namespace s2e::disturbances { + /** * @class LunarGravityField * @brief Class to calculate the high-order earth gravity acceleration @@ -45,19 +48,19 @@ class LunarGravityField : public Disturbance { * @fn Update * @brief Override Updates function of SimpleDisturbance * @param [in] local_environment: Local environment information - * @param [in] dynamics: Dynamics information + * @param [in] dynamics: dynamics::Dynamics information */ - virtual void Update(const LocalEnvironment &local_environment, const Dynamics &dynamics); + virtual void Update(const environment::LocalEnvironment &local_environment, const dynamics::Dynamics &dynamics); - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; @@ -65,10 +68,10 @@ class LunarGravityField : public Disturbance { gravity::GravityPotential lunar_potential_; double reference_radius_km_; double gravity_constants_km3_s2_; - size_t degree_; //!< Maximum degree setting to calculate the geo-potential - std::vector> c_; //!< Cosine coefficients - std::vector> s_; //!< Sine coefficients - Vector<3> acceleration_mcmf_m_s2_; //!< Calculated acceleration in the MCMF(Moon Centered Moon Fixed) frame [m/s2] + size_t degree_; //!< Maximum degree setting to calculate the geo-potential + std::vector> c_; //!< Cosine coefficients + std::vector> s_; //!< Sine coefficients + math::Vector<3> acceleration_mcmf_m_s2_; //!< Calculated acceleration in the MCMF(Moon Centered Moon Fixed) frame [m/s2] // debug math::Vector<3> debug_pos_mcmf_m_; //!< Spacecraft position in MCMF frame [m] @@ -89,4 +92,6 @@ class LunarGravityField : public Disturbance { */ LunarGravityField InitLunarGravityField(const std::string initialize_file_path); +} // namespace s2e::disturbances + #endif // S2E_DISTURBANCES_LUNAR_GRAVITY_FIELD_HPP_ diff --git a/src/disturbances/magnetic_disturbance.cpp b/src/disturbances/magnetic_disturbance.cpp index 901777c6a..ea0029218 100644 --- a/src/disturbances/magnetic_disturbance.cpp +++ b/src/disturbances/magnetic_disturbance.cpp @@ -13,18 +13,20 @@ #include "../math_physics/randomization/normal_randomization.hpp" #include "../math_physics/randomization/random_walk.hpp" -MagneticDisturbance::MagneticDisturbance(const ResidualMagneticMoment& rmm_params, const bool is_calculation_enabled) +namespace s2e::disturbances { + +MagneticDisturbance::MagneticDisturbance(const spacecraft::ResidualMagneticMoment& rmm_params, const bool is_calculation_enabled) : Disturbance(is_calculation_enabled, true), residual_magnetic_moment_(rmm_params) { rmm_b_Am2_ = residual_magnetic_moment_.GetConstantValue_b_Am2(); } -Vector<3> MagneticDisturbance::CalcTorque_b_Nm(const Vector<3>& magnetic_field_b_nT) { +math::Vector<3> MagneticDisturbance::CalcTorque_b_Nm(const math::Vector<3>& magnetic_field_b_nT) { CalcRMM(); - torque_b_Nm_ = kMagUnit_ * OuterProduct(rmm_b_Am2_, magnetic_field_b_nT); + torque_b_Nm_ = kMagUnit_ * math::OuterProduct(rmm_b_Am2_, magnetic_field_b_nT); return torque_b_Nm_; } -void MagneticDisturbance::Update(const LocalEnvironment& local_environment, const Dynamics& dynamics) { +void MagneticDisturbance::Update(const environment::LocalEnvironment& local_environment, const dynamics::Dynamics& dynamics) { UNUSED(dynamics); CalcTorque_b_Nm(local_environment.GetGeomagneticField().GetGeomagneticField_b_nT()); @@ -33,9 +35,9 @@ void MagneticDisturbance::Update(const LocalEnvironment& local_environment, cons void MagneticDisturbance::CalcRMM() { static math::Vector<3> random_walk_std_dev(residual_magnetic_moment_.GetRandomWalkStandardDeviation_Am2()); static math::Vector<3> random_walk_limit(residual_magnetic_moment_.GetRandomWalkLimit_Am2()); - static RandomWalk<3> random_walk(0.1, random_walk_std_dev, random_walk_limit); // [FIXME] step width is constant + static randomization::RandomWalk<3> random_walk(0.1, random_walk_std_dev, random_walk_limit); // [FIXME] step width is constant static randomization::NormalRand normal_random(0.0, residual_magnetic_moment_.GetRandomNoiseStandardDeviation_Am2(), - global_randomization.MakeSeed()); + randomization::global_randomization.MakeSeed()); rmm_b_Am2_ = residual_magnetic_moment_.GetConstantValue_b_Am2(); for (int i = 0; i < 3; ++i) { @@ -47,8 +49,8 @@ void MagneticDisturbance::CalcRMM() { std::string MagneticDisturbance::GetLogHeader() const { std::string str_tmp = ""; - str_tmp += WriteVector("spacecraft_magnetic_moment", "b", "Am2", 3); - str_tmp += WriteVector("magnetic_disturbance_torque", "b", "Nm", 3); + str_tmp += logger::WriteVector("spacecraft_magnetic_moment", "b", "Am2", 3); + str_tmp += logger::WriteVector("magnetic_disturbance_torque", "b", "Nm", 3); return str_tmp; } @@ -56,14 +58,14 @@ std::string MagneticDisturbance::GetLogHeader() const { std::string MagneticDisturbance::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteVector(rmm_b_Am2_); - str_tmp += WriteVector(torque_b_Nm_); + str_tmp += logger::WriteVector(rmm_b_Am2_); + str_tmp += logger::WriteVector(torque_b_Nm_); return str_tmp; } -MagneticDisturbance InitMagneticDisturbance(const std::string initialize_file_path, const ResidualMagneticMoment& rmm_params) { - auto conf = IniAccess(initialize_file_path); +MagneticDisturbance InitMagneticDisturbance(const std::string initialize_file_path, const spacecraft::ResidualMagneticMoment& rmm_params) { + auto conf = setting_file_reader::IniAccess(initialize_file_path); const char* section = "MAGNETIC_DISTURBANCE"; const bool is_calc_enable = conf.ReadEnable(section, INI_CALC_LABEL); @@ -72,3 +74,5 @@ MagneticDisturbance InitMagneticDisturbance(const std::string initialize_file_pa return mag_disturbance; } + +} // namespace s2e::disturbances diff --git a/src/disturbances/magnetic_disturbance.hpp b/src/disturbances/magnetic_disturbance.hpp index 80aea05e3..f51b3924b 100644 --- a/src/disturbances/magnetic_disturbance.hpp +++ b/src/disturbances/magnetic_disturbance.hpp @@ -13,6 +13,8 @@ #include "../simulation/spacecraft/structure/residual_magnetic_moment.hpp" #include "disturbance.hpp" +namespace s2e::disturbances { + /** * @class MagneticDisturbance * @brief Class to calculate the magnetic disturbance torque @@ -25,33 +27,33 @@ class MagneticDisturbance : public Disturbance { * @param [in] rmm_parameters: RMM parameters of the spacecraft * @param [in] is_calculation_enabled: Calculation flag */ - MagneticDisturbance(const ResidualMagneticMoment& rmm_parameters, const bool is_calculation_enabled = true); + MagneticDisturbance(const spacecraft::ResidualMagneticMoment& rmm_parameters, const bool is_calculation_enabled = true); /** * @fn Update * @brief Override Updates function of SimpleDisturbance * @param [in] local_environment: Local environment information - * @param [in] dynamics: Dynamics information + * @param [in] dynamics: dynamics::Dynamics information */ - virtual void Update(const LocalEnvironment& local_environment, const Dynamics& dynamics); + virtual void Update(const environment::LocalEnvironment& local_environment, const dynamics::Dynamics& dynamics); - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; private: const double kMagUnit_ = 1.0e-9; //!< Constant value to change the unit [nT] -> [T] - math::Vector<3> rmm_b_Am2_; //!< True RMM of the spacecraft in the body frame [Am2] - const ResidualMagneticMoment& residual_magnetic_moment_; //!< RMM parameters + math::Vector<3> rmm_b_Am2_; //!< True RMM of the spacecraft in the body frame [Am2] + const spacecraft::ResidualMagneticMoment& residual_magnetic_moment_; //!< RMM parameters /** * @fn CalcRMM @@ -73,6 +75,8 @@ class MagneticDisturbance : public Disturbance { * @param [in] initialize_file_path: Initialize file path * @param [in] rmm_params: RMM parameters */ -MagneticDisturbance InitMagneticDisturbance(const std::string initialize_file_path, const ResidualMagneticMoment& rmm_params); +MagneticDisturbance InitMagneticDisturbance(const std::string initialize_file_path, const spacecraft::ResidualMagneticMoment& rmm_params); + +} // namespace s2e::disturbances #endif // S2E_DISTURBANCES_MAGNETIC_DISTURBANCE_HPP_ diff --git a/src/disturbances/solar_radiation_pressure_disturbance.cpp b/src/disturbances/solar_radiation_pressure_disturbance.cpp index b07d2a858..369048683 100644 --- a/src/disturbances/solar_radiation_pressure_disturbance.cpp +++ b/src/disturbances/solar_radiation_pressure_disturbance.cpp @@ -10,11 +10,13 @@ #include "../logger/log_utility.hpp" -SolarRadiationPressureDisturbance::SolarRadiationPressureDisturbance(const std::vector& surfaces, +namespace s2e::disturbances { + +SolarRadiationPressureDisturbance::SolarRadiationPressureDisturbance(const std::vector& surfaces, const math::Vector<3>& center_of_gravity_b_m, const bool is_calculation_enabled) : SurfaceForce(surfaces, center_of_gravity_b_m, is_calculation_enabled) {} -void SolarRadiationPressureDisturbance::Update(const LocalEnvironment& local_environment, const Dynamics& dynamics) { +void SolarRadiationPressureDisturbance::Update(const environment::LocalEnvironment& local_environment, const dynamics::Dynamics& dynamics) { UNUSED(dynamics); math::Vector<3> sun_position_from_sc_b_m = local_environment.GetCelestialInformation().GetPositionFromSpacecraft_b_m("SUN"); @@ -37,8 +39,8 @@ void SolarRadiationPressureDisturbance::CalcCoefficients(const math::Vector<3>& std::string SolarRadiationPressureDisturbance::GetLogHeader() const { std::string str_tmp = ""; - str_tmp += WriteVector("srp_torque", "b", "Nm", 3); - str_tmp += WriteVector("srp_force", "b", "N", 3); + str_tmp += logger::WriteVector("srp_torque", "b", "Nm", 3); + str_tmp += logger::WriteVector("srp_force", "b", "N", 3); return str_tmp; } @@ -46,15 +48,16 @@ std::string SolarRadiationPressureDisturbance::GetLogHeader() const { std::string SolarRadiationPressureDisturbance::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteVector(torque_b_Nm_); - str_tmp += WriteVector(force_b_N_); + str_tmp += logger::WriteVector(torque_b_Nm_); + str_tmp += logger::WriteVector(force_b_N_); return str_tmp; } -SolarRadiationPressureDisturbance InitSolarRadiationPressureDisturbance(const std::string initialize_file_path, const std::vector& surfaces, - const Vector<3>& center_of_gravity_b_m) { - auto conf = IniAccess(initialize_file_path); +SolarRadiationPressureDisturbance InitSolarRadiationPressureDisturbance(const std::string initialize_file_path, + const std::vector& surfaces, + const math::Vector<3>& center_of_gravity_b_m) { + auto conf = setting_file_reader::IniAccess(initialize_file_path); const char* section = "SOLAR_RADIATION_PRESSURE_DISTURBANCE"; const bool is_calc_enable = conf.ReadEnable(section, INI_CALC_LABEL); @@ -65,3 +68,5 @@ SolarRadiationPressureDisturbance InitSolarRadiationPressureDisturbance(const st return srp_disturbance; } + +} // namespace s2e::disturbances diff --git a/src/disturbances/solar_radiation_pressure_disturbance.hpp b/src/disturbances/solar_radiation_pressure_disturbance.hpp index 7ec4e9bbc..8f2d22f82 100644 --- a/src/disturbances/solar_radiation_pressure_disturbance.hpp +++ b/src/disturbances/solar_radiation_pressure_disturbance.hpp @@ -12,6 +12,8 @@ #include "../math_physics/math/vector.hpp" #include "surface_force.hpp" +namespace s2e::disturbances { + /** * @class SolarRadiationPressureDisturbance * @brief Class to calculate the solar radiation pressure disturbance force and torque @@ -25,26 +27,26 @@ class SolarRadiationPressureDisturbance : public SurfaceForce { * @param [in] center_of_gravity_b_m: Center of gravity position at the body frame [m] * @param [in] is_calculation_enabled: Calculation flag */ - SolarRadiationPressureDisturbance(const std::vector& surfaces, const math::Vector<3>& center_of_gravity_b_m, + SolarRadiationPressureDisturbance(const std::vector& surfaces, const math::Vector<3>& center_of_gravity_b_m, const bool is_calculation_enabled = true); /** * @fn Update * @brief Override Updates function of SimpleDisturbance * @param [in] local_environment: Local environment information - * @param [in] dynamics: Dynamics information + * @param [in] dynamics: dynamics::Dynamics information */ - virtual void Update(const LocalEnvironment& local_environment, const Dynamics& dynamics); + virtual void Update(const environment::LocalEnvironment& local_environment, const dynamics::Dynamics& dynamics); - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; @@ -65,7 +67,10 @@ class SolarRadiationPressureDisturbance : public SurfaceForce { * @param [in] surfaces: surface information of the spacecraft * @param [in] center_of_gravity_b_m: Center of gravity position vector at body frame [m] */ -SolarRadiationPressureDisturbance InitSolarRadiationPressureDisturbance(const std::string initialize_file_path, const std::vector& surfaces, - const Vector<3>& center_of_gravity_b_m); +SolarRadiationPressureDisturbance InitSolarRadiationPressureDisturbance(const std::string initialize_file_path, + const std::vector& surfaces, + const math::Vector<3>& center_of_gravity_b_m); + +} // namespace s2e::disturbances #endif // S2E_DISTURBANCES_SOLAR_RADIATION_PRESSURE_DISTURBANCE_HPP_ diff --git a/src/disturbances/surface_force.cpp b/src/disturbances/surface_force.cpp index 348944267..391a78274 100644 --- a/src/disturbances/surface_force.cpp +++ b/src/disturbances/surface_force.cpp @@ -7,7 +7,10 @@ #include "../math_physics/math/vector.hpp" -SurfaceForce::SurfaceForce(const std::vector& surfaces, const math::Vector<3>& center_of_gravity_b_m, const bool is_calculation_enabled) +namespace s2e::disturbances { + +SurfaceForce::SurfaceForce(const std::vector& surfaces, const math::Vector<3>& center_of_gravity_b_m, + const bool is_calculation_enabled) : Disturbance(is_calculation_enabled, true), surfaces_(surfaces), center_of_gravity_b_m_(center_of_gravity_b_m) { // Initialize vectors size_t num = surfaces_.size(); @@ -52,3 +55,5 @@ void SurfaceForce::CalcTheta(math::Vector<3>& input_direction_b) { sin_theta_[i] = sqrt(1.0 - cos_theta_[i] * cos_theta_[i]); } } + +} // namespace s2e::disturbances diff --git a/src/disturbances/surface_force.hpp b/src/disturbances/surface_force.hpp index 2fa4a0ac3..36af265a5 100644 --- a/src/disturbances/surface_force.hpp +++ b/src/disturbances/surface_force.hpp @@ -15,6 +15,8 @@ #include "../simulation/spacecraft/structure/surface.hpp" #include "disturbance.hpp" +namespace s2e::disturbances { + /** * @class ThirdBodyGravity * @brief Class to calculate third body gravity disturbance @@ -28,7 +30,8 @@ class SurfaceForce : public Disturbance { * @param [in] center_of_gravity_b_m: Center of gravity position at the body frame [m] * @param [in] is_calculation_enabled: Calculation flag */ - SurfaceForce(const std::vector& surfaces, const math::Vector<3>& center_of_gravity_b_m, const bool is_calculation_enabled = true); + SurfaceForce(const std::vector& surfaces, const math::Vector<3>& center_of_gravity_b_m, + const bool is_calculation_enabled = true); /** * @fn ~SurfaceForce * @brief Destructor @@ -37,8 +40,8 @@ class SurfaceForce : public Disturbance { protected: // Spacecraft Structure parameters - const std::vector& surfaces_; //!< List of surfaces - const math::Vector<3>& center_of_gravity_b_m_; //!< Position vector of the center of mass_kg at body frame [m] + const std::vector& surfaces_; //!< List of surfaces + const math::Vector<3>& center_of_gravity_b_m_; //!< Position vector of the center of mass_kg at body frame [m] // Internal calculated variables std::vector normal_coefficients_; //!< coefficients for out-plane force for each surface @@ -71,4 +74,6 @@ class SurfaceForce : public Disturbance { virtual void CalcCoefficients(const math::Vector<3>& input_direction_b, const double item) = 0; }; +} // namespace s2e::disturbances + #endif // S2E_DISTURBANCES_SURFACE_FORCE_HPP_ diff --git a/src/disturbances/third_body_gravity.cpp b/src/disturbances/third_body_gravity.cpp index 72bb2d24f..9e2d6881c 100644 --- a/src/disturbances/third_body_gravity.cpp +++ b/src/disturbances/third_body_gravity.cpp @@ -7,6 +7,8 @@ #include +namespace s2e::disturbances { + ThirdBodyGravity::ThirdBodyGravity(std::set third_body_list, const bool is_calculation_enabled) : Disturbance(is_calculation_enabled, false), third_body_list_(third_body_list) { acceleration_i_m_s2_ = math::Vector<3>(0.0); @@ -14,7 +16,7 @@ ThirdBodyGravity::ThirdBodyGravity(std::set third_body_list, const ThirdBodyGravity::~ThirdBodyGravity() {} -void ThirdBodyGravity::Update(const LocalEnvironment& local_environment, const Dynamics& dynamics) { +void ThirdBodyGravity::Update(const environment::LocalEnvironment& local_environment, const dynamics::Dynamics& dynamics) { acceleration_i_m_s2_ = math::Vector<3>(0.0); // initialize math::Vector<3> sc_position_i_m = dynamics.GetOrbit().GetPosition_i_m(); @@ -44,21 +46,21 @@ math::Vector<3> ThirdBodyGravity::CalcAcceleration_i_m_s2(const math::Vector<3> std::string ThirdBodyGravity::GetLogHeader() const { std::string str_tmp = ""; - str_tmp += WriteVector("third_body_acceleration", "i", "m/s2", 3); + str_tmp += logger::WriteVector("third_body_acceleration", "i", "m/s2", 3); return str_tmp; } std::string ThirdBodyGravity::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteVector(acceleration_i_m_s2_); + str_tmp += logger::WriteVector(acceleration_i_m_s2_); return str_tmp; } ThirdBodyGravity InitThirdBodyGravity(const std::string initialize_file_path, const std::string ini_path_celes) { // Generate a list of bodies to be calculated in "CelesInfo" - auto conf_celes = IniAccess(ini_path_celes); + auto conf_celes = setting_file_reader::IniAccess(ini_path_celes); const char* section_celes = "CELESTIAL_INFORMATION"; const int num_of_selected_body = conf_celes.ReadInt(section_celes, "number_of_selected_body"); const std::string center_object = conf_celes.ReadString(section_celes, "center_object"); @@ -70,7 +72,7 @@ ThirdBodyGravity InitThirdBodyGravity(const std::string initialize_file_path, co } // Generate a list of bodies to be calculated in "ThirdBodyGravity" from the list of bodies of "CelesInfo" - auto conf = IniAccess(initialize_file_path); + auto conf = setting_file_reader::IniAccess(initialize_file_path); const char* section = "THIRD_BODY_GRAVITY"; const int num_of_third_body = conf.ReadInt(section, "number_of_third_body"); @@ -99,3 +101,5 @@ ThirdBodyGravity InitThirdBodyGravity(const std::string initialize_file_path, co return third_body_disturbance; } + +} // namespace s2e::disturbances diff --git a/src/disturbances/third_body_gravity.hpp b/src/disturbances/third_body_gravity.hpp index 12b9f8b68..bb45bec30 100644 --- a/src/disturbances/third_body_gravity.hpp +++ b/src/disturbances/third_body_gravity.hpp @@ -14,6 +14,8 @@ #include "../math_physics/math/vector.hpp" #include "disturbance.hpp" +namespace s2e::disturbances { + /** * @class ThirdBodyGravity * @brief Class to calculate third body gravity disturbance @@ -37,15 +39,15 @@ class ThirdBodyGravity : public Disturbance { * @fn Update * @brief Update third body disturbance * @param [in] local_environment: Local environment information - * @param [in] dynamics: Dynamics information + * @param [in] dynamics: dynamics::Dynamics information */ - virtual void Update(const LocalEnvironment& local_environment, const Dynamics& dynamics); + virtual void Update(const environment::LocalEnvironment& local_environment, const dynamics::Dynamics& dynamics); private: std::set third_body_list_; //!< List of celestial bodies to calculate the third body disturbances math::Vector<3> third_body_acceleration_i_m_s2_{0.0}; //!< Calculated third body disturbance acceleration in the inertial frame [m/s2] - // Override classes for ILoggable + // Override classes for logger::ILoggable /** * @fn GetLogHeader * @brief Override function of GetLogHeader @@ -76,4 +78,6 @@ class ThirdBodyGravity : public Disturbance { */ ThirdBodyGravity InitThirdBodyGravity(const std::string initialize_file_path, const std::string ini_path_celes); +} // namespace s2e::disturbances + #endif // S2E_DISTURBANCES_THIRD_BODY_GRAVITY_HPP_ diff --git a/src/dynamics/attitude/attitude.cpp b/src/dynamics/attitude/attitude.cpp index 461144660..86a6b2443 100644 --- a/src/dynamics/attitude/attitude.cpp +++ b/src/dynamics/attitude/attitude.cpp @@ -6,6 +6,8 @@ #include +namespace s2e::dynamics::attitude { + Attitude::Attitude(const math::Matrix<3, 3>& inertia_tensor_kgm2, const std::string& simulation_object_name) : SimulationObject(simulation_object_name), inertia_tensor_kgm2_(inertia_tensor_kgm2) { angular_velocity_b_rad_s_ = math::Vector<3>(0.0); @@ -22,11 +24,11 @@ Attitude::Attitude(const math::Matrix<3, 3>& inertia_tensor_kgm2, const std::str std::string Attitude::GetLogHeader() const { std::string str_tmp = ""; - str_tmp += WriteVector("spacecraft_angular_velocity", "b", "rad/s", 3); - str_tmp += WriteQuaternion("spacecraft_quaternion", "i2b"); - str_tmp += WriteVector("spacecraft_torque", "b", "Nm", 3); - str_tmp += WriteScalar("spacecraft_total_angular_momentum", "Nms"); - str_tmp += WriteScalar("spacecraft_kinematic_energy", "J"); + str_tmp += logger::WriteVector("spacecraft_angular_velocity", "b", "rad/s", 3); + str_tmp += logger::WriteQuaternion("spacecraft_quaternion", "i2b"); + str_tmp += logger::WriteVector("spacecraft_torque", "b", "Nm", 3); + str_tmp += logger::WriteScalar("spacecraft_total_angular_momentum", "Nms"); + str_tmp += logger::WriteScalar("spacecraft_kinematic_energy", "J"); return str_tmp; } @@ -34,16 +36,16 @@ std::string Attitude::GetLogHeader() const { std::string Attitude::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteVector(angular_velocity_b_rad_s_); - str_tmp += WriteQuaternion(quaternion_i2b_); - str_tmp += WriteVector(torque_b_Nm_); - str_tmp += WriteScalar(angular_momentum_total_Nms_); - str_tmp += WriteScalar(kinetic_energy_J_); + str_tmp += logger::WriteVector(angular_velocity_b_rad_s_); + str_tmp += logger::WriteQuaternion(quaternion_i2b_); + str_tmp += logger::WriteVector(torque_b_Nm_); + str_tmp += logger::WriteScalar(angular_momentum_total_Nms_); + str_tmp += logger::WriteScalar(kinetic_energy_J_); return str_tmp; } -void Attitude::SetParameters(const MonteCarloSimulationExecutor& mc_simulator) { +void Attitude::SetParameters(const simulation::MonteCarloSimulationExecutor& mc_simulator) { GetInitializedMonteCarloParameterQuaternion(mc_simulator, "quaternion_i2b", quaternion_i2b_); } @@ -79,3 +81,5 @@ math::Matrix<4, 4> CalcAngularVelocityMatrix(math::Vector<3> angular_velocity_b_ return angular_velocity_matrix; } + +} // namespace s2e::dynamics::attitude diff --git a/src/dynamics/attitude/attitude.hpp b/src/dynamics/attitude/attitude.hpp index 130040b88..59076b6ef 100644 --- a/src/dynamics/attitude/attitude.hpp +++ b/src/dynamics/attitude/attitude.hpp @@ -12,11 +12,13 @@ #include #include +namespace s2e::dynamics::attitude { + /** * @class Attitude * @brief Base class for attitude of spacecraft */ -class Attitude : public ILoggable, public SimulationObject { +class Attitude : public logger::ILoggable, public simulation::SimulationObject { public: /** * @fn Attitude @@ -98,20 +100,20 @@ class Attitude : public ILoggable, public SimulationObject { */ virtual void Propagate(const double end_time_s) = 0; - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; // SimulationObject for McSim - virtual void SetParameters(const MonteCarloSimulationExecutor& mc_simulator); + virtual void SetParameters(const simulation::MonteCarloSimulationExecutor& mc_simulator); protected: bool is_calc_enabled_ = true; //!< Calculation flag @@ -142,4 +144,6 @@ class Attitude : public ILoggable, public SimulationObject { */ math::Matrix<4, 4> CalcAngularVelocityMatrix(math::Vector<3> angular_velocity_b_rad_s); +} // namespace s2e::dynamics::attitude + #endif // S2E_DYNAMICS_ATTITUDE_ATTITUDE_HPP_ diff --git a/src/dynamics/attitude/attitude_rk4.cpp b/src/dynamics/attitude/attitude_rk4.cpp index 5ff72c44e..e432e665c 100644 --- a/src/dynamics/attitude/attitude_rk4.cpp +++ b/src/dynamics/attitude/attitude_rk4.cpp @@ -9,6 +9,8 @@ #include #include +namespace s2e::dynamics::attitude { + AttitudeRk4::AttitudeRk4(const math::Vector<3>& angular_velocity_b_rad_s, const math::Quaternion& quaternion_i2b, const math::Matrix<3, 3>& inertia_tensor_kgm2, const math::Vector<3>& torque_b_Nm, const double propagation_step_s, const std::string& simulation_object_name) @@ -26,7 +28,7 @@ AttitudeRk4::AttitudeRk4(const math::Vector<3>& angular_velocity_b_rad_s, const AttitudeRk4::~AttitudeRk4() {} -void AttitudeRk4::SetParameters(const MonteCarloSimulationExecutor& mc_simulator) { +void AttitudeRk4::SetParameters(const simulation::MonteCarloSimulationExecutor& mc_simulator) { Attitude::SetParameters(mc_simulator); GetInitializedMonteCarloParameterVector(mc_simulator, "angular_velocity_b_rad_s", angular_velocity_b_rad_s_); @@ -119,3 +121,5 @@ void AttitudeRk4::RungeKuttaOneStep(double t, double dt) { } quaternion_i2b_.Normalize(); } + +} // namespace s2e::dynamics::attitude diff --git a/src/dynamics/attitude/attitude_rk4.hpp b/src/dynamics/attitude/attitude_rk4.hpp index 5fe31d669..5924bd4cf 100644 --- a/src/dynamics/attitude/attitude_rk4.hpp +++ b/src/dynamics/attitude/attitude_rk4.hpp @@ -8,6 +8,8 @@ #include "attitude.hpp" +namespace s2e::dynamics::attitude { + /** * @class AttitudeRk4 * @brief Class to calculate spacecraft attitude with Runge-Kutta method @@ -44,7 +46,7 @@ class AttitudeRk4 : public Attitude { * @brief Set parameters for Monte-Carlo simulation * @param [in] mc_simulator: Monte-Carlo simulation executor */ - virtual void SetParameters(const MonteCarloSimulationExecutor& mc_simulator); + virtual void SetParameters(const simulation::MonteCarloSimulationExecutor& mc_simulator); private: double current_propagation_time_s_; //!< current time [sec] @@ -68,4 +70,6 @@ class AttitudeRk4 : public Attitude { void RungeKuttaOneStep(double t, double dt); }; +} // namespace s2e::dynamics::attitude + #endif // S2E_DYNAMICS_ATTITUDE_ATTITUDE_RK4_HPP_ diff --git a/src/dynamics/attitude/attitude_with_cantilever_vibration.cpp b/src/dynamics/attitude/attitude_with_cantilever_vibration.cpp index bb23cec85..bcda0d5c2 100644 --- a/src/dynamics/attitude/attitude_with_cantilever_vibration.cpp +++ b/src/dynamics/attitude/attitude_with_cantilever_vibration.cpp @@ -8,6 +8,8 @@ #include #include +namespace s2e::dynamics::attitude { + AttitudeWithCantileverVibration::AttitudeWithCantileverVibration( const math::Vector<3>& angular_velocity_b_rad_s, const math::Quaternion& quaternion_i2b, const math::Matrix<3, 3>& inertia_tensor_kgm2, const math::Matrix<3, 3>& inertia_tensor_cantilever_kgm2, const double damping_ratio_cantilever, @@ -44,8 +46,8 @@ AttitudeWithCantileverVibration::~AttitudeWithCantileverVibration() {} std::string AttitudeWithCantileverVibration::GetLogHeader() const { std::string str_tmp = Attitude::GetLogHeader(); - str_tmp += WriteVector("euler_angular_cantilever", "c", "rad", 3); - str_tmp += WriteVector("angular_velocity_cantilever", "c", "rad/s", 3); + str_tmp += logger::WriteVector("euler_angular_cantilever", "c", "rad", 3); + str_tmp += logger::WriteVector("angular_velocity_cantilever", "c", "rad/s", 3); return str_tmp; } @@ -53,13 +55,13 @@ std::string AttitudeWithCantileverVibration::GetLogHeader() const { std::string AttitudeWithCantileverVibration::GetLogValue() const { std::string str_tmp = Attitude::GetLogValue(); - str_tmp += WriteVector(euler_angular_cantilever_rad_); - str_tmp += WriteVector(angular_velocity_cantilever_rad_s_); + str_tmp += logger::WriteVector(euler_angular_cantilever_rad_); + str_tmp += logger::WriteVector(angular_velocity_cantilever_rad_s_); return str_tmp; } -void AttitudeWithCantileverVibration::SetParameters(const MonteCarloSimulationExecutor& mc_simulator) { +void AttitudeWithCantileverVibration::SetParameters(const simulation::MonteCarloSimulationExecutor& mc_simulator) { Attitude::SetParameters(mc_simulator); GetInitializedMonteCarloParameterVector(mc_simulator, "angular_velocity_b_rad_s", angular_velocity_b_rad_s_); @@ -99,3 +101,5 @@ void AttitudeWithCantileverVibration::Propagate(const double end_time_s) { attitude_ode_.SetPreviousInertiaTensor_kgm2(inertia_tensor_kgm2_); CalcAngularMomentum(); } + +} // namespace s2e::dynamics::attitude diff --git a/src/dynamics/attitude/attitude_with_cantilever_vibration.hpp b/src/dynamics/attitude/attitude_with_cantilever_vibration.hpp index 0ab64d619..f5f7747fa 100644 --- a/src/dynamics/attitude/attitude_with_cantilever_vibration.hpp +++ b/src/dynamics/attitude/attitude_with_cantilever_vibration.hpp @@ -12,6 +12,8 @@ #include "attitude.hpp" #include "ode_attitude_with_cantilever_vibration.hpp" +namespace s2e::dynamics::attitude { + /** * @class AttitudeWithCantileverVibration * @brief Class to calculate spacecraft attitude with cantilever vibration @@ -49,15 +51,15 @@ class AttitudeWithCantileverVibration : public Attitude { */ virtual void Propagate(const double end_time_s); - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; @@ -66,15 +68,17 @@ class AttitudeWithCantileverVibration : public Attitude { * @brief Set parameters for Monte-Carlo simulation * @param [in] mc_simulator: Monte-Carlo simulation executor */ - virtual void SetParameters(const MonteCarloSimulationExecutor& mc_simulator); + virtual void SetParameters(const simulation::MonteCarloSimulationExecutor& mc_simulator); private: double current_propagation_time_s_; //!< current time [sec] math::Vector<3> angular_velocity_cantilever_rad_s_{0.0}; //!< Angular velocity of the cantilever with respect to the body frame [rad/s] math::Vector<3> euler_angular_cantilever_rad_{0.0}; //!< Euler angle of the cantilever with respect to the body frame [rad/s] - numerical_integration::AttitudeWithCantileverVibrationOde attitude_ode_; + AttitudeWithCantileverVibrationOde attitude_ode_; numerical_integration::NumericalIntegratorManager<13> numerical_integrator_; }; +} // namespace s2e::dynamics::attitude + #endif // S2E_DYNAMICS_ATTITUDE_ATTITUDE_WITH_CANTILEVER_VIBRATION_HPP_ diff --git a/src/dynamics/attitude/controlled_attitude.cpp b/src/dynamics/attitude/controlled_attitude.cpp index ae12dc2e7..d852dc9e3 100644 --- a/src/dynamics/attitude/controlled_attitude.cpp +++ b/src/dynamics/attitude/controlled_attitude.cpp @@ -7,10 +7,13 @@ #include #include +namespace s2e::dynamics::attitude { + ControlledAttitude::ControlledAttitude(const AttitudeControlMode main_mode, const AttitudeControlMode sub_mode, const math::Quaternion quaternion_i2b, const math::Vector<3> main_target_direction_b, const math::Vector<3> sub_target_direction_b, - const math::Matrix<3, 3>& inertia_tensor_kgm2, const LocalCelestialInformation* local_celestial_information, - const Orbit* orbit, const std::string& simulation_object_name) + const math::Matrix<3, 3>& inertia_tensor_kgm2, + const environment::LocalCelestialInformation* local_celestial_information, const orbit::Orbit* orbit, + const std::string& simulation_object_name) : Attitude(inertia_tensor_kgm2, simulation_object_name), main_mode_(main_mode), sub_mode_(sub_mode), @@ -178,3 +181,5 @@ void ControlledAttitude::CalcAngularVelocity(const double current_time_s) { previous_quaternion_i2b_ = quaternion_i2b_; previous_omega_b_rad_s_ = angular_velocity_b_rad_s_; } + +} // namespace s2e::dynamics::attitude diff --git a/src/dynamics/attitude/controlled_attitude.hpp b/src/dynamics/attitude/controlled_attitude.hpp index ce26738d8..c2853871e 100644 --- a/src/dynamics/attitude/controlled_attitude.hpp +++ b/src/dynamics/attitude/controlled_attitude.hpp @@ -13,6 +13,8 @@ #include "../orbit/orbit.hpp" #include "attitude.hpp" +namespace s2e::dynamics::attitude { + /** * @enum AttitudeControlMode * @brief Attitude control mode @@ -56,8 +58,8 @@ class ControlledAttitude : public Attitude { */ ControlledAttitude(const AttitudeControlMode main_mode, const AttitudeControlMode sub_mode, const math::Quaternion quaternion_i2b, const math::Vector<3> main_target_direction_b, const math::Vector<3> sub_target_direction_b, - const math::Matrix<3, 3>& inertia_tensor_kgm2, const LocalCelestialInformation* local_celestial_information, const Orbit* orbit, - const std::string& simulation_object_name = "attitude"); + const math::Matrix<3, 3>& inertia_tensor_kgm2, const environment::LocalCelestialInformation* local_celestial_information, + const orbit::Orbit* orbit, const std::string& simulation_object_name = "attitude"); /** * @fn ~ControlledAttitude * @brief Destructor @@ -111,8 +113,8 @@ class ControlledAttitude : public Attitude { // TODO Change with ini file // Inputs - const LocalCelestialInformation* local_celestial_information_; //!< Local celestial information - const Orbit* orbit_; //!< Orbit information + const environment::LocalCelestialInformation* local_celestial_information_; //!< Local celestial information + const orbit::Orbit* orbit_; //!< Orbit information // Local functions /** @@ -149,4 +151,6 @@ class ControlledAttitude : public Attitude { math::Matrix<3, 3> CalcDcm(const math::Vector<3> main_direction, const math::Vector<3> sub_direction); }; +} // namespace s2e::dynamics::attitude + #endif // S2E_DYNAMICS_ATTITUDE_CONTROLLED_ATTITUDE_HPP_ diff --git a/src/dynamics/attitude/initialize_attitude.cpp b/src/dynamics/attitude/initialize_attitude.cpp index d4ed6e202..f5dbb7b82 100644 --- a/src/dynamics/attitude/initialize_attitude.cpp +++ b/src/dynamics/attitude/initialize_attitude.cpp @@ -6,9 +6,11 @@ #include -Attitude* InitAttitude(std::string file_name, const Orbit* orbit, const LocalCelestialInformation* local_celestial_information, +namespace s2e::dynamics::attitude { + +Attitude* InitAttitude(std::string file_name, const orbit::Orbit* orbit, const environment::LocalCelestialInformation* local_celestial_information, const double step_width_s, const math::Matrix<3, 3>& inertia_tensor_kgm2, const int spacecraft_id) { - IniAccess ini_file(file_name); + setting_file_reader::IniAccess ini_file(file_name); const char* section_ = "ATTITUDE"; std::string mc_name = "attitude" + std::to_string(spacecraft_id); Attitude* attitude; @@ -21,7 +23,7 @@ Attitude* InitAttitude(std::string file_name, const Orbit* orbit, const LocalCel math::Vector<3> torque_b; if (initialize_mode == "CONTROLLED") { // Initialize with Controlled attitude (attitude_tmp temporary used) - IniAccess ini_file_ca(file_name); + setting_file_reader::IniAccess ini_file_ca(file_name); const char* section_ca_ = "CONTROLLED_ATTITUDE"; const std::string main_mode_in = ini_file.ReadString(section_ca_, "main_mode"); const std::string sub_mode_in = ini_file.ReadString(section_ca_, "sub_mode"); @@ -51,7 +53,7 @@ Attitude* InitAttitude(std::string file_name, const Orbit* orbit, const LocalCel attitude = new AttitudeRk4(omega_b, quaternion_i2b, inertia_tensor_kgm2, torque_b, step_width_s, mc_name); } else if (propagate_mode == "CANTILEVER_VIBRATION") { std::string ini_structure_name = ini_file.ReadString("SETTING_FILES", "structure_file"); - IniAccess ini_structure(ini_structure_name); + setting_file_reader::IniAccess ini_structure(ini_structure_name); const char* section_cantilever = "CANTILEVER_PARAMETERS"; math::Matrix<3, 3> inertia_tensor_cantilever_kgm2; @@ -70,7 +72,7 @@ Attitude* InitAttitude(std::string file_name, const Orbit* orbit, const LocalCel intrinsic_angular_velocity_cantilever_rad_s, torque_b, step_width_s, mc_name); } else if (propagate_mode == "CONTROLLED") { // Controlled attitude - IniAccess ini_file_ca(file_name); + setting_file_reader::IniAccess ini_file_ca(file_name); const char* section_ca_ = "CONTROLLED_ATTITUDE"; const std::string main_mode_in = ini_file.ReadString(section_ca_, "main_mode"); const std::string sub_mode_in = ini_file.ReadString(section_ca_, "sub_mode"); @@ -93,3 +95,5 @@ Attitude* InitAttitude(std::string file_name, const Orbit* orbit, const LocalCel return attitude; } + +} // namespace s2e::dynamics::attitude diff --git a/src/dynamics/attitude/initialize_attitude.hpp b/src/dynamics/attitude/initialize_attitude.hpp index f9b1bebd4..335ee0c44 100644 --- a/src/dynamics/attitude/initialize_attitude.hpp +++ b/src/dynamics/attitude/initialize_attitude.hpp @@ -11,6 +11,8 @@ #include "attitude_with_cantilever_vibration.hpp" #include "controlled_attitude.hpp" +namespace s2e::dynamics::attitude { + /** * @fn InitAttitude * @brief Initialize function for Attitude @@ -21,7 +23,9 @@ * @param [in] inertia_tensor_kgm2: Inertia tensor [kg m^2] * @param [in] spacecraft_id: Satellite ID */ -Attitude* InitAttitude(std::string file_name, const Orbit* orbit, const LocalCelestialInformation* local_celestial_information, +Attitude* InitAttitude(std::string file_name, const orbit::Orbit* orbit, const environment::LocalCelestialInformation* local_celestial_information, const double step_width_s, const math::Matrix<3, 3>& inertia_tensor_kgm2, const int spacecraft_id); +} // namespace s2e::dynamics::attitude + #endif // S2E_DYNAMICS_ATTITUDE_INITIALIZE_ATTITUDE_HPP_ diff --git a/src/dynamics/attitude/ode_attitude_with_cantilever_vibration.hpp b/src/dynamics/attitude/ode_attitude_with_cantilever_vibration.hpp index bd2fd8ae5..c267b84f7 100644 --- a/src/dynamics/attitude/ode_attitude_with_cantilever_vibration.hpp +++ b/src/dynamics/attitude/ode_attitude_with_cantilever_vibration.hpp @@ -11,14 +11,15 @@ #include "attitude.hpp" -namespace numerical_integration { +namespace s2e::dynamics::attitude { + /** * @class AttitudeWithCantileverVibrationOde * @brief Class to implement Ordinary Differential Equations for Attitude with Cantilever Vibration * @note State variables in this ODE compose the following elenents (in order): angular_velocity_b_rad_s_ (3-dimension), * angular_velocity_cantilever_rad_s_ (3-dimension), quaternion_i2b_ (4-dmension), and euler_angular_cantilever_rad_ (3-dimension) */ -class AttitudeWithCantileverVibrationOde : public InterfaceOde<13> { +class AttitudeWithCantileverVibrationOde : public numerical_integration::InterfaceOde<13> { public: /** * @fn SetStateFromPhysicalQuantities @@ -221,6 +222,6 @@ class AttitudeWithCantileverVibrationOde : public InterfaceOde<13> { math::Matrix<3, 3> inverse_equivalent_inertia_tensor_cantilever_{0.0}; //!< Inverse of inertia tensor of the cantilever }; -} // namespace numerical_integration +} // namespace s2e::dynamics::attitude #endif // S2E_DYNAMICS_ATTITUDE_ODE_ATTITUDE_WITH_CANTILEVER_VIBRATION_HPP_ diff --git a/src/dynamics/dynamics.cpp b/src/dynamics/dynamics.cpp index 8f6f54198..a096eedad 100644 --- a/src/dynamics/dynamics.cpp +++ b/src/dynamics/dynamics.cpp @@ -5,11 +5,11 @@ #include "dynamics.hpp" -#include "../simulation/multiple_spacecraft/relative_information.hpp" +namespace s2e::dynamics { -Dynamics::Dynamics(const SimulationConfiguration* simulation_configuration, const SimulationTime* simulation_time, - const LocalEnvironment* local_environment, const int spacecraft_id, Structure* structure, - RelativeInformation* relative_information) +Dynamics::Dynamics(const simulation::SimulationConfiguration* simulation_configuration, const environment::SimulationTime* simulation_time, + const environment::LocalEnvironment* local_environment, const int spacecraft_id, spacecraft::Structure* structure, + simulation::RelativeInformation* relative_information) : structure_(structure), local_environment_(local_environment) { Initialize(simulation_configuration, simulation_time, spacecraft_id, structure, relative_information); } @@ -20,23 +20,24 @@ Dynamics::~Dynamics() { delete temperature_; } -void Dynamics::Initialize(const SimulationConfiguration* simulation_configuration, const SimulationTime* simulation_time, const int spacecraft_id, - Structure* structure, RelativeInformation* relative_information) { - const LocalCelestialInformation& local_celestial_information = local_environment_->GetCelestialInformation(); +void Dynamics::Initialize(const simulation::SimulationConfiguration* simulation_configuration, const environment::SimulationTime* simulation_time, + const int spacecraft_id, spacecraft::Structure* structure, simulation::RelativeInformation* relative_information) { + const environment::LocalCelestialInformation& local_celestial_information = local_environment_->GetCelestialInformation(); // Initialize - orbit_ = InitOrbit(&(local_celestial_information.GetGlobalInformation()), simulation_configuration->spacecraft_file_list_[spacecraft_id], - simulation_time->GetOrbitRkStepTime_s(), simulation_time->GetCurrentTime_jd(), - local_celestial_information.GetGlobalInformation().GetCenterBodyGravityConstant_m3_s2(), "ORBIT", relative_information); - attitude_ = InitAttitude(simulation_configuration->spacecraft_file_list_[spacecraft_id], orbit_, &local_celestial_information, - simulation_time->GetAttitudeRkStepTime_s(), structure->GetKinematicsParameters().GetInertiaTensor_b_kgm2(), spacecraft_id); - temperature_ = InitTemperature(simulation_configuration->spacecraft_file_list_[spacecraft_id], simulation_time->GetThermalRkStepTime_s(), - &(local_environment_->GetSolarRadiationPressure()), &(local_environment_->GetEarthAlbedo())); + orbit_ = orbit::InitOrbit(&(local_celestial_information.GetGlobalInformation()), simulation_configuration->spacecraft_file_list_[spacecraft_id], + simulation_time->GetOrbitRkStepTime_s(), simulation_time->GetCurrentTime_jd(), + local_celestial_information.GetGlobalInformation().GetCenterBodyGravityConstant_m3_s2(), "ORBIT", relative_information); + attitude_ = attitude::InitAttitude(simulation_configuration->spacecraft_file_list_[spacecraft_id], orbit_, &local_celestial_information, + simulation_time->GetAttitudeRkStepTime_s(), structure->GetKinematicsParameters().GetInertiaTensor_b_kgm2(), + spacecraft_id); + temperature_ = thermal::InitTemperature(simulation_configuration->spacecraft_file_list_[spacecraft_id], simulation_time->GetThermalRkStepTime_s(), + &(local_environment_->GetSolarRadiationPressure()), &(local_environment_->GetEarthAlbedo())); // To get initial value orbit_->UpdateByAttitude(attitude_->GetQuaternion_i2b()); } -void Dynamics::Update(const SimulationTime* simulation_time, const LocalCelestialInformation* local_celestial_information) { +void Dynamics::Update(const environment::SimulationTime* simulation_time, const environment::LocalCelestialInformation* local_celestial_information) { // Attitude propagation if (simulation_time->GetAttitudePropagateFlag()) { attitude_->Propagate(simulation_time->GetElapsedTime_s()); @@ -60,8 +61,10 @@ void Dynamics::ClearForceTorque(void) { orbit_->SetAcceleration_i_m_s2(zero); } -void Dynamics::LogSetup(Logger& logger) { +void Dynamics::LogSetup(logger::Logger& logger) { logger.AddLogList(attitude_); logger.AddLogList(orbit_); logger.AddLogList(temperature_); } + +} // namespace s2e::dynamics diff --git a/src/dynamics/dynamics.hpp b/src/dynamics/dynamics.hpp index 327cc399a..4bfd91673 100644 --- a/src/dynamics/dynamics.hpp +++ b/src/dynamics/dynamics.hpp @@ -10,6 +10,7 @@ #include "../environment/global/simulation_time.hpp" #include "../environment/local/local_environment.hpp" #include "../math_physics/math/vector.hpp" +#include "../simulation/multiple_spacecraft/relative_information.hpp" #include "../simulation/simulation_configuration.hpp" #include "../simulation/spacecraft/structure/structure.hpp" #include "dynamics/attitude/initialize_attitude.hpp" @@ -17,8 +18,14 @@ #include "dynamics/thermal/node.hpp" #include "dynamics/thermal/temperature.hpp" +namespace s2e::simulation { class RelativeInformation; +} +namespace s2e::environment { class LocalEnvironment; +} + +namespace s2e::dynamics { /** * @class Dynamics @@ -33,11 +40,12 @@ class Dynamics { * @param [in] simulation_time: Simulation time * @param [in] local_celestial_information: Local celestial information * @param [in] spacecraft_id: Spacecraft ID of the spacecraft - * @param [in] structure: Structure of the spacecraft + * @param [in] structure: spacecraft::Structure of the spacecraft * @param [in] relative_information: Relative information */ - Dynamics(const SimulationConfiguration* simulation_configuration, const SimulationTime* simulation_time, const LocalEnvironment* local_environment, - const int spacecraft_id, Structure* structure, RelativeInformation* relative_information = (RelativeInformation*)nullptr); + Dynamics(const simulation::SimulationConfiguration* simulation_configuration, const environment::SimulationTime* simulation_time, + const environment::LocalEnvironment* local_environment, const int spacecraft_id, spacecraft::Structure* structure, + simulation::RelativeInformation* relative_information = (simulation::RelativeInformation*)nullptr); /** * @fn ~Dynamics * @brief Destructor @@ -50,13 +58,13 @@ class Dynamics { * @param [in] simulation_time: Simulation time * @param [in] local_celestial_information: Local celestial information */ - void Update(const SimulationTime* simulation_time, const LocalCelestialInformation* local_celestial_information); + void Update(const environment::SimulationTime* simulation_time, const environment::LocalCelestialInformation* local_celestial_information); /** * @fn LogSetup * @brief Log setup for dynamics calculation */ - void LogSetup(Logger& logger); + void LogSetup(logger::Logger& logger); /** * @fn AddTorque_b_Nm @@ -89,29 +97,29 @@ class Dynamics { * @fn GetAttitude * @brief Return Attitude class */ - inline const Attitude& GetAttitude() const { return *attitude_; } + inline const attitude::Attitude& GetAttitude() const { return *attitude_; } /** * @fn GetOrbit * @brief Return Orbit class */ - inline const Orbit& GetOrbit() const { return *orbit_; } + inline const orbit::Orbit& GetOrbit() const { return *orbit_; } /** * @fn GetTemperature * @brief Return Temperature class */ - inline const Temperature& GetTemperature() const { return *temperature_; } + inline const thermal::Temperature& GetTemperature() const { return *temperature_; } /** * @fn SetAttitude * @brief Return Attitude class to change the Attitude */ - inline Attitude& SetAttitude() const { return *attitude_; } + inline attitude::Attitude& SetAttitude() const { return *attitude_; } private: - Attitude* attitude_; //!< Attitude dynamics - Orbit* orbit_; //!< Orbit dynamics - Temperature* temperature_; //!< Thermal dynamics - const Structure* structure_; //!< Structure information - const LocalEnvironment* local_environment_; //!< Local environment + attitude::Attitude* attitude_; //!< Attitude dynamics + orbit::Orbit* orbit_; //!< Orbit dynamics + thermal::Temperature* temperature_; //!< Thermal dynamics + const spacecraft::Structure* structure_; //!< Structure information + const environment::LocalEnvironment* local_environment_; //!< Local environment /** * @fn Initialize @@ -123,8 +131,11 @@ class Dynamics { * @param [in] structure: Structure of the spacecraft * @param [in] relative_information: Relative information */ - void Initialize(const SimulationConfiguration* simulation_configuration, const SimulationTime* simulation_time, const int spacecraft_id, - Structure* structure, RelativeInformation* relative_information = (RelativeInformation*)nullptr); + void Initialize(const simulation::SimulationConfiguration* simulation_configuration, const environment::SimulationTime* simulation_time, + const int spacecraft_id, spacecraft::Structure* structure, + simulation::RelativeInformation* relative_information = (simulation::RelativeInformation*)nullptr); }; +} // namespace s2e::dynamics + #endif // S2E_DYNAMICS_DYNAMICS_HPP_ diff --git a/src/dynamics/orbit/encke_orbit_propagation.cpp b/src/dynamics/orbit/encke_orbit_propagation.cpp index 9b67322f2..5a1ae0d0b 100644 --- a/src/dynamics/orbit/encke_orbit_propagation.cpp +++ b/src/dynamics/orbit/encke_orbit_propagation.cpp @@ -9,7 +9,9 @@ #include "../../math_physics/orbit/orbital_elements.hpp" -EnckeOrbitPropagation::EnckeOrbitPropagation(const CelestialInformation* celestial_information, const double gravity_constant_m3_s2, +namespace s2e::dynamics::orbit { + +EnckeOrbitPropagation::EnckeOrbitPropagation(const environment::CelestialInformation* celestial_information, const double gravity_constant_m3_s2, const double propagation_step_s, const double current_time_jd, const math::Vector<3> position_i_m, const math::Vector<3> velocity_i_m_s, const double error_tolerance) : Orbit(celestial_information), @@ -90,8 +92,8 @@ void EnckeOrbitPropagation::Initialize(double current_time_jd, math::Vector<3> r // reference orbit reference_position_i_m_ = reference_position_i_m; reference_velocity_i_m_s_ = reference_velocity_i_m_s; - orbit::OrbitalElements oe_ref(gravity_constant_m3_s2_, current_time_jd, reference_position_i_m, reference_velocity_i_m_s); - reference_kepler_orbit = orbit::KeplerOrbit(gravity_constant_m3_s2_, oe_ref); + s2e::orbit::OrbitalElements oe_ref(gravity_constant_m3_s2_, current_time_jd, reference_position_i_m, reference_velocity_i_m_s); + reference_kepler_orbit = s2e::orbit::KeplerOrbit(gravity_constant_m3_s2_, oe_ref); // difference orbit difference_position_i_m_.FillUp(0.0); @@ -124,3 +126,5 @@ double EnckeOrbitPropagation::CalcQFunction(math::Vector<3> difference_position_ return q_func; } + +} // namespace s2e::dynamics::orbit diff --git a/src/dynamics/orbit/encke_orbit_propagation.hpp b/src/dynamics/orbit/encke_orbit_propagation.hpp index a32052e2b..68542f198 100644 --- a/src/dynamics/orbit/encke_orbit_propagation.hpp +++ b/src/dynamics/orbit/encke_orbit_propagation.hpp @@ -10,6 +10,8 @@ #include "../../math_physics/orbit/kepler_orbit.hpp" #include "orbit.hpp" +namespace s2e::dynamics::orbit { + /** * @class EnckeOrbitPropagation * @brief Class to propagate spacecraft orbit with Encke's method @@ -27,9 +29,9 @@ class EnckeOrbitPropagation : public Orbit, public math::OrdinaryDifferentialEqu * @param [in] velocity_i_m_s: Initial value of velocity in the inertial frame [m/s] * @param [in] error_tolerance: Error tolerance threshold */ - EnckeOrbitPropagation(const CelestialInformation* celestial_information, const double gravity_constant_m3_s2, const double propagation_step_s, - const double current_time_jd, const math::Vector<3> position_i_m, const math::Vector<3> velocity_i_m_s, - const double error_tolerance); + EnckeOrbitPropagation(const environment::CelestialInformation* celestial_information, const double gravity_constant_m3_s2, + const double propagation_step_s, const double current_time_jd, const math::Vector<3> position_i_m, + const math::Vector<3> velocity_i_m_s, const double error_tolerance); /** * @fn ~EnckeOrbitPropagation * @brief Destructor @@ -63,9 +65,9 @@ class EnckeOrbitPropagation : public Orbit, public math::OrdinaryDifferentialEqu double propagation_time_s_; //!< Simulation current time for numerical integration by RK4 // reference orbit - math::Vector<3> reference_position_i_m_; //!< Reference orbit position in the inertial frame [m] - math::Vector<3> reference_velocity_i_m_s_; //!< Reference orbit velocity in the inertial frame [m/s] - orbit::KeplerOrbit reference_kepler_orbit; //!< Reference Kepler orbital element + math::Vector<3> reference_position_i_m_; //!< Reference orbit position in the inertial frame [m] + math::Vector<3> reference_velocity_i_m_s_; //!< Reference orbit velocity in the inertial frame [m/s] + s2e::orbit::KeplerOrbit reference_kepler_orbit; //!< Reference Kepler orbital element // difference orbit math::Vector<3> difference_position_i_m_; //!< Difference orbit position in the inertial frame [m] @@ -93,4 +95,6 @@ class EnckeOrbitPropagation : public Orbit, public math::OrdinaryDifferentialEqu double CalcQFunction(const math::Vector<3> difference_position_i_m); }; +} // namespace s2e::dynamics::orbit + #endif // S2E_DYNAMICS_ORBIT_ENCKE_ORBIT_PROPAGATION_HPP_ diff --git a/src/dynamics/orbit/initialize_orbit.cpp b/src/dynamics/orbit/initialize_orbit.cpp index 33d674044..e039adb98 100644 --- a/src/dynamics/orbit/initialize_orbit.cpp +++ b/src/dynamics/orbit/initialize_orbit.cpp @@ -13,9 +13,11 @@ #include "sgp4_orbit_propagation.hpp" #include "time_series_file_orbit_propagation.hpp" -Orbit* InitOrbit(const CelestialInformation* celestial_information, std::string initialize_file, double step_width_s, double current_time_jd, - double gravity_constant_m3_s2, std::string section, RelativeInformation* relative_information) { - auto conf = IniAccess(initialize_file); +namespace s2e::dynamics::orbit { + +Orbit* InitOrbit(const environment::CelestialInformation* celestial_information, std::string initialize_file, double step_width_s, + double current_time_jd, double gravity_constant_m3_s2, std::string section, simulation::RelativeInformation* relative_information) { + auto conf = setting_file_reader::IniAccess(initialize_file); const char* section_ = section.c_str(); Orbit* orbit; @@ -47,8 +49,9 @@ Orbit* InitOrbit(const CelestialInformation* celestial_information, std::string // initialize orbit for relative dynamics of formation flying RelativeOrbit::RelativeOrbitUpdateMethod update_method = (RelativeOrbit::RelativeOrbitUpdateMethod)(conf.ReadInt(section_, "relative_orbit_update_method")); - orbit::RelativeOrbitModel relative_dynamics_model_type = (orbit::RelativeOrbitModel)(conf.ReadInt(section_, "relative_dynamics_model_type")); - orbit::StmModel stm_model_type = (orbit::StmModel)(conf.ReadInt(section_, "stm_model_type")); + s2e::orbit::RelativeOrbitModel relative_dynamics_model_type = + (s2e::orbit::RelativeOrbitModel)(conf.ReadInt(section_, "relative_dynamics_model_type")); + s2e::orbit::StmModel stm_model_type = (s2e::orbit::StmModel)(conf.ReadInt(section_, "stm_model_type")); math::Vector<3> init_relative_position_lvlh; conf.ReadVector<3>(section_, "initial_relative_position_lvlh_m", init_relative_position_lvlh); @@ -63,7 +66,7 @@ Orbit* InitOrbit(const CelestialInformation* celestial_information, std::string init_relative_velocity_lvlh, update_method, relative_dynamics_model_type, stm_model_type, relative_information); } else if (propagate_mode == "KEPLER") { // initialize orbit for Kepler propagation - orbit::OrbitalElements oe; + s2e::orbit::OrbitalElements oe; // TODO: init_mode_kepler should be removed in the next major update if (initialize_mode == OrbitInitializeMode::kInertialPositionAndVelocity) { // initialize with position and velocity @@ -71,7 +74,7 @@ Orbit* InitOrbit(const CelestialInformation* celestial_information, std::string conf.ReadVector<3>(section_, "initial_position_i_m", init_pos_m); math::Vector<3> init_vel_m_s; conf.ReadVector<3>(section_, "initial_velocity_i_m_s", init_vel_m_s); - oe = orbit::OrbitalElements(gravity_constant_m3_s2, current_time_jd, init_pos_m, init_vel_m_s); + oe = s2e::orbit::OrbitalElements(gravity_constant_m3_s2, current_time_jd, init_pos_m, init_vel_m_s); } else { // initialize with orbital elements double semi_major_axis_m = conf.ReadDouble(section_, "semi_major_axis_m"); @@ -80,9 +83,9 @@ Orbit* InitOrbit(const CelestialInformation* celestial_information, std::string double raan_rad = conf.ReadDouble(section_, "raan_rad"); double arg_perigee_rad = conf.ReadDouble(section_, "argument_of_perigee_rad"); double epoch_jday = conf.ReadDouble(section_, "epoch_jday"); - oe = orbit::OrbitalElements(epoch_jday, semi_major_axis_m, eccentricity, inclination_rad, raan_rad, arg_perigee_rad); + oe = s2e::orbit::OrbitalElements(epoch_jday, semi_major_axis_m, eccentricity, inclination_rad, raan_rad, arg_perigee_rad); } - orbit::KeplerOrbit kepler_orbit(gravity_constant_m3_s2, oe); + s2e::orbit::KeplerOrbit kepler_orbit(gravity_constant_m3_s2, oe); orbit = new KeplerOrbitPropagation(celestial_information, current_time_jd, kepler_orbit); } else if (propagate_mode == "ENCKE") { // initialize orbit for Encke's method @@ -127,7 +130,7 @@ Orbit* InitOrbit(const CelestialInformation* celestial_information, std::string } math::Vector<6> InitializePosVel(std::string initialize_file, double current_time_jd, double gravity_constant_m3_s2, std::string section) { - auto conf = IniAccess(initialize_file); + auto conf = setting_file_reader::IniAccess(initialize_file); const char* section_ = section.c_str(); math::Vector<3> position_i_m; math::Vector<3> velocity_i_m_s; @@ -141,8 +144,8 @@ math::Vector<6> InitializePosVel(std::string initialize_file, double current_tim double raan_rad = conf.ReadDouble(section_, "raan_rad"); double arg_perigee_rad = conf.ReadDouble(section_, "argument_of_perigee_rad"); double epoch_jday = conf.ReadDouble(section_, "epoch_jday"); - orbit::OrbitalElements oe(epoch_jday, semi_major_axis_m, eccentricity, inclination_rad, raan_rad, arg_perigee_rad); - orbit::KeplerOrbit kepler_orbit(gravity_constant_m3_s2, oe); + s2e::orbit::OrbitalElements oe(epoch_jday, semi_major_axis_m, eccentricity, inclination_rad, raan_rad, arg_perigee_rad); + s2e::orbit::KeplerOrbit kepler_orbit(gravity_constant_m3_s2, oe); kepler_orbit.CalcOrbit(current_time_jd); position_i_m = kepler_orbit.GetPosition_i_m(); @@ -159,3 +162,5 @@ math::Vector<6> InitializePosVel(std::string initialize_file, double current_tim return pos_vel; } + +} // namespace s2e::dynamics::orbit diff --git a/src/dynamics/orbit/initialize_orbit.hpp b/src/dynamics/orbit/initialize_orbit.hpp index 6b3aad69f..dd38c127c 100644 --- a/src/dynamics/orbit/initialize_orbit.hpp +++ b/src/dynamics/orbit/initialize_orbit.hpp @@ -10,7 +10,11 @@ #include "orbit.hpp" +namespace s2e::simulation { class RelativeInformation; +} + +namespace s2e::dynamics::orbit { /** * @fn InitOrbit @@ -23,9 +27,9 @@ class RelativeInformation; * @param [in] section: Section name * @param [in] relative_information: Relative information */ -Orbit* InitOrbit(const CelestialInformation* celestial_information, std::string initialize_file, double step_width_s, double current_time_jd, - double gravity_constant_m3_s2, std::string section = "ORBIT", - RelativeInformation* relative_information = (RelativeInformation*)nullptr); +Orbit* InitOrbit(const environment::CelestialInformation* celestial_information, std::string initialize_file, double step_width_s, + double current_time_jd, double gravity_constant_m3_s2, std::string section = "ORBIT", + simulation::RelativeInformation* relative_information = (simulation::RelativeInformation*)nullptr); /** * @fn InitializePosVel @@ -37,4 +41,6 @@ Orbit* InitOrbit(const CelestialInformation* celestial_information, std::string */ math::Vector<6> InitializePosVel(std::string initialize_file, double current_time_jd, double gravity_constant_m3_s2, std::string section = "ORBIT"); +} // namespace s2e::dynamics::orbit + #endif // S2E_DYNAMICS_ORBIT_INITIALIZE_ORBIT_HPP_ diff --git a/src/dynamics/orbit/kepler_orbit_propagation.cpp b/src/dynamics/orbit/kepler_orbit_propagation.cpp index 905c56e39..4e9050844 100644 --- a/src/dynamics/orbit/kepler_orbit_propagation.cpp +++ b/src/dynamics/orbit/kepler_orbit_propagation.cpp @@ -8,7 +8,9 @@ #include "../../math_physics/math/s2e_math.hpp" -KeplerOrbitPropagation::KeplerOrbitPropagation(const CelestialInformation* celestial_information, const double current_time_jd, +namespace s2e::dynamics::orbit { + +KeplerOrbitPropagation::KeplerOrbitPropagation(const environment::CelestialInformation* celestial_information, const double current_time_jd, KeplerOrbit kepler_orbit) : Orbit(celestial_information), KeplerOrbit(kepler_orbit) { UpdateState(current_time_jd); @@ -32,3 +34,5 @@ void KeplerOrbitPropagation::UpdateState(const double current_time_jd) { TransformEciToEcef(); TransformEcefToGeodetic(); } + +} // namespace s2e::dynamics::orbit diff --git a/src/dynamics/orbit/kepler_orbit_propagation.hpp b/src/dynamics/orbit/kepler_orbit_propagation.hpp index ec93197ab..a43aff5c4 100644 --- a/src/dynamics/orbit/kepler_orbit_propagation.hpp +++ b/src/dynamics/orbit/kepler_orbit_propagation.hpp @@ -9,11 +9,13 @@ #include "../../math_physics/orbit/kepler_orbit.hpp" #include "orbit.hpp" +namespace s2e::dynamics::orbit { + /** * @class KeplerOrbitPropagation * @brief Class to propagate spacecraft orbit with Kepler equation */ -class KeplerOrbitPropagation : public Orbit, public orbit::KeplerOrbit { +class KeplerOrbitPropagation : public Orbit, public s2e::orbit::KeplerOrbit { public: // Initialize with orbital elements /** @@ -23,7 +25,8 @@ class KeplerOrbitPropagation : public Orbit, public orbit::KeplerOrbit { * @param [in] current_time_jd: Current Julian day [day] * @param [in] kepler_orbit: Kepler orbit */ - KeplerOrbitPropagation(const CelestialInformation* celestial_information, const double current_time_jd, orbit::KeplerOrbit kepler_orbit); + KeplerOrbitPropagation(const environment::CelestialInformation* celestial_information, const double current_time_jd, + s2e::orbit::KeplerOrbit kepler_orbit); /** * @fn ~KeplerOrbitPropagation * @brief Destructor @@ -48,4 +51,6 @@ class KeplerOrbitPropagation : public Orbit, public orbit::KeplerOrbit { void UpdateState(const double current_time_jd); }; +} // namespace s2e::dynamics::orbit + #endif // S2E_DYNAMICS_ORBIT_KEPLER_ORBIT_PROPAGATION_HPP_ diff --git a/src/dynamics/orbit/orbit.cpp b/src/dynamics/orbit/orbit.cpp index b38aa9c98..dbdcb7791 100644 --- a/src/dynamics/orbit/orbit.cpp +++ b/src/dynamics/orbit/orbit.cpp @@ -4,6 +4,8 @@ */ #include "orbit.hpp" +namespace s2e::dynamics::orbit { + math::Quaternion Orbit::CalcQuaternion_i2lvlh() const { math::Vector<3> lvlh_x = spacecraft_position_i_m_; // x-axis in LVLH frame is position vector direction from geocenter to satellite math::Vector<3> lvlh_ex = lvlh_x.CalcNormalizedVector(); @@ -67,14 +69,14 @@ OrbitInitializeMode SetOrbitInitializeMode(const std::string initialize_mode) { std::string Orbit::GetLogHeader() const { std::string str_tmp = ""; - str_tmp += WriteVector("spacecraft_position", "i", "m", 3); - str_tmp += WriteVector("spacecraft_position", "ecef", "m", 3); - str_tmp += WriteVector("spacecraft_velocity", "i", "m/s", 3); - str_tmp += WriteVector("spacecraft_velocity", "b", "m/s", 3); - str_tmp += WriteVector("spacecraft_acceleration", "i", "m/s2", 3); - str_tmp += WriteScalar("spacecraft_latitude", "rad"); - str_tmp += WriteScalar("spacecraft_longitude", "rad"); - str_tmp += WriteScalar("spacecraft_altitude", "m"); + str_tmp += logger::WriteVector("spacecraft_position", "i", "m", 3); + str_tmp += logger::WriteVector("spacecraft_position", "ecef", "m", 3); + str_tmp += logger::WriteVector("spacecraft_velocity", "i", "m/s", 3); + str_tmp += logger::WriteVector("spacecraft_velocity", "b", "m/s", 3); + str_tmp += logger::WriteVector("spacecraft_acceleration", "i", "m/s2", 3); + str_tmp += logger::WriteScalar("spacecraft_latitude", "rad"); + str_tmp += logger::WriteScalar("spacecraft_longitude", "rad"); + str_tmp += logger::WriteScalar("spacecraft_altitude", "m"); return str_tmp; } @@ -82,14 +84,16 @@ std::string Orbit::GetLogHeader() const { std::string Orbit::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteVector(spacecraft_position_i_m_, 16); - str_tmp += WriteVector(spacecraft_position_ecef_m_, 16); - str_tmp += WriteVector(spacecraft_velocity_i_m_s_, 10); - str_tmp += WriteVector(spacecraft_velocity_b_m_s_, 10); - str_tmp += WriteVector(spacecraft_acceleration_i_m_s2_, 10); - str_tmp += WriteScalar(spacecraft_geodetic_position_.GetLatitude_rad()); - str_tmp += WriteScalar(spacecraft_geodetic_position_.GetLongitude_rad()); - str_tmp += WriteScalar(spacecraft_geodetic_position_.GetAltitude_m()); + str_tmp += logger::WriteVector(spacecraft_position_i_m_, 16); + str_tmp += logger::WriteVector(spacecraft_position_ecef_m_, 16); + str_tmp += logger::WriteVector(spacecraft_velocity_i_m_s_, 10); + str_tmp += logger::WriteVector(spacecraft_velocity_b_m_s_, 10); + str_tmp += logger::WriteVector(spacecraft_acceleration_i_m_s2_, 10); + str_tmp += logger::WriteScalar(spacecraft_geodetic_position_.GetLatitude_rad()); + str_tmp += logger::WriteScalar(spacecraft_geodetic_position_.GetLongitude_rad()); + str_tmp += logger::WriteScalar(spacecraft_geodetic_position_.GetAltitude_m()); return str_tmp; } + +} // namespace s2e::dynamics::orbit diff --git a/src/dynamics/orbit/orbit.hpp b/src/dynamics/orbit/orbit.hpp index 7f99ba3af..c51f0dc61 100644 --- a/src/dynamics/orbit/orbit.hpp +++ b/src/dynamics/orbit/orbit.hpp @@ -16,6 +16,8 @@ #include #include +namespace s2e::dynamics::orbit { + /** * @enum OrbitPropagateMode * @brief Propagation mode of orbit @@ -43,14 +45,14 @@ enum class OrbitInitializeMode { * @class Orbit * @brief Base class of orbit propagation */ -class Orbit : public ILoggable { +class Orbit : public logger::ILoggable { public: /** * @fn Orbit * @brief Constructor * @param [in] celestial_information: Celestial information */ - Orbit(const CelestialInformation* celestial_information) : celestial_information_(celestial_information) {} + Orbit(const environment::CelestialInformation* celestial_information) : celestial_information_(celestial_information) {} /** * @fn ~Orbit * @brief Destructor @@ -114,7 +116,7 @@ class Orbit : public ILoggable { * @fn GetGeodeticPosition * @brief Return spacecraft position in the geodetic frame [m] */ - inline geodesy::GeodeticPosition GetGeodeticPosition() const { return spacecraft_geodetic_position_; } + inline s2e::geodesy::GeodeticPosition GetGeodeticPosition() const { return spacecraft_geodetic_position_; } // TODO delete the following functions inline double GetLatitude_rad() const { return spacecraft_geodetic_position_.GetLatitude_rad(); } @@ -173,28 +175,28 @@ class Orbit : public ILoggable { */ math::Quaternion CalcQuaternion_i2lvlh() const; - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; protected: - const CelestialInformation* celestial_information_; //!< Celestial information + const environment::CelestialInformation* celestial_information_; //!< Celestial information // Settings bool is_calc_enabled_ = false; //!< Calculate flag OrbitPropagateMode propagate_mode_; //!< Propagation mode - math::Vector<3> spacecraft_position_i_m_; //!< Spacecraft position in the inertial frame [m] - math::Vector<3> spacecraft_position_ecef_m_; //!< Spacecraft position in the ECEF frame [m] - geodesy::GeodeticPosition spacecraft_geodetic_position_; //!< Spacecraft position in the Geodetic frame + math::Vector<3> spacecraft_position_i_m_; //!< Spacecraft position in the inertial frame [m] + math::Vector<3> spacecraft_position_ecef_m_; //!< Spacecraft position in the ECEF frame [m] + s2e::geodesy::GeodeticPosition spacecraft_geodetic_position_; //!< Spacecraft position in the Geodetic frame math::Vector<3> spacecraft_velocity_i_m_s_; //!< Spacecraft velocity in the inertial frame [m/s] math::Vector<3> spacecraft_velocity_b_m_s_; //!< Spacecraft velocity in the body frame [m/s] @@ -218,4 +220,6 @@ class Orbit : public ILoggable { OrbitInitializeMode SetOrbitInitializeMode(const std::string initialize_mode); +} // namespace s2e::dynamics::orbit + #endif // S2E_DYNAMICS_ORBIT_ORBIT_HPP_ diff --git a/src/dynamics/orbit/relative_orbit.cpp b/src/dynamics/orbit/relative_orbit.cpp index f60f52682..6f4b2608d 100644 --- a/src/dynamics/orbit/relative_orbit.cpp +++ b/src/dynamics/orbit/relative_orbit.cpp @@ -8,10 +8,12 @@ #include "rk4_orbit_propagation.hpp" -RelativeOrbit::RelativeOrbit(const CelestialInformation* celestial_information, double gravity_constant_m3_s2, double time_step_s, +namespace s2e::dynamics::orbit { + +RelativeOrbit::RelativeOrbit(const environment::CelestialInformation* celestial_information, double gravity_constant_m3_s2, double time_step_s, int reference_spacecraft_id, math::Vector<3> relative_position_lvlh_m, math::Vector<3> relative_velocity_lvlh_m_s, - RelativeOrbitUpdateMethod update_method, orbit::RelativeOrbitModel relative_dynamics_model_type, - orbit::StmModel stm_model_type, RelativeInformation* relative_information) + RelativeOrbitUpdateMethod update_method, s2e::orbit::RelativeOrbitModel relative_dynamics_model_type, + s2e::orbit::StmModel stm_model_type, simulation::RelativeInformation* relative_information) : Orbit(celestial_information), math::OrdinaryDifferentialEquation<6>(time_step_s), gravity_constant_m3_s2_(gravity_constant_m3_s2), @@ -66,12 +68,12 @@ void RelativeOrbit::InitializeState(math::Vector<3> relative_position_lvlh_m, ma TransformEcefToGeodetic(); } -void RelativeOrbit::CalculateSystemMatrix(orbit::RelativeOrbitModel relative_dynamics_model_type, const Orbit* reference_sat_orbit, +void RelativeOrbit::CalculateSystemMatrix(s2e::orbit::RelativeOrbitModel relative_dynamics_model_type, const Orbit* reference_sat_orbit, double gravity_constant_m3_s2) { switch (relative_dynamics_model_type) { - case orbit::RelativeOrbitModel::kHill: { + case s2e::orbit::RelativeOrbitModel::kHill: { double reference_sat_orbit_radius = reference_sat_orbit->GetPosition_i_m().CalcNorm(); - system_matrix_ = orbit::CalcHillSystemMatrix(reference_sat_orbit_radius, gravity_constant_m3_s2); + system_matrix_ = s2e::orbit::CalcHillSystemMatrix(reference_sat_orbit_radius, gravity_constant_m3_s2); } default: { // NOT REACHED @@ -80,12 +82,12 @@ void RelativeOrbit::CalculateSystemMatrix(orbit::RelativeOrbitModel relative_dyn } } -void RelativeOrbit::CalculateStm(orbit::StmModel stm_model_type, const Orbit* reference_sat_orbit, double gravity_constant_m3_s2, +void RelativeOrbit::CalculateStm(s2e::orbit::StmModel stm_model_type, const Orbit* reference_sat_orbit, double gravity_constant_m3_s2, double elapsed_sec) { switch (stm_model_type) { - case orbit::StmModel::kHcw: { + case s2e::orbit::StmModel::kHcw: { double reference_sat_orbit_radius = reference_sat_orbit->GetPosition_i_m().CalcNorm(); - stm_ = orbit::CalcHcwStm(reference_sat_orbit_radius, gravity_constant_m3_s2, elapsed_sec); + stm_ = s2e::orbit::CalcHcwStm(reference_sat_orbit_radius, gravity_constant_m3_s2, elapsed_sec); } default: { // NOT REACHED @@ -157,3 +159,5 @@ void RelativeOrbit::DerivativeFunction(double t, const math::Vector<6>& state, rhs = system_matrix_ * state; (void)t; } + +} // namespace s2e::dynamics::orbit diff --git a/src/dynamics/orbit/relative_orbit.hpp b/src/dynamics/orbit/relative_orbit.hpp index 3aae6e104..313ac9429 100644 --- a/src/dynamics/orbit/relative_orbit.hpp +++ b/src/dynamics/orbit/relative_orbit.hpp @@ -13,6 +13,8 @@ #include "orbit.hpp" +namespace s2e::dynamics::orbit { + /** * @class RelativeOrbit * @brief Class to propagate relative orbit @@ -39,9 +41,10 @@ class RelativeOrbit : public Orbit, public math::OrdinaryDifferentialEquation<6> * @param [in] stm_model_type: State transition matrix type * @param [in] relative_information: Relative information */ - RelativeOrbit(const CelestialInformation* celestial_information, double gravity_constant_m3_s2, double time_step_s, int reference_spacecraft_id, - math::Vector<3> relative_position_lvlh_m, math::Vector<3> relative_velocity_lvlh_m_s, RelativeOrbitUpdateMethod update_method, - orbit::RelativeOrbitModel relative_dynamics_model_type, orbit::StmModel stm_model_type, RelativeInformation* relative_information); + RelativeOrbit(const environment::CelestialInformation* celestial_information, double gravity_constant_m3_s2, double time_step_s, + int reference_spacecraft_id, math::Vector<3> relative_position_lvlh_m, math::Vector<3> relative_velocity_lvlh_m_s, + RelativeOrbitUpdateMethod update_method, s2e::orbit::RelativeOrbitModel relative_dynamics_model_type, + s2e::orbit::StmModel stm_model_type, simulation::RelativeInformation* relative_information); /** * @fn ~RelativeOrbit * @brief Destructor @@ -65,7 +68,7 @@ class RelativeOrbit : public Orbit, public math::OrdinaryDifferentialEquation<6> * @param [in] state: Position and velocity as state vector * @param [out] rhs: Output of the function */ - virtual void DerivativeFunction(double t, const Vector<6>& state, Vector<6>& rhs); + virtual void DerivativeFunction(double t, const math::Vector<6>& state, math::Vector<6>& rhs); private: double gravity_constant_m3_s2_; //!< Gravity constant of the center body [m3/s2] @@ -80,10 +83,10 @@ class RelativeOrbit : public Orbit, public math::OrdinaryDifferentialEquation<6> math::Vector<3> relative_position_lvlh_m_; //!< Relative position in the LVLH frame math::Vector<3> relative_velocity_lvlh_m_s_; //!< Relative velocity in the LVLH frame - RelativeOrbitUpdateMethod update_method_; //!< Update method - orbit::RelativeOrbitModel relative_dynamics_model_type_; //!< Relative dynamics model type - orbit::StmModel stm_model_type_; //!< State Transition Matrix model type - RelativeInformation* relative_information_; //!< Relative information + RelativeOrbitUpdateMethod update_method_; //!< Update method + s2e::orbit::RelativeOrbitModel relative_dynamics_model_type_; //!< Relative dynamics model type + s2e::orbit::StmModel stm_model_type_; //!< State Transition Matrix model type + simulation::RelativeInformation* relative_information_; //!< Relative information /** * @fn InitializeState @@ -102,7 +105,8 @@ class RelativeOrbit : public Orbit, public math::OrdinaryDifferentialEquation<6> * @param [in] reference_sat_orbit: Orbit information of reference satellite * @param [in] gravity_constant_m3_s2: Gravity constant of the center body [m3/s2] */ - void CalculateSystemMatrix(orbit::RelativeOrbitModel relative_dynamics_model_type, const Orbit* reference_sat_orbit, double gravity_constant_m3_s2); + void CalculateSystemMatrix(s2e::orbit::RelativeOrbitModel relative_dynamics_model_type, const Orbit* reference_sat_orbit, + double gravity_constant_m3_s2); /** * @fn CalculateStm * @brief Calculate State Transition Matrix @@ -111,7 +115,7 @@ class RelativeOrbit : public Orbit, public math::OrdinaryDifferentialEquation<6> * @param [in] gravity_constant_m3_s2: Gravity constant of the center body [m3/s2] * @param [in] elapsed_sec: Elapsed time [sec] */ - void CalculateStm(orbit::StmModel stm_model_type, const Orbit* reference_sat_orbit, double gravity_constant_m3_s2, double elapsed_sec); + void CalculateStm(s2e::orbit::StmModel stm_model_type, const Orbit* reference_sat_orbit, double gravity_constant_m3_s2, double elapsed_sec); /** * @fn PropagateRk4 * @brief Propagate relative orbit with RK4 @@ -126,4 +130,6 @@ class RelativeOrbit : public Orbit, public math::OrdinaryDifferentialEquation<6> void PropagateStm(double elapsed_sec); }; +} // namespace s2e::dynamics::orbit + #endif // S2E_DYNAMICS_ORBIT_RELATIVE_ORBIT_HPP_ diff --git a/src/dynamics/orbit/rk4_orbit_propagation.cpp b/src/dynamics/orbit/rk4_orbit_propagation.cpp index 38a6e39b2..930677292 100644 --- a/src/dynamics/orbit/rk4_orbit_propagation.cpp +++ b/src/dynamics/orbit/rk4_orbit_propagation.cpp @@ -8,8 +8,10 @@ #include #include -Rk4OrbitPropagation::Rk4OrbitPropagation(const CelestialInformation* celestial_information, double gravity_constant_m3_s2, double time_step_s, - math::Vector<3> position_i_m, math::Vector<3> velocity_i_m_s, double initial_time_s) +namespace s2e::dynamics::orbit { + +Rk4OrbitPropagation::Rk4OrbitPropagation(const environment::CelestialInformation* celestial_information, double gravity_constant_m3_s2, + double time_step_s, math::Vector<3> position_i_m, math::Vector<3> velocity_i_m_s, double initial_time_s) : Orbit(celestial_information), OrdinaryDifferentialEquation<6>(time_step_s), gravity_constant_m3_s2_(gravity_constant_m3_s2) { propagate_mode_ = OrbitPropagateMode::kRk4; @@ -86,3 +88,5 @@ void Rk4OrbitPropagation::Propagate(const double end_time_s, const double curren TransformEciToEcef(); TransformEcefToGeodetic(); } + +} // namespace s2e::dynamics::orbit diff --git a/src/dynamics/orbit/rk4_orbit_propagation.hpp b/src/dynamics/orbit/rk4_orbit_propagation.hpp index fde677ddd..30be7b161 100644 --- a/src/dynamics/orbit/rk4_orbit_propagation.hpp +++ b/src/dynamics/orbit/rk4_orbit_propagation.hpp @@ -11,6 +11,8 @@ #include "orbit.hpp" +namespace s2e::dynamics::orbit { + /** * @class Rk4OrbitPropagation * @brief Class to propagate spacecraft orbit with Runge-Kutta-4 method @@ -27,7 +29,7 @@ class Rk4OrbitPropagation : public Orbit, public math::OrdinaryDifferentialEquat * @param [in] velocity_i_m_s: Initial value of velocity in the inertial frame [m/s] * @param [in] initial_time_s: Initial time [sec] */ - Rk4OrbitPropagation(const CelestialInformation* celestial_information, double gravity_constant_m3_s2, double time_step_s, + Rk4OrbitPropagation(const environment::CelestialInformation* celestial_information, double gravity_constant_m3_s2, double time_step_s, math::Vector<3> position_i_m, math::Vector<3> velocity_i_m_s, double initial_time_s = 0); /** * @fn ~Rk4OrbitPropagation @@ -69,4 +71,6 @@ class Rk4OrbitPropagation : public Orbit, public math::OrdinaryDifferentialEquat void Initialize(math::Vector<3> position_i_m, math::Vector<3> velocity_i_m_s, double initial_time_s = 0); }; +} // namespace s2e::dynamics::orbit + #endif // S2E_DYNAMICS_ORBIT_RK4_ORBIT_PROPAGATION_HPP_ diff --git a/src/dynamics/orbit/sgp4_orbit_propagation.cpp b/src/dynamics/orbit/sgp4_orbit_propagation.cpp index 30451f568..691644184 100644 --- a/src/dynamics/orbit/sgp4_orbit_propagation.cpp +++ b/src/dynamics/orbit/sgp4_orbit_propagation.cpp @@ -9,8 +9,10 @@ #include #include -Sgp4OrbitPropagation::Sgp4OrbitPropagation(const CelestialInformation* celestial_information, char* tle1, char* tle2, const int wgs_setting, - const double current_time_jd) +namespace s2e::dynamics::orbit { + +Sgp4OrbitPropagation::Sgp4OrbitPropagation(const environment::CelestialInformation* celestial_information, char* tle1, char* tle2, + const int wgs_setting, const double current_time_jd) : Orbit(celestial_information) { propagate_mode_ = OrbitPropagateMode::kSgp4; @@ -66,3 +68,5 @@ void Sgp4OrbitPropagation::Propagate(const double end_time_s, const double curre TransformEciToEcef(); TransformEcefToGeodetic(); } + +} // namespace s2e::dynamics::orbit diff --git a/src/dynamics/orbit/sgp4_orbit_propagation.hpp b/src/dynamics/orbit/sgp4_orbit_propagation.hpp index 42b69681c..5ccfea6ed 100644 --- a/src/dynamics/orbit/sgp4_orbit_propagation.hpp +++ b/src/dynamics/orbit/sgp4_orbit_propagation.hpp @@ -13,6 +13,8 @@ #include "orbit.hpp" +namespace s2e::dynamics::orbit { + /** * @class Sgp4OrbitPropagation * @brief Class to propagate spacecraft orbit with SGP4 method with TLE @@ -28,7 +30,7 @@ class Sgp4OrbitPropagation : public Orbit { * @param [in] wgs_setting: Wold Geodetic System * @param [in] current_time_jd: Current Julian day [day] */ - Sgp4OrbitPropagation(const CelestialInformation* celestial_information, char* tle1, char* tle2, const int wgs_setting, + Sgp4OrbitPropagation(const environment::CelestialInformation* celestial_information, char* tle1, char* tle2, const int wgs_setting, const double current_time_jd); // Override Orbit @@ -45,4 +47,6 @@ class Sgp4OrbitPropagation : public Orbit { elsetrec sgp4_data_; //!< Structure data for SGP4 library }; +} // namespace s2e::dynamics::orbit + #endif // S2E_DYNAMICS_ORBIT_SGP4_ORBIT_PROPAGATION_HPP_ diff --git a/src/dynamics/orbit/time_series_file_orbit_propagation.cpp b/src/dynamics/orbit/time_series_file_orbit_propagation.cpp index 709b23335..5230a18c2 100644 --- a/src/dynamics/orbit/time_series_file_orbit_propagation.cpp +++ b/src/dynamics/orbit/time_series_file_orbit_propagation.cpp @@ -14,9 +14,12 @@ #include "math_physics/math/constants.hpp" #include "setting_file_reader/initialize_file_access.hpp" -TimeSeriesFileOrbitPropagation::TimeSeriesFileOrbitPropagation(const CelestialInformation* celestial_information, std::string time_series_file_path, - int number_of_interpolation, int interpolation_method, - double orbital_period_correction_s, const double current_time_jd) +namespace s2e::dynamics::orbit { + +TimeSeriesFileOrbitPropagation::TimeSeriesFileOrbitPropagation(const environment::CelestialInformation* celestial_information, + std::string time_series_file_path, int number_of_interpolation, + int interpolation_method, double orbital_period_correction_s, + const double current_time_jd) : Orbit(celestial_information), is_time_range_warning_displayed_(false), is_interpolation_method_error_displayed_(false), @@ -27,7 +30,7 @@ TimeSeriesFileOrbitPropagation::TimeSeriesFileOrbitPropagation(const CelestialIn propagate_mode_ = OrbitPropagateMode::kTimeSeriesFile; // Read time series file - IniAccess time_series_file(time_series_file_path); + setting_file_reader::IniAccess time_series_file(time_series_file_path); time_series_file.ReadCsvDoubleWithHeader(time_series_data_, 7, 1, 0); // Get general info @@ -41,8 +44,8 @@ TimeSeriesFileOrbitPropagation::TimeSeriesFileOrbitPropagation(const CelestialIn reference_time_ = CalcEphemerisTimeData(reference_interpolation_id_); // Initialize orbit - orbit_position_i_m_.assign(1, orbit::InterpolationOrbit(number_of_interpolation)); - orbit_velocity_i_m_s_.assign(1, orbit::InterpolationOrbit(number_of_interpolation)); + orbit_position_i_m_.assign(1, s2e::orbit::InterpolationOrbit(number_of_interpolation)); + orbit_velocity_i_m_s_.assign(1, s2e::orbit::InterpolationOrbit(number_of_interpolation)); // Initialize interpolation for (int i = 0; i < number_of_interpolation; i++) { @@ -153,3 +156,4 @@ bool TimeSeriesFileOrbitPropagation::UpdateInterpolationInformation() { return true; } +} // namespace s2e::dynamics::orbit diff --git a/src/dynamics/orbit/time_series_file_orbit_propagation.hpp b/src/dynamics/orbit/time_series_file_orbit_propagation.hpp index 0db88a7de..722796b00 100644 --- a/src/dynamics/orbit/time_series_file_orbit_propagation.hpp +++ b/src/dynamics/orbit/time_series_file_orbit_propagation.hpp @@ -12,6 +12,7 @@ #include "orbit.hpp" +namespace s2e::dynamics::orbit { /** * @class TimeSeriesFileOrbitPropagation * @brief Class to calculate satellite orbit using interpolation with orbit time series input @@ -28,7 +29,7 @@ class TimeSeriesFileOrbitPropagation : public Orbit { * @param [in] orbital_period_correction_s: Orbital period correction [s] * @param [in] current_time_jd: Current Julian day [day] */ - TimeSeriesFileOrbitPropagation(const CelestialInformation* celestial_information, const std::string time_series_file_path, + TimeSeriesFileOrbitPropagation(const environment::CelestialInformation* celestial_information, const std::string time_series_file_path, const int number_of_interpolation, const int interpolation_method, const double orbital_period_correction_s, const double current_time_jd); @@ -73,8 +74,8 @@ class TimeSeriesFileOrbitPropagation : public Orbit { double reference_time_; //!< Reference start time of the time series data handling size_t reference_interpolation_id_; //!< Reference EphemerisTime ID of the interpolation - std::vector orbit_position_i_m_; //!< Position with interpolation - std::vector orbit_velocity_i_m_s_; //!< Velocity with interpolation + std::vector orbit_position_i_m_; //!< Position with interpolation + std::vector orbit_velocity_i_m_s_; //!< Velocity with interpolation /** * @fn UpdateInterpolationInformation @@ -84,5 +85,6 @@ class TimeSeriesFileOrbitPropagation : public Orbit { bool UpdateInterpolationInformation(); }; -#endif // S2E_DYNAMICS_ORBIT_TIME_SERIES_FILE_ORBIT_PROPAGATION_HPP_ +} // namespace s2e::dynamics::orbit +#endif // S2E_DYNAMICS_ORBIT_TIME_SERIES_FILE_ORBIT_PROPAGATION_HPP_ diff --git a/src/dynamics/thermal/heater.cpp b/src/dynamics/thermal/heater.cpp index d47ce224a..e43e32951 100644 --- a/src/dynamics/thermal/heater.cpp +++ b/src/dynamics/thermal/heater.cpp @@ -5,6 +5,8 @@ using namespace std; +namespace s2e::dynamics::thermal { + Heater::Heater(const size_t heater_id, const double power_rating_W) : heater_id_(heater_id), power_rating_W_(power_rating_W) { AssertHeaterParams(); heater_status_ = HeaterStatus::kOff; @@ -75,3 +77,5 @@ Heater InitHeater(const std::vector& heater_str) { Heater heater(heater_id, power_rating_W); return heater; } + +} // namespace s2e::dynamics::thermal diff --git a/src/dynamics/thermal/heater.hpp b/src/dynamics/thermal/heater.hpp index 42ea9774f..5643efcdc 100644 --- a/src/dynamics/thermal/heater.hpp +++ b/src/dynamics/thermal/heater.hpp @@ -11,6 +11,8 @@ #include #include +namespace s2e::dynamics::thermal { + /** * @enum HeaterStatus * @brief Status of heater (On/Off) @@ -99,4 +101,6 @@ class Heater { */ Heater InitHeater(const std::vector& heater_str); +} // namespace s2e::dynamics::thermal + #endif // S2E_DYNAMICS_THERMAL_HEATER_HPP_ diff --git a/src/dynamics/thermal/heater_controller.cpp b/src/dynamics/thermal/heater_controller.cpp index 93c0fc811..e0c02658f 100644 --- a/src/dynamics/thermal/heater_controller.cpp +++ b/src/dynamics/thermal/heater_controller.cpp @@ -4,6 +4,8 @@ #include using namespace std; +namespace s2e::dynamics::thermal { + HeaterController::HeaterController(const double lower_threshold_degC, const double upper_threshold_degC) : lower_threshold_degC_(lower_threshold_degC), upper_threshold_degC_(upper_threshold_degC) { AssertHeaterControllerParams(); @@ -52,3 +54,5 @@ HeaterController InitHeaterController(const std::vector& heater_str HeaterController heater_controller(lower_threshold_degC, upper_threshold_degC); return heater_controller; } + +} // namespace s2e::dynamics::thermal diff --git a/src/dynamics/thermal/heater_controller.hpp b/src/dynamics/thermal/heater_controller.hpp index 4c2353fb0..0d8f76bc5 100644 --- a/src/dynamics/thermal/heater_controller.hpp +++ b/src/dynamics/thermal/heater_controller.hpp @@ -13,6 +13,8 @@ #include "heater.hpp" +namespace s2e::dynamics::thermal { + class HeaterController { public: /** @@ -43,12 +45,12 @@ class HeaterController { * @fn GetLowerThreshold_K * @brief Return Lower Threshold [K] */ - inline double GetLowerThreshold_K(void) const { return degC2K(lower_threshold_degC_); } + inline double GetLowerThreshold_K(void) const { return environment::degC2K(lower_threshold_degC_); } /** * @fn GetUpperThreshold_K * @brief Return Upper Threshold [K] */ - inline double GetUpperThreshold_K(void) const { return degC2K(upper_threshold_degC_); } + inline double GetUpperThreshold_K(void) const { return environment::degC2K(upper_threshold_degC_); } // Setter /** @@ -89,4 +91,6 @@ class HeaterController { */ HeaterController InitHeaterController(const std::vector& heater_str); +} // namespace s2e::dynamics::thermal + #endif // S2E_DYNAMICS_THERMAL_HEATER_CONTROLLER_HPP_ diff --git a/src/dynamics/thermal/heatload.cpp b/src/dynamics/thermal/heatload.cpp index 415038f5f..29b8cdb44 100644 --- a/src/dynamics/thermal/heatload.cpp +++ b/src/dynamics/thermal/heatload.cpp @@ -5,7 +5,9 @@ #include using namespace std; -using namespace math; +using namespace s2e::math; + +namespace s2e::dynamics::thermal { Heatload::Heatload(int node_id, std::vector time_table_s, std::vector internal_heatload_table_W) : node_id_(node_id), time_table_s_(time_table_s), internal_heatload_table_W_(internal_heatload_table_W) { @@ -100,3 +102,5 @@ Heatload InitHeatload(const std::vector& time_str, const std::vecto return Heatload(node_id, time_table_s, internal_heatload_table_W); } + +} // namespace s2e::dynamics::thermal diff --git a/src/dynamics/thermal/heatload.hpp b/src/dynamics/thermal/heatload.hpp index ef17d51e4..a4e4afb25 100644 --- a/src/dynamics/thermal/heatload.hpp +++ b/src/dynamics/thermal/heatload.hpp @@ -10,6 +10,8 @@ #include #include +namespace s2e::dynamics::thermal { + /** * @class Heatload * @brief Class for calculating heatload value for Node class object at elapsed time @@ -127,4 +129,6 @@ class Heatload { */ Heatload InitHeatload(const std::vector& time_str, const std::vector& internal_heatload_str); +} // namespace s2e::dynamics::thermal + #endif // S2E_DYNAMICS_THERMAL_HEATLOAD_HPP_ diff --git a/src/dynamics/thermal/node.cpp b/src/dynamics/thermal/node.cpp index 48f6d9232..24440ce5a 100644 --- a/src/dynamics/thermal/node.cpp +++ b/src/dynamics/thermal/node.cpp @@ -10,7 +10,9 @@ #include using namespace std; -using namespace math; +using namespace s2e::math; + +namespace s2e::dynamics::thermal { Node::Node(const size_t node_id, const string node_name, const NodeType node_type, const size_t heater_id, const double temperature_ini_K, const double capacity_J_K, const double alpha, const double area_m2, math::Vector<3> normal_vector_b) @@ -186,3 +188,5 @@ Node InitNode(const std::vector& node_str) { Node node(node_id, node_label, node_type, heater_id, temperature_K, capacity_J_K, alpha, area_m2, normal_v_b); return node; } + +} // namespace s2e::dynamics::thermal diff --git a/src/dynamics/thermal/node.hpp b/src/dynamics/thermal/node.hpp index 248053f4e..6c9da2660 100644 --- a/src/dynamics/thermal/node.hpp +++ b/src/dynamics/thermal/node.hpp @@ -11,6 +11,8 @@ #include #include +namespace s2e::dynamics::thermal { + /** * @enum NodeType * @brief Type of node @@ -100,7 +102,7 @@ class Node { * @brief Get temperature of node in degC * @return double: temperature [degC] */ - inline double GetTemperature_degC(void) const { return K2degC(temperature_K_); } + inline double GetTemperature_degC(void) const { return environment::K2degC(temperature_K_); } /** * @fn GetCapacity_J_K * @brief Return heat capacity of node [J/K] @@ -170,4 +172,6 @@ class Node { */ Node InitNode(const std::vector& node_str); +} // namespace s2e::dynamics::thermal + #endif // S2E_DYNAMICS_THERMAL_NODE_HPP_ diff --git a/src/dynamics/thermal/temperature.cpp b/src/dynamics/thermal/temperature.cpp index 8436db0ac..4fd6cc251 100644 --- a/src/dynamics/thermal/temperature.cpp +++ b/src/dynamics/thermal/temperature.cpp @@ -14,10 +14,13 @@ using namespace std; +namespace s2e::dynamics::thermal { + Temperature::Temperature(const vector> conductance_matrix_W_K, const vector> radiation_matrix_m2, vector nodes, vector heatloads, vector heaters, vector heater_controllers, const size_t node_num, - const double propagation_step_s, const SolarRadiationPressureEnvironment* srp_environment, const EarthAlbedo* earth_albedo, - const bool is_calc_enabled, const SolarCalcSetting solar_calc_setting, const bool debug) + const double propagation_step_s, const environment::SolarRadiationPressureEnvironment* srp_environment, + const environment::EarthAlbedo* earth_albedo, const bool is_calc_enabled, const SolarCalcSetting solar_calc_setting, + const bool debug) : conductance_matrix_W_K_(conductance_matrix_W_K), radiation_matrix_m2_(radiation_matrix_m2), nodes_(nodes), @@ -48,7 +51,7 @@ Temperature::Temperature() { Temperature::~Temperature() {} -void Temperature::Propagate(const LocalCelestialInformation* local_celestial_information, const double time_end_s) { +void Temperature::Propagate(const environment::LocalCelestialInformation* local_celestial_information, const double time_end_s) { if (!is_calc_enabled_) return; while (time_end_s - propagation_time_s_ - propagation_step_s_ > 1.0e-6) { CalcRungeOneStep(propagation_time_s_, propagation_step_s_, local_celestial_information, node_num_); @@ -91,7 +94,7 @@ void Temperature::Propagate(const LocalCelestialInformation* local_celestial_inf } } -void Temperature::CalcRungeOneStep(double time_now_s, double time_step_s, const LocalCelestialInformation* local_celestial_information, +void Temperature::CalcRungeOneStep(double time_now_s, double time_step_s, const environment::LocalCelestialInformation* local_celestial_information, size_t node_num) { vector temperatures_now_K(node_num); for (size_t i = 0; i < node_num; i++) { @@ -129,7 +132,7 @@ void Temperature::CalcRungeOneStep(double time_now_s, double time_step_s, const } vector Temperature::CalcTemperatureDifferentials(vector temperatures_K, double t, - const LocalCelestialInformation* local_celestial_information, size_t node_num) { + const environment::LocalCelestialInformation* local_celestial_information, size_t node_num) { // TODO: consider the following unused arguments are really needed UNUSED(temperatures_K); @@ -194,14 +197,14 @@ string Temperature::GetLogHeader() const { // Do not retrieve boundary node values if (nodes_[i].GetNodeType() != NodeType::kBoundary) { string str_node = "temp_" + to_string(nodes_[i].GetNodeId()) + " (" + nodes_[i].GetNodeName() + ")"; - str_tmp += WriteScalar(str_node, "deg"); + str_tmp += logger::WriteScalar(str_node, "deg"); } } for (size_t i = 0; i < node_num_; i++) { // Do not retrieve boundary node values if (nodes_[i].GetNodeType() != NodeType::kBoundary) { string str_node = "heat_" + to_string(nodes_[i].GetNodeId()) + " (" + nodes_[i].GetNodeName() + ")"; - str_tmp += WriteScalar(str_node, "W"); + str_tmp += logger::WriteScalar(str_node, "W"); } } return str_tmp; @@ -212,13 +215,13 @@ string Temperature::GetLogValue() const { for (size_t i = 0; i < node_num_; i++) { // Do not retrieve boundary node values if (nodes_[i].GetNodeType() != NodeType::kBoundary) { - str_tmp += WriteScalar(nodes_[i].GetTemperature_degC()); + str_tmp += logger::WriteScalar(nodes_[i].GetTemperature_degC()); } } for (size_t i = 0; i < node_num_; i++) { // Do not retrieve boundary node values if (nodes_[i].GetNodeType() != NodeType::kBoundary) { - str_tmp += WriteScalar(heatloads_[i].GetTotalHeatload_W()); + str_tmp += logger::WriteScalar(heatloads_[i].GetTotalHeatload_W()); } } return str_tmp; @@ -289,9 +292,9 @@ First row is time data using std::string; using std::vector; -Temperature* InitTemperature(const std::string file_name, const double rk_prop_step_s, const SolarRadiationPressureEnvironment* srp_environment, - const EarthAlbedo* earth_albedo) { - auto mainIni = IniAccess(file_name); +Temperature* InitTemperature(const std::string file_name, const double rk_prop_step_s, + const environment::SolarRadiationPressureEnvironment* srp_environment, const environment::EarthAlbedo* earth_albedo) { + auto mainIni = setting_file_reader::IniAccess(file_name); vector node_list; vector heater_list; @@ -329,7 +332,7 @@ Temperature* InitTemperature(const std::string file_name, const double rk_prop_s // Read Heatloads from CSV File string filepath_heatload = file_path + "heatload.csv"; - IniAccess conf_heatload(filepath_heatload); + setting_file_reader::IniAccess conf_heatload(filepath_heatload); conf_heatload.ReadCsvString(heatload_str_list, 100); /*since we don't know the number of node_list yet, set node_num=100 temporary. Recall that Nodes_num are given to this function only to reserve memory*/ @@ -342,7 +345,7 @@ Temperature* InitTemperature(const std::string file_name, const double rk_prop_s // Read Node Properties from CSV File string filepath_node = file_path + "node.csv"; - IniAccess conf_node(filepath_node); + setting_file_reader::IniAccess conf_node(filepath_node); conf_node.ReadCsvString(node_str_list, 100); /*since we don't know the number of node_list yet, set node_num=100 temporary. Recall that Nodes_num are given to this function only to reserve memory*/ @@ -357,7 +360,7 @@ Temperature* InitTemperature(const std::string file_name, const double rk_prop_s // Read Heater Properties from CSV File string filepath_heater = file_path + "heaters.csv"; - IniAccess conf_heater(filepath_heater); + setting_file_reader::IniAccess conf_heater(filepath_heater); conf_heater.ReadCsvString(heater_str_list, 100); /*since we don't know the number of heater_list yet, set heater_num=100 temporary. Recall that heater_num are given to this function only to reserve memory*/ @@ -373,8 +376,8 @@ Temperature* InitTemperature(const std::string file_name, const double rk_prop_s // Read Cij,Rij data from CSV File string filepath_cij = file_path + "cij.csv"; string filepath_rij = file_path + "rij.csv"; - IniAccess conf_cij(filepath_cij); - IniAccess conf_rij(filepath_rij); + setting_file_reader::IniAccess conf_cij(filepath_cij); + setting_file_reader::IniAccess conf_rij(filepath_rij); conf_cij.ReadCsvDoubleWithHeader(conductance_matrix, node_num, 1, 1); conf_rij.ReadCsvDoubleWithHeader(radiation_matrix, node_num, 1, 1); @@ -388,3 +391,5 @@ Temperature* InitTemperature(const std::string file_name, const double rk_prop_s rk_prop_step_s, srp_environment, earth_albedo, is_calc_enabled, solar_calc_setting, debug); return temperature; } + +} // namespace s2e::dynamics::thermal diff --git a/src/dynamics/thermal/temperature.hpp b/src/dynamics/thermal/temperature.hpp index d286a7e91..292e432d5 100644 --- a/src/dynamics/thermal/temperature.hpp +++ b/src/dynamics/thermal/temperature.hpp @@ -17,6 +17,8 @@ #include "heatload.hpp" #include "node.hpp" +namespace s2e::dynamics::thermal { + /** * @enum SolarCalcSetting * @brief Whether to calculate solar radiation inside simulation @@ -30,7 +32,7 @@ enum class SolarCalcSetting { * @class Temperature * @brief class to calculate temperature of all nodes */ -class Temperature : public ILoggable { +class Temperature : public logger::ILoggable { protected: std::vector> conductance_matrix_W_K_; //!< Coupling of node i and node j by heat conduction [W/K] std::vector> radiation_matrix_m2_; //!< Coupling of node i and node j by thermal radiation [m2] @@ -41,11 +43,11 @@ class Temperature : public ILoggable { size_t node_num_; //!< number of nodes double propagation_step_s_; //!< propagation step [s] double propagation_time_s_; //!< Incremented time inside class Temperature [s], finish propagation when reaching end_time - const SolarRadiationPressureEnvironment* srp_environment_; //!< SolarRadiationPressureEnvironment for calculating solar flux - const EarthAlbedo* earth_albedo_; //!< EarthAlbedo object for calculating earth albedo - bool is_calc_enabled_; //!< Whether temperature calculation is enabled - SolarCalcSetting solar_calc_setting_; //!< setting for solar calculation - bool debug_; //!< Activate debug output or not + const environment::SolarRadiationPressureEnvironment* srp_environment_; //!< SolarRadiationPressureEnvironment for calculating solar flux + const environment::EarthAlbedo* earth_albedo_; //!< EarthAlbedo object for calculating earth albedo + bool is_calc_enabled_; //!< Whether temperature calculation is enabled + SolarCalcSetting solar_calc_setting_; //!< setting for solar calculation + bool debug_; //!< Activate debug output or not /** * @fn CalcRungeOneStep @@ -56,7 +58,8 @@ class Temperature : public ILoggable { * @param[in] local_celestial_information: LocalCelestialInformation object for calculating radiation * @param[in] node_num: Number of nodes */ - void CalcRungeOneStep(double time_now_s, double time_step_s, const LocalCelestialInformation* local_celestial_information, size_t node_num); + void CalcRungeOneStep(double time_now_s, double time_step_s, const environment::LocalCelestialInformation* local_celestial_information, + size_t node_num); /** * @fn CalcTemperatureDifferentials * @brief Calculate differential of thermal equilibrium equation @@ -68,7 +71,7 @@ class Temperature : public ILoggable { * @return std::vector: Differential of thermal equilibrium equation at time now */ std::vector CalcTemperatureDifferentials(std::vector temperatures_K, double time_now_s, - const LocalCelestialInformation* local_celestial_information, size_t node_num); + const environment::LocalCelestialInformation* local_celestial_information, size_t node_num); public: /** @@ -91,8 +94,8 @@ class Temperature : public ILoggable { */ Temperature(const std::vector> conductance_matrix_W_K, const std::vector> radiation_matrix_m2, std::vector nodes, std::vector heatloads, std::vector heaters, std::vector heater_controllers, - const size_t node_num, const double propagation_step_s, const SolarRadiationPressureEnvironment* srp_environment, - const EarthAlbedo* earth_albedo, const bool is_calc_enabled, const SolarCalcSetting solar_calc_setting, const bool debug); + const size_t node_num, const double propagation_step_s, const environment::SolarRadiationPressureEnvironment* srp_environment, + const environment::EarthAlbedo* earth_albedo, const bool is_calc_enabled, const SolarCalcSetting solar_calc_setting, const bool debug); /** * @fn Temperature * @brief Construct a new Temperature object, used when thermal calculation is disabled. @@ -112,11 +115,12 @@ class Temperature : public ILoggable { * @param[in] local_celestial_information: LocalCelestialInformation object for calculating radiation * @param time_end_s: Time to finish propagation [s] */ - void Propagate(const LocalCelestialInformation* local_celestial_information, const double time_end_s); + void Propagate(const environment::LocalCelestialInformation* local_celestial_information, const double time_end_s); // Getter /** * @fn GetNodes + * * @brief Return Nodes * @return std::vector */ @@ -162,7 +166,9 @@ class Temperature : public ILoggable { * @param[in] srp_environment: SolarRadiationPressureEnvironment object for calculating solar flux * @return Temperature* */ -Temperature* InitTemperature(const std::string file_name, const double rk_prop_step_s, const SolarRadiationPressureEnvironment* srp_environment, - const EarthAlbedo* earth_albedo); +Temperature* InitTemperature(const std::string file_name, const double rk_prop_step_s, + const environment::SolarRadiationPressureEnvironment* srp_environment, const environment::EarthAlbedo* earth_albedo); + +} // namespace s2e::dynamics::thermal #endif // S2E_DYNAMICS_THERMAL_TEMPERATURE_HPP_ diff --git a/src/environment/global/celestial_information.cpp b/src/environment/global/celestial_information.cpp index c51461e92..a8ffde6eb 100644 --- a/src/environment/global/celestial_information.cpp +++ b/src/environment/global/celestial_information.cpp @@ -18,6 +18,8 @@ #include "logger/log_utility.hpp" #include "setting_file_reader/initialize_file_access.hpp" +namespace s2e::environment { + CelestialInformation::CelestialInformation(const std::string inertial_frame_name, const std::string aberration_correction_setting, const std::string center_body_name, const unsigned int number_of_selected_body, int* selected_body_ids, const std::vector rotation_mode_list) @@ -163,8 +165,8 @@ std::string CelestialInformation::GetLogHeader() const { std::string body_pos = name + "_position"; std::string body_vel = name + "_velocity"; - str_tmp += WriteVector(body_pos, "i", "m", 3); - str_tmp += WriteVector(body_vel, "i", "m/s", 3); + str_tmp += logger::WriteVector(body_pos, "i", "m", 3); + str_tmp += logger::WriteVector(body_vel, "i", "m/s", 3); } return str_tmp; } @@ -173,10 +175,10 @@ std::string CelestialInformation::GetLogValue() const { std::string str_tmp = ""; for (unsigned int i = 0; i < number_of_selected_bodies_; i++) { for (int j = 0; j < 3; j++) { - str_tmp += WriteScalar(celestial_body_position_from_center_i_m_[i * 3 + j]); + str_tmp += logger::WriteScalar(celestial_body_position_from_center_i_m_[i * 3 + j]); } for (int j = 0; j < 3; j++) { - str_tmp += WriteScalar(celestial_body_velocity_from_center_i_m_s_[i * 3 + j]); + str_tmp += logger::WriteScalar(celestial_body_velocity_from_center_i_m_s_[i * 3 + j]); } } return str_tmp; @@ -199,7 +201,7 @@ void CelestialInformation::GetPlanetOrbit(const char* planet_name, const double } CelestialInformation* InitCelestialInformation(std::string file_name) { - IniAccess ini_file(file_name); + setting_file_reader::IniAccess ini_file(file_name); const char* section = "CELESTIAL_INFORMATION"; const char* furnsh_section = "CSPICE_KERNELS"; @@ -244,3 +246,5 @@ CelestialInformation* InitCelestialInformation(std::string file_name) { return celestial_info; } + +} // namespace s2e::environment diff --git a/src/environment/global/celestial_information.hpp b/src/environment/global/celestial_information.hpp index 50103ffca..ea04e562d 100644 --- a/src/environment/global/celestial_information.hpp +++ b/src/environment/global/celestial_information.hpp @@ -15,6 +15,8 @@ #include "moon_rotation.hpp" #include "simulation_time.hpp" +namespace s2e::environment { + class MoonRotation; /** @@ -22,7 +24,7 @@ class MoonRotation; * @brief Class to manage the information related with the celestial bodies * @details This class uses SPICE to get the information of celestial bodies */ -class CelestialInformation : public ILoggable { +class CelestialInformation : public logger::ILoggable { public: /** * @fn CelestialInformation @@ -47,15 +49,15 @@ class CelestialInformation : public ILoggable { */ virtual ~CelestialInformation(); - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; @@ -281,4 +283,6 @@ class CelestialInformation : public ILoggable { */ CelestialInformation* InitCelestialInformation(std::string file_name); +} // namespace s2e::environment + #endif // S2E_ENVIRONMENT_GLOBAL_CELESTIAL_INFORMATION_HPP_ diff --git a/src/environment/global/clock_generator.cpp b/src/environment/global/clock_generator.cpp index a196efac0..5fd61999c 100644 --- a/src/environment/global/clock_generator.cpp +++ b/src/environment/global/clock_generator.cpp @@ -5,11 +5,13 @@ #include "clock_generator.hpp" +namespace s2e::environment { + ClockGenerator::~ClockGenerator() {} -void ClockGenerator::RegisterComponent(ITickable* tickable) { components_.push_back(tickable); } +void ClockGenerator::RegisterComponent(components::ITickable* tickable) { components_.push_back(tickable); } -void ClockGenerator::RemoveComponent(ITickable* tickable) { +void ClockGenerator::RemoveComponent(components::ITickable* tickable) { for (auto itr = components_.begin(); itr != components_.end();) { if (*itr == tickable) { components_.erase(itr++); @@ -38,3 +40,5 @@ void ClockGenerator::UpdateComponents(const SimulationTime* simulation_time) { TickToComponents(); } } + +} // namespace s2e::environment diff --git a/src/environment/global/clock_generator.hpp b/src/environment/global/clock_generator.hpp index b09b80c4a..87361d772 100644 --- a/src/environment/global/clock_generator.hpp +++ b/src/environment/global/clock_generator.hpp @@ -11,6 +11,8 @@ #include "simulation_time.hpp" +namespace s2e::environment { + /** * @class ClockGenerator * @brief Class to generate clock for classes which have ITickable @@ -28,13 +30,13 @@ class ClockGenerator { * @brief Register component which has ITickable * @param [in] tickable: Component class */ - void RegisterComponent(ITickable* tickable); + void RegisterComponent(components::ITickable* tickable); /** * @fn RemoveComponent * @brief Removed registered component * @param [in] tickable: Registered component class */ - void RemoveComponent(ITickable* tickable); + void RemoveComponent(components::ITickable* tickable); /** * @fn TickToComponents * @brief Execute tick function of all registered components @@ -53,8 +55,10 @@ class ClockGenerator { inline void ClearTimerCount(void) { timer_count_ = 0; } private: - std::vector components_; //!< Component list fot tick - unsigned int timer_count_; //!< Timer count TODO: change to long? + std::vector components_; //!< Component list fot tick + unsigned int timer_count_; //!< Timer count TODO: change to long? }; +} // namespace s2e::environment + #endif // S2E_ENVIRONMENT_GLOBAL_CLOCK_GENERATOR_HPP_ diff --git a/src/environment/global/earth_rotation.cpp b/src/environment/global/earth_rotation.cpp index dd552f04d..f7eedde82 100644 --- a/src/environment/global/earth_rotation.cpp +++ b/src/environment/global/earth_rotation.cpp @@ -15,6 +15,8 @@ #include "math_physics/orbit/sgp4/sgp4ext.h" // for jday() #include "math_physics/orbit/sgp4/sgp4unit.h" // for gstime() +namespace s2e::environment { + // Default constructor EarthRotation::EarthRotation(const EarthRotationMode rotation_mode) : rotation_mode_(rotation_mode) { dcm_j2000_to_ecef_ = math::MakeIdentityMatrix<3>(); @@ -275,3 +277,5 @@ EarthRotationMode ConvertEarthRotationMode(const std::string mode) { return rotation_mode; } + +} // namespace s2e::environment diff --git a/src/environment/global/earth_rotation.hpp b/src/environment/global/earth_rotation.hpp index c12af3f2f..4c1668adb 100644 --- a/src/environment/global/earth_rotation.hpp +++ b/src/environment/global/earth_rotation.hpp @@ -11,6 +11,8 @@ #include "math_physics/math/matrix.hpp" +namespace s2e::environment { + /** * @enum EarthRotationMode * @brief Definition of calculation mode of earth rotation @@ -122,4 +124,6 @@ class EarthRotation { EarthRotationMode ConvertEarthRotationMode(const std::string mode); +} // namespace s2e::environment + #endif // S2E_ENVIRONMENT_GLOBAL_EARTH_ROTATION_HPP_ diff --git a/src/environment/global/global_environment.cpp b/src/environment/global/global_environment.cpp index 0e89b2346..0244387fe 100644 --- a/src/environment/global/global_environment.cpp +++ b/src/environment/global/global_environment.cpp @@ -7,7 +7,9 @@ #include "setting_file_reader/initialize_file_access.hpp" -GlobalEnvironment::GlobalEnvironment(const SimulationConfiguration* simulation_configuration) { Initialize(simulation_configuration); } +namespace s2e::environment { + +GlobalEnvironment::GlobalEnvironment(const simulation::SimulationConfiguration* simulation_configuration) { Initialize(simulation_configuration); } GlobalEnvironment::~GlobalEnvironment() { delete simulation_time_; @@ -16,9 +18,9 @@ GlobalEnvironment::~GlobalEnvironment() { delete gnss_satellites_; } -void GlobalEnvironment::Initialize(const SimulationConfiguration* simulation_configuration) { +void GlobalEnvironment::Initialize(const simulation::SimulationConfiguration* simulation_configuration) { // Get ini file path - IniAccess iniAccess = IniAccess(simulation_configuration->initialize_base_file_name_); + setting_file_reader::IniAccess iniAccess = setting_file_reader::IniAccess(simulation_configuration->initialize_base_file_name_); std::string simulation_time_ini_path = simulation_configuration->initialize_base_file_name_; // Initialize @@ -37,10 +39,12 @@ void GlobalEnvironment::Update() { gnss_satellites_->Update(*simulation_time_); } -void GlobalEnvironment::LogSetup(Logger& logger) { +void GlobalEnvironment::LogSetup(logger::Logger& logger) { logger.AddLogList(simulation_time_); logger.AddLogList(celestial_information_); logger.AddLogList(gnss_satellites_); } void GlobalEnvironment::Reset(void) { simulation_time_->ResetClock(); } + +} // namespace s2e::environment diff --git a/src/environment/global/global_environment.hpp b/src/environment/global/global_environment.hpp index b8bb56890..2ce5da7c3 100644 --- a/src/environment/global/global_environment.hpp +++ b/src/environment/global/global_environment.hpp @@ -13,6 +13,8 @@ #include "simulation/simulation_configuration.hpp" #include "simulation_time.hpp" +namespace s2e::environment { + /** * @class GlobalEnvironment * @brief Class to manage the global environment @@ -24,7 +26,7 @@ class GlobalEnvironment { * @brief Constructor * @param [in] simulation_configuration: Simulation configuration */ - GlobalEnvironment(const SimulationConfiguration* simulation_configuration); + GlobalEnvironment(const simulation::SimulationConfiguration* simulation_configuration); /** * @fn ~GlobalEnvironment * @brief Destructor @@ -36,7 +38,7 @@ class GlobalEnvironment { * @brief Initialize all global environment members * @param [in] simulation_configuration: Simulation configuration */ - void Initialize(const SimulationConfiguration* simulation_configuration); + void Initialize(const simulation::SimulationConfiguration* simulation_configuration); /** * @fn Update * @brief Update states of all global environment @@ -46,7 +48,7 @@ class GlobalEnvironment { * @fn LogSetup * @brief Log setup of global environment information */ - void LogSetup(Logger& logger); + void LogSetup(logger::Logger& logger); /** * @fn Reset * @brief Reset clock of SimulationTime @@ -82,4 +84,6 @@ class GlobalEnvironment { GnssSatellites* gnss_satellites_; //!< GNSS satellites }; +} // namespace s2e::environment + #endif // S2E_ENVIRONMENT_GLOBAL_GLOBAL_ENVIRONMENT_HPP_ diff --git a/src/environment/global/gnss_satellites.cpp b/src/environment/global/gnss_satellites.cpp index 21749c9aa..25724b5e2 100644 --- a/src/environment/global/gnss_satellites.cpp +++ b/src/environment/global/gnss_satellites.cpp @@ -15,7 +15,9 @@ #include "setting_file_reader/initialize_file_access.hpp" #include "utilities/macros.hpp" -using namespace gnss; +using namespace s2e::gnss; + +namespace s2e::environment { const size_t kNumberOfInterpolation = 9; @@ -156,8 +158,8 @@ std::string GnssSatellites::GetLogHeader() const { // TODO: Add log output for other navigation systems for (size_t gps_index = 0; gps_index < kNumberOfGpsSatellite; gps_index++) { - str_tmp += WriteVector("GPS" + std::to_string(gps_index) + "_position", "ecef", "m", 3); - str_tmp += WriteScalar("GPS" + std::to_string(gps_index) + "_clock_offset", "s"); + str_tmp += logger::WriteVector("GPS" + std::to_string(gps_index) + "_position", "ecef", "m", 3); + str_tmp += logger::WriteScalar("GPS" + std::to_string(gps_index) + "_clock_offset", "s"); } return str_tmp; @@ -167,15 +169,15 @@ std::string GnssSatellites::GetLogValue() const { std::string str_tmp = ""; for (size_t gps_index = 0; gps_index < kNumberOfGpsSatellite; gps_index++) { - str_tmp += WriteVector(GetPosition_ecef_m(gps_index), 16); - str_tmp += WriteScalar(GetClock_s(gps_index)); + str_tmp += logger::WriteVector(GetPosition_ecef_m(gps_index), 16); + str_tmp += logger::WriteScalar(GetClock_s(gps_index)); } return str_tmp; } GnssSatellites* InitGnssSatellites(const std::string file_name, const EarthRotation& earth_rotation, const SimulationTime& simulation_time) { - IniAccess ini_file(file_name); + setting_file_reader::IniAccess ini_file(file_name); char section[] = "GNSS_SATELLITES"; const bool is_calc_enable = ini_file.ReadEnable(section, INI_CALC_LABEL); @@ -234,3 +236,5 @@ GnssSatellites* InitGnssSatellites(const std::string file_name, const EarthRotat return gnss_satellites; } + +} // namespace s2e::environment diff --git a/src/environment/global/gnss_satellites.hpp b/src/environment/global/gnss_satellites.hpp index 77508f73b..065dc5840 100644 --- a/src/environment/global/gnss_satellites.hpp +++ b/src/environment/global/gnss_satellites.hpp @@ -21,11 +21,13 @@ #include "math_physics/math/vector.hpp" #include "simulation_time.hpp" +namespace s2e::environment { + /** * @class GnssSatellites * @brief Class to calculate GNSS satellite position and clock */ -class GnssSatellites : public ILoggable { +class GnssSatellites : public logger::ILoggable { public: /** * @fn GnssSatellites @@ -98,15 +100,15 @@ class GnssSatellites : public ILoggable { */ double GetClock_s(const size_t gnss_satellite_id, const time_system::EpochTime time = time_system::EpochTime(0, 0.0)) const; - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ std::string GetLogHeader() const override; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ std::string GetLogValue() const override; @@ -153,4 +155,6 @@ class GnssSatellites : public ILoggable { */ GnssSatellites* InitGnssSatellites(const std::string file_name, const EarthRotation& earth_rotation, const SimulationTime& simulation_time); +} // namespace s2e::environment + #endif // S2E_ENVIRONMENT_GLOBAL_GNSS_SATELLITES_HPP_ diff --git a/src/environment/global/hipparcos_catalogue.cpp b/src/environment/global/hipparcos_catalogue.cpp index 7ef29494b..8888085ac 100644 --- a/src/environment/global/hipparcos_catalogue.cpp +++ b/src/environment/global/hipparcos_catalogue.cpp @@ -14,6 +14,8 @@ #include "math_physics/math/constants.hpp" #include "setting_file_reader/initialize_file_access.hpp" +namespace s2e::environment { + HipparcosCatalogue::HipparcosCatalogue(double max_magnitude, std::string catalogue_path) : max_magnitude_(max_magnitude), catalogue_path_(catalogue_path) {} @@ -85,7 +87,7 @@ std::string HipparcosCatalogue::GetLogValue() const { } HipparcosCatalogue* InitHipparcosCatalogue(std::string file_name) { - IniAccess ini_file(file_name); + setting_file_reader::IniAccess ini_file(file_name); const char* section = "HIPPARCOS_CATALOGUE"; std::string catalogue_path = ini_file.ReadString(section, "catalogue_file_path"); @@ -99,3 +101,5 @@ HipparcosCatalogue* InitHipparcosCatalogue(std::string file_name) { return hipparcos_catalogue_; } + +} // namespace s2e::environment diff --git a/src/environment/global/hipparcos_catalogue.hpp b/src/environment/global/hipparcos_catalogue.hpp index d4a6afdd4..23dd55630 100644 --- a/src/environment/global/hipparcos_catalogue.hpp +++ b/src/environment/global/hipparcos_catalogue.hpp @@ -12,6 +12,8 @@ #include "math_physics/math/quaternion.hpp" #include "math_physics/math/vector.hpp" +namespace s2e::environment { + /** *@struct HipparcosData *@brief Hipparcos catalogue data @@ -26,7 +28,7 @@ struct HipparcosData { *@class HipparcosCatalogue *@brief Class to calculate star direction with Hipparcos catalogue */ -class HipparcosCatalogue : public ILoggable { +class HipparcosCatalogue : public logger::ILoggable { public: /** *@fn HipparcosCatalogue @@ -91,15 +93,15 @@ class HipparcosCatalogue : public ILoggable { */ math::Vector<3> GetStarDirection_b(size_t rank, math::Quaternion quaternion_i2b) const; - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; @@ -118,4 +120,6 @@ class HipparcosCatalogue : public ILoggable { */ HipparcosCatalogue* InitHipparcosCatalogue(std::string file_name); +} // namespace s2e::environment + #endif // S2E_ENVIRONMENT_GLOBAL_HIPPARCOS_CATALOGUE_HPP_ diff --git a/src/environment/global/moon_rotation.cpp b/src/environment/global/moon_rotation.cpp index 1b8aea98d..c2b107b63 100644 --- a/src/environment/global/moon_rotation.cpp +++ b/src/environment/global/moon_rotation.cpp @@ -10,6 +10,8 @@ #include #include +namespace s2e::environment { + MoonRotation::MoonRotation(const CelestialInformation& celestial_information, MoonRotationMode mode) : mode_(mode), celestial_information_(celestial_information) { dcm_j2000_to_mcmf_ = math::MakeIdentityMatrix<3>(); @@ -50,4 +52,6 @@ MoonRotationMode ConvertMoonRotationMode(const std::string mode) { } return rotation_mode; -} \ No newline at end of file +} + +} // namespace s2e::environment diff --git a/src/environment/global/moon_rotation.hpp b/src/environment/global/moon_rotation.hpp index fa9506757..1c5ea0d68 100644 --- a/src/environment/global/moon_rotation.hpp +++ b/src/environment/global/moon_rotation.hpp @@ -11,6 +11,8 @@ #include "math_physics/math/vector.hpp" #include "simulation_time.hpp" +namespace s2e::environment { + class CelestialInformation; /** @@ -62,4 +64,6 @@ class MoonRotation { const CelestialInformation &celestial_information_; //!< Celestial Information to get moon orbit }; +} // namespace s2e::environment + #endif // S2E_ENVIRONMENT_GLOBAL_MOON_ROTATION_HPP_ diff --git a/src/environment/global/physical_constants.hpp b/src/environment/global/physical_constants.hpp index c2acd7de0..c97259ee2 100644 --- a/src/environment/global/physical_constants.hpp +++ b/src/environment/global/physical_constants.hpp @@ -8,7 +8,7 @@ #include // std::is_floating_point_v -namespace environment { +namespace s2e::environment { template using enable_if_float = std::enable_if_t, T>; @@ -39,9 +39,9 @@ DEFINE_PHYSICAL_CONSTANT(earth_flattening, 3.352797e-3L) / #undef DEFINE_PHYSICAL_CONSTANT -} // namespace environment +inline double degC2K(double degC) { return (degC - absolute_zero_degC); } +inline double K2degC(double K) { return (K + absolute_zero_degC); } -inline double degC2K(double degC) { return (degC - environment::absolute_zero_degC); } -inline double K2degC(double K) { return (K + environment::absolute_zero_degC); } +} // namespace s2e::environment #endif // S2E_ENVIRONMENT_GLOBAL_PHYSICAL_CONSTANT_HPP_ diff --git a/src/environment/global/simulation_time.cpp b/src/environment/global/simulation_time.cpp index 149b88f42..6438e5011 100644 --- a/src/environment/global/simulation_time.cpp +++ b/src/environment/global/simulation_time.cpp @@ -21,6 +21,8 @@ using namespace std; +namespace s2e::environment { + SimulationTime::SimulationTime(const double end_sec, const double step_sec, const double attitude_update_interval_sec, const double attitude_rk_step_sec, const double orbit_update_interval_sec, const double orbit_rk_step_sec, const double thermal_update_interval_sec, const double thermal_rk_step_sec, const double compo_propagate_step_sec, @@ -202,8 +204,8 @@ void SimulationTime::PrintStartDateTime(void) const { string SimulationTime::GetLogHeader() const { string str_tmp = ""; - str_tmp += WriteScalar("elapsed_time", "s"); - str_tmp += WriteScalar("time", "UTC"); + str_tmp += logger::WriteScalar("elapsed_time", "s"); + str_tmp += logger::WriteScalar("time", "UTC"); return str_tmp; } @@ -211,7 +213,7 @@ string SimulationTime::GetLogHeader() const { string SimulationTime::GetLogValue() const { string str_tmp = ""; - str_tmp += WriteScalar(elapsed_time_sec_); + str_tmp += logger::WriteScalar(elapsed_time_sec_); const char kSize = 100; char ymdhms[kSize]; @@ -245,7 +247,7 @@ void SimulationTime::ConvJDtoCalendarDay(const double JD) { } SimulationTime* InitSimulationTime(std::string file_name) { - IniAccess ini_file(file_name); + setting_file_reader::IniAccess ini_file(file_name); const char* section = "TIME"; // Parameters about entire simulation @@ -275,3 +277,5 @@ SimulationTime* InitSimulationTime(std::string file_name) { return simTime; } + +} // namespace s2e::environment diff --git a/src/environment/global/simulation_time.hpp b/src/environment/global/simulation_time.hpp index f993b5ec8..7a2093c19 100644 --- a/src/environment/global/simulation_time.hpp +++ b/src/environment/global/simulation_time.hpp @@ -19,6 +19,8 @@ #include "math_physics/orbit/sgp4/sgp4io.h" #include "math_physics/orbit/sgp4/sgp4unit.h" +namespace s2e::environment { + /** *@struct TimeState *@brief State of timing controller @@ -47,7 +49,7 @@ struct UTC { *@class SimulationTime *@brief Class to manage simulation time related information */ -class SimulationTime : public ILoggable { +class SimulationTime : public logger::ILoggable { public: /** *@fn SimulationTime @@ -239,15 +241,15 @@ class SimulationTime : public ILoggable { */ inline double GetStartSecond(void) const { return start_sec_; }; - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; @@ -334,4 +336,6 @@ class SimulationTime : public ILoggable { */ SimulationTime* InitSimulationTime(std::string file_name); +} // namespace s2e::environment + #endif // S2E_ENVIRONMENT_GLOBAL_SIMULATION_TIME_HPP_ diff --git a/src/environment/local/atmosphere.cpp b/src/environment/local/atmosphere.cpp index b0792bca4..74b232364 100644 --- a/src/environment/local/atmosphere.cpp +++ b/src/environment/local/atmosphere.cpp @@ -14,6 +14,8 @@ #include "math_physics/randomization/random_walk.hpp" #include "setting_file_reader/initialize_file_access.hpp" +namespace s2e::environment { + Atmosphere::Atmosphere(const std::string model, const std::string space_weather_file_name, const double gauss_standard_deviation_rate, const bool is_manual_param, const double manual_f107, const double manual_f107a, const double manual_ap, const LocalCelestialInformation* local_celestial_information, const SimulationTime* simulation_time) @@ -50,7 +52,7 @@ Atmosphere::Atmosphere(const std::string model, const std::string space_weather_ } } -double Atmosphere::CalcAirDensity_kg_m3(const double decimal_year, const Orbit& orbit) { +double Atmosphere::CalcAirDensity_kg_m3(const double decimal_year, const dynamics::orbit::Orbit& orbit) { if (!is_calc_enabled_) return 0; if (model_ == "STANDARD") { @@ -78,7 +80,7 @@ double Atmosphere::CalcAirDensity_kg_m3(const double decimal_year, const Orbit& double Atmosphere::AddNoise(const double rho_kg_m3) { // RandomWalk rw(rho_kg_m3*rw_stepwidth_,rho_kg_m3*rw_stddev_,rho_kg_m3*rw_limit_); - randomization::NormalRand nr(0.0, rho_kg_m3 * gauss_standard_deviation_rate_, global_randomization.MakeSeed()); + randomization::NormalRand nr(0.0, rho_kg_m3 * gauss_standard_deviation_rate_, randomization::global_randomization.MakeSeed()); double nrd = nr; return rho_kg_m3 + nrd; @@ -86,7 +88,7 @@ double Atmosphere::AddNoise(const double rho_kg_m3) { std::string Atmosphere::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteScalar(air_density_kg_m3_); + str_tmp += logger::WriteScalar(air_density_kg_m3_); return str_tmp; } @@ -94,14 +96,14 @@ std::string Atmosphere::GetLogValue() const { std::string Atmosphere::GetLogHeader() const { std::string str_tmp = ""; - str_tmp += WriteScalar("air_density_at_spacecraft_position", "kg/m3"); + str_tmp += logger::WriteScalar("air_density_at_spacecraft_position", "kg/m3"); return str_tmp; } Atmosphere InitAtmosphere(const std::string initialize_file_path, const LocalCelestialInformation* local_celestial_information, const SimulationTime* simulation_time) { - auto conf = IniAccess(initialize_file_path); + auto conf = setting_file_reader::IniAccess(initialize_file_path); const char* section = "ATMOSPHERE"; double f107_threshold = 50.0; double f107_default = 150.0; @@ -133,3 +135,5 @@ Atmosphere InitAtmosphere(const std::string initialize_file_path, const LocalCel return atmosphere; } + +} // namespace s2e::environment diff --git a/src/environment/local/atmosphere.hpp b/src/environment/local/atmosphere.hpp index 8489891d8..81dd063eb 100644 --- a/src/environment/local/atmosphere.hpp +++ b/src/environment/local/atmosphere.hpp @@ -15,11 +15,13 @@ #include "math_physics/atmosphere/wrapper_nrlmsise00.hpp" #include "math_physics/math/vector.hpp" +namespace s2e::environment { + /** * @class Atmosphere * @brief Class to calculate earth's atmospheric density */ -class Atmosphere : public ILoggable { +class Atmosphere : public logger::ILoggable { public: /** * @fn Atmosphere @@ -49,7 +51,7 @@ class Atmosphere : public ILoggable { * @param [in] position: Position of target point to calculate the air density * @return Atmospheric density [kg/m^3] */ - double CalcAirDensity_kg_m3(const double decimal_year, const Orbit& orbit); + double CalcAirDensity_kg_m3(const double decimal_year, const dynamics::orbit::Orbit& orbit); /** * @fn GetAirDensity * @brief Return Atmospheric density [kg/m^3] @@ -61,15 +63,15 @@ class Atmosphere : public ILoggable { */ inline void SetCalcFlag(const bool is_calc_enabled) { is_calc_enabled_ = is_calc_enabled; } - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; @@ -80,8 +82,8 @@ class Atmosphere : public ILoggable { double air_density_kg_m3_; //!< Atmospheric density [kg/m^3] // NRLMSISE-00 model information - std::vector space_weather_table_; //!< Space weather table - bool is_manual_param_used_; //!< Flag to use manual parameters + std::vector space_weather_table_; //!< Space weather table + bool is_manual_param_used_; //!< Flag to use manual parameters // Reference of the following setting parameters https://www.swpc.noaa.gov/phenomena/f107-cm-radio-emissions double manual_daily_f107_; //!< Manual daily f10.7 value double manual_average_f107_; //!< Manual 3-month averaged f10.7 value @@ -116,4 +118,6 @@ class Atmosphere : public ILoggable { Atmosphere InitAtmosphere(const std::string initialize_file_path, const LocalCelestialInformation* local_celestial_information, const SimulationTime* simulation_time); +} // namespace s2e::environment + #endif // S2E_ENVIRONMENT_LOCAL_ATMOSPHERE_HPP_ diff --git a/src/environment/local/earth_albedo.cpp b/src/environment/local/earth_albedo.cpp index eabb04083..2e1ab6902 100644 --- a/src/environment/local/earth_albedo.cpp +++ b/src/environment/local/earth_albedo.cpp @@ -13,6 +13,8 @@ #include "math_physics/math/vector.hpp" #include "setting_file_reader/initialize_file_access.hpp" +namespace s2e::environment { + EarthAlbedo::EarthAlbedo(LocalCelestialInformation* local_celestial_information, SolarRadiationPressureEnvironment* srp_environment) : local_celestial_information_(local_celestial_information), srp_environment_(srp_environment) {} @@ -24,8 +26,8 @@ void EarthAlbedo::UpdateAllStates() { std::string EarthAlbedo::GetLogHeader() const { std::string str_tmp = ""; - str_tmp += WriteScalar("earth_albedo_factor"); - str_tmp += WriteScalar("earth_albedo_W_m2"); + str_tmp += logger::WriteScalar("earth_albedo_factor"); + str_tmp += logger::WriteScalar("earth_albedo_W_m2"); return str_tmp; } @@ -33,8 +35,8 @@ std::string EarthAlbedo::GetLogHeader() const { std::string EarthAlbedo::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteScalar(earth_albedo_factor_); - str_tmp += WriteScalar(earth_albedo_W_m2_); + str_tmp += logger::WriteScalar(earth_albedo_factor_); + str_tmp += logger::WriteScalar(earth_albedo_W_m2_); return str_tmp; } @@ -48,7 +50,7 @@ void EarthAlbedo::CalcEarthAlbedo(const LocalCelestialInformation* local_celesti EarthAlbedo InitEarthAlbedo(std::string initialize_file_path, LocalCelestialInformation* local_celestial_information, SolarRadiationPressureEnvironment* srp_environment) { - auto conf = IniAccess(initialize_file_path); + auto conf = setting_file_reader::IniAccess(initialize_file_path); const char* section = "EARTH_ALBEDO"; EarthAlbedo earth_albedo(local_celestial_information, srp_environment); @@ -57,3 +59,5 @@ EarthAlbedo InitEarthAlbedo(std::string initialize_file_path, LocalCelestialInfo return earth_albedo; } + +} // namespace s2e::environment diff --git a/src/environment/local/earth_albedo.hpp b/src/environment/local/earth_albedo.hpp index e07ad7b46..8fbd6521b 100644 --- a/src/environment/local/earth_albedo.hpp +++ b/src/environment/local/earth_albedo.hpp @@ -10,11 +10,13 @@ #include "environment/local/local_celestial_information.hpp" #include "solar_radiation_pressure_environment.hpp" +namespace s2e::environment { + /** * @class EarthAlbedo * @brief Class to calculate Solar Radiation Pressure */ -class EarthAlbedo : public ILoggable { +class EarthAlbedo : public logger::ILoggable { public: /** * @fn EarthAlbedo @@ -74,15 +76,15 @@ class EarthAlbedo : public ILoggable { LocalCelestialInformation* local_celestial_information_; //!< Local celestial information SolarRadiationPressureEnvironment* srp_environment_; //!< Solar radiation pressure environment - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; @@ -102,4 +104,6 @@ class EarthAlbedo : public ILoggable { EarthAlbedo InitEarthAlbedo(std::string initialize_file_path, LocalCelestialInformation* local_celestial_information, SolarRadiationPressureEnvironment* srp_environment); +} // namespace s2e::environment + #endif // S2E_ENVIRONMENT_LOCAL_EARTH_ALBEDO_HPP_ diff --git a/src/environment/local/geomagnetic_field.cpp b/src/environment/local/geomagnetic_field.cpp index d167ae9ea..8fff876a9 100644 --- a/src/environment/local/geomagnetic_field.cpp +++ b/src/environment/local/geomagnetic_field.cpp @@ -11,6 +11,8 @@ #include "math_physics/randomization/random_walk.hpp" #include "setting_file_reader/initialize_file_access.hpp" +namespace s2e::environment { + GeomagneticField::GeomagneticField(const std::string igrf_file_name, const double random_walk_srandard_deviation_nT, const double random_walk_limit_nT, const double white_noise_standard_deviation_nT) : magnetic_field_i_nT_(0.0), @@ -42,9 +44,9 @@ void GeomagneticField::CalcMagneticField(const double decimal_year, const double void GeomagneticField::AddNoise(double* magnetic_field_array_i_nT) { static math::Vector<3> standard_deviation(random_walk_standard_deviation_nT_); static math::Vector<3> limit(random_walk_limit_nT_); - static RandomWalk<3> random_walk(0.1, standard_deviation, limit); + static randomization::RandomWalk<3> random_walk(0.1, standard_deviation, limit); - static randomization::NormalRand white_noise(0.0, white_noise_standard_deviation_nT_, global_randomization.MakeSeed()); + static randomization::NormalRand white_noise(0.0, white_noise_standard_deviation_nT_, randomization::global_randomization.MakeSeed()); for (int i = 0; i < 3; ++i) { magnetic_field_array_i_nT[i] += random_walk[i] + white_noise; @@ -55,8 +57,8 @@ void GeomagneticField::AddNoise(double* magnetic_field_array_i_nT) { std::string GeomagneticField::GetLogHeader() const { std::string str_tmp = ""; - str_tmp += WriteVector("geomagnetic_field_at_spacecraft_position", "i", "nT", 3); - str_tmp += WriteVector("geomagnetic_field_at_spacecraft_position", "b", "nT", 3); + str_tmp += logger::WriteVector("geomagnetic_field_at_spacecraft_position", "i", "nT", 3); + str_tmp += logger::WriteVector("geomagnetic_field_at_spacecraft_position", "b", "nT", 3); return str_tmp; } @@ -64,14 +66,14 @@ std::string GeomagneticField::GetLogHeader() const { std::string GeomagneticField::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteVector(magnetic_field_i_nT_); - str_tmp += WriteVector(magnetic_field_b_nT_); + str_tmp += logger::WriteVector(magnetic_field_i_nT_); + str_tmp += logger::WriteVector(magnetic_field_b_nT_); return str_tmp; } GeomagneticField InitGeomagneticField(std::string initialize_file_path) { - auto conf = IniAccess(initialize_file_path); + auto conf = setting_file_reader::IniAccess(initialize_file_path); const char* section = "MAGNETIC_FIELD_ENVIRONMENT"; std::string fname = conf.ReadString(section, "coefficient_file"); @@ -85,3 +87,5 @@ GeomagneticField InitGeomagneticField(std::string initialize_file_path) { return geomagnetic_field; } + +} // namespace s2e::environment diff --git a/src/environment/local/geomagnetic_field.hpp b/src/environment/local/geomagnetic_field.hpp index f8c38b997..1f38c03c6 100644 --- a/src/environment/local/geomagnetic_field.hpp +++ b/src/environment/local/geomagnetic_field.hpp @@ -11,11 +11,13 @@ #include "math_physics/math/quaternion.hpp" #include "math_physics/math/vector.hpp" +namespace s2e::environment { + /** * @class GeomagneticField * @brief Class to calculate magnetic field of the earth */ -class GeomagneticField : public ILoggable { +class GeomagneticField : public logger::ILoggable { public: bool IsCalcEnabled = true; //!< Calculation flag @@ -57,15 +59,15 @@ class GeomagneticField : public ILoggable { */ inline math::Vector<3> GetGeomagneticField_b_nT() const { return magnetic_field_b_nT_; } - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; @@ -92,4 +94,6 @@ class GeomagneticField : public ILoggable { */ GeomagneticField InitGeomagneticField(std::string initialize_file_path); +} // namespace s2e::environment + #endif // S2E_ENVIRONMENT_LOCAL_GEOMAGNETIC_FIELD_HPP_ diff --git a/src/environment/local/local_celestial_information.cpp b/src/environment/local/local_celestial_information.cpp index e73d23132..dab63eec9 100644 --- a/src/environment/local/local_celestial_information.cpp +++ b/src/environment/local/local_celestial_information.cpp @@ -14,6 +14,8 @@ #include "logger/log_utility.hpp" +namespace s2e::environment { + LocalCelestialInformation::LocalCelestialInformation(const CelestialInformation* global_celestial_information) : global_celestial_information_(global_celestial_information) { int num_of_state = global_celestial_information_->GetNumberOfSelectedBodies() * 3; @@ -179,8 +181,8 @@ std::string LocalCelestialInformation::GetLogHeader() const { std::string body_pos = name + "_position_from_spacecraft"; std::string body_vel = name + "_velocity_from_spacecraft"; - str_tmp += WriteVector(body_pos, "b", "m", 3); - str_tmp += WriteVector(body_vel, "b", "m/s", 3); + str_tmp += logger::WriteVector(body_pos, "b", "m", 3); + str_tmp += logger::WriteVector(body_vel, "b", "m/s", 3); } return str_tmp; } @@ -189,11 +191,13 @@ std::string LocalCelestialInformation::GetLogValue() const { std::string str_tmp = ""; for (int i = 0; i < global_celestial_information_->GetNumberOfSelectedBodies(); i++) { for (int j = 0; j < 3; j++) { - str_tmp += WriteScalar(celestial_body_position_from_spacecraft_b_m_[i * 3 + j]); + str_tmp += logger::WriteScalar(celestial_body_position_from_spacecraft_b_m_[i * 3 + j]); } for (int j = 0; j < 3; j++) { - str_tmp += WriteScalar(celestial_body_velocity_from_spacecraft_b_m_s_[i * 3 + j]); + str_tmp += logger::WriteScalar(celestial_body_velocity_from_spacecraft_b_m_s_[i * 3 + j]); } } return str_tmp; } + +} // namespace s2e::environment diff --git a/src/environment/local/local_celestial_information.hpp b/src/environment/local/local_celestial_information.hpp index dc10ab302..1d15a2ca6 100644 --- a/src/environment/local/local_celestial_information.hpp +++ b/src/environment/local/local_celestial_information.hpp @@ -8,11 +8,13 @@ #include "../global/celestial_information.hpp" +namespace s2e::environment { + /** * @class LocalCelestialInformation * @brief Class to manage celestial body information in the spacecraft body frame */ -class LocalCelestialInformation : public ILoggable { +class LocalCelestialInformation : public logger::ILoggable { public: /** * @fn LocalCelestialInformation @@ -68,15 +70,15 @@ class LocalCelestialInformation : public ILoggable { */ inline const CelestialInformation& GetGlobalInformation() const { return *global_celestial_information_; } - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; @@ -120,4 +122,6 @@ class LocalCelestialInformation : public ILoggable { const math::Vector<3> angular_velocity_b); }; +} // namespace s2e::environment + #endif // S2E_ENVIRONMENT_LOCAL_LOCAL_CELESTIAL_INFORMATION_HPP_ diff --git a/src/environment/local/local_environment.cpp b/src/environment/local/local_environment.cpp index 7cd898db9..7be568bce 100644 --- a/src/environment/local/local_environment.cpp +++ b/src/environment/local/local_environment.cpp @@ -8,8 +8,10 @@ #include "dynamics/orbit/orbit.hpp" #include "setting_file_reader/initialize_file_access.hpp" -LocalEnvironment::LocalEnvironment(const SimulationConfiguration* simulation_configuration, const GlobalEnvironment* global_environment, - const int spacecraft_id) { +namespace s2e::environment { + +LocalEnvironment::LocalEnvironment(const simulation::SimulationConfiguration* simulation_configuration, + const environment::GlobalEnvironment* global_environment, const int spacecraft_id) { Initialize(simulation_configuration, global_environment, spacecraft_id); } @@ -21,10 +23,10 @@ LocalEnvironment::~LocalEnvironment() { delete celestial_information_; } -void LocalEnvironment::Initialize(const SimulationConfiguration* simulation_configuration, const GlobalEnvironment* global_environment, - const int spacecraft_id) { +void LocalEnvironment::Initialize(const simulation::SimulationConfiguration* simulation_configuration, + const environment::GlobalEnvironment* global_environment, const int spacecraft_id) { // Read file name - IniAccess iniAccess = IniAccess(simulation_configuration->spacecraft_file_list_[spacecraft_id]); + setting_file_reader::IniAccess iniAccess = setting_file_reader::IniAccess(simulation_configuration->spacecraft_file_list_[spacecraft_id]); std::string ini_fname = iniAccess.ReadString("SETTING_FILES", "local_environment_file"); // Save ini file @@ -45,11 +47,11 @@ void LocalEnvironment::Initialize(const SimulationConfiguration* simulation_conf } // Log setting for Local celestial information - IniAccess conf = IniAccess(ini_fname); + setting_file_reader::IniAccess conf = setting_file_reader::IniAccess(ini_fname); celestial_information_->is_log_enabled_ = conf.ReadEnable("LOCAL_CELESTIAL_INFORMATION", "logging"); } -void LocalEnvironment::Update(const Dynamics* dynamics, const SimulationTime* simulation_time) { +void LocalEnvironment::Update(const dynamics::Dynamics* dynamics, const SimulationTime* simulation_time) { auto& orbit = dynamics->GetOrbit(); auto& attitude = dynamics->GetAttitude(); @@ -69,10 +71,12 @@ void LocalEnvironment::Update(const Dynamics* dynamics, const SimulationTime* si } } -void LocalEnvironment::LogSetup(Logger& logger) { +void LocalEnvironment::LogSetup(logger::Logger& logger) { logger.AddLogList(geomagnetic_field_); logger.AddLogList(solar_radiation_pressure_environment_); logger.AddLogList(earth_albedo_); logger.AddLogList(atmosphere_); logger.AddLogList(celestial_information_); } + +} // namespace s2e::environment diff --git a/src/environment/local/local_environment.hpp b/src/environment/local/local_environment.hpp index a7d0b7cac..e35b4973d 100644 --- a/src/environment/local/local_environment.hpp +++ b/src/environment/local/local_environment.hpp @@ -15,7 +15,11 @@ #include "simulation/simulation_configuration.hpp" #include "solar_radiation_pressure_environment.hpp" +namespace s2e::dynamics { class Dynamics; +} + +namespace s2e::environment { /** * @class LocalEnvironment @@ -30,7 +34,8 @@ class LocalEnvironment { * @param [in] global_environment: Global environment * @param [in] spacecraft_id: Satellite ID */ - LocalEnvironment(const SimulationConfiguration* simulation_configuration, const GlobalEnvironment* global_environment, const int spacecraft_id); + LocalEnvironment(const simulation::SimulationConfiguration* simulation_configuration, const environment::GlobalEnvironment* global_environment, + const int spacecraft_id); /** * @fn ~LocalEnvironment * @brief Destructor @@ -43,13 +48,13 @@ class LocalEnvironment { * @param [in] dynamics: Dynamics information of the satellite * @param [in] simulation_time: Simulation time */ - void Update(const Dynamics* dynamics, const SimulationTime* simulation_time); + void Update(const dynamics::Dynamics* dynamics, const SimulationTime* simulation_time); /** * @fn LogSetup * @brief Log setup for local environments */ - void LogSetup(Logger& logger); + void LogSetup(logger::Logger& logger); /** * @fn GetAtmosphere @@ -91,7 +96,10 @@ class LocalEnvironment { * @param [in] global_environment: Global environment * @param [in] spacecraft_id: Satellite ID */ - void Initialize(const SimulationConfiguration* simulation_configuration, const GlobalEnvironment* global_environment, const int spacecraft_id); + void Initialize(const simulation::SimulationConfiguration* simulation_configuration, const environment::GlobalEnvironment* global_environment, + const int spacecraft_id); }; +} // namespace s2e::environment + #endif // S2E_ENVIRONMENT_LOCAL_LOCAL_ENVIRONMENT_HPP_ diff --git a/src/environment/local/solar_radiation_pressure_environment.cpp b/src/environment/local/solar_radiation_pressure_environment.cpp index 181e1ea7a..c571f309f 100644 --- a/src/environment/local/solar_radiation_pressure_environment.cpp +++ b/src/environment/local/solar_radiation_pressure_environment.cpp @@ -13,6 +13,8 @@ #include "math_physics/math/vector.hpp" #include "setting_file_reader/initialize_file_access.hpp" +namespace s2e::environment { + SolarRadiationPressureEnvironment::SolarRadiationPressureEnvironment(LocalCelestialInformation* local_celestial_information) : local_celestial_information_(local_celestial_information) { solar_radiation_pressure_N_m2_ = solar_constant_W_m2_ / environment::speed_of_light_m_s; @@ -40,8 +42,8 @@ void SolarRadiationPressureEnvironment::UpdatePressure() { std::string SolarRadiationPressureEnvironment::GetLogHeader() const { std::string str_tmp = ""; - str_tmp += WriteScalar("solar_radiation_pressure_at_spacecraft_position", "N/m2"); - str_tmp += WriteScalar("shadow_coefficient_at_spacecraft_position"); + str_tmp += logger::WriteScalar("solar_radiation_pressure_at_spacecraft_position", "N/m2"); + str_tmp += logger::WriteScalar("shadow_coefficient_at_spacecraft_position"); return str_tmp; } @@ -49,8 +51,8 @@ std::string SolarRadiationPressureEnvironment::GetLogHeader() const { std::string SolarRadiationPressureEnvironment::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteScalar(solar_radiation_pressure_N_m2_ * shadow_coefficient_); - str_tmp += WriteScalar(shadow_coefficient_); + str_tmp += logger::WriteScalar(solar_radiation_pressure_N_m2_ * shadow_coefficient_); + str_tmp += logger::WriteScalar(shadow_coefficient_); return str_tmp; } @@ -104,7 +106,7 @@ void SolarRadiationPressureEnvironment::CalcShadowCoefficient(std::string shadow SolarRadiationPressureEnvironment InitSolarRadiationPressureEnvironment(std::string initialize_file_path, LocalCelestialInformation* local_celestial_information) { - auto conf = IniAccess(initialize_file_path); + auto conf = setting_file_reader::IniAccess(initialize_file_path); const char* section = "SOLAR_RADIATION_PRESSURE_ENVIRONMENT"; SolarRadiationPressureEnvironment srp_env(local_celestial_information); @@ -119,3 +121,5 @@ SolarRadiationPressureEnvironment InitSolarRadiationPressureEnvironment(std::str return srp_env; } + +} // namespace s2e::environment diff --git a/src/environment/local/solar_radiation_pressure_environment.hpp b/src/environment/local/solar_radiation_pressure_environment.hpp index 8fbc73250..98f833b6c 100644 --- a/src/environment/local/solar_radiation_pressure_environment.hpp +++ b/src/environment/local/solar_radiation_pressure_environment.hpp @@ -9,11 +9,13 @@ #include "environment/global/physical_constants.hpp" #include "environment/local/local_celestial_information.hpp" +namespace s2e::environment { + /** * @class SolarRadiationPressureEnvironment * @brief Class to calculate Solar Radiation Pressure */ -class SolarRadiationPressureEnvironment : public ILoggable { +class SolarRadiationPressureEnvironment : public logger::ILoggable { public: bool IsCalcEnabled = true; //!< Calculation flag @@ -78,15 +80,15 @@ class SolarRadiationPressureEnvironment : public ILoggable { */ inline bool GetIsEclipsed() const { return (shadow_coefficient_ >= 1.0 ? false : true); } - // Override ILoggable + // Override logger::ILoggable /** * @fn GetLogHeader - * @brief Override GetLogHeader function of ILoggable + * @brief Override GetLogHeader function of logger::ILoggable */ virtual std::string GetLogHeader() const; /** * @fn GetLogValue - * @brief Override GetLogValue function of ILoggable + * @brief Override GetLogValue function of logger::ILoggable */ virtual std::string GetLogValue() const; @@ -122,4 +124,6 @@ class SolarRadiationPressureEnvironment : public ILoggable { SolarRadiationPressureEnvironment InitSolarRadiationPressureEnvironment(std::string initialize_file_path, LocalCelestialInformation* local_celestial_information); +} // namespace s2e::environment + #endif // S2E_ENVIRONMENT_LOCAL_SOLAR_RADIATION_PRESSURE_ENVIRONMENT_HPP_ diff --git a/src/logger/initialize_log.cpp b/src/logger/initialize_log.cpp index 239cfe3d4..84098e57b 100644 --- a/src/logger/initialize_log.cpp +++ b/src/logger/initialize_log.cpp @@ -7,8 +7,10 @@ #include "../setting_file_reader/initialize_file_access.hpp" +namespace s2e::logger { + Logger* InitLog(std::string file_name) { - IniAccess ini_file(file_name); + setting_file_reader::IniAccess ini_file(file_name); std::string log_file_path = ini_file.ReadString("SIMULATION_SETTINGS", "log_file_save_directory"); bool log_ini = ini_file.ReadEnable("SIMULATION_SETTINGS", "save_initialize_files"); @@ -19,7 +21,7 @@ Logger* InitLog(std::string file_name) { } Logger* InitMonteCarloLog(std::string file_name, bool enable) { - IniAccess ini_file(file_name); + setting_file_reader::IniAccess ini_file(file_name); std::string log_file_path = ini_file.ReadString("SIMULATION_SETTINGS", "log_file_save_directory"); bool log_ini = ini_file.ReadEnable("SIMULATION_SETTINGS", "save_initialize_files"); @@ -28,3 +30,5 @@ Logger* InitMonteCarloLog(std::string file_name, bool enable) { return log; } + +} // namespace s2e::logger diff --git a/src/logger/initialize_log.hpp b/src/logger/initialize_log.hpp index 0d70fc1e8..9d7c7a45b 100644 --- a/src/logger/initialize_log.hpp +++ b/src/logger/initialize_log.hpp @@ -8,6 +8,8 @@ #include +namespace s2e::logger { + /** * @fn InitLog * @brief Initialize normal logger (default.csv) @@ -23,4 +25,6 @@ Logger* InitLog(std::string file_name); */ Logger* InitMonteCarloLog(std::string file_name, bool enable); +} // namespace s2e::logger + #endif // S2E_LIBRARY_LOGGER_INITIALIZE_LOG_HPP_ diff --git a/src/logger/log_utility.hpp b/src/logger/log_utility.hpp index 7eba4b767..3328d358e 100644 --- a/src/logger/log_utility.hpp +++ b/src/logger/log_utility.hpp @@ -12,6 +12,8 @@ #include #include +namespace s2e::logger { + /** * @fn WriteScalar * @brief Write scalar value @@ -156,4 +158,6 @@ std::string WriteQuaternion(const std::string name, const std::string frame) { return str_tmp.str(); } +} // namespace s2e::logger + #endif // S2E_LIBRARY_LOGGER_LOG_UTILITY_HPP_ diff --git a/src/logger/loggable.hpp b/src/logger/loggable.hpp index ab1b22a8b..b8616f1a7 100644 --- a/src/logger/loggable.hpp +++ b/src/logger/loggable.hpp @@ -10,6 +10,8 @@ #include "log_utility.hpp" // This is not necessary but include here for convenience +namespace s2e::logger { + /** * @class ILoggable * @brief Abstract class to manage logging @@ -34,4 +36,6 @@ class ILoggable { bool is_log_enabled_ = true; //!< Log enable flag }; +} // namespace s2e::logger + #endif // S2E_LIBRARY_LOGGER_LOGGABLE_HPP_ diff --git a/src/logger/logger.cpp b/src/logger/logger.cpp index f4795d537..3bc823cad 100644 --- a/src/logger/logger.cpp +++ b/src/logger/logger.cpp @@ -8,6 +8,8 @@ #include #include +namespace s2e::logger { + std::vector log_list_; bool Logger::is_directory_created_ = false; @@ -103,3 +105,5 @@ void Logger::CopyFileToLogDirectory(const fs::path &ini_file_name) { fs::copy_file(ini_file_name, to_file_name); return; } + +} // namespace s2e::logger diff --git a/src/logger/logger.hpp b/src/logger/logger.hpp index e9ac5b1f0..066c6814f 100644 --- a/src/logger/logger.hpp +++ b/src/logger/logger.hpp @@ -15,6 +15,8 @@ #include "loggable.hpp" +namespace s2e::logger { + /** * @class Logger * @brief Class to manage log output file @@ -121,4 +123,6 @@ class Logger { std::filesystem::path CreateDirectory(const std::filesystem::path &data_path, const std::string &time); }; +} // namespace s2e::logger + #endif // S2E_LIBRARY_LOGGER_LOGGER_HPP_ diff --git a/src/math_physics/atmosphere/harris_priester_coefficients.hpp b/src/math_physics/atmosphere/harris_priester_coefficients.hpp index 3c467501b..7fd6802b7 100644 --- a/src/math_physics/atmosphere/harris_priester_coefficients.hpp +++ b/src/math_physics/atmosphere/harris_priester_coefficients.hpp @@ -7,7 +7,7 @@ #include -namespace atmosphere { +namespace s2e::atmosphere { // Height [km], density [g/km3] // TODO: Add other solar activities value @@ -28,6 +28,6 @@ const std::map harris_priester_max_density_table = { {640, 0.4121}, {660, 0.3325}, {680, 0.2691}, {700, 0.2185}, {720, 0.1779}, {740, 0.1452}, {760, 0.1190}, {780, 0.09776}, {800, 0.08059}, {840, 0.05741}, {880, 0.04210}, {920, 0.03130}, {960, 0.02360}, {1000, 0.01810}}; -} // namespace atmosphere +} // namespace s2e::atmosphere #endif // S2E_LIBRARY_HARRIS_COEFFICIENTS_HPP_ diff --git a/src/math_physics/atmosphere/harris_priester_model.cpp b/src/math_physics/atmosphere/harris_priester_model.cpp index 3f2b022b3..6973caf98 100644 --- a/src/math_physics/atmosphere/harris_priester_model.cpp +++ b/src/math_physics/atmosphere/harris_priester_model.cpp @@ -10,7 +10,7 @@ #include "harris_priester_coefficients.hpp" -namespace atmosphere { +namespace s2e::atmosphere { /** * @fn CalcScaleHeight_km @@ -88,4 +88,4 @@ double CalcApexDensity_g_km3(const std::map::const_iterator dens return apex_density_g_km3; } -} // namespace atmosphere +} // namespace s2e::atmosphere diff --git a/src/math_physics/atmosphere/harris_priester_model.hpp b/src/math_physics/atmosphere/harris_priester_model.hpp index f9d8ffcc5..8b64550ad 100644 --- a/src/math_physics/atmosphere/harris_priester_model.hpp +++ b/src/math_physics/atmosphere/harris_priester_model.hpp @@ -9,7 +9,7 @@ #include #include -namespace atmosphere { +namespace s2e::atmosphere { /** * @fn CalcAirDensityWithHarrisPriester @@ -23,6 +23,6 @@ namespace atmosphere { double CalcAirDensityWithHarrisPriester_kg_m3(const geodesy::GeodeticPosition geodetic_position, const math::Vector<3> sun_direction_eci, const double f10_7 = 100.0, const double exponent_parameter = 4); -} // namespace atmosphere +} // namespace s2e::atmosphere #endif // S2E_LIBRARY_HARRIS_PRIESTER_HPP_ diff --git a/src/math_physics/atmosphere/simple_air_density_model.cpp b/src/math_physics/atmosphere/simple_air_density_model.cpp index 7e2b0a440..f616f674b 100644 --- a/src/math_physics/atmosphere/simple_air_density_model.cpp +++ b/src/math_physics/atmosphere/simple_air_density_model.cpp @@ -6,7 +6,7 @@ #include -namespace atmosphere { +namespace s2e::atmosphere { double CalcAirDensityWithSimpleModel(const double altitude_m) { double altitude_km = altitude_m / 1000.0; @@ -138,4 +138,4 @@ double CalcAirDensityWithSimpleModel(const double altitude_m) { return rho_kg_m3; } -} // namespace atmosphere +} // namespace s2e::atmosphere diff --git a/src/math_physics/atmosphere/simple_air_density_model.hpp b/src/math_physics/atmosphere/simple_air_density_model.hpp index b697a66e4..834807d96 100644 --- a/src/math_physics/atmosphere/simple_air_density_model.hpp +++ b/src/math_physics/atmosphere/simple_air_density_model.hpp @@ -5,7 +5,7 @@ #ifndef S2E_LIBRARY_ATMOSPHERE_SIMPLE_AIR_DENSITY_MODEL_HPP_ #define S2E_LIBRARY_ATMOSPHERE_SIMPLE_AIR_DENSITY_MODEL_HPP_ -namespace atmosphere { +namespace s2e::atmosphere { /** * @fn CalcAirDensityWithSimpleModel @@ -15,6 +15,6 @@ namespace atmosphere { */ double CalcAirDensityWithSimpleModel(const double altitude_m); -} // namespace atmosphere +} // namespace s2e::atmosphere #endif // S2E_LIBRARY_ATMOSPHERE_SIMPLE_AIR_DENSITY_MODEL_HPP_ diff --git a/src/math_physics/atmosphere/wrapper_nrlmsise00.cpp b/src/math_physics/atmosphere/wrapper_nrlmsise00.cpp index c000ca49e..c467efe37 100644 --- a/src/math_physics/atmosphere/wrapper_nrlmsise00.cpp +++ b/src/math_physics/atmosphere/wrapper_nrlmsise00.cpp @@ -23,6 +23,8 @@ extern "C" { using namespace std; +namespace s2e::atmosphere { + /* ------------------------------------------------------------------- */ /* ------------------------------ DEFINES ---------------------------- */ /* ------------------------------------------------------------------- */ @@ -305,3 +307,5 @@ size_t GetSpaceWeatherTable_(double decyear, double endsec, const string& filena return table.size(); } + +} // namespace s2e::atmosphere diff --git a/src/math_physics/atmosphere/wrapper_nrlmsise00.hpp b/src/math_physics/atmosphere/wrapper_nrlmsise00.hpp index 88bf51ee2..ea1e6e43f 100644 --- a/src/math_physics/atmosphere/wrapper_nrlmsise00.hpp +++ b/src/math_physics/atmosphere/wrapper_nrlmsise00.hpp @@ -12,6 +12,8 @@ #include #include +namespace s2e::atmosphere { + /** * @struct nrlmsise_table * @brief Parameters for NRLMSISE calculation @@ -74,4 +76,6 @@ size_t GetSpaceWeatherTable_(double decyear, double endsec, const std::string& f #define __inline_double double #endif +} // namespace s2e::atmosphere + #endif // S2E_LIBRARY_EXTERNAL_NRLMSISE00_WRAPPER_NRLMSISE00__HPP_ diff --git a/src/math_physics/control_utilities/first_order_lag.hpp b/src/math_physics/control_utilities/first_order_lag.hpp index 9a9d27ed3..3c61593be 100644 --- a/src/math_physics/control_utilities/first_order_lag.hpp +++ b/src/math_physics/control_utilities/first_order_lag.hpp @@ -6,7 +6,7 @@ #ifndef S2E_LIBRARY_CONTROL_UTILITIES_FIRST_ORDER_LAG_HPP_ #define S2E_LIBRARY_CONTROL_UTILITIES_FIRST_ORDER_LAG_HPP_ -namespace control_utilities { +namespace s2e::control_utilities { /** * @class FirstOderLag @@ -47,6 +47,6 @@ class FirstOrderLag { const double gain_; //!< Gain }; -} // namespace control_utilities +} // namespace s2e::control_utilities #endif // S2E_LIBRARY_CONTROL_UTILITIES_FIRST_ORDER_LAG_HPP_ diff --git a/src/math_physics/geodesy/geodetic_position.cpp b/src/math_physics/geodesy/geodetic_position.cpp index e7353b670..b72aa1804 100644 --- a/src/math_physics/geodesy/geodetic_position.cpp +++ b/src/math_physics/geodesy/geodetic_position.cpp @@ -10,7 +10,7 @@ #include #include -namespace geodesy { +namespace s2e::geodesy { GeodeticPosition::GeodeticPosition() { latitude_rad_ = 0.0; @@ -86,4 +86,4 @@ void GeodeticPosition::CalcQuaternionXcxfToLtc() { quaternion_xcxf_to_ltc_ = quaternion_xcxf_to_ltc_.ConvertFromDcm(dcm_xcxf_to_ltc); } -} // namespace geodesy +} // namespace s2e::geodesy diff --git a/src/math_physics/geodesy/geodetic_position.hpp b/src/math_physics/geodesy/geodetic_position.hpp index 556744f69..36cb4e839 100644 --- a/src/math_physics/geodesy/geodetic_position.hpp +++ b/src/math_physics/geodesy/geodetic_position.hpp @@ -9,7 +9,7 @@ #include #include -namespace geodesy { +namespace s2e::geodesy { /** * @class GeodeticPosition @@ -80,6 +80,6 @@ class GeodeticPosition { void CalcQuaternionXcxfToLtc(); }; -} // namespace geodesy +} // namespace s2e::geodesy #endif // S2E_LIBRARY_GEODESY_GEODETIC_POSITION_HPP_ \ No newline at end of file diff --git a/src/math_physics/gnss/antex_file_reader.cpp b/src/math_physics/gnss/antex_file_reader.cpp index c36cdacc4..4a3c74f23 100644 --- a/src/math_physics/gnss/antex_file_reader.cpp +++ b/src/math_physics/gnss/antex_file_reader.cpp @@ -10,7 +10,7 @@ #include #include -namespace gnss { +namespace s2e::gnss { #define ANTEX_LINE_TYPE_POSITION (60) @@ -199,4 +199,4 @@ time_system::DateTime AntexFileReader::ReadDateTime(std::string line) { return time_system::DateTime(year, month, day, hour, minute, second); } -} // namespace gnss +} // namespace s2e::gnss diff --git a/src/math_physics/gnss/antex_file_reader.hpp b/src/math_physics/gnss/antex_file_reader.hpp index 13e126c55..b463c5f4d 100644 --- a/src/math_physics/gnss/antex_file_reader.hpp +++ b/src/math_physics/gnss/antex_file_reader.hpp @@ -16,7 +16,7 @@ #include #include -namespace gnss { +namespace s2e::gnss { /** * @class AntexGridDefinition @@ -345,6 +345,6 @@ class AntexFileReader { time_system::DateTime ReadDateTime(std::string line); }; -} // namespace gnss +} // namespace s2e::gnss #endif // S2E_LIBRARY_ANTEX_FILE_READER_HPP_ diff --git a/src/math_physics/gnss/bias_sinex_file_reader.cpp b/src/math_physics/gnss/bias_sinex_file_reader.cpp index 252523ebf..b8a203c27 100644 --- a/src/math_physics/gnss/bias_sinex_file_reader.cpp +++ b/src/math_physics/gnss/bias_sinex_file_reader.cpp @@ -9,7 +9,7 @@ #include #include -namespace gnss { +namespace s2e::gnss { bool BiasSinexFileReader::ReadFile(const std::string file_name) { // File open @@ -245,4 +245,4 @@ void BiasSolutionData::SetTargetSignal(const std::string signal1, const std::str } } -} // namespace gnss +} // namespace s2e::gnss diff --git a/src/math_physics/gnss/bias_sinex_file_reader.hpp b/src/math_physics/gnss/bias_sinex_file_reader.hpp index 20e591d0c..694a9bcc5 100644 --- a/src/math_physics/gnss/bias_sinex_file_reader.hpp +++ b/src/math_physics/gnss/bias_sinex_file_reader.hpp @@ -10,7 +10,7 @@ #include #include -namespace gnss { +namespace s2e::gnss { /** * @enum BiasIdentifier @@ -186,6 +186,6 @@ class BiasSinexFileReader { void ReadBiasSolution(std::ifstream& bias_sinex_file); }; -} // namespace gnss +} // namespace s2e::gnss #endif // S2E_LIBRARY_BIAS_SINEX_FILE_READER_HPP_ \ No newline at end of file diff --git a/src/math_physics/gnss/gnss_satellite_number.cpp b/src/math_physics/gnss/gnss_satellite_number.cpp index 6eb8861a5..2241db843 100644 --- a/src/math_physics/gnss/gnss_satellite_number.cpp +++ b/src/math_physics/gnss/gnss_satellite_number.cpp @@ -5,7 +5,7 @@ #include "gnss_satellite_number.hpp" -namespace gnss { +namespace s2e::gnss { size_t ConvertGnssSatelliteNumberToIndex(const std::string satellite_number) { switch (satellite_number.front()) { @@ -61,4 +61,4 @@ std::string ConvertIndexToGnssSatelliteNumber(const size_t index) { return output; } -} // namespace gnss +} // namespace s2e::gnss diff --git a/src/math_physics/gnss/gnss_satellite_number.hpp b/src/math_physics/gnss/gnss_satellite_number.hpp index 35087c537..2b4e1f08b 100644 --- a/src/math_physics/gnss/gnss_satellite_number.hpp +++ b/src/math_physics/gnss/gnss_satellite_number.hpp @@ -10,7 +10,7 @@ #include -namespace gnss { +namespace s2e::gnss { // GNSS satellite number definition // TODO: Move to initialized file? @@ -46,6 +46,6 @@ size_t ConvertGnssSatelliteNumberToIndex(const std::string satellite_number); */ std::string ConvertIndexToGnssSatelliteNumber(const size_t index); -} // namespace gnss +} // namespace s2e::gnss #endif // S2E_LIBRARY_GNSS_GNSS_SATELLITE_NUMBER_HPP_ diff --git a/src/math_physics/gnss/igs_product_name_handling.hpp b/src/math_physics/gnss/igs_product_name_handling.hpp index e2352f76c..01c923fe7 100644 --- a/src/math_physics/gnss/igs_product_name_handling.hpp +++ b/src/math_physics/gnss/igs_product_name_handling.hpp @@ -10,7 +10,7 @@ #include -namespace gnss { +namespace s2e::gnss { /** * @fn GetOrbitClockFileName @@ -85,6 +85,6 @@ size_t IncrementYearDoy(const size_t year_doy) { return output; } -} // namespace gnss +} // namespace s2e::gnss #endif // S2E_LIBRARY_GNSS_IGS_PRODUCT_NAME_HANDLING_HPP_ diff --git a/src/math_physics/gnss/sp3_file_reader.cpp b/src/math_physics/gnss/sp3_file_reader.cpp index 7fbf0e831..2ae136626 100644 --- a/src/math_physics/gnss/sp3_file_reader.cpp +++ b/src/math_physics/gnss/sp3_file_reader.cpp @@ -11,7 +11,7 @@ #include #include -namespace gnss { +namespace s2e::gnss { Sp3FileReader::Sp3FileReader(const std::string file_name) { ReadFile(file_name); } @@ -422,4 +422,4 @@ Sp3VelocityClockRateCorrelation Sp3FileReader::DecodeVelocityClockRateCorrelatio return correlation; } -} // namespace gnss +} // namespace s2e::gnss diff --git a/src/math_physics/gnss/sp3_file_reader.hpp b/src/math_physics/gnss/sp3_file_reader.hpp index 15e4566dc..4e98933aa 100644 --- a/src/math_physics/gnss/sp3_file_reader.hpp +++ b/src/math_physics/gnss/sp3_file_reader.hpp @@ -17,7 +17,7 @@ #include #include -namespace gnss { +namespace s2e::gnss { #define SP3_BAD_CLOCK_VALUE (999999.999999) #define SP3_BAD_POSITION_VALUE (0.000000) @@ -236,6 +236,6 @@ class Sp3FileReader { Sp3VelocityClockRateCorrelation DecodeVelocityClockRateCorrelation(std::string line); }; -} // namespace gnss +} // namespace s2e::gnss #endif // S2E_LIBRARY_GNSS_SP3_FILE_READER_HPP_ diff --git a/src/math_physics/gnss/test_antex_file_reader.cpp b/src/math_physics/gnss/test_antex_file_reader.cpp index 320c598af..f64af1003 100644 --- a/src/math_physics/gnss/test_antex_file_reader.cpp +++ b/src/math_physics/gnss/test_antex_file_reader.cpp @@ -7,7 +7,7 @@ #include "antex_file_reader.hpp" -using namespace gnss; +using namespace s2e::gnss; /** * @brief Test Constructor diff --git a/src/math_physics/gnss/test_bias_sinex_file_reader.cpp b/src/math_physics/gnss/test_bias_sinex_file_reader.cpp index a681eedcc..c58f7ceae 100644 --- a/src/math_physics/gnss/test_bias_sinex_file_reader.cpp +++ b/src/math_physics/gnss/test_bias_sinex_file_reader.cpp @@ -2,7 +2,7 @@ #include "bias_sinex_file_reader.hpp" -using namespace gnss; +using namespace s2e::gnss; TEST(BiasSinex, Constructor) { // File read error check diff --git a/src/math_physics/gnss/test_gnss_satellite_number.cpp b/src/math_physics/gnss/test_gnss_satellite_number.cpp index 259920e29..0d4cae6f6 100644 --- a/src/math_physics/gnss/test_gnss_satellite_number.cpp +++ b/src/math_physics/gnss/test_gnss_satellite_number.cpp @@ -6,7 +6,7 @@ #include "gnss_satellite_number.hpp" -using namespace gnss; +using namespace s2e::gnss; /** * @brief Test satellite number to index diff --git a/src/math_physics/gnss/test_igs_product_name_handling.cpp b/src/math_physics/gnss/test_igs_product_name_handling.cpp index f1af19529..6b5d40270 100644 --- a/src/math_physics/gnss/test_igs_product_name_handling.cpp +++ b/src/math_physics/gnss/test_igs_product_name_handling.cpp @@ -7,7 +7,7 @@ #include "igs_product_name_handling.hpp" -using namespace gnss; +using namespace s2e::gnss; /** * @brief Test GetOrbitClockFinalFileName diff --git a/src/math_physics/gnss/test_sp3_file_reader.cpp b/src/math_physics/gnss/test_sp3_file_reader.cpp index 9ef514d41..2f9672ab0 100644 --- a/src/math_physics/gnss/test_sp3_file_reader.cpp +++ b/src/math_physics/gnss/test_sp3_file_reader.cpp @@ -6,7 +6,7 @@ #include "sp3_file_reader.hpp" -using namespace gnss; +using namespace s2e::gnss; /** * @brief Test Constructor diff --git a/src/math_physics/gravity/gravity_potential.cpp b/src/math_physics/gravity/gravity_potential.cpp index d6c2fda06..05f502fa5 100644 --- a/src/math_physics/gravity/gravity_potential.cpp +++ b/src/math_physics/gravity/gravity_potential.cpp @@ -10,7 +10,7 @@ #include #include -namespace gravity { +namespace s2e::gravity { GravityPotential::GravityPotential(const size_t degree, const std::vector> cosine_coefficients, const std::vector> sine_coefficients, const double gravity_constants_m3_s2, @@ -278,4 +278,4 @@ void GravityPotential::v_w_nm_update(double *v_nm, double *w_nm, const double v_ return; } -} // namespace gravity +} // namespace s2e::gravity diff --git a/src/math_physics/gravity/gravity_potential.hpp b/src/math_physics/gravity/gravity_potential.hpp index 94d0c8269..bf06ee4d2 100644 --- a/src/math_physics/gravity/gravity_potential.hpp +++ b/src/math_physics/gravity/gravity_potential.hpp @@ -12,7 +12,7 @@ #include "../math/matrix.hpp" #include "../math/vector.hpp" -namespace gravity { +namespace s2e::gravity { /** * @class GravityPotential @@ -85,6 +85,6 @@ class GravityPotential { void v_w_nm_update(double *v_nm, double *w_nm, const double v_prev, const double w_prev, const double v_prev2, const double w_prev2); }; -} // namespace gravity +} // namespace s2e::gravity #endif // S2E_LIBRARY_GRAVITY_GRAVITY_POTENTIAL_HPP_ diff --git a/src/math_physics/gravity/test_gravity_potential.cpp b/src/math_physics/gravity/test_gravity_potential.cpp index 22450d621..0dd54376e 100644 --- a/src/math_physics/gravity/test_gravity_potential.cpp +++ b/src/math_physics/gravity/test_gravity_potential.cpp @@ -6,8 +6,6 @@ #include "gravity_potential.hpp" -using namespace gravity; - /** * @brief Test for Acceleration calculation */ @@ -22,11 +20,11 @@ TEST(GravityPotential, Acceleration) { s_.assign(degree + 1, std::vector(degree + 1, 1.0)); // Initialize GravityPotential - GravityPotential gravity_potential_(degree, c_, s_, 1.0, 1.0); + s2e::gravity::GravityPotential gravity_potential_(degree, c_, s_, 1.0, 1.0); // Acceleration Calculation check - math::Vector<3> position_xcxf_m; - math::Vector<3> acceleration_xcxf_m_s2; + s2e::math::Vector<3> position_xcxf_m; + s2e::math::Vector<3> acceleration_xcxf_m_s2; const double accuracy = 1.0e-3; // Calc Acceleration @@ -64,11 +62,11 @@ TEST(GravityPotential, PartialDerivative1) { s_.assign(degree + 1, std::vector(degree + 1, 1.0)); // Initialize GravityPotential - GravityPotential gravity_potential_(degree, c_, s_, 1.0, 1.0); + s2e::gravity::GravityPotential gravity_potential_(degree, c_, s_, 1.0, 1.0); // Calculation check - math::Vector<3> position_xcxf_m; - math::Matrix<3, 3> partial_derivative_xcxf_s2; + s2e::math::Vector<3> position_xcxf_m; + s2e::math::Matrix<3, 3> partial_derivative_xcxf_s2; const double accuracy = 1.0e-3; // Calc Partial Derivative @@ -79,22 +77,22 @@ TEST(GravityPotential, PartialDerivative1) { // Calc Acceleration and numerical partial derivatives double d_r = 1e-9; - math::Matrix<3, 3> numerical_partial_derivative_xcxf_s2; + s2e::math::Matrix<3, 3> numerical_partial_derivative_xcxf_s2; for (size_t i = 0; i < 3; i++) { - math::Vector<3> position_1_xcxf_m = position_xcxf_m; - math::Vector<3> position_2_xcxf_m = position_xcxf_m; + s2e::math::Vector<3> position_1_xcxf_m = position_xcxf_m; + s2e::math::Vector<3> position_2_xcxf_m = position_xcxf_m; position_1_xcxf_m[i] = position_xcxf_m[i] - d_r / 2.0; position_2_xcxf_m[i] = position_xcxf_m[i] + d_r / 2.0; - math::Vector<3> acceleration_1_xcxf_m_s2 = gravity_potential_.CalcAcceleration_xcxf_m_s2(position_1_xcxf_m); - math::Vector<3> acceleration_2_xcxf_m_s2 = gravity_potential_.CalcAcceleration_xcxf_m_s2(position_2_xcxf_m); - math::Vector<3> diff_acceleration_xcxf_m_s2 = acceleration_2_xcxf_m_s2 - acceleration_1_xcxf_m_s2; + s2e::math::Vector<3> acceleration_1_xcxf_m_s2 = gravity_potential_.CalcAcceleration_xcxf_m_s2(position_1_xcxf_m); + s2e::math::Vector<3> acceleration_2_xcxf_m_s2 = gravity_potential_.CalcAcceleration_xcxf_m_s2(position_2_xcxf_m); + s2e::math::Vector<3> diff_acceleration_xcxf_m_s2 = acceleration_2_xcxf_m_s2 - acceleration_1_xcxf_m_s2; for (size_t j = 0; j < 3; j++) { numerical_partial_derivative_xcxf_s2[i][j] = diff_acceleration_xcxf_m_s2[j] / d_r; } } // Compare numerical and analytical calculation - math::Matrix<3, 3> diff; + s2e::math::Matrix<3, 3> diff; for (size_t i = 0; i < 3; i++) { for (size_t j = 0; j < 3; j++) { EXPECT_NEAR(numerical_partial_derivative_xcxf_s2[i][j], partial_derivative_xcxf_s2[i][j], accuracy); @@ -117,11 +115,11 @@ TEST(GravityPotential, PartialDerivative2) { s_.assign(degree + 1, std::vector(degree + 1, 1.0)); // Initialize GravityPotential - GravityPotential gravity_potential_(degree, c_, s_, 1.0, 1.0); + s2e::gravity::GravityPotential gravity_potential_(degree, c_, s_, 1.0, 1.0); // Calculation check - math::Vector<3> position_xcxf_m; - math::Matrix<3, 3> partial_derivative_xcxf_s2; + s2e::math::Vector<3> position_xcxf_m; + s2e::math::Matrix<3, 3> partial_derivative_xcxf_s2; const double accuracy = 1.0e-3; // Calc Partial Derivative @@ -132,22 +130,22 @@ TEST(GravityPotential, PartialDerivative2) { // Calc Acceleration and numerical partial derivatives double d_r = 1e-9; - math::Matrix<3, 3> numerical_partial_derivative_xcxf_s2; + s2e::math::Matrix<3, 3> numerical_partial_derivative_xcxf_s2; for (size_t i = 0; i < 3; i++) { - math::Vector<3> position_1_xcxf_m = position_xcxf_m; - math::Vector<3> position_2_xcxf_m = position_xcxf_m; + s2e::math::Vector<3> position_1_xcxf_m = position_xcxf_m; + s2e::math::Vector<3> position_2_xcxf_m = position_xcxf_m; position_1_xcxf_m[i] = position_xcxf_m[i] - d_r / 2.0; position_2_xcxf_m[i] = position_xcxf_m[i] + d_r / 2.0; - math::Vector<3> acceleration_1_xcxf_m_s2 = gravity_potential_.CalcAcceleration_xcxf_m_s2(position_1_xcxf_m); - math::Vector<3> acceleration_2_xcxf_m_s2 = gravity_potential_.CalcAcceleration_xcxf_m_s2(position_2_xcxf_m); - math::Vector<3> diff_acceleration_xcxf_m_s2 = acceleration_2_xcxf_m_s2 - acceleration_1_xcxf_m_s2; + s2e::math::Vector<3> acceleration_1_xcxf_m_s2 = gravity_potential_.CalcAcceleration_xcxf_m_s2(position_1_xcxf_m); + s2e::math::Vector<3> acceleration_2_xcxf_m_s2 = gravity_potential_.CalcAcceleration_xcxf_m_s2(position_2_xcxf_m); + s2e::math::Vector<3> diff_acceleration_xcxf_m_s2 = acceleration_2_xcxf_m_s2 - acceleration_1_xcxf_m_s2; for (size_t j = 0; j < 3; j++) { numerical_partial_derivative_xcxf_s2[i][j] = diff_acceleration_xcxf_m_s2[j] / d_r; } } // Compare numerical and analytical calculation - math::Matrix<3, 3> diff; + s2e::math::Matrix<3, 3> diff; for (size_t i = 0; i < 3; i++) { for (size_t j = 0; j < 3; j++) { EXPECT_NEAR(numerical_partial_derivative_xcxf_s2[i][j], partial_derivative_xcxf_s2[i][j], accuracy); diff --git a/src/math_physics/math/constants.hpp b/src/math_physics/math/constants.hpp index 9e6744015..7a6f0cf21 100644 --- a/src/math_physics/math/constants.hpp +++ b/src/math_physics/math/constants.hpp @@ -8,7 +8,7 @@ #include // std::is_floating_point_v -namespace math { +namespace s2e::math { // instead of C++20 std::numbers inline namespace numbers { @@ -47,6 +47,6 @@ DEFINE_MATH_CONSTANT(rad_s_to_rpm, 60.0L / tau) /* rad/s to rpm */ #undef DEFINE_MATH_CONSTANT } // namespace numbers -} // namespace math +} // namespace s2e::math #endif // S2E_LIBRARY_MATH_CONSTANTS_HPP_ diff --git a/src/math_physics/math/interpolation.cpp b/src/math_physics/math/interpolation.cpp index 4415c4dd5..2cab687a6 100644 --- a/src/math_physics/math/interpolation.cpp +++ b/src/math_physics/math/interpolation.cpp @@ -7,7 +7,7 @@ #include -namespace math { +namespace s2e::math { double Interpolation::CalcPolynomial(const double x) const { // Search nearest point @@ -94,4 +94,4 @@ size_t Interpolation::FindNearestPoint(const double x) const { return output; } -} // namespace math +} // namespace s2e::math diff --git a/src/math_physics/math/interpolation.hpp b/src/math_physics/math/interpolation.hpp index 7620ff338..f9815bc78 100644 --- a/src/math_physics/math/interpolation.hpp +++ b/src/math_physics/math/interpolation.hpp @@ -9,7 +9,7 @@ #include #include -namespace math { +namespace s2e::math { /** * @class Interpolation @@ -90,6 +90,6 @@ class Interpolation { size_t FindNearestPoint(const double x) const; }; -} // namespace math +} // namespace s2e::math #endif // S2E_LIBRARY_MATH_INTERPOLATION_HPP_ diff --git a/src/math_physics/math/matrix.hpp b/src/math_physics/math/matrix.hpp index 89429a8ca..a731e1d79 100644 --- a/src/math_physics/math/matrix.hpp +++ b/src/math_physics/math/matrix.hpp @@ -9,7 +9,7 @@ #include // for size_t #include // for ostream, cout -namespace math { +namespace s2e::math { /** * @class Matrix @@ -244,7 +244,7 @@ Matrix MakeRotationMatrixY(const double& theta_rad); template Matrix MakeRotationMatrixZ(const double& theta_rad); -} // namespace math +} // namespace s2e::math #include "matrix_template_functions.hpp" diff --git a/src/math_physics/math/matrix_template_functions.hpp b/src/math_physics/math/matrix_template_functions.hpp index dbfa9aa1b..56685a685 100644 --- a/src/math_physics/math/matrix_template_functions.hpp +++ b/src/math_physics/math/matrix_template_functions.hpp @@ -9,7 +9,7 @@ #include #include // for cout -namespace math { +namespace s2e::math { template Matrix::Matrix(const T& n) { @@ -186,6 +186,6 @@ Matrix MakeRotationMatrixZ(const double& theta_rad) { return m; } -} // namespace math +} // namespace s2e::math #endif // S2E_LIBRARY_MATH_MATRIX_TEMPLATE_FUNCTIONS_HPP_ diff --git a/src/math_physics/math/matrix_vector.hpp b/src/math_physics/math/matrix_vector.hpp index 7c76a07f5..1d4803ded 100644 --- a/src/math_physics/math/matrix_vector.hpp +++ b/src/math_physics/math/matrix_vector.hpp @@ -9,7 +9,7 @@ #include "matrix.hpp" #include "vector.hpp" -namespace math { +namespace s2e::math { /** * @fn operator* @@ -52,7 +52,7 @@ Matrix& LuDecomposition(Matrix& matrix, size_t index[]); template Vector& SolveLinearSystemWithLu(const Matrix& matrix, const size_t index[], Vector& vector); -} // namespace math +} // namespace s2e::math #include "matrix_vector_template_functions.hpp" diff --git a/src/math_physics/math/matrix_vector_template_functions.hpp b/src/math_physics/math/matrix_vector_template_functions.hpp index d16f08a2a..31289721b 100644 --- a/src/math_physics/math/matrix_vector_template_functions.hpp +++ b/src/math_physics/math/matrix_vector_template_functions.hpp @@ -8,7 +8,7 @@ #include // for invalid_argument. -namespace math { +namespace s2e::math { template Vector operator*(const Matrix& matrix, const Vector& vector) { @@ -139,6 +139,6 @@ Vector& SolveLinearSystemWithLu(const Matrix& a, const size_t index[], return b; } -} // namespace math +} // namespace s2e::math #endif // S2E_LIBRARY_MATH_MATRIX_VECTOR_TEMPLATE_FUNCTIONS_HPP_ diff --git a/src/math_physics/math/ordinary_differential_equation.hpp b/src/math_physics/math/ordinary_differential_equation.hpp index 36ff4ae86..1c861a391 100644 --- a/src/math_physics/math/ordinary_differential_equation.hpp +++ b/src/math_physics/math/ordinary_differential_equation.hpp @@ -8,7 +8,7 @@ #include "./vector.hpp" -namespace math { +namespace s2e::math { /** * @class OrdinaryDifferentialEquation @@ -111,7 +111,7 @@ class OrdinaryDifferentialEquation { double step_width_s_; //!< Step width }; -} // namespace math +} // namespace s2e::math #include "./ordinary_differential_equation_template_functions.hpp" diff --git a/src/math_physics/math/ordinary_differential_equation_template_functions.hpp b/src/math_physics/math/ordinary_differential_equation_template_functions.hpp index 7c5dc3071..334be563a 100644 --- a/src/math_physics/math/ordinary_differential_equation_template_functions.hpp +++ b/src/math_physics/math/ordinary_differential_equation_template_functions.hpp @@ -5,7 +5,7 @@ #ifndef S2E_LIBRARY_MATH_ORDINARY_DIFFERENTIA_EQUATION_TEMPLATE_FUNCTIONS_HPP_ #define S2E_LIBRARY_MATH_ORDINARY_DIFFERENTIA_EQUATION_TEMPLATE_FUNCTIONS_HPP_ -namespace math { +namespace s2e::math { template OrdinaryDifferentialEquation::OrdinaryDifferentialEquation(double step_width_s) @@ -44,6 +44,6 @@ void OrdinaryDifferentialEquation::Update() { independent_variable_ += step_width_s_; // Update independent variable } -} // namespace math +} // namespace s2e::math #endif // S2E_LIBRARY_MATH_ORDINARY_DIFFERENTIA_EQUATION_TEMPLATE_FUNCTIONS_HPP_ diff --git a/src/math_physics/math/quaternion.cpp b/src/math_physics/math/quaternion.cpp index 27dacc275..d2f28f085 100644 --- a/src/math_physics/math/quaternion.cpp +++ b/src/math_physics/math/quaternion.cpp @@ -9,7 +9,7 @@ #include #include -namespace math { +namespace s2e::math { Quaternion::Quaternion(const Vector<3>& rotation_axis, const double rotation_angle_rad) { double half_rotation_angle_rad = rotation_angle_rad * 0.5; @@ -236,4 +236,4 @@ Vector<3> Quaternion::InverseFrameConversion(const Vector<3>& vector) const { Vector<4> Quaternion::ConvertToVector() { return quaternion_; } -} // namespace math +} // namespace s2e::math diff --git a/src/math_physics/math/quaternion.hpp b/src/math_physics/math/quaternion.hpp index 76720f773..1980ec8c1 100644 --- a/src/math_physics/math/quaternion.hpp +++ b/src/math_physics/math/quaternion.hpp @@ -9,7 +9,7 @@ #include "matrix.hpp" #include "vector.hpp" -namespace math { +namespace s2e::math { /** * @class Quaternion @@ -203,6 +203,6 @@ Quaternion operator*(const Quaternion& lhs, const Vector<3>& rhs); * @return Quaternion */ Quaternion operator*(const double& lhs, const Quaternion& rhs); -} // namespace math +} // namespace s2e::math #endif // S2E_LIBRARY_MATH_QUATERNION_HPP_ diff --git a/src/math_physics/math/s2e_math.cpp b/src/math_physics/math/s2e_math.cpp index 943e6da91..fb4e53e1e 100644 --- a/src/math_physics/math/s2e_math.cpp +++ b/src/math_physics/math/s2e_math.cpp @@ -7,7 +7,7 @@ #include -namespace math { +namespace s2e::math { double WrapTo2Pi(const double angle_rad) { double angle_out = angle_rad; if (angle_out < 0.0) { @@ -23,4 +23,4 @@ double WrapTo2Pi(const double angle_rad) { } return angle_out; } -} // namespace math +} // namespace s2e::math diff --git a/src/math_physics/math/s2e_math.hpp b/src/math_physics/math/s2e_math.hpp index fb7bbccb6..8cafb64d4 100644 --- a/src/math_physics/math/s2e_math.hpp +++ b/src/math_physics/math/s2e_math.hpp @@ -8,7 +8,7 @@ #include -namespace math { +namespace s2e::math { /** * @fn WrapTo2Pi @@ -17,6 +17,6 @@ namespace math { */ double WrapTo2Pi(const double angle_rad); -} // namespace math +} // namespace s2e::math #endif // S2E_LIBRARY_MATH_S2E_MATH_HPP_ diff --git a/src/math_physics/math/test_interpolation.cpp b/src/math_physics/math/test_interpolation.cpp index 674b12419..a29f3b330 100644 --- a/src/math_physics/math/test_interpolation.cpp +++ b/src/math_physics/math/test_interpolation.cpp @@ -15,7 +15,7 @@ TEST(Interpolation, PolynomialLinearFunction) { std::vector x{0.0, 1.0, 2.0, 3.0, 4.0}; std::vector y{0.0, 2.0, 4.0, 6.0, 8.0}; - math::Interpolation interpolation(x, y); + s2e::math::Interpolation interpolation(x, y); double xx = 0.4; EXPECT_DOUBLE_EQ(2.0 * xx, interpolation.CalcPolynomial(xx)); @@ -31,7 +31,7 @@ TEST(Interpolation, PolynomialLinearFunction) { TEST(Interpolation, PolynomialQuadraticFunction) { std::vector x{0.0, 1.0, 2.0, 3.0, 4.0}; std::vector y{0.0, 1.0, 4.0, 9.0, 16.0}; - math::Interpolation interpolation(x, y); + s2e::math::Interpolation interpolation(x, y); double xx = 0.4; EXPECT_DOUBLE_EQ(pow(xx, 2.0), interpolation.CalcPolynomial(xx)); @@ -45,16 +45,16 @@ TEST(Interpolation, PolynomialQuadraticFunction) { * @brief Test for sin function with trigonometric interpolation */ TEST(Interpolation, TrigonometricSinFunction) { - std::vector x{0.0, math::pi_2, math::pi, math::pi * 3.0 / 2.0, math::tau}; + std::vector x{0.0, s2e::math::pi_2, s2e::math::pi, s2e::math::pi * 3.0 / 2.0, s2e::math::tau}; std::vector y; for (size_t i = 0; i < x.size(); i++) { y.push_back(sin(x[i])); } - math::Interpolation interpolation(x, y); + s2e::math::Interpolation interpolation(x, y); - double xx = 0.4 * math::pi; + double xx = 0.4 * s2e::math::pi; EXPECT_DOUBLE_EQ(sin(xx), interpolation.CalcTrigonometric(xx)); - xx = 1.4 * math::pi; + xx = 1.4 * s2e::math::pi; EXPECT_DOUBLE_EQ(sin(xx), interpolation.CalcTrigonometric(xx)); } @@ -62,16 +62,16 @@ TEST(Interpolation, TrigonometricSinFunction) { * @brief Test for cos function with trigonometric interpolation */ TEST(Interpolation, TrigonometricCosFunction) { - std::vector x{0.0, 0.3 * math::pi_2, 0.6 * math::pi_2, 0.9 * math::pi_2, 1.2 * math::pi_2}; + std::vector x{0.0, 0.3 * s2e::math::pi_2, 0.6 * s2e::math::pi_2, 0.9 * s2e::math::pi_2, 1.2 * s2e::math::pi_2}; std::vector y; for (size_t i = 0; i < x.size(); i++) { y.push_back(cos(x[i])); } - math::Interpolation interpolation(x, y); + s2e::math::Interpolation interpolation(x, y); - double xx = 0.1 * math::pi_2; + double xx = 0.1 * s2e::math::pi_2; EXPECT_NEAR(cos(xx), interpolation.CalcTrigonometric(xx), 1e-6); - xx = 0.8 * math::pi_2; + xx = 0.8 * s2e::math::pi_2; EXPECT_NEAR(cos(xx), interpolation.CalcTrigonometric(xx), 1e-6); } @@ -79,16 +79,16 @@ TEST(Interpolation, TrigonometricCosFunction) { * @brief Test for cos function with trigonometric interpolation */ TEST(Interpolation, TrigonometricCosSinFunctionOddDegree) { - std::vector x{0.0, 0.3 * math::pi_2, 0.6 * math::pi_2, 0.9 * math::pi_2, 1.2 * math::pi_2, 1.5 * math::pi_2}; + std::vector x{0.0, 0.3 * s2e::math::pi_2, 0.6 * s2e::math::pi_2, 0.9 * s2e::math::pi_2, 1.2 * s2e::math::pi_2, 1.5 * s2e::math::pi_2}; std::vector y; for (size_t i = 0; i < x.size(); i++) { y.push_back(cos(x[i]) + sin(x[i])); } - math::Interpolation interpolation(x, y); + s2e::math::Interpolation interpolation(x, y); - double xx = 0.1 * math::pi_2; + double xx = 0.1 * s2e::math::pi_2; EXPECT_NEAR(cos(xx) + sin(xx), interpolation.CalcTrigonometric(xx), 1e-6); - xx = 0.8 * math::pi_2; + xx = 0.8 * s2e::math::pi_2; EXPECT_NEAR(cos(xx) + sin(xx), interpolation.CalcTrigonometric(xx), 1e-6); } @@ -98,7 +98,7 @@ TEST(Interpolation, TrigonometricCosSinFunctionOddDegree) { TEST(Interpolation, PushAndPop) { std::vector x{0.0, 1.0, 2.0, 3.0, 4.0}; std::vector y{0.0, 2.0, 4.0, 6.0, 8.0}; - math::Interpolation interpolation(x, y); + s2e::math::Interpolation interpolation(x, y); EXPECT_EQ(x.size(), interpolation.GetDegree()); for (size_t i = 0; i < x.size(); i++) { diff --git a/src/math_physics/math/test_matrix.cpp b/src/math_physics/math/test_matrix.cpp index 53dee0b75..9b23c15d5 100644 --- a/src/math_physics/math/test_matrix.cpp +++ b/src/math_physics/math/test_matrix.cpp @@ -14,7 +14,7 @@ TEST(Matrix, ConstructorWithNumber) { const size_t R = 6; const size_t C = 3; double initialize_value = 2.0; - math::Matrix m(initialize_value); + s2e::math::Matrix m(initialize_value); for (size_t r = 0; r < R; r++) { for (size_t c = 0; c < C; c++) { @@ -30,7 +30,7 @@ TEST(Matrix, ConstructorWithNumber) { TEST(Matrix, GetLength) { const size_t R = 6; const size_t C = 3; - math::Matrix m; + s2e::math::Matrix m; EXPECT_EQ(R, m.GetRowLength()); EXPECT_EQ(C, m.GetColumnLength()); @@ -43,8 +43,8 @@ TEST(Matrix, OperatorPlusEqual) { const size_t R = 6; const size_t C = 3; double initialize_value = 2.0; - math::Matrix m(initialize_value); - math::Matrix adding; + s2e::math::Matrix m(initialize_value); + s2e::math::Matrix adding; for (size_t r = 0; r < R; r++) { for (size_t c = 0; c < C; c++) { @@ -71,8 +71,8 @@ TEST(Matrix, OperatorMinusEqual) { const size_t R = 6; const size_t C = 3; double initialize_value = 2.0; - math::Matrix m(initialize_value); - math::Matrix subtracting; + s2e::math::Matrix m(initialize_value); + s2e::math::Matrix subtracting; for (size_t r = 0; r < R; r++) { for (size_t c = 0; c < C; c++) { @@ -99,7 +99,7 @@ TEST(Matrix, OperatorMultiplyEqual) { const size_t R = 6; const size_t C = 3; - math::Matrix m; + s2e::math::Matrix m; double multiplying = 2.0; for (size_t r = 0; r < R; r++) { @@ -125,7 +125,7 @@ TEST(Matrix, OperatorDivideEqual) { const size_t R = 6; const size_t C = 3; - math::Matrix m; + s2e::math::Matrix m; double dividing = 2.0; for (size_t r = 0; r < R; r++) { @@ -152,7 +152,7 @@ TEST(Matrix, FillUp) { const size_t C = 3; double value = 3.0; - math::Matrix m; + s2e::math::Matrix m; m.FillUp(value); @@ -169,7 +169,7 @@ TEST(Matrix, FillUp) { */ TEST(Matrix, CalcTrace) { const size_t N = 6; - math::Matrix m; + s2e::math::Matrix m; for (size_t r = 0; r < N; r++) { for (size_t c = 0; c < N; c++) { @@ -201,8 +201,8 @@ TEST(Matrix, OperatorPlus) { const size_t R = 6; const size_t C = 3; double initialize_value = -2.0; - math::Matrix m(initialize_value); - math::Matrix adding; + s2e::math::Matrix m(initialize_value); + s2e::math::Matrix adding; for (size_t r = 0; r < R; r++) { for (size_t c = 0; c < C; c++) { @@ -210,7 +210,7 @@ TEST(Matrix, OperatorPlus) { } } - math::Matrix added = m + adding; + s2e::math::Matrix added = m + adding; for (size_t r = 0; r < R; r++) { for (size_t c = 0; c < C; c++) { @@ -230,8 +230,8 @@ TEST(Matrix, OperatorMinus) { const size_t R = 6; const size_t C = 3; double initialize_value = 0.6; - math::Matrix m(initialize_value); - math::Matrix subtracting; + s2e::math::Matrix m(initialize_value); + s2e::math::Matrix subtracting; for (size_t r = 0; r < R; r++) { for (size_t c = 0; c < C; c++) { @@ -239,7 +239,7 @@ TEST(Matrix, OperatorMinus) { } } - math::Matrix subtracted = m - subtracting; + s2e::math::Matrix subtracted = m - subtracting; for (size_t r = 0; r < R; r++) { for (size_t c = 0; c < C; c++) { @@ -259,7 +259,7 @@ TEST(Matrix, OperatorMultiplyScalar) { const size_t R = 6; const size_t C = 3; - math::Matrix m; + s2e::math::Matrix m; double multiplying = 0.3; for (size_t r = 0; r < R; r++) { @@ -268,7 +268,7 @@ TEST(Matrix, OperatorMultiplyScalar) { } } - math::Matrix subtracted = multiplying * m; + s2e::math::Matrix subtracted = multiplying * m; for (size_t r = 0; r < R; r++) { for (size_t c = 0; c < C; c++) { @@ -287,8 +287,8 @@ TEST(Matrix, OperatorMultiplyMatrix) { const size_t R = 2; const size_t C = 3; - math::Matrix a; - math::Matrix b; + s2e::math::Matrix a; + s2e::math::Matrix b; a[0][0] = 1.0; a[0][1] = 2.0; @@ -304,7 +304,7 @@ TEST(Matrix, OperatorMultiplyMatrix) { b[2][0] = 5.0; b[2][1] = 6.0; - math::Matrix result = a * b; + s2e::math::Matrix result = a * b; EXPECT_DOUBLE_EQ(22.0, result[0][0]); EXPECT_DOUBLE_EQ(28.0, result[0][1]); @@ -319,14 +319,14 @@ TEST(Matrix, Transpose) { const size_t R = 6; const size_t C = 3; - math::Matrix m; + s2e::math::Matrix m; for (size_t r = 0; r < R; r++) { for (size_t c = 0; c < C; c++) { m[r][c] = r * c; } } - math::Matrix transposed = m.Transpose(); + s2e::math::Matrix transposed = m.Transpose(); for (size_t r = 0; r < R; r++) { for (size_t c = 0; c < C; c++) { @@ -344,7 +344,7 @@ TEST(Matrix, Transpose) { TEST(Matrix, MakeIdentityMatrix) { const size_t N = 6; - math::Matrix m = math::MakeIdentityMatrix(); + s2e::math::Matrix m = s2e::math::MakeIdentityMatrix(); for (size_t r = 0; r < N; r++) { for (size_t c = 0; c < N; c++) { @@ -362,9 +362,9 @@ TEST(Matrix, MakeIdentityMatrix) { */ TEST(Matrix, MakeRotationMatrixX) { const size_t N = 3; - double theta_rad = -45.0 * math::deg_to_rad; + double theta_rad = -45.0 * s2e::math::deg_to_rad; - math::Matrix m = math::MakeRotationMatrixX(theta_rad); + s2e::math::Matrix m = s2e::math::MakeRotationMatrixX(theta_rad); EXPECT_DOUBLE_EQ(1.0, m[0][0]); EXPECT_DOUBLE_EQ(0.0, m[0][1]); @@ -382,9 +382,9 @@ TEST(Matrix, MakeRotationMatrixX) { */ TEST(Matrix, MakeRotationMatrixY) { const size_t N = 3; - double theta_rad = 120.0 * math::deg_to_rad; + double theta_rad = 120.0 * s2e::math::deg_to_rad; - math::Matrix m = math::MakeRotationMatrixY(theta_rad); + s2e::math::Matrix m = s2e::math::MakeRotationMatrixY(theta_rad); EXPECT_DOUBLE_EQ(cos(theta_rad), m[0][0]); EXPECT_DOUBLE_EQ(0.0, m[0][1]); @@ -402,9 +402,9 @@ TEST(Matrix, MakeRotationMatrixY) { */ TEST(Matrix, MakeRotationMatrixZ) { const size_t N = 3; - double theta_rad = 30.0 * math::deg_to_rad; + double theta_rad = 30.0 * s2e::math::deg_to_rad; - math::Matrix m = math::MakeRotationMatrixZ(theta_rad); + s2e::math::Matrix m = s2e::math::MakeRotationMatrixZ(theta_rad); EXPECT_DOUBLE_EQ(cos(theta_rad), m[0][0]); EXPECT_DOUBLE_EQ(sin(theta_rad), m[0][1]); diff --git a/src/math_physics/math/test_matrix_vector.cpp b/src/math_physics/math/test_matrix_vector.cpp index 78fc9babf..958a409b6 100644 --- a/src/math_physics/math/test_matrix_vector.cpp +++ b/src/math_physics/math/test_matrix_vector.cpp @@ -14,8 +14,8 @@ TEST(MatrixVector, MultiplyMatrixVector) { const size_t R = 3; const size_t C = 2; - math::Matrix m; - math::Vector v; + s2e::math::Matrix m; + s2e::math::Vector v; m[0][0] = 1.0; m[0][1] = 2.0; @@ -27,7 +27,7 @@ TEST(MatrixVector, MultiplyMatrixVector) { v[0] = 7.0; v[1] = 1.0; - math::Vector result = m * v; + s2e::math::Vector result = m * v; EXPECT_DOUBLE_EQ(9.0, result[0]); EXPECT_DOUBLE_EQ(-7.0, result[1]); @@ -40,7 +40,7 @@ TEST(MatrixVector, MultiplyMatrixVector) { TEST(MatrixVector, CalcInverseMatrix) { const size_t N = 3; - math::Matrix m; + s2e::math::Matrix m; m[0][0] = 1.0; m[0][1] = 1.0; @@ -52,7 +52,7 @@ TEST(MatrixVector, CalcInverseMatrix) { m[2][1] = -2.0; m[2][2] = 1.0; - math::Matrix inverse = math::CalcInverseMatrix(m); + s2e::math::Matrix inverse = s2e::math::CalcInverseMatrix(m); EXPECT_NEAR(-1.0, inverse[0][0], 1e-10); EXPECT_NEAR(-1.0, inverse[0][1], 1e-10); diff --git a/src/math_physics/math/test_quaternion.cpp b/src/math_physics/math/test_quaternion.cpp index 4995afccc..2821eccee 100644 --- a/src/math_physics/math/test_quaternion.cpp +++ b/src/math_physics/math/test_quaternion.cpp @@ -11,7 +11,7 @@ * @brief Test for constructor from four numbers */ TEST(Quaternion, ConstructorFourNumber) { - math::Quaternion q(0.5, 0.5, 0.5, 0.5); + s2e::math::Quaternion q(0.5, 0.5, 0.5, 0.5); EXPECT_DOUBLE_EQ(0.5, q[0]); EXPECT_DOUBLE_EQ(0.5, q[1]); @@ -23,8 +23,8 @@ TEST(Quaternion, ConstructorFourNumber) { * @brief Test for constructor from Vector */ TEST(Quaternion, ConstructorVector) { - math::Vector<4> v(0.5); - math::Quaternion q(v); + s2e::math::Vector<4> v(0.5); + s2e::math::Quaternion q(v); EXPECT_DOUBLE_EQ(0.5, q[0]); EXPECT_DOUBLE_EQ(0.5, q[1]); @@ -36,12 +36,12 @@ TEST(Quaternion, ConstructorVector) { * @brief Test for constructor from axis and rotation angle X rotation */ TEST(Quaternion, ConstructorAxisAndAngleX) { - math::Vector<3> axis; + s2e::math::Vector<3> axis; axis[0] = 1.0; axis[1] = 0.0; axis[2] = 0.0; - double theta_rad = 90 * math::deg_to_rad; - math::Quaternion q(axis, theta_rad); + double theta_rad = 90 * s2e::math::deg_to_rad; + s2e::math::Quaternion q(axis, theta_rad); EXPECT_NEAR(axis[0] * sin(theta_rad / 2.0), q[0], 1e-5); EXPECT_NEAR(axis[1] * sin(theta_rad / 2.0), q[1], 1e-5); @@ -53,12 +53,12 @@ TEST(Quaternion, ConstructorAxisAndAngleX) { * @brief Test for constructor from axis and rotation angle Y rotation */ TEST(Quaternion, ConstructorAxisAndAngleY) { - math::Vector<3> axis; + s2e::math::Vector<3> axis; axis[0] = 0.0; axis[1] = 1.0; axis[2] = 0.0; - double theta_rad = 45 * math::deg_to_rad; - math::Quaternion q(axis, theta_rad); + double theta_rad = 45 * s2e::math::deg_to_rad; + s2e::math::Quaternion q(axis, theta_rad); EXPECT_NEAR(axis[0] * sin(theta_rad / 2.0), q[0], 1e-5); EXPECT_NEAR(axis[1] * sin(theta_rad / 2.0), q[1], 1e-5); @@ -70,12 +70,12 @@ TEST(Quaternion, ConstructorAxisAndAngleY) { * @brief Test for constructor from axis and rotation angle Z rotation */ TEST(Quaternion, ConstructorAxisAndAngleZ) { - math::Vector<3> axis; + s2e::math::Vector<3> axis; axis[0] = 0.0; axis[1] = 0.0; axis[2] = 1.0; - double theta_rad = -60 * math::deg_to_rad; - math::Quaternion q(axis, theta_rad); + double theta_rad = -60 * s2e::math::deg_to_rad; + s2e::math::Quaternion q(axis, theta_rad); EXPECT_NEAR(axis[0] * sin(theta_rad / 2.0), q[0], 1e-5); EXPECT_NEAR(axis[1] * sin(theta_rad / 2.0), q[1], 1e-5); @@ -87,12 +87,12 @@ TEST(Quaternion, ConstructorAxisAndAngleZ) { * @brief Test for constructor from axis and rotation angle All axes rotation */ TEST(Quaternion, ConstructorAxisAndAngleAll) { - math::Vector<3> axis; + s2e::math::Vector<3> axis; axis[0] = 1.0; axis[1] = 1.0; axis[2] = 1.0; - double theta_rad = 180 * math::deg_to_rad; - math::Quaternion q(axis, theta_rad); + double theta_rad = 180 * s2e::math::deg_to_rad; + s2e::math::Quaternion q(axis, theta_rad); EXPECT_NEAR(axis[0] * sin(theta_rad / 2.0), q[0], 1e-5); EXPECT_NEAR(axis[1] * sin(theta_rad / 2.0), q[1], 1e-5); @@ -104,16 +104,16 @@ TEST(Quaternion, ConstructorAxisAndAngleAll) { * @brief Test for constructor from two vectors: No rotation */ TEST(Quaternion, ConstructorTwoVectorsNoRotation) { - math::Vector<3> before; + s2e::math::Vector<3> before; before[0] = 0.0; before[1] = 0.0; before[2] = 2.0; // To check normalization - math::Vector<3> after; + s2e::math::Vector<3> after; after[0] = 0.0; after[1] = 0.0; after[2] = 1.0; - math::Quaternion q(before, after); + s2e::math::Quaternion q(before, after); EXPECT_NEAR(0.0, q[0], 1e-5); EXPECT_NEAR(0.0, q[1], 1e-5); @@ -125,18 +125,18 @@ TEST(Quaternion, ConstructorTwoVectorsNoRotation) { * @brief Test for constructor from two vectors: X rotation */ TEST(Quaternion, ConstructorTwoVectorsX) { - math::Vector<3> before; + s2e::math::Vector<3> before; before[0] = 0.0; before[1] = 0.0; before[2] = 1.0; - math::Vector<3> after; + s2e::math::Vector<3> after; after[0] = 0.0; after[1] = 1.0; after[2] = 0.0; - math::Quaternion q(before, after); + s2e::math::Quaternion q(before, after); - double theta_rad = -90 * math::deg_to_rad; + double theta_rad = -90 * s2e::math::deg_to_rad; EXPECT_NEAR(sin(theta_rad / 2.0), q[0], 1e-5); EXPECT_NEAR(0.0, q[1], 1e-5); EXPECT_NEAR(0.0, q[2], 1e-5); @@ -147,18 +147,18 @@ TEST(Quaternion, ConstructorTwoVectorsX) { * @brief Test for constructor from two vectors: Y rotation */ TEST(Quaternion, ConstructorTwoVectorsY) { - math::Vector<3> before; + s2e::math::Vector<3> before; before[0] = 0.0; before[1] = 0.0; before[2] = 1.0; - math::Vector<3> after; + s2e::math::Vector<3> after; after[0] = 1.0; after[1] = 0.0; after[2] = 0.0; - math::Quaternion q(before, after); + s2e::math::Quaternion q(before, after); - double theta_rad = 90 * math::deg_to_rad; + double theta_rad = 90 * s2e::math::deg_to_rad; EXPECT_NEAR(0.0, q[0], 1e-5); EXPECT_NEAR(sin(theta_rad / 2.0), q[1], 1e-5); EXPECT_NEAR(0.0, q[2], 1e-5); @@ -169,18 +169,18 @@ TEST(Quaternion, ConstructorTwoVectorsY) { * @brief Test for constructor from two vectors: Z rotation */ TEST(Quaternion, ConstructorTwoVectorsZ) { - math::Vector<3> before; + s2e::math::Vector<3> before; before[0] = 1.0; before[1] = 0.0; before[2] = 0.0; - math::Vector<3> after; + s2e::math::Vector<3> after; after[0] = 0.0; after[1] = 1.0; after[2] = 0.0; - math::Quaternion q(before, after); + s2e::math::Quaternion q(before, after); - double theta_rad = 90 * math::deg_to_rad; + double theta_rad = 90 * s2e::math::deg_to_rad; EXPECT_NEAR(0.0, q[0], 1e-5); EXPECT_NEAR(0.0, q[1], 1e-5); EXPECT_NEAR(sin(theta_rad / 2.0), q[2], 1e-5); @@ -192,7 +192,7 @@ TEST(Quaternion, ConstructorTwoVectorsZ) { * @note TODO: Fix to nondestructive function */ TEST(Quaternion, Normalize) { - math::Quaternion q(1.0, 1.0, 1.0, 1.0); + s2e::math::Quaternion q(1.0, 1.0, 1.0, 1.0); EXPECT_DOUBLE_EQ(1.0, q[0]); EXPECT_DOUBLE_EQ(1.0, q[1]); EXPECT_DOUBLE_EQ(1.0, q[2]); @@ -209,9 +209,9 @@ TEST(Quaternion, Normalize) { * @brief Test for Conjugate */ TEST(Quaternion, Conjugate) { - math::Quaternion q(0.5, 0.5, 0.5, 0.5); + s2e::math::Quaternion q(0.5, 0.5, 0.5, 0.5); - math::Quaternion q_conjugate = q.Conjugate(); + s2e::math::Quaternion q_conjugate = q.Conjugate(); // Check nondestructive function EXPECT_DOUBLE_EQ(0.5, q[0]); @@ -229,10 +229,10 @@ TEST(Quaternion, Conjugate) { * @brief Test for ConvertToDcm Y rotation */ TEST(Quaternion, ConvertToDcmY) { - math::Quaternion q(0.0, 1.0, 0.0, 1.0); + s2e::math::Quaternion q(0.0, 1.0, 0.0, 1.0); q.Normalize(); - math::Matrix<3, 3> dcm = q.ConvertToDcm(); + s2e::math::Matrix<3, 3> dcm = q.ConvertToDcm(); // Check nondestructive function EXPECT_DOUBLE_EQ(0.0, q[0]); @@ -253,7 +253,7 @@ TEST(Quaternion, ConvertToDcmY) { EXPECT_NEAR(0.0, dcm[2][2], accuracy); // Inverse Conversion - math::Quaternion q_from_dcm = math::Quaternion::ConvertFromDcm(dcm); + s2e::math::Quaternion q_from_dcm = s2e::math::Quaternion::ConvertFromDcm(dcm); for (size_t i = 0; i < 4; i++) { EXPECT_NEAR(q[i], q_from_dcm[i], accuracy); } @@ -263,10 +263,10 @@ TEST(Quaternion, ConvertToDcmY) { * @brief Test for ConvertToDcm */ TEST(Quaternion, ConvertToDcm) { - math::Quaternion q(0.5, 0.3, 0.1, 1.0); + s2e::math::Quaternion q(0.5, 0.3, 0.1, 1.0); q.Normalize(); - math::Matrix<3, 3> dcm = q.ConvertToDcm(); + s2e::math::Matrix<3, 3> dcm = q.ConvertToDcm(); // Check nondestructive function const double accuracy = 1.0e-5; @@ -281,7 +281,7 @@ TEST(Quaternion, ConvertToDcm) { EXPECT_NEAR(0.4962963, dcm[2][2], accuracy); // Inverse Conversion - math::Quaternion q_from_dcm = math::Quaternion::ConvertFromDcm(dcm); + s2e::math::Quaternion q_from_dcm = s2e::math::Quaternion::ConvertFromDcm(dcm); for (size_t i = 0; i < 4; i++) { EXPECT_NEAR(q[i], q_from_dcm[i], accuracy); } @@ -291,10 +291,10 @@ TEST(Quaternion, ConvertToDcm) { * @brief Test for ConvertToEuler X rotation */ TEST(Quaternion, ConvertToEulerX) { - math::Quaternion q(1.0, 0.0, 0.0, 1.0); + s2e::math::Quaternion q(1.0, 0.0, 0.0, 1.0); q.Normalize(); - math::Vector<3> euler = q.ConvertToEuler(); + s2e::math::Vector<3> euler = q.ConvertToEuler(); // Check nondestructive function EXPECT_DOUBLE_EQ(1.0 / sqrt(2.0), q[0]); @@ -304,12 +304,12 @@ TEST(Quaternion, ConvertToEulerX) { // Check nondestructive function const double accuracy = 1.0e-7; - EXPECT_NEAR(90 * math::deg_to_rad, euler[0], accuracy); + EXPECT_NEAR(90 * s2e::math::deg_to_rad, euler[0], accuracy); EXPECT_NEAR(0.0, euler[1], accuracy); EXPECT_NEAR(0.0, euler[2], accuracy); // Inverse Conversion - math::Quaternion q_from_euler = math::Quaternion::ConvertFromEuler(euler); + s2e::math::Quaternion q_from_euler = s2e::math::Quaternion::ConvertFromEuler(euler); for (size_t i = 0; i < 4; i++) { EXPECT_NEAR(q[i], q_from_euler[i], accuracy); } @@ -319,10 +319,10 @@ TEST(Quaternion, ConvertToEulerX) { * @brief Test for ConvertToEuler */ TEST(Quaternion, ConvertToEuler) { - math::Quaternion q(0.5, 0.3, 0.1, 1.0); + s2e::math::Quaternion q(0.5, 0.3, 0.1, 1.0); q.Normalize(); - math::Vector<3> euler = q.ConvertToEuler(); + s2e::math::Vector<3> euler = q.ConvertToEuler(); // Check nondestructive function const double accuracy = 1.0e-7; @@ -331,7 +331,7 @@ TEST(Quaternion, ConvertToEuler) { EXPECT_NEAR(0.41012734, euler[2], accuracy); // Inverse Conversion - math::Quaternion q_from_euler = math::Quaternion::ConvertFromEuler(euler); + s2e::math::Quaternion q_from_euler = s2e::math::Quaternion::ConvertFromEuler(euler); for (size_t i = 0; i < 4; i++) { EXPECT_NEAR(q[i], q_from_euler[i], accuracy); } @@ -341,22 +341,22 @@ TEST(Quaternion, ConvertToEuler) { * @brief Test for FrameConversion Z rotation */ TEST(Quaternion, FrameConversionZ) { - math::Quaternion q(0.0, 0.0, 1.0, 1.0); + s2e::math::Quaternion q(0.0, 0.0, 1.0, 1.0); q.Normalize(); - math::Vector<3> v; + s2e::math::Vector<3> v; v[0] = 1.0; v[1] = 0.0; v[2] = 0.0; - math::Vector<3> v_frame_conv = q.FrameConversion(v); + s2e::math::Vector<3> v_frame_conv = q.FrameConversion(v); const double accuracy = 1.0e-7; EXPECT_NEAR(0.0, v_frame_conv[0], accuracy); EXPECT_NEAR(-1.0, v_frame_conv[1], accuracy); EXPECT_NEAR(0.0, v_frame_conv[2], accuracy); - math::Vector<3> v_frame_conv_inv = q.InverseFrameConversion(v_frame_conv); + s2e::math::Vector<3> v_frame_conv_inv = q.InverseFrameConversion(v_frame_conv); for (size_t i = 0; i < 3; i++) { EXPECT_NEAR(v[i], v_frame_conv_inv[i], accuracy); @@ -367,15 +367,15 @@ TEST(Quaternion, FrameConversionZ) { * @brief Test for FrameConversion */ TEST(Quaternion, FrameConversion) { - math::Quaternion q(0.5, 0.3, 0.1, 1.0); + s2e::math::Quaternion q(0.5, 0.3, 0.1, 1.0); q.Normalize(); - math::Vector<3> v; + s2e::math::Vector<3> v; v[0] = 1.0; v[1] = 0.0; v[2] = 0.0; - math::Vector<3> v_frame_conv = q.FrameConversion(v); - math::Vector<3> v_frame_conv_inv = q.InverseFrameConversion(v_frame_conv); + s2e::math::Vector<3> v_frame_conv = q.FrameConversion(v); + s2e::math::Vector<3> v_frame_conv_inv = q.InverseFrameConversion(v_frame_conv); const double accuracy = 1.0e-7; for (size_t i = 0; i < 3; i++) { @@ -387,9 +387,9 @@ TEST(Quaternion, FrameConversion) { * @brief Test for ConvertToVector */ TEST(Quaternion, ConvertToVector) { - math::Quaternion q(0.5, 0.3, 0.1, 1.0); + s2e::math::Quaternion q(0.5, 0.3, 0.1, 1.0); - math::Vector<4> v = q.ConvertToVector(); + s2e::math::Vector<4> v = q.ConvertToVector(); for (size_t i = 0; i < 4; i++) { EXPECT_DOUBLE_EQ(q[i], v[i]); @@ -400,10 +400,10 @@ TEST(Quaternion, ConvertToVector) { * @brief Test for operator+ */ TEST(Quaternion, OperatorPlus) { - math::Quaternion q1(0.5, 0.3, 0.1, 1.0); - math::Quaternion q2(-0.3, 0.1, -1.0, 0.4); + s2e::math::Quaternion q1(0.5, 0.3, 0.1, 1.0); + s2e::math::Quaternion q2(-0.3, 0.1, -1.0, 0.4); - math::Quaternion result = q1 + q2; + s2e::math::Quaternion result = q1 + q2; EXPECT_DOUBLE_EQ(0.2, result[0]); EXPECT_DOUBLE_EQ(0.4, result[1]); @@ -415,10 +415,10 @@ TEST(Quaternion, OperatorPlus) { * @brief Test for operator- */ TEST(Quaternion, OperatorMinus) { - math::Quaternion q1(0.5, 0.3, 0.1, 1.0); - math::Quaternion q2(-0.3, 0.1, -1.0, 0.4); + s2e::math::Quaternion q1(0.5, 0.3, 0.1, 1.0); + s2e::math::Quaternion q2(-0.3, 0.1, -1.0, 0.4); - math::Quaternion result = q1 - q2; + s2e::math::Quaternion result = q1 - q2; EXPECT_DOUBLE_EQ(0.8, result[0]); EXPECT_DOUBLE_EQ(0.2, result[1]); @@ -430,10 +430,10 @@ TEST(Quaternion, OperatorMinus) { * @brief Test for operator* quaternion */ TEST(Quaternion, OperatorQuaternionMultiply) { - math::Quaternion q1(0.289271, -0.576012, -0.420972, 0.638212); - math::Quaternion q2(-0.0821846, 0.501761, 0.721995, -0.469259); + s2e::math::Quaternion q1(0.289271, -0.576012, -0.420972, 0.638212); + s2e::math::Quaternion q2(-0.0821846, 0.501761, 0.721995, -0.469259); - math::Quaternion result = q1 * q2; + s2e::math::Quaternion result = q1 * q2; const double accuracy = 1.0e-7; EXPECT_NEAR(-0.3928446703722, result[0], accuracy); @@ -446,10 +446,10 @@ TEST(Quaternion, OperatorQuaternionMultiply) { * @brief Test for operator* scalar */ TEST(Quaternion, OperatorScalarMultiply) { - math::Quaternion q(0.289271, -0.576012, -0.420972, 0.638212); + s2e::math::Quaternion q(0.289271, -0.576012, -0.420972, 0.638212); double scalar = 2.3; - math::Quaternion result = scalar * q; + s2e::math::Quaternion result = scalar * q; const double accuracy = 1.0e-7; EXPECT_NEAR(q[0] * 2.3, result[0], accuracy); diff --git a/src/math_physics/math/test_s2e_math.cpp b/src/math_physics/math/test_s2e_math.cpp index 949751a3b..7a293b967 100644 --- a/src/math_physics/math/test_s2e_math.cpp +++ b/src/math_physics/math/test_s2e_math.cpp @@ -14,18 +14,18 @@ TEST(S2eMath, WrapTo2Pi) { const double accuracy = 1.0e-7; double input_angle_rad = 0.0; - double wrapped_angle_rad = math::WrapTo2Pi(input_angle_rad); + double wrapped_angle_rad = s2e::math::WrapTo2Pi(input_angle_rad); EXPECT_NEAR(0.0, wrapped_angle_rad, accuracy); input_angle_rad = -1.0e-5; - wrapped_angle_rad = math::WrapTo2Pi(input_angle_rad); - EXPECT_NEAR(math::tau + input_angle_rad, wrapped_angle_rad, accuracy); + wrapped_angle_rad = s2e::math::WrapTo2Pi(input_angle_rad); + EXPECT_NEAR(s2e::math::tau + input_angle_rad, wrapped_angle_rad, accuracy); - input_angle_rad = math::tau + 1.0e-5; - wrapped_angle_rad = math::WrapTo2Pi(input_angle_rad); + input_angle_rad = s2e::math::tau + 1.0e-5; + wrapped_angle_rad = s2e::math::WrapTo2Pi(input_angle_rad); EXPECT_NEAR(1.0e-5, wrapped_angle_rad, accuracy); - input_angle_rad = 10 * math::tau + 1.0e-5; - wrapped_angle_rad = math::WrapTo2Pi(input_angle_rad); + input_angle_rad = 10 * s2e::math::tau + 1.0e-5; + wrapped_angle_rad = s2e::math::WrapTo2Pi(input_angle_rad); EXPECT_NEAR(1.0e-5, wrapped_angle_rad, accuracy); } diff --git a/src/math_physics/math/test_vector.cpp b/src/math_physics/math/test_vector.cpp index 5f636960d..e920dc0b8 100644 --- a/src/math_physics/math/test_vector.cpp +++ b/src/math_physics/math/test_vector.cpp @@ -13,7 +13,7 @@ TEST(Vector, ConstructorWithNumber) { const size_t N = 6; double initialize_value = 2.0; - math::Vector v(initialize_value); + s2e::math::Vector v(initialize_value); for (size_t i = 0; i < N; i++) { EXPECT_DOUBLE_EQ(initialize_value, v[i]); @@ -26,7 +26,7 @@ TEST(Vector, ConstructorWithNumber) { */ TEST(Vector, GetLength) { const size_t N = 6; - math::Vector v; + s2e::math::Vector v; EXPECT_EQ(N, v.GetLength()); } @@ -37,8 +37,8 @@ TEST(Vector, GetLength) { TEST(Vector, OperatorPlusEqual) { const size_t N = 6; double initialize_value = 2.0; - math::Vector v(initialize_value); - math::Vector adding; + s2e::math::Vector v(initialize_value); + s2e::math::Vector adding; for (size_t i = 0; i < N; i++) { adding[i] = double(i); @@ -60,8 +60,8 @@ TEST(Vector, OperatorPlusEqual) { TEST(Vector, OperatorMinusEqual) { const size_t N = 6; double initialize_value = 2.0; - math::Vector v(initialize_value); - math::Vector subtracting; + s2e::math::Vector v(initialize_value); + s2e::math::Vector subtracting; for (size_t i = 0; i < N; i++) { subtracting[i] = double(i); @@ -82,7 +82,7 @@ TEST(Vector, OperatorMinusEqual) { */ TEST(Vector, OperatorMultiplyEqual) { const size_t N = 6; - math::Vector v; + s2e::math::Vector v; double multiplying = 2.0; for (size_t i = 0; i < N; i++) { @@ -104,7 +104,7 @@ TEST(Vector, OperatorMultiplyEqual) { */ TEST(Vector, OperatorDivideEqual) { const size_t N = 6; - math::Vector v; + s2e::math::Vector v; double dividing = 3.0; for (size_t i = 0; i < N; i++) { @@ -126,13 +126,13 @@ TEST(Vector, OperatorDivideEqual) { */ TEST(Vector, OperatorNegative) { const size_t N = 6; - math::Vector v; + s2e::math::Vector v; for (size_t i = 0; i < N; i++) { v[i] = double(i); } - math::Vector v_negative = -v; + s2e::math::Vector v_negative = -v; for (size_t i = 0; i < N; i++) { // Check nondestructive @@ -147,7 +147,7 @@ TEST(Vector, OperatorNegative) { */ TEST(Vector, FillUp) { const size_t N = 6; - math::Vector v; + s2e::math::Vector v; for (size_t i = 0; i < N; i++) { v[i] = double(i); @@ -171,14 +171,14 @@ TEST(Vector, FillUp) { TEST(Vector, OperatorPlus) { const size_t N = 6; double initialize_value = 2.0; - math::Vector v(initialize_value); - math::Vector adding; + s2e::math::Vector v(initialize_value); + s2e::math::Vector adding; for (size_t i = 0; i < N; i++) { adding[i] = double(i); } - math::Vector added = v + adding; + s2e::math::Vector added = v + adding; for (size_t i = 0; i < N; i++) { // Check nondestructive @@ -195,14 +195,14 @@ TEST(Vector, OperatorPlus) { TEST(Vector, OperatorMinus) { const size_t N = 6; double initialize_value = 2.0; - math::Vector v(initialize_value); - math::Vector subtracting; + s2e::math::Vector v(initialize_value); + s2e::math::Vector subtracting; for (size_t i = 0; i < N; i++) { subtracting[i] = double(i); } - math::Vector subtracted = v - subtracting; + s2e::math::Vector subtracted = v - subtracting; for (size_t i = 0; i < N; i++) { // Check nondestructive @@ -218,8 +218,8 @@ TEST(Vector, OperatorMinus) { */ TEST(Vector, InnerProduct) { const size_t N = 3; - math::Vector a; - math::Vector b; + s2e::math::Vector a; + s2e::math::Vector b; for (size_t i = 0; i < N; i++) { a[i] = double(i + 1); @@ -235,8 +235,8 @@ TEST(Vector, InnerProduct) { */ TEST(Vector, InnerProductZero) { const size_t N = 3; - math::Vector a; - math::Vector b; + s2e::math::Vector a; + s2e::math::Vector b; a[0] = 1.0; a[1] = 0.0; @@ -255,8 +255,8 @@ TEST(Vector, InnerProductZero) { */ TEST(Vector, OuterProductZero) { const size_t N = 3; - math::Vector a; - math::Vector b; + s2e::math::Vector a; + s2e::math::Vector b; a[0] = 1.0; a[1] = 0.0; @@ -266,7 +266,7 @@ TEST(Vector, OuterProductZero) { b[1] = 0.0; b[2] = 0.0; - math::Vector<3> result = OuterProduct(a, b); + s2e::math::Vector<3> result = OuterProduct(a, b); for (size_t i = 0; i < N; i++) { EXPECT_DOUBLE_EQ(0.0, result[i]); @@ -278,8 +278,8 @@ TEST(Vector, OuterProductZero) { */ TEST(Vector, OuterProductX) { const size_t N = 3; - math::Vector a; - math::Vector b; + s2e::math::Vector a; + s2e::math::Vector b; a[0] = 0.0; a[1] = 0.0; @@ -289,7 +289,7 @@ TEST(Vector, OuterProductX) { b[1] = 1.0; b[2] = 0.0; - math::Vector<3> result = OuterProduct(a, b); + s2e::math::Vector<3> result = OuterProduct(a, b); EXPECT_DOUBLE_EQ(-1.0, result[0]); EXPECT_DOUBLE_EQ(0.0, result[1]); @@ -301,8 +301,8 @@ TEST(Vector, OuterProductX) { */ TEST(Vector, OuterProductY) { const size_t N = 3; - math::Vector a; - math::Vector b; + s2e::math::Vector a; + s2e::math::Vector b; a[0] = 0.0; a[1] = 0.0; @@ -312,7 +312,7 @@ TEST(Vector, OuterProductY) { b[1] = 0.0; b[2] = 0.0; - math::Vector<3> result = OuterProduct(a, b); + s2e::math::Vector<3> result = OuterProduct(a, b); EXPECT_DOUBLE_EQ(0.0, result[0]); EXPECT_DOUBLE_EQ(1.0, result[1]); @@ -324,8 +324,8 @@ TEST(Vector, OuterProductY) { */ TEST(Vector, OuterProductZ) { const size_t N = 3; - math::Vector a; - math::Vector b; + s2e::math::Vector a; + s2e::math::Vector b; a[0] = 1.0; a[1] = 0.0; @@ -335,7 +335,7 @@ TEST(Vector, OuterProductZ) { b[1] = 1.0; b[2] = 0.0; - math::Vector<3> result = OuterProduct(a, b); + s2e::math::Vector<3> result = OuterProduct(a, b); EXPECT_DOUBLE_EQ(0.0, result[0]); EXPECT_DOUBLE_EQ(0.0, result[1]); @@ -347,7 +347,7 @@ TEST(Vector, OuterProductZ) { */ TEST(Vector, CalcNorm) { const size_t N = 10; - math::Vector v(1.0); + s2e::math::Vector v(1.0); double norm = v.CalcNorm(); @@ -364,9 +364,9 @@ TEST(Vector, CalcNorm) { */ TEST(Vector, Normalize) { const size_t N = 5; - math::Vector v(1.0); + s2e::math::Vector v(1.0); - math::Vector normalized = v.CalcNormalizedVector(); + s2e::math::Vector normalized = v.CalcNormalizedVector(); for (size_t i = 0; i < N; i++) { // Check nondestructive @@ -381,8 +381,8 @@ TEST(Vector, Normalize) { */ TEST(Vector, CalcAngleTwoVectors90deg) { const size_t N = 3; - math::Vector a; - math::Vector b; + s2e::math::Vector a; + s2e::math::Vector b; a[0] = 1.0; a[1] = 0.0; @@ -394,7 +394,7 @@ TEST(Vector, CalcAngleTwoVectors90deg) { double angle_rad = CalcAngleTwoVectors_rad(a, b); - EXPECT_DOUBLE_EQ(90.0 * math::deg_to_rad, angle_rad); + EXPECT_DOUBLE_EQ(90.0 * s2e::math::deg_to_rad, angle_rad); } /** @@ -402,7 +402,7 @@ TEST(Vector, CalcAngleTwoVectors90deg) { */ TEST(Vector, CalcAngleTwoVectors0deg) { const size_t N = 3; - math::Vector a; + s2e::math::Vector a; a[0] = 1.0; a[1] = 0.0; @@ -410,7 +410,7 @@ TEST(Vector, CalcAngleTwoVectors0deg) { double angle_rad = CalcAngleTwoVectors_rad(a, a); - EXPECT_DOUBLE_EQ(0.0 * math::deg_to_rad, angle_rad); + EXPECT_DOUBLE_EQ(0.0 * s2e::math::deg_to_rad, angle_rad); } /** @@ -418,8 +418,8 @@ TEST(Vector, CalcAngleTwoVectors0deg) { */ TEST(Vector, CalcAngleTwoVectors45deg) { const size_t N = 3; - math::Vector a; - math::Vector b; + s2e::math::Vector a; + s2e::math::Vector b; a[0] = 0.0; a[1] = 1.0; @@ -431,7 +431,7 @@ TEST(Vector, CalcAngleTwoVectors45deg) { double angle_rad = CalcAngleTwoVectors_rad(a, b); - EXPECT_DOUBLE_EQ(45.0 * math::deg_to_rad, angle_rad); + EXPECT_DOUBLE_EQ(45.0 * s2e::math::deg_to_rad, angle_rad); } /** @@ -439,11 +439,11 @@ TEST(Vector, CalcAngleTwoVectors45deg) { */ TEST(Vector, GenerateOrthogonalUnitVector) { const size_t N = 3; - math::Vector a(1.0); + s2e::math::Vector a(1.0); - math::Vector b = GenerateOrthogonalUnitVector(a); + s2e::math::Vector b = GenerateOrthogonalUnitVector(a); double angle_rad = CalcAngleTwoVectors_rad(a, b); - EXPECT_DOUBLE_EQ(90.0 * math::deg_to_rad, angle_rad); + EXPECT_DOUBLE_EQ(90.0 * s2e::math::deg_to_rad, angle_rad); } diff --git a/src/math_physics/math/vector.cpp b/src/math_physics/math/vector.cpp index 88c214ba7..22a74e119 100644 --- a/src/math_physics/math/vector.cpp +++ b/src/math_physics/math/vector.cpp @@ -7,7 +7,7 @@ #include "constants.hpp" -namespace math { +namespace s2e::math { Vector<3, double> ConvertFrameOrthogonal2Polar(const Vector<3, double>& orthogonal) { Vector<3, double> polar; // vector on the polar coordinate polar.FillUp(0.0); @@ -51,4 +51,4 @@ Vector<3, double> GenerateOrthogonalUnitVector(const Vector<3, double>& v) { return (orthogonal_vector); } } -} // namespace math +} // namespace s2e::math diff --git a/src/math_physics/math/vector.hpp b/src/math_physics/math/vector.hpp index 5d290d87f..b210759e6 100644 --- a/src/math_physics/math/vector.hpp +++ b/src/math_physics/math/vector.hpp @@ -9,10 +9,11 @@ #include // for size_t #include // for ostream, cout +namespace s2e::math { + #define dot InnerProduct #define cross OuterProduct -namespace math { /** * @class Vector * @brief Class for mathematical vector @@ -237,7 +238,7 @@ Vector<3, double> ConvertFrameOrthogonal2Polar(const Vector<3, double>& orthogon */ Vector<3, double> GenerateOrthogonalUnitVector(const Vector<3, double>& v); -} // namespace math +} // namespace s2e::math #include "vector_template_functions.hpp" diff --git a/src/math_physics/math/vector_template_functions.hpp b/src/math_physics/math/vector_template_functions.hpp index 80e51ce5f..9b9900388 100644 --- a/src/math_physics/math/vector_template_functions.hpp +++ b/src/math_physics/math/vector_template_functions.hpp @@ -8,7 +8,7 @@ #include -namespace math { +namespace s2e::math { template Vector::Vector(const T& n) { @@ -146,6 +146,6 @@ double CalcAngleTwoVectors_rad(const Vector& v1, const Vector { std::vector CalcInterpolationWeights(const double sigma) const; }; -} // namespace numerical_integration +} // namespace s2e::numerical_integration #include "dormand_prince_5_implementation.hpp" diff --git a/src/math_physics/numerical_integration/dormand_prince_5_implementation.hpp b/src/math_physics/numerical_integration/dormand_prince_5_implementation.hpp index 40b09a9c1..8a5bbb55e 100644 --- a/src/math_physics/numerical_integration/dormand_prince_5_implementation.hpp +++ b/src/math_physics/numerical_integration/dormand_prince_5_implementation.hpp @@ -11,7 +11,7 @@ #include "dormand_prince_5.hpp" -namespace numerical_integration { +namespace s2e::numerical_integration { template DormandPrince5::DormandPrince5(const double step_width, const InterfaceOde& ode) : EmbeddedRungeKutta(step_width, ode) { @@ -149,6 +149,6 @@ std::vector DormandPrince5::CalcInterpolationWeights(const double sig return interpolation_weights; } -} // namespace numerical_integration +} // namespace s2e::numerical_integration #endif // S2E_LIBRARY_NUMERICAL_INTEGRATION_DORMAND_PRINCE_5_IMPLEMENTATION_HPP_ diff --git a/src/math_physics/numerical_integration/embedded_runge_kutta.hpp b/src/math_physics/numerical_integration/embedded_runge_kutta.hpp index 5e6fd605c..c453fc606 100644 --- a/src/math_physics/numerical_integration/embedded_runge_kutta.hpp +++ b/src/math_physics/numerical_integration/embedded_runge_kutta.hpp @@ -8,7 +8,7 @@ #include "runge_kutta.hpp" -namespace numerical_integration { +namespace s2e::numerical_integration { /** * @class EmbeddedRungeKutta @@ -51,7 +51,7 @@ class EmbeddedRungeKutta : public RungeKutta { double local_truncation_error_; //!< Norm of estimated local truncation error }; -} // namespace numerical_integration +} // namespace s2e::numerical_integration #include "embedded_runge_kutta_implementation.hpp" diff --git a/src/math_physics/numerical_integration/embedded_runge_kutta_implementation.hpp b/src/math_physics/numerical_integration/embedded_runge_kutta_implementation.hpp index ac13a861f..f4e794a0f 100644 --- a/src/math_physics/numerical_integration/embedded_runge_kutta_implementation.hpp +++ b/src/math_physics/numerical_integration/embedded_runge_kutta_implementation.hpp @@ -7,7 +7,7 @@ #include "embedded_runge_kutta.hpp" -namespace numerical_integration { +namespace s2e::numerical_integration { template void EmbeddedRungeKutta::Integrate() { @@ -37,6 +37,6 @@ void EmbeddedRungeKutta::ControlStepWidth(const double error_tolerance) { this->step_width_ = updated_step_width; } -} // namespace numerical_integration +} // namespace s2e::numerical_integration #endif // S2E_LIBRARY_NUMERICAL_INTEGRATION_EMBEDDED_RUNGE_KUTTA_IMPLEMENTATION_HPP_ diff --git a/src/math_physics/numerical_integration/interface_ode.hpp b/src/math_physics/numerical_integration/interface_ode.hpp index 1c30058e9..fada6e5b0 100644 --- a/src/math_physics/numerical_integration/interface_ode.hpp +++ b/src/math_physics/numerical_integration/interface_ode.hpp @@ -8,7 +8,7 @@ #include "../math/vector.hpp" -namespace numerical_integration { +namespace s2e::numerical_integration { /** * @class InterfaceOde @@ -27,6 +27,6 @@ class InterfaceOde { virtual math::Vector DerivativeFunction(const double independent_variable, const math::Vector& state) const = 0; }; -} // namespace numerical_integration +} // namespace s2e::numerical_integration #endif // S2E_LIBRARY_NUMERICAL_INTEGRATION_INTERFACE_ODE_HPP_ diff --git a/src/math_physics/numerical_integration/numerical_integrator.hpp b/src/math_physics/numerical_integration/numerical_integrator.hpp index 5f19d0185..ae708a753 100644 --- a/src/math_physics/numerical_integration/numerical_integrator.hpp +++ b/src/math_physics/numerical_integration/numerical_integrator.hpp @@ -11,7 +11,7 @@ #include "../math/vector.hpp" #include "interface_ode.hpp" -namespace numerical_integration { +namespace s2e::numerical_integration { /** * @class NumericalIntegrator @@ -32,7 +32,7 @@ class NumericalIntegrator { * @fn ~NumericalIntegrator * @brief Destructor */ - inline virtual ~NumericalIntegrator(){}; + inline virtual ~NumericalIntegrator() {}; /** * @fn Integrate @@ -75,6 +75,6 @@ class NumericalIntegrator { math::Vector previous_state_; //!< Previous state vector }; -} // namespace numerical_integration +} // namespace s2e::numerical_integration #endif // S2E_LIBRARY_NUMERICAL_INTEGRATION_NUMERICAL_INTEGRATOR_HPP_ diff --git a/src/math_physics/numerical_integration/numerical_integrator_manager.hpp b/src/math_physics/numerical_integration/numerical_integrator_manager.hpp index 8869f82b6..c37d3b375 100644 --- a/src/math_physics/numerical_integration/numerical_integrator_manager.hpp +++ b/src/math_physics/numerical_integration/numerical_integrator_manager.hpp @@ -12,7 +12,7 @@ #include "runge_kutta_4.hpp" #include "runge_kutta_fehlberg.hpp" -namespace numerical_integration { +namespace s2e::numerical_integration { /** * @enum NumericalIntegrationMethod @@ -62,6 +62,6 @@ class NumericalIntegratorManager { std::shared_ptr> integrator_; }; -} // namespace numerical_integration +} // namespace s2e::numerical_integration #endif // S2E_LIBRARY_NUMERICAL_INTEGRATION_NUMERICAL_INTEGRATION_HPP_ diff --git a/src/math_physics/numerical_integration/ode_examples.hpp b/src/math_physics/numerical_integration/ode_examples.hpp index b0c9085b5..98ee43d63 100644 --- a/src/math_physics/numerical_integration/ode_examples.hpp +++ b/src/math_physics/numerical_integration/ode_examples.hpp @@ -9,7 +9,7 @@ #include "../../utilities/macros.hpp" #include "interface_ode.hpp" -namespace numerical_integration { +namespace s2e::numerical_integration { class ExampleLinearOde : public InterfaceOde<1> { public: @@ -86,6 +86,6 @@ class Example2dTwoBodyOrbitOde : public InterfaceOde<4> { } }; -} // namespace numerical_integration +} // namespace s2e::numerical_integration #endif // S2E_LIBRARY_NUMERICAL_INTEGRATION_EXAMPLE_ODE_HPP_s diff --git a/src/math_physics/numerical_integration/runge_kutta.hpp b/src/math_physics/numerical_integration/runge_kutta.hpp index 18730c667..a24b4f53b 100644 --- a/src/math_physics/numerical_integration/runge_kutta.hpp +++ b/src/math_physics/numerical_integration/runge_kutta.hpp @@ -9,7 +9,7 @@ #include "numerical_integrator.hpp" -namespace numerical_integration { +namespace s2e::numerical_integration { /** * @class RungeKutta @@ -29,7 +29,7 @@ class RungeKutta : public NumericalIntegrator { * @fn ~RungeKutta * @brief Destructor */ - inline virtual ~RungeKutta(){}; + inline virtual ~RungeKutta() {}; /** * @fn Integrate @@ -55,7 +55,7 @@ class RungeKutta : public NumericalIntegrator { void CalcSlope(); }; -} // namespace numerical_integration +} // namespace s2e::numerical_integration #include "runge_kutta_template.hpp" diff --git a/src/math_physics/numerical_integration/runge_kutta_4.hpp b/src/math_physics/numerical_integration/runge_kutta_4.hpp index b2f267d58..d8925f51c 100644 --- a/src/math_physics/numerical_integration/runge_kutta_4.hpp +++ b/src/math_physics/numerical_integration/runge_kutta_4.hpp @@ -10,7 +10,7 @@ #include "runge_kutta.hpp" -namespace numerical_integration { +namespace s2e::numerical_integration { /** * @class RungeKutta4 @@ -51,6 +51,6 @@ class RungeKutta4 : public RungeKutta { } }; -} // namespace numerical_integration +} // namespace s2e::numerical_integration #endif // S2E_LIBRARY_NUMERICAL_INTEGRATION_RUNGE_KUTTA_4_HPP_ diff --git a/src/math_physics/numerical_integration/runge_kutta_fehlberg.hpp b/src/math_physics/numerical_integration/runge_kutta_fehlberg.hpp index 3056241ac..11a4a51ff 100644 --- a/src/math_physics/numerical_integration/runge_kutta_fehlberg.hpp +++ b/src/math_physics/numerical_integration/runge_kutta_fehlberg.hpp @@ -8,7 +8,7 @@ #include "embedded_runge_kutta.hpp" -namespace numerical_integration { +namespace s2e::numerical_integration { /** * @class RungeKuttaFehlberg @@ -41,7 +41,7 @@ class RungeKuttaFehlberg : public EmbeddedRungeKutta { std::vector CalcInterpolationWeights(const double sigma) const; }; -} // namespace numerical_integration +} // namespace s2e::numerical_integration #include "runge_kutta_fehlberg_implementation.hpp" diff --git a/src/math_physics/numerical_integration/runge_kutta_fehlberg_implementation.hpp b/src/math_physics/numerical_integration/runge_kutta_fehlberg_implementation.hpp index d5ef9f7c0..c9887034c 100644 --- a/src/math_physics/numerical_integration/runge_kutta_fehlberg_implementation.hpp +++ b/src/math_physics/numerical_integration/runge_kutta_fehlberg_implementation.hpp @@ -8,7 +8,7 @@ #include "runge_kutta_fehlberg.hpp" -namespace numerical_integration { +namespace s2e::numerical_integration { template RungeKuttaFehlberg::RungeKuttaFehlberg(const double step_width, const InterfaceOde& ode) : EmbeddedRungeKutta(step_width, ode) { @@ -96,6 +96,6 @@ std::vector RungeKuttaFehlberg::CalcInterpolationWeights(const double return interpolation_weights; } -} // namespace numerical_integration +} // namespace s2e::numerical_integration #endif // S2E_LIBRARY_NUMERICAL_INTEGRATION_RUNGE_KUTTA_FEHLBERG_IMPLEMENTATION_HPP_ diff --git a/src/math_physics/numerical_integration/runge_kutta_template.hpp b/src/math_physics/numerical_integration/runge_kutta_template.hpp index 99bab650c..0a34a7485 100644 --- a/src/math_physics/numerical_integration/runge_kutta_template.hpp +++ b/src/math_physics/numerical_integration/runge_kutta_template.hpp @@ -7,7 +7,7 @@ #include "./runge_kutta.hpp" -namespace numerical_integration { +namespace s2e::numerical_integration { template void RungeKutta::Integrate() { @@ -34,6 +34,6 @@ void RungeKutta::CalcSlope() { } } -} // namespace numerical_integration +} // namespace s2e::numerical_integration #endif // S2E_LIBRARY_NUMERICAL_INTEGRATION_RUNGE_KUTTA_TEMPLATE_HPP_ diff --git a/src/math_physics/numerical_integration/test_runge_kutta.cpp b/src/math_physics/numerical_integration/test_runge_kutta.cpp index 376406850..d544caae3 100644 --- a/src/math_physics/numerical_integration/test_runge_kutta.cpp +++ b/src/math_physics/numerical_integration/test_runge_kutta.cpp @@ -15,10 +15,10 @@ * @brief Test for constructor */ TEST(NUMERICAL_INTEGRATION, Constructor) { - numerical_integration::ExampleLinearOde ode; - numerical_integration::RungeKutta4<1> linear_ode(0.1, ode); + s2e::numerical_integration::ExampleLinearOde ode; + s2e::numerical_integration::RungeKutta4<1> linear_ode(0.1, ode); - math::Vector<1> state = linear_ode.GetState(); + s2e::math::Vector<1> state = linear_ode.GetState(); EXPECT_DOUBLE_EQ(0.0, state[0]); } @@ -27,10 +27,10 @@ TEST(NUMERICAL_INTEGRATION, Constructor) { */ TEST(NUMERICAL_INTEGRATION, IntegrateLinearRk4) { double step_width_s = 0.1; - numerical_integration::ExampleLinearOde ode; - numerical_integration::RungeKutta4<1> rk4_ode(step_width_s, ode); + s2e::numerical_integration::ExampleLinearOde ode; + s2e::numerical_integration::RungeKutta4<1> rk4_ode(step_width_s, ode); - math::Vector<1> state = rk4_ode.GetState(); + s2e::math::Vector<1> state = rk4_ode.GetState(); EXPECT_DOUBLE_EQ(0.0, state[0]); size_t step_num = 10000; @@ -48,10 +48,10 @@ TEST(NUMERICAL_INTEGRATION, IntegrateLinearRk4) { */ TEST(NUMERICAL_INTEGRATION, IntegrateLinearRkf) { double step_width_s = 0.1; - numerical_integration::ExampleLinearOde ode; - numerical_integration::RungeKuttaFehlberg<1> rkf_ode(step_width_s, ode); + s2e::numerical_integration::ExampleLinearOde ode; + s2e::numerical_integration::RungeKuttaFehlberg<1> rkf_ode(step_width_s, ode); - math::Vector<1> state = rkf_ode.GetState(); + s2e::math::Vector<1> state = rkf_ode.GetState(); EXPECT_DOUBLE_EQ(0.0, state[0]); size_t step_num = 10000; @@ -69,10 +69,10 @@ TEST(NUMERICAL_INTEGRATION, IntegrateLinearRkf) { */ TEST(NUMERICAL_INTEGRATION, IntegrateLinearDp5) { double step_width_s = 0.1; - numerical_integration::ExampleLinearOde ode; - numerical_integration::DormandPrince5<1> dp5_ode(step_width_s, ode); + s2e::numerical_integration::ExampleLinearOde ode; + s2e::numerical_integration::DormandPrince5<1> dp5_ode(step_width_s, ode); - math::Vector<1> state = dp5_ode.GetState(); + s2e::math::Vector<1> state = dp5_ode.GetState(); EXPECT_DOUBLE_EQ(0.0, state[0]); size_t step_num = 10000; @@ -90,10 +90,10 @@ TEST(NUMERICAL_INTEGRATION, IntegrateLinearDp5) { */ TEST(NUMERICAL_INTEGRATION, IntegrateLinearNumericalIntegratorManagerRk4) { double step_width_s = 0.1; - numerical_integration::ExampleLinearOde ode; - numerical_integration::NumericalIntegratorManager<1> numerical_integrator(step_width_s, ode); + s2e::numerical_integration::ExampleLinearOde ode; + s2e::numerical_integration::NumericalIntegratorManager<1> numerical_integrator(step_width_s, ode); - math::Vector<1> state = numerical_integrator.GetIntegrator()->GetState(); + s2e::math::Vector<1> state = numerical_integrator.GetIntegrator()->GetState(); EXPECT_DOUBLE_EQ(0.0, state[0]); size_t step_num = 10000; @@ -111,11 +111,11 @@ TEST(NUMERICAL_INTEGRATION, IntegrateLinearNumericalIntegratorManagerRk4) { */ TEST(NUMERICAL_INTEGRATION, IntegrateLinearNumericalIntegratorManagerRkf) { double step_width_s = 0.1; - numerical_integration::ExampleLinearOde ode; - numerical_integration::NumericalIntegratorManager<1> numerical_integrator(step_width_s, ode, - numerical_integration::NumericalIntegrationMethod::kRkf); + s2e::numerical_integration::ExampleLinearOde ode; + s2e::numerical_integration::NumericalIntegratorManager<1> numerical_integrator(step_width_s, ode, + s2e::numerical_integration::NumericalIntegrationMethod::kRkf); - math::Vector<1> state = numerical_integrator.GetIntegrator()->GetState(); + s2e::math::Vector<1> state = numerical_integrator.GetIntegrator()->GetState(); EXPECT_DOUBLE_EQ(0.0, state[0]); size_t step_num = 10000; @@ -137,11 +137,11 @@ TEST(NUMERICAL_INTEGRATION, IntegrateLinearNumericalIntegratorManagerRkf) { */ TEST(NUMERICAL_INTEGRATION, IntegrateLinearNumericalIntegratorManagerDp5) { double step_width_s = 0.1; - numerical_integration::ExampleLinearOde ode; - numerical_integration::NumericalIntegratorManager<1> numerical_integrator(step_width_s, ode, - numerical_integration::NumericalIntegrationMethod::kDp5); + s2e::numerical_integration::ExampleLinearOde ode; + s2e::numerical_integration::NumericalIntegratorManager<1> numerical_integrator(step_width_s, ode, + s2e::numerical_integration::NumericalIntegrationMethod::kDp5); - math::Vector<1> state = numerical_integrator.GetIntegrator()->GetState(); + s2e::math::Vector<1> state = numerical_integrator.GetIntegrator()->GetState(); EXPECT_DOUBLE_EQ(0.0, state[0]); size_t step_num = 10000; @@ -163,10 +163,10 @@ TEST(NUMERICAL_INTEGRATION, IntegrateLinearNumericalIntegratorManagerDp5) { */ TEST(NUMERICAL_INTEGRATION, IntegrateQuadraticRk4) { double step_width_s = 0.1; - numerical_integration::ExampleQuadraticOde ode; - numerical_integration::RungeKutta4<1> rk4_ode(step_width_s, ode); + s2e::numerical_integration::ExampleQuadraticOde ode; + s2e::numerical_integration::RungeKutta4<1> rk4_ode(step_width_s, ode); - math::Vector<1> state = rk4_ode.GetState(); + s2e::math::Vector<1> state = rk4_ode.GetState(); EXPECT_DOUBLE_EQ(0.0, state[0]); size_t step_num = 10000; @@ -184,10 +184,10 @@ TEST(NUMERICAL_INTEGRATION, IntegrateQuadraticRk4) { */ TEST(NUMERICAL_INTEGRATION, IntegrateQuadraticRkf) { double step_width_s = 0.1; - numerical_integration::ExampleQuadraticOde ode; - numerical_integration::RungeKuttaFehlberg<1> rkf_ode(step_width_s, ode); + s2e::numerical_integration::ExampleQuadraticOde ode; + s2e::numerical_integration::RungeKuttaFehlberg<1> rkf_ode(step_width_s, ode); - math::Vector<1> state = rkf_ode.GetState(); + s2e::math::Vector<1> state = rkf_ode.GetState(); EXPECT_DOUBLE_EQ(0.0, state[0]); size_t step_num = 10000; @@ -205,10 +205,10 @@ TEST(NUMERICAL_INTEGRATION, IntegrateQuadraticRkf) { */ TEST(NUMERICAL_INTEGRATION, InterpolationQuadraticRkf) { double step_width_s = 10.0; - numerical_integration::ExampleQuadraticOde ode; - numerical_integration::RungeKuttaFehlberg<1> rkf_ode(step_width_s, ode); + s2e::numerical_integration::ExampleQuadraticOde ode; + s2e::numerical_integration::RungeKuttaFehlberg<1> rkf_ode(step_width_s, ode); - math::Vector<1> state = rkf_ode.GetState(); + s2e::math::Vector<1> state = rkf_ode.GetState(); EXPECT_DOUBLE_EQ(0.0, state[0]); rkf_ode.Integrate(); @@ -234,10 +234,10 @@ TEST(NUMERICAL_INTEGRATION, InterpolationQuadraticRkf) { */ TEST(NUMERICAL_INTEGRATION, IntegrateQuadraticDp5) { double step_width_s = 0.1; - numerical_integration::ExampleQuadraticOde ode; - numerical_integration::DormandPrince5<1> dp5_ode(step_width_s, ode); + s2e::numerical_integration::ExampleQuadraticOde ode; + s2e::numerical_integration::DormandPrince5<1> dp5_ode(step_width_s, ode); - math::Vector<1> state = dp5_ode.GetState(); + s2e::math::Vector<1> state = dp5_ode.GetState(); EXPECT_DOUBLE_EQ(0.0, state[0]); size_t step_num = 10000; @@ -255,10 +255,10 @@ TEST(NUMERICAL_INTEGRATION, IntegrateQuadraticDp5) { */ TEST(NUMERICAL_INTEGRATION, InterpolationQuadraticDp5) { double step_width_s = 10.0; - numerical_integration::ExampleQuadraticOde ode; - numerical_integration::DormandPrince5<1> dp5_ode(step_width_s, ode); + s2e::numerical_integration::ExampleQuadraticOde ode; + s2e::numerical_integration::DormandPrince5<1> dp5_ode(step_width_s, ode); - math::Vector<1> state = dp5_ode.GetState(); + s2e::math::Vector<1> state = dp5_ode.GetState(); EXPECT_DOUBLE_EQ(0.0, state[0]); dp5_ode.Integrate(); @@ -284,15 +284,15 @@ TEST(NUMERICAL_INTEGRATION, InterpolationQuadraticDp5) { */ TEST(NUMERICAL_INTEGRATION, Integrate1dPositionVelocityRk4) { double step_width_s = 0.1; - numerical_integration::Example1dPositionVelocityOde ode; - numerical_integration::RungeKutta4<2> rk4_ode(step_width_s, ode); + s2e::numerical_integration::Example1dPositionVelocityOde ode; + s2e::numerical_integration::RungeKutta4<2> rk4_ode(step_width_s, ode); - math::Vector<2> initial_state(0.0); + s2e::math::Vector<2> initial_state(0.0); initial_state[0] = 0.0; initial_state[1] = 0.1; rk4_ode.SetState(0.0, initial_state); - math::Vector<2> state = rk4_ode.GetState(); + s2e::math::Vector<2> state = rk4_ode.GetState(); EXPECT_DOUBLE_EQ(initial_state[0], state[0]); EXPECT_DOUBLE_EQ(initial_state[1], state[1]); @@ -301,7 +301,7 @@ TEST(NUMERICAL_INTEGRATION, Integrate1dPositionVelocityRk4) { rk4_ode.Integrate(); } state = rk4_ode.GetState(); - math::Vector<2> estimated_result(0.0); + s2e::math::Vector<2> estimated_result(0.0); estimated_result[0] = (step_width_s * step_num) * initial_state[1] + initial_state[0]; estimated_result[1] = initial_state[1]; @@ -314,15 +314,15 @@ TEST(NUMERICAL_INTEGRATION, Integrate1dPositionVelocityRk4) { */ TEST(NUMERICAL_INTEGRATION, Integrate1dPositionVelocityRkf) { double step_width_s = 0.1; - numerical_integration::Example1dPositionVelocityOde ode; - numerical_integration::RungeKuttaFehlberg<2> rkf_ode(step_width_s, ode); + s2e::numerical_integration::Example1dPositionVelocityOde ode; + s2e::numerical_integration::RungeKuttaFehlberg<2> rkf_ode(step_width_s, ode); - math::Vector<2> initial_state(0.0); + s2e::math::Vector<2> initial_state(0.0); initial_state[0] = 0.0; initial_state[1] = 0.1; rkf_ode.SetState(0.0, initial_state); - math::Vector<2> state = rkf_ode.GetState(); + s2e::math::Vector<2> state = rkf_ode.GetState(); EXPECT_DOUBLE_EQ(initial_state[0], state[0]); EXPECT_DOUBLE_EQ(initial_state[1], state[1]); @@ -331,7 +331,7 @@ TEST(NUMERICAL_INTEGRATION, Integrate1dPositionVelocityRkf) { rkf_ode.Integrate(); } state = rkf_ode.GetState(); - math::Vector<2> estimated_result(0.0); + s2e::math::Vector<2> estimated_result(0.0); estimated_result[0] = (step_width_s * step_num) * initial_state[1] + initial_state[0]; estimated_result[1] = initial_state[1]; @@ -344,15 +344,15 @@ TEST(NUMERICAL_INTEGRATION, Integrate1dPositionVelocityRkf) { */ TEST(NUMERICAL_INTEGRATION, Integrate1dPositionVelocityDp5) { double step_width_s = 0.1; - numerical_integration::Example1dPositionVelocityOde ode; - numerical_integration::DormandPrince5<2> dp5_ode(step_width_s, ode); + s2e::numerical_integration::Example1dPositionVelocityOde ode; + s2e::numerical_integration::DormandPrince5<2> dp5_ode(step_width_s, ode); - math::Vector<2> initial_state(0.0); + s2e::math::Vector<2> initial_state(0.0); initial_state[0] = 0.0; initial_state[1] = 0.1; dp5_ode.SetState(0.0, initial_state); - math::Vector<2> state = dp5_ode.GetState(); + s2e::math::Vector<2> state = dp5_ode.GetState(); EXPECT_DOUBLE_EQ(initial_state[0], state[0]); EXPECT_DOUBLE_EQ(initial_state[1], state[1]); @@ -361,7 +361,7 @@ TEST(NUMERICAL_INTEGRATION, Integrate1dPositionVelocityDp5) { dp5_ode.Integrate(); } state = dp5_ode.GetState(); - math::Vector<2> estimated_result(0.0); + s2e::math::Vector<2> estimated_result(0.0); estimated_result[0] = (step_width_s * step_num) * initial_state[1] + initial_state[0]; estimated_result[1] = initial_state[1]; @@ -374,12 +374,12 @@ TEST(NUMERICAL_INTEGRATION, Integrate1dPositionVelocityDp5) { */ TEST(NUMERICAL_INTEGRATION, Integrate2dTwoBodyOrbitSmallEccentricity) { double step_width_s = 0.1; - numerical_integration::Example2dTwoBodyOrbitOde ode; - numerical_integration::RungeKutta4<4> rk4_ode(step_width_s, ode); - numerical_integration::RungeKuttaFehlberg<4> rkf_ode(step_width_s, ode); - numerical_integration::DormandPrince5<4> dp5_ode(step_width_s, ode); + s2e::numerical_integration::Example2dTwoBodyOrbitOde ode; + s2e::numerical_integration::RungeKutta4<4> rk4_ode(step_width_s, ode); + s2e::numerical_integration::RungeKuttaFehlberg<4> rkf_ode(step_width_s, ode); + s2e::numerical_integration::DormandPrince5<4> dp5_ode(step_width_s, ode); - math::Vector<4> initial_state(0.0); + s2e::math::Vector<4> initial_state(0.0); const double eccentricity = 0.1; initial_state[0] = 1.0 - eccentricity; initial_state[1] = 0.0; @@ -389,9 +389,9 @@ TEST(NUMERICAL_INTEGRATION, Integrate2dTwoBodyOrbitSmallEccentricity) { rkf_ode.SetState(0.0, initial_state); dp5_ode.SetState(0.0, initial_state); - math::Vector<4> state_rk4 = rk4_ode.GetState(); - math::Vector<4> state_rkf = rkf_ode.GetState(); - math::Vector<4> state_dp5 = dp5_ode.GetState(); + s2e::math::Vector<4> state_rk4 = rk4_ode.GetState(); + s2e::math::Vector<4> state_rkf = rkf_ode.GetState(); + s2e::math::Vector<4> state_dp5 = dp5_ode.GetState(); for (size_t i = 0; i < 4; i++) { EXPECT_DOUBLE_EQ(initial_state[i], state_rk4[i]); EXPECT_DOUBLE_EQ(initial_state[i], state_rkf[i]); @@ -409,15 +409,15 @@ TEST(NUMERICAL_INTEGRATION, Integrate2dTwoBodyOrbitSmallEccentricity) { state_dp5 = dp5_ode.GetState(); // Estimation by Kepler Orbit calculation - math::Vector<3> initial_position(0.0); - math::Vector<3> initial_velocity(0.0); + s2e::math::Vector<3> initial_position(0.0); + s2e::math::Vector<3> initial_velocity(0.0); initial_position[0] = initial_state[0]; initial_position[1] = initial_state[1]; initial_velocity[0] = initial_state[2]; initial_velocity[1] = initial_state[3]; - orbit::OrbitalElements oe(1.0, 0.0, initial_position, initial_velocity); - orbit::KeplerOrbit kepler(1.0, oe); + s2e::orbit::OrbitalElements oe(1.0, 0.0, initial_position, initial_velocity); + s2e::orbit::KeplerOrbit kepler(1.0, oe); kepler.CalcOrbit((double)(step_num * step_width_s) / (24.0 * 60.0 * 60.0)); double error_tolerance = 2e-4; @@ -444,12 +444,12 @@ TEST(NUMERICAL_INTEGRATION, Integrate2dTwoBodyOrbitSmallEccentricity) { */ TEST(NUMERICAL_INTEGRATION, Integrate2dTwoBodyOrbitLargeEccentricity) { double step_width_s = 0.01; - numerical_integration::Example2dTwoBodyOrbitOde ode; - numerical_integration::RungeKutta4<4> rk4_ode(step_width_s, ode); - numerical_integration::RungeKuttaFehlberg<4> rkf_ode(step_width_s, ode); - numerical_integration::DormandPrince5<4> dp5_ode(step_width_s, ode); + s2e::numerical_integration::Example2dTwoBodyOrbitOde ode; + s2e::numerical_integration::RungeKutta4<4> rk4_ode(step_width_s, ode); + s2e::numerical_integration::RungeKuttaFehlberg<4> rkf_ode(step_width_s, ode); + s2e::numerical_integration::DormandPrince5<4> dp5_ode(step_width_s, ode); - math::Vector<4> initial_state(0.0); + s2e::math::Vector<4> initial_state(0.0); const double eccentricity = 0.9; initial_state[0] = 1.0 - eccentricity; initial_state[1] = 0.0; @@ -459,9 +459,9 @@ TEST(NUMERICAL_INTEGRATION, Integrate2dTwoBodyOrbitLargeEccentricity) { rkf_ode.SetState(0.0, initial_state); dp5_ode.SetState(0.0, initial_state); - math::Vector<4> state_rk4 = rk4_ode.GetState(); - math::Vector<4> state_rkf = rkf_ode.GetState(); - math::Vector<4> state_dp5 = dp5_ode.GetState(); + s2e::math::Vector<4> state_rk4 = rk4_ode.GetState(); + s2e::math::Vector<4> state_rkf = rkf_ode.GetState(); + s2e::math::Vector<4> state_dp5 = dp5_ode.GetState(); for (size_t i = 0; i < 4; i++) { EXPECT_DOUBLE_EQ(initial_state[i], state_rk4[i]); EXPECT_DOUBLE_EQ(initial_state[i], state_rkf[i]); @@ -479,15 +479,15 @@ TEST(NUMERICAL_INTEGRATION, Integrate2dTwoBodyOrbitLargeEccentricity) { state_dp5 = dp5_ode.GetState(); // Estimation by Kepler Orbit calculation - math::Vector<3> initial_position(0.0); - math::Vector<3> initial_velocity(0.0); + s2e::math::Vector<3> initial_position(0.0); + s2e::math::Vector<3> initial_velocity(0.0); initial_position[0] = initial_state[0]; initial_position[1] = initial_state[1]; initial_velocity[0] = initial_state[2]; initial_velocity[1] = initial_state[3]; - orbit::OrbitalElements oe(1.0, 0.0, initial_position, initial_velocity); - orbit::KeplerOrbit kepler(1.0, oe); + s2e::orbit::OrbitalElements oe(1.0, 0.0, initial_position, initial_velocity); + s2e::orbit::KeplerOrbit kepler(1.0, oe); kepler.CalcOrbit((double)(step_num * step_width_s) / (24.0 * 60.0 * 60.0)); double error_tolerance = 2e-1; @@ -514,11 +514,11 @@ TEST(NUMERICAL_INTEGRATION, Integrate2dTwoBodyOrbitLargeEccentricity) { */ TEST(NUMERICAL_INTEGRATION, Interpolation2dTwoBodyOrbitSmallEccentricity) { double step_width_s = 1.0; - numerical_integration::Example2dTwoBodyOrbitOde ode; - numerical_integration::RungeKuttaFehlberg<4> rkf_ode(step_width_s, ode); - numerical_integration::DormandPrince5<4> dp5_ode(step_width_s, ode); + s2e::numerical_integration::Example2dTwoBodyOrbitOde ode; + s2e::numerical_integration::RungeKuttaFehlberg<4> rkf_ode(step_width_s, ode); + s2e::numerical_integration::DormandPrince5<4> dp5_ode(step_width_s, ode); - math::Vector<4> initial_state(0.0); + s2e::math::Vector<4> initial_state(0.0); const double eccentricity = 0.1; initial_state[0] = 1.0 - eccentricity; initial_state[1] = 0.0; @@ -527,8 +527,8 @@ TEST(NUMERICAL_INTEGRATION, Interpolation2dTwoBodyOrbitSmallEccentricity) { rkf_ode.SetState(0.0, initial_state); dp5_ode.SetState(0.0, initial_state); - math::Vector<4> state_rkf = rkf_ode.GetState(); - math::Vector<4> state_dp5 = dp5_ode.GetState(); + s2e::math::Vector<4> state_rkf = rkf_ode.GetState(); + s2e::math::Vector<4> state_dp5 = dp5_ode.GetState(); for (size_t i = 0; i < 4; i++) { EXPECT_DOUBLE_EQ(initial_state[i], state_rkf[i]); EXPECT_DOUBLE_EQ(initial_state[i], state_dp5[i]); @@ -543,16 +543,16 @@ TEST(NUMERICAL_INTEGRATION, Interpolation2dTwoBodyOrbitSmallEccentricity) { state_dp5 = dp5_ode.GetState(); // Estimation by Kepler Orbit calculation - math::Vector<3> initial_position(0.0); - math::Vector<3> initial_velocity(0.0); + s2e::math::Vector<3> initial_position(0.0); + s2e::math::Vector<3> initial_velocity(0.0); // Final value initial_position[0] = initial_state[0]; initial_position[1] = initial_state[1]; initial_velocity[0] = initial_state[2]; initial_velocity[1] = initial_state[3]; - orbit::OrbitalElements oe(1.0, 0.0, initial_position, initial_velocity); - orbit::KeplerOrbit kepler(1.0, oe); + s2e::orbit::OrbitalElements oe(1.0, 0.0, initial_position, initial_velocity); + s2e::orbit::KeplerOrbit kepler(1.0, oe); kepler.CalcOrbit((double)(step_num * step_width_s) / (24.0 * 60.0 * 60.0)); double error_tolerance = 5e-2; @@ -609,11 +609,11 @@ TEST(NUMERICAL_INTEGRATION, Interpolation2dTwoBodyOrbitSmallEccentricity) { */ TEST(NUMERICAL_INTEGRATION, Interpolation2dTwoBodyOrbitLargeEccentricity) { double step_width_s = 0.01; - numerical_integration::Example2dTwoBodyOrbitOde ode; - numerical_integration::RungeKuttaFehlberg<4> rkf_ode(step_width_s, ode); - numerical_integration::DormandPrince5<4> dp5_ode(step_width_s, ode); + s2e::numerical_integration::Example2dTwoBodyOrbitOde ode; + s2e::numerical_integration::RungeKuttaFehlberg<4> rkf_ode(step_width_s, ode); + s2e::numerical_integration::DormandPrince5<4> dp5_ode(step_width_s, ode); - math::Vector<4> initial_state(0.0); + s2e::math::Vector<4> initial_state(0.0); const double eccentricity = 0.8; initial_state[0] = 1.0 - eccentricity; initial_state[1] = 0.0; @@ -622,8 +622,8 @@ TEST(NUMERICAL_INTEGRATION, Interpolation2dTwoBodyOrbitLargeEccentricity) { rkf_ode.SetState(0.0, initial_state); dp5_ode.SetState(0.0, initial_state); - math::Vector<4> state_rkf = rkf_ode.GetState(); - math::Vector<4> state_dp5 = dp5_ode.GetState(); + s2e::math::Vector<4> state_rkf = rkf_ode.GetState(); + s2e::math::Vector<4> state_dp5 = dp5_ode.GetState(); for (size_t i = 0; i < 4; i++) { EXPECT_DOUBLE_EQ(initial_state[i], state_rkf[i]); EXPECT_DOUBLE_EQ(initial_state[i], state_dp5[i]); @@ -638,16 +638,16 @@ TEST(NUMERICAL_INTEGRATION, Interpolation2dTwoBodyOrbitLargeEccentricity) { state_dp5 = dp5_ode.GetState(); // Estimation by Kepler Orbit calculation - math::Vector<3> initial_position(0.0); - math::Vector<3> initial_velocity(0.0); + s2e::math::Vector<3> initial_position(0.0); + s2e::math::Vector<3> initial_velocity(0.0); // Final value initial_position[0] = initial_state[0]; initial_position[1] = initial_state[1]; initial_velocity[0] = initial_state[2]; initial_velocity[1] = initial_state[3]; - orbit::OrbitalElements oe(1.0, 0.0, initial_position, initial_velocity); - orbit::KeplerOrbit kepler(1.0, oe); + s2e::orbit::OrbitalElements oe(1.0, 0.0, initial_position, initial_velocity); + s2e::orbit::KeplerOrbit kepler(1.0, oe); kepler.CalcOrbit((double)(step_num * step_width_s) / (24.0 * 60.0 * 60.0)); double error_tolerance = 1e-5; diff --git a/src/math_physics/optics/gaussian_beam_base.cpp b/src/math_physics/optics/gaussian_beam_base.cpp index 86995e7e2..10b9745c8 100644 --- a/src/math_physics/optics/gaussian_beam_base.cpp +++ b/src/math_physics/optics/gaussian_beam_base.cpp @@ -8,7 +8,7 @@ #include #include -namespace optics { +namespace s2e::optics { GaussianBeamBase::GaussianBeamBase(double wavelength_m, double radius_beam_waist_m, double total_power_W) : wavelength_m_(wavelength_m), radius_beam_waist_m_(radius_beam_waist_m), total_power_W_(total_power_W) {} @@ -49,4 +49,4 @@ double GaussianBeamBase::CalcIntensity_W_m2(double distance_from_beam_waist_m, d return intensity_W_m2; } -} // namespace optics +} // namespace s2e::optics diff --git a/src/math_physics/optics/gaussian_beam_base.hpp b/src/math_physics/optics/gaussian_beam_base.hpp index 6f40fa8a2..cf79b46e3 100644 --- a/src/math_physics/optics/gaussian_beam_base.hpp +++ b/src/math_physics/optics/gaussian_beam_base.hpp @@ -8,7 +8,7 @@ #include "../math/vector.hpp" -namespace optics { +namespace s2e::optics { /** * @class GaussianBeamBase @@ -109,6 +109,6 @@ class GaussianBeamBase { math::Vector<3> position_beam_waist_i_m_{0.0}; //!< Position of beam waist in the inertial frame [m] (Not used?) }; -} // namespace optics +} // namespace s2e::optics #endif // S2E_LIBRARY_OPTICS_GAUSSIAN_BEAM_BASE_HPP_ diff --git a/src/math_physics/orbit/interpolation_orbit.cpp b/src/math_physics/orbit/interpolation_orbit.cpp index 9b3a50e31..aa4874389 100644 --- a/src/math_physics/orbit/interpolation_orbit.cpp +++ b/src/math_physics/orbit/interpolation_orbit.cpp @@ -5,7 +5,7 @@ #include "interpolation_orbit.hpp" -namespace orbit { +namespace s2e::orbit { InterpolationOrbit::InterpolationOrbit(const size_t degree) { std::vector time; @@ -44,4 +44,5 @@ math::Vector<3> InterpolationOrbit::CalcPositionWithPolynomial(const double time } return output_position; } -} // namespace orbit \ No newline at end of file + +} // namespace s2e::orbit diff --git a/src/math_physics/orbit/interpolation_orbit.hpp b/src/math_physics/orbit/interpolation_orbit.hpp index f99a3d152..83913573b 100644 --- a/src/math_physics/orbit/interpolation_orbit.hpp +++ b/src/math_physics/orbit/interpolation_orbit.hpp @@ -10,7 +10,7 @@ #include #include -namespace orbit { +namespace s2e::orbit { /** * @class InterpolationOrbit @@ -79,6 +79,6 @@ class InterpolationOrbit { std::vector interpolation_position_; // 3D vector of interpolation }; -} // namespace orbit +} // namespace s2e::orbit #endif // S2E_LIBRARY_ORBIT_INTERPOLATION_ORBIT_HPP_ \ No newline at end of file diff --git a/src/math_physics/orbit/kepler_orbit.cpp b/src/math_physics/orbit/kepler_orbit.cpp index 2b3878703..2f49fd5db 100644 --- a/src/math_physics/orbit/kepler_orbit.cpp +++ b/src/math_physics/orbit/kepler_orbit.cpp @@ -7,7 +7,7 @@ #include "../math/matrix_vector.hpp" #include "../math/s2e_math.hpp" -namespace orbit { +namespace s2e::orbit { KeplerOrbit::KeplerOrbit() {} // Initialize with orbital elements @@ -100,4 +100,4 @@ double KeplerOrbit::SolveKeplerNewtonMethod(const double eccentricity, const dou return u_rad; } -} // namespace orbit +} // namespace s2e::orbit diff --git a/src/math_physics/orbit/kepler_orbit.hpp b/src/math_physics/orbit/kepler_orbit.hpp index fec55f130..efe4e7f5c 100644 --- a/src/math_physics/orbit/kepler_orbit.hpp +++ b/src/math_physics/orbit/kepler_orbit.hpp @@ -10,7 +10,7 @@ #include "../math/vector.hpp" #include "./orbital_elements.hpp" -namespace orbit { +namespace s2e::orbit { /** * @class KeplerOrbit @@ -89,6 +89,6 @@ class KeplerOrbit { double SolveKeplerNewtonMethod(const double eccentricity, const double mean_anomaly_rad, const double angle_limit_rad, const int iteration_limit); }; -} // namespace orbit +} // namespace s2e::orbit #endif // S2E_LIBRARY_ORBIT_KEPLER_ORBIT_HPP_ diff --git a/src/math_physics/orbit/orbital_elements.cpp b/src/math_physics/orbit/orbital_elements.cpp index 3fd2920b7..d02a324e2 100644 --- a/src/math_physics/orbit/orbital_elements.cpp +++ b/src/math_physics/orbit/orbital_elements.cpp @@ -9,7 +9,7 @@ #include "../math/s2e_math.hpp" -namespace orbit { +namespace s2e::orbit { OrbitalElements::OrbitalElements() {} @@ -88,4 +88,4 @@ void OrbitalElements::CalcOeFromPosVel(const double gravity_constant_m3_s2, cons epoch_jday_ = time_jday - dt_s / (24.0 * 60.0 * 60.0); } -} // namespace orbit +} // namespace s2e::orbit diff --git a/src/math_physics/orbit/orbital_elements.hpp b/src/math_physics/orbit/orbital_elements.hpp index 27424653e..4b4e3f04f 100644 --- a/src/math_physics/orbit/orbital_elements.hpp +++ b/src/math_physics/orbit/orbital_elements.hpp @@ -8,7 +8,7 @@ #include "../math/vector.hpp" -namespace orbit { +namespace s2e::orbit { /** * @class OrbitalElements @@ -106,6 +106,6 @@ class OrbitalElements { const math::Vector<3> velocity_i_m_s); }; -} // namespace orbit +} // namespace s2e::orbit #endif // S2E_LIBRARY_ORBIT_ORBITAL_ELEMENTS_HPP_ diff --git a/src/math_physics/orbit/relative_orbit_models.cpp b/src/math_physics/orbit/relative_orbit_models.cpp index a291e4633..0ec2ebfff 100644 --- a/src/math_physics/orbit/relative_orbit_models.cpp +++ b/src/math_physics/orbit/relative_orbit_models.cpp @@ -4,7 +4,7 @@ */ #include "relative_orbit_models.hpp" -namespace orbit { +namespace s2e::orbit { math::Matrix<6, 6> CalcHillSystemMatrix(double orbit_radius_m, double gravity_constant_m3_s2) { math::Matrix<6, 6> system_matrix; @@ -94,4 +94,4 @@ math::Matrix<6, 6> CalcHcwStm(double orbit_radius_m, double gravity_constant_m3_ return stm; } -} // namespace orbit +} // namespace s2e::orbit diff --git a/src/math_physics/orbit/relative_orbit_models.hpp b/src/math_physics/orbit/relative_orbit_models.hpp index 881d73bfb..eb5c42a45 100644 --- a/src/math_physics/orbit/relative_orbit_models.hpp +++ b/src/math_physics/orbit/relative_orbit_models.hpp @@ -9,7 +9,7 @@ #include "../math/matrix.hpp" #include "../math/vector.hpp" -namespace orbit { +namespace s2e::orbit { /** * @enum RelativeOrbitModel @@ -44,6 +44,6 @@ math::Matrix<6, 6> CalcHillSystemMatrix(const double orbit_radius_m, const doubl */ math::Matrix<6, 6> CalcHcwStm(const double orbit_radius_m, const double gravity_constant_m3_s2, const double elapsed_time_s); -} // namespace orbit +} // namespace s2e::orbit #endif // S2E_LIBRARY_ORBIT_RELATIVE_ORBIT_MODEL_HPP_ diff --git a/src/math_physics/orbit/test_interpolation_orbit.cpp b/src/math_physics/orbit/test_interpolation_orbit.cpp index d7fe51c67..f83a3f0cf 100644 --- a/src/math_physics/orbit/test_interpolation_orbit.cpp +++ b/src/math_physics/orbit/test_interpolation_orbit.cpp @@ -8,7 +8,7 @@ #include "interpolation_orbit.hpp" -using namespace orbit; +using namespace s2e::orbit; /** * @brief Test for Constructor function @@ -33,7 +33,7 @@ TEST(InterpolationOrbit, PushAndPop) { EXPECT_EQ(degree, interpolation_orbit.GetDegree()); for (size_t i = 0; i < degree; i++) { double time = (double)i; - math::Vector<3> position{i * 2.0}; + s2e::math::Vector<3> position{i * 2.0}; bool ret = interpolation_orbit.PushAndPopData(time, position); EXPECT_TRUE(ret); } @@ -46,7 +46,7 @@ TEST(InterpolationOrbit, PushAndPop) { // False test double time = 2.0; - math::Vector<3> position{-100.0}; + s2e::math::Vector<3> position{-100.0}; bool ret = interpolation_orbit.PushAndPopData(time, position); EXPECT_FALSE(ret); } diff --git a/src/math_physics/planet_rotation/moon_rotation_utilities.cpp b/src/math_physics/planet_rotation/moon_rotation_utilities.cpp index cd6dc020a..370e5ba63 100644 --- a/src/math_physics/planet_rotation/moon_rotation_utilities.cpp +++ b/src/math_physics/planet_rotation/moon_rotation_utilities.cpp @@ -10,7 +10,7 @@ #include -namespace planet_rotation { +namespace s2e::planet_rotation { math::Matrix<3, 3> CalcDcmEciToPrincipalAxis(const math::Vector<3> moon_position_eci_m, const math::Vector<3> moon_velocity_eci_m_s) { math::Matrix<3, 3> dcm_eci2me = CalcDcmEciToMeanEarth(moon_position_eci_m, moon_velocity_eci_m_s); @@ -49,4 +49,4 @@ math::Matrix<3, 3> CalcDcmMeanEarthToPrincipalAxis() { return dcm_me_pa; } -} // namespace planet_rotation +} // namespace s2e::planet_rotation diff --git a/src/math_physics/planet_rotation/moon_rotation_utilities.hpp b/src/math_physics/planet_rotation/moon_rotation_utilities.hpp index 9ce97f876..b46dbd7e1 100644 --- a/src/math_physics/planet_rotation/moon_rotation_utilities.hpp +++ b/src/math_physics/planet_rotation/moon_rotation_utilities.hpp @@ -12,7 +12,7 @@ #include "math_physics/math/matrix.hpp" #include "math_physics/math/vector.hpp" -namespace planet_rotation { +namespace s2e::planet_rotation { /** * @fn CalcDcmEciToPrincipalAxis @@ -36,6 +36,6 @@ math::Matrix<3, 3> CalcDcmEciToMeanEarth(const math::Vector<3> moon_position_eci */ math::Matrix<3, 3> CalcDcmMeanEarthToPrincipalAxis(); -} // namespace planet_rotation +} // namespace s2e::planet_rotation #endif // S2E_LIBRARY_PLANET_ROTATION_MOON_MEAN_EARTH_PRINCIPAL_AXIS_FRAME_HPP_ diff --git a/src/math_physics/randomization/global_randomization.cpp b/src/math_physics/randomization/global_randomization.cpp index 7a7282902..5c1bdef1a 100644 --- a/src/math_physics/randomization/global_randomization.cpp +++ b/src/math_physics/randomization/global_randomization.cpp @@ -5,6 +5,8 @@ #include "global_randomization.hpp" +namespace s2e::randomization { + GlobalRandomization global_randomization; GlobalRandomization::GlobalRandomization() { seed_ = 0xdeadbeef; } @@ -21,4 +23,6 @@ long GlobalRandomization::MakeSeed() { seed = 0xdeadbeef; } return seed; -} \ No newline at end of file +} + +} // namespace s2e::randomization diff --git a/src/math_physics/randomization/global_randomization.hpp b/src/math_physics/randomization/global_randomization.hpp index 24c88ec2b..5220420cf 100644 --- a/src/math_physics/randomization/global_randomization.hpp +++ b/src/math_physics/randomization/global_randomization.hpp @@ -8,6 +8,8 @@ #include "./minimal_standard_linear_congruential_generator.hpp" +namespace s2e::randomization { + /** * @class global_randomization.hpp * @brief Class to manage global randomization @@ -32,11 +34,13 @@ class GlobalRandomization { long MakeSeed(); private: - static const unsigned int kMaxSeed = 0xffffffff; //!< Maximum value of seed - randomization::MinimalStandardLcg base_randomizer_; //!< Base of global randomization - long seed_; //!< Seed of global randomization + static const unsigned int kMaxSeed = 0xffffffff; //!< Maximum value of seed + MinimalStandardLcg base_randomizer_; //!< Base of global randomization + long seed_; //!< Seed of global randomization }; extern GlobalRandomization global_randomization; //!< Global randomization +} // namespace s2e::randomization + #endif // S2E_LIBRARY_RANDOMIZATION_GLOBAL_RANDOMIZATION_HPP_ diff --git a/src/math_physics/randomization/minimal_standard_linear_congruential_generator.cpp b/src/math_physics/randomization/minimal_standard_linear_congruential_generator.cpp index ccd179507..c1821e93b 100644 --- a/src/math_physics/randomization/minimal_standard_linear_congruential_generator.cpp +++ b/src/math_physics/randomization/minimal_standard_linear_congruential_generator.cpp @@ -5,7 +5,7 @@ */ #include "minimal_standard_linear_congruential_generator.hpp" -using randomization::MinimalStandardLcg; +using s2e::randomization::MinimalStandardLcg; #include diff --git a/src/math_physics/randomization/minimal_standard_linear_congruential_generator.hpp b/src/math_physics/randomization/minimal_standard_linear_congruential_generator.hpp index 9120faffd..01ff61947 100644 --- a/src/math_physics/randomization/minimal_standard_linear_congruential_generator.hpp +++ b/src/math_physics/randomization/minimal_standard_linear_congruential_generator.hpp @@ -7,7 +7,7 @@ #ifndef S2E_LIBRARY_RANDOMIZATION_MINIMAL_STANDARD_LINEAR_CONGRUENTIAL_GENERATOR_HPP_ #define S2E_LIBRARY_RANDOMIZATION_MINIMAL_STANDARD_LINEAR_CONGRUENTIAL_GENERATOR_HPP_ -namespace randomization { +namespace s2e::randomization { /** * @class MinimalStandardLcg @@ -52,6 +52,6 @@ class MinimalStandardLcg { long seed_; //!< Seed of randomization }; -} // namespace randomization +} // namespace s2e::randomization #endif // S2E_LIBRARY_RANDOMIZATION_MINIMAL_STANDARD_LINEAR_CONGRUENTIAL_GENERATOR_HPP_ diff --git a/src/math_physics/randomization/minimal_standard_linear_congruential_generator_with_shuffle.cpp b/src/math_physics/randomization/minimal_standard_linear_congruential_generator_with_shuffle.cpp index ea0a6bf43..3bdd51de9 100644 --- a/src/math_physics/randomization/minimal_standard_linear_congruential_generator_with_shuffle.cpp +++ b/src/math_physics/randomization/minimal_standard_linear_congruential_generator_with_shuffle.cpp @@ -5,7 +5,7 @@ */ #include "minimal_standard_linear_congruential_generator_with_shuffle.hpp" -using randomization::MinimalStandardLcgWithShuffle; +using s2e::randomization::MinimalStandardLcgWithShuffle; MinimalStandardLcgWithShuffle::MinimalStandardLcgWithShuffle() : table_position_(0) { Initialize(); } diff --git a/src/math_physics/randomization/minimal_standard_linear_congruential_generator_with_shuffle.hpp b/src/math_physics/randomization/minimal_standard_linear_congruential_generator_with_shuffle.hpp index 5c016291f..3d5913bb7 100644 --- a/src/math_physics/randomization/minimal_standard_linear_congruential_generator_with_shuffle.hpp +++ b/src/math_physics/randomization/minimal_standard_linear_congruential_generator_with_shuffle.hpp @@ -11,7 +11,7 @@ #include "minimal_standard_linear_congruential_generator.hpp" -namespace randomization { +namespace s2e::randomization { /** * @class MinimalStandardLcgWithShuffle @@ -58,6 +58,6 @@ class MinimalStandardLcgWithShuffle { double mixing_table_[kTableSize]; //!< Mixing table }; -} // namespace randomization +} // namespace s2e::randomization #endif // S2E_LIBRARY_RANDOMIZATION_MINIMAL_STANDARD_LINEAR_CONGRUENTIAL_GENERATOR_WITH_SHUFFLE_HPP_ diff --git a/src/math_physics/randomization/normal_randomization.cpp b/src/math_physics/randomization/normal_randomization.cpp index 0e5c9e36c..b136700cb 100644 --- a/src/math_physics/randomization/normal_randomization.cpp +++ b/src/math_physics/randomization/normal_randomization.cpp @@ -4,7 +4,7 @@ * @note Ref: NUMERICAL RECIPES in C, p.216-p.217 */ #include "normal_randomization.hpp" -using randomization::NormalRand; +using s2e::randomization::NormalRand; #include //DBL_EPSILON #include //sqrt, log; diff --git a/src/math_physics/randomization/normal_randomization.hpp b/src/math_physics/randomization/normal_randomization.hpp index 81e688091..b230680a3 100644 --- a/src/math_physics/randomization/normal_randomization.hpp +++ b/src/math_physics/randomization/normal_randomization.hpp @@ -8,9 +8,9 @@ #define S2E_LIBRARY_RANDOMIZATION_NORMAL_RANDOMIZATION_HPP_ #include "minimal_standard_linear_congruential_generator_with_shuffle.hpp" -using randomization::MinimalStandardLcgWithShuffle; +using s2e::randomization::MinimalStandardLcgWithShuffle; -namespace randomization { +namespace s2e::randomization { /** * @class NormalRand @@ -106,6 +106,6 @@ class NormalRand { bool is_empty_; //!< Flag to show the holder_ has available value }; -} // namespace randomization +} // namespace s2e::randomization #endif // S2E_LIBRARY_RANDOMIZATION_NORMAL_RANDOMIZATION_HPP_ diff --git a/src/math_physics/randomization/random_walk.hpp b/src/math_physics/randomization/random_walk.hpp index ecd269001..aed70512b 100644 --- a/src/math_physics/randomization/random_walk.hpp +++ b/src/math_physics/randomization/random_walk.hpp @@ -10,6 +10,8 @@ #include "../math/vector.hpp" #include "./normal_randomization.hpp" +namespace s2e::randomization { + /** * @class RandomWalk * @brief Class to calculate random wark value @@ -36,10 +38,12 @@ class RandomWalk : public math::OrdinaryDifferentialEquation { virtual void DerivativeFunction(double x, const math::Vector& state, math::Vector& rhs); private: - math::Vector limit_; //!< Limit of random walk - randomization::NormalRand normal_randomizer_[N]; //!< Random walk excitation noise + math::Vector limit_; //!< Limit of random walk + NormalRand normal_randomizer_[N]; //!< Random walk excitation noise }; +} // namespace s2e::randomization + #include "random_walk_template_functions.hpp" // template function definisions. #endif // S2E_LIBRARY_RANDOMIZATION_RANDOM_WALK_HPP_ \ No newline at end of file diff --git a/src/math_physics/randomization/random_walk_template_functions.hpp b/src/math_physics/randomization/random_walk_template_functions.hpp index c316a3aab..1f782b7cb 100644 --- a/src/math_physics/randomization/random_walk_template_functions.hpp +++ b/src/math_physics/randomization/random_walk_template_functions.hpp @@ -9,12 +9,14 @@ #include #include +namespace s2e::randomization { + template RandomWalk::RandomWalk(double step_width_s, const math::Vector& standard_deviation, const math::Vector& limit) : math::OrdinaryDifferentialEquation(step_width_s), limit_(limit) { // Set standard deviation for (size_t i = 0; i < N; ++i) { - normal_randomizer_[i].SetParameters(0.0, standard_deviation[i], global_randomization.MakeSeed()); + normal_randomizer_[i].SetParameters(0.0, standard_deviation[i], s2e::randomization::global_randomization.MakeSeed()); } } @@ -32,4 +34,6 @@ void RandomWalk::DerivativeFunction(double x, const math::Vector& state, m } } +} // namespace s2e::randomization + #endif // S2E_LIBRARY_RANDOMIZATION_RANDOM_WALK_TEMPLATE_FUNCTIONS_HPP_ diff --git a/src/math_physics/time_system/date_time_format.cpp b/src/math_physics/time_system/date_time_format.cpp index 069c7247f..d470bfef5 100644 --- a/src/math_physics/time_system/date_time_format.cpp +++ b/src/math_physics/time_system/date_time_format.cpp @@ -11,7 +11,7 @@ #include #include -namespace time_system { +namespace s2e::time_system { DateTime::DateTime(const std::string date_time) { sscanf(date_time.c_str(), "%zu/%zu/%zu %zu:%zu:%lf", &year_, &month_, &day_, &hour_, &minute_, &second_); @@ -55,4 +55,4 @@ std::string DateTime::GetAsString() const { return output; } -} // namespace time_system +} // namespace s2e::time_system diff --git a/src/math_physics/time_system/date_time_format.hpp b/src/math_physics/time_system/date_time_format.hpp index 25084e979..540c6fefa 100644 --- a/src/math_physics/time_system/date_time_format.hpp +++ b/src/math_physics/time_system/date_time_format.hpp @@ -10,7 +10,7 @@ #include "epoch_time.hpp" -namespace time_system { +namespace s2e::time_system { class EpochTime; @@ -62,6 +62,6 @@ class DateTime { double second_; //!< Second [0.0, 60.0) }; -} // namespace time_system +} // namespace s2e::time_system #endif // S2E_LIBRARY_TIME_SYSTEM_DATE_TIME_FORMAT_HPP_ diff --git a/src/math_physics/time_system/epoch_time.cpp b/src/math_physics/time_system/epoch_time.cpp index b3b6ec730..cee1a4068 100644 --- a/src/math_physics/time_system/epoch_time.cpp +++ b/src/math_physics/time_system/epoch_time.cpp @@ -7,7 +7,7 @@ #include -namespace time_system { +namespace s2e::time_system { EpochTime::EpochTime(const DateTime date_time) { // No leap second calculation @@ -76,4 +76,4 @@ EpochTime EpochTime::operator-(const EpochTime& right_side) const { return result; } -} // namespace time_system +} // namespace s2e::time_system diff --git a/src/math_physics/time_system/epoch_time.hpp b/src/math_physics/time_system/epoch_time.hpp index 7f7dfe871..72723c066 100644 --- a/src/math_physics/time_system/epoch_time.hpp +++ b/src/math_physics/time_system/epoch_time.hpp @@ -10,7 +10,7 @@ #include "date_time_format.hpp" -namespace time_system { +namespace s2e::time_system { class DateTime; @@ -69,6 +69,6 @@ class EpochTime { double fraction_s_; //!< Fraction of second under 1 sec [0, 1) }; -} // namespace time_system +} // namespace s2e::time_system #endif // S2E_LIBRARY_TIME_SYSTEM_EPOCH_TIME_HPP_ diff --git a/src/math_physics/time_system/gps_time.cpp b/src/math_physics/time_system/gps_time.cpp index cb3a5fec9..5bed94290 100644 --- a/src/math_physics/time_system/gps_time.cpp +++ b/src/math_physics/time_system/gps_time.cpp @@ -5,7 +5,7 @@ #include "gps_time.hpp" -namespace time_system { +namespace s2e::time_system { const DateTime GpsTime::kEpochOfGpsTimeInDateTime_ = DateTime("1980/1/6 00:00:00.0"); const EpochTime GpsTime::kEpochOfGpsTimeInEpochTime_ = EpochTime(kEpochOfGpsTimeInDateTime_); @@ -26,4 +26,4 @@ void GpsTime::CalcEpochTime() { epoch_time_ = kEpochOfGpsTimeInEpochTime_ + time_diff; } -} // namespace time_system +} // namespace s2e::time_system diff --git a/src/math_physics/time_system/gps_time.hpp b/src/math_physics/time_system/gps_time.hpp index f86242754..fdc42d5a8 100644 --- a/src/math_physics/time_system/gps_time.hpp +++ b/src/math_physics/time_system/gps_time.hpp @@ -11,7 +11,7 @@ #include "date_time_format.hpp" #include "epoch_time.hpp" -namespace time_system { +namespace s2e::time_system { /** * @class GpsTime @@ -97,6 +97,6 @@ class GpsTime { void CalcEpochTime(); }; -} // namespace time_system +} // namespace s2e::time_system #endif // S2E_LIBRARY_TIME_SYSTEM_GPS_TIME_HPP_ diff --git a/src/math_physics/time_system/test_date_time_format.cpp b/src/math_physics/time_system/test_date_time_format.cpp index 4ac1a3840..935e92776 100644 --- a/src/math_physics/time_system/test_date_time_format.cpp +++ b/src/math_physics/time_system/test_date_time_format.cpp @@ -2,7 +2,7 @@ #include "date_time_format.hpp" -using namespace time_system; +using namespace s2e::time_system; /** * @brief Test Constructor with value diff --git a/src/math_physics/time_system/test_epoch_time.cpp b/src/math_physics/time_system/test_epoch_time.cpp index 6cb5f0c1b..e1281ca11 100644 --- a/src/math_physics/time_system/test_epoch_time.cpp +++ b/src/math_physics/time_system/test_epoch_time.cpp @@ -3,7 +3,7 @@ #include "date_time_format.hpp" #include "epoch_time.hpp" -using namespace time_system; +using namespace s2e::time_system; TEST(EpochTime, ConstructorNominal) { EpochTime time(1000000000, 0.250); diff --git a/src/math_physics/time_system/test_gps_time.cpp b/src/math_physics/time_system/test_gps_time.cpp index 425556774..737d2f7c6 100644 --- a/src/math_physics/time_system/test_gps_time.cpp +++ b/src/math_physics/time_system/test_gps_time.cpp @@ -2,7 +2,7 @@ #include "gps_time.hpp" -using namespace time_system; +using namespace s2e::time_system; /** * @brief Test Constructor diff --git a/src/s2e.cpp b/src/s2e.cpp index 960452763..f0d19356e 100644 --- a/src/s2e.cpp +++ b/src/s2e.cpp @@ -69,7 +69,7 @@ int main(int argc, char *argv[]) std::cout << "\tIni file: "; print_path(ini_file); - auto simulation_case = SampleCase(ini_file); + auto simulation_case = s2e::sample::SampleCase(ini_file); simulation_case.Initialize(); simulation_case.Main(); diff --git a/src/setting_file_reader/c2a_command_database.cpp b/src/setting_file_reader/c2a_command_database.cpp index 650c11cf5..7811b36ee 100644 --- a/src/setting_file_reader/c2a_command_database.cpp +++ b/src/setting_file_reader/c2a_command_database.cpp @@ -11,6 +11,8 @@ #include #include +namespace s2e::setting_file_reader { + C2aCommandInformation::C2aCommandInformation(const std::string cmd_db_line) { if (cmd_db_line.find("*") == 0) return; if (cmd_db_line.find(",") != 0) return; @@ -93,61 +95,61 @@ void DecodeC2aCommandArgument(const C2aArgumentType type, const std::string argu case C2aArgumentType::kUint8t: { size_param = 1; uint8_t argument = (uint8_t)std::stoul(argument_string); // TODO: 範囲外処理 - endian_memcpy(param, &argument, size_param); + utilities::endian_memcpy(param, &argument, size_param); break; } case C2aArgumentType::kUint16t: { size_param = 2; uint16_t argument = (uint16_t)std::stoul(argument_string); // TODO: 範囲外処理 - endian_memcpy(param, &argument, size_param); + utilities::endian_memcpy(param, &argument, size_param); break; } case C2aArgumentType::kUint32t: { size_param = 4; uint32_t argument = (uint32_t)std::stoul(argument_string); // TODO: 範囲外処理 - endian_memcpy(param, &argument, size_param); + utilities::endian_memcpy(param, &argument, size_param); break; } case C2aArgumentType::kUint64t: { size_param = 8; uint64_t argument = std::stoul(argument_string); - endian_memcpy(param, &argument, size_param); + utilities::endian_memcpy(param, &argument, size_param); break; } case C2aArgumentType::kInt8t: { size_param = 1; int8_t argument = (int8_t)std::stoi(argument_string); // TODO: 範囲外処理 - endian_memcpy(param, &argument, size_param); + utilities::endian_memcpy(param, &argument, size_param); break; } case C2aArgumentType::kInt16t: { size_param = 2; int16_t argument = (int16_t)std::stoi(argument_string); // TODO: 範囲外処理 - endian_memcpy(param, &argument, size_param); + utilities::endian_memcpy(param, &argument, size_param); break; } case C2aArgumentType::kInt32t: { size_param = 4; int32_t argument = std::stoi(argument_string); - endian_memcpy(param, &argument, size_param); + utilities::endian_memcpy(param, &argument, size_param); break; } case C2aArgumentType::kInt64t: { size_param = 8; int64_t argument = std::stol(argument_string); - endian_memcpy(param, &argument, size_param); + utilities::endian_memcpy(param, &argument, size_param); break; } case C2aArgumentType::kFloat: { size_param = 4; float argument = std::stof(argument_string); - endian_memcpy(param, &argument, size_param); + utilities::endian_memcpy(param, &argument, size_param); break; } case C2aArgumentType::kDouble: { size_param = 8; double argument = std::stod(argument_string); - endian_memcpy(param, &argument, size_param); + utilities::endian_memcpy(param, &argument, size_param); break; } case C2aArgumentType::kRaw: { @@ -158,3 +160,5 @@ void DecodeC2aCommandArgument(const C2aArgumentType type, const std::string argu break; } } + +} // namespace s2e::setting_file_reader diff --git a/src/setting_file_reader/c2a_command_database.hpp b/src/setting_file_reader/c2a_command_database.hpp index 9fd2e9125..f8905f49a 100644 --- a/src/setting_file_reader/c2a_command_database.hpp +++ b/src/setting_file_reader/c2a_command_database.hpp @@ -12,6 +12,8 @@ #include #include +namespace s2e::setting_file_reader { + /** * @enum C2aArgumentType * @brief Argument type used in C2A command @@ -115,4 +117,6 @@ class C2aCommandDatabase { */ void DecodeC2aCommandArgument(const C2aArgumentType type, const std::string argument_string, uint8_t* param, size_t& size_param); +} // namespace s2e::setting_file_reader + #endif // S2E_LIBRARY_INITIALIZE_C2A_COMMAND_DATABASE_HPP_ diff --git a/src/setting_file_reader/initialize_file_access.cpp b/src/setting_file_reader/initialize_file_access.cpp index e25f89583..187b55998 100644 --- a/src/setting_file_reader/initialize_file_access.cpp +++ b/src/setting_file_reader/initialize_file_access.cpp @@ -14,6 +14,8 @@ #include "../utilities/macros.hpp" +namespace s2e::setting_file_reader { + #ifdef WIN32 IniAccess::IniAccess(const std::string file_path) : file_path_(file_path) { // strcpy_s(file_path_char_, (size_t)_countof(file_path_char_), file_path_.c_str()); @@ -283,3 +285,5 @@ void IniAccess::ReadCsvString(std::vector>& output_valu output_value.push_back(temp); } } + +} // namespace s2e::setting_file_reader diff --git a/src/setting_file_reader/initialize_file_access.hpp b/src/setting_file_reader/initialize_file_access.hpp index df49969ce..e63cd424f 100644 --- a/src/setting_file_reader/initialize_file_access.hpp +++ b/src/setting_file_reader/initialize_file_access.hpp @@ -27,6 +27,8 @@ #include #include +namespace s2e::setting_file_reader { + /** * @class IniAccess * @brief Class to read and get parameters for the `ini` format file @@ -216,4 +218,6 @@ void IniAccess::ReadVector(const char* section_name, const char* key_name, math: } } +} // namespace s2e::setting_file_reader + #endif // S2E_LIBRARY_INITIALIZE_INITIALIZE_FILE_ACCESS_HPP_ diff --git a/src/setting_file_reader/wings_operation_file.cpp b/src/setting_file_reader/wings_operation_file.cpp index 628c22fcf..78efa4d9d 100644 --- a/src/setting_file_reader/wings_operation_file.cpp +++ b/src/setting_file_reader/wings_operation_file.cpp @@ -7,6 +7,8 @@ #include +namespace s2e::setting_file_reader { + WingsOperationFile::WingsOperationFile(const std::string file_path) { // File open std::ifstream file(file_path); @@ -45,3 +47,5 @@ std::string WingsOperationFile::GetLatestLine() { return line; } + +} // namespace s2e::setting_file_reader diff --git a/src/setting_file_reader/wings_operation_file.hpp b/src/setting_file_reader/wings_operation_file.hpp index 11cb2a9b0..51ed0d1d5 100644 --- a/src/setting_file_reader/wings_operation_file.hpp +++ b/src/setting_file_reader/wings_operation_file.hpp @@ -11,6 +11,8 @@ #include "c2a_command_database.hpp" +namespace s2e::setting_file_reader { + /** * @class WingsOperationFile * @brief A class to handle WINGS operation file @@ -35,4 +37,6 @@ class WingsOperationFile { size_t line_pointer_ = 0; //!< Line pointer }; +} // namespace s2e::setting_file_reader + #endif // S2E_LIBRARY_INITIALIZE_WINGS_OPERATION_FILE_HPP_ diff --git a/src/simulation/case/simulation_case.cpp b/src/simulation/case/simulation_case.cpp index 1a19dd003..e8cfb56e6 100644 --- a/src/simulation/case/simulation_case.cpp +++ b/src/simulation/case/simulation_case.cpp @@ -9,9 +9,11 @@ #include #include +namespace s2e::simulation { + SimulationCase::SimulationCase(const std::string initialize_base_file) { // Initialize Log - simulation_configuration_.main_logger_ = InitLog(initialize_base_file); + simulation_configuration_.main_logger_ = logger::InitLog(initialize_base_file); // Initialize Simulation Configuration InitializeSimulationConfiguration(initialize_base_file); @@ -21,16 +23,16 @@ SimulationCase::SimulationCase(const std::string initialize_base_file, const Mon const std::string log_path) { if (monte_carlo_simulator.IsEnabled() == false) { // Monte Carlo simulation is disabled - simulation_configuration_.main_logger_ = InitLog(initialize_base_file); + simulation_configuration_.main_logger_ = logger::InitLog(initialize_base_file); } else { // Monte Carlo Simulation is enabled std::string log_file_name = "default" + std::to_string(monte_carlo_simulator.GetNumberOfExecutionsDone()) + ".csv"; - IniAccess ini_file(initialize_base_file); + setting_file_reader::IniAccess ini_file(initialize_base_file); bool save_ini_files = ini_file.ReadEnable("SIMULATION_SETTINGS", "save_initialize_files"); simulation_configuration_.main_logger_ = - new Logger(log_file_name, log_path, initialize_base_file, save_ini_files, monte_carlo_simulator.GetSaveLogHistoryFlag()); + new logger::Logger(log_file_name, log_path, initialize_base_file, save_ini_files, monte_carlo_simulator.GetSaveLogHistoryFlag()); } // Initialize Simulation Configuration InitializeSimulationConfiguration(initialize_base_file); @@ -85,7 +87,7 @@ std::string SimulationCase::GetLogValue() const { void SimulationCase::InitializeSimulationConfiguration(const std::string initialize_base_file) { // Initialize - IniAccess simulation_base_ini = IniAccess(initialize_base_file); + setting_file_reader::IniAccess simulation_base_ini = setting_file_reader::IniAccess(initialize_base_file); const char* section = "SIMULATION_SETTINGS"; simulation_configuration_.initialize_base_file_name_ = initialize_base_file; @@ -102,6 +104,8 @@ void SimulationCase::InitializeSimulationConfiguration(const std::string initial simulation_configuration_.gnss_file_ = simulation_base_ini.ReadString(section, "gnss_file"); // Global Environment - global_environment_ = new GlobalEnvironment(&simulation_configuration_); + global_environment_ = new environment::GlobalEnvironment(&simulation_configuration_); global_environment_->LogSetup(*(simulation_configuration_.main_logger_)); -} \ No newline at end of file +} + +} // namespace s2e::simulation diff --git a/src/simulation/case/simulation_case.hpp b/src/simulation/case/simulation_case.hpp index 68f73f66c..26f012dc4 100644 --- a/src/simulation/case/simulation_case.hpp +++ b/src/simulation/case/simulation_case.hpp @@ -13,11 +13,13 @@ #include "../simulation_configuration.hpp" class Logger; +namespace s2e::simulation { + /** * @class SimulationCase * @brief Base class to define simulation scenario */ -class SimulationCase : public ILoggable { +class SimulationCase : public logger::ILoggable { public: /** * @fn SimulationCase @@ -72,11 +74,11 @@ class SimulationCase : public ILoggable { * @fn GetGlobalEnvironment * @brief Return global environment */ - inline const GlobalEnvironment& GetGlobalEnvironment() const { return *global_environment_; } + inline const environment::GlobalEnvironment& GetGlobalEnvironment() const { return *global_environment_; } protected: - SimulationConfiguration simulation_configuration_; //!< Simulation setting - GlobalEnvironment* global_environment_; //!< Global Environment + SimulationConfiguration simulation_configuration_; //!< Simulation setting + environment::GlobalEnvironment* global_environment_; //!< Global Environment /** * @fn InitializeSimulationConfiguration @@ -98,4 +100,6 @@ class SimulationCase : public ILoggable { virtual void UpdateTargetObjects() = 0; }; +} // namespace s2e::simulation + #endif // S2E_SIMULATION_CASE_SIMULATION_CASE_HPP_ diff --git a/src/simulation/ground_station/ground_station.cpp b/src/simulation/ground_station/ground_station.cpp index 2f9483f2c..2c06c7b4c 100644 --- a/src/simulation/ground_station/ground_station.cpp +++ b/src/simulation/ground_station/ground_station.cpp @@ -13,7 +13,9 @@ #include #include -GroundStation::GroundStation(const SimulationConfiguration* configuration, const unsigned int ground_station_id) +namespace s2e::ground_station { + +GroundStation::GroundStation(const simulation::SimulationConfiguration* configuration, const unsigned int ground_station_id) : ground_station_id_(ground_station_id) { Initialize(configuration, ground_station_id_); number_of_spacecraft_ = configuration->number_of_simulated_spacecraft_; @@ -24,9 +26,9 @@ GroundStation::GroundStation(const SimulationConfiguration* configuration, const GroundStation::~GroundStation() {} -void GroundStation::Initialize(const SimulationConfiguration* configuration, const unsigned int ground_station_id) { +void GroundStation::Initialize(const simulation::SimulationConfiguration* configuration, const unsigned int ground_station_id) { std::string gs_ini_path = configuration->ground_station_file_list_[0]; - auto conf = IniAccess(gs_ini_path); + auto conf = setting_file_reader::IniAccess(gs_ini_path); const char* section_base = "GROUND_STATION_"; const std::string section_tmp = section_base + std::to_string(static_cast(ground_station_id)); @@ -43,9 +45,9 @@ void GroundStation::Initialize(const SimulationConfiguration* configuration, con configuration->main_logger_->CopyFileToLogDirectory(gs_ini_path); } -void GroundStation::LogSetup(Logger& logger) { logger.AddLogList(this); } +void GroundStation::LogSetup(logger::Logger& logger) { logger.AddLogList(this); } -void GroundStation::Update(const EarthRotation& celestial_rotation, const Spacecraft& spacecraft) { +void GroundStation::Update(const environment::EarthRotation& celestial_rotation, const spacecraft::Spacecraft& spacecraft) { math::Matrix<3, 3> dcm_ecef2eci = celestial_rotation.GetDcmJ2000ToEcef().Transpose(); position_i_m_ = dcm_ecef2eci * position_ecef_m_; @@ -75,9 +77,9 @@ std::string GroundStation::GetLogHeader() const { std::string head = "ground_station" + std::to_string(ground_station_id_) + "_"; for (unsigned int i = 0; i < number_of_spacecraft_; i++) { std::string legend = head + "sc" + std::to_string(i) + "_visible_flag"; - str_tmp += WriteScalar(legend); + str_tmp += logger::WriteScalar(legend); } - str_tmp += WriteVector("ground_station_position", "eci", "m", 3); + str_tmp += logger::WriteVector("ground_station_position", "eci", "m", 3); return str_tmp; } @@ -85,8 +87,10 @@ std::string GroundStation::GetLogValue() const { std::string str_tmp = ""; for (unsigned int i = 0; i < number_of_spacecraft_; i++) { - str_tmp += WriteScalar(is_visible_.at(i)); + str_tmp += logger::WriteScalar(is_visible_.at(i)); } - str_tmp += WriteVector(position_i_m_); + str_tmp += logger::WriteVector(position_i_m_); return str_tmp; } + +} // namespace s2e::ground_station diff --git a/src/simulation/ground_station/ground_station.hpp b/src/simulation/ground_station/ground_station.hpp index 41a051d58..866b31edf 100644 --- a/src/simulation/ground_station/ground_station.hpp +++ b/src/simulation/ground_station/ground_station.hpp @@ -12,17 +12,19 @@ #include "../simulation_configuration.hpp" +namespace s2e::ground_station { + /** * @class GroundStation * @brief Base class of ground station */ -class GroundStation : public ILoggable { +class GroundStation : public logger::ILoggable { public: /** * @fn GroundStation * @brief Constructor */ - GroundStation(const SimulationConfiguration* configuration, const unsigned int ground_station_id_); + GroundStation(const simulation::SimulationConfiguration* configuration, const unsigned int ground_station_id_); /** * @fn ~GroundStation * @brief Destructor @@ -33,17 +35,17 @@ class GroundStation : public ILoggable { * @fn Initialize * @brief Virtual function to initialize the ground station */ - virtual void Initialize(const SimulationConfiguration* configuration, const unsigned int ground_station_id); + virtual void Initialize(const simulation::SimulationConfiguration* configuration, const unsigned int ground_station_id); /** * @fn LogSetup * @brief Virtual function to log output setting for ground station related components */ - virtual void LogSetup(Logger& logger); + virtual void LogSetup(logger::Logger& logger); /** * @fn Update * @brief Virtual function of main routine */ - virtual void Update(const EarthRotation& celestial_rotation, const Spacecraft& spacecraft); + virtual void Update(const environment::EarthRotation& celestial_rotation, const spacecraft::Spacecraft& spacecraft); // Override functions for ILoggable /** @@ -72,12 +74,12 @@ class GroundStation : public ILoggable { * @fn GetPosition_ecef_m * @brief Return ground station position in the ECEF frame [m] */ - Vector<3> GetPosition_ecef_m() const { return position_ecef_m_; } + math::Vector<3> GetPosition_ecef_m() const { return position_ecef_m_; } /** * @fn GetPosition_i_m * @brief Return ground station position in the inertial frame [m] */ - Vector<3> GetPosition_i_m() const { return position_i_m_; } + math::Vector<3> GetPosition_i_m() const { return position_i_m_; } /** * @fn GetElevationLimitAngle_deg * @brief Return ground station elevation limit angle [deg] @@ -93,8 +95,8 @@ class GroundStation : public ILoggable { protected: unsigned int ground_station_id_; //!< Ground station ID geodesy::GeodeticPosition geodetic_position_; //!< Ground Station Position in the geodetic frame - Vector<3> position_ecef_m_{0.0}; //!< Ground Station Position in the ECEF frame [m] - Vector<3> position_i_m_{0.0}; //!< Ground Station Position in the inertial frame [m] + math::Vector<3> position_ecef_m_{0.0}; //!< Ground Station Position in the ECEF frame [m] + math::Vector<3> position_i_m_{0.0}; //!< Ground Station Position in the inertial frame [m] double elevation_limit_angle_deg_; //!< Minimum elevation angle to work the ground station [deg] std::map is_visible_; //!< Visible flag for each spacecraft ID (not care antenna) @@ -106,7 +108,9 @@ class GroundStation : public ILoggable { * @param [in] spacecraft_position_ecef_m: spacecraft position in ECEF frame [m] * @return True when the satellite is visible from the ground station */ - bool CalcIsVisible(const Vector<3> spacecraft_position_ecef_m); + bool CalcIsVisible(const math::Vector<3> spacecraft_position_ecef_m); }; +} // namespace s2e::ground_station + #endif // S2E_SIMULATION_GROUND_STATION_GROUND_STATION_HPP_ diff --git a/src/simulation/hils/hils_port_manager.cpp b/src/simulation/hils/hils_port_manager.cpp index 40e4d36fe..8f68bff4f 100644 --- a/src/simulation/hils/hils_port_manager.cpp +++ b/src/simulation/hils/hils_port_manager.cpp @@ -7,6 +7,8 @@ #include +namespace s2e::simulation { + // #define HILS_PORT_MANAGER_SHOW_DEBUG_DATA HilsPortManager::HilsPortManager() {} @@ -45,7 +47,7 @@ int HilsPortManager::UartCloseComPort(unsigned int port_id) { } uart_ports_[port_id]->ClosePort(); - HilsUartPort* port = uart_ports_.at(port_id); + components::HilsUartPort* port = uart_ports_.at(port_id); delete port; uart_ports_.erase(port_id); return 0; @@ -58,7 +60,7 @@ int HilsPortManager::UartCloseComPort(unsigned int port_id) { int HilsPortManager::UartReceive(unsigned int port_id, unsigned char* buffer, int offset, int length) { #ifdef USE_HILS - HilsUartPort* port = uart_ports_[port_id]; + components::HilsUartPort* port = uart_ports_[port_id]; if (port == nullptr) return -1; int ret = port->ReadRx(buffer, offset, length); #ifdef HILS_PORT_MANAGER_SHOW_DEBUG_DATA @@ -83,7 +85,7 @@ int HilsPortManager::UartReceive(unsigned int port_id, unsigned char* buffer, in int HilsPortManager::UartSend(unsigned int port_id, const unsigned char* buffer, int offset, int length) { #ifdef USE_HILS - HilsUartPort* port = uart_ports_[port_id]; + components::HilsUartPort* port = uart_ports_[port_id]; if (port == nullptr) return -1; int ret = port->WriteTx(buffer, offset, length); #ifdef HILS_PORT_MANAGER_SHOW_DEBUG_DATA @@ -130,7 +132,7 @@ int HilsPortManager::I2cTargetCloseComPort(unsigned int port_id) { return -1; } i2c_ports_[port_id]->ClosePort(); - HilsI2cTargetPort* port = i2c_ports_.at(port_id); + components::HilsI2cTargetPort* port = i2c_ports_.at(port_id); delete port; i2c_ports_.erase(port_id); return 0; @@ -144,7 +146,7 @@ int HilsPortManager::I2cTargetCloseComPort(unsigned int port_id) { int HilsPortManager::I2cTargetWriteRegister(unsigned int port_id, const unsigned char register_address, const unsigned char* data, const unsigned char length) { #ifdef USE_HILS - HilsI2cTargetPort* port = i2c_ports_[port_id]; + components::HilsI2cTargetPort* port = i2c_ports_[port_id]; if (port == nullptr) return -1; for (unsigned char i = 0; i < length; i++) { port->WriteRegister(register_address + i, data[i]); @@ -163,7 +165,7 @@ int HilsPortManager::I2cTargetWriteRegister(unsigned int port_id, const unsigned int HilsPortManager::I2cTargetReadRegister(unsigned int port_id, const unsigned char register_address, unsigned char* data, const unsigned char length) { #ifdef USE_HILS - HilsI2cTargetPort* port = i2c_ports_[port_id]; + components::HilsI2cTargetPort* port = i2c_ports_[port_id]; if (port == nullptr) return -1; for (unsigned char i = 0; i < length; i++) { data[i] = port->ReadRegister(register_address + i); @@ -181,7 +183,7 @@ int HilsPortManager::I2cTargetReadRegister(unsigned int port_id, const unsigned int HilsPortManager::I2cTargetReadCommand(unsigned int port_id, unsigned char* data, const unsigned char length) { #ifdef USE_HILS - HilsI2cTargetPort* port = i2c_ports_[port_id]; + components::HilsI2cTargetPort* port = i2c_ports_[port_id]; if (port == nullptr) return -1; port->ReadCommand(data, length); return 0; @@ -196,7 +198,7 @@ int HilsPortManager::I2cTargetReadCommand(unsigned int port_id, unsigned char* d int HilsPortManager::I2cTargetReceive(unsigned int port_id) { #ifdef USE_HILS - HilsI2cTargetPort* port = i2c_ports_[port_id]; + components::HilsI2cTargetPort* port = i2c_ports_[port_id]; if (port == nullptr) return -1; int ret = port->Receive(); #ifdef HILS_PORT_MANAGER_SHOW_DEBUG_DATA @@ -214,7 +216,7 @@ int HilsPortManager::I2cTargetReceive(unsigned int port_id) { int HilsPortManager::I2cTargetSend(unsigned int port_id, const unsigned char length) { #ifdef USE_HILS - HilsI2cTargetPort* port = i2c_ports_[port_id]; + components::HilsI2cTargetPort* port = i2c_ports_[port_id]; if (port == nullptr) return -1; int ret = port->Send(length); #ifdef HILS_PORT_MANAGER_SHOW_DEBUG_DATA @@ -233,7 +235,7 @@ int HilsPortManager::I2cTargetSend(unsigned int port_id, const unsigned char len int HilsPortManager::I2cTargetGetStoredFrameCounter(unsigned int port_id) { #ifdef USE_HILS - HilsI2cTargetPort* port = i2c_ports_[port_id]; + components::HilsI2cTargetPort* port = i2c_ports_[port_id]; if (port == nullptr) return -1; return port->GetStoredFrameCounter(); #else @@ -258,3 +260,5 @@ int HilsPortManager::I2cControllerReceive(unsigned int port_id, unsigned char* b int HilsPortManager::I2cControllerSend(unsigned int port_id, const unsigned char* buffer, int offset, int length) { return UartSend(port_id, buffer, offset, length); } + +} // namespace s2e::simulation diff --git a/src/simulation/hils/hils_port_manager.hpp b/src/simulation/hils/hils_port_manager.hpp index 9fbeaf2c7..cd04dc173 100644 --- a/src/simulation/hils/hils_port_manager.hpp +++ b/src/simulation/hils/hils_port_manager.hpp @@ -12,6 +12,8 @@ #endif #include +namespace s2e::simulation { + /** * @class HilsPortManager * @brief Class to manage COM ports for HILS test @@ -163,9 +165,11 @@ class HilsPortManager { private: #ifdef USE_HILS - std::map uart_ports_; //!< UART ports - std::map i2c_ports_; //!< I2C ports + std::map uart_ports_; //!< UART ports + std::map i2c_ports_; //!< I2C ports #endif }; +} // namespace s2e::simulation + #endif // S2E_SIMULATION_HILS_HILS_PORT_MANAGER_HPP_ diff --git a/src/simulation/monte_carlo_simulation/initialize_monte_carlo_parameters.cpp b/src/simulation/monte_carlo_simulation/initialize_monte_carlo_parameters.cpp index 44d6c211a..967b92b1d 100644 --- a/src/simulation/monte_carlo_simulation/initialize_monte_carlo_parameters.cpp +++ b/src/simulation/monte_carlo_simulation/initialize_monte_carlo_parameters.cpp @@ -9,6 +9,8 @@ using namespace std; +namespace s2e::simulation { + random_device InitializedMonteCarloParameters::randomizer_; mt19937 InitializedMonteCarloParameters::mt_; uniform_real_distribution<>* InitializedMonteCarloParameters::uniform_distribution_; @@ -315,3 +317,5 @@ void InitializedMonteCarloParameters::GenerateQuaternionNormal() { randomized_value_.push_back(temp_q[i]); } } + +} // namespace s2e::simulation diff --git a/src/simulation/monte_carlo_simulation/initialize_monte_carlo_parameters.hpp b/src/simulation/monte_carlo_simulation/initialize_monte_carlo_parameters.hpp index 534650c04..e4bc3469f 100644 --- a/src/simulation/monte_carlo_simulation/initialize_monte_carlo_parameters.hpp +++ b/src/simulation/monte_carlo_simulation/initialize_monte_carlo_parameters.hpp @@ -13,6 +13,8 @@ #include #include +namespace s2e::simulation { + /** * @class InitializedMonteCarloParameters * @brief Initialized parameters for Monte-Carlo simulation @@ -31,7 +33,7 @@ class InitializedMonteCarloParameters { kCircularNormalNormal, //!< r and θ follow normal distribution in Circular frame kSphericalNormalUniformUniform, //!< r follows normal distribution, and θ and φ follow uniform distribution in Spherical frame kSphericalNormalNormal, //!< r and θ follow normal distribution, and mean vector angle φ follows uniform distribution [0,2*pi] - kQuaternionUniform, //!< Perfectly Randomized math::Quaternion + kQuaternionUniform, //!< Perfectly Randomized Quaternion kQuaternionNormal, //!< Angle from the default quaternion θ follows normal distribution }; @@ -232,4 +234,6 @@ void InitializedMonteCarloParameters::GetRandomizedVector(math::Vector #include +namespace s2e::simulation { + #define MAX_CHAR_NUM 256 MonteCarloSimulationExecutor* InitMonteCarloSimulation(std::string file_name) { - IniAccess ini_file(file_name); + setting_file_reader::IniAccess ini_file(file_name); const char* section = "MONTE_CARLO_EXECUTION"; unsigned long long total_num_of_executions = ini_file.ReadInt(section, "number_of_executions"); @@ -93,3 +95,5 @@ MonteCarloSimulationExecutor* InitMonteCarloSimulation(std::string file_name) { return monte_carlo_simulator; } + +} // namespace s2e::simulation diff --git a/src/simulation/monte_carlo_simulation/initialize_monte_carlo_simulation.hpp b/src/simulation/monte_carlo_simulation/initialize_monte_carlo_simulation.hpp index e4dcd60a2..6620467ac 100644 --- a/src/simulation/monte_carlo_simulation/initialize_monte_carlo_simulation.hpp +++ b/src/simulation/monte_carlo_simulation/initialize_monte_carlo_simulation.hpp @@ -9,10 +9,14 @@ #include "initialize_monte_carlo_parameters.hpp" #include "monte_carlo_simulation_executor.hpp" +namespace s2e::simulation { + /** * @fn InitMonteCarloSimulation * @brief Initialize function for Monte-Carlo Simulator */ MonteCarloSimulationExecutor* InitMonteCarloSimulation(std::string file_name); +} // namespace s2e::simulation + #endif // S2E_SIMULATION_MONTE_CARLO_SIMULATION_INITIALIZE_MONTE_CARLO_SIMULATION_HPP_ diff --git a/src/simulation/monte_carlo_simulation/monte_carlo_simulation_executor.cpp b/src/simulation/monte_carlo_simulation/monte_carlo_simulation_executor.cpp index dead43808..6279a3b08 100644 --- a/src/simulation/monte_carlo_simulation/monte_carlo_simulation_executor.cpp +++ b/src/simulation/monte_carlo_simulation/monte_carlo_simulation_executor.cpp @@ -7,6 +7,8 @@ using std::string; +namespace s2e::simulation { + MonteCarloSimulationExecutor::MonteCarloSimulationExecutor(unsigned long long total_num_of_executions) : total_number_of_executions_(total_num_of_executions) { number_of_executions_done_ = 0; @@ -69,3 +71,5 @@ void MonteCarloSimulationExecutor::RandomizeAllParameters() { void MonteCarloSimulationExecutor::SetSeed(unsigned long seed, bool is_deterministic) { InitializedMonteCarloParameters::SetSeed(seed, is_deterministic); } + +} // namespace s2e::simulation diff --git a/src/simulation/monte_carlo_simulation/monte_carlo_simulation_executor.hpp b/src/simulation/monte_carlo_simulation/monte_carlo_simulation_executor.hpp index ad1fe87cc..729a11d8e 100644 --- a/src/simulation/monte_carlo_simulation/monte_carlo_simulation_executor.hpp +++ b/src/simulation/monte_carlo_simulation/monte_carlo_simulation_executor.hpp @@ -12,6 +12,8 @@ // #include "simulation_object.hpp" #include "initialize_monte_carlo_parameters.hpp" +namespace s2e::simulation { + /** * @class MonteCarloSimulationExecutor * @brief Monte-Carlo Simulation Executor class @@ -166,4 +168,6 @@ void MonteCarloSimulationExecutor::AddInitializedMonteCarloParameter(std::string } } +} // namespace s2e::simulation + #endif // S2E_SIMULATION_MONTE_CARLO_SIMULATION_MONTE_CARLO_SIMULATION_EXECUTOR_HPP_ diff --git a/src/simulation/monte_carlo_simulation/simulation_object.cpp b/src/simulation/monte_carlo_simulation/simulation_object.cpp index 9f41f0e15..2561ee68f 100644 --- a/src/simulation/monte_carlo_simulation/simulation_object.cpp +++ b/src/simulation/monte_carlo_simulation/simulation_object.cpp @@ -5,6 +5,8 @@ #include "simulation_object.hpp" +namespace s2e::simulation { + std::map SimulationObject::object_list_; SimulationObject::SimulationObject(std::string name) : name_(name) { @@ -41,3 +43,5 @@ void SimulationObject::GetInitializedMonteCarloParameterQuaternion(const MonteCa std::string init_monte_carlo_parameter_name, math::Quaternion& destination) const { monte_carlo_simulator.GetInitializedMonteCarloParameterQuaternion(name_, init_monte_carlo_parameter_name, destination); } + +} // namespace s2e::simulation diff --git a/src/simulation/monte_carlo_simulation/simulation_object.hpp b/src/simulation/monte_carlo_simulation/simulation_object.hpp index 33708e59d..6855011f3 100644 --- a/src/simulation/monte_carlo_simulation/simulation_object.hpp +++ b/src/simulation/monte_carlo_simulation/simulation_object.hpp @@ -16,6 +16,8 @@ #include "initialize_monte_carlo_parameters.hpp" #include "monte_carlo_simulation_executor.hpp" +namespace s2e::simulation { + /** * @class SimulationObject * @brief Class to manage randomization of variables for Monte-Carlo simulation @@ -84,4 +86,6 @@ void SimulationObject::GetInitializedMonteCarloParameterVector(const MonteCarloS monte_carlo_simulator.GetInitializedMonteCarloParameterVector(name_, init_monte_carlo_parameter_name, destination); } +} // namespace s2e::simulation + #endif // S2E_SIMULATION_MONTE_CARLO_SIMULATION_SIMULATION_OBJECT_HPP_ diff --git a/src/simulation/multiple_spacecraft/inter_spacecraft_communication.cpp b/src/simulation/multiple_spacecraft/inter_spacecraft_communication.cpp index 0324d2e2e..90a1443e3 100644 --- a/src/simulation/multiple_spacecraft/inter_spacecraft_communication.cpp +++ b/src/simulation/multiple_spacecraft/inter_spacecraft_communication.cpp @@ -7,8 +7,12 @@ #include +namespace s2e::simulation { + InterSpacecraftCommunication::InterSpacecraftCommunication(const SimulationConfiguration* simulation_configuration) { UNUSED(simulation_configuration); } InterSpacecraftCommunication::~InterSpacecraftCommunication() {} + +} // namespace s2e::simulation diff --git a/src/simulation/multiple_spacecraft/inter_spacecraft_communication.hpp b/src/simulation/multiple_spacecraft/inter_spacecraft_communication.hpp index 11b32008e..bd3940f81 100644 --- a/src/simulation/multiple_spacecraft/inter_spacecraft_communication.hpp +++ b/src/simulation/multiple_spacecraft/inter_spacecraft_communication.hpp @@ -8,6 +8,8 @@ #include "../simulation_configuration.hpp" +namespace s2e::simulation { + /** * @class InterSpacecraftCommunication * @brief Base class of inter satellite communication @@ -28,4 +30,6 @@ class InterSpacecraftCommunication { private: }; +} // namespace s2e::simulation + #endif // S2E_SIMULATION_MULTIPLE_SPACECRAFT_INTER_SPACECRAFT_COMMUNICATION_HPP_ diff --git a/src/simulation/multiple_spacecraft/relative_information.cpp b/src/simulation/multiple_spacecraft/relative_information.cpp index f81227cb7..3aed97e77 100644 --- a/src/simulation/multiple_spacecraft/relative_information.cpp +++ b/src/simulation/multiple_spacecraft/relative_information.cpp @@ -5,6 +5,8 @@ #include "relative_information.hpp" +namespace s2e::simulation { + RelativeInformation::RelativeInformation() {} RelativeInformation::~RelativeInformation() {} @@ -37,7 +39,7 @@ void RelativeInformation::Update() { } } -void RelativeInformation::RegisterDynamicsInfo(const size_t spacecraft_id, const Dynamics* dynamics) { +void RelativeInformation::RegisterDynamicsInfo(const size_t spacecraft_id, const dynamics::Dynamics* dynamics) { dynamics_database_.emplace(spacecraft_id, dynamics); ResizeLists(); } @@ -51,28 +53,28 @@ std::string RelativeInformation::GetLogHeader() const { std::string str_tmp = ""; for (size_t target_spacecraft_id = 0; target_spacecraft_id < dynamics_database_.size(); target_spacecraft_id++) { for (size_t reference_spacecraft_id = 0; reference_spacecraft_id < target_spacecraft_id; reference_spacecraft_id++) { - str_tmp += WriteVector( + str_tmp += logger::WriteVector( "satellite" + std::to_string(target_spacecraft_id) + "_position_from_satellite" + std::to_string(reference_spacecraft_id), "i", "m", 3); } } for (size_t target_spacecraft_id = 0; target_spacecraft_id < dynamics_database_.size(); target_spacecraft_id++) { for (size_t reference_spacecraft_id = 0; reference_spacecraft_id < target_spacecraft_id; reference_spacecraft_id++) { - str_tmp += WriteVector( + str_tmp += logger::WriteVector( "satellite" + std::to_string(target_spacecraft_id) + "_velocity_from_satellite" + std::to_string(reference_spacecraft_id), "i", "m/s", 3); } } for (size_t target_spacecraft_id = 0; target_spacecraft_id < dynamics_database_.size(); target_spacecraft_id++) { for (size_t reference_spacecraft_id = 0; reference_spacecraft_id < target_spacecraft_id; reference_spacecraft_id++) { - str_tmp += WriteVector( + str_tmp += logger::WriteVector( "satellite" + std::to_string(target_spacecraft_id) + "_position_from_satellite" + std::to_string(reference_spacecraft_id), "rtn", "m", 3); } } for (size_t target_spacecraft_id = 0; target_spacecraft_id < dynamics_database_.size(); target_spacecraft_id++) { for (size_t reference_spacecraft_id = 0; reference_spacecraft_id < target_spacecraft_id; reference_spacecraft_id++) { - str_tmp += WriteVector( + str_tmp += logger::WriteVector( "satellite" + std::to_string(target_spacecraft_id) + "_velocity_from_satellite" + std::to_string(reference_spacecraft_id), "rtn", "m/s", 3); } } @@ -84,32 +86,32 @@ std::string RelativeInformation::GetLogValue() const { std::string str_tmp = ""; for (size_t target_spacecraft_id = 0; target_spacecraft_id < dynamics_database_.size(); target_spacecraft_id++) { for (size_t reference_spacecraft_id = 0; reference_spacecraft_id < target_spacecraft_id; reference_spacecraft_id++) { - str_tmp += WriteVector(GetRelativePosition_i_m(target_spacecraft_id, reference_spacecraft_id)); + str_tmp += logger::WriteVector(GetRelativePosition_i_m(target_spacecraft_id, reference_spacecraft_id)); } } for (size_t target_spacecraft_id = 0; target_spacecraft_id < dynamics_database_.size(); target_spacecraft_id++) { for (size_t reference_spacecraft_id = 0; reference_spacecraft_id < target_spacecraft_id; reference_spacecraft_id++) { - str_tmp += WriteVector(GetRelativeVelocity_i_m_s(target_spacecraft_id, reference_spacecraft_id)); + str_tmp += logger::WriteVector(GetRelativeVelocity_i_m_s(target_spacecraft_id, reference_spacecraft_id)); } } for (size_t target_spacecraft_id = 0; target_spacecraft_id < dynamics_database_.size(); target_spacecraft_id++) { for (size_t reference_spacecraft_id = 0; reference_spacecraft_id < target_spacecraft_id; reference_spacecraft_id++) { - str_tmp += WriteVector(GetRelativePosition_rtn_m(target_spacecraft_id, reference_spacecraft_id)); + str_tmp += logger::WriteVector(GetRelativePosition_rtn_m(target_spacecraft_id, reference_spacecraft_id)); } } for (size_t target_spacecraft_id = 0; target_spacecraft_id < dynamics_database_.size(); target_spacecraft_id++) { for (size_t reference_spacecraft_id = 0; reference_spacecraft_id < target_spacecraft_id; reference_spacecraft_id++) { - str_tmp += WriteVector(GetRelativeVelocity_rtn_m_s(target_spacecraft_id, reference_spacecraft_id)); + str_tmp += logger::WriteVector(GetRelativeVelocity_rtn_m_s(target_spacecraft_id, reference_spacecraft_id)); } } return str_tmp; } -void RelativeInformation::LogSetup(Logger& logger) { logger.AddLogList(this); } +void RelativeInformation::LogSetup(logger::Logger& logger) { logger.AddLogList(this); } math::Quaternion RelativeInformation::CalcRelativeAttitudeQuaternion(const size_t target_spacecraft_id, const size_t reference_spacecraft_id) { // Observer SC Body frame(obs_sat) -> ECI frame(i) @@ -163,3 +165,5 @@ void RelativeInformation::ResizeLists() { relative_velocity_list_rtn_m_s_.assign(size, std::vector>(size, math::Vector<3>(0))); relative_attitude_quaternion_list_.assign(size, std::vector(size, math::Quaternion(0, 0, 0, 1))); } + +} // namespace s2e::simulation diff --git a/src/simulation/multiple_spacecraft/relative_information.hpp b/src/simulation/multiple_spacecraft/relative_information.hpp index 87a273641..d49f4c74a 100644 --- a/src/simulation/multiple_spacecraft/relative_information.hpp +++ b/src/simulation/multiple_spacecraft/relative_information.hpp @@ -6,17 +6,24 @@ #ifndef S2E_MULTIPLE_SPACECRAFT_RELATIVE_INFORMATION_HPP_ #define S2E_MULTIPLE_SPACECRAFT_RELATIVE_INFORMATION_HPP_ +#include #include #include "../../dynamics/dynamics.hpp" #include "../../logger/loggable.hpp" #include "../../logger/logger.hpp" +namespace s2e::dynamics { +class Dynamics; +} + +namespace s2e::simulation { + /** * @class RelativeInformation * @brief Base class to manage relative information between spacecraft */ -class RelativeInformation : public ILoggable { +class RelativeInformation : public logger::ILoggable { public: /** * @fn RelativeInformation @@ -40,7 +47,7 @@ class RelativeInformation : public ILoggable { * @param [in] spacecraft_id: ID of target spacecraft * @param [in] dynamics: Dynamics information of the target spacecraft */ - void RegisterDynamicsInfo(const size_t spacecraft_id, const Dynamics* dynamics); + void RegisterDynamicsInfo(const size_t spacecraft_id, const dynamics::Dynamics* dynamics); /** * @fn RegisterDynamicsInfo * @brief Remove dynamics information of target spacecraft @@ -64,7 +71,7 @@ class RelativeInformation : public ILoggable { * @fn LogSetup * @brief Logging setup for relative information */ - void LogSetup(Logger& logger); + void LogSetup(logger::Logger& logger); // Getter /** @@ -127,12 +134,12 @@ class RelativeInformation : public ILoggable { * @brief Return the dynamics information of a spacecraft * @param [in] target_spacecraft_id: ID of the spacecraft */ - inline const Dynamics* GetReferenceSatDynamics(const size_t reference_spacecraft_id) const { + inline const dynamics::Dynamics* GetReferenceSatDynamics(const size_t reference_spacecraft_id) const { return dynamics_database_.at(reference_spacecraft_id); }; private: - std::map dynamics_database_; //!< Dynamics database of all spacecraft + std::map dynamics_database_; //!< Dynamics database of all spacecraft std::vector>> relative_position_list_i_m_; //!< Relative position list in the inertial frame in unit [m] std::vector>> relative_velocity_list_i_m_s_; //!< Relative velocity list in the inertial frame in unit [m/s] @@ -170,4 +177,6 @@ class RelativeInformation : public ILoggable { void ResizeLists(); }; +} // namespace s2e::simulation + #endif // S2E_MULTIPLE_SPACECRAFT_RELATIVE_INFORMATION_HPP_ diff --git a/src/simulation/simulation_configuration.hpp b/src/simulation/simulation_configuration.hpp index 28b6f74f0..e3adeb87d 100644 --- a/src/simulation/simulation_configuration.hpp +++ b/src/simulation/simulation_configuration.hpp @@ -11,13 +11,15 @@ #include "../logger/logger.hpp" +namespace s2e::simulation { + /** * @struct SimulationConfiguration * @brief Simulation setting information */ struct SimulationConfiguration { std::string initialize_base_file_name_; //!< Base file name for initialization - Logger* main_logger_; //!< Main logger + logger::Logger* main_logger_; //!< Main logger unsigned int number_of_simulated_spacecraft_; //!< Number of simulated spacecraft std::vector spacecraft_file_list_; //!< File name list for spacecraft initialization @@ -35,4 +37,6 @@ struct SimulationConfiguration { ~SimulationConfiguration() { delete main_logger_; } }; +} // namespace s2e::simulation + #endif // S2E_SIMULATION_SIMULATION_CONFIGURATION_HPP_ diff --git a/src/simulation/spacecraft/installed_components.cpp b/src/simulation/spacecraft/installed_components.cpp index 7497df29e..c6a482fce 100644 --- a/src/simulation/spacecraft/installed_components.cpp +++ b/src/simulation/spacecraft/installed_components.cpp @@ -7,6 +7,8 @@ #include +namespace s2e::spacecraft { + math::Vector<3> InstalledComponents::GenerateForce_b_N() { math::Vector<3> force_b_N_(0.0); return force_b_N_; @@ -17,4 +19,6 @@ math::Vector<3> InstalledComponents::GenerateTorque_b_Nm() { return torque_b_Nm_; } -void InstalledComponents::LogSetup(Logger& logger) { UNUSED(logger); } +void InstalledComponents::LogSetup(logger::Logger& logger) { UNUSED(logger); } + +} // namespace s2e::spacecraft diff --git a/src/simulation/spacecraft/installed_components.hpp b/src/simulation/spacecraft/installed_components.hpp index 4a4550c55..096bba236 100644 --- a/src/simulation/spacecraft/installed_components.hpp +++ b/src/simulation/spacecraft/installed_components.hpp @@ -9,6 +9,8 @@ #include #include +namespace s2e::spacecraft { + /** * @class InstalledComponents * @brief Base class to express components list installed on a spacecraft @@ -46,7 +48,9 @@ class InstalledComponents { * @brief Setup the logger for components * @details Users need to override this function to add logger for components */ - virtual void LogSetup(Logger& logger); + virtual void LogSetup(logger::Logger& logger); }; +} // namespace s2e::spacecraft + #endif // S2E_SIMULATION_SPACECRAFT_INSTALLED_COMPONENTS_HPP_ diff --git a/src/simulation/spacecraft/spacecraft.cpp b/src/simulation/spacecraft/spacecraft.cpp index 61a7762d4..59e060a3a 100644 --- a/src/simulation/spacecraft/spacecraft.cpp +++ b/src/simulation/spacecraft/spacecraft.cpp @@ -8,8 +8,10 @@ #include #include -Spacecraft::Spacecraft(const SimulationConfiguration* simulation_configuration, const GlobalEnvironment* global_environment, const int spacecraft_id, - RelativeInformation* relative_information) +namespace s2e::spacecraft { + +Spacecraft::Spacecraft(const simulation::SimulationConfiguration* simulation_configuration, const environment::GlobalEnvironment* global_environment, + const int spacecraft_id, simulation::RelativeInformation* relative_information) : spacecraft_id_(spacecraft_id) { Initialize(simulation_configuration, global_environment, spacecraft_id, relative_information); } @@ -25,14 +27,15 @@ Spacecraft::~Spacecraft() { delete components_; } -void Spacecraft::Initialize(const SimulationConfiguration* simulation_configuration, const GlobalEnvironment* global_environment, - const int spacecraft_id, RelativeInformation* relative_information) { +void Spacecraft::Initialize(const simulation::SimulationConfiguration* simulation_configuration, + const environment::GlobalEnvironment* global_environment, const int spacecraft_id, + simulation::RelativeInformation* relative_information) { clock_generator_.ClearTimerCount(); - structure_ = new Structure(simulation_configuration, spacecraft_id); - local_environment_ = new LocalEnvironment(simulation_configuration, global_environment, spacecraft_id); - dynamics_ = new Dynamics(simulation_configuration, &(global_environment->GetSimulationTime()), local_environment_, spacecraft_id, structure_, - relative_information); - disturbances_ = new Disturbances(simulation_configuration, spacecraft_id, structure_, global_environment); + structure_ = new spacecraft::Structure(simulation_configuration, spacecraft_id); + local_environment_ = new environment::LocalEnvironment(simulation_configuration, global_environment, spacecraft_id); + dynamics_ = new dynamics::Dynamics(simulation_configuration, &(global_environment->GetSimulationTime()), local_environment_, spacecraft_id, + structure_, relative_information); + disturbances_ = new disturbances::Disturbances(simulation_configuration, spacecraft_id, structure_, global_environment); simulation_configuration->main_logger_->CopyFileToLogDirectory(simulation_configuration->spacecraft_file_list_[spacecraft_id]); @@ -42,14 +45,14 @@ void Spacecraft::Initialize(const SimulationConfiguration* simulation_configurat } } -void Spacecraft::LogSetup(Logger& logger) { +void Spacecraft::LogSetup(logger::Logger& logger) { dynamics_->LogSetup(logger); local_environment_->LogSetup(logger); disturbances_->LogSetup(logger); components_->LogSetup(logger); } -void Spacecraft::Update(const SimulationTime* simulation_time) { +void Spacecraft::Update(const environment::SimulationTime* simulation_time) { dynamics_->ClearForceTorque(); // Update local environment and disturbance @@ -74,3 +77,5 @@ void Spacecraft::Update(const SimulationTime* simulation_time) { } void Spacecraft::Clear(void) { dynamics_->ClearForceTorque(); } + +} // namespace s2e::spacecraft diff --git a/src/simulation/spacecraft/spacecraft.hpp b/src/simulation/spacecraft/spacecraft.hpp index 2d9552f24..b7de8189c 100644 --- a/src/simulation/spacecraft/spacecraft.hpp +++ b/src/simulation/spacecraft/spacecraft.hpp @@ -15,6 +15,8 @@ #include "installed_components.hpp" #include "structure/structure.hpp" +namespace s2e::spacecraft { + /** * @class Spacecraft * @brief Base class to express Spacecraft @@ -25,8 +27,8 @@ class Spacecraft { * @fn Spacecraft * @brief Constructor for single satellite simulation */ - Spacecraft(const SimulationConfiguration* simulation_configuration, const GlobalEnvironment* global_environment, const int spacecraft_id, - RelativeInformation* relative_information = nullptr); + Spacecraft(const simulation::SimulationConfiguration* simulation_configuration, const environment::GlobalEnvironment* global_environment, + const int spacecraft_id, simulation::RelativeInformation* relative_information = nullptr); /** * @fn ~Spacecraft @@ -43,14 +45,15 @@ class Spacecraft { * @fn Initialize * @brief Initialize function for multiple spacecraft simulation */ - virtual void Initialize(const SimulationConfiguration* simulation_configuration, const GlobalEnvironment* global_environment, - const int spacecraft_id, RelativeInformation* relative_information = nullptr); + virtual void Initialize(const simulation::SimulationConfiguration* simulation_configuration, + const environment::GlobalEnvironment* global_environment, const int spacecraft_id, + simulation::RelativeInformation* relative_information = nullptr); /** * @fn Update * @brief Update all states related with the spacecraft */ - virtual void Update(const SimulationTime* simulation_time); + virtual void Update(const environment::SimulationTime* simulation_time); /** * @fn Clear @@ -62,29 +65,29 @@ class Spacecraft { * @fn LogSetup * @brief Logger setting for the spacecraft specific information */ - virtual void LogSetup(Logger& logger); + virtual void LogSetup(logger::Logger& logger); // Getters /** * @fn GetDynamics * @brief Get dynamics of the spacecraft */ - inline const Dynamics& GetDynamics() const { return *dynamics_; } + inline const dynamics::Dynamics& GetDynamics() const { return *dynamics_; } /** * @fn GetLocalEnvironment * @brief Get local environment around the spacecraft */ - inline const LocalEnvironment& GetLocalEnvironment() const { return *local_environment_; } + inline const environment::LocalEnvironment& GetLocalEnvironment() const { return *local_environment_; } /** * @fn GetDisturbances * @brief Get disturbance acting of the spacecraft */ - inline const Disturbances& GetDisturbances() const { return *disturbances_; } + inline const disturbances::Disturbances& GetDisturbances() const { return *disturbances_; } /** * @fn GetStructure * @brief Get structure of the spacecraft */ - inline const Structure& GetStructure() const { return *structure_; } + inline const spacecraft::Structure& GetStructure() const { return *structure_; } /** * @fn GetInstalledComponents * @brief Get components installed on the spacecraft @@ -97,14 +100,16 @@ class Spacecraft { inline unsigned int GetSpacecraftId() const { return spacecraft_id_; } protected: - ClockGenerator clock_generator_; //!< Origin of clock for the spacecraft - Dynamics* dynamics_; //!< Dynamics information of the spacecraft - RelativeInformation* relative_information_; //!< Relative information with respect to the other spacecraft - LocalEnvironment* local_environment_; //!< Local environment information around the spacecraft - Disturbances* disturbances_; //!< Disturbance information acting on the spacecraft - Structure* structure_; //!< Structure information of the spacecraft - InstalledComponents* components_; //!< Components information installed on the spacecraft - const unsigned int spacecraft_id_; //!< ID of the spacecraft + environment::ClockGenerator clock_generator_; //!< Origin of clock for the spacecraft + dynamics::Dynamics* dynamics_; //!< Dynamics information of the spacecraft + simulation::RelativeInformation* relative_information_; //!< Relative information with respect to the other spacecraft + environment::LocalEnvironment* local_environment_; //!< Local environment information around the spacecraft + disturbances::Disturbances* disturbances_; //!< Disturbance information acting on the spacecraft + spacecraft::Structure* structure_; //!< Structure information of the spacecraft + InstalledComponents* components_; //!< Components information installed on the spacecraft + const unsigned int spacecraft_id_; //!< ID of the spacecraft }; +} // namespace s2e::spacecraft + #endif // S2E_SIMULATION_SPACECRAFT_SPACECRAFT_HPP_ diff --git a/src/simulation/spacecraft/structure/initialize_structure.cpp b/src/simulation/spacecraft/structure/initialize_structure.cpp index 0c2a49b35..4fa2b131c 100644 --- a/src/simulation/spacecraft/structure/initialize_structure.cpp +++ b/src/simulation/spacecraft/structure/initialize_structure.cpp @@ -8,9 +8,11 @@ #include #include +namespace s2e::spacecraft { + #define MIN_VAL 1e-6 KinematicsParameters InitKinematicsParameters(std::string file_name) { - auto conf = IniAccess(file_name); + auto conf = setting_file_reader::IniAccess(file_name); const char* section = "KINEMATIC_PARAMETERS"; math::Vector<3> center_of_gravity_b_m; @@ -29,14 +31,14 @@ KinematicsParameters InitKinematicsParameters(std::string file_name) { return kinematics_params; } -std::vector InitSurfaces(std::string file_name) { +std::vector InitSurfaces(std::string file_name) { using std::cout; - auto conf = IniAccess(file_name); + auto conf = setting_file_reader::IniAccess(file_name); const char* section = "SURFACES"; const int num_surface = conf.ReadInt(section, "number_of_surfaces"); - std::vector surfaces; + std::vector surfaces; for (int i = 0; i < num_surface; i++) { std::string idx = std::to_string(i); @@ -87,7 +89,7 @@ std::vector InitSurfaces(std::string file_name) { break; } - Vector<3> position, normal; + math::Vector<3> position, normal; keyword = "position" + idx + "_b_m"; conf.ReadVector(section, keyword.c_str(), position); @@ -101,13 +103,13 @@ std::vector InitSurfaces(std::string file_name) { } // Add a surface - surfaces.push_back(Surface(position, normal, area, ref, spe, air_spe)); + surfaces.push_back(spacecraft::Surface(position, normal, area, ref, spe, air_spe)); } return surfaces; } ResidualMagneticMoment InitResidualMagneticMoment(std::string file_name) { - auto conf = IniAccess(file_name); + auto conf = setting_file_reader::IniAccess(file_name); const char* section = "RESIDUAL_MAGNETIC_MOMENT"; math::Vector<3> rmm_const_b; @@ -119,3 +121,5 @@ ResidualMagneticMoment InitResidualMagneticMoment(std::string file_name) { ResidualMagneticMoment rmm_params(rmm_const_b, rmm_rwdev, random_walk_limit_Am2, random_noise_standard_deviation_Am2); return rmm_params; } + +} // namespace s2e::spacecraft diff --git a/src/simulation/spacecraft/structure/initialize_structure.hpp b/src/simulation/spacecraft/structure/initialize_structure.hpp index 59311219a..8995a9689 100644 --- a/src/simulation/spacecraft/structure/initialize_structure.hpp +++ b/src/simulation/spacecraft/structure/initialize_structure.hpp @@ -6,10 +6,10 @@ #ifndef S2E_SIMULATION_SPACECRAFT_STRUCTURE_INITIALIZE_STRUCTURE_HPP_ #define S2E_SIMULATION_SPACECRAFT_STRUCTURE_INITIALIZE_STRUCTURE_HPP_ -#pragma once - #include +namespace s2e::spacecraft { + /** * @fn InitKinematicsParameters * @brief Initialize the kinematics parameters with an ini file @@ -26,4 +26,6 @@ std::vector InitSurfaces(std::string file_name); */ ResidualMagneticMoment InitResidualMagneticMoment(std::string file_name); +} // namespace s2e::spacecraft + #endif // S2E_SIMULATION_SPACECRAFT_STRUCTURE_INITIALIZE_STRUCTURE_HPP_ diff --git a/src/simulation/spacecraft/structure/kinematics_parameters.cpp b/src/simulation/spacecraft/structure/kinematics_parameters.cpp index 67906710a..5768c73e7 100644 --- a/src/simulation/spacecraft/structure/kinematics_parameters.cpp +++ b/src/simulation/spacecraft/structure/kinematics_parameters.cpp @@ -5,5 +5,9 @@ #include "kinematics_parameters.hpp" +namespace s2e::spacecraft { + KinematicsParameters::KinematicsParameters(math::Vector<3> center_of_gravity_b_m, double mass_kg, math::Matrix<3, 3> inertia_tensor_b_kgm2) - : center_of_gravity_b_m_(center_of_gravity_b_m), mass_kg_(mass_kg), inertia_tensor_b_kgm2_(inertia_tensor_b_kgm2) {} \ No newline at end of file + : center_of_gravity_b_m_(center_of_gravity_b_m), mass_kg_(mass_kg), inertia_tensor_b_kgm2_(inertia_tensor_b_kgm2) {} + +} // namespace s2e::spacecraft diff --git a/src/simulation/spacecraft/structure/kinematics_parameters.hpp b/src/simulation/spacecraft/structure/kinematics_parameters.hpp index 52818f018..33cc7cb9b 100644 --- a/src/simulation/spacecraft/structure/kinematics_parameters.hpp +++ b/src/simulation/spacecraft/structure/kinematics_parameters.hpp @@ -9,6 +9,8 @@ #include #include +namespace s2e::spacecraft { + /** * @class KinematicsParameters * @brief Class for spacecraft Kinematics information @@ -24,7 +26,7 @@ class KinematicsParameters { * @fn ~KinematicsParameters * @brief Destructor */ - ~KinematicsParameters(){}; + ~KinematicsParameters() {}; // Getter /** @@ -86,4 +88,6 @@ class KinematicsParameters { math::Matrix<3, 3> inertia_tensor_b_kgm2_; //!< Inertia tensor at body frame [kgm2] }; +} // namespace s2e::spacecraft + #endif // S2E_SIMULATION_SPACECRAFT_STRUCTURE_KINEMATICS_PARAMETERS_HPP_ diff --git a/src/simulation/spacecraft/structure/residual_magnetic_moment.cpp b/src/simulation/spacecraft/structure/residual_magnetic_moment.cpp index 0fe90e09f..7e10c5014 100644 --- a/src/simulation/spacecraft/structure/residual_magnetic_moment.cpp +++ b/src/simulation/spacecraft/structure/residual_magnetic_moment.cpp @@ -5,9 +5,13 @@ #include "residual_magnetic_moment.hpp" -ResidualMagneticMoment::ResidualMagneticMoment(const Vector<3> constant_value_b_Am2_, const double random_walk_standard_deviation_Am2, +namespace s2e::spacecraft { + +ResidualMagneticMoment::ResidualMagneticMoment(const math::Vector<3> constant_value_b_Am2_, const double random_walk_standard_deviation_Am2, const double random_walk_limit_Am2, const double random_noise_standard_deviation_Am2) : constant_value_b_Am2_(constant_value_b_Am2_), random_walk_standard_deviation_Am2_(random_walk_standard_deviation_Am2), random_walk_limit_Am2_(random_walk_limit_Am2), random_noise_standard_deviation_Am2_(random_noise_standard_deviation_Am2) {} + +} // namespace s2e::spacecraft diff --git a/src/simulation/spacecraft/structure/residual_magnetic_moment.hpp b/src/simulation/spacecraft/structure/residual_magnetic_moment.hpp index 72000e51f..7fbb338d6 100644 --- a/src/simulation/spacecraft/structure/residual_magnetic_moment.hpp +++ b/src/simulation/spacecraft/structure/residual_magnetic_moment.hpp @@ -7,7 +7,8 @@ #define S2E_SIMULATION_SPACECRAFT_STRUCTURE_RESIDUAL_MAGNETIC_MOMENT_HPP_ #include -using math::Vector; + +namespace s2e::spacecraft { /** * @class ResidualMagneticMoment @@ -19,20 +20,20 @@ class ResidualMagneticMoment { * @fn ResidualMagneticMoment * @brief Constructor */ - ResidualMagneticMoment(const Vector<3> constant_value_b_Am2_, const double random_walk_standard_deviation_Am2, const double random_walk_limit_Am2, - const double random_noise_standard_deviation_Am2); + ResidualMagneticMoment(const math::Vector<3> constant_value_b_Am2_, const double random_walk_standard_deviation_Am2, + const double random_walk_limit_Am2, const double random_noise_standard_deviation_Am2); /** * @fn ~ResidualMagneticMoment * @brief Destructor */ - ~ResidualMagneticMoment(){}; + ~ResidualMagneticMoment() {}; // Getter /** * @fn GetConstantValue_b_Am2 * @brief Return Constant value of RMM at body frame [Am2] */ - inline const Vector<3>& GetConstantValue_b_Am2(void) const { return constant_value_b_Am2_; } + inline const math::Vector<3>& GetConstantValue_b_Am2(void) const { return constant_value_b_Am2_; } /** * @fn GetRandomWalkStandardDeviation_Am2 * @brief Return Random walk standard deviation of RMM [Am2] @@ -55,19 +56,21 @@ class ResidualMagneticMoment { * @brief Set Constant value of RMM at body frame [Am2] * @param [in] rmm_const_b_Am2: Constant value of RMM at the body frame [Am2] */ - inline void SetRmmConstant_b_Am2(const Vector<3> rmm_const_b_Am2) { constant_value_b_Am2_ = rmm_const_b_Am2; } + inline void SetRmmConstant_b_Am2(const math::Vector<3> rmm_const_b_Am2) { constant_value_b_Am2_ = rmm_const_b_Am2; } /** * @fn AddRMMConst_b_Am2 * @brief Add Constant value of RMM at body frame [Am2] * @param [in] rmm_const_b_Am2: Constant value of RMM at the body frame [Am2] */ - inline void AddRmmConstant_b_Am2(const Vector<3> rmm_const_b_Am2) { constant_value_b_Am2_ += rmm_const_b_Am2; } + inline void AddRmmConstant_b_Am2(const math::Vector<3> rmm_const_b_Am2) { constant_value_b_Am2_ += rmm_const_b_Am2; } private: - Vector<3> constant_value_b_Am2_; //!< Constant value of RMM at body frame [Am2] + math::Vector<3> constant_value_b_Am2_; //!< Constant value of RMM at body frame [Am2] double random_walk_standard_deviation_Am2_; //!< Random walk standard deviation of RMM [Am2] double random_walk_limit_Am2_; //!< Random walk limit of RMM [Am2] double random_noise_standard_deviation_Am2_; //!< Standard deviation of white noise of RMM [Am2] }; +} // namespace s2e::spacecraft + #endif // S2E_SIMULATION_SPACECRAFT_STRUCTURE_RESIDUAL_MAGNETIC_MOMENT_HPP_ \ No newline at end of file diff --git a/src/simulation/spacecraft/structure/structure.cpp b/src/simulation/spacecraft/structure/structure.cpp index bf4510005..af7e345d7 100644 --- a/src/simulation/spacecraft/structure/structure.cpp +++ b/src/simulation/spacecraft/structure/structure.cpp @@ -8,7 +8,9 @@ #include #include -Structure::Structure(const SimulationConfiguration* simulation_configuration, const int spacecraft_id) { +namespace s2e::spacecraft { + +Structure::Structure(const simulation::SimulationConfiguration* simulation_configuration, const int spacecraft_id) { Initialize(simulation_configuration, spacecraft_id); } @@ -17,9 +19,9 @@ Structure::~Structure() { delete residual_magnetic_moment_; } -void Structure::Initialize(const SimulationConfiguration* simulation_configuration, const int spacecraft_id) { +void Structure::Initialize(const simulation::SimulationConfiguration* simulation_configuration, const int spacecraft_id) { // Read file name - IniAccess conf = IniAccess(simulation_configuration->spacecraft_file_list_[spacecraft_id]); + setting_file_reader::IniAccess conf = setting_file_reader::IniAccess(simulation_configuration->spacecraft_file_list_[spacecraft_id]); std::string ini_fname = conf.ReadString("SETTING_FILES", "structure_file"); // Save ini file simulation_configuration->main_logger_->CopyFileToLogDirectory(ini_fname); @@ -28,3 +30,5 @@ void Structure::Initialize(const SimulationConfiguration* simulation_configurati surfaces_ = InitSurfaces(ini_fname); residual_magnetic_moment_ = new ResidualMagneticMoment(InitResidualMagneticMoment(ini_fname)); } + +} // namespace s2e::spacecraft diff --git a/src/simulation/spacecraft/structure/structure.hpp b/src/simulation/spacecraft/structure/structure.hpp index acc0b5d36..09001aaeb 100644 --- a/src/simulation/spacecraft/structure/structure.hpp +++ b/src/simulation/spacecraft/structure/structure.hpp @@ -13,6 +13,8 @@ #include "residual_magnetic_moment.hpp" #include "surface.hpp" +namespace s2e::spacecraft { + /** * @class Structure * @brief Class for spacecraft structure information @@ -23,7 +25,7 @@ class Structure { * @fn Structure * @brief Constructor */ - Structure(const SimulationConfiguration* simulation_configuration, const int spacecraft_id); + Structure(const simulation::SimulationConfiguration* simulation_configuration, const int spacecraft_id); /** * @fn ~Structure * @brief Destructor @@ -33,7 +35,7 @@ class Structure { * @fn Initialize * @brief Initialize function */ - void Initialize(const SimulationConfiguration* simulation_configuration, const int spacecraft_id); + void Initialize(const simulation::SimulationConfiguration* simulation_configuration, const int spacecraft_id); // Getter /** @@ -74,4 +76,6 @@ class Structure { ResidualMagneticMoment* residual_magnetic_moment_; //!< Residual Magnetic Moment }; +} // namespace s2e::spacecraft + #endif // S2E_SIMULATION_SPACECRAFT_STRUCTURE_STRUCTURE_HPP_ diff --git a/src/simulation/spacecraft/structure/surface.cpp b/src/simulation/spacecraft/structure/surface.cpp index 06af72cde..316d6165e 100644 --- a/src/simulation/spacecraft/structure/surface.cpp +++ b/src/simulation/spacecraft/structure/surface.cpp @@ -5,6 +5,8 @@ #include "surface.hpp" +namespace s2e::spacecraft { + Surface::Surface(const math::Vector<3> position_b_m, const math::Vector<3> normal_b, const double area_m2, const double reflectivity, const double specularity, const double air_specularity) : position_b_m_(position_b_m), @@ -13,3 +15,5 @@ Surface::Surface(const math::Vector<3> position_b_m, const math::Vector<3> norma reflectivity_(reflectivity), specularity_(specularity), air_specularity_(air_specularity) {} + +} // namespace s2e::spacecraft diff --git a/src/simulation/spacecraft/structure/surface.hpp b/src/simulation/spacecraft/structure/surface.hpp index db54f219b..9f5375a29 100644 --- a/src/simulation/spacecraft/structure/surface.hpp +++ b/src/simulation/spacecraft/structure/surface.hpp @@ -8,6 +8,8 @@ #include +namespace s2e::spacecraft { + /** * @class Surface * @brief Class for spacecraft surface @@ -24,7 +26,7 @@ class Surface { * @fn ~Surface * @brief Destructor */ - ~Surface(){}; + ~Surface() {}; // Getter /** @@ -113,4 +115,6 @@ class Surface { double air_specularity_; //!< Specularity for air drag }; +} // namespace s2e::spacecraft + #endif // S2E_SIMULATION_SPACECRAFT_STRUCTURE_SURFACE_HPP_ diff --git a/src/simulation_sample/case/sample_case.cpp b/src/simulation_sample/case/sample_case.cpp index ce6376ebe..4697ecd07 100644 --- a/src/simulation_sample/case/sample_case.cpp +++ b/src/simulation_sample/case/sample_case.cpp @@ -5,7 +5,9 @@ #include "sample_case.hpp" -SampleCase::SampleCase(std::string initialise_base_file) : SimulationCase(initialise_base_file) {} +namespace s2e::sample { + +SampleCase::SampleCase(std::string initialise_base_file) : simulation::SimulationCase(initialise_base_file) {} SampleCase::~SampleCase() { delete sample_spacecraft_; @@ -35,7 +37,7 @@ void SampleCase::UpdateTargetObjects() { std::string SampleCase::GetLogHeader() const { std::string str_tmp = ""; - str_tmp += WriteScalar("time", "s"); + str_tmp += logger::WriteScalar("time", "s"); return str_tmp; } @@ -43,7 +45,9 @@ std::string SampleCase::GetLogHeader() const { std::string SampleCase::GetLogValue() const { std::string str_tmp = ""; - str_tmp += WriteScalar(global_environment_->GetSimulationTime().GetElapsedTime_s()); + str_tmp += logger::WriteScalar(global_environment_->GetSimulationTime().GetElapsedTime_s()); return str_tmp; } + +} // namespace s2e::sample diff --git a/src/simulation_sample/case/sample_case.hpp b/src/simulation_sample/case/sample_case.hpp index a4664a190..af3fc5b74 100644 --- a/src/simulation_sample/case/sample_case.hpp +++ b/src/simulation_sample/case/sample_case.hpp @@ -11,11 +11,13 @@ #include "../ground_station/sample_ground_station.hpp" #include "../spacecraft/sample_spacecraft.hpp" +namespace s2e::sample { + /** * @class SampleCase * @brief An example of user defined simulation class */ -class SampleCase : public SimulationCase { +class SampleCase : public simulation::SimulationCase { public: /** * @fn SampleCase @@ -57,4 +59,6 @@ class SampleCase : public SimulationCase { void UpdateTargetObjects(); }; +} // namespace s2e::sample + #endif // S2E_SIMULATION_SAMPLE_CASE_SAMPLE_CASE_HPP_ diff --git a/src/simulation_sample/ground_station/sample_ground_station.cpp b/src/simulation_sample/ground_station/sample_ground_station.cpp index 1aa881352..5ca22e707 100644 --- a/src/simulation_sample/ground_station/sample_ground_station.cpp +++ b/src/simulation_sample/ground_station/sample_ground_station.cpp @@ -7,19 +7,23 @@ #include "sample_ground_station_components.hpp" -SampleGroundStation::SampleGroundStation(const SimulationConfiguration* configuration, const unsigned int ground_station_id) - : GroundStation(configuration, ground_station_id) { +namespace s2e::sample { + +SampleGroundStation::SampleGroundStation(const simulation::SimulationConfiguration* configuration, const unsigned int ground_station_id) + : ground_station::GroundStation(configuration, ground_station_id) { components_ = new SampleGsComponents(configuration); } SampleGroundStation::~SampleGroundStation() { delete components_; } -void SampleGroundStation::LogSetup(Logger& logger) { - GroundStation::LogSetup(logger); +void SampleGroundStation::LogSetup(logger::Logger& logger) { + ground_station::GroundStation::LogSetup(logger); components_->CompoLogSetUp(logger); } -void SampleGroundStation::Update(const EarthRotation& celestial_rotation, const SampleSpacecraft& spacecraft) { - GroundStation::Update(celestial_rotation, spacecraft); +void SampleGroundStation::Update(const environment::EarthRotation& celestial_rotation, const SampleSpacecraft& spacecraft) { + ground_station::GroundStation::Update(celestial_rotation, spacecraft); components_->GetGsCalculator()->Update(spacecraft, spacecraft.GetInstalledComponents().GetAntenna(), *this, *(components_->GetAntenna())); } + +} // namespace s2e::sample diff --git a/src/simulation_sample/ground_station/sample_ground_station.hpp b/src/simulation_sample/ground_station/sample_ground_station.hpp index 8fe089bba..0d45f86f4 100644 --- a/src/simulation_sample/ground_station/sample_ground_station.hpp +++ b/src/simulation_sample/ground_station/sample_ground_station.hpp @@ -14,19 +14,21 @@ #include "../spacecraft/sample_spacecraft.hpp" +namespace s2e::sample { + class SampleGsComponents; /** * @class SampleGroundStation * @brief An example of user defined ground station class */ -class SampleGroundStation : public GroundStation { +class SampleGroundStation : public ground_station::GroundStation { public: /** * @fn SampleGroundStation * @brief Constructor */ - SampleGroundStation(const SimulationConfiguration* configuration, const unsigned int ground_station_id); + SampleGroundStation(const simulation::SimulationConfiguration* configuration, const unsigned int ground_station_id); /** * @fn ~SampleGroundStation * @brief Destructor @@ -37,16 +39,18 @@ class SampleGroundStation : public GroundStation { * @fn LogSetup * @brief Override function of LogSetup in GroundStation class */ - virtual void LogSetup(Logger& logger); + virtual void LogSetup(logger::Logger& logger); /** * @fn Update * @brief Override function of Update in GroundStation class */ - virtual void Update(const EarthRotation& celestial_rotation, const SampleSpacecraft& spacecraft); + virtual void Update(const environment::EarthRotation& celestial_rotation, const SampleSpacecraft& spacecraft); private: using GroundStation::Update; SampleGsComponents* components_; //!< Ground station related components }; +} // namespace s2e::sample + #endif // S2E_SIMULATION_SAMPLE_GROUND_STATION_SAMPLE_GROUND_STATION_HPP_ diff --git a/src/simulation_sample/ground_station/sample_ground_station_components.cpp b/src/simulation_sample/ground_station/sample_ground_station_components.cpp index bf7fbdbb6..45ba2ee24 100644 --- a/src/simulation_sample/ground_station/sample_ground_station_components.cpp +++ b/src/simulation_sample/ground_station/sample_ground_station_components.cpp @@ -6,15 +6,17 @@ #include -SampleGsComponents::SampleGsComponents(const SimulationConfiguration* configuration) : configuration_(configuration) { - IniAccess iniAccess = IniAccess(configuration_->ground_station_file_list_[0]); +namespace s2e::sample { + +SampleGsComponents::SampleGsComponents(const simulation::SimulationConfiguration* configuration) : configuration_(configuration) { + setting_file_reader::IniAccess iniAccess = setting_file_reader::IniAccess(configuration_->ground_station_file_list_[0]); std::string ant_ini_path = iniAccess.ReadString("COMPONENT_FILES", "ground_station_antenna_file"); configuration_->main_logger_->CopyFileToLogDirectory(ant_ini_path); - antenna_ = new Antenna(InitAntenna(1, ant_ini_path)); + antenna_ = new components::Antenna(components::InitAntenna(1, ant_ini_path)); std::string gs_calculator_ini_path = iniAccess.ReadString("COMPONENT_FILES", "ground_station_calculator_file"); configuration_->main_logger_->CopyFileToLogDirectory(gs_calculator_ini_path); - gs_calculator_ = new GroundStationCalculator(InitGsCalculator(gs_calculator_ini_path)); + gs_calculator_ = new components::GroundStationCalculator(components::InitGsCalculator(gs_calculator_ini_path)); } SampleGsComponents::~SampleGsComponents() { @@ -22,7 +24,9 @@ SampleGsComponents::~SampleGsComponents() { delete gs_calculator_; } -void SampleGsComponents::CompoLogSetUp(Logger& logger) { +void SampleGsComponents::CompoLogSetUp(logger::Logger& logger) { // logger.AddLogList(ant_); logger.AddLogList(gs_calculator_); } + +} // namespace s2e::sample 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 15f1632bb..35df9ce22 100644 --- a/src/simulation_sample/ground_station/sample_ground_station_components.hpp +++ b/src/simulation_sample/ground_station/sample_ground_station_components.hpp @@ -9,6 +9,8 @@ #include #include +namespace s2e::sample { + /** * @class SampleGsComponents * @brief An example of ground station related components list class @@ -19,7 +21,7 @@ class SampleGsComponents { * @fn SampleGsComponents * @brief Constructor */ - SampleGsComponents(const SimulationConfiguration* configuration); + SampleGsComponents(const simulation::SimulationConfiguration* configuration); /** * @fn ~SampleGsComponents * @brief Destructor @@ -29,24 +31,26 @@ class SampleGsComponents { * @fn CompoLogSetUp * @brief Log setup for ground station components */ - void CompoLogSetUp(Logger& logger); + void CompoLogSetUp(logger::Logger& logger); // Getter /** * @fn GetAntenna * @brief Return antenna */ - inline Antenna* GetAntenna() const { return antenna_; } + inline components::Antenna* GetAntenna() const { return antenna_; } /** * @fn GetGsCalculator * @brief Return ground station calculator */ - inline GroundStationCalculator* GetGsCalculator() const { return gs_calculator_; } + inline components::GroundStationCalculator* GetGsCalculator() const { return gs_calculator_; } private: - Antenna* antenna_; //!< Antenna on ground station - GroundStationCalculator* gs_calculator_; //!< Ground station calculation algorithm - const SimulationConfiguration* configuration_; //!< Simulation setting + components::Antenna* antenna_; //!< Antenna on ground station + components::GroundStationCalculator* gs_calculator_; //!< Ground station calculation algorithm + const simulation::SimulationConfiguration* configuration_; //!< Simulation setting }; +} // namespace s2e::sample + #endif // S2E_SIMULATION_SAMPLE_GROUND_STATION_SAMPLE_GROUND_STATION_COMPONENTS_HPP_ diff --git a/src/simulation_sample/spacecraft/sample_components.cpp b/src/simulation_sample/spacecraft/sample_components.cpp index b45d960c3..12cd92b38 100644 --- a/src/simulation_sample/spacecraft/sample_components.cpp +++ b/src/simulation_sample/spacecraft/sample_components.cpp @@ -9,15 +9,20 @@ #include "sample_port_configuration.hpp" -SampleComponents::SampleComponents(const Dynamics* dynamics, Structure* structure, const LocalEnvironment* local_environment, - const GlobalEnvironment* global_environment, const SimulationConfiguration* configuration, - ClockGenerator* clock_generator, const unsigned int spacecraft_id) +namespace s2e::sample { + +using namespace components; + +SampleComponents::SampleComponents(const dynamics::Dynamics* dynamics, spacecraft::Structure* structure, + const environment::LocalEnvironment* local_environment, const environment::GlobalEnvironment* global_environment, + const simulation::SimulationConfiguration* configuration, environment::ClockGenerator* clock_generator, + const unsigned int spacecraft_id) : configuration_(configuration), dynamics_(dynamics), structure_(structure), local_environment_(local_environment), global_environment_(global_environment) { - IniAccess iniAccess = IniAccess(configuration_->spacecraft_file_list_[spacecraft_id]); + setting_file_reader::IniAccess iniAccess = setting_file_reader::IniAccess(configuration_->spacecraft_file_list_[spacecraft_id]); // PCU power port connection pcu_ = new PowerControlUnit(clock_generator); @@ -27,7 +32,7 @@ SampleComponents::SampleComponents(const Dynamics* dynamics, Structure* structur // Components obc_ = new OnBoardComputer(1, clock_generator, pcu_->GetPowerPort(0)); - hils_port_manager_ = new HilsPortManager(); + hils_port_manager_ = new simulation::HilsPortManager(); // GyroSensor std::string file_name = iniAccess.ReadString("COMPONENT_FILES", "gyro_file"); @@ -206,7 +211,7 @@ math::Vector<3> SampleComponents::GenerateTorque_b_Nm() { void SampleComponents::ComponentInterference() { mtq_magnetometer_interference_->UpdateInterference(); } -void SampleComponents::LogSetup(Logger& logger) { +void SampleComponents::LogSetup(logger::Logger& logger) { logger.AddLogList(gyro_sensor_); logger.AddLogList(magnetometer_); logger.AddLogList(star_sensor_); @@ -222,3 +227,5 @@ void SampleComponents::LogSetup(Logger& logger) { logger.AddLogList(attitude_observer_); logger.AddLogList(orbit_observer_); } + +} // namespace s2e::sample diff --git a/src/simulation_sample/spacecraft/sample_components.hpp b/src/simulation_sample/spacecraft/sample_components.hpp index d03044b3b..11a534e95 100644 --- a/src/simulation_sample/spacecraft/sample_components.hpp +++ b/src/simulation_sample/spacecraft/sample_components.hpp @@ -34,6 +34,7 @@ #include #include +namespace s2e::components { class OnBoardComputer; class PowerControlUnit; class GyroSensor; @@ -49,20 +50,23 @@ class TorqueGenerator; class AngularVelocityObserver; class AttitudeObserver; class Telescope; +} // namespace s2e::components + +namespace s2e::sample { /** * @class SampleComponents * @brief An example of user side components management class */ -class SampleComponents : public InstalledComponents { +class SampleComponents : public spacecraft::InstalledComponents { public: /** * @fn SampleComponents * @brief Constructor */ - SampleComponents(const Dynamics* dynamics, Structure* structure, const LocalEnvironment* local_environment, - const GlobalEnvironment* global_environment, const SimulationConfiguration* configuration, ClockGenerator* clock_generator, - const unsigned int spacecraft_id); + SampleComponents(const dynamics::Dynamics* dynamics, spacecraft::Structure* structure, const environment::LocalEnvironment* local_environment, + const environment::GlobalEnvironment* global_environment, const simulation::SimulationConfiguration* configuration, + environment::ClockGenerator* clock_generator, const unsigned int spacecraft_id); /** * @fn ~SampleComponents * @brief Destructor @@ -90,41 +94,41 @@ class SampleComponents : public InstalledComponents { * @fn LogSetup * @brief Setup the logger for components */ - void LogSetup(Logger& logger) override; + void LogSetup(logger::Logger& logger) override; // Getter - inline Antenna& GetAntenna() const { return *antenna_; } + inline components::Antenna& GetAntenna() const { return *antenna_; } private: - PowerControlUnit* pcu_; //!< Power Control Unit - OnBoardComputer* obc_; //!< Onboard Computer - HilsPortManager* hils_port_manager_; //!< Port manager for HILS test + components::PowerControlUnit* pcu_; //!< Power Control Unit + components::OnBoardComputer* obc_; //!< Onboard Computer + simulation::HilsPortManager* hils_port_manager_; //!< Port manager for HILS test // AOCS - GyroSensor* gyro_sensor_; //!< GyroSensor sensor - Magnetometer* magnetometer_; //!< Magnetometer - StarSensor* star_sensor_; //!< Star sensor - SunSensor* sun_sensor_; //!< Sun sensor - GnssReceiver* gnss_receiver_; //!< GNSS receiver - Magnetorquer* magnetorquer_; //!< Magnetorquer - ReactionWheel* reaction_wheel_; //!< Reaction Wheel - SimpleThruster* thruster_; //!< Thruster + components::GyroSensor* gyro_sensor_; //!< GyroSensor sensor + components::Magnetometer* magnetometer_; //!< Magnetometer + components::StarSensor* star_sensor_; //!< Star sensor + components::SunSensor* sun_sensor_; //!< Sun sensor + components::GnssReceiver* gnss_receiver_; //!< GNSS receiver + components::Magnetorquer* magnetorquer_; //!< Magnetorquer + components::ReactionWheel* reaction_wheel_; //!< Reaction Wheel + components::SimpleThruster* thruster_; //!< Thruster // Ideal component - ForceGenerator* force_generator_; //!< Ideal Force Generator - TorqueGenerator* torque_generator_; //!< Ideal Torque Generator - AngularVelocityObserver* angular_velocity_observer_; //!< Ideal Angular velocity observer - AttitudeObserver* attitude_observer_; //!< Ideal Attitude observer - OrbitObserver* orbit_observer_; //!< Ideal Orbit observer + components::ForceGenerator* force_generator_; //!< Ideal Force Generator + components::TorqueGenerator* torque_generator_; //!< Ideal Torque Generator + components::AngularVelocityObserver* angular_velocity_observer_; //!< Ideal Angular velocity observer + components::AttitudeObserver* attitude_observer_; //!< Ideal Attitude observer + components::OrbitObserver* orbit_observer_; //!< Ideal Orbit observer // Mission - Telescope* telescope_; //!< Telescope + components::Telescope* telescope_; //!< Telescope // CommGs - Antenna* antenna_; //!< Antenna + components::Antenna* antenna_; //!< Antenna // Component Interference - MtqMagnetometerInterference* mtq_magnetometer_interference_; //!< Additional Bias noise by MTQ-Magnetometer interference + components::MtqMagnetometerInterference* mtq_magnetometer_interference_; //!< Additional Bias noise by MTQ-Magnetometer interference // Examples // ExampleChangeStructure* change_structure_; //!< Change structure @@ -136,11 +140,13 @@ class SampleComponents : public InstalledComponents { */ // States - const SimulationConfiguration* configuration_; //!< Simulation settings - const Dynamics* dynamics_; //!< Dynamics information of the spacecraft - Structure* structure_; //!< Structure information of the spacecraft - const LocalEnvironment* local_environment_; //!< Local environment information around the spacecraft - const GlobalEnvironment* global_environment_; //!< Global environment information + const simulation::SimulationConfiguration* configuration_; //!< Simulation settings + const dynamics::Dynamics* dynamics_; //!< Dynamics information of the spacecraft + spacecraft::Structure* structure_; //!< Structure information of the spacecraft + const environment::LocalEnvironment* local_environment_; //!< Local environment information around the spacecraft + const environment::GlobalEnvironment* global_environment_; //!< Global environment information }; +} // namespace s2e::sample + #endif // S2E_SIMULATION_SAMPLE_SPACECRAFT_SAMPLE_COMPONENTS_HPP_ diff --git a/src/simulation_sample/spacecraft/sample_port_configuration.hpp b/src/simulation_sample/spacecraft/sample_port_configuration.hpp index 413e22fce..dd67bddab 100644 --- a/src/simulation_sample/spacecraft/sample_port_configuration.hpp +++ b/src/simulation_sample/spacecraft/sample_port_configuration.hpp @@ -6,6 +6,8 @@ #ifndef S2E_SIMULATION_SAMPLE_SPACECRAFT_SAMPLE_PORT_CONFIGURATION_HPP_ #define S2E_SIMULATION_SAMPLE_SPACECRAFT_SAMPLE_PORT_CONFIGURATION_HPP_ +namespace s2e::sample { + /** * @enum PowerPortConfig * @brief ID list of electrical power switch ports @@ -27,4 +29,6 @@ enum class UARTPortConfig { kUartComponentMax //!< Maximum port number. Do not remove. Place on the bottom. }; +} // namespace s2e::sample + #endif // S2E_SIMULATION_SAMPLE_SPACECRAFT_SAMPLE_PORT_CONFIGURATION_HPP_ diff --git a/src/simulation_sample/spacecraft/sample_spacecraft.cpp b/src/simulation_sample/spacecraft/sample_spacecraft.cpp index 09c7df86c..4a4970ab6 100644 --- a/src/simulation_sample/spacecraft/sample_spacecraft.cpp +++ b/src/simulation_sample/spacecraft/sample_spacecraft.cpp @@ -10,10 +10,14 @@ #include "sample_components.hpp" -SampleSpacecraft::SampleSpacecraft(const SimulationConfiguration* simulation_configuration, const GlobalEnvironment* global_environment, - const unsigned int spacecraft_id) - : Spacecraft(simulation_configuration, global_environment, spacecraft_id) { +namespace s2e::sample { + +SampleSpacecraft::SampleSpacecraft(const simulation::SimulationConfiguration* simulation_configuration, + const environment::GlobalEnvironment* global_environment, const unsigned int spacecraft_id) + : spacecraft::Spacecraft(simulation_configuration, global_environment, spacecraft_id) { sample_components_ = new SampleComponents(dynamics_, structure_, local_environment_, global_environment, simulation_configuration, &clock_generator_, spacecraft_id); components_ = sample_components_; } + +} // namespace s2e::sample diff --git a/src/simulation_sample/spacecraft/sample_spacecraft.hpp b/src/simulation_sample/spacecraft/sample_spacecraft.hpp index 1436dbfe1..d745e1774 100644 --- a/src/simulation_sample/spacecraft/sample_spacecraft.hpp +++ b/src/simulation_sample/spacecraft/sample_spacecraft.hpp @@ -12,17 +12,19 @@ class SampleComponents; +namespace s2e::sample { + /** * @class SampleSpacecraft * @brief An example of user side spacecraft class */ -class SampleSpacecraft : public Spacecraft { +class SampleSpacecraft : public spacecraft::Spacecraft { public: /** * @fn SampleSpacecraft * @brief Constructor */ - SampleSpacecraft(const SimulationConfiguration* simulation_configuration, const GlobalEnvironment* global_environment, + SampleSpacecraft(const simulation::SimulationConfiguration* simulation_configuration, const environment::GlobalEnvironment* global_environment, const unsigned int spacecraft_id); /** @@ -35,4 +37,6 @@ class SampleSpacecraft : public Spacecraft { SampleComponents* sample_components_; }; +} // namespace s2e::sample + #endif // S2E_SIMULATION_SAMPLE_SPACECRAFT_SAMPLE_SPACECRAFT_HPP_ diff --git a/src/utilities/com_port_interface.cpp b/src/utilities/com_port_interface.cpp index ab15eb3ab..4644fa5c9 100644 --- a/src/utilities/com_port_interface.cpp +++ b/src/utilities/com_port_interface.cpp @@ -7,6 +7,8 @@ #include "com_port_interface.hpp" +namespace s2e::utilities { + ComPortInterface::ComPortInterface(int port_id, int baudrate, unsigned int tx_buffer_size, unsigned int rx_buffer_size) : kPortId(port_id), kPortName(PortName(port_id)), kBaudRate(baudrate), kTxBufferSize(tx_buffer_size), kRxBufferSize(rx_buffer_size) { // Allocate managed memory @@ -114,3 +116,5 @@ int ComPortInterface::DiscardInBuffer() { } return 0; } + +} // namespace s2e::utilities diff --git a/src/utilities/com_port_interface.hpp b/src/utilities/com_port_interface.hpp index 03ccd568b..3da5bd6eb 100644 --- a/src/utilities/com_port_interface.hpp +++ b/src/utilities/com_port_interface.hpp @@ -17,6 +17,9 @@ using namespace System; using namespace System::Runtime::InteropServices; + +namespace s2e::utilities { + typedef cli::array bytearray; /** @@ -105,4 +108,6 @@ class ComPortInterface { msclr::gcroot rx_buf_; //!< RX Buffer }; +} // namespace s2e::utilities + #endif // S2E_LIBRARY_COMMUNICATION_COM_PORT_INTERFACE_HPP_ diff --git a/src/utilities/endian.cpp b/src/utilities/endian.cpp index a20149b0c..6aa2111a1 100644 --- a/src/utilities/endian.cpp +++ b/src/utilities/endian.cpp @@ -7,6 +7,8 @@ #include +namespace s2e::utilities { + void *endian_memcpy(void *dst, const void *src, size_t size) { #ifdef IS_LITTLE_ENDIAN uint8_t *src_ = (uint8_t *)src; @@ -25,4 +27,6 @@ void *endian_memcpy(void *dst, const void *src, size_t size) { #else return memcpy(dst, src, size); #endif // IS_LITTLE_ENDIAN -} \ No newline at end of file +} + +} // namespace s2e::utilities diff --git a/src/utilities/endian.hpp b/src/utilities/endian.hpp index 27195efd1..0660d78f9 100644 --- a/src/utilities/endian.hpp +++ b/src/utilities/endian.hpp @@ -11,6 +11,8 @@ #include "endian_define.hpp" // for IS_LITTLE_ENDIAN +namespace s2e::utilities { + /** * @fn endian_memcpy * @brief Memory copy considering endian @@ -20,4 +22,6 @@ */ void *endian_memcpy(void *dst, const void *src, size_t count); +} // namespace s2e::utilities + #endif // S2E_LIBRARY_UTILITIES_ENDIAN_HPP_ diff --git a/src/utilities/macros.hpp b/src/utilities/macros.hpp index 308db3cd8..cbd37f012 100644 --- a/src/utilities/macros.hpp +++ b/src/utilities/macros.hpp @@ -6,6 +6,10 @@ #ifndef S2E_LIBRARY_UTILITIES_MACROS_HPP_ #define S2E_LIBRARY_UTILITIES_MACROS_HPP_ +namespace s2e::utilities { + #define UNUSED(x) (void)(x) //!< Macro to avoid unused warnings +} // namespace s2e::utilities + #endif // S2E_LIBRARY_UTILITIES_MACROS_HPP_ diff --git a/src/utilities/quantization.cpp b/src/utilities/quantization.cpp index 114c0e2fe..1cfd3268e 100644 --- a/src/utilities/quantization.cpp +++ b/src/utilities/quantization.cpp @@ -5,9 +5,13 @@ #include "quantization.hpp" +namespace s2e::utilities { + double quantization(const double continuous_number, const double resolution) { int bin_num = (int)((double)continuous_number / resolution); return (double)bin_num * resolution; } float quantization_float(const double continuous_number, const double resolution) { return (float)quantization(continuous_number, resolution); } + +} // namespace s2e::utilities diff --git a/src/utilities/quantization.hpp b/src/utilities/quantization.hpp index f23eebdeb..9fd075e3b 100644 --- a/src/utilities/quantization.hpp +++ b/src/utilities/quantization.hpp @@ -6,6 +6,8 @@ #ifndef S2E_LIBRARY_UTILITIES_QUANTIZATION_HPP_ #define S2E_LIBRARY_UTILITIES_QUANTIZATION_HPP_ +namespace s2e::utilities { + /** * @fn quantization * @brief Default constructor without any initialization @@ -24,4 +26,6 @@ double quantization(const double continuous_number, const double resolution); */ float quantization_float(const double continuous_number, const double resolution); +} // namespace s2e::utilities + #endif // S2E_LIBRARY_UTILITIES_QUANTIZATION_HPP_ diff --git a/src/utilities/ring_buffer.cpp b/src/utilities/ring_buffer.cpp index d89f10204..40aed8adb 100644 --- a/src/utilities/ring_buffer.cpp +++ b/src/utilities/ring_buffer.cpp @@ -10,6 +10,8 @@ #include #include +namespace s2e::utilities { + RingBuffer::RingBuffer(int buffer_size) : buffer_size_(buffer_size) { buffer_ = new byte[buffer_size]; write_pointer_ = 0; @@ -44,3 +46,5 @@ int RingBuffer::Read(byte* buffer, const unsigned int offset, const unsigned int return read_count; } + +} // namespace s2e::utilities diff --git a/src/utilities/ring_buffer.hpp b/src/utilities/ring_buffer.hpp index 3e133de26..3855c8179 100644 --- a/src/utilities/ring_buffer.hpp +++ b/src/utilities/ring_buffer.hpp @@ -6,6 +6,8 @@ #ifndef S2E_LIBRARY_UTILITIES_RING_BUFFER_HPP_ #define S2E_LIBRARY_UTILITIES_RING_BUFFER_HPP_ +namespace s2e::utilities { + typedef unsigned char byte; /** @@ -52,4 +54,6 @@ class RingBuffer { unsigned int write_pointer_; //!< Write pointer }; +} // namespace s2e::utilities + #endif // S2E_LIBRARY_UTILITIES_RING_BUFFER_HPP_ diff --git a/src/utilities/slip.cpp b/src/utilities/slip.cpp index 6f2192409..b1f0fbb03 100644 --- a/src/utilities/slip.cpp +++ b/src/utilities/slip.cpp @@ -8,6 +8,8 @@ #include #include +namespace s2e::utilities { + static uint8_t kSlipFend_ = 0xc0; //!< FEND: Frame End static uint8_t kSlipFesc_ = 0xdb; //!< FESC: Frame Escape static uint8_t kSlipTfend_ = 0xdc; //!< TFEND: Transposed Frame End @@ -77,3 +79,5 @@ std::vector encode_slip_with_header(const std::vector in) { out.insert(out.begin(), kSlipFend_); return out; } + +} // namespace s2e::utilities diff --git a/src/utilities/slip.hpp b/src/utilities/slip.hpp index b5355bb5d..da9e222d5 100644 --- a/src/utilities/slip.hpp +++ b/src/utilities/slip.hpp @@ -10,6 +10,8 @@ #include +namespace s2e::utilities { + /** * @fn decode_slip * @brief Decode SLIP data @@ -40,4 +42,6 @@ std::vector encode_slip(std::vector in); */ std::vector encode_slip_with_header(std::vector in); +} // namespace s2e::utilities + #endif // S2E_LIBRARY_UTILITIES_SLIP_HPP_