diff --git a/CMakeLists.txt b/CMakeLists.txt index fcbb6eec9..3ccb6f546 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,12 @@ cmake_policy(SET CMP0048 NEW) +cmake_minimum_required(VERSION 3.13) + project(S2E LANGUAGES CXX DESCRIPTION "S2E: Spacecraft Simulation Environment" VERSION 6.4.0 ) -cmake_minimum_required(VERSION 3.13) - # build config option(USE_HILS "Use HILS" OFF) option(USE_C2A "Use C2A" OFF) diff --git a/src/components/real/communication/antenna.cpp b/src/components/real/communication/antenna.cpp index 6459cb947..3941e1690 100644 --- a/src/components/real/communication/antenna.cpp +++ b/src/components/real/communication/antenna.cpp @@ -5,7 +5,6 @@ #include "antenna.hpp" -#define _CRT_SECURE_NO_WARNINGS #include #include @@ -109,35 +108,31 @@ AntennaGainModel SetAntennaGainModel(const std::string gain_model_name) { Antenna InitAntenna(const int antenna_id, const std::string file_name) { IniAccess antenna_conf(file_name); - const std::string st_antenna_id = std::to_string(static_cast(antenna_id)); - const char* cs = st_antenna_id.data(); - - char Section[30] = "ANTENNA_"; - strcat(Section, cs); + const std::string section_name = "ANTENNA_" + std::to_string(static_cast(antenna_id)); Quaternion quaternion_b2c; - antenna_conf.ReadQuaternion(Section, "quaternion_b2c", quaternion_b2c); + antenna_conf.ReadQuaternion(section_name.c_str(), "quaternion_b2c", quaternion_b2c); - bool is_transmitter = antenna_conf.ReadBoolean(Section, "is_transmitter"); - bool is_receiver = antenna_conf.ReadBoolean(Section, "is_receiver"); - double frequency_MHz = antenna_conf.ReadDouble(Section, "frequency_MHz"); + bool is_transmitter = antenna_conf.ReadBoolean(section_name.c_str(), "is_transmitter"); + bool is_receiver = antenna_conf.ReadBoolean(section_name.c_str(), "is_receiver"); + double frequency_MHz = antenna_conf.ReadDouble(section_name.c_str(), "frequency_MHz"); - double tx_bitrate_bps = antenna_conf.ReadDouble(Section, "tx_bitrate_bps"); - double tx_output_power_W = antenna_conf.ReadDouble(Section, "tx_output_W"); - double rx_system_noise_temperature_K = antenna_conf.ReadDouble(Section, "rx_system_noise_temperature_K"); + double tx_bitrate_bps = antenna_conf.ReadDouble(section_name.c_str(), "tx_bitrate_bps"); + double tx_output_power_W = antenna_conf.ReadDouble(section_name.c_str(), "tx_output_W"); + double rx_system_noise_temperature_K = antenna_conf.ReadDouble(section_name.c_str(), "rx_system_noise_temperature_K"); AntennaParameters tx_parameters; if (is_transmitter) { - tx_parameters.gain_dBi_ = antenna_conf.ReadDouble(Section, "tx_gain_dBi"); - tx_parameters.loss_feeder_dB_ = antenna_conf.ReadDouble(Section, "tx_loss_feeder_dB"); - tx_parameters.loss_pointing_dB_ = antenna_conf.ReadDouble(Section, "tx_loss_pointing_dB"); - tx_parameters.antenna_gain_model = SetAntennaGainModel(antenna_conf.ReadString(Section, "tx_antenna_gain_model")); - size_t length_theta = antenna_conf.ReadInt(Section, "tx_length_theta"); - size_t length_phi = antenna_conf.ReadInt(Section, "tx_length_phi"); - double theta_max_rad = antenna_conf.ReadDouble(Section, "tx_theta_max_rad"); - double phi_max_rad = antenna_conf.ReadDouble(Section, "tx_phi_max_rad"); - tx_parameters.radiation_pattern = AntennaRadiationPattern(antenna_conf.ReadString(Section, "tx_antenna_radiation_pattern_file"), length_theta, - length_phi, theta_max_rad, phi_max_rad); + tx_parameters.gain_dBi_ = antenna_conf.ReadDouble(section_name.c_str(), "tx_gain_dBi"); + tx_parameters.loss_feeder_dB_ = antenna_conf.ReadDouble(section_name.c_str(), "tx_loss_feeder_dB"); + tx_parameters.loss_pointing_dB_ = antenna_conf.ReadDouble(section_name.c_str(), "tx_loss_pointing_dB"); + tx_parameters.antenna_gain_model = SetAntennaGainModel(antenna_conf.ReadString(section_name.c_str(), "tx_antenna_gain_model")); + size_t length_theta = antenna_conf.ReadInt(section_name.c_str(), "tx_length_theta"); + size_t length_phi = antenna_conf.ReadInt(section_name.c_str(), "tx_length_phi"); + double theta_max_rad = antenna_conf.ReadDouble(section_name.c_str(), "tx_theta_max_rad"); + double phi_max_rad = antenna_conf.ReadDouble(section_name.c_str(), "tx_phi_max_rad"); + tx_parameters.radiation_pattern = AntennaRadiationPattern(antenna_conf.ReadString(section_name.c_str(), "tx_antenna_radiation_pattern_file"), + length_theta, length_phi, theta_max_rad, phi_max_rad); } else { tx_parameters.gain_dBi_ = 0.0; tx_parameters.loss_feeder_dB_ = 0.0; @@ -147,17 +142,17 @@ Antenna InitAntenna(const int antenna_id, const std::string file_name) { AntennaParameters rx_parameters; if (is_receiver) { - rx_parameters.gain_dBi_ = antenna_conf.ReadDouble(Section, "rx_gain_dBi"); - rx_parameters.loss_feeder_dB_ = antenna_conf.ReadDouble(Section, "rx_loss_feeder_dB"); - rx_parameters.loss_pointing_dB_ = antenna_conf.ReadDouble(Section, "rx_loss_pointing_dB"); - rx_parameters.antenna_gain_model = SetAntennaGainModel(antenna_conf.ReadString(Section, "rx_antenna_gain_model")); - rx_parameters.radiation_pattern = AntennaRadiationPattern(antenna_conf.ReadString(Section, "rx_antenna_radiation_pattern_file")); - size_t length_theta = antenna_conf.ReadInt(Section, "rx_length_theta"); - size_t length_phi = antenna_conf.ReadInt(Section, "rx_length_phi"); - double theta_max_rad = antenna_conf.ReadDouble(Section, "rx_theta_max_rad"); - double phi_max_rad = antenna_conf.ReadDouble(Section, "rx_phi_max_rad"); - rx_parameters.radiation_pattern = AntennaRadiationPattern(antenna_conf.ReadString(Section, "rx_antenna_radiation_pattern_file"), length_theta, - length_phi, theta_max_rad, phi_max_rad); + rx_parameters.gain_dBi_ = antenna_conf.ReadDouble(section_name.c_str(), "rx_gain_dBi"); + rx_parameters.loss_feeder_dB_ = antenna_conf.ReadDouble(section_name.c_str(), "rx_loss_feeder_dB"); + rx_parameters.loss_pointing_dB_ = antenna_conf.ReadDouble(section_name.c_str(), "rx_loss_pointing_dB"); + rx_parameters.antenna_gain_model = SetAntennaGainModel(antenna_conf.ReadString(section_name.c_str(), "rx_antenna_gain_model")); + rx_parameters.radiation_pattern = AntennaRadiationPattern(antenna_conf.ReadString(section_name.c_str(), "rx_antenna_radiation_pattern_file")); + size_t length_theta = antenna_conf.ReadInt(section_name.c_str(), "rx_length_theta"); + size_t length_phi = antenna_conf.ReadInt(section_name.c_str(), "rx_length_phi"); + double theta_max_rad = antenna_conf.ReadDouble(section_name.c_str(), "rx_theta_max_rad"); + double phi_max_rad = antenna_conf.ReadDouble(section_name.c_str(), "rx_phi_max_rad"); + rx_parameters.radiation_pattern = AntennaRadiationPattern(antenna_conf.ReadString(section_name.c_str(), "rx_antenna_radiation_pattern_file"), + length_theta, length_phi, theta_max_rad, phi_max_rad); } else { rx_parameters.gain_dBi_ = 0.0; rx_parameters.loss_feeder_dB_ = 0.0; diff --git a/src/components/real/power/battery.cpp b/src/components/real/power/battery.cpp index d1e16af5d..072f55fc5 100644 --- a/src/components/real/power/battery.cpp +++ b/src/components/real/power/battery.cpp @@ -77,11 +77,11 @@ void Battery::MainRoutine(const int time_count) { } void Battery::UpdateBatVoltage() { - double cell_discharge_capasity = depth_of_discharge_percent_ / 100.0 * cell_capacity_Ah_; + double cell_discharge_capacity = depth_of_discharge_percent_ / 100.0 * cell_capacity_Ah_; double temp = 0.0; int index = 0; for (auto coeff : cell_discharge_curve_coefficients_) { - temp += coeff * std::pow(cell_discharge_capasity, index); + temp += coeff * std::pow(cell_discharge_capacity, index); ++index; } battery_voltage_V_ = temp * number_of_series_; @@ -90,44 +90,40 @@ void Battery::UpdateBatVoltage() { Battery InitBAT(ClockGenerator* clock_generator, int bat_id, const std::string file_name, double component_step_time_s) { IniAccess bat_conf(file_name); - const std::string st_bat_id = std::to_string(bat_id); - const char* cs = st_bat_id.data(); + const std::string section_name = "BATTERY_" + std::to_string(static_cast(bat_id)); - char Section[30] = "BATTERY_"; - strcat(Section, cs); - - int prescaler = bat_conf.ReadInt(Section, "prescaler"); + int prescaler = bat_conf.ReadInt(section_name.c_str(), "prescaler"); if (prescaler <= 1) prescaler = 1; int number_of_series; - number_of_series = bat_conf.ReadInt(Section, "number_of_series"); + number_of_series = bat_conf.ReadInt(section_name.c_str(), "number_of_series"); int number_of_parallel; - number_of_parallel = bat_conf.ReadInt(Section, "number_of_parallel"); + number_of_parallel = bat_conf.ReadInt(section_name.c_str(), "number_of_parallel"); double cell_capacity_Ah; - cell_capacity_Ah = bat_conf.ReadDouble(Section, "cell_capacity_Ah"); + cell_capacity_Ah = bat_conf.ReadDouble(section_name.c_str(), "cell_capacity_Ah"); int approx_order; - approx_order = bat_conf.ReadInt(Section, "approximation_order"); + approx_order = bat_conf.ReadInt(section_name.c_str(), "approximation_order"); std::vector cell_discharge_curve_coefficients; for (int i = 0; i <= approx_order; ++i) { cell_discharge_curve_coefficients.push_back( - bat_conf.ReadDouble(Section, ("cell_discharge_curve_coefficients(" + std::to_string(i) + ")").c_str())); + bat_conf.ReadDouble(section_name.c_str(), ("cell_discharge_curve_coefficients(" + std::to_string(i) + ")").c_str())); } double initial_dod; - initial_dod = bat_conf.ReadDouble(Section, "initial_dod"); + initial_dod = bat_conf.ReadDouble(section_name.c_str(), "initial_dod"); double cc_charge_c_rate; - cc_charge_c_rate = bat_conf.ReadDouble(Section, "constant_charge_current_A_rate_C"); + cc_charge_c_rate = bat_conf.ReadDouble(section_name.c_str(), "constant_charge_current_A_rate_C"); double cv_charge_voltage_V; - cv_charge_voltage_V = bat_conf.ReadDouble(Section, "constant_voltage_charge_voltage_V"); + cv_charge_voltage_V = bat_conf.ReadDouble(section_name.c_str(), "constant_voltage_charge_voltage_V"); double battery_resistance_Ohm; - battery_resistance_Ohm = bat_conf.ReadDouble(Section, "battery_resistance_Ohm"); + battery_resistance_Ohm = bat_conf.ReadDouble(section_name.c_str(), "battery_resistance_Ohm"); Battery battery(prescaler, clock_generator, number_of_series, number_of_parallel, cell_capacity_Ah, cell_discharge_curve_coefficients, initial_dod, cc_charge_c_rate, cv_charge_voltage_V, battery_resistance_Ohm, component_step_time_s); diff --git a/src/components/real/power/pcu_initial_study.cpp b/src/components/real/power/pcu_initial_study.cpp index c50f539b4..d7249bd11 100644 --- a/src/components/real/power/pcu_initial_study.cpp +++ b/src/components/real/power/pcu_initial_study.cpp @@ -115,13 +115,9 @@ PcuInitialStudy InitPCU_InitialStudy(ClockGenerator* clock_generator, int pcu_id const std::vector saps, Battery* battery, double component_step_time_s) { IniAccess pcu_conf(file_name); - const std::string st_pcu_id = std::to_string(pcu_id); - const char* cs = st_pcu_id.data(); + const std::string section_name = "PCU_INITIAL_STUDY_" + std::to_string(static_cast(pcu_id)); - char Section[30] = "PCU_INITIAL_STUDY_"; - strcat(Section, cs); - - int prescaler = pcu_conf.ReadInt(Section, "prescaler"); + int prescaler = pcu_conf.ReadInt(section_name.c_str(), "prescaler"); if (prescaler <= 1) prescaler = 1; PcuInitialStudy pcu(prescaler, clock_generator, saps, battery, component_step_time_s); diff --git a/src/components/real/power/solar_array_panel.cpp b/src/components/real/power/solar_array_panel.cpp index 2ed2a9698..b693e36e6 100644 --- a/src/components/real/power/solar_array_panel.cpp +++ b/src/components/real/power/solar_array_panel.cpp @@ -119,32 +119,28 @@ SolarArrayPanel InitSAP(ClockGenerator* clock_generator, int sap_id, const std:: double component_step_time_s) { IniAccess sap_conf(file_name); - const std::string st_sap_id = std::to_string(sap_id); - const char* cs = st_sap_id.data(); + const std::string section_name = "SOLAR_ARRAY_PANEL_" + std::to_string(static_cast(sap_id)); - char Section[30] = "SOLAR_ARRAY_PANEL_"; - strcat(Section, cs); - - int prescaler = sap_conf.ReadInt(Section, "prescaler"); + int prescaler = sap_conf.ReadInt(section_name.c_str(), "prescaler"); if (prescaler <= 1) prescaler = 1; int number_of_series; - number_of_series = sap_conf.ReadInt(Section, "number_of_series"); + number_of_series = sap_conf.ReadInt(section_name.c_str(), "number_of_series"); int number_of_parallel; - number_of_parallel = sap_conf.ReadInt(Section, "number_of_parallel"); + number_of_parallel = sap_conf.ReadInt(section_name.c_str(), "number_of_parallel"); double cell_area_m2; - cell_area_m2 = sap_conf.ReadDouble(Section, "cell_area_m2"); + cell_area_m2 = sap_conf.ReadDouble(section_name.c_str(), "cell_area_m2"); libra::Vector<3> normal_vector; - sap_conf.ReadVector(Section, "normal_vector_b", normal_vector); + sap_conf.ReadVector(section_name.c_str(), "normal_vector_b", normal_vector); double cell_efficiency; - cell_efficiency = sap_conf.ReadDouble(Section, "cell_efficiency"); + cell_efficiency = sap_conf.ReadDouble(section_name.c_str(), "cell_efficiency"); double transmission_efficiency; - transmission_efficiency = sap_conf.ReadDouble(Section, "transmission_efficiency"); + transmission_efficiency = sap_conf.ReadDouble(section_name.c_str(), "transmission_efficiency"); SolarArrayPanel sap(prescaler, clock_generator, sap_id, number_of_series, number_of_parallel, cell_area_m2, normal_vector, cell_efficiency, transmission_efficiency, srp_environment, local_celestial_information, component_step_time_s); @@ -156,32 +152,28 @@ SolarArrayPanel InitSAP(ClockGenerator* clock_generator, int sap_id, const std:: const SolarRadiationPressureEnvironment* srp_environment, double component_step_time_s) { IniAccess sap_conf(file_name); - const std::string st_sap_id = std::to_string(sap_id); - const char* cs = st_sap_id.data(); - - char Section[30] = "SOLAR_ARRAY_PANEL_"; - strcat(Section, cs); + const std::string section_name = "SOLAR_ARRAY_PANEL_" + std::to_string(static_cast(sap_id)); - int prescaler = sap_conf.ReadInt(Section, "prescaler"); + int prescaler = sap_conf.ReadInt(section_name.c_str(), "prescaler"); if (prescaler <= 1) prescaler = 1; int number_of_series; - number_of_series = sap_conf.ReadInt(Section, "number_of_series"); + number_of_series = sap_conf.ReadInt(section_name.c_str(), "number_of_series"); int number_of_parallel; - number_of_parallel = sap_conf.ReadInt(Section, "number_of_parallel"); + number_of_parallel = sap_conf.ReadInt(section_name.c_str(), "number_of_parallel"); double cell_area_m2; - cell_area_m2 = sap_conf.ReadDouble(Section, "cell_area_m2"); + cell_area_m2 = sap_conf.ReadDouble(section_name.c_str(), "cell_area_m2"); libra::Vector<3> normal_vector; - sap_conf.ReadVector(Section, "normal_vector_b", normal_vector); + sap_conf.ReadVector(section_name.c_str(), "normal_vector_b", normal_vector); double cell_efficiency; - cell_efficiency = sap_conf.ReadDouble(Section, "cell_efficiency"); + cell_efficiency = sap_conf.ReadDouble(section_name.c_str(), "cell_efficiency"); double transmission_efficiency; - transmission_efficiency = sap_conf.ReadDouble(Section, "transmission_efficiency"); + transmission_efficiency = sap_conf.ReadDouble(section_name.c_str(), "transmission_efficiency"); SolarArrayPanel sap(prescaler, clock_generator, sap_id, number_of_series, number_of_parallel, cell_area_m2, normal_vector, cell_efficiency, transmission_efficiency, srp_environment, component_step_time_s); diff --git a/src/dynamics/thermal/heater.cpp b/src/dynamics/thermal/heater.cpp index 2399f2b65..2ed6a4135 100644 --- a/src/dynamics/thermal/heater.cpp +++ b/src/dynamics/thermal/heater.cpp @@ -4,7 +4,7 @@ using namespace std; -Heater::Heater(const unsigned int heater_id, const double power_rating_W) : heater_id_(heater_id), power_rating_W_(power_rating_W) { +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; power_output_W_ = 0; diff --git a/src/dynamics/thermal/heater.hpp b/src/dynamics/thermal/heater.hpp index c858a3951..e981b1fe3 100644 --- a/src/dynamics/thermal/heater.hpp +++ b/src/dynamics/thermal/heater.hpp @@ -34,7 +34,7 @@ class Heater { * @param [in] heater_id * @param [in] power_rating_W: Power Rating (100% Duty Output) of Heater [W] */ - Heater(const unsigned int heater_id, const double power_rating_W); + Heater(const size_t heater_id, const double power_rating_W); /** * @fn ~Heater * @brief Destroy the Heater object @@ -46,7 +46,7 @@ class Heater { * @fn GetHeaterID * @brief Return Heater Id */ - inline int GetHeaterId(void) const { return heater_id_; } + inline size_t GetHeaterId(void) const { return heater_id_; } /** * @fn GetPowerRating_W * @brief Return power rating [W] @@ -78,8 +78,8 @@ class Heater { void PrintParam(void); protected: - unsigned int heater_id_; // heater id (Use values over 1) - double power_rating_W_; // Power Rating (100% Duty) [W] + size_t heater_id_; // heater id (Use values over 1) + double power_rating_W_; // Power Rating (100% Duty) [W] HeaterStatus heater_status_; // Power Status of Heater double power_output_W_; // Power Output of Heater [W] diff --git a/src/environment/global/gnss_satellites.cpp b/src/environment/global/gnss_satellites.cpp index e12f979af..dbda420ea 100644 --- a/src/environment/global/gnss_satellites.cpp +++ b/src/environment/global/gnss_satellites.cpp @@ -376,8 +376,8 @@ void GnssSat_position::SetUp(const double start_unix_time, const double step_sec continue; } - int index = lower_bound(unixtime_vector_.at(gnss_satellite_id).begin(), unixtime_vector_.at(gnss_satellite_id).end(), start_unix_time) - - unixtime_vector_.at(gnss_satellite_id).begin(); + int index = (int)(lower_bound(unixtime_vector_.at(gnss_satellite_id).begin(), unixtime_vector_.at(gnss_satellite_id).end(), start_unix_time) - + unixtime_vector_.at(gnss_satellite_id).begin()); if (index == (int)unixtime_vector_.at(gnss_satellite_id).size()) { nearest_index_.at(gnss_satellite_id) = index; validate_.at(gnss_satellite_id) = false; @@ -673,8 +673,8 @@ void GnssSat_clock::SetUp(const double start_unix_time, const double step_sec) { continue; } - int index = lower_bound(unixtime_vector_.at(gnss_satellite_id).begin(), unixtime_vector_.at(gnss_satellite_id).end(), start_unix_time) - - unixtime_vector_.at(gnss_satellite_id).begin(); + int index = (int)(lower_bound(unixtime_vector_.at(gnss_satellite_id).begin(), unixtime_vector_.at(gnss_satellite_id).end(), start_unix_time) - + unixtime_vector_.at(gnss_satellite_id).begin()); if (index == (int)unixtime_vector_.at(gnss_satellite_id).size()) { validate_.at(gnss_satellite_id) = false; nearest_index_.at(gnss_satellite_id) = index;