diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..98270ff2a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,15 @@ +* text=auto + +*.md text +*.txt text +*.json text + +*.cpp text +*.h text +*.hpp text + +*.sh text eol=lf +*.bat text eol=crlf + +*.ini text +*.csv text diff --git a/CMakeLists.txt b/CMakeLists.txt index 28f8c43c3..a43b64af7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,18 @@ if(USE_C2A) add_subdirectory(${C2A_DIR} C2A) endif() +## options to use HILS +option(USE_HILS "Use HILS") +set(USE_HILS OFF) +if(USE_HILS AND WIN32) + add_definitions(-DUSE_HILS) + ## winsock2 + SET (CMAKE_FIND_LIBRARY_SUFFIXES ".lib") + find_library(WS2_32_LIB ws2_32.lib) + message("path for winsock2 is") + message(${WS2_32_LIB}) +endif() + ## include directories include_directories(${CSPICE_DIR}/include) include_directories(${NRLMSISE00_DIR}/src) @@ -49,6 +61,7 @@ add_subdirectory(src/RelativeInformation) add_subdirectory(src/Interface/InitInput) add_subdirectory(src/Interface/LogOutput) add_subdirectory(src/Interface/SpacecraftInOut) +add_subdirectory(src/Interface/HilsInOut) add_subdirectory(src/Library/igrf) add_subdirectory(src/Library/inih) add_subdirectory(src/Library/math) @@ -57,7 +70,6 @@ add_subdirectory(src/Library/sgp4) add_subdirectory(src/Library/utils) add_subdirectory(src/Library/optics) add_subdirectory(src/Library/RelativeOrbit) -#add_subdirectory(src/Interface/HilsInOut) set(SOURCE_FILES src/S2E.cpp @@ -137,17 +149,7 @@ target_link_libraries(${PROJECT_NAME} GLOBAL_ENVIRONMENT LOCAL_ENVIRONMENT) target_link_libraries(${PROJECT_NAME} RELATIVE_INFO) target_link_libraries(${PROJECT_NAME} INI_ACC LOG_OUT SC_IO) target_link_libraries(${PROJECT_NAME} COMPONENT) - -## HILS -if (WIN32) -# target_link_libraries(${PROJECT_NAME} HILS_IO) - ## winsock2 - #SET (CMAKE_FIND_LIBRARY_SUFFIXES ".lib") - #find_library(WS2_32_LIB ws2_32.lib) - #message("path for winsock2 is") - #message(${WS2_32_LIB}) -# target_link_libraries(${PROJECT_NAME} ${WS2_32_LIB}) -endif() +target_link_libraries(${PROJECT_NAME} HILS_IO) ## C2A integration if(USE_C2A) @@ -155,6 +157,21 @@ if(USE_C2A) target_link_libraries(${PROJECT_NAME} SC_IO) endif() +## HILS +if(USE_HILS) + target_link_libraries(${PROJECT_NAME} ${WS2_32_LIB}) + set_target_properties(${PROJECT_NAME} PROPERTIES COMMON_LANGUAGE_RUNTIME "") + set_target_properties(COMPONENT PROPERTIES COMMON_LANGUAGE_RUNTIME "") + set_target_properties(DYNAMICS PROPERTIES COMMON_LANGUAGE_RUNTIME "") + set_target_properties(DISTURBANCE PROPERTIES COMMON_LANGUAGE_RUNTIME "") + set_target_properties(SIMULATION PROPERTIES COMMON_LANGUAGE_RUNTIME "") + set_target_properties(GLOBAL_ENVIRONMENT PROPERTIES COMMON_LANGUAGE_RUNTIME "") + set_target_properties(LOCAL_ENVIRONMENT PROPERTIES COMMON_LANGUAGE_RUNTIME "") + set_target_properties(INI_IN PROPERTIES COMMON_LANGUAGE_RUNTIME "") + set_target_properties(HILS_IO PROPERTIES COMMON_LANGUAGE_RUNTIME "") + set_target_properties(RELATIVE_INFO PROPERTIES COMMON_LANGUAGE_RUNTIME "") +endif() + ## Cmake debug message("Cspice_LIB: " ${CSPICE_LIB}) message("nrlmsise00_LIB: " ${NRLMSISE00_LIB}) diff --git a/CMakeSettings.json b/CMakeSettings.json index 8995927c6..431847fbf 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -7,7 +7,6 @@ "inheritEnvironments": [ "msvc_x86" ], - //"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", "buildRoot": "${thisFileDir}\\CMakeBuilds", "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", "cmakeCommandArgs": "", diff --git a/LICENSE b/LICENSE index 4bd93920c..89f748ff8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,18 +1,21 @@ -現時点ではフルオープンではないので厳密なライセンスは規定していませんが,次の点を守っていただきたいと考えております. -- 無断二次配布禁止 -- 商用利用は事前に相談 -- 更新があればISSL_OSSに反映させる -- 何か不具合があってもISSLは責任を負わない -- 成果を発表する時には謝辞に入れてもらう -- 特許,著作権など気になる場合は要相談 +MIT License -その他ライセンスに関して気になるところがあれば,#management チャンネルでご質問ください. +Copyright (c) 2021 Intelligent Space Systems Laboratory, The University of Tokyo -Currently, ISSL doesn't have a strict license because the codes are not fully opened. -However, ISSL require all users to accept following points. -- Secondary distribution prohibited -- Discuss with ISSL members before commercial use -- Useful modification should be commited to the ISSL_OSS repositories -- ISSL is not responsible any failure related with the codes -- When you publish papers or official documents with results from ISSL_OSS source codes, please refer this activity as acknowledgement in the document -- If you have any questions about license, patent, and copyright, pleaase ask ISSL members. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/data/SampleSat/ini/SampleDisturbance.ini b/data/SampleSat/ini/SampleDisturbance.ini index eff7f99d6..d4e54ef4d 100644 --- a/data/SampleSat/ini/SampleDisturbance.ini +++ b/data/SampleSat/ini/SampleDisturbance.ini @@ -4,34 +4,43 @@ logging = ENABLE degree = 4 file_path = ../../../ExtLibraries/GeoPotential/egm96_to360.ascii + [MAG_DISTURBANCE] calculation = ENABLE logging = ENABLE + [AIRDRAG] calculation = ENABLE logging = ENABLE -//Condition of air drag -Temp_wall = 30 //Surface Temperature[degC] -Temp_molecular = 3 //Atmosphere Temperature[degC] -//Note: they are converted in unit [K] inside the codes -Molecular = 18.0 //Molecular weight of the thermosphere[g/mol] + +// Condition of air drag +Temp_wall = 30 // Surface Temperature[degC] +Temp_molecular = 3 // Atmosphere Temperature[degC] + +// Note: they are converted in unit [K] inside the codes +Molecular = 18.0 // Molecular weight of the thermosphere[g/mol] + [SRDIST] calculation = ENABLE logging = ENABLE + [GRAVITY_GRADIENT] calculation = ENABLE logging = ENABLE + [THIRD_BODY_GRAVITY] calculation = DISABLE logging = ENABLE -//The number of gravity-generating bodies other than the central body + +// The number of gravity-generating bodies other than the central body num_of_third_body = 1 -//List of gravity-generating bodies other than the central body -//All these bodies must be included in the "selected_body" of "PlanetSelect.ini" + +// List of gravity-generating bodies other than the central body +// All these bodies must be included in the "selected_body" of "PlanetSelect.ini" third_body(0) = SUN third_body(1) = MOON third_body(2) = MARS diff --git a/data/SampleSat/ini/SampleGNSS.ini b/data/SampleSat/ini/SampleGNSS.ini index 92b67fba2..8b978c033 100644 --- a/data/SampleSat/ini/SampleGNSS.ini +++ b/data/SampleSat/ini/SampleGNSS.ini @@ -2,54 +2,50 @@ directory_path = ../../../ExtLibraries/sp3/ calculation = DISABLE -true_position_file_sort = IGS -//choose from IGS, IGR, IGU, -// CODE_Final, CODE_Rapid, CODE_Ultra_rapid, -// JAXA_Final, JAXA_Rapid, JAXA_Ultra_rapid, madocaRT, -// QZSS_Final, QZSS_Rapid, QZSS_Ultra_rapid -true_position_first = igs21233.sp3 -//As small as possible within the range. -true_position_last = igs21233.sp3 +true_position_file_sort = IGS +// choose from IGS, CODE_Final, JAXA_Final, QZSS_Final +// As small as possible within the range. +true_position_first = igs21610.sp3 +true_position_last = igs21613.sp3 true_position_interpolation_method = 1 -//choose from 0: Lagrange, 1: Trigonometric : temporarily, only Trigonometric is valid, Lagrange is not yet implemented. +// choose from 0: Lagrange, 1: Trigonometric : temporarily, only Trigonometric is valid, Lagrange is not yet implemented. true_position_interpolation_number = 9 -//if you chose Trigonometric as interpolation method, you must choose odds number here. +// if you chose Trigonometric as interpolation method, you must choose odds number here. +// choose frome .sp3, .clk_30s or .clk true_clock_file_extension = .clk_30s -//choose frome .sp3, .clk_30s or .clk true_clock_file_sort = IGS -//choose from IGS, IGR, IGU, -// CODE_Final, CODE_Rapid, CODE_Ultra_rapid, -// JAXA_Final, JAXA_Rapid, JAXA_Ultra_rapid, madocaRT, -// QZSS_Final, QZSS_Rapid, QZSS_Ultra_rapid +// choose from IGS, CODE_Final, JAXA_Final, QZSS_Final //if you choose clk_30s, should choose the one equivalent to final, if you choose clk should choose the one equivalent to rapid. -true_clock_first = igs21233.clk_30s -//As small as possible within the range. -true_clock_last = igs21233.clk_30s +// As small as possible within the range. +// The method is fixed with Lagrange interpolation, 3 (quadratic) recommended +true_clock_first = igs21610.clk_30s +true_clock_last = igs21613.clk_30s true_clock_interpolation_number = 3 -//The method is fixed with Lagrange interpolation, 3 (quadratic) recommended estimate_position_file_sort = madocaRT -//choose from IGS, IGR, IGU, -// CODE_Final, CODE_Rapid, CODE_Ultra_rapid, +// choose from IGS, IGR, IGU, +// CODE_Final, CODE_Rapid // JAXA_Final, JAXA_Rapid, JAXA_Ultra_rapid, madocaRT, // QZSS_Final, QZSS_Rapid, QZSS_Ultra_rapid -estimate_position_first = madoca21233.sp3 -//As small as possible within the range. -estimate_position_last = madoca21233.sp3 +// As small as possible within the range. +estimate_position_first = madoca21610.sp3 +estimate_position_last = madoca21613.sp3 +// when you use Ultra Rapid Product, you can choose "observe" or "predict" estimate_position_interpolation_method = 1 -//choose from 0: Lagrange, 1: Trigonometric : temporarily, only Trigonometric is valid, Lagrange is not yet implemented. +// choose from 0: Lagrange, 1: Trigonometric : temporarily, only Trigonometric is valid, Lagrange is not yet implemented. estimate_position_interpolation_number = 9 -//if you chose Trigonometric as interpolation method, you must choose odds number here. +// if you chose Trigonometric as interpolation method, you must choose odds number here. estimate_clock_file_sort = madocaRT -//choose from IGS, IGR, IGU, -// CODE_Final, CODE_Rapid, CODE_Ultra_rapid, +// choose from IGS, IGR, IGU, +// CODE_Final, CODE_Rapid // JAXA_Final, JAXA_Rapid, JAXA_Ultra_rapid, madocaRT, // QZSS_Final, QZSS_Rapid, QZSS_Ultra_rapid +// choose frome .sp3, .clk_30s or .clk estimate_clock_file_extension = .sp3 -//choose frome .sp3, .clk_30s or .clk -estimate_clock_first = madoca21233.sp3 -//As small as possible within the range. -estimate_clock_last = madoca21233.sp3 +// As small as possible within the range. +estimate_clock_first = madoca21610.sp3 +estimate_clock_last = madoca21613.sp3 +// The method is fixed with Lagrange interpolation, 3 (quadratic) recommended estimate_clock_interpolation_number = 3 -//The method is fixed with Lagrange interpolation, 3 (quadratic) recommended \ No newline at end of file +estimate_ur_observe_or_predict = observe diff --git a/data/SampleSat/ini/SampleLocalEnvironment.ini b/data/SampleSat/ini/SampleLocalEnvironment.ini index 53abd2a86..174ab57f5 100644 --- a/data/SampleSat/ini/SampleLocalEnvironment.ini +++ b/data/SampleSat/ini/SampleLocalEnvironment.ini @@ -1,22 +1,34 @@ [MAG_ENVIRONMENT] calculation = ENABLE logging = ENABLE -coeff_file = ../../src/Library/igrf/igrf13.coef -mag_rwdev = 0.0//10.0 //磁気ランダムウォーク速度[nT] Default(10.0) -mag_rwlimit = 0.0//400.0 //磁気ランダムウォーク最大値[nT] Default(400.0) -mag_wnvar = 0.0//50.0 //磁気ホワイトノイズ分散[nT] Default(50.0) +coeff_file = ../../../S2E_CORE_OSS/src/Library/igrf/igrf13.coef +mag_rwdev = 10.0 //Random Walk speed[nT] +mag_rwlimit = 400.0 //Random Walk max limit[nT] +mag_wnvar = 50.0 //White noise standard deviation [nT] + [SRP] calculation = ENABLE logging = ENABLE + [ATMOSPHERE] -// 大気密度モデル STANDARD->スケールハイトを用いたモデル,NRLMSISE00->NRLMSISE00モデル -model = NRLMSISE00 -nrlmsise00_table_path = ../../../ExtLibraries/nrlmsise00/table/SpaceWeather.txt calculation = ENABLE logging = ENABLE -rho_stddev = 0.0//0.1 //空気密度標準偏差の割合 + +// Atmosphere model +// STANDARD: Model using scale height, NRLMSISE00: NRLMSISE00 model +model = STANDARD +nrlmsise00_table_path = ../../../ExtLibraries/nrlmsise00/table/SpaceWeather.txt +// Whether using user-defined f10.7 and ap value +// Ref of f10.7: https://www.swpc.noaa.gov/phenomena/f107-cm-radio-emissions +// Ref of ap: http://wdc.kugi.kyoto-u.ac.jp/kp/kpexp-j.html +is_manual_param_used = ENABLE +manual_daily_f107 = 150.0 // User defined f10.7(1 day) +manual_average_f107 = 150.0 // User defined f10.7(30 days average) +manual_ap = 3.0 // User defined ap +rho_stddev = 0.0 // Standard deviation of the air density + [LOCAL_CELESTIAL_INFORMATION] -logging = ENABLE \ No newline at end of file +logging = ENABLE diff --git a/data/SampleSat/ini/SampleSat.ini b/data/SampleSat/ini/SampleSat.ini index b3cc833d4..f64c0703d 100644 --- a/data/SampleSat/ini/SampleSat.ini +++ b/data/SampleSat/ini/SampleSat.ini @@ -1,22 +1,27 @@ [ATTITUDE] -propagate_mode = 0; //0: RK4, 1: ControlledAttitude -//角速度,機体固定座標,[rad/s] +// Attitude propagation mode +// 0: RK4, 1: ControlledAttitude +propagate_mode = 0 + +// Initial angular velocity at body frame,[rad/s] Omega_b(0) = 0.0 Omega_b(1) = 0.0 Omega_b(2) = 0.0 -//姿勢Quaternion,i2b,(実部,虚部) + +// Initial quaternion,i->b,(real part,imaginary part) Quaternion_i2b(0) = 0.0 Quaternion_i2b(1) = 0.0 Quaternion_i2b(2) = 0.0 Quaternion_i2b(3) = 1.0 -//トルク,機体固定座標,[Nm] -//*ただし,このトルクは最初の1ステップ間しか入力されない + +// Initial torque at body frame,[Nm] +// Note: The initial torque added just for the first propagation step Torque_b(0) = +0.000 Torque_b(1) = -0.000 Torque_b(2) = 0.000 [ControlledAttitude] -// mode definitions +// Mode definitions // INERTIAL_STABILIZE = 0, // SUN_POINTING = 1, // EARTH_CENTER_POINTING = 2 @@ -46,79 +51,73 @@ pointing_sub_t_b(2) = 1.0 calculation = ENABLE logging = ENABLE +// Orbit propagation mode +// 0: RK4 with initial position and velocity +// 1: SGP4 with TLE +// 2: Relative dynamics (for formation flying simulation) propagate_mode = 1 -//0→propagate orbit using Runge-Kutta method -//1→propagate orbit using SGP4(only for Earth orbit) -//2→propagate orbit using relative dynamics theory(for formation flying simulation) - -//地球周回軌道情報////////////////////////////////////////////////////////////// -//ISS -//tle1=1 25544U 98067A 20076.51604214 .00016717 00000-0 10270-3 0 9005 -//tle2=2 25544 51.6412 86.9962 0006063 30.9353 329.2153 15.49228202 17647 - -//NJ模擬軌道 -//高度 883km 近地点引数 300.0deg 軌道傾斜角 98.603deg 平均近点角 180.0deg -//離心率 0.000001 昇交点赤経 315.41deg Epoch 2012/8/24 00:00:00 ID1 38666 ID2 12003B -tle1=1 38666U 12003B 12237.00000000 +.00000100 00000-0 67980-4 0 00008 -tle2=2 38666 098.6030 315.4100 0000010 300.0000 180.0000 14.09465034 0011 - -wgs = 2 -//測地系の変更 -//0→wgs72old -//1→wgs72 -//2→wgs84 -/////////////////////////////////////////////////////////////////////////////// -//Information used for orbital propagation by the Runge-Kutta method/////////// -//initial satellite position[m] -//*The coordinate system is defined in PlanetSelect.ini -init_position(0) = 4.2164140100E+07 //radius of GEO +// TLE definition for SGP4 /////////////////////////////////////////////// +// ISS +tle1=1 25544U 98067A 20076.51604214 .00016717 00000-0 10270-3 0 9005 +tle2=2 25544 51.6412 86.9962 0006063 30.9353 329.2153 15.49228202 17647 +wgs = 2 // 0: wgs72old, 1: wgs72, 2: wgs84 +////////////////////////////////////////////////////////////////////////// + +// Initial value definition for RK4 ////////////////////////////////////// +// *The coordinate system is defined in PlanetSelect.ini +// Initial satellite position[m] +init_position(0) = 4.2164140100E+07 // radius of GEO init_position(1) = 0 init_position(2) = 0 + //initial satellite velocity[m/s] -//*The coordinate system is defined in PlanetSelect.ini init_velocity(0) = 0 -init_velocity(1) = 3.074661E+03 //Speed of a spacecraft in GEO +init_velocity(1) = 3.074661E+03 // Speed of a spacecraft in GEO init_velocity(2) = 0 -/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////// -//Information used for relative orbit propagation////////////////////////////// -//Relative Orbit Update Method (0 means RK4, 1 means STM) + +// Information used for relative orbit propagation////////////////////////////// +// Relative Orbit Update Method (0 means RK4, 1 means STM) relative_orbit_update_method = 0 -//RK4 Relative Dynamics model type (only valid for RK4 update) -//0: Hill +// RK4 Relative Dynamics model type (only valid for RK4 update) +// 0: Hill relative_dynamics_model_type = 0 -//STM Relative Dynamics model type (only valid for STM update) -//0: HCW +// STM Relative Dynamics model type (only valid for STM update) +// 0: HCW stm_model_type = 0 -//initial satellite position relative to the reference satellite in LVLH frame[m] -//*The coordinate system is defined in PlanetSelect.ini +// Initial satellite position relative to the reference satellite in LVLH frame[m] +// *The coordinate system is defined in PlanetSelect.ini init_relative_position_lvlh(0) = 0.0 init_relative_position_lvlh(1) = 100.0 init_relative_position_lvlh(2) = 0.0 -//initial satellite velocity relative to the reference satellite in LVLH frame[m/s] +// initial satellite velocity relative to the reference satellite in LVLH frame[m/s] init_relative_velocity_lvlh(0) = 0.0 init_relative_velocity_lvlh(1) = 0.0 init_relative_velocity_lvlh(2) = 0.0 -//information of reference satellite +// information of reference satellite reference_sat_id = 1 /////////////////////////////////////////////////////////////////////////////// + [Thermal] IsCalcEnabled=0 debug=0 - thrm_file = ../../data/SampleSat/ini/Thermal_CSV/ [LOCAL_ENVIRONMENT] local_env_file = ../../data/SampleSat/ini/SampleLocalEnvironment.ini + [DISTURBANCE] -dist_file = ../../data/SampleSat/ini/SampleDisturbance.ini +dist_file = ../../data/SampleSat/ini/SampleDisturbance.ini + [STRUCTURE_FILE] structure_file = ../../data/SampleSat/ini/SampleStructure.ini + [COMPONENTS_FILE] gyro_file = ../../data/SampleSat/ini/component/gyro.ini mag_sensor_file = ../../data/SampleSat/ini/component/magsensor.ini diff --git a/data/SampleSat/ini/SampleSimBase.ini b/data/SampleSat/ini/SampleSimBase.ini index 6c32cfe3a..2cda948ae 100644 --- a/data/SampleSat/ini/SampleSimBase.ini +++ b/data/SampleSat/ini/SampleSimBase.ini @@ -1,49 +1,60 @@ [TIME] -//Simulation start date [UTC] +// Simulation start date [UTC] StartYMDHMS=2020/01/01 12:00:00.0 -//Simulation finish time [sec] + +// Simulation finish time [sec] EndTimeSec=200 -//Simulation step time [sec] -//Minimum time step for the entire simulation + +// Simulation step time [sec] +// Minimum time step for the entire simulation StepTimeSec=0.1 -//Attitude Update Period [sec] -//Attitude is updated at the period specified here +// Attitude Update Period [sec] +// Attitude is updated at the period specified here AttitudeUpdateIntervalSec=0.1 // should be larger than StepTimeSec -//Attitide Δt for Runge-Kutt method [sec] -//This must be smaller than "AttitudeUpdateIntervalSec" + +// Attitide Δt for Runge-Kutt method [sec] +// This must be smaller than "AttitudeUpdateIntervalSec" AttitudeRKStepSec = 0.001 -//Orbit Update Period [sec] -//Orbit is updated at the period specified here +// Orbit Update Period [sec] +// Orbit is updated at the period specified here OrbitUpdateIntervalSec = 0.1 // should be larger than StepTimeSec -//Orbit Δt for Runge-Kutta method [sec] -//This must be smaller than "OrbitUpdateIntervalSec" + +// Orbit Δt for Runge-Kutta method [sec] +// This must be smaller than "OrbitUpdateIntervalSec" OrbitRKStepSec = 0.1 -//Thermal Update Period [sec] -//Thermal is updated at the period specified here +// Thermal Update Period [sec] +// Thermal is updated at the period specified here ThermalUpdateIntervalSec = 0.1 // should be larger than StepTimeSec -//Thermal Δt for Runge-Kutta method [sec] -//This must be smaller than "ThermalUpdateIntervalSec" + +// Thermal Δt for Runge-Kutta method [sec] +// This must be smaller than "ThermalUpdateIntervalSec" ThermalRKStepSec = 0.1 -//Component Update Period [sec] +// Component Update Period [sec] CompoUpdateIntervalSec = 0.1 // should be larger than StepTimeSec -//Log Output Period [sec] +// Log Output Period [sec] LogOutPutIntervalSec = 0.1 // should be larger than StepTimeSec -//Simulation speed. 0: as fast as possible, 1: real-time, >1: faster than real-time, <1: slower than real-time + +// Simulation speed +// 0: as fast as possible, 1: real-time, >1: faster than real-time, <1: slower than real-time SimulationSpeed = 0 + [MC_EXECUTION] -// Monte-Carlo Simulationを行うかどうか +// Whether Monte-Carlo Simulation is executed or not MCSimEnabled = DISABLE -// 各caseごとのログcsvファイルを出力するかどうか(MCSimEnabled = DISABLEDの場合にはこの設定に関わらず出力される) + +// Whether you want output the log file for each step LogHistory = ENABLE -// ケース数の設定. + +// Number of execution NumOfExecutions = 100 + [MC_RANDOMIZATION] Param(0) = ATTITUDE0.Debug ATTITUDE0.Debug.randomization_type = CartesianUniform @@ -63,45 +74,59 @@ ATTITUDE0.Omega_b.sigma_or_max(0) = 0.05817764 // 3-sigma = 10 [deg/s] ATTITUDE0.Omega_b.sigma_or_max(1) = 0.05817764 // 3-sigma = 10 [deg/s] ATTITUDE0.Omega_b.sigma_or_max(2) = 0.05817764 // 3-sigma = 10 [deg/s] + [PLANET_SELECTION] -//Whether global celestial information is logged or not +// Whether global celestial information is logged or not logging = ENABLE -//Celestial Information + +// Definition of Inertial frame inertial_frame = J2000 aberration_correction = NONE center_object = EARTH -//designation of dynamics model, Idle:no motion,Simple:rotation only,Full:full-dynamics + +// Earth Rotation model +// Idle:no motion,Simple:rotation only,Full:full-dynamics rotation_mode = Simple + +// Definition of calculation celestial bodies num_of_selected_body = 3 selected_body(0) = EARTH selected_body(1) = SUN selected_body(2) = MOON selected_body(3) = MARS + [FURNSH_PATH] -//Furnsh ファイルパス +// CSPICE Kernel files definition TLS = ../../../ExtLibraries/cspice/generic_kernels/lsk/naif0010.tls TPC1 = ../../../ExtLibraries/cspice/generic_kernels/pck/de-403-masses.tpc TPC2 = ../../../ExtLibraries/cspice/generic_kernels/pck/gm_de431.tpc TPC3 = ../../../ExtLibraries/cspice/generic_kernels/pck/pck00010.tpc BSP = ../../../ExtLibraries/cspice/generic_kernels/spk/planets/de430.bsp + [HIPPARCOS_CATALOGUE] catalogue_path = ../../../ExtLibraries/HipparcosCatalogue/hip_main.csv -max_magnitude = 3.0 //ヒッパルコス星表から読み出す等級の上限,ここで指定した等級より暗い星は計算に使用されない +max_magnitude = 3.0 // Max magnitude to read from Hip catalog calculation = DISABLE logging = DISABLE + [RAND] -Rand_Seed = 0x11223344 //乱数のSeed. 0にすると時変になる +// Seed of randam. When this value is 0, the seed will be varied by time. +Rand_Seed = 0x11223344 + [SIM_SETTING] +// Whether the ini files are saved or not log_inifile = 1 -//ファイル設定 -//If you want to add a spacecraft, create the corresponding Sat.ini, and specify it as sat_file(1), sat_file(2)... . + +// Initialize files +// File name must not over 256 characters (defined in initialize.h as MAX_CHAR_NUM) +// If you want to add a spacecraft, create the corresponding Sat.ini, and specify it as sat_file(1), sat_file(2)... . num_of_simulated_spacecraft = 1 sat_file(0) = ../../data/SampleSat/ini/SampleSat.ini gs_file = ../../data/SampleSat/ini/SampleGS.ini inter_sat_comm_file = ../../data/SampleSat/ini/SampleInterSatComm.ini gnss_file = ../../data/SampleSat/ini/SampleGNSS.ini -log_file_path = ../../data/SampleSat/logs/ \ No newline at end of file +log_file_path = ../../data/SampleSat/logs/ diff --git a/data/SampleSat/ini/SampleStructure.ini b/data/SampleSat/ini/SampleStructure.ini index 2cd6cd0bc..7d64810d2 100644 --- a/data/SampleSat/ini/SampleStructure.ini +++ b/data/SampleSat/ini/SampleStructure.ini @@ -1,5 +1,12 @@ +// +// The origin of all vectors defined here is the body-fixed frame. +// Users can define the origin of the body-fixed frame by themselves. +// If users want to define the origin as the center of gravity, they need to set cg_b = zero vector. +// If users want to define the origin as a specific point, they need to set all vectors to suit their definition carefully. +// + [STRUCTURE] -//慣性テンソル,機体固定座標,[kg・m2] +// Inertia Tensor @ body fixed frame [kg・m2] Iner(0) = 0.1 //I(0,0) Iner(1) = 0.0 //I(0,1) Iner(2) = 0.0 //I(0,2) @@ -9,9 +16,10 @@ Iner(5) = 0.0 //I(1,2) Iner(6) = 0.0 //I(2,0) Iner(7) = 0.0 //I(2,1) Iner(8) = 0.1 //I(2,2) -//質量, [kg] -mass = 14 -//Position vector of the center of gravity at the body frame[m] + +mass = 14 //[kg] + +// Position vector of the center of gravity @ the body frame [m] cg_b(0) = 0.01 cg_b(1) = 0.01 cg_b(2) = 0.01 @@ -19,7 +27,7 @@ cg_b(2) = 0.01 [SURFACES] num_of_surfaces = 6 -//Area of each surface[m^2] +// Area of each surface [m^2] area_0 = 0.25 area_1 = 0.25 area_2 = 0.25 @@ -27,77 +35,81 @@ area_3 = 0.25 area_4 = 0.25 area_5 = 0.25 -//Position vector of each surface geometric center @ body frame[m] -position_0(0) = 0.25// -position_0(1) = 0.0// -position_0(2) = 0.0// -position_1(0) = -0.25// -position_1(1) = 0.0// -position_1(2) = 0.0// -position_2(0) = 0.0// -position_2(1) = 0.25// -position_2(2) = 0.0// -position_3(0) = 0.0// -position_3(1) = -0.25// -position_3(2) = 0.0// -position_4(0) = 0.0// -position_4(1) = 0.0// -position_4(2) = 0.25// -position_5(0) = 0.0// -position_5(1) = 0.0// -position_5(2) = -0.25// -//Normal vector of each surface @ body frame -normal_0(0) = 1.0// -normal_0(1) = 0.0// -normal_0(2) = 0.0// -normal_1(0) = -1.0// -normal_1(1) = 0.0// -normal_1(2) = 0.0// -normal_2(0) = 0.0// -normal_2(1) = 1.0// -normal_2(2) = 0.0// -normal_3(0) = 0.0// -normal_3(1) = -1.0// -normal_3(2) = 0.0// -normal_4(0) = 0.0// -normal_4(1) = 0.0// -normal_4(2) = 1.0// -normal_5(0) = 0.0// -normal_5(1) = 0.0// -normal_5(2) = -1.0// +// Position vector of each surface geometric center @ body frame [m] +position_0(0) = 0.25 +position_0(1) = 0.0 +position_0(2) = 0.0 +position_1(0) = -0.25 +position_1(1) = 0.0 +position_1(2) = 0.0 +position_2(0) = 0.0 +position_2(1) = 0.25 +position_2(2) = 0.0 +position_3(0) = 0.0 +position_3(1) = -0.25 +position_3(2) = 0.0 +position_4(0) = 0.0 +position_4(1) = 0.0 +position_4(2) = 0.25 +position_5(0) = 0.0 +position_5(1) = 0.0 +position_5(2) = -0.25 + +// Normal vector of each surface @ body frame +normal_0(0) = 1.0 +normal_0(1) = 0.0 +normal_0(2) = 0.0 +normal_1(0) = -1.0 +normal_1(1) = 0.0 +normal_1(2) = 0.0 +normal_2(0) = 0.0 +normal_2(1) = 1.0 +normal_2(2) = 0.0 +normal_3(0) = 0.0 +normal_3(1) = -1.0 +normal_3(2) = 0.0 +normal_4(0) = 0.0 +normal_4(1) = 0.0 +normal_4(2) = 1.0 +normal_5(0) = 0.0 +normal_5(1) = 0.0 +normal_5(2) = -1.0 -//Total reflectance for the sun spectrum -reflectivity_0 = 0.4 //PX -reflectivity_1 = 0.4 //MX -reflectivity_2 = 0.4 //PY -reflectivity_3 = 0.4 //PMY -reflectivity_4 = 0.4 //PZ -reflectivity_5 = 0.4 //MZ +// Total reflectance for the Sun spectrum +reflectivity_0 = 0.4 +reflectivity_1 = 0.4 +reflectivity_2 = 0.4 +reflectivity_3 = 0.4 +reflectivity_4 = 0.4 +reflectivity_5 = 0.4 -//Specularity for the sun spectrum -specularity_0 = 0.4 //PX -specularity_1 = 0.4 //MX -specularity_2 = 0.4 //PY -specularity_3 = 0.4 //PMY -specularity_4 = 0.4 //PZ -specularity_5 = 0.4 //MZ +// Specularity for the Sun spectrum +specularity_0 = 0.4 +specularity_1 = 0.4 +specularity_2 = 0.4 +specularity_3 = 0.4 +specularity_4 = 0.4 +specularity_5 = 0.4 -//specularity for air drag -air_specularity_0 = 0.4 //PX -air_specularity_1 = 0.4 //MX -air_specularity_2 = 0.4 //PY -air_specularity_3 = 0.4 //PMY -air_specularity_4 = 0.4 //PZ -air_specularity_5 = 0.4 //MZ +// Specularity for air drag +air_specularity_0 = 0.4 +air_specularity_1 = 0.4 +air_specularity_2 = 0.4 +air_specularity_3 = 0.4 +air_specularity_4 = 0.4 +air_specularity_5 = 0.4 [RMM] -//残留磁気モーメント[A・m^2] +// Constant component of Residual Magnetic Moment(RMM) [A・m^2] rmm_const_b(0) = 0.04 rmm_const_b(1) = 0.04 rmm_const_b(2) = 0.04 -//残留磁気モーメントランダムウォーク速度[nT] -rmm_rwdev = 1.0E-5 -//残留磁気モーメントランダムウォーク最大値[nT] + +// RMM Random Walk Speed [nT] +rmm_rwdev = 1.0E-5 + +// RMM Random Walk Limit [nT] rmm_rwlimit = 1.0E-3 -//残留磁気モーメントホワイトノイズ分散[nT] -rmm_wnvar = 5.0E-5 + +// RMM White Noise Standard deviation [nT] +rmm_wnvar = 5.0E-5 diff --git a/data/SampleSat/ini/component/gyro.ini b/data/SampleSat/ini/component/gyro.ini index 468dd9ca2..32286d88b 100644 --- a/data/SampleSat/ini/component/gyro.ini +++ b/data/SampleSat/ini/component/gyro.ini @@ -1,13 +1,13 @@ [GYRO] prescaler = 10 -//Quaternion from body frame to component frame +// Quaternion from body frame to component frame +// Including misalignment q_b2c(0) = 0.0 q_b2c(1) = 0.0 q_b2c(2) = 0.0 q_b2c(3) = 1.0 -// Sensor Base // Scale Factor Matrix (3×3) // (0) = (0,0), (1) = (0,1), (2) = (0,2), ScaleFactor(0) = 1.0 @@ -46,4 +46,4 @@ Range_to_zero = 10.0 // Power Port minimum_voltage = 3.3 // V -assumed_power_consumption = 1.0 //W \ No newline at end of file +assumed_power_consumption = 1.0 //W diff --git a/scripts/Docker_Ubuntu/Dockerfile b/scripts/Docker_Ubuntu/Dockerfile index 55b74838f..afe37151c 100644 --- a/scripts/Docker_Ubuntu/Dockerfile +++ b/scripts/Docker_Ubuntu/Dockerfile @@ -69,12 +69,6 @@ RUN chmod +x /home/s2e/work/scripts/hoge/hoge/download_HIPcatalogue.sh RUN chmod +x /home/s2e/work/scripts/hoge/hoge/download_nrlmsise00_src_and_table.sh - # 改行コードをCRLFからLFに置換する. - RUN sed -i 's/\r//' /home/s2e/work/scripts/hoge/hoge/download_cspice_Linux_gcc.sh - RUN sed -i 's/\r//' /home/s2e/work/scripts/hoge/hoge/download_EGM96coefficients.sh - RUN sed -i 's/\r//' /home/s2e/work/scripts/hoge/hoge/download_HIPcatalogue.sh - RUN sed -i 's/\r//' /home/s2e/work/scripts/hoge/hoge/download_nrlmsise00_src_and_table.sh - WORKDIR /home/s2e/work/scripts/hoge/hoge RUN /home/s2e/work/scripts/hoge/hoge/download_cspice_Linux_gcc.sh RUN /home/s2e/work/scripts/hoge/hoge/download_EGM96coefficients.sh diff --git a/src/Component/AOCS/EMDS.cpp b/src/Component/AOCS/EMDS.cpp index 4f236832a..855cc0186 100644 --- a/src/Component/AOCS/EMDS.cpp +++ b/src/Component/AOCS/EMDS.cpp @@ -23,9 +23,9 @@ void EMDS::Update(EMDS& other) other.torque_b_ = results[3]; } -string EMDS::GetLogHeader() const +std::string EMDS::GetLogHeader() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteVector("emds_force", "b", "N", 3); str_tmp += WriteVector("emds_torque", "b", "Nm", 3); @@ -33,9 +33,9 @@ string EMDS::GetLogHeader() const return str_tmp; } -string EMDS::GetLogValue() const +std::string EMDS::GetLogValue() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteVector(force_b_); str_tmp += WriteVector(torque_b_); diff --git a/src/Component/AOCS/EMDS.h b/src/Component/AOCS/EMDS.h index 2a66dbd34..75665a9a1 100644 --- a/src/Component/AOCS/EMDS.h +++ b/src/Component/AOCS/EMDS.h @@ -17,8 +17,8 @@ class EMDS : public ILoggable inline Vector<3> GetTorque_b() { return torque_b_; } inline Vector<3> GetForce_b() { return force_b_; } - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; // position: position of C.G. of s/c in inertia frame // quaternion: quaternion from inertia to body frame diff --git a/src/Component/AOCS/GNSSReceiver.cpp b/src/Component/AOCS/GNSSReceiver.cpp index df6ee7aec..052df65fa 100644 --- a/src/Component/AOCS/GNSSReceiver.cpp +++ b/src/Component/AOCS/GNSSReceiver.cpp @@ -7,7 +7,7 @@ GNSSReceiver::GNSSReceiver( const int prescaler, ClockGenerator* clock_gen, const int id, - const string gnss_id, + const std::string gnss_id, const int ch_max, const AntennaModel antenna_model, const Vector<3> ant_pos_b, @@ -26,7 +26,7 @@ GNSSReceiver::GNSSReceiver( ClockGenerator* clock_gen, PowerPort* power_port, const int id, - const string gnss_id, + const std::string gnss_id, const int ch_max, const AntennaModel antenna_model, const Vector<3> ant_pos_b, @@ -113,8 +113,8 @@ void GNSSReceiver::CheckAntennaCone(const Vector<3> pos_true_eci_, Quaternion q_ for (int i = 0; i < gnss_num; i++) { // check if gnss ID is compatible with the receiver - string id_tmp = gnss_satellites_->GetIDFromIndex(i); - if (gnss_id_.find(id_tmp[0]) == string::npos) continue; + std::string id_tmp = gnss_satellites_->GetIDFromIndex(i); + if (gnss_id_.find(id_tmp[0]) == std::string::npos) continue; // compute direction from sat to gnss in body-fixed frame gnss_sat_pos_i = gnss_satellites_->GetSatellitePositionEci(i); @@ -154,7 +154,7 @@ void GNSSReceiver::CheckAntennaCone(const Vector<3> pos_true_eci_, Quaternion q_ is_gnss_sats_visible_ = 0; } -void GNSSReceiver::SetGnssInfo(Vector<3> ant2gnss_i, Quaternion q_i2b, string gnss_id) +void GNSSReceiver::SetGnssInfo(Vector<3> ant2gnss_i, Quaternion q_i2b, std::string gnss_id) { Vector<3> ant2gnss_b, ant2gnss_c; @@ -195,9 +195,9 @@ void GNSSReceiver::ConvertJulianDayToGPSTime(const double JulianDay) gpstime_sec_ = (elapsed_day - (double)(gpstime_week_)*kDayInWeek) * kSecInDay; } -string GNSSReceiver::GetLogHeader() const //For logs +std::string GNSSReceiver::GetLogHeader() const //For logs { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteScalar("gnss_year"); str_tmp += WriteScalar("gnss_month"); str_tmp += WriteScalar("gnss_day"); @@ -215,9 +215,9 @@ string GNSSReceiver::GetLogHeader() const //For logs return str_tmp; } -string GNSSReceiver::GetLogValue() const //For logs +std::string GNSSReceiver::GetLogValue() const //For logs { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteScalar(utc_.year); str_tmp += WriteScalar(utc_.month); str_tmp += WriteScalar(utc_.day); diff --git a/src/Component/AOCS/GNSSReceiver.h b/src/Component/AOCS/GNSSReceiver.h index 676cf95f2..615cf0fea 100644 --- a/src/Component/AOCS/GNSSReceiver.h +++ b/src/Component/AOCS/GNSSReceiver.h @@ -20,7 +20,7 @@ enum AntennaModel typedef struct _gnssinfo { - string ID; + std::string ID; double latitude; double longitude; double distance; @@ -33,7 +33,7 @@ class GNSSReceiver : public ComponentBase, public ILoggable const int prescaler, ClockGenerator* clock_gen, const int id, - const string gnss_id, + const std::string gnss_id, const int ch_max, const AntennaModel antenna_model, const Vector<3> ant_pos_b, @@ -49,7 +49,7 @@ class GNSSReceiver : public ComponentBase, public ILoggable ClockGenerator* clock_gen, PowerPort* power_port, const int id, - string gnss_id, + std::string gnss_id, const int ch_max, const AntennaModel antenna_model, const Vector<3> ant_pos_b, @@ -70,8 +70,8 @@ class GNSSReceiver : public ComponentBase, public ILoggable inline const Vector<3> GetVelocityECI(void) const { return velocity_eci_; } inline const Vector<3> GetVelocityECEF(void) const { return velocity_ecef_; } - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; protected: //Parameters for receiver @@ -81,7 +81,7 @@ class GNSSReceiver : public ComponentBase, public ILoggable Quaternion q_b2c_; // Quaternion from body frame to component frame libra::NormalRand nrs_eci_x_, nrs_eci_y_, nrs_eci_z_; // Random Error for each axis double half_width_ = 0.0; - string gnss_id_; + std::string gnss_id_; AntennaModel antenna_model_; //Calculated values @@ -106,7 +106,7 @@ class GNSSReceiver : public ComponentBase, public ILoggable void CheckAntenna(Vector<3> location_true, Quaternion q_i2b); void CheckAntennaSimple(Vector<3> location_true, Quaternion q_i2b); void CheckAntennaCone(Vector<3> location_true, Quaternion q_i2b); - void SetGnssInfo(Vector<3> ant2gnss_i, Quaternion q_i2b, string gnss_id); + void SetGnssInfo(Vector<3> ant2gnss_i, Quaternion q_i2b, std::string gnss_id); void AddNoise(Vector<3> location_true_eci, Vector<3> location_true_ecef); // substitutional method for "Measure" in other sensor modles inherited SensorBase class void ConvertJulianDayToGPSTime(const double JulianDay); }; diff --git a/src/Component/AOCS/Gyro.cpp b/src/Component/AOCS/Gyro.cpp index cb6fe263c..46e40d59f 100644 --- a/src/Component/AOCS/Gyro.cpp +++ b/src/Component/AOCS/Gyro.cpp @@ -38,20 +38,20 @@ void Gyro::MainRoutine(int count) omega_c_ = Measure(omega_c_); //Add noises } -string Gyro::GetLogHeader() const +std::string Gyro::GetLogHeader() const { - string str_tmp = ""; - const string st_sensor_id = std::to_string(static_cast(sensor_id_)); + std::string str_tmp = ""; + const std::string st_sensor_id = std::to_string(static_cast(sensor_id_)); const char *cs = st_sensor_id.data(); - string GSection = "gyro_omega"; + std::string GSection = "gyro_omega"; str_tmp += WriteVector(GSection + cs, "c", "rad/s", kGyroDim); return str_tmp; } -string Gyro::GetLogValue() const +std::string Gyro::GetLogValue() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteVector(omega_c_); diff --git a/src/Component/AOCS/Gyro.h b/src/Component/AOCS/Gyro.h index bdb84e82e..c2fcbc559 100644 --- a/src/Component/AOCS/Gyro.h +++ b/src/Component/AOCS/Gyro.h @@ -33,8 +33,8 @@ class Gyro : public ComponentBase, public SensorBase, public ILoggable // ComponentBase void MainRoutine(int count) override; // ILoggable - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; //Getter inline const libra::Vector& GetOmegaC(void)const{return omega_c_;} @@ -46,4 +46,4 @@ class Gyro : public ComponentBase, public SensorBase, public ILoggable const Dynamics* dynamics_; }; -#endif \ No newline at end of file +#endif diff --git a/src/Component/AOCS/MagSensor.cpp b/src/Component/AOCS/MagSensor.cpp index 425e8c9d2..6db04d639 100644 --- a/src/Component/AOCS/MagSensor.cpp +++ b/src/Component/AOCS/MagSensor.cpp @@ -34,22 +34,22 @@ void MagSensor::MainRoutine(int count) mag_c_ = Measure(mag_c_); //Add noises } -string MagSensor::GetLogHeader() const +std::string MagSensor::GetLogHeader() const { - string str_tmp = ""; - const string st_sensor_id = std::to_string(static_cast(sensor_id_)); + std::string str_tmp = ""; + const std::string st_sensor_id = std::to_string(static_cast(sensor_id_)); const char *cs = st_sensor_id.data(); - string MSSection = "mag_sensor"; + std::string MSSection = "mag_sensor"; str_tmp += WriteVector(MSSection+cs, "c", "nT", kMagDim); return str_tmp; } -string MagSensor::GetLogValue() const +std::string MagSensor::GetLogValue() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteVector(mag_c_); return str_tmp; -} \ No newline at end of file +} diff --git a/src/Component/AOCS/MagSensor.h b/src/Component/AOCS/MagSensor.h index c61768d0a..a0a9ebc5c 100644 --- a/src/Component/AOCS/MagSensor.h +++ b/src/Component/AOCS/MagSensor.h @@ -33,8 +33,8 @@ class MagSensor: public ComponentBase, public SensorBase, public ILogga // ComponentBase void MainRoutine(int count) override; // ILoggable - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; //Getter inline const libra::Vector& GetMagC(void)const{return mag_c_;} @@ -46,4 +46,4 @@ class MagSensor: public ComponentBase, public SensorBase, public ILogga const MagEnvironment* magnet_; }; -#endif \ No newline at end of file +#endif diff --git a/src/Component/AOCS/MagTorquer.cpp b/src/Component/AOCS/MagTorquer.cpp index 081e96f4c..e7c1636d5 100644 --- a/src/Component/AOCS/MagTorquer.cpp +++ b/src/Component/AOCS/MagTorquer.cpp @@ -92,12 +92,12 @@ libra::Vector MagTorquer::CalcOutputTorque(void) return torque_b_; } -string MagTorquer::GetLogHeader() const +std::string MagTorquer::GetLogHeader() const { - string str_tmp = ""; - const string st_sensor_id = std::to_string(static_cast(id_)); + std::string str_tmp = ""; + const std::string st_sensor_id = std::to_string(static_cast(id_)); const char *cs = st_sensor_id.data(); - string MSSection = "mag_torquer"; + std::string MSSection = "mag_torquer"; str_tmp += WriteVector(MSSection + cs, "b", "Am^2", kMtqDim); str_tmp += WriteVector(MSSection + cs, "b", "Nm", kMtqDim); @@ -105,11 +105,11 @@ string MagTorquer::GetLogHeader() const return str_tmp; } -string MagTorquer::GetLogValue() const +std::string MagTorquer::GetLogValue() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteVector(mag_moment_b_); str_tmp += WriteVector(torque_b_); return str_tmp; -} \ No newline at end of file +} diff --git a/src/Component/AOCS/MagTorquer.h b/src/Component/AOCS/MagTorquer.h index bf4b36408..7d7b2fad9 100644 --- a/src/Component/AOCS/MagTorquer.h +++ b/src/Component/AOCS/MagTorquer.h @@ -64,8 +64,8 @@ class MagTorquer: public ComponentBase, public ILoggable // ComponentBase override functions void MainRoutine(int count) override; // ILogabble override functions - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; // Getter inline const libra::Vector& GetMagMoment_b(void)const{return mag_moment_b_;}; //Am2 diff --git a/src/Component/AOCS/RWModel.cpp b/src/Component/AOCS/RWModel.cpp index fad1cdff5..12d129d2c 100644 --- a/src/Component/AOCS/RWModel.cpp +++ b/src/Component/AOCS/RWModel.cpp @@ -238,9 +238,9 @@ void RWModel::SetVelocityLimitRpm(double velocity_limit_rpm) return; } -string RWModel::GetLogHeader() const +std::string RWModel::GetLogHeader() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteScalar("rw_angular_velocity", "rad/s"); str_tmp += WriteScalar("rw_angular_velocity_rpm", "rpm"); @@ -256,9 +256,9 @@ string RWModel::GetLogHeader() const return str_tmp; } -string RWModel::GetLogValue() const +std::string RWModel::GetLogValue() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteScalar(angular_velocity_rad_); str_tmp += WriteScalar(angular_velocity_rpm_); @@ -272,4 +272,4 @@ string RWModel::GetLogValue() const } return str_tmp; -} \ No newline at end of file +} diff --git a/src/Component/AOCS/RWModel.h b/src/Component/AOCS/RWModel.h index a8e6b2a02..0fcb5c627 100644 --- a/src/Component/AOCS/RWModel.h +++ b/src/Component/AOCS/RWModel.h @@ -47,8 +47,8 @@ class RWModel : public ComponentBase, public ILoggable const Vector<3> coasting_lag_coef, bool is_calc_jitter_enabled, bool is_log_jitter_enabled, - vector> radial_force_harmonics_coef, - vector> radial_torque_harmonics_coef, + std::vector> radial_force_harmonics_coef, + std::vector> radial_torque_harmonics_coef, double structural_resonance_freq, double damping_factor, double bandwidth, @@ -74,8 +74,8 @@ class RWModel : public ComponentBase, public ILoggable const Vector<3> coasting_lag_coef, bool is_calc_jitter_enabled, bool is_log_jitter_enabled, - vector> radial_force_harmonics_coef, - vector> radial_torque_harmonics_coef, + std::vector> radial_force_harmonics_coef, + std::vector> radial_torque_harmonics_coef, double structural_resonance_freq, double damping_factor, double bandwidth, @@ -90,8 +90,8 @@ class RWModel : public ComponentBase, public ILoggable void FastUpdate() override; // Iloggable override function - string GetLogHeader() const; - string GetLogValue() const; + std::string GetLogHeader() const; + std::string GetLogValue() const; //Getter const libra::Vector<3> GetOutputTorqueB() const; diff --git a/src/Component/AOCS/STT.cpp b/src/Component/AOCS/STT.cpp index dc528939a..7722e7bad 100644 --- a/src/Component/AOCS/STT.cpp +++ b/src/Component/AOCS/STT.cpp @@ -180,10 +180,10 @@ int STT::CaptureRateJudgement(const libra::Vector<3>& omega_b) return 0; } -string STT::GetLogHeader() const +std::string STT::GetLogHeader() const { - string str_tmp = ""; - const string sensor_id = std::to_string(static_cast(id_)); + std::string str_tmp = ""; + const std::string sensor_id = std::to_string(static_cast(id_)); str_tmp += WriteVector("quaternion_STT"+sensor_id, "i2c", "-", 4); str_tmp += WriteScalar("STT error flag"+sensor_id); @@ -191,9 +191,9 @@ string STT::GetLogHeader() const return str_tmp; } -string STT::GetLogValue() const +std::string STT::GetLogValue() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteQuaternion(q_stt_i2c_); str_tmp += WriteScalar(double(error_flag_)); diff --git a/src/Component/AOCS/STT.h b/src/Component/AOCS/STT.h index 1886cd95b..26ad1d789 100644 --- a/src/Component/AOCS/STT.h +++ b/src/Component/AOCS/STT.h @@ -69,8 +69,8 @@ class STT: public ComponentBase, public ILoggable // ComponentBase override functions void MainRoutine(int count) override; // ILogabble override functions - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; // Getter inline const libra::Quaternion GetObsQuaternion() const { return q_stt_i2c_; }; @@ -124,4 +124,4 @@ class STT: public ComponentBase, public ILoggable void Initialize(); }; -#endif \ No newline at end of file +#endif diff --git a/src/Component/AOCS/SunSensor.h b/src/Component/AOCS/SunSensor.h index 3c2e44be8..872ba7680 100644 --- a/src/Component/AOCS/SunSensor.h +++ b/src/Component/AOCS/SunSensor.h @@ -38,8 +38,8 @@ class SunSensor: public ComponentBase, public ILoggable //ComponentBase override function void MainRoutine(int count) override; // ILogabble override functions - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; // Getter inline const bool GetSunDetectedFlag() const { return sun_detected_flag_; }; inline const Vector<3> GetMeasuredSun_c() const { return measured_sun_c_; }; @@ -80,4 +80,4 @@ class SunSensor: public ComponentBase, public ILoggable void CalcSolarIlluminance(); }; -#endif //__SunSensor_H__ \ No newline at end of file +#endif //__SunSensor_H__ diff --git a/src/Component/Abstract/EXP.cpp b/src/Component/Abstract/EXP.cpp index 47537f211..baffe531e 100644 --- a/src/Component/Abstract/EXP.cpp +++ b/src/Component/Abstract/EXP.cpp @@ -41,7 +41,7 @@ int EXP::GenerateTelemetry() { tx_buff[i] = (unsigned char)memory[i]; } - tx_buffer_.assign(std::begin(tx_buff),end(tx_buff)); + tx_buffer_.assign(std::begin(tx_buff),std::end(tx_buff)); return sizeof(tx_buff); } void EXP::MainRoutine(int count) @@ -53,4 +53,4 @@ void EXP::MainRoutine(int count) void EXP::GPIOStateChanged(int port_id, bool isPosedge) { printf("interrupted"); -} \ No newline at end of file +} diff --git a/src/Component/Abstract/ExpHils.cpp b/src/Component/Abstract/ExpHils.cpp new file mode 100644 index 000000000..ecffb70e4 --- /dev/null +++ b/src/Component/Abstract/ExpHils.cpp @@ -0,0 +1,71 @@ +#include "ExpHils.h" + +ExpHils::ExpHils( + ClockGenerator* clock_gen, + const int sils_port_id, + OBC* obc, + const unsigned int hils_port_id, + const unsigned int baud_rate, + HilsPortManager* hils_port_manager, + const int mode_id) + : ComponentBase(300, clock_gen), + ObcCommunicationBase(sils_port_id, obc, hils_port_id, baud_rate, hils_port_manager), mode_id_(mode_id) +{ +} + +ExpHils::~ExpHils() +{ +} + +int ExpHils::ParseCommand(const int cmd_size) +{ + if (mode_id_ == 1) + { + for (int i = 0; i < kMemorySize; i++) + { + memory_[i] = (unsigned char)rx_buffer_[i]; + } + memory_[kMemorySize - 1] = '\0'; + } + else if (mode_id_ == 0) // data returned from the responder component to the sender component + { + // the first row will overwrite the progress output in SampleCase.cpp + std::cout << std::endl << rx_buffer_[0] << rx_buffer_[1] << rx_buffer_[2] << std::endl; + } + return 0; +} + +int ExpHils::GenerateTelemetry() +{ + if (mode_id_ == 0) // The sender component sends ABC, BCD, CDE ... + { + for (int i = 0; i < kMemorySize; i++) + { + tx_[i] = (char)('A' + counter_ + i); + } + counter_++; + tx_[kMemorySize - 1] = '\0'; + if (counter_ > kNumAlphabet - (kMemorySize - 1)) + { + counter_ = 0; + } + tx_buffer_.assign(std::begin(tx_), std::end(tx_)); + return sizeof(tx_); + } + else if (mode_id_ == 1) // The responder component sends back the received message. + { + for (int i = 0; i < kMemorySize; i++) + { + tx_[i] = (unsigned char)memory_[i]; + } + tx_buffer_.assign(std::begin(tx_), std::end(tx_)); + return sizeof(tx_); + } + return 0; +} + +void ExpHils::MainRoutine(int count) +{ + ReceiveCommand(0, kMemorySize); + SendTelemetry(0); +} diff --git a/src/Component/Abstract/ExpHils.h b/src/Component/Abstract/ExpHils.h new file mode 100644 index 000000000..9d8b9a8e8 --- /dev/null +++ b/src/Component/Abstract/ExpHils.h @@ -0,0 +1,42 @@ +#pragma once +#include +#include "ComponentBase.h" +#include "ObcCommunicationBase.h" + +// mock components for training +// # Specification for ExpHils +// * Checking UART communication for HILS exam +// compo_id = 0 : the sender compo which sends out a new massage +// compo_id = 1 : the responder compo which returns the message as received +// * message size is 4 bytes +// the first 3 bytes : ASCII(ABC, BCD, CDE,...) +// the last byte : \0 + +class ExpHils : public ComponentBase, public ObcCommunicationBase +{ +public: + ExpHils( + ClockGenerator* clock_gen, + const int sils_port_id, + OBC* obc, + const unsigned int hils_port_id, + const unsigned int baud_rate, + HilsPortManager* hils_port_manager, + const int mode_id + ); + ~ExpHils(); +protected: + void MainRoutine(int count); + +private: + const static int kMemorySize = 4; + const int kNumAlphabet = 26; + char memory_[kMemorySize] = { 0, 0, 0, '\0' }; // for the responder compo + char tx_[kMemorySize] = { 0, 0, 0, '\0' }; + const int mode_id_; + int counter_ = 0; + + // override ObcComunication + int ParseCommand(const int cmd_size) override; + int GenerateTelemetry() override; +}; diff --git a/src/Component/Abstract/ObcCommunicationBase.cpp b/src/Component/Abstract/ObcCommunicationBase.cpp index 874b59628..939be80b6 100644 --- a/src/Component/Abstract/ObcCommunicationBase.cpp +++ b/src/Component/Abstract/ObcCommunicationBase.cpp @@ -1,60 +1,171 @@ +#include + #include "ObcCommunicationBase.h" -ObcCommunicationBase::ObcCommunicationBase(int port_id, OBC* obc) -: port_id_(port_id), obc_(obc) +ObcCommunicationBase::ObcCommunicationBase(int sils_port_id, OBC* obc) + : sils_port_id_(sils_port_id), obc_(obc) +{ +#ifdef USE_HILS + sim_mode_ = OBC_COM_UART_MODE::MODE_ERROR; + printf("Error: USE_HILS:ON Check compo initialization"); +#else + sim_mode_ = OBC_COM_UART_MODE::SILS; +#endif + tx_buf_size_ = kDefaultBufferSize; + rx_buf_size_ = kDefaultBufferSize; + InitializeObcComBase(); +} + +ObcCommunicationBase::ObcCommunicationBase(int sils_port_id, const int tx_buf_size, const int rx_buf_size, OBC* obc) + : sils_port_id_(sils_port_id), tx_buf_size_(tx_buf_size), rx_buf_size_(rx_buf_size), obc_(obc) +{ +#ifdef USE_HILS + sim_mode_ = OBC_COM_UART_MODE::MODE_ERROR; + printf("Error: USE_HILS:ON Check compo initialization"); +#else + sim_mode_ = OBC_COM_UART_MODE::SILS; +#endif + if (tx_buf_size_ > kDefaultBufferSize) tx_buf_size_ = kDefaultBufferSize; + if (rx_buf_size_ > kDefaultBufferSize) rx_buf_size_ = kDefaultBufferSize; + InitializeObcComBase(); +} + +ObcCommunicationBase::ObcCommunicationBase(const unsigned int hils_port_id, const unsigned int baud_rate, HilsPortManager* hils_port_manager) + : hils_port_id_(hils_port_id), baud_rate_(baud_rate), hils_port_manager_(hils_port_manager) { +#ifdef USE_HILS + sim_mode_ = OBC_COM_UART_MODE::HILS; +#else + sim_mode_ = OBC_COM_UART_MODE::MODE_ERROR; + printf("Error: USE_HILS:OFF Check compo initialization"); +#endif tx_buf_size_ = kDefaultBufferSize; rx_buf_size_ = kDefaultBufferSize; InitializeObcComBase(); } -ObcCommunicationBase::ObcCommunicationBase(int port_id, const int tx_buf_size, const int rx_buf_size, OBC* obc) -: port_id_(port_id), tx_buf_size_(tx_buf_size), rx_buf_size_(rx_buf_size), obc_(obc) +ObcCommunicationBase::ObcCommunicationBase(const unsigned int hils_port_id, const unsigned int baud_rate, const int tx_buf_size, const int rx_buf_size, HilsPortManager* hils_port_manager) + : hils_port_id_(hils_port_id), baud_rate_(baud_rate), tx_buf_size_(tx_buf_size), rx_buf_size_(rx_buf_size), hils_port_manager_(hils_port_manager) { +#ifdef USE_HILS + sim_mode_ = OBC_COM_UART_MODE::HILS; +#else + sim_mode_ = OBC_COM_UART_MODE::MODE_ERROR; + printf("Error: USE_HILS:OFF Check compo initialization"); +#endif if (tx_buf_size_ > kDefaultBufferSize) tx_buf_size_ = kDefaultBufferSize; if (rx_buf_size_ > kDefaultBufferSize) rx_buf_size_ = kDefaultBufferSize; InitializeObcComBase(); } +ObcCommunicationBase::ObcCommunicationBase(const int sils_port_id, OBC* obc, const unsigned int hils_port_id, const unsigned int baud_rate, HilsPortManager* hils_port_manager) + : sils_port_id_(sils_port_id), obc_(obc), hils_port_id_(hils_port_id), baud_rate_(baud_rate), hils_port_manager_(hils_port_manager) +{ +#ifdef USE_HILS + sim_mode_ = OBC_COM_UART_MODE::HILS; +#else + sim_mode_ = OBC_COM_UART_MODE::SILS; +#endif + tx_buf_size_ = kDefaultBufferSize; + rx_buf_size_ = kDefaultBufferSize; + InitializeObcComBase(); +} + ObcCommunicationBase::~ObcCommunicationBase() { - if(is_connected_ == false) return; - int ret = obc_->CloseComPort(port_id_); - if (ret != 0) + if (is_connected_ == false) return; + + if (sim_mode_ == OBC_COM_UART_MODE::MODE_ERROR) { - cout << "Error: ObcCommunication CloseComPort ID:" << port_id_ << "\n"; + return; + } + else if (sim_mode_ == OBC_COM_UART_MODE::SILS) + { + int ret = obc_->CloseComPort(sils_port_id_); + if (ret != 0) + { + std::cout << "Error: ObcCommunication CloseComPort ID:" << sils_port_id_ << "\n"; + } + } + else // sim_mode_ == OBC_COM_UART_MODE::HILS + { + int ret = hils_port_manager_->UartCloseComPort(hils_port_id_); + if (ret != 0) + { + std::cout << "Error: ObcCommunication CloseComPort ID:" << hils_port_id_ << "\n"; + } } } void ObcCommunicationBase::InitializeObcComBase() { - int ret = obc_->ConnectComPort(port_id_,tx_buf_size_,rx_buf_size_); - if (ret != 0) + if (sim_mode_ == OBC_COM_UART_MODE::MODE_ERROR) + { + return; + } + else if (sim_mode_ == OBC_COM_UART_MODE::SILS) { - cout << "Already connected: ObcCommunication ConnectComPort ID:" << port_id_ << "\n"; - is_connected_ = false; + int ret = obc_->ConnectComPort(sils_port_id_, tx_buf_size_, rx_buf_size_); + if (ret != 0) + { + std::cout << "Already connected: ObcCommunication ConnectComPort ID:" << sils_port_id_ << "\n"; + is_connected_ = false; + } + else + { + is_connected_ = true; + } } - else + else // sim_mode_ == OBC_COM_UART_MODE::HILS { - is_connected_ = true; + int ret = hils_port_manager_->UartConnectComPort(hils_port_id_, baud_rate_, tx_buf_size_, rx_buf_size_); + if (ret != 0) + { + std::cout << "Error: ObcCommunication ConnectComPort ID:" << hils_port_id_ << "\n"; + is_connected_ = false; + } + else + { + is_connected_ = true; + } } } int ObcCommunicationBase::ReceiveCommand(const int offset, const int rec_size) { + if (sim_mode_ == OBC_COM_UART_MODE::MODE_ERROR) return -1; if (offset > rx_buf_size_) return -1; if (offset+rec_size > rx_buf_size_) return -1; rx_buffer_.resize(rec_size); - int ret = obc_->ReceivedByCompo(port_id_, &rx_buffer_.front(), offset, rec_size); - if (ret == 0) return 0; //No read data - return ParseCommand(ret); + if (sim_mode_ == OBC_COM_UART_MODE::SILS) + { + int ret = obc_->ReceivedByCompo(sils_port_id_, &rx_buffer_.front(), offset, rec_size); + if (ret == 0) return 0; // No read data + return ParseCommand(ret); + } + else // sim_mode_ == OBC_COM_UART_MODE::HILS + { + int ret = hils_port_manager_->UartReceive(hils_port_id_, &rx_buffer_.front(), offset, rec_size); + if (ret == 0) return 0; // No read data + return ParseCommand(ret); + } } int ObcCommunicationBase::SendTelemetry(const int offset) { + if (sim_mode_ == OBC_COM_UART_MODE::MODE_ERROR) return -1; int tlm_size = GenerateTelemetry(); if (offset > rx_buf_size_) return -1; if (offset+tlm_size > rx_buf_size_) return -1; - obc_->SendFromCompo(port_id_, &tx_buffer_.front(), offset, tlm_size); - return 0; -} \ No newline at end of file + + if (sim_mode_ == OBC_COM_UART_MODE::SILS) + { + obc_->SendFromCompo(sils_port_id_, &tx_buffer_.front(), offset, tlm_size); + return 0; + } + else // sim_mode_ == OBC_COM_UART_MODE::HILS + { + hils_port_manager_->UartSend(hils_port_id_, &tx_buffer_.front(), offset, tlm_size); + return 0; + } +} diff --git a/src/Component/Abstract/ObcCommunicationBase.h b/src/Component/Abstract/ObcCommunicationBase.h index 2a8444b2e..2aed3ce15 100644 --- a/src/Component/Abstract/ObcCommunicationBase.h +++ b/src/Component/Abstract/ObcCommunicationBase.h @@ -1,19 +1,46 @@ #pragma once #include "../CDH/OBC.h" +#include "../../Interface/HilsInOut/HilsPortManager.h" + +enum class OBC_COM_UART_MODE +{ + SILS, + HILS, + MODE_ERROR, +}; class ObcCommunicationBase { public: ObcCommunicationBase( - const int port_id, + const int sils_port_id, OBC* obc ); ObcCommunicationBase( - const int port_id, - const int tx_buf_size, - const int rx_buf_size, + const int sils_port_id, + const int tx_buf_size, + const int rx_buf_size, OBC* obc ); + ObcCommunicationBase( + const unsigned int hils_port_id, + const unsigned int baud_rate, + HilsPortManager* hils_port_manager + ); + ObcCommunicationBase( + const unsigned int hils_port_id, + const unsigned int baud_rate, + const int tx_buf_size, + const int rx_buf_size, + HilsPortManager* hils_port_manager + ); + ObcCommunicationBase( + const int sils_port_id, + OBC* obc, + const unsigned int hils_port_id, + const unsigned int baud_rate, + HilsPortManager* hils_port_manager + ); ~ObcCommunicationBase(); inline const bool IsConnected() const{return is_connected_;} @@ -21,19 +48,23 @@ class ObcCommunicationBase protected: int ReceiveCommand(const int offset, const int rec_size); int SendTelemetry(const int offset); - vector tx_buffer_; - vector rx_buffer_; + std::vector tx_buffer_; + std::vector rx_buffer_; private: const int kDefaultBufferSize = 1024;// Fixme: The magic number. This is depending on SCIPort.h. - int port_id_; + int sils_port_id_; + int hils_port_id_; + int baud_rate_; // [baud] ex. 9600, 115200 int tx_buf_size_; int rx_buf_size_; bool is_connected_ = false; + OBC_COM_UART_MODE sim_mode_ = OBC_COM_UART_MODE::MODE_ERROR; OBC* obc_; + HilsPortManager* hils_port_manager_; void InitializeObcComBase(); virtual int ParseCommand(const int cmd_size)=0; // return value should be error code (ret<=0 means error, ret>0 means fine) virtual int GenerateTelemetry()=0; //return value should be the telemetry size -}; \ No newline at end of file +}; diff --git a/src/Component/Abstract/ObcGpioBase.cpp b/src/Component/Abstract/ObcGpioBase.cpp index e3713553c..0f0993809 100644 --- a/src/Component/Abstract/ObcGpioBase.cpp +++ b/src/Component/Abstract/ObcGpioBase.cpp @@ -1,6 +1,6 @@ #include "ObcGpioBase.h" -ObcGpioBase::ObcGpioBase(const vector port_id, OBC* obc) +ObcGpioBase::ObcGpioBase(const std::vector port_id, OBC* obc) : port_id_(port_id), obc_(obc) { for (size_t i = 0; i< port_id_.size(); i++) @@ -21,4 +21,4 @@ bool ObcGpioBase::Read(const int idx) void ObcGpioBase::Write(const int idx, const bool is_high) { obc_->GpioComponentWrite(port_id_[idx], is_high); -} \ No newline at end of file +} diff --git a/src/Component/Abstract/ObcGpioBase.h b/src/Component/Abstract/ObcGpioBase.h index 420941722..7e6e6ed73 100644 --- a/src/Component/Abstract/ObcGpioBase.h +++ b/src/Component/Abstract/ObcGpioBase.h @@ -5,7 +5,7 @@ class ObcGpioBase { public: ObcGpioBase( - const vector port_id, + const std::vector port_id, OBC* obc ); ~ObcGpioBase(); @@ -15,6 +15,6 @@ class ObcGpioBase void Write(const int idx, const bool is_high); // The first arg is the element index for port_id_ vector, not the GPIO port ID for OBC. private: - vector port_id_; + std::vector port_id_; OBC* obc_; -}; \ No newline at end of file +}; diff --git a/src/Component/Abstract/SensorBase_tfs.hpp b/src/Component/Abstract/SensorBase_tfs.hpp index 7203823e8..f87fa9b86 100644 --- a/src/Component/Abstract/SensorBase_tfs.hpp +++ b/src/Component/Abstract/SensorBase_tfs.hpp @@ -71,15 +71,15 @@ void SensorBase::RangeCheck(void) { if (range_to_const_c_[i] < 0.0 || range_to_zero_c_[i] < 0.0) { - cout << "SensorBase: Range should be positive!!\n"; - cout << "The range values are set as positive.\n"; + std::cout << "SensorBase: Range should be positive!!\n"; + std::cout << "The range values are set as positive.\n"; range_to_zero_c_[i] = fabs(range_to_zero_c_[i]); range_to_const_c_[i] = fabs(range_to_const_c_[i]); } if (range_to_const_c_[i] > range_to_zero_c_[i]) { - cout << "SensorBase: range_zero should be greater than range_const!!\n"; - cout << "The range_zero is set as twice value of the range_const.\n"; + std::cout << "SensorBase: range_zero should be greater than range_const!!\n"; + std::cout << "The range_zero is set as twice value of the range_const.\n"; range_to_zero_c_[i] = 2.0*range_to_const_c_[i]; } } diff --git a/src/Component/CMakeLists.txt b/src/Component/CMakeLists.txt index 9d68b20a9..ea92f4a84 100644 --- a/src/Component/CMakeLists.txt +++ b/src/Component/CMakeLists.txt @@ -6,6 +6,7 @@ add_library(${PROJECT_NAME} STATIC Abstract/ObcI2cCommunicationBase.cpp Abstract/ObcGpioBase.cpp Abstract/EXP.cpp + Abstract/ExpHils.cpp AOCS/EMDS.cpp AOCS/Gyro.cpp AOCS/MagSensor.cpp diff --git a/src/Component/CommGS/GScalculator.cpp b/src/Component/CommGS/GScalculator.cpp index a08d23b68..5172eb75c 100644 --- a/src/Component/CommGS/GScalculator.cpp +++ b/src/Component/CommGS/GScalculator.cpp @@ -115,9 +115,9 @@ double GScalculator::CalcMaxBitrate(const Dynamics& dynamics, const ANT& sc_ant, } } -string GScalculator::GetLogHeader() const +std::string GScalculator::GetLogHeader() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteScalar("visible flag"); str_tmp += WriteScalar("max bitrate[Mbps]"); @@ -125,9 +125,9 @@ string GScalculator::GetLogHeader() const return str_tmp; } -string GScalculator::GetLogValue() const +std::string GScalculator::GetLogValue() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteScalar(visible_flag_); str_tmp += WriteScalar(max_bitrate_); diff --git a/src/Component/CommGS/GScalculator.h b/src/Component/CommGS/GScalculator.h index f4dc5de89..016ea60cb 100644 --- a/src/Component/CommGS/GScalculator.h +++ b/src/Component/CommGS/GScalculator.h @@ -56,8 +56,8 @@ class GScalculator : public ILoggable void Initialize(); void Update(const Dynamics& dynamics, const ANT& sc_ant, const GroundStation& groundstation, const ANT& gs_ant); - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; protected: // 衛星と地上局が可視の位置関係のときにtrue,非可視のときにfalseを返す diff --git a/src/Component/Logic/RVDController.cpp b/src/Component/Logic/RVDController.cpp index 331de3c3a..e58f3e4a5 100644 --- a/src/Component/Logic/RVDController.cpp +++ b/src/Component/Logic/RVDController.cpp @@ -80,17 +80,17 @@ Vector<3> RVDController::CalcRW(Quaternion q_ib_now) return res; } -string RVDController::GetLogHeader() const +std::string RVDController::GetLogHeader() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteVector("thrust", "b", "N", 3); str_tmp += WriteVector("torque", "b", "Nm", 3); return str_tmp; } -string RVDController::GetLogValue() const +std::string RVDController::GetLogValue() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteVector(thrust_b_); str_tmp += WriteVector(torque_); return str_tmp; diff --git a/src/Component/Logic/RVDController.h b/src/Component/Logic/RVDController.h index 53fab9892..7e7abd3f4 100644 --- a/src/Component/Logic/RVDController.h +++ b/src/Component/Logic/RVDController.h @@ -40,8 +40,8 @@ class RVDController :public ILoggable inline Vector<3> GetTorque() { return torque_; } inline void ClearForce() { thrust_b_ *= 0; } - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; private: double acos_tolerant(double x); diff --git a/src/Component/Logic/UWBEstimator.cpp b/src/Component/Logic/UWBEstimator.cpp index dbd36ac5a..c928753a0 100644 --- a/src/Component/Logic/UWBEstimator.cpp +++ b/src/Component/Logic/UWBEstimator.cpp @@ -54,7 +54,7 @@ void UWBEstimator::Update(Vector<12> visibility, Vector<12> measurement) } catch (...) { fill_up(inv, 0.0); - cout << "singular!!\r\n"; + std::cout << "singular!!\r\n"; } K = M * transpose(H) * inv; @@ -113,9 +113,9 @@ bool UWBEstimator::IsConverged() return isconverged; } -string UWBEstimator::GetLogHeader() const +std::string UWBEstimator::GetLogHeader() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteVector("RelPosEst", "i", "m", 3); str_tmp += WriteVector("RelVelEst", "i", "m/s", 3); str_tmp += WriteVector("UWBObs", "i", "m", 12); @@ -123,9 +123,9 @@ string UWBEstimator::GetLogHeader() const return str_tmp; } -string UWBEstimator::GetLogValue() const +std::string UWBEstimator::GetLogValue() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteVector(x); str_tmp += WriteVector(lastObservation); str_tmp += WriteVector(Fcontrol_i); diff --git a/src/Component/Logic/UWBEstimator.h b/src/Component/Logic/UWBEstimator.h index 07c94cd02..c128ff30b 100644 --- a/src/Component/Logic/UWBEstimator.h +++ b/src/Component/Logic/UWBEstimator.h @@ -34,8 +34,8 @@ class UWBEstimator : public ILoggable void SetX(Vector<6> x_new); bool IsConverged(); - string GetLogHeader() const; - string GetLogValue() const; + std::string GetLogHeader() const; + std::string GetLogValue() const; private: double Rinf = 1000000; diff --git a/src/Component/Mission/Telescope/Telescope.h b/src/Component/Mission/Telescope/Telescope.h index 2f088c04d..6fab51ed7 100644 --- a/src/Component/Mission/Telescope/Telescope.h +++ b/src/Component/Mission/Telescope/Telescope.h @@ -74,8 +74,8 @@ class Telescope : public ComponentBase, public ILoggable const HipparcosCatalogue* hipp_; const LocalCelestialInformation *local_celes_info_; - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; //デバッグ用変数********************************************** //Vector<3> sun_pos_c; diff --git a/src/Component/Power/BAT.cpp b/src/Component/Power/BAT.cpp index 46d8bd5aa..cfae1095c 100644 --- a/src/Component/Power/BAT.cpp +++ b/src/Component/Power/BAT.cpp @@ -54,17 +54,17 @@ double BAT::GetCVChargeVoltage() const return cv_charge_voltage_; } -string BAT::GetLogHeader() const +std::string BAT::GetLogHeader() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteScalar("bat_voltage", "V"); str_tmp += WriteScalar("DoD", "%"); return str_tmp; } -string BAT::GetLogValue() const +std::string BAT::GetLogValue() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteScalar(bat_voltage_); str_tmp += WriteScalar(dod_); return str_tmp; diff --git a/src/Component/Power/BAT.h b/src/Component/Power/BAT.h index 8799b6265..5cb09d34c 100644 --- a/src/Component/Power/BAT.h +++ b/src/Component/Power/BAT.h @@ -25,8 +25,8 @@ class BAT : public ComponentBase, public ILoggable double GetCVChargeVoltage() const; //今後実装方法は変える? /*LOG出力用関数*/ - string GetLogHeader() const override; - string GetLogValue() const override; + std::string GetLogHeader() const override; + std::string GetLogValue() const override; private: const int number_of_series_; @@ -42,4 +42,4 @@ class BAT : public ComponentBase, public ILoggable void MainRoutine(int time_count) override; void UpdateBatVoltage(); -}; \ No newline at end of file +}; diff --git a/src/Component/Power/PCU.cpp b/src/Component/Power/PCU.cpp index 1870785da..0a9e86506 100644 --- a/src/Component/Power/PCU.cpp +++ b/src/Component/Power/PCU.cpp @@ -47,14 +47,14 @@ int PCU::ClosePort(const int port_id) return 0; } -string PCU::GetLogHeader() const +std::string PCU::GetLogHeader() const { - string str_tmp = ""; + std::string str_tmp = ""; return str_tmp; } -string PCU::GetLogValue() const +std::string PCU::GetLogValue() const { - string str_tmp = ""; + std::string str_tmp = ""; return str_tmp; } diff --git a/src/Component/Power/PCU.h b/src/Component/Power/PCU.h index f76a6a777..ea185b6c9 100644 --- a/src/Component/Power/PCU.h +++ b/src/Component/Power/PCU.h @@ -15,8 +15,8 @@ class PCU : public ComponentBase, public ILoggable // Override ComponentBase void MainRoutine(int count) override; // Override ILoggable - string GetLogHeader() const override; - string GetLogValue() const override; + std::string GetLogHeader() const override; + std::string GetLogValue() const override; // Getter inline PowerPort* GetPowerPort(int port_id){return ports_[port_id];}; @@ -28,4 +28,4 @@ class PCU : public ComponentBase, public ILoggable private: std::map ports_; -}; \ No newline at end of file +}; diff --git a/src/Component/Power/PCU_InitialStudy.cpp b/src/Component/Power/PCU_InitialStudy.cpp index 99f33861a..5321d874e 100644 --- a/src/Component/Power/PCU_InitialStudy.cpp +++ b/src/Component/Power/PCU_InitialStudy.cpp @@ -16,17 +16,17 @@ PCU_InitialStudy::~PCU_InitialStudy() { } -string PCU_InitialStudy::GetLogHeader() const +std::string PCU_InitialStudy::GetLogHeader() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteScalar("power_consumption", "W"); str_tmp += WriteScalar("bus_voltage", "V"); return str_tmp; } -string PCU_InitialStudy::GetLogValue() const +std::string PCU_InitialStudy::GetLogValue() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteScalar(power_consumption_); str_tmp += WriteScalar(bus_voltage_); return str_tmp; @@ -110,4 +110,4 @@ void PCU_InitialStudy::UpdateChargeCurrentAndBusVoltage() bus_voltage_ = bat_voltage + bat_resistance * (cv_charge_voltage_ - bat_voltage) / bat_resistance; } } -} \ No newline at end of file +} diff --git a/src/Component/Power/PCU_InitialStudy.h b/src/Component/Power/PCU_InitialStudy.h index 89c726aba..01303e319 100644 --- a/src/Component/Power/PCU_InitialStudy.h +++ b/src/Component/Power/PCU_InitialStudy.h @@ -14,8 +14,8 @@ class PCU_InitialStudy : public ComponentBase , public ILoggable ~PCU_InitialStudy(); /*LOG出力用関数*/ - string GetLogHeader() const override; - string GetLogValue() const override; + std::string GetLogHeader() const override; + std::string GetLogValue() const override; private: const std::vector saps_; @@ -28,4 +28,4 @@ class PCU_InitialStudy : public ComponentBase , public ILoggable void MainRoutine(int time_count) override; double CalcPowerConsumption(int time_in_sec) const; void UpdateChargeCurrentAndBusVoltage(); -}; \ No newline at end of file +}; diff --git a/src/Component/Power/SAP.cpp b/src/Component/Power/SAP.cpp index 15bc33ded..562d7d49d 100644 --- a/src/Component/Power/SAP.cpp +++ b/src/Component/Power/SAP.cpp @@ -40,16 +40,16 @@ void SAP::SetVoltage(const double voltage) voltage_ = voltage; } -string SAP::GetLogHeader() const +std::string SAP::GetLogHeader() const { - string str_tmp = ""; - str_tmp += WriteScalar("power_generation"+to_string(id_), "W"); + std::string str_tmp = ""; + str_tmp += WriteScalar("power_generation"+std::to_string(id_), "W"); return str_tmp; } -string SAP::GetLogValue() const +std::string SAP::GetLogValue() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteScalar(power_generation_); return str_tmp; } @@ -74,4 +74,4 @@ void SAP::MainRoutine(int time_count) inner_product(normal_vector_, normalized_sun_direction); //仮の実装.実際は太陽方向などからIVカーブを更新.動作電圧に応じた発電電力を求める } if (power_generation_ < 0) power_generation_ = 0.0; -} \ No newline at end of file +} diff --git a/src/Component/Power/SAP.h b/src/Component/Power/SAP.h index 4380cdc27..9d0fce191 100644 --- a/src/Component/Power/SAP.h +++ b/src/Component/Power/SAP.h @@ -24,8 +24,8 @@ class SAP : public ComponentBase, public ILoggable void SetVoltage(const double voltage); /*LOG出力用関数*/ - string GetLogHeader() const override; - string GetLogValue() const override; + std::string GetLogHeader() const override; + std::string GetLogValue() const override; private: const int id_; //ここは文字列にした方が分かりやすい? @@ -45,4 +45,4 @@ class SAP : public ComponentBase, public ILoggable static const double light_speed_; void MainRoutine(int time_count) override; -}; \ No newline at end of file +}; diff --git a/src/Component/Propulsion/SimpleThruster.cpp b/src/Component/Propulsion/SimpleThruster.cpp index 03935d9ff..f1e43bfb9 100644 --- a/src/Component/Propulsion/SimpleThruster.cpp +++ b/src/Component/Propulsion/SimpleThruster.cpp @@ -74,20 +74,20 @@ void SimpleThruster::CalcTorque(Vector<3> center, double temp) torque_b_ = torque; } -string SimpleThruster::GetLogHeader() const +std::string SimpleThruster::GetLogHeader() const { - string str_tmp = ""; + std::string str_tmp = ""; - string head = "TH" + to_string(id_); + std::string head = "TH" + std::to_string(id_); str_tmp += WriteVector(head+"thrust", "b", "N", 3); str_tmp += WriteVector(head+"torque", "b", "Nm", 3); str_tmp += WriteScalar(head + "thrust", "N"); return str_tmp; } -string SimpleThruster::GetLogValue() const +std::string SimpleThruster::GetLogValue() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteVector(thrust_b_); str_tmp += WriteVector(torque_b_); diff --git a/src/Component/Propulsion/SimpleThruster.h b/src/Component/Propulsion/SimpleThruster.h index cfb684646..eafc253a1 100644 --- a/src/Component/Propulsion/SimpleThruster.h +++ b/src/Component/Propulsion/SimpleThruster.h @@ -43,8 +43,8 @@ class SimpleThruster : public ComponentBase, public ILoggable void MainRoutine(int count); // ILogabble override function - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; // Getter inline const Vector<3> GetThrustB() const { return thrust_b_; }; diff --git a/src/Disturbance/AirDrag.h b/src/Disturbance/AirDrag.h index cfd7a3cf7..de02a89ba 100644 --- a/src/Disturbance/AirDrag.h +++ b/src/Disturbance/AirDrag.h @@ -1,6 +1,9 @@ #ifndef __AirDrag_H__ #define __AirDrag_H__ +#include +#include + #include "../Library/math/Vector.hpp" #include "../Library/math/Quaternion.hpp" #include "SurfaceForce.h" @@ -26,12 +29,12 @@ class AirDrag : public SurfaceForce virtual void Update(const LocalEnvironment & local_env, const Dynamics & dynamics); // Override Loggable - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; //for debug void PrintParams(void); - vector cnct; + std::vector cnct; private: vector Cn_; //coefficients for out-plane force diff --git a/src/Disturbance/Disturbances.h b/src/Disturbance/Disturbances.h index d34f3a472..ac01f00cb 100644 --- a/src/Disturbance/Disturbances.h +++ b/src/Disturbance/Disturbances.h @@ -6,8 +6,6 @@ #include"../Simulation/Spacecraft/Structure/Structure.h" #include"../Environment/Global/SimTime.h" -using namespace std; - class Logger; class Disturbances @@ -24,11 +22,11 @@ class Disturbances Vector<3> GetAccelerationI(); private: - string ini_fname_; + std::string ini_fname_; void InitializeInstances(SimulationConfig* sim_config, const int sat_id, Structure* structure); void InitializeForceAndTorque(); void InitializeAcceleration(); - vector disturbances_; + std::vector disturbances_; Vector<3> sum_torque_; Vector<3> sum_force_; vector acc_disturbances_; diff --git a/src/Disturbance/GGDist.h b/src/Disturbance/GGDist.h index c4e0a9bab..c560e86cb 100644 --- a/src/Disturbance/GGDist.h +++ b/src/Disturbance/GGDist.h @@ -1,5 +1,7 @@ #ifndef __GGDist_H__ #define __GGDist_H__ +#include + #include "../Interface/LogOutput/ILoggable.h" #include "../Library/math/Matrix.hpp" #include "../Library/math/Vector.hpp" @@ -17,8 +19,8 @@ class GGDist : public SimpleDisturbance virtual void Update(const LocalEnvironment & local_env, const Dynamics & dynamics); Vector<3> CalcTorque(double R0, Vector<3> u_b, Matrix<3, 3> I_b); Vector<3> CalcTorque(Vector<3> r_b, Matrix<3, 3> I_b); - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; private: double mu_e_; diff --git a/src/Disturbance/GeoPotential.h b/src/Disturbance/GeoPotential.h index e4c2787d2..deaf41158 100644 --- a/src/Disturbance/GeoPotential.h +++ b/src/Disturbance/GeoPotential.h @@ -1,5 +1,7 @@ #ifndef __GEOPOTENTIAL_H__ #define __GEOPOTENTIAL_H__ +#include + #include "../Interface/LogOutput/ILoggable.h" #include "../Library/math/Matrix.hpp" #include "../Library/math/Vector.hpp" @@ -12,13 +14,13 @@ using libra::Vector; class GeoPotential : public AccelerationDisturbance { public: - GeoPotential(const int degree, const string file_path); + GeoPotential(const int degree, const std::string file_path); virtual void Update(const LocalEnvironment & local_env, const Dynamics & dynamics); - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; void CalcAccelerationECEF(const Vector<3>& position_ecef); - bool ReadCoefficientsEGM96(string file_name); + bool ReadCoefficientsEGM96(std::string file_name); private: int degree_; vector> c_; diff --git a/src/Disturbance/MagDisturbance.h b/src/Disturbance/MagDisturbance.h index 5743eb531..f6a16edd7 100644 --- a/src/Disturbance/MagDisturbance.h +++ b/src/Disturbance/MagDisturbance.h @@ -1,6 +1,8 @@ #ifndef __MagDisturbance_H__ #define __MagDisturbance_H__ +#include + #include "../Library/math/Vector.hpp" using libra::Vector; @@ -27,8 +29,8 @@ class MagDisturbance : public SimpleDisturbance virtual void Update(const LocalEnvironment & local_env, const Dynamics & dynamics); void PrintTorque(); - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; }; #endif //__MagDisturbance_H__ diff --git a/src/Disturbance/SolarRadiation.cpp b/src/Disturbance/SolarRadiation.cpp index 57af7ac6e..22f68e2f2 100644 --- a/src/Disturbance/SolarRadiation.cpp +++ b/src/Disturbance/SolarRadiation.cpp @@ -34,9 +34,9 @@ void SolarRadiation::CalcCoef(Vector<3>& input_b, double item) } } -string SolarRadiation::GetLogHeader() const +std::string SolarRadiation::GetLogHeader() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteVector("srp_torque", "b", "Nm", 3); str_tmp += WriteVector("srp_force", "b", "N", 3); @@ -44,9 +44,9 @@ string SolarRadiation::GetLogHeader() const return str_tmp; } -string SolarRadiation::GetLogValue() const +std::string SolarRadiation::GetLogValue() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteVector(torque_b_); str_tmp += WriteVector(force_b_); diff --git a/src/Disturbance/SolarRadiation.h b/src/Disturbance/SolarRadiation.h index df22f0ee6..899e5d686 100644 --- a/src/Disturbance/SolarRadiation.h +++ b/src/Disturbance/SolarRadiation.h @@ -8,6 +8,8 @@ #ifndef __SolarRadiation_h__ #define __SolarRadiation_h__ +#include + #include "../Interface/LogOutput/ILoggable.h" #include "SurfaceForce.h" #include "../Library/math/Vector.hpp" @@ -22,8 +24,8 @@ class SolarRadiation : public SurfaceForce virtual void Update(const LocalEnvironment & local_env, const Dynamics & dynamics); // Override Loggable - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; private: // Override SurfaceForce diff --git a/src/Disturbance/ThirdBodyGravity.cpp b/src/Disturbance/ThirdBodyGravity.cpp index af49902b6..041ff14c3 100644 --- a/src/Disturbance/ThirdBodyGravity.cpp +++ b/src/Disturbance/ThirdBodyGravity.cpp @@ -1,6 +1,6 @@ #include "ThirdBodyGravity.h" -ThirdBodyGravity::ThirdBodyGravity(std::set third_body_list) :third_body_list_(third_body_list) +ThirdBodyGravity::ThirdBodyGravity(std::set third_body_list) :third_body_list_(third_body_list) { acceleration_i_ *= 0; } @@ -39,18 +39,18 @@ libra::Vector<3> ThirdBodyGravity::CalcAcceleration(libra::Vector<3> s, libra::V return acc; } -string ThirdBodyGravity::GetLogHeader() const +std::string ThirdBodyGravity::GetLogHeader() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteVector("acc_thirdbody", "i", "m/s2", 3); return str_tmp; } -string ThirdBodyGravity::GetLogValue() const +std::string ThirdBodyGravity::GetLogValue() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteVector(acceleration_i_); return str_tmp; -} \ No newline at end of file +} diff --git a/src/Disturbance/ThirdBodyGravity.h b/src/Disturbance/ThirdBodyGravity.h index 2a6fb4661..65517431e 100644 --- a/src/Disturbance/ThirdBodyGravity.h +++ b/src/Disturbance/ThirdBodyGravity.h @@ -1,4 +1,6 @@ #pragma once +#include + #include"../Interface/LogOutput/ILoggable.h" #include"AccelerationDisturbance.h" #include @@ -8,17 +10,17 @@ class ThirdBodyGravity : public AccelerationDisturbance { public: - ThirdBodyGravity(std::set third_body_list); + ThirdBodyGravity(std::set third_body_list); ~ThirdBodyGravity(); virtual void Update(const LocalEnvironment & local_env, const Dynamics & dynamics); private: - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; libra::Vector<3> CalcAcceleration(libra::Vector<3> s, libra::Vector<3> sr, double GM); - std::set third_body_list_; + std::set third_body_list_; libra::Vector<3> thirdbody_acc_i_{ 0 }; }; diff --git a/src/Dynamics/Attitude/Attitude.h b/src/Dynamics/Attitude/Attitude.h index c912fa6eb..d428f0420 100644 --- a/src/Dynamics/Attitude/Attitude.h +++ b/src/Dynamics/Attitude/Attitude.h @@ -2,7 +2,6 @@ #define __attitude_H__ #include -using namespace std; #include "../../Library/math/MatVec.hpp" #include "../../Library/math/Quaternion.hpp" @@ -85,8 +84,8 @@ class Attitude : public ILoggable virtual void Propagate(double endtime) = 0; - virtual string GetLogHeader() const = 0; - virtual string GetLogValue() const = 0; + virtual std::string GetLogHeader() const = 0; + virtual std::string GetLogValue() const = 0; bool IsCalcEnabled = true; diff --git a/src/Dynamics/Attitude/AttitudeRK4.h b/src/Dynamics/Attitude/AttitudeRK4.h index 6a757b143..c8a523774 100644 --- a/src/Dynamics/Attitude/AttitudeRK4.h +++ b/src/Dynamics/Attitude/AttitudeRK4.h @@ -17,7 +17,7 @@ class AttitudeRK4 :public Attitude, public SimulationObject const Matrix<3, 3>& InertiaTensor_ini, const Vector<3>& torque_b_ini, const double prop_step_ini, - string name); + std::string name); ~AttitudeRK4(); //MonteCalro @@ -25,8 +25,8 @@ class AttitudeRK4 :public Attitude, public SimulationObject virtual void Propagate(double endtime); // 姿勢・角速度のプロパゲーション - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; //デバッグ出力 void PrintParams(void); diff --git a/src/Dynamics/Attitude/ControlledAttitude.h b/src/Dynamics/Attitude/ControlledAttitude.h index 345b9a14d..0d72593d7 100644 --- a/src/Dynamics/Attitude/ControlledAttitude.h +++ b/src/Dynamics/Attitude/ControlledAttitude.h @@ -2,7 +2,6 @@ #define __controlled_attitude_H__ #include -using namespace std; #include "Attitude.h" #include "../../Environment/Local/LocalCelestialInformation.h" @@ -26,8 +25,8 @@ class ControlledAttitude : public Attitude virtual void Propagate(double endtime); // Override ILoggable - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; private: //Inputs diff --git a/src/Dynamics/Dynamics.h b/src/Dynamics/Dynamics.h index e8a239d30..82ed01e6e 100644 --- a/src/Dynamics/Dynamics.h +++ b/src/Dynamics/Dynamics.h @@ -2,7 +2,6 @@ #define __dynamics_H__ #include -using namespace std; #include "../Library/math/Vector.hpp" using libra::Vector; @@ -69,4 +68,4 @@ class Dynamics Temperature* temperature_; }; -#endif //__dynamics_H__ \ No newline at end of file +#endif //__dynamics_H__ diff --git a/src/Dynamics/Orbit/EarthCenteredOrbit.h b/src/Dynamics/Orbit/EarthCenteredOrbit.h index 1151efab9..1eae06b32 100644 --- a/src/Dynamics/Orbit/EarthCenteredOrbit.h +++ b/src/Dynamics/Orbit/EarthCenteredOrbit.h @@ -13,8 +13,8 @@ class EarthCenteredOrbit : public Orbit Vector<3> GetESIOmega(); - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; private: const CelestialInformation* celes_info_; diff --git a/src/Dynamics/Orbit/Orbit.h b/src/Dynamics/Orbit/Orbit.h index c9daf5f3f..cd59b7c1e 100644 --- a/src/Dynamics/Orbit/Orbit.h +++ b/src/Dynamics/Orbit/Orbit.h @@ -161,8 +161,8 @@ class Orbit: public ILoggable return q_i2lvlh.normalize(); } - virtual string GetLogHeader() const = 0; - virtual string GetLogValue() const = 0; + virtual std::string GetLogHeader() const = 0; + virtual std::string GetLogValue() const = 0; inline virtual Vector<3> GetESIOmega()const { return Vector<3>();} diff --git a/src/Dynamics/Orbit/RelativeOrbit.cpp b/src/Dynamics/Orbit/RelativeOrbit.cpp index d21864b0a..401516da0 100644 --- a/src/Dynamics/Orbit/RelativeOrbit.cpp +++ b/src/Dynamics/Orbit/RelativeOrbit.cpp @@ -183,15 +183,15 @@ void RelativeOrbit::RHS(double t, const Vector<6>& state, Vector<6>& rhs) // onl (void)t; } -string RelativeOrbit::GetLogHeader() const +std::string RelativeOrbit::GetLogHeader() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteVector("sat_position", "i", "m", 3); str_tmp += WriteVector("sat_velocity", "i", "m/s", 3); str_tmp += WriteVector("sat_velocity", "b", "m/s", 3); - str_tmp += WriteVector("sat_position_relative_to_sat" + to_string(reference_sat_id_), "LVLH", "m", 3); - str_tmp += WriteVector("sat_velocity_relative_to_sat" + to_string(reference_sat_id_), "LVLH", "m", 3); + str_tmp += WriteVector("sat_position_relative_to_sat" + std::to_string(reference_sat_id_), "LVLH", "m", 3); + str_tmp += WriteVector("sat_velocity_relative_to_sat" + std::to_string(reference_sat_id_), "LVLH", "m", 3); str_tmp += WriteVector("sat_acc_i", "i", "m/s^2", 3); str_tmp += WriteScalar("lat", "rad"); str_tmp += WriteScalar("lon", "rad"); @@ -200,9 +200,9 @@ string RelativeOrbit::GetLogHeader() const return str_tmp; } -string RelativeOrbit::GetLogValue() const +std::string RelativeOrbit::GetLogValue() const { - string str_tmp = ""; + std::string str_tmp = ""; str_tmp += WriteVector(sat_position_i_, 16); str_tmp += WriteVector(sat_velocity_i_, 10); diff --git a/src/Dynamics/Orbit/RelativeOrbit.h b/src/Dynamics/Orbit/RelativeOrbit.h index cc3223a37..aaea21f93 100644 --- a/src/Dynamics/Orbit/RelativeOrbit.h +++ b/src/Dynamics/Orbit/RelativeOrbit.h @@ -1,4 +1,6 @@ #pragma once +#include + #include "Orbit.h" #include "../../Library/math/ODE.hpp" #include "../../RelativeInformation/RelativeInformation.h" @@ -31,8 +33,8 @@ class RelativeOrbit : public Orbit, public libra::ODE<6> virtual void RHS(double t, const Vector<6>& state, Vector<6>& rhs); - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; private: double mu_; diff --git a/src/Dynamics/Orbit/SimpleCircularOrbit.cpp b/src/Dynamics/Orbit/SimpleCircularOrbit.cpp index 4939e9626..be457fcee 100644 --- a/src/Dynamics/Orbit/SimpleCircularOrbit.cpp +++ b/src/Dynamics/Orbit/SimpleCircularOrbit.cpp @@ -2,6 +2,8 @@ #include #include +using std::string; + SimpleCircularOrbit::SimpleCircularOrbit(const CelestialInformation* celes_info, double mu, double timestep, int wgs, Vector<3> init_position, Vector<3> init_velocity, double current_jd, double init_time) : celes_info_(celes_info), ODE(timestep), mu(mu) { diff --git a/src/Dynamics/Orbit/SimpleCircularOrbit.h b/src/Dynamics/Orbit/SimpleCircularOrbit.h index 259639d3e..8c1f87233 100644 --- a/src/Dynamics/Orbit/SimpleCircularOrbit.h +++ b/src/Dynamics/Orbit/SimpleCircularOrbit.h @@ -24,8 +24,8 @@ class SimpleCircularOrbit : public Orbit, public libra::ODE<6> virtual void AddPositionOffset(Vector<3> offset_i); - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; private: double prop_time_; //Simulation current time for numerical integration by RK4 diff --git a/src/Dynamics/Thermal/Node.h b/src/Dynamics/Thermal/Node.h index 937a54ffe..098dc5c47 100644 --- a/src/Dynamics/Thermal/Node.h +++ b/src/Dynamics/Thermal/Node.h @@ -5,8 +5,6 @@ #include #include -using namespace std; - #include "../../Interface/LogOutput/Logger.h" @@ -14,7 +12,7 @@ class Node { protected: int node_id_; //node番号 - string node_label_; //node name + std::string node_label_; //node name int heater_node_id_; // heater node番号 double temperature_; // 温度[K] double capacity_; // 熱容量[J/K] @@ -29,7 +27,7 @@ class Node public: Node(const int node_id, - const string node_label, + const std::string node_label, const int heater_node_id, const double temperature_ini, const double capacity_ini, @@ -45,7 +43,7 @@ class Node //Output from this class int GetNodeId(void) const; - string GetNodeLabel(void) const; + std::string GetNodeLabel(void) const; int GetHeaterNodeId(void) const; double GetTemperature_K(void) const; double GetTemperature_deg(void) const; diff --git a/src/Dynamics/Thermal/Temperature.h b/src/Dynamics/Thermal/Temperature.h index 25bc91b06..f75d748cd 100644 --- a/src/Dynamics/Thermal/Temperature.h +++ b/src/Dynamics/Thermal/Temperature.h @@ -5,7 +5,6 @@ #include #include -using namespace std; #include "../../Interface/LogOutput/ILoggable.h" #include "Node.h" @@ -13,9 +12,9 @@ using namespace std; class Temperature: public ILoggable { protected: - vector> cij_; //Coupling of node i and node j by heat conduction - vector> rij_; //Coupling of node i and node j by thermal radiation - vector vnodes_; //vector of nodes + std::vector> cij_; //Coupling of node i and node j by heat conduction + std::vector> rij_; //Coupling of node i and node j by thermal radiation + std::vector vnodes_; //vector of nodes int node_num_; //number of nodes double prop_step_; //積分刻み幅[sec] double prop_time_; //Temperatureクラス内での累積積分時間(end_timeに等しくなるまで積分する) @@ -23,22 +22,22 @@ class Temperature: public ILoggable bool debug_; void RungeOneStep(double t, double dt, Vector<3> sun_direction, int node_num); // ルンゲクッタOne Step - vector OdeTemperature(vector x, double t, const Vector<3> sun_direction, int node_num); // 温度に関する常微分方程式, xはnodeの温度をならべたもの + std::vector OdeTemperature(std::vector x, double t, const Vector<3> sun_direction, int node_num); // 温度に関する常微分方程式, xはnodeの温度をならべたもの public: - Temperature(const vector> cij_, - const vector> rij, - vector vnodes, + Temperature(const std::vector> cij_, + const std::vector> rij, + std::vector vnodes, const int node_num, const double propstep, const bool is_calc_enabled, const bool debug); ~Temperature(); void Propagate(Vector<3> sun_direction,const double endtime); //太陽入熱量計算のため, 太陽方向の情報を入手 - vector GetVnodes() const; - void AddHeaterPower(vector heater_power); - string GetLogHeader() const; - string GetLogValue() const; + std::vector GetVnodes() const; + void AddHeaterPower(std::vector heater_power); + std::string GetLogHeader() const; + std::string GetLogValue() const; void PrintParams(void); //デバッグ出力 }; #endif //__temperature_H__ diff --git a/src/Environment/Global/CelestialInformation.h b/src/Environment/Global/CelestialInformation.h index 1bf02b234..643f6e691 100644 --- a/src/Environment/Global/CelestialInformation.h +++ b/src/Environment/Global/CelestialInformation.h @@ -3,7 +3,6 @@ #include #include -using namespace std; #include "../../Library/math/Matrix.hpp" #include "../../Library/math/Vector.hpp" @@ -19,7 +18,7 @@ class CelestialInformation : public ILoggable { public: // CONSTRUCTOR OF CELESTIAL INFORMATION - CelestialInformation(string inertial_frame, string aber_cor, string center_obj, RotationMode rotation_mode, int num_of_selected_body, int* selected_body); + CelestialInformation(std::string inertial_frame, std::string aber_cor, std::string center_obj, RotationMode rotation_mode, int num_of_selected_body, int* selected_body); CelestialInformation(const CelestialInformation &obj); ~CelestialInformation(); @@ -35,13 +34,13 @@ class CelestialInformation : public ILoggable inline int GetNumBody(void) const{return num_of_selected_body_;} inline int* GetSelectedBody(void) const{return selected_body_;} int CalcBodyIdFromName(const char* body_name) const; - inline string GetCenterBodyName(void) const { return center_obj_; } + inline std::string GetCenterBodyName(void) const { return center_obj_; } inline CelestialRotation GetEarthRotation(void) const { return *EarthRotation_; }; // FOR LOG OUTPUT - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; // FOR DEBUG OUTPUT void DebugOutput(void); @@ -49,9 +48,9 @@ class CelestialInformation : public ILoggable private: int num_of_selected_body_; int* selected_body_; //IDs of selected bodies. - string inertial_frame_; //Definition of inertial frame. Default = "J2000" - string aber_cor_; //stellar aberration correction. Default = "NONE"(Ref:http://fermi.gsfc.nasa.gov/ssc/library/fug/051108/Aberration_Julie.ppt) - string center_obj_; //center object. Default = "EARTH" + std::string inertial_frame_; //Definition of inertial frame. Default = "J2000" + std::string aber_cor_; //stellar aberration correction. Default = "NONE"(Ref:http://fermi.gsfc.nasa.gov/ssc/library/fug/051108/Aberration_Julie.ppt) + std::string center_obj_; //center object. Default = "EARTH" RotationMode rotation_mode_; //designation of dynamics model. Default = "Full" // Global Information. POS:[m], VEL:[m/s], GRAVITY CONSTANT (G*M):[m^3/s^2] diff --git a/src/Environment/Global/CelestialRotation.cpp b/src/Environment/Global/CelestialRotation.cpp index c2d8e6268..d0c20f6bc 100644 --- a/src/Environment/Global/CelestialRotation.cpp +++ b/src/Environment/Global/CelestialRotation.cpp @@ -1,264 +1,264 @@ -#include -#include - -#include "CelestialRotation.h" -#include "../../Library/sgp4/sgp4unit.h" //for gstime() -#include "../../Library/sgp4/sgp4ext.h" //for jday() - -using namespace std; - -#define DEG2RAD 0.017453292519943295769 // PI/180 -#define ASEC2RAD DEG2RAD/3600.0 - -// default constructor -CelestialRotation::CelestialRotation(const RotationMode rotation_mode, const string center_obj) -{ - planet_name_ = "Anonymous"; - rotation_mode_ = Idle; - unitalize(DCM_J2000toXCXF_); - DCM_TEMEtoXCXF_ = DCM_J2000toXCXF_; - if (center_obj == "EARTH") - { - Init_CelestialRotation_As_Earth(rotation_mode, center_obj); - } -}; - -// initialize the class CelestialRotation instance as Earth -void CelestialRotation::Init_CelestialRotation_As_Earth(const RotationMode rotation_mode, const string center_obj) -{ - planet_name_ = "EARTH"; - if (center_obj == planet_name_) - { - if (rotation_mode == Simple) - { - rotation_mode_ = Simple; - - // 自転軸周りの回転だけなら,係数初期化は不要か - } - else if (rotation_mode == Full) - { - rotation_mode_ = Full; - - // フルダイナミクスを使う場合は,ひとまず直接,各種係数の初期化を実施 - // 文献との比較確認がし易い様に,単位系は(敢えて)文献に良くあるdeg,arcsec混在系で定義しておく - // coefficients for computing mean obliquity of the ecliptic - // the actual unit of c_epsi_rad_ is [rad/century^i], i is the index of the array - c_epsi_rad_[0] = 23.4392911 * DEG2RAD; // [rad] - c_epsi_rad_[1] = -46.8150000 * ASEC2RAD; // [rad/century] - c_epsi_rad_[2] = -5.9000e-4 * ASEC2RAD; // [rad/century^2] - c_epsi_rad_[3] = 1.8130e-3 * ASEC2RAD; // [rad/century^3] - - // coefficients for computing five delauney angles(l=lm,l'=ls,F,D,Ω=O) - // lm means mean anomaly of the moon - // the actual unit of c_lm_rad_ is [rad/century^i], i is the index of the array - c_lm_rad_[0] = 134.96340251 * DEG2RAD; // [rad] - c_lm_rad_[1] = 1717915923.21780000 * ASEC2RAD; // [rad/century] - c_lm_rad_[2] = 31.87920000 * ASEC2RAD; // [rad/century^2] - c_lm_rad_[3] = 0.05163500 * ASEC2RAD; // [rad/century^3] - c_lm_rad_[4] = -0.00024470 * ASEC2RAD; // [rad/century^4] - // ls means mean anomaly of the sun - // the actual unit of c_ls_rad_ is [rad/century^i], i is the index of the array - c_ls_rad_[0] = 357.52910918 * DEG2RAD; // [rad] - c_ls_rad_[1] = 129596581.04810000 * ASEC2RAD; // [rad/century] - c_ls_rad_[2] = -0.55320000 * ASEC2RAD; // [rad/century^2] - c_ls_rad_[3] = 0.00013600 * ASEC2RAD; // [rad/century^3] - c_ls_rad_[4] = -0.00001149 * ASEC2RAD; // [rad/century^4] - // F means mean longitude of the moon - mean longitude of ascending node of the moon - // the actual unit of c_F_rad_ is [rad/century^i], i is the index of the array - c_F_rad_[0] = 93.27209062 * DEG2RAD; // [rad] - c_F_rad_[1] = 1739527262.84780000 * ASEC2RAD; // [rad/century] - c_F_rad_[2] = -12.75120000 * ASEC2RAD; // [rad/century^2] - c_F_rad_[3] = -0.00103700 * ASEC2RAD; // [rad/century^3] - c_F_rad_[4] = 0.00000417 * ASEC2RAD; // [rad/century^4] - // D means mean elogation of the moon from the sun - // the actual unit of c_D_rad_ is [rad/century^i], i is the index of the array - c_D_rad_[0] = 297.85019547 * DEG2RAD; // [rad] - c_D_rad_[1] = 1602961601.20900000 * ASEC2RAD; // [rad/century] - c_D_rad_[2] = -6.37060000 * ASEC2RAD; // [rad/century^2] - c_D_rad_[3] = 0.00659300 * ASEC2RAD; // [rad/century^3] - c_D_rad_[4] = -0.00003169 * ASEC2RAD; // [rad/century^4] - // O means mean longitude of ascending node of the moon - // the actual unit of c_O_rad_ is [rad/century^i], i is the index of the array - c_O_rad_[0] = 125.04455501 * DEG2RAD; // [rad] - c_O_rad_[1] = -6962890.54310000 * ASEC2RAD; // [rad/century] - c_O_rad_[2] = 7.47220000 * ASEC2RAD; // [rad/century^2] - c_O_rad_[3] = 0.00770200 * ASEC2RAD; // [rad/century^3] - c_O_rad_[4] = -0.00005939 * ASEC2RAD; // [rad/century^4] - - // coefficients for computing nutation angles - // delta epsilon - c_depsilon_rad_[0] = 9.2050 * ASEC2RAD; // [rad] - c_depsilon_rad_[1] = 0.5730 * ASEC2RAD; // [rad] - c_depsilon_rad_[2] = -0.0900 * ASEC2RAD; // [rad] - c_depsilon_rad_[3] = 0.0980 * ASEC2RAD; // [rad] - c_depsilon_rad_[4] = 0.0070 * ASEC2RAD; // [rad] - c_depsilon_rad_[5] = -0.0010 * ASEC2RAD; // [rad] - c_depsilon_rad_[6] = 0.0220 * ASEC2RAD; // [rad] - c_depsilon_rad_[7] = 0.0130 * ASEC2RAD; // [rad] - c_depsilon_rad_[8] = -0.0100 * ASEC2RAD; // [rad] - // delta psi - c_dpsi_rad_[0] = -17.2060 * ASEC2RAD; // [rad] - c_dpsi_rad_[1] = -1.3170 * ASEC2RAD; // [rad] - c_dpsi_rad_[2] = 0.2070 * ASEC2RAD; // [rad] - c_dpsi_rad_[3] = -0.2280 * ASEC2RAD; // [rad] - c_dpsi_rad_[4] = 0.1480 * ASEC2RAD; // [rad] - c_dpsi_rad_[5] = 0.0710 * ASEC2RAD; // [rad] - c_dpsi_rad_[6] = -0.0520 * ASEC2RAD; // [rad] - c_dpsi_rad_[7] = -0.0300 * ASEC2RAD; // [rad] - c_dpsi_rad_[8] = 0.0220 * ASEC2RAD; // [rad] - - // coefficients for computing precession angles(zeta, theta, z) - // the actual unit of c_zeta_rad_ is [rad/century^(i+1)], i is the index of the array - c_zeta_rad_[0] = 2306.218100 * ASEC2RAD; // [rad/century] - c_zeta_rad_[1] = 0.301880 * ASEC2RAD; // [rad/century^2] - c_zeta_rad_[2] = 0.017998 * ASEC2RAD; // [rad/century^3] - // the actual unit of c_theta_rad_ is [rad/century^(i+1)], i is the index of the array - c_theta_rad_[0] = 2004.310900 * ASEC2RAD; // [rad/century] - c_theta_rad_[1] = -0.426650 * ASEC2RAD; // [rad/century^2] - c_theta_rad_[2] = -0.041833 * ASEC2RAD; // [rad/century^3] - // the actual unit of c_z_rad_ is [rad/century^(i+1)], i is the index of the array - c_z_rad_[0] = 2306.218100 * ASEC2RAD; // [rad/century] - c_z_rad_[1] = 1.094680 * ASEC2RAD; // [rad/century^2] - c_z_rad_[2] = 0.018203 * ASEC2RAD; // [rad/century^3] - } - else - { - // if the rotation mode is neither Simple nor Full, disable the rotation calculation and make the DCM a unit matrix - rotation_mode_ = Idle; - unitalize(DCM_J2000toXCXF_); - } - } - else - { - // if the center object is not the Earth, disable the Earth's rotation calculation and make the DCM a unit matrix - rotation_mode_ = Idle; - unitalize(DCM_J2000toXCXF_); - } -} - -void CelestialRotation::Update(const double JulianDate) -{ - double gmst_rad = gstime(JulianDate); //長沢のアルゴリズムと微妙に違う…?,他と合わせた方が良いので,暫定このままで行く. - - if (rotation_mode_ == Full) - { - // compute Julian date for terestrial time - double jdTT_day = JulianDate + dtUT1UTC_ * kSec2Day; // 不正確かも(?)だが,S2E内部でグレゴリオ暦の伝播はしていないので,これで済ませる - - // compute nth power of julian century for terrestrial time - // the actual unit of tTT_century is [century^(i+1)], i is the index of the array - double tTT_century[4]; - tTT_century[0] = (jdTT_day - kJulianDateJ2000) / kDayJulianCentury; - for (int i = 0; i < 3; i++) { tTT_century[i+1] = tTT_century[i] * tTT_century[0]; } - - Matrix<3, 3> P; Matrix<3, 3> N; Matrix<3, 3> R; Matrix<3, 3> W; - // Nutation + Precession - P = Precession(tTT_century); - N = Nutation(tTT_century); // epsi_rad_, depsilon_rad_, dpsi_rad_ are updated in this proccedure - - // Axial Rotation - double Eq_rad = dpsi_rad_ * cos(epsi_rad_ + depsilon_rad_); // equation of equinoxes [rad] - double gast_rad = gmst_rad + Eq_rad; // Greenwitch 'Appearent' Sidereal Time [rad] - R = AxialRotation(gast_rad); - // polar motion (isnot considered so far, even without polar motion, the result agrees well with the matlab reference) - double Xp = 0.0; double Yp = 0.0; - W = PolarMotion(Xp, Yp); - - // total orientation - DCM_J2000toXCXF_ = W * R * N * P; - } - else if (rotation_mode_ == Simple) - { - // In this case, only Axial Rotation is executed, with its argument replaced from G'A'ST to G'M'ST - DCM_J2000toXCXF_ = AxialRotation(gmst_rad); - } - else - { - // leave the DCM as unit Matrix(diag{1,1,1}) - return; - } -} - -Matrix<3, 3> CelestialRotation::AxialRotation(const double GAST_rad) -{ - return libra::rotz(GAST_rad); -} - -Matrix<3, 3> CelestialRotation::Nutation(const double(&tTT_century)[4]) -{ - // mean obliquity of the ecliptic - epsi_rad_ = c_epsi_rad_[0]; // [rad] - for (int i = 0; i < 3; i++) { epsi_rad_ += c_epsi_rad_[i+1] * tTT_century[i]; } - - // compute five delauney angles(l=lm,l'=ls,F,D,Ω=O) - // mean anomaly of the moon - double lm_rad = c_lm_rad_[0]; // [rad] - for (int i = 0; i < 4; i++) { lm_rad += c_lm_rad_[i+1] * tTT_century[i]; } - // mean anomaly of the sun - double ls_rad = c_ls_rad_[0]; // [rad] - for (int i = 0; i < 4; i++) { ls_rad += c_ls_rad_[i+1] * tTT_century[i]; } - // mean longitude of the moon - mean longitude of ascending node of the moon - double F_rad = c_F_rad_[0]; // [rad] - for (int i = 0; i < 4; i++) { F_rad += c_F_rad_[i+1] * tTT_century[i]; } - // mean elogation of the moon from the sun - double D_rad = c_D_rad_[0]; // [rad] - for (int i = 0; i < 4; i++) { D_rad += c_D_rad_[i+1] * tTT_century[i]; } - // mean longitude of ascending node of the moon - double O_rad = c_O_rad_[0]; // [rad] - for (int i = 0; i < 4; i++) { O_rad += c_O_rad_[i+1] * tTT_century[i]; } - - // additional angles - double L_rad = F_rad + O_rad; // F + Ω [rad] - double Ld_rad = L_rad - D_rad; // F - D + Ω [rad] - - // compute luni-solar nutation - // nutation in obliquity - dpsi_rad_ = c_dpsi_rad_[0] * sin(O_rad) + c_dpsi_rad_[1] * sin(2 * Ld_rad) + c_dpsi_rad_[2] * sin(2 * O_rad) + c_dpsi_rad_[3] * sin(2 * L_rad) + c_dpsi_rad_[4] * sin(ls_rad); // [rad] - dpsi_rad_ = dpsi_rad_ + c_dpsi_rad_[5] * sin(lm_rad) + c_dpsi_rad_[6] * sin(2 * Ld_rad + ls_rad) + c_dpsi_rad_[7] * sin(2 * L_rad + lm_rad) + c_dpsi_rad_[8] * sin(2 * Ld_rad - ls_rad); // [rad] - - // nutation in longitude - depsilon_rad_ = c_depsilon_rad_[0] * cos(O_rad) + c_depsilon_rad_[1] * cos(2 * Ld_rad) + c_depsilon_rad_[2] * cos(2 * O_rad) + c_depsilon_rad_[3] * cos(2 * L_rad) + c_depsilon_rad_[4] * cos(ls_rad); // [rad] - depsilon_rad_ = depsilon_rad_ + c_depsilon_rad_[5] * cos(lm_rad) + c_depsilon_rad_[6] * cos(2 * Ld_rad + ls_rad) + c_depsilon_rad_[7] * cos(2 * L_rad + lm_rad) + c_depsilon_rad_[8] * cos(2 * Ld_rad - ls_rad); // [rad] - - double epsi_mod_rad = epsi_rad_ + depsilon_rad_; - Matrix<3, 3> X_epsi_1st = libra::rotx(epsi_rad_); - Matrix<3, 3> Z_dpsi = libra::rotz(-dpsi_rad_); - Matrix<3, 3> X_epsi_2nd = libra::rotx(-epsi_mod_rad); - - Matrix<3, 3> N; - N = X_epsi_2nd * Z_dpsi * X_epsi_1st; - - return N; -} - -Matrix<3, 3> CelestialRotation::Precession(const double (&tTT_century)[4]) -{ - // compute precession angles(zeta, theta, z) - double zeta_rad = 0.0; // [rad] - for (int i = 0; i < 3; i++) { zeta_rad += c_zeta_rad_[i] * tTT_century[i]; } - double theta_rad = 0.0; // [rad] - for (int i = 0; i < 3; i++) { theta_rad += c_theta_rad_[i] * tTT_century[i]; } - double z_rad = 0.0; // [rad] - for (int i = 0; i < 3; i++) { z_rad += c_z_rad_[i] * tTT_century[i]; } - - // develop transformation matrix - Matrix<3, 3> Z_zeta = libra::rotz(-zeta_rad); - Matrix<3, 3> Y_theta = libra::roty(theta_rad); - Matrix<3, 3> Z_z = libra::rotz(-z_rad); - - Matrix<3, 3> P; - P = Z_z * Y_theta * Z_zeta; - - return P; -} - -Matrix<3, 3> CelestialRotation::PolarMotion(const double Xp, const double Yp) -{ - Matrix<3, 3> W; - - W[0][0] = 1.0; W[0][1] = 0.0; W[0][2] = -Xp; - W[1][0] = 0.0; W[1][1] = 1.0; W[1][2] = -Yp; - W[2][0] = Xp; W[2][1] = Yp; W[2][2] = 1.0; - - return W; +#include +#include + +#include "CelestialRotation.h" +#include "../../Library/sgp4/sgp4unit.h" //for gstime() +#include "../../Library/sgp4/sgp4ext.h" //for jday() + +using namespace std; + +#define DEG2RAD 0.017453292519943295769 // PI/180 +#define ASEC2RAD DEG2RAD/3600.0 + +// default constructor +CelestialRotation::CelestialRotation(const RotationMode rotation_mode, const string center_obj) +{ + planet_name_ = "Anonymous"; + rotation_mode_ = Idle; + unitalize(DCM_J2000toXCXF_); + DCM_TEMEtoXCXF_ = DCM_J2000toXCXF_; + if (center_obj == "EARTH") + { + Init_CelestialRotation_As_Earth(rotation_mode, center_obj); + } +}; + +// initialize the class CelestialRotation instance as Earth +void CelestialRotation::Init_CelestialRotation_As_Earth(const RotationMode rotation_mode, const string center_obj) +{ + planet_name_ = "EARTH"; + if (center_obj == planet_name_) + { + if (rotation_mode == Simple) + { + rotation_mode_ = Simple; + + // 自転軸周りの回転だけなら,係数初期化は不要か + } + else if (rotation_mode == Full) + { + rotation_mode_ = Full; + + // フルダイナミクスを使う場合は,ひとまず直接,各種係数の初期化を実施 + // 文献との比較確認がし易い様に,単位系は(敢えて)文献に良くあるdeg,arcsec混在系で定義しておく + // coefficients for computing mean obliquity of the ecliptic + // the actual unit of c_epsi_rad_ is [rad/century^i], i is the index of the array + c_epsi_rad_[0] = 23.4392911 * DEG2RAD; // [rad] + c_epsi_rad_[1] = -46.8150000 * ASEC2RAD; // [rad/century] + c_epsi_rad_[2] = -5.9000e-4 * ASEC2RAD; // [rad/century^2] + c_epsi_rad_[3] = 1.8130e-3 * ASEC2RAD; // [rad/century^3] + + // coefficients for computing five delauney angles(l=lm,l'=ls,F,D,Ω=O) + // lm means mean anomaly of the moon + // the actual unit of c_lm_rad_ is [rad/century^i], i is the index of the array + c_lm_rad_[0] = 134.96340251 * DEG2RAD; // [rad] + c_lm_rad_[1] = 1717915923.21780000 * ASEC2RAD; // [rad/century] + c_lm_rad_[2] = 31.87920000 * ASEC2RAD; // [rad/century^2] + c_lm_rad_[3] = 0.05163500 * ASEC2RAD; // [rad/century^3] + c_lm_rad_[4] = -0.00024470 * ASEC2RAD; // [rad/century^4] + // ls means mean anomaly of the sun + // the actual unit of c_ls_rad_ is [rad/century^i], i is the index of the array + c_ls_rad_[0] = 357.52910918 * DEG2RAD; // [rad] + c_ls_rad_[1] = 129596581.04810000 * ASEC2RAD; // [rad/century] + c_ls_rad_[2] = -0.55320000 * ASEC2RAD; // [rad/century^2] + c_ls_rad_[3] = 0.00013600 * ASEC2RAD; // [rad/century^3] + c_ls_rad_[4] = -0.00001149 * ASEC2RAD; // [rad/century^4] + // F means mean longitude of the moon - mean longitude of ascending node of the moon + // the actual unit of c_F_rad_ is [rad/century^i], i is the index of the array + c_F_rad_[0] = 93.27209062 * DEG2RAD; // [rad] + c_F_rad_[1] = 1739527262.84780000 * ASEC2RAD; // [rad/century] + c_F_rad_[2] = -12.75120000 * ASEC2RAD; // [rad/century^2] + c_F_rad_[3] = -0.00103700 * ASEC2RAD; // [rad/century^3] + c_F_rad_[4] = 0.00000417 * ASEC2RAD; // [rad/century^4] + // D means mean elogation of the moon from the sun + // the actual unit of c_D_rad_ is [rad/century^i], i is the index of the array + c_D_rad_[0] = 297.85019547 * DEG2RAD; // [rad] + c_D_rad_[1] = 1602961601.20900000 * ASEC2RAD; // [rad/century] + c_D_rad_[2] = -6.37060000 * ASEC2RAD; // [rad/century^2] + c_D_rad_[3] = 0.00659300 * ASEC2RAD; // [rad/century^3] + c_D_rad_[4] = -0.00003169 * ASEC2RAD; // [rad/century^4] + // O means mean longitude of ascending node of the moon + // the actual unit of c_O_rad_ is [rad/century^i], i is the index of the array + c_O_rad_[0] = 125.04455501 * DEG2RAD; // [rad] + c_O_rad_[1] = -6962890.54310000 * ASEC2RAD; // [rad/century] + c_O_rad_[2] = 7.47220000 * ASEC2RAD; // [rad/century^2] + c_O_rad_[3] = 0.00770200 * ASEC2RAD; // [rad/century^3] + c_O_rad_[4] = -0.00005939 * ASEC2RAD; // [rad/century^4] + + // coefficients for computing nutation angles + // delta epsilon + c_depsilon_rad_[0] = 9.2050 * ASEC2RAD; // [rad] + c_depsilon_rad_[1] = 0.5730 * ASEC2RAD; // [rad] + c_depsilon_rad_[2] = -0.0900 * ASEC2RAD; // [rad] + c_depsilon_rad_[3] = 0.0980 * ASEC2RAD; // [rad] + c_depsilon_rad_[4] = 0.0070 * ASEC2RAD; // [rad] + c_depsilon_rad_[5] = -0.0010 * ASEC2RAD; // [rad] + c_depsilon_rad_[6] = 0.0220 * ASEC2RAD; // [rad] + c_depsilon_rad_[7] = 0.0130 * ASEC2RAD; // [rad] + c_depsilon_rad_[8] = -0.0100 * ASEC2RAD; // [rad] + // delta psi + c_dpsi_rad_[0] = -17.2060 * ASEC2RAD; // [rad] + c_dpsi_rad_[1] = -1.3170 * ASEC2RAD; // [rad] + c_dpsi_rad_[2] = 0.2070 * ASEC2RAD; // [rad] + c_dpsi_rad_[3] = -0.2280 * ASEC2RAD; // [rad] + c_dpsi_rad_[4] = 0.1480 * ASEC2RAD; // [rad] + c_dpsi_rad_[5] = 0.0710 * ASEC2RAD; // [rad] + c_dpsi_rad_[6] = -0.0520 * ASEC2RAD; // [rad] + c_dpsi_rad_[7] = -0.0300 * ASEC2RAD; // [rad] + c_dpsi_rad_[8] = 0.0220 * ASEC2RAD; // [rad] + + // coefficients for computing precession angles(zeta, theta, z) + // the actual unit of c_zeta_rad_ is [rad/century^(i+1)], i is the index of the array + c_zeta_rad_[0] = 2306.218100 * ASEC2RAD; // [rad/century] + c_zeta_rad_[1] = 0.301880 * ASEC2RAD; // [rad/century^2] + c_zeta_rad_[2] = 0.017998 * ASEC2RAD; // [rad/century^3] + // the actual unit of c_theta_rad_ is [rad/century^(i+1)], i is the index of the array + c_theta_rad_[0] = 2004.310900 * ASEC2RAD; // [rad/century] + c_theta_rad_[1] = -0.426650 * ASEC2RAD; // [rad/century^2] + c_theta_rad_[2] = -0.041833 * ASEC2RAD; // [rad/century^3] + // the actual unit of c_z_rad_ is [rad/century^(i+1)], i is the index of the array + c_z_rad_[0] = 2306.218100 * ASEC2RAD; // [rad/century] + c_z_rad_[1] = 1.094680 * ASEC2RAD; // [rad/century^2] + c_z_rad_[2] = 0.018203 * ASEC2RAD; // [rad/century^3] + } + else + { + // if the rotation mode is neither Simple nor Full, disable the rotation calculation and make the DCM a unit matrix + rotation_mode_ = Idle; + unitalize(DCM_J2000toXCXF_); + } + } + else + { + // if the center object is not the Earth, disable the Earth's rotation calculation and make the DCM a unit matrix + rotation_mode_ = Idle; + unitalize(DCM_J2000toXCXF_); + } +} + +void CelestialRotation::Update(const double JulianDate) +{ + double gmst_rad = gstime(JulianDate); //長沢のアルゴリズムと微妙に違う…?,他と合わせた方が良いので,暫定このままで行く. + + if (rotation_mode_ == Full) + { + // compute Julian date for terestrial time + double jdTT_day = JulianDate + dtUT1UTC_ * kSec2Day; // 不正確かも(?)だが,S2E内部でグレゴリオ暦の伝播はしていないので,これで済ませる + + // compute nth power of julian century for terrestrial time + // the actual unit of tTT_century is [century^(i+1)], i is the index of the array + double tTT_century[4]; + tTT_century[0] = (jdTT_day - kJulianDateJ2000) / kDayJulianCentury; + for (int i = 0; i < 3; i++) { tTT_century[i+1] = tTT_century[i] * tTT_century[0]; } + + Matrix<3, 3> P; Matrix<3, 3> N; Matrix<3, 3> R; Matrix<3, 3> W; + // Nutation + Precession + P = Precession(tTT_century); + N = Nutation(tTT_century); // epsi_rad_, depsilon_rad_, dpsi_rad_ are updated in this proccedure + + // Axial Rotation + double Eq_rad = dpsi_rad_ * cos(epsi_rad_ + depsilon_rad_); // equation of equinoxes [rad] + double gast_rad = gmst_rad + Eq_rad; // Greenwitch 'Appearent' Sidereal Time [rad] + R = AxialRotation(gast_rad); + // polar motion (isnot considered so far, even without polar motion, the result agrees well with the matlab reference) + double Xp = 0.0; double Yp = 0.0; + W = PolarMotion(Xp, Yp); + + // total orientation + DCM_J2000toXCXF_ = W * R * N * P; + } + else if (rotation_mode_ == Simple) + { + // In this case, only Axial Rotation is executed, with its argument replaced from G'A'ST to G'M'ST + DCM_J2000toXCXF_ = AxialRotation(gmst_rad); + } + else + { + // leave the DCM as unit Matrix(diag{1,1,1}) + return; + } +} + +Matrix<3, 3> CelestialRotation::AxialRotation(const double GAST_rad) +{ + return libra::rotz(GAST_rad); +} + +Matrix<3, 3> CelestialRotation::Nutation(const double(&tTT_century)[4]) +{ + // mean obliquity of the ecliptic + epsi_rad_ = c_epsi_rad_[0]; // [rad] + for (int i = 0; i < 3; i++) { epsi_rad_ += c_epsi_rad_[i+1] * tTT_century[i]; } + + // compute five delauney angles(l=lm,l'=ls,F,D,Ω=O) + // mean anomaly of the moon + double lm_rad = c_lm_rad_[0]; // [rad] + for (int i = 0; i < 4; i++) { lm_rad += c_lm_rad_[i+1] * tTT_century[i]; } + // mean anomaly of the sun + double ls_rad = c_ls_rad_[0]; // [rad] + for (int i = 0; i < 4; i++) { ls_rad += c_ls_rad_[i+1] * tTT_century[i]; } + // mean longitude of the moon - mean longitude of ascending node of the moon + double F_rad = c_F_rad_[0]; // [rad] + for (int i = 0; i < 4; i++) { F_rad += c_F_rad_[i+1] * tTT_century[i]; } + // mean elogation of the moon from the sun + double D_rad = c_D_rad_[0]; // [rad] + for (int i = 0; i < 4; i++) { D_rad += c_D_rad_[i+1] * tTT_century[i]; } + // mean longitude of ascending node of the moon + double O_rad = c_O_rad_[0]; // [rad] + for (int i = 0; i < 4; i++) { O_rad += c_O_rad_[i+1] * tTT_century[i]; } + + // additional angles + double L_rad = F_rad + O_rad; // F + Ω [rad] + double Ld_rad = L_rad - D_rad; // F - D + Ω [rad] + + // compute luni-solar nutation + // nutation in obliquity + dpsi_rad_ = c_dpsi_rad_[0] * sin(O_rad) + c_dpsi_rad_[1] * sin(2 * Ld_rad) + c_dpsi_rad_[2] * sin(2 * O_rad) + c_dpsi_rad_[3] * sin(2 * L_rad) + c_dpsi_rad_[4] * sin(ls_rad); // [rad] + dpsi_rad_ = dpsi_rad_ + c_dpsi_rad_[5] * sin(lm_rad) + c_dpsi_rad_[6] * sin(2 * Ld_rad + ls_rad) + c_dpsi_rad_[7] * sin(2 * L_rad + lm_rad) + c_dpsi_rad_[8] * sin(2 * Ld_rad - ls_rad); // [rad] + + // nutation in longitude + depsilon_rad_ = c_depsilon_rad_[0] * cos(O_rad) + c_depsilon_rad_[1] * cos(2 * Ld_rad) + c_depsilon_rad_[2] * cos(2 * O_rad) + c_depsilon_rad_[3] * cos(2 * L_rad) + c_depsilon_rad_[4] * cos(ls_rad); // [rad] + depsilon_rad_ = depsilon_rad_ + c_depsilon_rad_[5] * cos(lm_rad) + c_depsilon_rad_[6] * cos(2 * Ld_rad + ls_rad) + c_depsilon_rad_[7] * cos(2 * L_rad + lm_rad) + c_depsilon_rad_[8] * cos(2 * Ld_rad - ls_rad); // [rad] + + double epsi_mod_rad = epsi_rad_ + depsilon_rad_; + Matrix<3, 3> X_epsi_1st = libra::rotx(epsi_rad_); + Matrix<3, 3> Z_dpsi = libra::rotz(-dpsi_rad_); + Matrix<3, 3> X_epsi_2nd = libra::rotx(-epsi_mod_rad); + + Matrix<3, 3> N; + N = X_epsi_2nd * Z_dpsi * X_epsi_1st; + + return N; +} + +Matrix<3, 3> CelestialRotation::Precession(const double (&tTT_century)[4]) +{ + // compute precession angles(zeta, theta, z) + double zeta_rad = 0.0; // [rad] + for (int i = 0; i < 3; i++) { zeta_rad += c_zeta_rad_[i] * tTT_century[i]; } + double theta_rad = 0.0; // [rad] + for (int i = 0; i < 3; i++) { theta_rad += c_theta_rad_[i] * tTT_century[i]; } + double z_rad = 0.0; // [rad] + for (int i = 0; i < 3; i++) { z_rad += c_z_rad_[i] * tTT_century[i]; } + + // develop transformation matrix + Matrix<3, 3> Z_zeta = libra::rotz(-zeta_rad); + Matrix<3, 3> Y_theta = libra::roty(theta_rad); + Matrix<3, 3> Z_z = libra::rotz(-z_rad); + + Matrix<3, 3> P; + P = Z_z * Y_theta * Z_zeta; + + return P; +} + +Matrix<3, 3> CelestialRotation::PolarMotion(const double Xp, const double Yp) +{ + Matrix<3, 3> W; + + W[0][0] = 1.0; W[0][1] = 0.0; W[0][2] = -Xp; + W[1][0] = 0.0; W[1][1] = 1.0; W[1][2] = -Yp; + W[2][0] = Xp; W[2][1] = Yp; W[2][2] = 1.0; + + return W; } \ No newline at end of file diff --git a/src/Environment/Global/CelestialRotation.h b/src/Environment/Global/CelestialRotation.h index 7fbdaa30c..337aeec74 100644 --- a/src/Environment/Global/CelestialRotation.h +++ b/src/Environment/Global/CelestialRotation.h @@ -1,86 +1,85 @@ -#ifndef __celestial_rotation_H__ -#define __celestial_rotation_H__ - -#include -#include -using namespace std; - -#include "../../Library/math/Matrix.hpp" -#include "../../Library/math/Vector.hpp" -#include "../../Library/math/MatVec.hpp" -#include "../../Library/math/Quaternion.hpp" -#include "../../Interface/LogOutput/ILoggable.h" - -using libra::Vector; -using libra::Quaternion; - -enum RotationMode -{ - Idle, - Simple, - Full, -}; - -// class for describing the rotational motion of center objects,instantiated as private members of CelesInfo(ひとまず地球自転のみに対応) -// アルゴリズムは暫定的に,福島,"天体の回転運動理論入門講義ノート",2007, 及び,長沢,"天体の位置計算(増補版)",2001に従う.(IERS Conventions 2003) -class CelestialRotation -{ -public: - // initialize DCM to unit matrix in the default constructor - CelestialRotation(const RotationMode rotation_mode, const string center_obj); - // calculate rotation - void Update(const double JulianDate); - // get the DCM between J2000 and the coordinate system attached to the surface of the target object X (X-Centered X-Fixed) - inline const Matrix<3, 3> GetDCMJ2000toXCXF() const { return DCM_J2000toXCXF_; }; - // get the DCM between TEME (Inertial coordinate used in SGP4) and the coordinate system attached to the surface of the target object X (X-Centered X-Fixed) - inline const Matrix<3, 3> GetDCMTEMEtoXCXF() const { return DCM_TEMEtoXCXF_; }; - -private: - // coefficient initialization function, 対象天体ごとに用意するか…? - void Init_CelestialRotation_As_Earth(const RotationMode rotation_mode, const string center_obj); - Matrix<3, 3> AxialRotation(const double GAST_rad); // movement of the coordinate axes due to rotation around the rotation axis - Matrix<3, 3> Nutation(const double (&tTT_century)[4]); // movement of the coordinate axes due to Nutation - Matrix<3, 3> Precession(const double (&tTT_century)[4]); // movement of the coordinate axes due to Precession - Matrix<3, 3> PolarMotion(const double Xp, const double Yp); // movement of the coordinate axes due to Polar Motion - - double dpsi_rad_; // nutation in obliquity [rad] - double depsilon_rad_; // nutation in longitude [rad] - double epsi_rad_; // mean obliquity of the ecliptic [rad] - Matrix<3, 3> DCM_J2000toXCXF_; // DCM J2000 to XCXF(X-Centered X-Fixed) - Matrix<3, 3> DCM_TEMEtoXCXF_; // DCM TEME to XCXF(X-Centered X-Fixed) - RotationMode rotation_mode_; // designation of dynamics model, "Idle":no motion,"Simple":rotation only,"Full":full-dynamics - string planet_name_; // designate which solar planet the instance should work as - - // definitions of coefficeints(地球以外の天体の場合はケアすべき天体が変わりうる気もするが,ひとまず日月歳差の形式を前提とする) - // (実装時の理解では)頻繁に変わるものではなさそうなので暫定的に初期化関数内でべた書きで初期化 - // 将来的には設定ファイル読込にすることも視野に入れる - - // coefficients for computing mean obliquity of the ecliptic - double c_epsi_rad_[4]; - - // coefficients for computing five delauney angles(l=lm,l'=ls,F,D,Ω=O) - double c_lm_rad_[5]; - double c_ls_rad_[5]; - double c_F_rad_[5]; - double c_D_rad_[5]; - double c_O_rad_[5]; - - // coefficients for computing nutation angles(delta-epsilon, delta-psi) - double c_depsilon_rad_[9]; - double c_dpsi_rad_[9]; - - // coefficients for computing precession angles(zeta, theta, z) - double c_zeta_rad_[3]; - double c_theta_rad_[3]; - double c_z_rad_[2]; - - // time difference b/w UT1 and UTC [sec] - const double dtUT1UTC_ = 32.184; - - // definitions of constant names - const double kSec2Day = 1/(24.0 * 60.0 * 60.0); - const double kJulianDateJ2000 = 2451545.0; // [day] - const double kDayJulianCentury = 36525; // [day/century] -}; - -#endif //__celestial_rotation_H__ \ No newline at end of file +#ifndef __celestial_rotation_H__ +#define __celestial_rotation_H__ + +#include +#include + +#include "../../Library/math/Matrix.hpp" +#include "../../Library/math/Vector.hpp" +#include "../../Library/math/MatVec.hpp" +#include "../../Library/math/Quaternion.hpp" +#include "../../Interface/LogOutput/ILoggable.h" + +using libra::Vector; +using libra::Quaternion; + +enum RotationMode +{ + Idle, + Simple, + Full, +}; + +// class for describing the rotational motion of center objects,instantiated as private members of CelesInfo(ひとまず地球自転のみに対応) +// アルゴリズムは暫定的に,福島,"天体の回転運動理論入門講義ノート",2007, 及び,長沢,"天体の位置計算(増補版)",2001に従う.(IERS Conventions 2003) +class CelestialRotation +{ +public: + // initialize DCM to unit matrix in the default constructor + CelestialRotation(const RotationMode rotation_mode, const std::string center_obj); + // calculate rotation + void Update(const double JulianDate); + // get the DCM between J2000 and the coordinate system attached to the surface of the target object X (X-Centered X-Fixed) + inline const Matrix<3, 3> GetDCMJ2000toXCXF() const { return DCM_J2000toXCXF_; }; + // get the DCM between TEME (Inertial coordinate used in SGP4) and the coordinate system attached to the surface of the target object X (X-Centered X-Fixed) + inline const Matrix<3, 3> GetDCMTEMEtoXCXF() const { return DCM_TEMEtoXCXF_; }; + +private: + // coefficient initialization function, 対象天体ごとに用意するか…? + void Init_CelestialRotation_As_Earth(const RotationMode rotation_mode, const std::string center_obj); + Matrix<3, 3> AxialRotation(const double GAST_rad); // movement of the coordinate axes due to rotation around the rotation axis + Matrix<3, 3> Nutation(const double (&tTT_century)[4]); // movement of the coordinate axes due to Nutation + Matrix<3, 3> Precession(const double (&tTT_century)[4]); // movement of the coordinate axes due to Precession + Matrix<3, 3> PolarMotion(const double Xp, const double Yp); // movement of the coordinate axes due to Polar Motion + + double dpsi_rad_; // nutation in obliquity [rad] + double depsilon_rad_; // nutation in longitude [rad] + double epsi_rad_; // mean obliquity of the ecliptic [rad] + Matrix<3, 3> DCM_J2000toXCXF_; // DCM J2000 to XCXF(X-Centered X-Fixed) + Matrix<3, 3> DCM_TEMEtoXCXF_; // DCM TEME to XCXF(X-Centered X-Fixed) + RotationMode rotation_mode_; // designation of dynamics model, "Idle":no motion,"Simple":rotation only,"Full":full-dynamics + std::string planet_name_; // designate which solar planet the instance should work as + + // definitions of coefficeints(地球以外の天体の場合はケアすべき天体が変わりうる気もするが,ひとまず日月歳差の形式を前提とする) + // (実装時の理解では)頻繁に変わるものではなさそうなので暫定的に初期化関数内でべた書きで初期化 + // 将来的には設定ファイル読込にすることも視野に入れる + + // coefficients for computing mean obliquity of the ecliptic + double c_epsi_rad_[4]; + + // coefficients for computing five delauney angles(l=lm,l'=ls,F,D,Ω=O) + double c_lm_rad_[5]; + double c_ls_rad_[5]; + double c_F_rad_[5]; + double c_D_rad_[5]; + double c_O_rad_[5]; + + // coefficients for computing nutation angles(delta-epsilon, delta-psi) + double c_depsilon_rad_[9]; + double c_dpsi_rad_[9]; + + // coefficients for computing precession angles(zeta, theta, z) + double c_zeta_rad_[3]; + double c_theta_rad_[3]; + double c_z_rad_[2]; + + // time difference b/w UT1 and UTC [sec] + const double dtUT1UTC_ = 32.184; + + // definitions of constant names + const double kSec2Day = 1/(24.0 * 60.0 * 60.0); + const double kJulianDateJ2000 = 2451545.0; // [day] + const double kDayJulianCentury = 36525; // [day/century] +}; + +#endif //__celestial_rotation_H__ diff --git a/src/Environment/Global/GlobalEnvironment.cpp b/src/Environment/Global/GlobalEnvironment.cpp index a0e00c1e4..9b50743f0 100644 --- a/src/Environment/Global/GlobalEnvironment.cpp +++ b/src/Environment/Global/GlobalEnvironment.cpp @@ -18,7 +18,7 @@ void GlobalEnvironment::Initialize(SimulationConfig* sim_config) { //Get ini file path IniAccess iniAccess = IniAccess(sim_config->ini_base_fname_); - string sim_time_ini_path = sim_config->ini_base_fname_; + std::string sim_time_ini_path = sim_config->ini_base_fname_; //Initialize sim_time_ = InitSimTime(sim_time_ini_path); @@ -47,4 +47,4 @@ void GlobalEnvironment::LogSetup(Logger& logger) void GlobalEnvironment::Reset(void) { sim_time_->ResetClock(); -} \ No newline at end of file +} diff --git a/src/Environment/Global/GlobalEnvironment.h b/src/Environment/Global/GlobalEnvironment.h index cd82a7408..68dca2235 100644 --- a/src/Environment/Global/GlobalEnvironment.h +++ b/src/Environment/Global/GlobalEnvironment.h @@ -7,8 +7,6 @@ #include "../../Interface/LogOutput/Logger.h" #include "../../Simulation/SimulationConfig.h" -using namespace std; - class GlobalEnvironment { public: diff --git a/src/Environment/Global/GnssSatellites.cpp b/src/Environment/Global/GnssSatellites.cpp index 30aff9ce4..7816d2976 100644 --- a/src/Environment/Global/GnssSatellites.cpp +++ b/src/Environment/Global/GnssSatellites.cpp @@ -6,9 +6,26 @@ #include #include "GnssSatellites.h" #include "../../Interface/LogOutput/LogUtility.h" -#include "../../Library/sgp4/sgp4unit.h" //for gstime() +#include "../../Library/sgp4/sgp4unit.h" //for gstime() #include "../../Library/sgp4/sgp4ext.h" //for jday() +const double speed_of_light_m_s = 299792458.0; //[m/s] in vacuum +const double nan99 = 999999.999999; + +const int gps_sat_num_ = 32; +const int glonass_sat_num_ = 26; +const int galileo_sat_num_ = 36; +const int beidou_sat_num_ = 16; +const int qzss_sat_num_ = 7; + +const int gps_index_bias_ = -1; +const int glonass_index_bias_ = gps_index_bias_ + gps_sat_num_; +const int galileo_index_bias_ = glonass_index_bias_ + glonass_sat_num_; +const int beidou_index_bias_ = galileo_index_bias_ + galileo_sat_num_; +const int qzss_index_bias_ = beidou_index_bias_ + beidou_sat_num_; + +const int all_sat_num_ = gps_sat_num_ + glonass_sat_num_ + galileo_sat_num_ + beidou_sat_num_ + qzss_sat_num_; + using namespace std; tm* initilized_tm() @@ -25,7 +42,7 @@ tm* initilized_tm() time_tm->tm_isdst = 0; time_tm->tm_yday = 0; time_tm->tm_wday = 0; - + #ifndef WIN32 time_tm->tm_zone = NULL; time_tm->tm_gmtoff = 0; @@ -34,6 +51,21 @@ tm* initilized_tm() return time_tm; } +double get_unixtime_from_timestamp_line(std::vector& s) +{ + tm *time_tm = initilized_tm(); + time_tm->tm_year = stoi(s.at(1)) - 1900; + time_tm->tm_mon = stoi(s.at(2)) - 1; // 0 - 11, in time struct, 1 - 12 month is expressed by 1 - 12 + time_tm->tm_mday = stoi(s.at(3)); + time_tm->tm_hour = stoi(s.at(4)); + time_tm->tm_min = stoi(s.at(5)); + time_tm->tm_sec = (int)(stod(s.at(6)) + 1e-4); // for the numerical error, plus 1e-4 (tm_sec is to be int) + double unix_time = (double)mktime(time_tm); + std::free(time_tm); + + return unix_time; +} + template Vector GnssSat_coordinate::TrigonometricInterpolation(const vector& time_vector, const vector>& values, double time) const { @@ -47,7 +79,7 @@ Vector GnssSat_coordinate::TrigonometricInterpolation(const vector& t if(i == j) continue; t_k *= sin(w*(time - time_vector.at(j))/2.0)/sin(w*(time_vector.at(i) - time_vector.at(j))/2.0); } - for(int j = 0;j < N;++j){ + for(int j = 0;j < (int)N;++j){ res(j) += t_k*values.at(i)(j); } } @@ -85,7 +117,7 @@ Vector GnssSat_coordinate::LagrangeInterpolation(const vector& time_v if(i == j) continue; l_i *= (time - time_vector.at(j))/(time_vector.at(i) - time_vector.at(j)); } - for(int j = 0;j < n;++j){ + for(int j = 0;j < N;++j){ res(j) += l_i*values.at(i)(j); } } @@ -116,7 +148,7 @@ int GnssSat_coordinate::GetIndexFromID(string sat_num) const { case 'G': return stoi(sat_num.substr(2)) + gps_index_bias_; - case 'R': + case 'R': return stoi(sat_num.substr(2)) + glonass_index_bias_; case 'E': return stoi(sat_num.substr(2)) + galileo_index_bias_; @@ -133,7 +165,7 @@ int GnssSat_coordinate::GetIndexFromID(string sat_num) const { case 'G': return stoi(sat_num.substr(1)) + gps_index_bias_; - case 'R': + case 'R': return stoi(sat_num.substr(1)) + glonass_index_bias_; case 'E': return stoi(sat_num.substr(1)) + galileo_index_bias_; @@ -187,190 +219,133 @@ bool GnssSat_coordinate::GetWhetherValid(int sat_id) const return validate_.at(sat_id); } -void GnssSat_coordinate::ProcessData(vector>& raw_file, vector>>& data) +pair GnssSat_position::Init(vector>& file, + int interpolation_method, + int interpolation_number, + UR_KINDS ur_flag) { - for(int i = 0;i < raw_file.size();++i){ - int num_of_time_stamps = 0; - int num_of_sat = 0; - - for(int j = 0;j < 3;++j){ - if(j == 0){ - istringstream iss{raw_file.at(i).at(j)}; - for(int k = 0;k < 7;++k){ - //how many time stamps are written? - string each; - iss >> each; - if(k == 6){ - num_of_time_stamps = stoi(each); - if(num_of_time_stamps%24) num_of_time_stamps -= num_of_time_stamps%24; - } + interpolation_number_ = interpolation_number; + + // 拡張 + gnss_sat_table_ecef_.resize(all_sat_num_); // first vectir size is the sat num + gnss_sat_table_eci_.resize(all_sat_num_); + unixtime_vector_.resize(all_sat_num_); + + // for using min and max, set the sup & inf before + double start_unix_time = 1e16; + double end_unix_time = 0; + + // Get Header Info + for(int page = 0;page < (int)file.size();++page){ + int num_of_time_stamps, num_of_sat; + + for(int line = 0;line < 3;++line){ + istringstream iss{file.at(page).at(line)}; + + if(line == 0){ + // in seventh line, there is time stamps + // http://epncb.oma.be/ftp/data/format/sp3c.txt + for(int i = 0;i < 7;++i){ + // how many time stamps are written? + string each; iss >> each; + if(i == 6) num_of_time_stamps = stoi(each); } - }else if(j == 2){ - istringstream iss{raw_file.at(i).at(j)}; - for(int k = 0;k < 2;++k){ - string each; - iss >> each; - if(k == 1){ - //how many satellites - num_of_sat = stoi(each); - } + }else if(line == 1){ + for(int i= 0;i < 4;++i){ + string each; iss >> each; + if(i == 3) time_interval_ = stod(each); + } + }else if(line == 2){ + for(int i = 0;i < 2;++i){ + string each; iss >> each; + if(i == 1) num_of_sat = stoi(each); } } } - int j = 3; - while(raw_file.at(i).at(j).front() != '*') ++j; - int initial_row = j; - for(j = 0;j < (num_of_sat + 1)*num_of_time_stamps;++j){ - int index = j + initial_row; - if(j%(num_of_sat + 1) == 0) data.push_back({raw_file.at(i).at(index), vector()}); - else data.back().second.push_back(raw_file.at(i).at(index)); - } - } -} + int line = 3; + while(file.at(page).at(line).front() != '*') ++line; -void GnssSat_coordinate::ProcessData(vector>& raw_file, vector>>& data, bool ur_flag) -{ - for(int i = 0;i < raw_file.size();++i){ - int num_of_sat = 0; - int num_of_time_stamps_in_file = 0; - - for(int j = 0;j < 3;++j){ - if(j == 0){ - istringstream iss{raw_file.at(i).at(j)}; - for(int k = 0;k < 7;++k){ - //How many time stamps are written? - string each; - iss >> each; - if(k == 6){ - num_of_time_stamps_in_file = stoi(each); - if(num_of_time_stamps_in_file%24) num_of_time_stamps_in_file -= num_of_time_stamps_in_file%24; - } - } - }else if(j == 2){ - istringstream iss{raw_file.at(i).at(j)}; - for(int k = 0;k < 2;++k){ - string each; - iss >> each; - if(k == 1){ - //how many satellites - num_of_sat = stoi(each); - } - } - } + int start_line, end_line; + if(ur_flag == UR_NOT_UR){ + start_line = line; + end_line = line + (num_of_sat + 1)*num_of_time_stamps; + }else{ + int offset = (int)ur_flag - (int)UR_OBSERVE1; + start_line = line + (num_of_sat + 1)*num_of_time_stamps/8*offset; + end_line = line + (num_of_sat + 1)*num_of_time_stamps/8*(offset + 1); } - vector tmp_data; - int j = 3; - while(raw_file.at(i).at(j).front() != '*') ++j; - int initial_row = j; - for(j = initial_row;j < initial_row + (num_of_sat + 1)*num_of_time_stamps_in_file;++j) tmp_data.push_back(raw_file.at(i).at(j)); - - int n = (num_of_sat + 1)*num_of_time_stamps_in_file; - // in ultra rapid, extract only the most recent estimation data - for(int j = n/2;j < n/2 + n/8;++j){ - if(j%(num_of_sat + 1) == 0) data.push_back({tmp_data.at(j), vector()}); - else data.back().second.push_back(tmp_data.at(j)); - } - } -} + double unix_time = 0; + double cos_, sin_; + for(int i = 0;i < end_line - start_line;++i){ + int line = i + start_line; -void GnssSat_coordinate::ProcessData(vector>& raw_file, vector& data) -{ - for(int i = 0;i < raw_file.size();++i){ - for(int j = 0;j < raw_file.at(i).size();++j){ - if(raw_file.at(i).at(j).substr(0, 3) == "AS ") data.push_back(raw_file.at(i).at(j)); - } - } -} + istringstream iss{file.at(page).at(line)}; + vector s; + if(i%(num_of_sat + 1) == 0){ + for(int j = 0;j < 7;++j){ + string tmp; + iss >> tmp; + s.push_back(tmp); + } -void GnssSat_position::Init(vector>& file, - int interpolation_method, - int interpolation_number, - bool ur_flag) -{ - interpolation_number_ = interpolation_number; - vector>> data; //vector of pair, which is string of clock and data of satllites - if(ur_flag) ProcessData(file, data, ur_flag); - else ProcessData(file, data); - - //拡張 - gnss_sat_table_ecef_.assign(data.size(), vector>(all_sat_num_, libra::Vector<3>(0.0))); - gnss_sat_table_eci_.assign(data.size(), vector>(all_sat_num_, libra::Vector<3>(0.0))); - time_table_.resize(data.size()); - available_table_.assign(data.size(), vector(all_sat_num_, false)); - time_and_index_list_.resize(all_sat_num_); - - for(int i = 0;i < data.size();++i){ - string time_str = data.at(i).first; - const auto& sp3_str = data.at(i).second; - istringstream iss_time_str{time_str}; - vector s; - for(int j = 0;j < 7;++j){ - string tmp; - iss_time_str >> tmp; - s.push_back(tmp); - } - tm *time_tm = initilized_tm(); - time_tm->tm_year = stoi(s.at(1)) - 1900; - time_tm->tm_mon = stoi(s.at(2)) - 1; //0 - 11 - time_tm->tm_mday = stoi(s.at(3)); - time_tm->tm_hour = stoi(s.at(4)); - time_tm->tm_min = stoi(s.at(5)); - time_tm->tm_sec = (int)(stod(s.at(6)) + 1e-4); - double unix_time = (double)mktime(time_tm); - std::free(time_tm); - time_table_.at(i) = unix_time; - if(i > 0) time_interval_ = min(time_interval_, time_table_.at(i) - time_table_.at(i-1)); - double jd; - jday(stoi(s.at(1)), stoi(s.at(2)), stoi(s.at(3)), stoi(s.at(4)), stoi(s.at(5)), stod(s.at(6)), jd); - double gs_time_ = gstime(jd); - double cos_ = cos(gs_time_); - double sin_ = sin(gs_time_); - - for(int j = 0;j < sp3_str.size();++j){ - istringstream iss{sp3_str.at(j)}; - vector ss; - for(int k = 0;k < 5;++k){ - string tmp; - iss >> tmp; - ss.push_back(tmp); - } - int sat_id = GetIndexFromID(ss.front()); + unix_time = get_unixtime_from_timestamp_line(s); + double jd; + jday(stoi(s.at(1)), stoi(s.at(2)), stoi(s.at(3)), stoi(s.at(4)), stoi(s.at(5)), stod(s.at(6)), jd); + double gs_time_ = gstime(jd); + cos_ = cos(gs_time_); + sin_ = sin(gs_time_); - bool available_flag = true; - for(int k = 0;k < 3;++k){ - if(std::abs(stod(ss.at(k + 1)) - nan99) < 1.0){ - available_flag = false; - break; + start_unix_time = std::min(start_unix_time, unix_time); + end_unix_time = std::max(end_unix_time, unix_time); + }else{ + for(int j = 0;j < 5;++j){ + string tmp; + iss >> tmp; + s.push_back(tmp); } - } - available_table_.at(i).at(sat_id) = available_flag; + int sat_id = GetIndexFromID(s.front()); - libra::Vector<3> ecef_position(0.0); - libra::Vector<3> eci_position(0.0); - if(available_flag){ - for(int k = 0;k < 3;++k){ - ecef_position[k] = stod(ss.at(k + 1)); + bool available_flag = true; + libra::Vector<3> ecef_position_m(0.0); + for(int j = 0;j < 3;++j){ + if(std::abs(stod(s.at(j + 1)) - nan99) < 1.0){ + available_flag = false; + break; + }else{ + ecef_position_m(j) = stod(s.at(j + 1)); + } } + if(!available_flag) continue; + //[km] -> [m] - ecef_position *= 1000.0; + ecef_position_m *= 1000.0; + + libra::Vector<3> eci_position(0.0); - double x = ecef_position(0); - double y = ecef_position(1); - double z = ecef_position(2); + double x = ecef_position_m(0); + double y = ecef_position_m(1); + double z = ecef_position_m(2); eci_position(0) = cos_*x - sin_*y; eci_position(1) = sin_*x + cos_*y; eci_position(2) = z; - time_and_index_list_.at(sat_id).emplace_back(unix_time, i); + if(!unixtime_vector_.at(sat_id).empty() && std::abs(unix_time - unixtime_vector_.at(sat_id).back()) < 1.0){ + unixtime_vector_.at(sat_id).back() = unix_time; + gnss_sat_table_ecef_.at(sat_id).back() = ecef_position_m; + gnss_sat_table_eci_.at(sat_id).back() = eci_position; + }else{ + unixtime_vector_.at(sat_id).emplace_back(unix_time); + gnss_sat_table_ecef_.at(sat_id).emplace_back(ecef_position_m); + gnss_sat_table_eci_.at(sat_id).emplace_back(eci_position); + } } - - gnss_sat_table_ecef_.at(i).at(sat_id) = ecef_position; - gnss_sat_table_eci_.at(i).at(sat_id) = eci_position; } } + + return make_pair(start_unix_time, end_unix_time); } void GnssSat_position::SetUp(const double start_unix_time, const double step_sec) @@ -382,118 +357,130 @@ void GnssSat_position::SetUp(const double start_unix_time, const double step_sec validate_.assign(all_sat_num_, false); nearest_index_.resize(all_sat_num_); - time_vector_.resize(all_sat_num_); + time_period_.resize(all_sat_num_); ecef_.resize(all_sat_num_); eci_.resize(all_sat_num_); - for(int i = 0;i < all_sat_num_;++i){ - if(!time_and_index_list_.at(i).size()){ - validate_.at(i) = false; + for(int sat_id = 0;sat_id < all_sat_num_;++sat_id){ + if(unixtime_vector_.at(sat_id).empty()){ + validate_.at(sat_id) = false; continue; } - int list_index = lower_bound(time_and_index_list_.at(i).begin(), time_and_index_list_.at(i).end(), make_pair(start_unix_time, 0)) - time_and_index_list_.at(i).begin(); - double now_time = time_and_index_list_.at(i).at(list_index).first; - - if(interpolation_number_%2 && list_index != 0){ - double pre_time = time_and_index_list_.at(i).at(list_index - 1).first; - if(std::abs(start_unix_time - pre_time) < std::abs(start_unix_time - now_time)) --list_index; + int index = lower_bound(unixtime_vector_.at(sat_id).begin(), unixtime_vector_.at(sat_id).end(), start_unix_time) - unixtime_vector_.at(sat_id).begin(); + if(index == (int)unixtime_vector_.at(sat_id).size()){ + nearest_index_.at(sat_id) = index; + validate_.at(sat_id) = false; + continue; } - nearest_index_.at(i) = list_index; + double nearest_unixtime = unixtime_vector_.at(sat_id).at(index); + if(interpolation_number_%2 && index != 0){ + double pre_time = unixtime_vector_.at(sat_id).at(index - 1); + if(std::abs(start_unix_time - pre_time) < std::abs(start_unix_time - nearest_unixtime)) --index; + } + nearest_index_.at(sat_id) = index; + nearest_unixtime = unixtime_vector_.at(sat_id).at(index); + if (std::abs(start_unix_time - nearest_unixtime) > time_interval_){ + validate_.at(sat_id) = false; + continue; + } //for both even and odd: 2n+1 -> [-n, n] 2n -> [-n, n) for(int j = -interpolation_number_/2;j < (interpolation_number_ + 1)/2;++j){ - int now_index = list_index + j; - if(now_index < 0 || now_index >= time_and_index_list_.at(i).size()) continue; - - const auto& now_pair = time_and_index_list_.at(i).at(now_index); - const int table_index = now_pair.second; - time_vector_.at(i).push_back(now_pair.first); - ecef_.at(i).push_back(gnss_sat_table_ecef_.at(table_index).at(i)); - eci_.at(i).push_back(gnss_sat_table_eci_.at(table_index).at(i)); + int now_index = index + j; + if(now_index < 0 || now_index >= (int)unixtime_vector_.at(sat_id).size()) continue; + + time_period_.at(sat_id).push_back(unixtime_vector_.at(sat_id).at(now_index)); + ecef_.at(sat_id).push_back(gnss_sat_table_ecef_.at(sat_id).at(now_index)); + eci_.at(sat_id).push_back(gnss_sat_table_eci_.at(sat_id).at(now_index)); + } + if((int)time_period_.at(sat_id).size() != interpolation_number_){ + validate_.at(sat_id) = false; + continue; } - if(ecef_.at(i).size() != interpolation_number_) continue; - double time_period_length = time_vector_.at(i).back() - time_vector_.at(i).front(); - if(time_period_length >= 4.0*60.0*60.0) continue; - else validate_.at(i) = true; - - const auto& nearest_pair = time_and_index_list_.at(i).at(list_index); - double nearest_unix_time = nearest_pair.first; - int table_index = nearest_pair.second; - if(std::abs(start_unix_time - nearest_unix_time) < step_sec/2.0){ - gnss_sat_ecef_.at(i) = gnss_sat_table_ecef_.at(table_index).at(i); - gnss_sat_eci_.at(i) = gnss_sat_table_eci_.at(table_index).at(i); + double time_period_length = time_period_.at(sat_id).back() - time_period_.at(sat_id).front(); + if(time_period_length > time_interval_*(interpolation_number_ - 1 + 3) + 1e-4){ // allow for 3 missing + validate_.at(sat_id) = false; continue; + }else{ + validate_.at(sat_id) = true; } - if(validate_.at(i)){ - gnss_sat_ecef_.at(i) = TrigonometricInterpolation(time_vector_.at(i), ecef_.at(i), start_unix_time); - gnss_sat_eci_.at(i) = TrigonometricInterpolation(time_vector_.at(i), eci_.at(i), start_unix_time); + if(std::abs(start_unix_time - nearest_unixtime) < 1e-4){ // for the numerical error, plus 1e-4 + gnss_sat_ecef_.at(sat_id) = gnss_sat_table_ecef_.at(sat_id).at(index); + gnss_sat_eci_.at(sat_id) = gnss_sat_table_eci_.at(sat_id).at(index); + }else{ + gnss_sat_ecef_.at(sat_id) = TrigonometricInterpolation(time_period_.at(sat_id), ecef_.at(sat_id), start_unix_time); + gnss_sat_eci_.at(sat_id) = TrigonometricInterpolation(time_period_.at(sat_id), eci_.at(sat_id), start_unix_time); } } } void GnssSat_position::Update(const double now_unix_time) { - for(int i = 0;i < all_sat_num_;++i){ - if(!time_and_index_list_.at(i).size()){ - validate_.at(i) = false; + for(int sat_id = 0;sat_id < all_sat_num_;++sat_id){ + if(unixtime_vector_.at(sat_id).empty()){ + validate_.at(sat_id) = false; continue; } - int list_index = nearest_index_.at(i); - double pre_unix = time_and_index_list_.at(i).at(list_index).first; - double post_unix; - if(list_index + 1 < time_and_index_list_.at(i).size()) post_unix = time_and_index_list_.at(i).at(list_index + 1).first; - else post_unix = 0; - - if(std::abs(now_unix_time - post_unix) < std::abs(now_unix_time - pre_unix)){ - ++list_index; - nearest_index_.at(i) = list_index; - - time_vector_.at(i).clear(); - ecef_.at(i).clear(); - eci_.at(i).clear(); - - //for both even and odd: 2n+1 -> [-n, n] 2n -> [-n, n) - for(int j = -interpolation_number_/2;j < (interpolation_number_ + 1)/2;++j){ - int now_index = list_index + j; - if(now_index < 0 || now_index >= time_and_index_list_.at(i).size()) continue; - - const auto& now_pair = time_and_index_list_.at(i).at(now_index); - const int table_index = now_pair.second; - time_vector_.at(i).push_back(now_pair.first); - ecef_.at(i).push_back(gnss_sat_table_ecef_.at(table_index).at(i)); - eci_.at(i).push_back(gnss_sat_table_eci_.at(table_index).at(i)); - } + int index = nearest_index_.at(sat_id); + if(index == (int)unixtime_vector_.at(sat_id).size()){ + validate_.at(sat_id) = false; + continue; } - if(ecef_.at(i).size() != interpolation_number_){ - validate_.at(i) = false; + if(index + 1 < (int)unixtime_vector_.at(sat_id).size()){ + double pre_unix = unixtime_vector_.at(sat_id).at(index); + double post_unix = unixtime_vector_.at(sat_id).at(index + 1); + + if(std::abs(now_unix_time - post_unix) < std::abs(now_unix_time - pre_unix)){ + ++index; + nearest_index_.at(sat_id) = index; + + time_period_.at(sat_id).clear(); + ecef_.at(sat_id).clear(); + eci_.at(sat_id).clear(); + + //for both even and odd: 2n+1 -> [-n, n] 2n -> [-n, n) + for(int j = -interpolation_number_/2;j < (interpolation_number_ + 1)/2;++j){ + int now_index = index + j; + if(now_index < 0 || now_index >= (int)unixtime_vector_.at(sat_id).size()) continue; + + time_period_.at(sat_id).push_back(unixtime_vector_.at(sat_id).at(now_index)); + ecef_.at(sat_id).push_back(gnss_sat_table_ecef_.at(sat_id).at(now_index)); + eci_.at(sat_id).push_back(gnss_sat_table_eci_.at(sat_id).at(now_index)); + } + } + } + double nearest_unix_time = unixtime_vector_.at(sat_id).at(index); + if (std::abs(now_unix_time - nearest_unix_time) > time_interval_){ + validate_.at(sat_id) = false; continue; } - double time_period_length = time_vector_.at(i).back() - time_vector_.at(i).front(); - if(time_period_length >= 4.0*60.0*60.0){ - validate_.at(i) = false; + if((int)time_period_.at(sat_id).size() != interpolation_number_){ + validate_.at(sat_id) = false; continue; - }else validate_.at(i) = true; + } - const auto& nearest_pair = time_and_index_list_.at(i).at(list_index); - double nearest_unix_time = nearest_pair.first; - int table_index = nearest_pair.second; + double time_period_length = time_period_.at(sat_id).back() - time_period_.at(sat_id).front(); + if(time_period_length > time_interval_*(interpolation_number_ - 1 + 3) + 1e-4){ // allow for 3 missing + validate_.at(sat_id) = false; + continue; + }else{ + validate_.at(sat_id) = true; + } - if(validate_.at(i)){ - if(std::abs(now_unix_time - nearest_unix_time) < step_sec_/2.0){ - gnss_sat_ecef_.at(i) = gnss_sat_table_ecef_.at(table_index).at(i); - gnss_sat_eci_.at(i) = gnss_sat_table_eci_.at(table_index).at(i); - }else{ - gnss_sat_ecef_.at(i) = TrigonometricInterpolation(time_vector_.at(i), ecef_.at(i), now_unix_time); - gnss_sat_eci_.at(i) = TrigonometricInterpolation(time_vector_.at(i), eci_.at(i), now_unix_time); - } + if(std::abs(now_unix_time - nearest_unix_time) < 1e-4){ // for the numerical error, plus 1e-4 + gnss_sat_ecef_.at(sat_id) = gnss_sat_table_ecef_.at(sat_id).at(index); + gnss_sat_eci_.at(sat_id) = gnss_sat_table_eci_.at(sat_id).at(index); + }else{ + gnss_sat_ecef_.at(sat_id) = TrigonometricInterpolation(time_period_.at(sat_id), ecef_.at(sat_id), now_unix_time); + gnss_sat_eci_.at(sat_id) = TrigonometricInterpolation(time_period_.at(sat_id), eci_.at(sat_id), now_unix_time); } } } @@ -510,104 +497,146 @@ libra::Vector<3> GnssSat_position::GetSatEci(int sat_id) const return gnss_sat_eci_.at(sat_id); } -void GnssSat_clock::Init(vector>& file, string file_extension, - int interpolation_number, bool ur_flag) +void GnssSat_clock::Init(vector>& file, string file_extension, int interpolation_number, UR_KINDS ur_flag, pair unix_time_period) { interpolation_number_ = interpolation_number; + gnss_sat_clock_table_.resize(all_sat_num_); // first vectir size is the sat num + unixtime_vector_.resize(all_sat_num_); + if(file_extension == ".sp3"){ - vector>> data; //vector of pair, which is string of clock and data of satllites - if(ur_flag) ProcessData(file, data, ur_flag); - else ProcessData(file, data); - - gnss_sat_clock_table_.assign(data.size(), vector(all_sat_num_, 0)); - time_table_.resize(data.size()); - available_table_.assign(data.size(), vector(all_sat_num_, false)); - time_and_index_num_.assign(all_sat_num_, 0); - - for(int i = 0;i < data.size();++i){ - string time_str = data.at(i).first; - const auto& sp3_str = data.at(i).second; - istringstream iss_time_str{time_str}; - vector s; - for(int j = 0;j < 7;++j){ - string tmp; - iss_time_str >> tmp; - s.push_back(tmp); - } - tm* time_tm = initilized_tm(); - time_tm->tm_year = stoi(s.at(1)) - 1900; - time_tm->tm_mon = stoi(s.at(2)) - 1; //0 - 11 - time_tm->tm_mday = stoi(s.at(3)); - time_tm->tm_hour = stoi(s.at(4)); - time_tm->tm_min = stoi(s.at(5)); - time_tm->tm_sec = (int)(stod(s.at(6)) + 1e-4); - double unix_time = (double)mktime(time_tm); - time_table_.at(i) = unix_time; - if(i > 0) time_interval_ = min(time_interval_, time_table_.at(i) - time_table_.at(i-1)); - std::free(time_tm); - - for(int j = 0;j < sp3_str.size();++j){ - istringstream iss{sp3_str.at(j)}; - vector ss; - for(int k = 0;k < 5;++k){ - string tmp; - iss >> tmp; - ss.push_back(tmp); + // Get Header Info + for(int page = 0;page < (int)file.size();++page){ + int num_of_time_stamps, num_of_sat; + + for(int line = 0;line < 3;++line){ + istringstream iss{file.at(page).at(line)}; + + if(line == 0){ + // in seventh line, there is time stamps + // http://epncb.oma.be/ftp/data/format/sp3c.txt + for(int i = 0;i < 7;++i){ + // how many time stamps are written? + string each; iss >> each; + if(i == 6) num_of_time_stamps = stoi(each); + } + }else if(line == 1){ + for(int i= 0;i < 4;++i){ + string each; iss >> each; + if(i == 3) time_interval_ = stod(each); + } + }else if(line == 2){ + for(int i = 0;i < 2;++i){ + string each; iss >> each; + if(i == 1) num_of_sat = stoi(each); + } } - int sat_id = GetIndexFromID(ss.front()); + } - bool available_flag = true; - double clock = stod(ss.at(4)); - if(std::abs(clock - nan99) < 1.0) available_flag = false; - available_table_.at(i).at(sat_id) = available_flag; + int line = 3; + while(file.at(page).at(line).front() != '*') ++line; + + int start_line, end_line; + if(ur_flag == UR_NOT_UR){ + start_line = line; + end_line = line + (num_of_sat + 1)*num_of_time_stamps; + }else{ + int offset = (int)ur_flag - (int)UR_OBSERVE1; + start_line = line + (num_of_sat + 1)*num_of_time_stamps/8*offset; + end_line = line + (num_of_sat + 1)*num_of_time_stamps/8*(offset + 1); + } - if(available_flag) ++time_and_index_num_.at(sat_id); - gnss_sat_clock_table_.at(i).at(sat_id) = clock*(speed_of_light*1e-6); + double unix_time = 0; + for(int i = 0;i < end_line - start_line;++i){ + int line = i + start_line; + + istringstream iss{file.at(page).at(line)}; + vector s; + if(i%(num_of_sat + 1) == 0){ + for(int j = 0;j < 7;++j){ + string tmp; + iss >> tmp; + s.push_back(tmp); + } + unix_time = get_unixtime_from_timestamp_line(s); + }else{ + for(int j = 0;j < 5;++j){ + string tmp; + iss >> tmp; + s.push_back(tmp); + } + int sat_id = GetIndexFromID(s.front()); + + double clock = stod(s.at(4)); + if(std::abs(clock - nan99) < 1.0) continue; + + // in the file, clock bias is expressed in [micro second], so by multiplying by the speed_of_light & 1e-6, they are converted to [m] + clock *= (speed_of_light_m_s*1e-6); + if(!unixtime_vector_.at(sat_id).empty() && std::abs(unix_time - unixtime_vector_.at(sat_id).back()) < 1.0){ + unixtime_vector_.at(sat_id).back() = unix_time; + gnss_sat_clock_table_.at(sat_id).back() = clock; + }else{ + unixtime_vector_.at(sat_id).push_back(unix_time); + gnss_sat_clock_table_.at(sat_id).emplace_back(clock); + } + } } } - }else{ - vector data; - if(ur_flag){ + }else{ // .clk30s + if(UR_PREDICT1 <= ur_flag && ur_flag <= UR_PREDICT4){ cout << "clock settings has something wrong" << endl; exit(1); } - else ProcessData(file, data); + time_interval_ = 1e9; - time_and_index_num_.assign(all_sat_num_, 0); - - for(int i = 0;i < data.size();++i){ - istringstream iss{data.at(i)}; - vector s; - for(int j = 0;j < 11;++j){ - string tmp; - iss >> tmp; - s.push_back(tmp); + for(int page = 0;page < (int)file.size();++page){ + double start_unix_time, end_unix_time; + if(ur_flag == UR_NOT_UR){ + start_unix_time = unix_time_period.first; + end_unix_time = unix_time_period.second + 30; + }else{ + start_unix_time = -1; + end_unix_time = 0; } - - tm *time_tm = initilized_tm(); - time_tm->tm_year = stoi(s.at(2)) - 1900; - time_tm->tm_mon = stoi(s.at(3)) - 1; //0 - 11 - time_tm->tm_mday = stoi(s.at(4)); - time_tm->tm_hour = stoi(s.at(5)); - time_tm->tm_min = stoi(s.at(6)); - time_tm->tm_sec = (int)(stod(s.at(7)) + 1e-4); - double unix_time = (double)mktime(time_tm); - std::free(time_tm); - if(!time_table_.size() || std::abs(time_table_.back() - unix_time) > 1e-4){ - if(time_table_.size()){ - time_interval_ = min(time_interval_, unix_time - time_table_.back()); + for(int line = 0;line < (int)file.at(page).size();++line){ + if(file.at(page).at(line).substr(0, 3) != "AS ") continue; + + istringstream iss{file.at(page).at(line)}; + vector s; + for(int i = 0;i < 11;++i){ + string tmp; + iss >> tmp; + s.push_back(tmp); } - time_table_.push_back(unix_time); - gnss_sat_clock_table_.push_back(vector(all_sat_num_, 0)); - available_table_.push_back(vector(all_sat_num_, false)); - } + tm *time_tm = initilized_tm(); + time_tm->tm_year = stoi(s.at(2)) - 1900; + time_tm->tm_mon = stoi(s.at(3)) - 1; // 0 - 11, in time struct, 1 - 12 month is expressed by 1 - 12 + time_tm->tm_mday = stoi(s.at(4)); + time_tm->tm_hour = stoi(s.at(5)); + time_tm->tm_min = stoi(s.at(6)); + time_tm->tm_sec = (int)(stod(s.at(7)) + 1e-4); // for the numerical error, plus 1e-4. tm_sec is tobe int + double unix_time = (double)mktime(time_tm); + const double interval = 6*60*60; + if(start_unix_time < 0){ + start_unix_time = unix_time + (ur_flag - UR_OBSERVE1)*interval; + end_unix_time = start_unix_time + interval; + } - int sat_id = GetIndexFromID(s.at(1)); - double clock_bias = stod(s.at(9))*speed_of_light; //[s] -> [m] - available_table_.back().at(sat_id) = true; - ++time_and_index_num_.at(sat_id); - gnss_sat_clock_table_.back().at(sat_id) = clock_bias; + std::free(time_tm); + + int sat_id = GetIndexFromID(s.at(1)); + double clock_bias = stod(s.at(9))*speed_of_light_m_s; // [s] -> [m] + if(start_unix_time - unix_time > 1e-4) continue; // for the numerical error + if(end_unix_time - unix_time < 1e-4) break; + if(!unixtime_vector_.at(sat_id).empty() && std::abs(unix_time - unixtime_vector_.at(sat_id).back()) < 1e-4){ // for the numerical error + unixtime_vector_.at(sat_id).back() = unix_time; + gnss_sat_clock_table_.at(sat_id).back() = clock_bias; + }else{ + if(!unixtime_vector_.at(sat_id).empty()) time_interval_ = min(time_interval_, unix_time - unixtime_vector_.at(sat_id).back()); + unixtime_vector_.at(sat_id).emplace_back(unix_time); + gnss_sat_clock_table_.at(sat_id).emplace_back(clock_bias); + } + } } } } @@ -620,92 +649,124 @@ void GnssSat_clock::SetUp(const double start_unix_time, const double step_sec) validate_.assign(all_sat_num_, false); nearest_index_.resize(all_sat_num_); - time_vector_.resize(all_sat_num_); + time_period_.resize(all_sat_num_); clock_bias_.resize(all_sat_num_); - for(int i = 0;i < all_sat_num_;++i){ - if(!time_and_index_num_.at(i)){ - validate_.at(i) = false; + for(int sat_id = 0;sat_id < all_sat_num_;++sat_id){ + if(unixtime_vector_.at(sat_id).empty()){ + validate_.at(sat_id) = false; continue; } - int table_index = lower_bound(time_table_.begin(), time_table_.end(), start_unix_time) - time_table_.begin(); - double now_time = time_table_.at(table_index); + int index = lower_bound(unixtime_vector_.at(sat_id).begin(), unixtime_vector_.at(sat_id).end(), start_unix_time) - unixtime_vector_.at(sat_id).begin(); + if(index == (int)unixtime_vector_.at(sat_id).size()){ + validate_.at(sat_id) = false; + nearest_index_.at(sat_id) = index; + continue; + } - if(interpolation_number_%2 && table_index != 0){ - double pre_time = time_table_.at(table_index - 1); - if(std::abs(start_unix_time - pre_time) < std::abs(start_unix_time - now_time)) --table_index; + double nearest_unixtime = unixtime_vector_.at(sat_id).at(index); + if(interpolation_number_%2 && index != 0){ + double pre_time = unixtime_vector_.at(sat_id).at(index - 1); + if(std::abs(start_unix_time - pre_time) < std::abs(start_unix_time - nearest_unixtime)) --index; + } + nearest_index_.at(sat_id) = index; + nearest_unixtime = unixtime_vector_.at(sat_id).at(index); + if (std::abs(start_unix_time - nearest_unixtime) > time_interval_){ + validate_.at(sat_id) = false; + continue; } - - nearest_index_.at(i) = table_index; //for both even and odd: 2n+1 -> [-n, n] 2n -> [-n, n) for(int j = -interpolation_number_/2;j < (interpolation_number_ + 1)/2;++j){ - int index = table_index + j; - if(index < 0 || index >= time_table_.size()) continue; - if(!available_table_.at(index).at(i)) continue; + int now_index = index + j; + if(now_index < 0 || now_index >= (int)unixtime_vector_.at(sat_id).size()) continue; - time_vector_.at(i).push_back(time_table_.at(index)); - clock_bias_.at(i).push_back(gnss_sat_clock_table_.at(index).at(i)); + time_period_.at(sat_id).push_back(unixtime_vector_.at(sat_id).at(now_index)); + clock_bias_.at(sat_id).push_back(gnss_sat_clock_table_.at(sat_id).at(now_index)); } - if(clock_bias_.at(i).size() != interpolation_number_) continue; - else validate_.at(i) = true; + if((int)time_period_.at(sat_id).size() != interpolation_number_){ + validate_.at(sat_id) = false; + continue; + } + double time_period_length = time_period_.at(sat_id).back() - time_period_.at(sat_id).front(); + if(time_period_length > time_interval_*(interpolation_number_ - 1) + 1e-4){ // more strict for clock_bias + validate_.at(sat_id) = false; + continue; + }else{ + validate_.at(sat_id) = true; + } - if(validate_.at(i)){ - if(std::abs(start_unix_time - time_table_.at(table_index)) < step_sec/2.0){ - gnss_sat_clock_.at(i) = gnss_sat_clock_table_.at(table_index).at(i); - }else{ - gnss_sat_clock_.at(i) = LagrangeInterpolation(time_vector_.at(i), clock_bias_.at(i), start_unix_time); - } + if(std::abs(start_unix_time - nearest_unixtime) < 1e-4){ // for the numerical error + gnss_sat_clock_.at(sat_id) = gnss_sat_clock_table_.at(sat_id).at(index); + }else{ + gnss_sat_clock_.at(sat_id) = LagrangeInterpolation(time_period_.at(sat_id), clock_bias_.at(sat_id), start_unix_time); } } } void GnssSat_clock::Update(const double now_unix_time) { - for(int i = 0;i < all_sat_num_;++i){ - if(!time_and_index_num_.at(i)){ - validate_.at(i) = false; + for(int sat_id = 0;sat_id < all_sat_num_;++sat_id){ + if(unixtime_vector_.at(sat_id).empty()){ + validate_.at(sat_id) = false; continue; } - int table_index = nearest_index_.at(i); - double pre_unix = time_table_.at(table_index); - double post_unix; - if(table_index + 1 < time_table_.size()) post_unix = time_table_.at(table_index + 1); - else post_unix = 0; - - if(std::abs(now_unix_time - post_unix) < std::abs(now_unix_time - pre_unix)){ - ++table_index; - nearest_index_.at(i) = table_index; - - time_vector_.at(i).clear(); - clock_bias_.at(i).clear(); - - //for both even and odd: 2n+1 -> [-n, n] 2n -> [-n, n) //in clock_bias, more strict. - for(int j = -interpolation_number_/2;j < (interpolation_number_ + 1)/2;++j){ - int index = table_index + j; - if(index < 0 || index >= time_table_.size()) continue; - if(!available_table_.at(index).at(i)) continue; - time_vector_.at(i).push_back(time_table_.at(index)); - clock_bias_.at(i).push_back(gnss_sat_clock_table_.at(index).at(i)); + int index = nearest_index_.at(sat_id); + if(index == (int)unixtime_vector_.at(sat_id).size()){ + validate_.at(sat_id) = false; + continue; + } + + if(index + 1 < (int)unixtime_vector_.at(sat_id).size()){ + double pre_unix = unixtime_vector_.at(sat_id).at(index); + double post_unix = unixtime_vector_.at(sat_id).at(index + 1); + + if(std::abs(now_unix_time - post_unix) < std::abs(now_unix_time - pre_unix)){ + ++index; + nearest_index_.at(sat_id) = index; + + time_period_.at(sat_id).clear(); + clock_bias_.at(sat_id).clear(); + + //for both even and odd: 2n+1 -> [-n, n] 2n -> [-n, n) + for(int j = -interpolation_number_/2;j < (interpolation_number_ + 1)/2;++j){ + int now_index = index + j; + if(now_index < 0 || now_index >= (int)unixtime_vector_.at(sat_id).size()) continue; + + time_period_.at(sat_id).push_back(unixtime_vector_.at(sat_id).at(now_index)); + clock_bias_.at(sat_id).push_back(gnss_sat_clock_table_.at(sat_id).at(now_index)); + } } } + if((int)time_period_.at(sat_id).size() != interpolation_number_){ + validate_.at(sat_id) = false; + continue; + } - if(clock_bias_.at(i).size() != interpolation_number_){ - validate_.at(i) = false; + double nearest_unix_time = unixtime_vector_.at(sat_id).at(index); + if (std::abs(now_unix_time - nearest_unix_time) > time_interval_){ + validate_.at(sat_id) = false; continue; - }else validate_.at(i) = true; + } - if(validate_.at(i)){ - if(std::abs(now_unix_time - time_table_.at(table_index)) < step_sec_/2.0){ - gnss_sat_clock_.at(i) = gnss_sat_clock_table_.at(table_index).at(i); - }else{ - gnss_sat_clock_.at(i) = LagrangeInterpolation(time_vector_.at(i), clock_bias_.at(i), now_unix_time); - } - } + //in clock_bias, more strict. + double time_period_length = time_period_.at(sat_id).back() - time_period_.at(sat_id).front(); + if(time_period_length > time_interval_*(interpolation_number_ - 1) + 1e-4){ // more strict for clock_bias + validate_.at(sat_id) = false; + continue; + }else{ + validate_.at(sat_id) = true; + } + + if(std::abs(now_unix_time - nearest_unix_time) < 1e-4){ + gnss_sat_clock_.at(sat_id) = gnss_sat_clock_table_.at(sat_id).at(index); + }else{ + gnss_sat_clock_.at(sat_id) = LagrangeInterpolation(time_period_.at(sat_id), clock_bias_.at(sat_id), now_unix_time); + } } } @@ -719,17 +780,17 @@ GnssSat_Info::GnssSat_Info() {} void GnssSat_Info::Init(vector>& position_file, int position_interpolation_method, int position_interpolation_number, - bool position_ur_flag, + UR_KINDS position_ur_flag, vector>& clock_file, string clock_file_extension, int clock_interpolation_number, - bool clock_ur_flag) + UR_KINDS clock_ur_flag) { - position_.Init(position_file, position_interpolation_method, - position_interpolation_number, position_ur_flag); + auto unix_time_period = position_.Init(position_file, position_interpolation_method, + position_interpolation_number, position_ur_flag); clock_.Init(clock_file, clock_file_extension, - clock_interpolation_number, clock_ur_flag); + clock_interpolation_number, clock_ur_flag, unix_time_period); } void GnssSat_Info::SetUp(const double start_unix_time, const double step_sec) @@ -785,7 +846,10 @@ double GnssSat_Info::GetSatelliteClock(int sat_id) const return clock_.GetSatClock(sat_id); } -GnssSatellites::GnssSatellites(bool is_calc_enabled)//: ofs_true("true.csv"), ofs_esti("esti.csv"), ofs_sa("sa.csv") +GnssSatellites::GnssSatellites(bool is_calc_enabled) +#ifdef GNSS_SATELLITES_DEBUG_OUTPUT + : ofs_true("true.csv"), ofs_esti("esti.csv"), ofs_sa("sa.csv") +#endif { is_calc_enabled_ = is_calc_enabled; } @@ -798,22 +862,22 @@ bool GnssSatellites::IsCalcEnabled() const void GnssSatellites::Init(vector>& true_position_file, int true_position_interpolation_method, int true_position_interpolation_number, - bool true_position_ur_flag, + UR_KINDS true_position_ur_flag, vector>& true_clock_file, string true_clock_file_extension, int true_clock_interpolation_number, - bool true_clock_ur_flag, + UR_KINDS true_clock_ur_flag, vector>& estimate_position_file, int estimate_position_interpolation_method, int estimate_position_interpolation_number, - bool estimate_position_ur_flag, + UR_KINDS estimate_position_ur_flag, vector>& estimate_clock_file, string estimate_clock_file_extension, int estimate_clock_interpolation_number, - bool estimate_clock_ur_flag) + UR_KINDS estimate_clock_ur_flag) { true_info_.Init(true_position_file, true_position_interpolation_method, @@ -824,7 +888,7 @@ void GnssSatellites::Init(vector>& true_position_file, true_clock_file_extension, true_clock_interpolation_number, true_clock_ur_flag); - + estimate_info_.Init(estimate_position_file, estimate_position_interpolation_method, estimate_position_interpolation_number, @@ -834,7 +898,7 @@ void GnssSatellites::Init(vector>& true_position_file, estimate_clock_file_extension, estimate_clock_interpolation_number, estimate_clock_ur_flag); - + return; } @@ -863,13 +927,16 @@ void GnssSatellites::SetUp(const SimTime* sim_time) void GnssSatellites::Update(const SimTime* sim_time) { if (!IsCalcEnabled()) return; - + double elapsed_sec = sim_time->GetElapsedSec(); true_info_.Update(elapsed_sec + start_unix_time_); estimate_info_.Update(elapsed_sec + start_unix_time_); - //DebugOutput(); +#ifdef GNSS_SATELLITES_DEBUG_OUTPUT + DebugOutput(); +#endif + return; } @@ -938,8 +1005,8 @@ double GnssSatellites::GetSatelliteClock(const int sat_id) const if(sat_id >= GetNumOfSatellites() || !GetWhetherValid(sat_id)){ return 0.0; } - - return estimate_info_.GetSatelliteClock(sat_id) + clock_bias_bias_; + + return estimate_info_.GetSatelliteClock(sat_id); } double GnssSatellites::GetPseudoRangeECEF(const int sat_id, libra::Vector<3> rec_position, double rec_clock, const double frequency) const @@ -959,7 +1026,7 @@ double GnssSatellites::GetPseudoRangeECEF(const int sat_id, libra::Vector<3> rec //ionospheric delay const double ionospheric_delay = AddIonosphericDelay(sat_id, rec_position, frequency, ECEF); - + res += ionospheric_delay; return res; @@ -982,7 +1049,7 @@ double GnssSatellites::GetPseudoRangeECI(const int sat_id, libra::Vector<3> rec_ //ionospheric delay const double ionospheric_delay = AddIonosphericDelay(sat_id, rec_position, frequency, ECI); - + res += ionospheric_delay; return res; @@ -1005,11 +1072,12 @@ pair GnssSatellites::GetCarrierPhaseECEF(const int sat_id, libra //ionospheric delay const double ionospheric_delay = AddIonosphericDelay(sat_id, rec_position, frequency, ECEF); - + res -= ionospheric_delay; - + // wavelength - double lambda = speed_of_light*1e-6/frequency; + // frequency is thought to be given by MHz + double lambda = speed_of_light_m_s*1e-6/frequency; double cycle = res/lambda; double bias = floor(cycle); @@ -1035,11 +1103,12 @@ pair GnssSatellites::GetCarrierPhaseECI(const int sat_id, libra: //ionospheric delay const double ionospheric_delay = AddIonosphericDelay(sat_id, rec_position, frequency, ECI); - + res -= ionospheric_delay; // wavelength - double lambda = speed_of_light*1e-6/frequency; + // frequency is thought to be given by MHz + double lambda = speed_of_light_m_s*1e-6/frequency; double cycle = res/lambda; double bias = floor(cycle); @@ -1064,7 +1133,7 @@ double GnssSatellites::AddIonosphericDelay(const int sat_id, const libra::Vector libra::Vector<3> gnss_position; if(flag == ECEF) gnss_position = true_info_.GetSatellitePositionEcef(sat_id); - else if(flag == ECI) gnss_position = true_info_.GetSatellitePositionEci(sat_id); + else if(flag == ECI) gnss_position = true_info_.GetSatellitePositionEci(sat_id); double angle_rad = angle(rec_position, gnss_position - rec_position); const double default_delay = 20.0; //[m] default delay @@ -1076,69 +1145,70 @@ double GnssSatellites::AddIonosphericDelay(const int sat_id, const libra::Vector return delay; } -string GnssSatellites::GetLogHeader() const +std::string GnssSatellites::GetLogHeader() const { - string str_tmp = ""; + std::string str_tmp = ""; return str_tmp; } -string GnssSatellites::GetLogValue() const +std::string GnssSatellites::GetLogValue() const { - string str_tmp = ""; - + std::string str_tmp = ""; + return str_tmp; } void GnssSatellites::DebugOutput() { - for(int sat_id = 0;sat_id < 32;++sat_id){ +#ifdef GNSS_SATELLITES_DEBUG_OUTPUT + for(int sat_id = 0;sat_id < gps_sat_num_;++sat_id){ if(true_info_.GetWhetherValid(sat_id)){ - auto true_pos = true_info_.GetSatellitePositionEci(sat_id); + auto true_pos = true_info_.GetSatellitePositionEcef(sat_id); for(int i = 0;i < 3;++i){ - //ofs_true << fixed << setprecision(10) << true_pos[i] << ","; + ofs_true << fixed << setprecision(10) << true_pos[i] << ","; } auto true_clock = true_info_.GetSatelliteClock(sat_id); - //ofs_true << true_clock << ","; + ofs_true << true_clock << ","; }else{ for(int i = 0;i < 4;++i){ - //ofs_true << 0.0 << ","; + ofs_true << 0.0 << ","; } } if(estimate_info_.GetWhetherValid(sat_id)){ - auto esti_pos = estimate_info_.GetSatellitePositionEci(sat_id); + auto esti_pos = estimate_info_.GetSatellitePositionEcef(sat_id); for(int i = 0;i < 3;++i){ - //ofs_esti << fixed << setprecision(10) << esti_pos[i] << ","; + ofs_esti << fixed << setprecision(10) << esti_pos[i] << ","; } auto esti_clock = estimate_info_.GetSatelliteClock(sat_id); - //ofs_esti << esti_clock << ","; + ofs_esti << esti_clock << ","; }else{ for(int i = 0;i < 4;++i){ - //ofs_esti << 0.0 << ","; + ofs_esti << 0.0 << ","; } } if(GetWhetherValid(sat_id)){ - auto true_pos = true_info_.GetSatellitePositionEci(sat_id); + auto true_pos = true_info_.GetSatellitePositionEcef(sat_id); auto true_clock = true_info_.GetSatelliteClock(sat_id); - auto esti_pos = estimate_info_.GetSatellitePositionEci(sat_id); + auto esti_pos = estimate_info_.GetSatellitePositionEcef(sat_id); auto esti_clock = estimate_info_.GetSatelliteClock(sat_id); for(int i = 0;i < 3;++i){ - //ofs_sa << fixed << setprecision(10) << esti_pos[i] - true_pos[i] << ","; + ofs_sa << fixed << setprecision(10) << esti_pos[i] - true_pos[i] << ","; } - //ofs_sa << fixed << setprecision(10) << esti_clock - true_clock << ","; + ofs_sa << fixed << setprecision(10) << esti_clock - true_clock << ","; }else{ for(int i = 0;i < 4;++i){ - //ofs_sa << 0.0 << ","; + ofs_sa << 0.0 << ","; } } } - //ofs_true << endl; - //ofs_esti << endl; - //ofs_sa << endl; - + ofs_true << endl; + ofs_esti << endl; + ofs_sa << endl; +#endif return; } diff --git a/src/Environment/Global/GnssSatellites.h b/src/Environment/Global/GnssSatellites.h index f62899b93..932b03f95 100644 --- a/src/Environment/Global/GnssSatellites.h +++ b/src/Environment/Global/GnssSatellites.h @@ -12,7 +12,8 @@ #include "../../Library/math/Vector.hpp" #include "../../Interface/LogOutput/ILoggable.h" -const double speed_of_light = 299792458.0; //[m/s] in vacuum +extern const double speed_of_light; //[m/s] in vacuum +extern const double nan99; #define ECEF 0 #define ECI 1 @@ -20,66 +21,71 @@ const double speed_of_light = 299792458.0; //[m/s] in vacuum #define Lagrange 0 #define Trigonometric 1 -const double nan99 = 999999.999999; +// #define GNSS_SATELLITES_DEBUG_OUTPUT // for debug output, Uncomment + +/** + * @enum UR_KINDS + * @enum When Using Ultra Rapid Calendar, decide to use which 6 hours in each observe and predict 24 hours calender + */ +typedef enum +{ + UR_NOT_UR, //!< don't use UR + + UR_OBSERVE1, //!< the most oldest observe 6 hours (most precise) + UR_OBSERVE2, //!< the second oldest observe 6 hours (6 ~ 12) + UR_OBSERVE3, + UR_OBSERVE4, + + UR_PREDICT1, //!< the most oldest presercve 6 hours (most precise) + UR_PREDICT2, + UR_PREDICT3, + UR_PREDICT4, + + UR_UNKNOWN +} UR_KINDS; class GnssSat_coordinate { public: - int GetIndexFromID(string sat_num) const; - string GetIDFromIndex(int index) const; + int GetIndexFromID(std::string sat_num) const; + std::string GetIDFromIndex(int index) const; int GetNumOfSatellites() const; bool GetWhetherValid(int sat_id) const; protected: - void ProcessData(vector>& raw_file, vector>>& data); - void ProcessData(vector>& raw_file, vector>>& data, bool ur_flag); - void ProcessData(vector>& raw_file, vector& data); /* https://en.wikipedia.org/wiki/Trigonometric_interpolation# http://acc.igs.org/orbits/orbit-interp_gpssoln03.pdf */ - template Vector TrigonometricInterpolation(const vector& time_vector, const vector>& values, double time) const; - double TrigonometricInterpolation(const vector& time_vector, const vector& values, double time) const; - template Vector LagrangeInterpolation(const vector& time_vector, const vector>& values, double time) const; - double LagrangeInterpolation(const vector& time_vector, const vector& values, double time) const; + template libra::Vector TrigonometricInterpolation(const std::vector& time_vector, const std::vector>& values, double time) const; + double TrigonometricInterpolation(const std::vector& time_vector, const std::vector& values, double time) const; + template libra::Vector LagrangeInterpolation(const std::vector& time_vector, const std::vector>& values, double time) const; + double LagrangeInterpolation(const std::vector& time_vector, const std::vector& values, double time) const; + + std::vector> unixtime_vector_; // unixtime for all sat + + std::vector> time_period_; // for inter polation - std::vector time_table_; //unix_time - std::vector> available_table_; //whether available for every time std::vector validate_; //whether available at the time std::vector nearest_index_; //index list for update(in position, time_and_index_list_. in clock_bias, time_table_) - std::vector> time_vector_; double step_sec_; - double time_interval_ = 1e9; + double time_interval_; int interpolation_number_; - - const int gps_sat_num_ = 32; - const int glonass_sat_num_ = 26; - const int galileo_sat_num_ = 36; - const int beidou_sat_num_ = 16; - const int qzss_sat_num_ = 7; - - const int gps_index_bias_ = -1; - const int glonass_index_bias_ = gps_index_bias_ + gps_sat_num_; - const int galileo_index_bias_ = glonass_index_bias_ + glonass_sat_num_; - const int beidou_index_bias_ = galileo_index_bias_ + galileo_sat_num_; - const int qzss_index_bias_ = beidou_index_bias_ + beidou_sat_num_; - - const int all_sat_num_ = gps_sat_num_ + glonass_sat_num_ + galileo_sat_num_ + beidou_sat_num_ + qzss_sat_num_; }; class GnssSat_position: public GnssSat_coordinate { public: GnssSat_position() {} - void Init(vector>& file, int interpolation_method, - int interpolation_number, bool ur_flag); + std::pair Init(std::vector>& file, int interpolation_method, + int interpolation_number, UR_KINDS ur_flag); void SetUp(const double start_unix_time, const double step_sec); void Update(const double now_unix_time); - Vector<3> GetSatEcef(int sat_id) const; - Vector<3> GetSatEci(int sat_id) const; - + libra::Vector<3> GetSatEcef(int sat_id) const; + libra::Vector<3> GetSatEci(int sat_id) const; + private: //gnss_satellites_position [m] std::vector> gnss_sat_ecef_; @@ -87,18 +93,17 @@ class GnssSat_position: public GnssSat_coordinate std::vector>> gnss_sat_table_ecef_; std::vector>> gnss_sat_table_eci_; - vector>> time_and_index_list_; //contains the pair of available time and index. - vector>> ecef_; - vector>> eci_; + std::vector>> ecef_; + std::vector>> eci_; }; class GnssSat_clock: public GnssSat_coordinate { public: GnssSat_clock() {} - void Init(vector>& file, string file_extension, - int interpolation_number, bool ur_flag); + void Init(std::vector>& file, std::string file_extension, + int interpolation_number, UR_KINDS ur_flag, std::pair unix_time_period); void SetUp(const double start_unix_time, const double step_sec); void Update(const double now_unix_time); @@ -107,7 +112,6 @@ class GnssSat_clock: public GnssSat_coordinate private: std::vector gnss_sat_clock_; //clock bias [m], not micro second std::vector> gnss_sat_clock_table_; - vector time_and_index_num_; //clock bias calculation should be stict, so it includes time_table_index(not for available) std::vector> clock_bias_; }; @@ -115,15 +119,15 @@ class GnssSat_Info { public: GnssSat_Info(); - void Init(vector>& position_file, + void Init(std::vector>& position_file, int position_interpolation_method, int position_interpolation_number, - bool position_ur_flag, + UR_KINDS position_ur_flag, - vector>& clock_file, - string clock_file_extension, + std::vector>& clock_file, + std::string clock_file_extension, int clock_interpolation_number, - bool clock_ur_flag); + UR_KINDS clock_ur_flag); void SetUp(const double start_unix_time, const double step_sec); void Update(const double now_unix_time); @@ -145,27 +149,27 @@ class GnssSatellites : public ILoggable public: //CONSTRUCTOR AND DECONSTRUCTOR GnssSatellites(bool is_calc_enabled); - ~GnssSatellites() {} + virtual ~GnssSatellites() {} - void Init(vector>& true_position_file, + void Init(std::vector>& true_position_file, int true_position_interpolation_method, int true_position_interpolation_number, - bool true_position_ur_flag, + UR_KINDS true_position_ur_flag, - vector>& true_clock_file, - string true_clock_file_extension, + std::vector>& true_clock_file, + std::string true_clock_file_extension, int true_clock_interpolation_number, - bool true_clock_ur_flag, - - vector>& estimate_position_file, + UR_KINDS true_clock_ur_flag, + + std::vector>& estimate_position_file, int estimate_position_interpolation_method, int estimate_position_interpolation_number, - bool estimate_position_ur_flag, + UR_KINDS estimate_position_ur_flag, - vector>& estimate_clock_file, - string estimate_clock_file_extension, + std::vector>& estimate_clock_file, + std::string estimate_clock_file_extension, int estimate_clock_interpolation_number, - bool estimate_clock_ur_flag); + UR_KINDS estimate_clock_ur_flag); bool IsCalcEnabled() const; @@ -173,8 +177,8 @@ class GnssSatellites : public ILoggable void Update(const SimTime* sim_time); //GET FUNCTIONS - int GetIndexFromID(string sat_num) const; - string GetIDFromIndex(int index) const; + int GetIndexFromID(std::string sat_num) const; + std::string GetIDFromIndex(int index) const; int GetNumOfSatellites() const; bool GetWhetherValid(int sat_id) const; double GetStartUnixTime() const; @@ -186,21 +190,21 @@ class GnssSatellites : public ILoggable double GetSatelliteClock(const int sat_id) const; - //Get observation Range:[m] CarrierPhase:[no unit] + //Get observation Range:[m] CarrierPhase:[no unit], frequency is thought to be expressed in MHz double GetPseudoRangeECEF(const int sat_id, libra::Vector<3> rec_position, double rec_clock, const double frequency) const; double GetPseudoRangeECI(const int sat_id, libra::Vector<3> rec_position, double rec_clock, const double frequency) const; - pair GetCarrierPhaseECEF(const int sat_id, libra::Vector<3> rec_position, double rec_clock, const double frequency) const; - pair GetCarrierPhaseECI(const int sat_id, libra::Vector<3> rec_position, double rec_clock, const double frequency) const; + std::pair GetCarrierPhaseECEF(const int sat_id, libra::Vector<3> rec_position, double rec_clock, const double frequency) const; + std::pair GetCarrierPhaseECI(const int sat_id, libra::Vector<3> rec_position, double rec_clock, const double frequency) const; // FOR LOG OUTPUT // 継承のために - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + std::string GetLogHeader() const override; + std::string GetLogValue() const override; // FOR DEBUG OUTPUT void DebugOutput(void); private: - double TrigonometricInterpolation(vector time_period, vector position, double time); + double TrigonometricInterpolation(std::vector time_period, std::vector position, double time); // for Ionospheric delay very Miscellaneous need to fix. double AddIonosphericDelay(const int sat_id, const libra::Vector<3> rec_position, const double frequency, const bool flag) const; @@ -208,10 +212,12 @@ class GnssSatellites : public ILoggable GnssSat_Info true_info_; GnssSat_Info estimate_info_; double start_unix_time_; - const double clock_bias_bias_ = 0.0; //there is fixed bias between IGS clk and other files...(I don't know why) - //ofstream ofs_true; - //ofstream ofs_esti; - //ofstream ofs_sa; +#ifdef GNSS_SATELLITES_DEBUG_OUTPUT + ofstream ofs_true; + ofstream ofs_esti; + ofstream ofs_sa; +#endif + }; #endif diff --git a/src/Environment/Global/HipparcosCatalogue.h b/src/Environment/Global/HipparcosCatalogue.h index 923ddd4d5..842dcf972 100644 --- a/src/Environment/Global/HipparcosCatalogue.h +++ b/src/Environment/Global/HipparcosCatalogue.h @@ -18,9 +18,9 @@ struct HipData class HipparcosCatalogue : public ILoggable { public: - HipparcosCatalogue(double max_magnitude, string catalogue_path); + HipparcosCatalogue(double max_magnitude, std::string catalogue_path); ~HipparcosCatalogue(); - bool ReadContents(const string& filename, const char delimiter); + bool ReadContents(const std::string& filename, const char delimiter); //ヒッパルコス星表のデータは視等級順に並べているので、等級の順位を引数に取る int GetCatalogueSize() const { return hip_catalogue.size(); } int GetHipID(int rank) const { return hip_catalogue[rank].hip_num; } @@ -30,14 +30,13 @@ class HipparcosCatalogue : public ILoggable libra::Vector<3> GetStarDir_i(int rank) const;//恒星の方向を返す libra::Vector<3> GetStarDir_b(int rank, Quaternion q_i2b) const;//恒星の方向を返す - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; bool IsCalcEnabled = true; private: std::vector hip_catalogue;//CSVデータの格納先 double max_magnitude_; - string catalogue_path_; - + std::string catalogue_path_; }; diff --git a/src/Environment/Global/SimTime.cpp b/src/Environment/Global/SimTime.cpp index 51a8b8927..07ce8a145 100644 --- a/src/Environment/Global/SimTime.cpp +++ b/src/Environment/Global/SimTime.cpp @@ -105,7 +105,7 @@ void SimTime::UpdateTime(void) // カウントアップしてきた経過時刻を強制的に実際の経過時刻に合わせる // 意図としては、ブレークポイントからの復帰後に一瞬でリアルタイムに追いつかせるため - elapsed_time_sec_ = chrono::duration_cast(clk.now() - clock_start_time_millisec_).count() * sim_speed_; + elapsed_time_sec_ = (chrono::duration_cast>>(clk.now() - clock_start_time_millisec_).count() * sim_speed_); } else { diff --git a/src/Environment/Global/SimTime.h b/src/Environment/Global/SimTime.h index 113b33e44..8ac1f0c9d 100644 --- a/src/Environment/Global/SimTime.h +++ b/src/Environment/Global/SimTime.h @@ -14,8 +14,6 @@ #include "../../Library/sgp4/sgp4io.h" #include "../../Library/sgp4/sgp4ext.h" -using namespace std; - struct TimeState { bool running = false; @@ -88,8 +86,8 @@ class SimTime: public ILoggable inline const int GetStartMin(void) const { return start_min_; }; inline const double GetStartSec(void) const { return start_sec_; }; // logs - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; //debug void PrintStartDateTime(void) const; @@ -112,7 +110,7 @@ class SimTime: public ILoggable int log_counter_; int disp_counter_; TimeState state_; - chrono::system_clock::time_point clock_start_time_millisec_; + std::chrono::system_clock::time_point clock_start_time_millisec_; // chrono::system_clock::time_point clock_elapsed_time_millisec_; //実時間でのシミュレーション実行時間 //固定値 diff --git a/src/Environment/Local/Atmosphere.cpp b/src/Environment/Local/Atmosphere.cpp index 7e1023db1..d8650a6df 100644 --- a/src/Environment/Local/Atmosphere.cpp +++ b/src/Environment/Local/Atmosphere.cpp @@ -8,28 +8,29 @@ using libra::Vector; using libra::NormalRand; +using std::string; +using std::cerr; +using std::endl; using namespace libra; -Atmosphere::Atmosphere(string model, string fname, double gauss_stddev) //コンストラクタ,空気密度外乱の割合を決定 +Atmosphere::Atmosphere(string model, string fname, double gauss_stddev, + bool is_manual_param_used, double manual_daily_f107, double manual_average_f107, double manual_ap) + :model_(model), fname_(fname), air_density_(0.0), gauss_stddev_(gauss_stddev), + is_table_imported_(false), is_manual_param_used_(is_manual_param_used), + manual_daily_f107_(manual_daily_f107), manual_average_f107_(manual_average_f107), manual_ap_(manual_ap) { - model_ = model; - fname_ = fname; - gauss_stddev_ = gauss_stddev; - air_density_ = 0.0; - is_table_imported_ = false; - if (model_ == "STANDARD") { - cerr << "Air density model : STANDARD" << endl; + std::cerr << "Air density model : STANDARD" << std::endl; } else if (model_ == "NRLMSISE00") { - cerr << "Air density model : NRLMSISE00" << endl; + std::cerr << "Air density model : NRLMSISE00" << std::endl; } else { - cerr << "Air density model : None" << endl; - cerr << "Air density is set as 0.0 kg/m3" << endl; + std::cerr << "Air density model : None" << std::endl; + std::cerr << "Air density is set as 0.0 kg/m3" << std::endl; } } @@ -55,23 +56,27 @@ double Atmosphere::CalcAirDensity(double decyear, double endsec, Vector<3> lat_l } else if (model_ == "NRLMSISE00") // NRLMSISE00 model { - if (!is_table_imported_) + if (!is_manual_param_used_) { - if (GetSpaceWeatherTable(decyear, endsec)) - { - is_table_imported_ = true; - } - else + if (!is_table_imported_) { - cerr << "Air density is changed to STANDARD model" << endl; - model_ = "STANDARD"; + if (GetSpaceWeatherTable(decyear, endsec)) + { + is_table_imported_ = true; + } + else + { + std::cerr << "Air density is switched to STANDARD model" << std::endl; + model_ = "STANDARD"; + } } } double latrad = lat_lon_alt(0); double lonrad = lat_lon_alt(1); double alt = lat_lon_alt(2); - air_density_ = CalcNRLMSISE00(decyear, latrad, lonrad, alt, table_); + air_density_ = CalcNRLMSISE00(decyear, latrad, lonrad, alt, + table_, is_manual_param_used_, manual_daily_f107_, manual_average_f107_, manual_ap_); } else { diff --git a/src/Environment/Local/Atmosphere.h b/src/Environment/Local/Atmosphere.h index 0165c7ed1..9cea44849 100644 --- a/src/Environment/Local/Atmosphere.h +++ b/src/Environment/Local/Atmosphere.h @@ -3,6 +3,9 @@ #ifndef __Atmosphere_H__ #define __Atmosphere_H__ +#include +#include + #include "../../Library/math/Vector.hpp" #include "../../Library/math/Quaternion.hpp" #include "../../Interface/LogOutput/ILoggable.h" @@ -16,19 +19,24 @@ class Atmosphere : public ILoggable public: bool IsCalcEnabled = true; - Atmosphere(string model, string fname, double gauss_stddev); + Atmosphere(std::string model, std::string fname, double gauss_stddev, + bool is_manual_param, double manual_f107, double manual_f107a, double manual_ap); double CalcAirDensity(double decyear, double endsec, Vector<3> lat_lon_alt); double GetAirDensity() const; - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; private: - string model_; - string fname_; - double air_density_; - double gauss_stddev_; //空気密度の標準偏差(密度に対する割合で定義) - vector table_; - bool is_table_imported_; + std::string model_; // 大気密度モデル + std::string fname_; // iniファイルのパス + double air_density_; // 大気密度 kg/m^3 + double gauss_stddev_; // 空気密度の標準偏差(密度に対する割合で定義) + std::vector table_; // Space weather table + bool is_table_imported_; // tableが読み込まれたかどうか + bool is_manual_param_used_; // ユーザー指定の固定値(f10.7,ap値)を使うかどうか f10.7値については https://www.swpc.noaa.gov/phenomena/f107-cm-radio-emissions 参照 + double manual_daily_f107_; // ユーザー指定のf10.7値(1日あたりの値) + double manual_average_f107_; // ユーザー指定のf10.7値(3ヶ月程度の平均値) + double manual_ap_; // ユーザー指定のap値 ap値については http://wdc.kugi.kyoto-u.ac.jp/kp/kpexp-j.html 参照 // double rw_stepwidth_; // double rw_stddev_; // double rw_limit_; diff --git a/src/Environment/Local/LocalCelestialInformation.h b/src/Environment/Local/LocalCelestialInformation.h index daa451b01..53ef5479b 100644 --- a/src/Environment/Local/LocalCelestialInformation.h +++ b/src/Environment/Local/LocalCelestialInformation.h @@ -20,8 +20,8 @@ class LocalCelestialInformation : public ILoggable // Get Global CelesInfo for gravitational constant inline const CelestialInformation& GetGlobalInfo() const { return *glo_celes_info_; } // FOR LOG OUTPUT - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; private: const CelestialInformation* glo_celes_info_; diff --git a/src/Environment/Local/LocalEnvironment.cpp b/src/Environment/Local/LocalEnvironment.cpp index f3e1bf7ee..0f275739a 100644 --- a/src/Environment/Local/LocalEnvironment.cpp +++ b/src/Environment/Local/LocalEnvironment.cpp @@ -22,7 +22,7 @@ void LocalEnvironment::Initialize(SimulationConfig* sim_config, const GlobalEnvi { // Read file name IniAccess iniAccess = IniAccess(sim_config->sat_file_[sat_id]); - string ini_fname = iniAccess.ReadString("LOCAL_ENVIRONMENT", "local_env_file"); + std::string ini_fname = iniAccess.ReadString("LOCAL_ENVIRONMENT", "local_env_file"); // Save ini file sim_config->main_logger_->CopyFileToLogDir(ini_fname); // Initialize diff --git a/src/Environment/Local/MagEnvironment.h b/src/Environment/Local/MagEnvironment.h index b113f68df..49ed4413b 100644 --- a/src/Environment/Local/MagEnvironment.h +++ b/src/Environment/Local/MagEnvironment.h @@ -13,7 +13,7 @@ class MagEnvironment : public ILoggable public: bool IsCalcEnabled = true; - MagEnvironment(string fname, + MagEnvironment(std::string fname, double mag_rwdev, double mag_rwlimit, double mag_wnvar); @@ -21,8 +21,8 @@ class MagEnvironment : public ILoggable Vector<3> GetMag_i() const; Vector<3> GetMag_b() const; - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; private: Vector<3> Mag_i_; @@ -30,11 +30,11 @@ class MagEnvironment : public ILoggable double mag_rwdev_; double mag_rwlimit_; double mag_wnvar_; - string fname_; + std::string fname_; void AddNoise(double* mag_i_array); }; -#endif //__MagEnvironment_H__ \ No newline at end of file +#endif //__MagEnvironment_H__ diff --git a/src/Environment/Local/SRPEnvironment.h b/src/Environment/Local/SRPEnvironment.h index c1ec67161..a56658cb2 100644 --- a/src/Environment/Local/SRPEnvironment.h +++ b/src/Environment/Local/SRPEnvironment.h @@ -19,8 +19,8 @@ class SRPEnvironment : public ILoggable double GetShadowFunction() const; //Get Shadow function inline bool GetIsEclipsed() const { return(shadow_function_ >= 1.0 ? false : true); } //Returns true if the shadow function is less than 1 - virtual string GetLogHeader() const; //ログofヘッダー - virtual string GetLogValue() const; //ログof値 + virtual std::string GetLogHeader() const; //ログofヘッダー + virtual std::string GetLogValue() const; //ログof値 private: double pressure_; //太陽輻射定数、単位はN/m^2 @@ -35,4 +35,4 @@ class SRPEnvironment : public ILoggable void CalcShadowFunction(double a, double b, double c, double x, double y); }; -#endif /* SRPEnvironment_h */ \ No newline at end of file +#endif /* SRPEnvironment_h */ diff --git a/src/Interface/HilsInOut/CMakeLists.txt b/src/Interface/HilsInOut/CMakeLists.txt index 12c4df538..49291c9ec 100644 --- a/src/Interface/HilsInOut/CMakeLists.txt +++ b/src/Interface/HilsInOut/CMakeLists.txt @@ -1,15 +1,17 @@ cmake_minimum_required(VERSION 3.13) project(HILS_IO) + +if(USE_HILS) add_library(${PROJECT_NAME} STATIC - ComPortInterface.cpp - ComPortInterface.h - COSMOS_TCP_IF.cpp - COSMOS_TCP_IF.h - COSMOSWrapper.cpp - COSMOSWrapper.h - HardwareMessage.cpp - HardwareMessage.h -) + HilsPortManager.cpp + Ports/HilsUartPort.cpp + ) +else() +add_library(${PROJECT_NAME} STATIC + HilsPortManager.cpp + ) +endif() + # Compile option if(MSVC) target_compile_options(${PROJECT_NAME} PUBLIC "/W4") diff --git a/src/Interface/HilsInOut/HilsPortManager.cpp b/src/Interface/HilsInOut/HilsPortManager.cpp new file mode 100644 index 000000000..0274cba0a --- /dev/null +++ b/src/Interface/HilsInOut/HilsPortManager.cpp @@ -0,0 +1,71 @@ +#include "HilsPortManager.h" + +HilsPortManager::HilsPortManager() +{ +} + +HilsPortManager::~HilsPortManager() +{ +} + +int HilsPortManager::UartConnectComPort(unsigned int port_id, unsigned int baud_rate, unsigned int tx_buf_size, unsigned int rx_buf_size) +{ +#ifdef USE_HILS + if (uart_com_ports_[port_id] != nullptr) + { + printf("Error: Port is already used\n"); + return -1; + } + if (baud_rate <= 0 || tx_buf_size <= 0 || rx_buf_size <= 0) + { + printf("Error: Illegal parameter\n"); + return -1; + } + uart_com_ports_[port_id] = new HilsUartPort(port_id, baud_rate, tx_buf_size, rx_buf_size); + return 0; +#else + return -1; +#endif +} + +// Close port and free resources +int HilsPortManager::UartCloseComPort(unsigned int port_id) +{ +#ifdef USE_HILS + if (uart_com_ports_[port_id] == nullptr) + { + // Port not used + return -1; + } + + uart_com_ports_[port_id]->ClosePort(); + HilsUartPort* port = uart_com_ports_.at(port_id); + delete port; + uart_com_ports_.erase(port_id); + return 0; +#else + return -1; +#endif +} + +int HilsPortManager::UartReceive(unsigned int port_id, unsigned char* buffer, int offset, int count) +{ +#ifdef USE_HILS + HilsUartPort* port = uart_com_ports_[port_id]; + if (port == nullptr) return -1; + return port->ReadRx(buffer, offset, count); +#else + return -1; +#endif +} + +int HilsPortManager::UartSend(unsigned int port_id, unsigned char* buffer, int offset, int count) +{ +#ifdef USE_HILS + HilsUartPort* port = uart_com_ports_[port_id]; + if (port == nullptr) return -1; + return port->WriteTx(buffer, offset, count); +#else + return -1; +#endif +} diff --git a/src/Interface/HilsInOut/HilsPortManager.h b/src/Interface/HilsInOut/HilsPortManager.h new file mode 100644 index 000000000..0c523f14c --- /dev/null +++ b/src/Interface/HilsInOut/HilsPortManager.h @@ -0,0 +1,32 @@ +#pragma once +#ifdef USE_HILS + #include "Ports/HilsUartPort.h" +#endif +#include + +class HilsPortManager +{ +public: + HilsPortManager(); + virtual ~HilsPortManager(); + + // Uart Communication port functions + virtual int UartConnectComPort(unsigned int port_id, + unsigned int baud_rate, // [baud] ex 9600, 115200 + unsigned int tx_buf_size, unsigned int rx_buf_size); + virtual int UartCloseComPort(unsigned int port_id); + // Uart Com ports -> Components + virtual int UartReceive(unsigned int port_id, unsigned char* buffer, int offset, int count); + // Uart Components -> Com ports + virtual int UartSend(unsigned int port_id, unsigned char* buffer, int offset, int count); + + // TODO: Add I2C Communication port functions + +private: + // Uart ports +#ifdef USE_HILS + std::map uart_com_ports_; +#endif + // I2C ports + // std::map i2c_com_ports_; +}; diff --git a/src/Interface/HilsInOut/Ports/HilsUartPort.cpp b/src/Interface/HilsInOut/Ports/HilsUartPort.cpp new file mode 100644 index 000000000..b8bc630c3 --- /dev/null +++ b/src/Interface/HilsInOut/Ports/HilsUartPort.cpp @@ -0,0 +1,173 @@ +#include "HilsUartPort.h" + +HilsUartPort::HilsUartPort(const unsigned int port_id, const unsigned int baud_rate, + const unsigned int tx_buffer_size, const unsigned int rx_buffer_size) + :kPortName(PortName(port_id)), baud_rate_(baud_rate), + kTxBufferSize(tx_buffer_size), kRxBufferSize(rx_buffer_size) +{ + // Allocate managed arrays. + tx_buf_ = gcnew bytearray(kTxBufferSize); + rx_buf_ = gcnew bytearray(kRxBufferSize); + + Initialize(); +} + +HilsUartPort::~HilsUartPort() +{ + // Memory allocated by gcnew does not have to be explicitly deleted. +} + +// Static method to convert from com port number to com port name. +std::string HilsUartPort::PortName(unsigned int port_id) +{ + return "COM" + std::to_string(port_id); +} + +int HilsUartPort::Initialize() +{ + try + { + // Initialize port + // Type conversion from unmanaged string to managed string + msclr::gcroot port_name_managed = msclr::interop::marshal_as(kPortName); + port_ = gcnew System::IO::Ports::SerialPort(port_name_managed, baud_rate_); + // TODO: set parameter + port_->ReadTimeout = 10; // [ms] + port_->WriteTimeout = 10; // [ms] + } + catch (System::Exception^ e) + { + // baudrate must be larger than zero + // port nameのチェックはここでは行われない + System::Console::Write(e->Message); + return -1; + } + + int ret = OpenPort(); + + return ret; +} + +int HilsUartPort::ClosePort() +{ + try + { + port_->Close(); + } + catch (System::Exception^ e) + { + System::Console::Write(e->Message); + return -1; + } + return 0; +} + +int HilsUartPort::OpenPort() +{ + try + { + port_->Open(); + // TODO: Add enum for exception + // Exception reference + // https://docs.microsoft.com/en-us/dotnet/api/system.io.ports.serialport.open?view=netframework-4.7.2 + + } + catch (System::UnauthorizedAccessException^ e) + { + // Access is denied to the port. + // or + // The current process, or another process on the system, already has the specified COM port open + // either by a SerialPort instance or in unmanaged code. + System::Console::Write(e->Message); + return -2; + } + catch (System::ArgumentOutOfRangeException^ e) + { + // One or more of the properties for this instance are invalid. + System::Console::Write(e->Message); + return -3; + } + catch (System::ArgumentException^ e) + { + // The port name does not begin with "COM". + // or + // The file type of the port is not supported. + System::Console::Write(e->Message); + return -4; + } + catch (System::IO::IOException^ e) + { + // The port is in an invalid state. + System::Console::Write(e->Message); + return -5; + } + return 0; // Success !! +} + +int HilsUartPort::WriteTx(unsigned char* buffer, int offset, int count) +{ + // Marshal::Copy : Copies data from an unmanaged memory pointer to a managed array. + System::Runtime::InteropServices::Marshal::Copy((System::IntPtr)(buffer + offset), tx_buf_, 0, count); + try + { + port_->Write(tx_buf_, 0, count); + } + catch (System::Exception^ e) + { + System::Console::Write(e->Message); + return -1; + } + return 0; +} + +int HilsUartPort::ReadRx(unsigned char* buffer, int offset, int count) +{ + try + { + int received_bytes = port_->Read(rx_buf_, 0, count); + // Marshal::Copy : Copies data from a managed array to an unmanaged memory pointer. + System::Runtime::InteropServices::Marshal::Copy(rx_buf_, 0, (System::IntPtr)(buffer + offset), count); + return received_bytes; + // TODO: Add enum for exception + } + catch (System::TimeoutException^ e) + { + // No bytes were available to read. + return -1; + } + catch (System::Exception^ e) + { + System::Console::Write(e->Message); + return -2; + } +} + +int HilsUartPort::GetBytesToRead() +{ + int bytes_to_read; + try + { + bytes_to_read = port_->BytesToRead; + } + catch (System::Exception^ e) + { + // Port is not open + System::Console::Write(e->Message); + return -1; + } + return bytes_to_read; +} + +int HilsUartPort::DiscardInBuffer() +{ + try + { + port_->DiscardInBuffer(); + } + catch (System::Exception^ e) + { + System::Console::Write(e->Message); + return -1; + } + return 0; +} diff --git a/src/Interface/HilsInOut/Ports/HilsUartPort.h b/src/Interface/HilsInOut/Ports/HilsUartPort.h new file mode 100644 index 000000000..c4a01d0e4 --- /dev/null +++ b/src/Interface/HilsInOut/Ports/HilsUartPort.h @@ -0,0 +1,34 @@ +#pragma once +#include +#include + +#include + +// SerialPort Class Reference: https://docs.microsoft.com/en-us/dotnet/api/system.io.ports.serialport?view=netframework-4.7.2 +// System::Byte: an 8-bit unsigned integer +typedef cli::array bytearray; + +class HilsUartPort +{ +public: + HilsUartPort(const unsigned int port_id, const unsigned int baud_rate, const unsigned int tx_buffer_size, const unsigned int rx_buffer_size); + ~HilsUartPort(); + int OpenPort(); + int ClosePort(); + int WriteTx(unsigned char* buffer, int offset, int count); + int ReadRx(unsigned char* buffer, int offset, int count); +private: + const unsigned int kTxBufferSize; + const unsigned int kRxBufferSize; + const std::string kPortName; + static std::string PortName(unsigned int port_id); + int Initialize(); + int GetBytesToRead(); + int DiscardInBuffer(); + unsigned int baud_rate_; // [baud] ex. 9600, 115200 + // gcroot is the type-safe wrapper template to refer to a CLR object from the c++ heap + // reference: https://docs.microsoft.com/en-us/cpp/dotnet/how-to-declare-handles-in-native-types?view=msvc-160 + msclr::gcroot port_; + msclr::gcroot tx_buf_; + msclr::gcroot rx_buf_; +}; diff --git a/src/Interface/InitInput/IniAccess.h b/src/Interface/InitInput/IniAccess.h index e57a46ace..c6ed00ffb 100644 --- a/src/Interface/InitInput/IniAccess.h +++ b/src/Interface/InitInput/IniAccess.h @@ -20,8 +20,6 @@ #undef MAX_PATH #define MAX_PATH 1024 -using namespace std; -using std::string; using libra::Vector; using libra::Quaternion; @@ -29,7 +27,7 @@ class IniAccess { //変数 private: - string file_path_; //読み込みファイルパス + std::string file_path_; //読み込みファイルパス char strPath_[MAX_PATH]; //読み込みファイルパス char strText_[1024]; //バッファ #ifndef WIN32 @@ -37,7 +35,7 @@ class IniAccess #endif public: - IniAccess(string path); + IniAccess(std::string path); //iniファイル読み込み関数 double ReadDouble(const char* section_name, const char* key_name); @@ -46,15 +44,15 @@ class IniAccess void ReadDoubleArray(const char* section_name, const char* key_name, int id, int num, double* data); template< size_t NumElement> void ReadVector(const char* section_name, const char* key_name, Vector& data); - vector ReadStrVector(const char* section_name, const char* key_name); + std::vector ReadStrVector(const char* section_name, const char* key_name); void ReadQuaternion(const char* section_name, const char* key_name, Quaternion& data); void ReadChar(const char* section_name, const char* key_name, int size, char* data); - string ReadString(const char* section_name, const char* key_name); + std::string ReadString(const char* section_name, const char* key_name); bool ReadEnable(const char* section_name, const char* key_name); // CSV読み込み関数 - vector Split(string& input, char delimiter); - void ReadCsvDouble(vector>& doublevec, int node_num); /*nxm行列を読み込む場合, n,mの内大きい方を第二引数に代入する(メモリ事前確保のため)*/ - void ReadCsvString(vector>& stringvec, int node_num); + std::vector Split(std::string& input, char delimiter); + void ReadCsvDouble(std::vector>& doublevec, int node_num); /*nxm行列を読み込む場合, n,mの内大きい方を第二引数に代入する(メモリ事前確保のため)*/ + void ReadCsvString(std::vector>& stringvec, int node_num); }; //テンプレートなのでヘッダに書く @@ -62,7 +60,7 @@ template void IniAccess::ReadVector(const char* section_name, const char* key_name, Vector& data) { for (int i = 0; i < NumElement; i++){ - stringstream c_name; + std::stringstream c_name; c_name << key_name << "(" << i << ")"; data[i] = ReadDouble(section_name, c_name.str().c_str()); } diff --git a/src/Interface/InitInput/InitComponent/InitANT.cpp b/src/Interface/InitInput/InitComponent/InitANT.cpp index c3deeec0b..c281f3000 100644 --- a/src/Interface/InitInput/InitComponent/InitANT.cpp +++ b/src/Interface/InitInput/InitComponent/InitANT.cpp @@ -7,11 +7,11 @@ using libra::Vector; // アンテナ初期化,ant_idで対応するアンテナ読み込み -ANT InitANT(int ant_id, const string fname){ +ANT InitANT(int ant_id, const std::string fname){ IniAccess ant_conf(fname); - const string st_ant_id = std::to_string(static_cast(ant_id)); + const std::string st_ant_id = std::to_string(static_cast(ant_id)); const char *cs = st_ant_id.data(); char Section[30] = "ANT"; diff --git a/src/Interface/InitInput/InitComponent/InitBAT.cpp b/src/Interface/InitInput/InitComponent/InitBAT.cpp index 7cc8224f2..cea6fa575 100644 --- a/src/Interface/InitInput/InitComponent/InitBAT.cpp +++ b/src/Interface/InitInput/InitComponent/InitBAT.cpp @@ -4,11 +4,11 @@ #include "../Initialize.h" #include "../../../Component/Power/BAT.h" -BAT InitBAT(ClockGenerator* clock_gen, int bat_id, const string fname) { +BAT InitBAT(ClockGenerator* clock_gen, int bat_id, const std::string fname) { IniAccess bat_conf(fname); - const string st_bat_id = std::to_string(static_cast(bat_id)); + const std::string st_bat_id = std::to_string(static_cast(bat_id)); const char *cs = st_bat_id.data(); char Section[30] = "BAT"; @@ -29,7 +29,7 @@ BAT InitBAT(ClockGenerator* clock_gen, int bat_id, const string fname) { std::vector cell_discharge_curve_coeffs; for (int i=0; i<=approx_order; ++i) { - cell_discharge_curve_coeffs.push_back(bat_conf.ReadDouble(Section, ("cell_discharge_curve_coeffs(" + to_string(i) + ")").c_str())); + cell_discharge_curve_coeffs.push_back(bat_conf.ReadDouble(Section, ("cell_discharge_curve_coeffs(" + std::to_string(i) + ")").c_str())); } double initial_dod; diff --git a/src/Interface/InitInput/InitComponent/InitEMDS.cpp b/src/Interface/InitInput/InitComponent/InitEMDS.cpp index 6a8411738..85c4862a3 100644 --- a/src/Interface/InitInput/InitComponent/InitEMDS.cpp +++ b/src/Interface/InitInput/InitComponent/InitEMDS.cpp @@ -5,7 +5,7 @@ EMDS InitEMDS(int actuator_id) { IniAccess emds_conf("data/ini/component/EMDS.ini"); - string section = "EMDS" + to_string(actuator_id); + std::string section = "EMDS" + std::to_string(actuator_id); Vector<3> displacement; emds_conf.ReadVector(section.c_str(), "displacement", displacement); diff --git a/src/Interface/InitInput/InitComponent/InitGNSSReceiver.cpp b/src/Interface/InitInput/InitComponent/InitGNSSReceiver.cpp index dea98c1af..c31db87ee 100644 --- a/src/Interface/InitInput/InitComponent/InitGNSSReceiver.cpp +++ b/src/Interface/InitInput/InitComponent/InitGNSSReceiver.cpp @@ -9,13 +9,13 @@ typedef struct _gnssrecever_param Vector<3> antenna_pos_b; Quaternion q_b2c; double half_width; - string gnss_id; + std::string gnss_id; int ch_max; Vector<3> noise_std; }GNSSReceiverParam; -GNSSReceiverParam ReadGNSSReceiverIni(const string fname, const GnssSatellites* gnss_satellites) +GNSSReceiverParam ReadGNSSReceiverIni(const std::string fname, const GnssSatellites* gnss_satellites) { GNSSReceiverParam gnssreceiver_param; @@ -44,7 +44,7 @@ GNSSReceiverParam ReadGNSSReceiverIni(const string fname, const GnssSatellites* }; -GNSSReceiver InitGNSSReceiver(ClockGenerator* clock_gen, int id, const string fname, const Dynamics* dynamics, const GnssSatellites* gnss_satellites, const SimTime* simtime) +GNSSReceiver InitGNSSReceiver(ClockGenerator* clock_gen, int id, const std::string fname, const Dynamics* dynamics, const GnssSatellites* gnss_satellites, const SimTime* simtime) { GNSSReceiverParam gr_param = ReadGNSSReceiverIni(fname, gnss_satellites); @@ -54,11 +54,11 @@ GNSSReceiver InitGNSSReceiver(ClockGenerator* clock_gen, int id, const string fn }; -GNSSReceiver InitGNSSReceiver(ClockGenerator* clock_gen, PowerPort* power_port, int id, const string fname, const Dynamics* dynamics, const GnssSatellites* gnss_satellites, const SimTime* simtime) +GNSSReceiver InitGNSSReceiver(ClockGenerator* clock_gen, PowerPort* power_port, int id, const std::string fname, const Dynamics* dynamics, const GnssSatellites* gnss_satellites, const SimTime* simtime) { GNSSReceiverParam gr_param = ReadGNSSReceiverIni(fname, gnss_satellites); GNSSReceiver gnss_r(gr_param.prescaler, clock_gen, power_port, id, gr_param.gnss_id, gr_param.ch_max, gr_param.antenna_model, gr_param.antenna_pos_b, gr_param.q_b2c, gr_param.half_width, gr_param.noise_std, dynamics, gnss_satellites, simtime); return gnss_r; -}; \ No newline at end of file +}; diff --git a/src/Interface/InitInput/InitComponent/InitGScalculator.cpp b/src/Interface/InitInput/InitComponent/InitGScalculator.cpp index 97faf4f11..a11f0c7b5 100644 --- a/src/Interface/InitInput/InitComponent/InitGScalculator.cpp +++ b/src/Interface/InitInput/InitComponent/InitGScalculator.cpp @@ -4,7 +4,7 @@ #include "../../../Component/CommGS/GScalculator.h" // 地上局計算クラス初期化 -GScalculator InitGScalculator(const string fname){ +GScalculator InitGScalculator(const std::string fname){ IniAccess gs_conf(fname); diff --git a/src/Interface/InitInput/InitComponent/InitGyro.cpp b/src/Interface/InitInput/InitComponent/InitGyro.cpp index b52084cd7..3c30c94ee 100644 --- a/src/Interface/InitInput/InitComponent/InitGyro.cpp +++ b/src/Interface/InitInput/InitComponent/InitGyro.cpp @@ -1,7 +1,7 @@ #include "../Initialize.h" #include "../../../Component/AOCS/Gyro.h" -Gyro InitGyro(ClockGenerator* clock_gen, int sensor_id, const string fname, double compo_step_time, const Dynamics* dynamics){ +Gyro InitGyro(ClockGenerator* clock_gen, int sensor_id, const std::string fname, double compo_step_time, const Dynamics* dynamics){ IniAccess gyro_conf(fname); char GSection[30] = "GYRO"; @@ -45,7 +45,7 @@ Gyro InitGyro(ClockGenerator* clock_gen, int sensor_id, const string fname, doub return gyro; } -Gyro InitGyro(ClockGenerator* clock_gen, PowerPort* power_port, int sensor_id, const string fname, double compo_step_time, const Dynamics* dynamics){ +Gyro InitGyro(ClockGenerator* clock_gen, PowerPort* power_port, int sensor_id, const std::string fname, double compo_step_time, const Dynamics* dynamics){ IniAccess gyro_conf(fname); char GSection[30] = "GYRO"; @@ -92,4 +92,4 @@ Gyro InitGyro(ClockGenerator* clock_gen, PowerPort* power_port, int sensor_id, c Gyro gyro(prescaler, clock_gen, power_port, gyro_sb, sensor_id, q_b2c, dynamics); return gyro; -} \ No newline at end of file +} diff --git a/src/Interface/InitInput/InitComponent/InitMagSensor.cpp b/src/Interface/InitInput/InitComponent/InitMagSensor.cpp index acd367f07..5b060888c 100644 --- a/src/Interface/InitInput/InitComponent/InitMagSensor.cpp +++ b/src/Interface/InitInput/InitComponent/InitMagSensor.cpp @@ -1,7 +1,7 @@ #include "../Initialize.h" #include "../../../Component/AOCS/MagSensor.h" -MagSensor InitMagSensor(ClockGenerator* clock_gen, int sensor_id, const string fname, double compo_step_time, const MagEnvironment* magnet){ +MagSensor InitMagSensor(ClockGenerator* clock_gen, int sensor_id, const std::string fname, double compo_step_time, const MagEnvironment* magnet){ IniAccess magsensor_conf(fname); char MSSection[30] = "MAGSENSOR"; @@ -44,7 +44,7 @@ MagSensor InitMagSensor(ClockGenerator* clock_gen, int sensor_id, const string f return magsensor; } -MagSensor InitMagSensor(ClockGenerator* clock_gen, PowerPort* power_port, int sensor_id, const string fname, double compo_step_time, const MagEnvironment* magnet){ +MagSensor InitMagSensor(ClockGenerator* clock_gen, PowerPort* power_port, int sensor_id, const std::string fname, double compo_step_time, const MagEnvironment* magnet){ IniAccess magsensor_conf(fname); char MSSection[30] = "MAGSENSOR"; @@ -91,4 +91,4 @@ MagSensor InitMagSensor(ClockGenerator* clock_gen, PowerPort* power_port, int se MagSensor magsensor(prescaler, clock_gen, power_port, mag_sb, sensor_id, q_b2c, magnet); return magsensor; -} \ No newline at end of file +} diff --git a/src/Interface/InitInput/InitComponent/InitMagTorquer.cpp b/src/Interface/InitInput/InitComponent/InitMagTorquer.cpp index 00560a099..b0f52066d 100644 --- a/src/Interface/InitInput/InitComponent/InitMagTorquer.cpp +++ b/src/Interface/InitInput/InitComponent/InitMagTorquer.cpp @@ -1,7 +1,7 @@ #include "../Initialize.h" #include "../../../Component/AOCS/MagTorquer.h" -MagTorquer InitMagTorquer(ClockGenerator* clock_gen, int actuator_id, const string fname, double compo_step_time, const MagEnvironment* mag_env) +MagTorquer InitMagTorquer(ClockGenerator* clock_gen, int actuator_id, const std::string fname, double compo_step_time, const MagEnvironment* mag_env) { IniAccess magtorquer_conf(fname); char MTSection[30] = "MAGTORQUER"; @@ -46,7 +46,7 @@ MagTorquer InitMagTorquer(ClockGenerator* clock_gen, int actuator_id, const stri return magtorquer; } -MagTorquer InitMagTorquer(ClockGenerator* clock_gen, PowerPort* power_port, int actuator_id, const string fname, double compo_step_time, const MagEnvironment* mag_env) +MagTorquer InitMagTorquer(ClockGenerator* clock_gen, PowerPort* power_port, int actuator_id, const std::string fname, double compo_step_time, const MagEnvironment* mag_env) { IniAccess magtorquer_conf(fname); char MTSection[30] = "MAGTORQUER"; @@ -95,4 +95,4 @@ MagTorquer InitMagTorquer(ClockGenerator* clock_gen, PowerPort* power_port, int q_b2c, scale_factor, max_c, min_c, bias_c, rw_stepwidth, rw_stddev_c, rw_limit_c, nr_stddev_c, mag_env); return magtorquer; -} \ No newline at end of file +} diff --git a/src/Interface/InitInput/InitComponent/InitRWModel.cpp b/src/Interface/InitInput/InitComponent/InitRWModel.cpp index 7f8cf9cea..bb3a7e0fe 100644 --- a/src/Interface/InitInput/InitComponent/InitRWModel.cpp +++ b/src/Interface/InitInput/InitComponent/InitRWModel.cpp @@ -28,13 +28,13 @@ namespace { bool drive_flag; double init_velocity; - void InitParams(int actuator_id, string file_name, double prop_step, double compo_update_step) + void InitParams(int actuator_id, std::string file_name, double prop_step, double compo_update_step) { //Access Parameters IniAccess rwmodel_conf(file_name); - const string st_actuator_num = std::to_string(static_cast(actuator_id)); + const std::string st_actuator_num = std::to_string(static_cast(actuator_id)); const char *cs = st_actuator_num.data(); - string section_tmp = "RW"; + std::string section_tmp = "RW"; section_tmp += cs; const char *RWsection = section_tmp.data(); @@ -47,7 +47,7 @@ namespace { max_torque = rwmodel_conf.ReadDouble(RWsection, "max_torque"); max_velocity = rwmodel_conf.ReadDouble(RWsection, "max_angular_velocity"); - string direction_determination_mode; + std::string direction_determination_mode; direction_determination_mode = rwmodel_conf.ReadString(RWsection, "direction_determination_mode"); if (direction_determination_mode == "QUATERNION") { @@ -70,8 +70,8 @@ namespace { is_calc_jitter_enabled = rwmodel_conf.ReadEnable(RWsection, "jitter_calculation"); is_log_jitter_enabled = rwmodel_conf.ReadEnable(RWsection, "jitter_logging"); - string radial_force_harmonics_coef_path = rwmodel_conf.ReadString(RWsection, "radial_force_harmonics_coef_path"); - string radial_torque_harmonics_coef_path = rwmodel_conf.ReadString(RWsection, "radial_torque_harmonics_coef_path"); + std::string radial_force_harmonics_coef_path = rwmodel_conf.ReadString(RWsection, "radial_force_harmonics_coef_path"); + std::string radial_torque_harmonics_coef_path = rwmodel_conf.ReadString(RWsection, "radial_torque_harmonics_coef_path"); int harmonics_degree = rwmodel_conf.ReadInt(RWsection, "harmonics_degree"); IniAccess conf_radial_force_harmonics(radial_force_harmonics_coef_path); IniAccess conf_radial_torque_harmonics(radial_torque_harmonics_coef_path); @@ -93,7 +93,7 @@ namespace { } } -RWModel InitRWModel(ClockGenerator* clock_gen, int actuator_id, string file_name, double prop_step, double compo_update_step){ +RWModel InitRWModel(ClockGenerator* clock_gen, int actuator_id, std::string file_name, double prop_step, double compo_update_step){ InitParams(actuator_id, file_name, prop_step, compo_update_step); RWModel rwmodel(prescaler, fast_prescaler, clock_gen, step_width, dt_main_routine, jitter_update_interval, @@ -105,7 +105,7 @@ RWModel InitRWModel(ClockGenerator* clock_gen, int actuator_id, string file_name return rwmodel; } -RWModel InitRWModel(ClockGenerator* clock_gen, PowerPort* power_port, int actuator_id, string file_name, double prop_step, double compo_update_step){ +RWModel InitRWModel(ClockGenerator* clock_gen, PowerPort* power_port, int actuator_id, std::string file_name, double prop_step, double compo_update_step){ InitParams(actuator_id, file_name, prop_step, compo_update_step); RWModel rwmodel(prescaler, fast_prescaler, clock_gen, power_port, step_width, dt_main_routine, jitter_update_interval, @@ -115,4 +115,4 @@ RWModel InitRWModel(ClockGenerator* clock_gen, PowerPort* power_port, int actuat drive_flag, init_velocity); return rwmodel; -} \ No newline at end of file +} diff --git a/src/Interface/InitInput/InitComponent/InitSAP.cpp b/src/Interface/InitInput/InitComponent/InitSAP.cpp index cc58e04e6..274fb7c94 100644 --- a/src/Interface/InitInput/InitComponent/InitSAP.cpp +++ b/src/Interface/InitInput/InitComponent/InitSAP.cpp @@ -3,11 +3,11 @@ #include "../Initialize.h" #include "../../../Component/Power/SAP.h" -SAP InitSAP(ClockGenerator* clock_gen, int sap_id, const string fname, const SRPEnvironment* srp) { +SAP InitSAP(ClockGenerator* clock_gen, int sap_id, const std::string fname, const SRPEnvironment* srp) { IniAccess sap_conf(fname); - const string st_sap_id = std::to_string(static_cast(sap_id)); + const std::string st_sap_id = std::to_string(static_cast(sap_id)); const char *cs = st_sap_id.data(); char Section[30] = "SAP"; @@ -34,4 +34,4 @@ SAP InitSAP(ClockGenerator* clock_gen, int sap_id, const string fname, const SRP SAP sap(clock_gen, sap_id, number_of_series, number_of_parallel, cell_area, normal_vector, cell_efficiency, transmission_efficiency, srp); return sap; -} \ No newline at end of file +} diff --git a/src/Interface/InitInput/InitComponent/InitSimpleThruster.cpp b/src/Interface/InitInput/InitComponent/InitSimpleThruster.cpp index 31471262e..5d6e809e5 100644 --- a/src/Interface/InitInput/InitComponent/InitSimpleThruster.cpp +++ b/src/Interface/InitInput/InitComponent/InitSimpleThruster.cpp @@ -3,7 +3,7 @@ SimpleThruster InitSimpleThruster(ClockGenerator* clock_gen, int thruster_id, const std::string fname, const Structure* structure, const Dynamics* dynamics){ IniAccess thruster_conf(fname); - string sectionstr = "THRUSTER" + to_string(thruster_id); + std::string sectionstr = "THRUSTER" + std::to_string(thruster_id); auto* Section = sectionstr.c_str(); int prescaler = thruster_conf.ReadInt(Section, "prescaler"); @@ -31,7 +31,7 @@ SimpleThruster InitSimpleThruster(ClockGenerator* clock_gen, int thruster_id, co SimpleThruster InitSimpleThruster(ClockGenerator* clock_gen, PowerPort* power_port, int thruster_id, const std::string fname, const Structure* structure, const Dynamics* dynamics){ IniAccess thruster_conf(fname); - string sectionstr = "THRUSTER" + to_string(thruster_id); + std::string sectionstr = "THRUSTER" + std::to_string(thruster_id); auto* Section = sectionstr.c_str(); int prescaler = thruster_conf.ReadInt(Section, "prescaler"); diff --git a/src/Interface/InitInput/InitComponent/InitSunSensor.cpp b/src/Interface/InitInput/InitComponent/InitSunSensor.cpp index 3bd5d1b4a..2f8e0d13d 100644 --- a/src/Interface/InitInput/InitComponent/InitSunSensor.cpp +++ b/src/Interface/InitInput/InitComponent/InitSunSensor.cpp @@ -2,10 +2,10 @@ #include "../Initialize.h" #include "../../../Component/AOCS/SunSensor.h" -SunSensor InitSunSensor(ClockGenerator* clock_gen, int ss_id, string file_name, const SRPEnvironment* srp) +SunSensor InitSunSensor(ClockGenerator* clock_gen, int ss_id, std::string file_name, const SRPEnvironment* srp) { IniAccess ss_conf(file_name); - const string st_ss_id = std::to_string(static_cast(ss_id)); + const std::string st_ss_id = std::to_string(static_cast(ss_id)); const char *cs = st_ss_id.data(); char Section[30] = "SUNSENSOR"; strcat(Section, cs); @@ -35,10 +35,10 @@ SunSensor InitSunSensor(ClockGenerator* clock_gen, int ss_id, string file_name, return ss; } -SunSensor InitSunSensor(ClockGenerator* clock_gen, PowerPort* power_port, int ss_id, string file_name, const SRPEnvironment* srp) +SunSensor InitSunSensor(ClockGenerator* clock_gen, PowerPort* power_port, int ss_id, std::string file_name, const SRPEnvironment* srp) { IniAccess ss_conf(file_name); - const string st_ss_id = std::to_string(static_cast(ss_id)); + const std::string st_ss_id = std::to_string(static_cast(ss_id)); const char *cs = st_ss_id.data(); char Section[30] = "SUNSENSOR"; strcat(Section, cs); @@ -66,4 +66,4 @@ SunSensor InitSunSensor(ClockGenerator* clock_gen, PowerPort* power_port, int ss SunSensor ss(prescaler, clock_gen, power_port, ss_id, q_b2c, detectable_angle_rad, nr_stddev, nr_bias_stddev, intensity_lower_threshold_percent, srp); return ss; -} \ No newline at end of file +} diff --git a/src/Interface/InitInput/InitComponent/InitUWBSensor.cpp b/src/Interface/InitInput/InitComponent/InitUWBSensor.cpp index 84b852433..5692dc524 100644 --- a/src/Interface/InitInput/InitComponent/InitUWBSensor.cpp +++ b/src/Interface/InitInput/InitComponent/InitUWBSensor.cpp @@ -4,7 +4,7 @@ UWBSensor InitUWBSensor(int sensor_id) { IniAccess conf("data/ini/component/UWBSensor.ini"); - string section = "UWB" + to_string(sensor_id); + std::string section = "UWB" + std::to_string(sensor_id); const char* csection = section.c_str(); Vector<3> pos; diff --git a/src/Interface/InitInput/InitPower/CsvScenarioInterface.cpp b/src/Interface/InitInput/InitPower/CsvScenarioInterface.cpp index 23f3301f6..7a1c5f931 100644 --- a/src/Interface/InitInput/InitPower/CsvScenarioInterface.cpp +++ b/src/Interface/InitInput/InitPower/CsvScenarioInterface.cpp @@ -12,7 +12,7 @@ void CsvScenarioInterface::Initialize(const std::string fname) CsvScenarioInterface::is_csv_senario_enabled_ = scenario_conf.ReadBoolean(Section, "is_csv_scenario_enabled"); - string csv_path; + std::string csv_path; csv_path = scenario_conf.ReadString(Section, "csv_path"); buffer_line_id_["sun_dir_b_x"] = 1; @@ -99,4 +99,4 @@ double CsvScenarioInterface::GetValueFromBuffer(const std::string buffer_name, c if (itr == buffers_.at(buffer_name).end()) return 0; output = itr->second; return output; -} \ No newline at end of file +} diff --git a/src/Interface/InitInput/Init_Attitude.cpp b/src/Interface/InitInput/Init_Attitude.cpp index 2ba061f84..b117c27e8 100644 --- a/src/Interface/InitInput/Init_Attitude.cpp +++ b/src/Interface/InitInput/Init_Attitude.cpp @@ -2,7 +2,7 @@ #include "../../Dynamics/Attitude/AttitudeRK4.h" #include "../../Dynamics/Attitude/ControlledAttitude.h" -Attitude* InitAttitude(string file_name, const Orbit* orbit, const LocalCelestialInformation* celes_info, const double step_sec, const Matrix<3, 3> inertia_tensor, const int sat_id) +Attitude* InitAttitude(std::string file_name, const Orbit* orbit, const LocalCelestialInformation* celes_info, const double step_sec, const Matrix<3, 3> inertia_tensor, const int sat_id) { IniAccess ini_file(file_name); char* section_ = "ATTITUDE"; @@ -20,7 +20,7 @@ Attitude* InitAttitude(string file_name, const Orbit* orbit, const LocalCelestia Vector<3> torque_b; ini_file.ReadVector(section_, "Torque_b", torque_b); - string name = section_ + to_string(sat_id); // "Attitude" + to_string(id); + std::string name = section_ + std::to_string(sat_id); // "Attitude" + to_string(id); attitude = new AttitudeRK4(omega_b, quaternion_i2b, inertia_tensor, torque_b, step_sec, name); } // Controlled attitude @@ -41,4 +41,4 @@ Attitude* InitAttitude(string file_name, const Orbit* orbit, const LocalCelestia } return attitude; -} \ No newline at end of file +} diff --git a/src/Interface/InitInput/Init_CelesInfo.cpp b/src/Interface/InitInput/Init_CelesInfo.cpp index e05ff73c3..21117fc81 100644 --- a/src/Interface/InitInput/Init_CelesInfo.cpp +++ b/src/Interface/InitInput/Init_CelesInfo.cpp @@ -4,18 +4,18 @@ #include "Initialize.h" #include -CelestialInformation* InitCelesInfo(string file_name) +CelestialInformation* InitCelesInfo(std::string file_name) { IniAccess ini_file(file_name); char* section = "PLANET_SELECTION"; char* furnsh_section = "FURNSH_PATH"; //各種定義読み込み - string inertial_frame = ini_file.ReadString(section, "inertial_frame"); - string aber_cor = ini_file.ReadString(section, "aberration_correction"); - string center_obj = ini_file.ReadString(section, "center_object"); + std::string inertial_frame = ini_file.ReadString(section, "inertial_frame"); + std::string aber_cor = ini_file.ReadString(section, "aberration_correction"); + std::string center_obj = ini_file.ReadString(section, "center_object"); RotationMode rotation_mode; - string rotation_mode_temp = ini_file.ReadString(section, "rotation_mode"); + std::string rotation_mode_temp = ini_file.ReadString(section, "rotation_mode"); if (rotation_mode_temp == "Idle") { rotation_mode = Idle; @@ -34,10 +34,10 @@ CelestialInformation* InitCelesInfo(string file_name) } //SPICE Furnsh - vector keywords = {"TLS", "TPC1", "TPC2", "TPC3", "BSP"}; + std::vector keywords = {"TLS", "TPC1", "TPC2", "TPC3", "BSP"}; for(int i=0;i& surfaces, const Vector<3> cg_b) +AirDrag InitAirDrag(std::string ini_path, const std::vector& surfaces, const Vector<3> cg_b) { auto conf = IniAccess(ini_path); char* section = "AIRDRAG"; @@ -27,7 +27,7 @@ AirDrag InitAirDrag(string ini_path, const vector& surfaces, const Vect return airdrag; } -SolarRadiation InitSRDist(string ini_path, const vector& surfaces, const Vector<3> cg_b) +SolarRadiation InitSRDist(std::string ini_path, const std::vector& surfaces, const Vector<3> cg_b) { auto conf = IniAccess(ini_path); char* section = "SRDIST"; @@ -42,7 +42,7 @@ SolarRadiation InitSRDist(string ini_path, const vector& surfaces, cons return srdist; } -GGDist InitGGDist(string ini_path) +GGDist InitGGDist(std::string ini_path) { auto conf = IniAccess(ini_path); const char* section = "GRAVITY_GRADIENT"; @@ -54,7 +54,7 @@ GGDist InitGGDist(string ini_path) return ggdist; } -MagDisturbance InitMagDisturbance(string ini_path, RMMParams rmm_params) +MagDisturbance InitMagDisturbance(std::string ini_path, RMMParams rmm_params) { auto conf = IniAccess(ini_path); char* section = "MAG_DISTURBANCE"; @@ -66,13 +66,13 @@ MagDisturbance InitMagDisturbance(string ini_path, RMMParams rmm_params) return mag_dist; } -GeoPotential InitGeoPotential(string ini_path) +GeoPotential InitGeoPotential(std::string ini_path) { auto conf = IniAccess(ini_path); const char* section = "GEOPOTENTIAL"; int degree = conf.ReadInt(section, "degree"); - string file_path = conf.ReadString(section, "file_path"); + std::string file_path = conf.ReadString(section, "file_path"); GeoPotential geop(degree, file_path); geop.IsCalcEnabled = conf.ReadEnable(section, CALC_LABEL); geop.IsLogEnabled = conf.ReadEnable(section, LOG_LABEL); @@ -80,17 +80,17 @@ GeoPotential InitGeoPotential(string ini_path) return geop; } -ThirdBodyGravity InitThirdBodyGravity(string ini_path, string ini_path_celes) +ThirdBodyGravity InitThirdBodyGravity(std::string ini_path, std::string ini_path_celes) { //Generate a list of bodies to be calculated in "CelesInfo" auto conf_celes = IniAccess(ini_path_celes); const char* section_celes = "PLANET_SELECTION"; const int num_of_selected_body = conf_celes.ReadInt(section_celes, "num_of_selected_body"); - string center_object = conf_celes.ReadString(section_celes, "center_object"); - std::set selected_body_list; + std::string center_object = conf_celes.ReadString(section_celes, "center_object"); + std::set selected_body_list; for (int i = 0; i < num_of_selected_body; i++) { - string selected_body_id = "selected_body(" + to_string(i) + ")"; + std::string selected_body_id = "selected_body(" + std::to_string(i) + ")"; selected_body_list.insert(conf_celes.ReadString(section_celes, selected_body_id.c_str())); } @@ -99,13 +99,13 @@ ThirdBodyGravity InitThirdBodyGravity(string ini_path, string ini_path_celes) const char* section = "THIRD_BODY_GRAVITY"; const int num_of_third_body = conf.ReadInt(section, "num_of_third_body"); - std::set third_body_list; + std::set third_body_list; if (conf.ReadEnable(section, CALC_LABEL)) //Generate the list of the third object if and only if "calculation=ENABLE" { for (int i = 0; i < num_of_third_body; i++) { - string third_body_id = "third_body(" + to_string(i) + ")"; - string third_body_name = conf.ReadString(section, third_body_id.c_str()); + std::string third_body_id = "third_body(" + std::to_string(i) + ")"; + std::string third_body_name = conf.ReadString(section, third_body_id.c_str()); //If the object specified by `third_body` in "SampleDisturbance.ini" is the center object of the orbital propagation, the system prints an error message. assert(third_body_name != center_object); //If the target specified by `third_body` in "SampleDisturbance.ini" is not in the list of bodies to be calculated by "CelesInfo", the system prints an error message. @@ -119,4 +119,4 @@ ThirdBodyGravity InitThirdBodyGravity(string ini_path, string ini_path_celes) thirdbodyg.IsLogEnabled = conf.ReadEnable(section, LOG_LABEL); return thirdbodyg; -} \ No newline at end of file +} diff --git a/src/Interface/InitInput/Init_Environment.cpp b/src/Interface/InitInput/Init_Environment.cpp index 4a9c2e54e..94dfe10a8 100644 --- a/src/Interface/InitInput/Init_Environment.cpp +++ b/src/Interface/InitInput/Init_Environment.cpp @@ -1,14 +1,16 @@ +#include + #include "Initialize.h" #include "../../Environment/Local/MagEnvironment.h" #include "../../Environment/Local/SRPEnvironment.h" #include "../../Environment/Local/Atmosphere.h" -MagEnvironment InitMagEnvironment(string ini_path) +MagEnvironment InitMagEnvironment(std::string ini_path) { auto conf = IniAccess(ini_path); const char* section = "MAG_ENVIRONMENT"; - string fname = conf.ReadString(section,"coeff_file"); + std::string fname = conf.ReadString(section,"coeff_file"); double mag_rwdev = conf.ReadDouble(section, "mag_rwdev"); double mag_rwlimit = conf.ReadDouble(section, "mag_rwlimit"); double mag_wnvar = conf.ReadDouble(section, "mag_wnvar"); @@ -21,11 +23,11 @@ MagEnvironment InitMagEnvironment(string ini_path) return mag_env; } -SRPEnvironment InitSRPEnvironment(string ini_path) +SRPEnvironment InitSRPEnvironment(std::string ini_path) { auto conf = IniAccess(ini_path); const char* section = "SRP"; - + SRPEnvironment srp_env; srp_env.IsCalcEnabled = conf.ReadEnable(section, CALC_LABEL); srp_env.IsLogEnabled = conf.ReadEnable(section, LOG_LABEL); @@ -33,15 +35,32 @@ SRPEnvironment InitSRPEnvironment(string ini_path) return srp_env; } -Atmosphere InitAtmosphere(string ini_path) +Atmosphere InitAtmosphere(std::string ini_path) { auto conf = IniAccess(ini_path); const char* section = "ATMOSPHERE"; + double f107_threshold = 50.0; + double f107_default = 150.0; - string model = conf.ReadString(section, "model"); - string table_path = conf.ReadString(section, "nrlmsise00_table_path"); + std::string model = conf.ReadString(section, "model"); + std::string table_path = conf.ReadString(section, "nrlmsise00_table_path"); double rho_stddev = conf.ReadDouble(section, "rho_stddev"); - Atmosphere atmosphere(model, table_path, rho_stddev); + bool is_manual_param_used = conf.ReadEnable(section, "is_manual_param_used"); + double manual_daily_f107 = conf.ReadDouble(section, "manual_daily_f107"); + if (manual_daily_f107 < f107_threshold) + { + std::cerr << "Daily F10.7 may be too low. It is set as 150.0 in this simulation. Check [ATMOSPHERE] section in LocalEnvironment.ini." << std::endl; + manual_daily_f107 = f107_default; + } + double manual_average_f107 = conf.ReadDouble(section, "manual_average_f107"); + if (manual_average_f107 < f107_threshold) + { + std::cerr << "Average F10.7 may be too low. It is set as 150.0 in this simulation. Check [ATMOSPHERE] section in LocalEnvironment.ini." << std::endl; + manual_average_f107 = f107_default; + } + double manual_ap = conf.ReadDouble(section, "manual_ap"); + + Atmosphere atmosphere(model, table_path, rho_stddev, is_manual_param_used, manual_daily_f107, manual_average_f107, manual_ap); atmosphere.IsCalcEnabled = conf.ReadEnable(section, CALC_LABEL); atmosphere.IsLogEnabled = conf.ReadEnable(section, LOG_LABEL); diff --git a/src/Interface/InitInput/Init_GnssSatellites.cpp b/src/Interface/InitInput/Init_GnssSatellites.cpp index 364e4a955..380dcddb3 100644 --- a/src/Interface/InitInput/Init_GnssSatellites.cpp +++ b/src/Interface/InitInput/Init_GnssSatellites.cpp @@ -1,10 +1,11 @@ #include +#include #include "../../Environment/Global/GnssSatellites.h" #include "Initialize.h" -string return_dirctory_path(string sort) +std::string return_dirctory_path(std::string sort) { - string main_directory,sub_directory; + std::string main_directory,sub_directory; if(sort.substr(0, 2) == "IG"){ main_directory = "IGS/"; @@ -19,7 +20,7 @@ string return_dirctory_path(string sort) main_directory = "JAXA/"; sub_directory = "madoca/"; }else{ - for(int i = 0;i < sort.size();++i){ + for(int i = 0;i < (int)sort.size();++i){ if(sort.at(i) == '_'){ main_directory = sort.substr(0, i) + "/"; if(sort.at(i + 1) == 'F'){ @@ -29,7 +30,7 @@ string return_dirctory_path(string sort) }else if(sort.at(i + 1) == 'U'){ sub_directory = "ultra_rapid/"; }else{ - cout << "file_sort has something wrong" << endl; + std::cout << "file_sort has something wrong" << std::endl; exit(1); } break; @@ -40,17 +41,17 @@ string return_dirctory_path(string sort) return main_directory + sub_directory; } -void get_raw_contents(string directory_path, string file_name, vector& storage) +void get_raw_contents(std::string directory_path, std::string file_name, std::vector& storage) { - string all_file_path = directory_path + file_name; - ifstream ifs(all_file_path); + std::string all_file_path = directory_path + file_name; + std::ifstream ifs(all_file_path); if(!ifs.is_open()){ - cout << "in " << directory_path << "gnss file: " << file_name << " not found" << endl; + std::cout << "in " << directory_path << "gnss file: " << file_name << " not found" << std::endl; exit(1); } - string str; - while(getline(ifs, str)){ + std::string str; + while(std::getline(ifs, str)){ storage.push_back(str); } ifs.close(); @@ -59,14 +60,14 @@ void get_raw_contents(string directory_path, string file_name, vector& s return; } -void get_sp3_file_contents(string directory_path, string file_sort, string first, string last, vector>& file_contents, bool& ur_flag) +void get_sp3_file_contents(std::string directory_path, std::string file_sort, std::string first, std::string last, std::vector>& file_contents, UR_KINDS& ur_flag) { - string all_directory_path = directory_path + return_dirctory_path(file_sort); - ur_flag = false; + std::string all_directory_path = directory_path + return_dirctory_path(file_sort); + ur_flag = UR_NOT_UR; if(first.substr(0, 3) == "COD"){ - string file_header = "COD0MGXFIN_"; - string file_footer = "0000_01D_05M_ORB.SP3"; + std::string file_header = "COD0MGXFIN_"; + std::string file_footer = "0000_01D_05M_ORB.SP3"; int year = stoi(first.substr(file_header.size(), 4)); int year_last_day = 365 + (year%4 == 0) - (year%100 == 0) + (year%400 == 0); int day = stoi(first.substr(file_header.size() + 4, 3)); @@ -79,26 +80,27 @@ void get_sp3_file_contents(string directory_path, string file_sort, string first year_last_day = 365 + (year%4 == 0) - (year%100 == 0) + (year%400 == 0); day = 1; } - string s_day; - if(day >= 100) s_day = to_string(day); - else if(day >= 10) s_day = '0' + to_string(day); - else s_day = "00" + to_string(day); - string file_name = file_header + to_string(year) + s_day + file_footer; - file_contents.push_back(vector()); + std::string s_day; + if(day >= 100) s_day = std::to_string(day); + else if(day >= 10) s_day = '0' + std::to_string(day); + else s_day = "00" + std::to_string(day); + std::string file_name = file_header + std::to_string(year) + s_day + file_footer; + file_contents.push_back(std::vector()); get_raw_contents(all_directory_path, file_name, file_contents.back()); - + if(file_name == last) break; ++day; } - }else if(file_sort.substr(0, 3) == "IGU" || (file_sort.size() >= 11 && file_sort.substr(file_sort.size() - 11) == "Ultra_rapid")){ //URの場合 - ur_flag = true; - string file_header, file_footer; + }else if(file_sort.substr(0, 3) == "IGU" || file_sort.find("Ultra") != std::string::npos){ //URの場合 + ur_flag = UR_UNKNOWN; + std::string file_header, file_footer; int gps_week, day; int hour; - for(int i = 0;i < first.size();++i){ + for(int i = 0;i < (int)first.size();++i){ int n = first.at(i); - if(48 <= n && n < 58){ + // Looking for the number of file name + if((int)'0' <= n && n < (int)('0' + 10)){ file_header = first.substr(0, i); gps_week = stoi(first.substr(file_header.size(), 4)); day = stoi(first.substr(file_header.size() + 4, 1)); @@ -119,24 +121,25 @@ void get_sp3_file_contents(string directory_path, string file_sort, string first ++gps_week; day = 0; } - string file_name = file_header + to_string(gps_week) + to_string(day) + "_"; + std::string file_name = file_header + std::to_string(gps_week) + std::to_string(day) + "_"; if(hour < 10){ file_name += "0"; } - file_name += to_string(hour) + file_footer; - file_contents.push_back(vector()); + file_name += std::to_string(hour) + file_footer; + file_contents.push_back(std::vector()); get_raw_contents(all_directory_path, file_name, file_contents.back()); - + if(file_name == last) break; hour += 6; } }else{ - string file_header, file_footer; + std::string file_header, file_footer; int gps_week, day; - for(int i = 0;i < first.size();++i){ + for(int i = 0;i < (int)first.size();++i){ int n = first.at(i); - if(48 <= n && n < 58){ + // Looking for the number of file name + if((int)'0' <= n && n < (int)('0' + 10)){ file_header = first.substr(0, i); gps_week = stoi(first.substr(file_header.size(), 4)); day = stoi(first.substr(file_header.size() + 4, 1)); @@ -144,7 +147,7 @@ void get_sp3_file_contents(string directory_path, string file_sort, string first break; } } - + file_contents.clear(); while(true){ @@ -152,11 +155,11 @@ void get_sp3_file_contents(string directory_path, string file_sort, string first ++gps_week; day = 0; } - string file_name = file_header + to_string(gps_week) + to_string(day) + file_footer; - file_contents.push_back(vector()); + std::string file_name = file_header + std::to_string(gps_week) + std::to_string(day) + file_footer; + file_contents.push_back(std::vector()); get_raw_contents(all_directory_path, file_name, file_contents.back()); - + if(file_name == last) break; ++day; } @@ -165,70 +168,117 @@ void get_sp3_file_contents(string directory_path, string file_sort, string first return; } -void get_clk_file_contents(string directory_path, string extension, string file_sort, string first, string last, vector>& file_contents) +void get_clk_file_contents(std::string directory_path, std::string extension, std::string file_sort, std::string first, std::string last, std::vector>& file_contents) { - string all_directory_path = directory_path + return_dirctory_path(file_sort) + extension.substr(1) + '/'; - - string file_header, file_footer; - int gps_week, day; - for(int i = 0;i < first.size();++i){ - int n = first.at(i); - if(48 <= n && n < 58){ - file_header = first.substr(0, i); - gps_week = stoi(first.substr(file_header.size(), 4)); - day = stoi(first.substr(file_header.size() + 4, 1)); - file_footer = first.substr(file_header.size() + 5); - break; + std::string all_directory_path = directory_path + return_dirctory_path(file_sort) + extension.substr(1) + '/'; + + if(file_sort.find("Ultra") != std::string::npos){ + std::string file_header, file_footer; + int gps_week, day; + int hour; + for(int i = 0;i < (int)first.size();++i){ + int n = first.at(i); + // Looking for the number of file name + if((int)'0' <= n && n < (int)('0' + 10)){ + file_header = first.substr(0, i); + gps_week = stoi(first.substr(file_header.size(), 4)); + day = stoi(first.substr(file_header.size() + 4, 1)); + hour = stoi(first.substr(file_header.size() + 6, 2)); + file_footer = first.substr(file_header.size() + 8); + break; + } } - } - file_contents.clear(); + file_contents.clear(); + + while(true){ + if(hour == 24){ + hour = 0; + ++day; + } + if(day == 7){ + ++gps_week; + day = 0; + } + std::string file_name = file_header + std::to_string(gps_week) + std::to_string(day) + "_"; + if(hour < 10){ + file_name += "0"; + } + file_name += std::to_string(hour) + file_footer; + file_contents.push_back(std::vector()); - while(true){ - if(day == 7){ - ++gps_week; - day = 0; + get_raw_contents(all_directory_path, file_name, file_contents.back()); + + if(file_name == last) break; + hour += 6; } - string file_name = file_header + to_string(gps_week) + to_string(day) + file_footer; - file_contents.push_back(vector()); + }else{ + std::string file_header, file_footer; + int gps_week, day; + for(int i = 0;i < (int)first.size();++i){ + int n = first.at(i); + // Looking for the number of file name + if((int)'0' <= n && n < (int)('0' + 10)){ + file_header = first.substr(0, i); + gps_week = stoi(first.substr(file_header.size(), 4)); + day = stoi(first.substr(file_header.size() + 4, 1)); + file_footer = first.substr(file_header.size() + 5); + break; + } + } + + file_contents.clear(); - get_raw_contents(all_directory_path, file_name, file_contents.back()); - - if(file_name == last) break; - ++day; + while(true){ + if(day == 7){ + ++gps_week; + day = 0; + } + std::string file_name = file_header + std::to_string(gps_week) + std::to_string(day) + file_footer; + file_contents.push_back(std::vector()); + + get_raw_contents(all_directory_path, file_name, file_contents.back()); + + if(file_name == last) break; + ++day; + } } return; } -GnssSatellites* InitGnssSatellites(string file_name) -{ +GnssSatellites* InitGnssSatellites(std::string file_name) +{ IniAccess ini_file(file_name); - char* section = "GNSS_SATELLIES"; + char section[] = "GNSS_SATELLIES"; GnssSatellites* gnss_satellites = new GnssSatellites(ini_file.ReadEnable(section, CALC_LABEL)); if(!gnss_satellites->IsCalcEnabled()){ return gnss_satellites; } - string directory_path = ini_file.ReadString(section, "directory_path"); + std::string directory_path = ini_file.ReadString(section, "directory_path"); - vector> true_position_file; - bool true_position_ur_flag = false; - get_sp3_file_contents(directory_path, - ini_file.ReadString(section, "true_position_file_sort"), + std::vector> true_position_file; + UR_KINDS true_position_ur_flag = UR_NOT_UR; + get_sp3_file_contents(directory_path, + ini_file.ReadString(section, "true_position_file_sort"), ini_file.ReadString(section, "true_position_first"), - ini_file.ReadString(section, "true_position_last"), true_position_file, true_position_ur_flag); + ini_file.ReadString(section, "true_position_last"), + true_position_file, + true_position_ur_flag); int true_position_interpolation_method = ini_file.ReadInt(section, "true_position_interpolation_method"); int true_position_interpolation_number = ini_file.ReadInt(section, "true_position_interpolation_number"); - vector> true_clock_file; - bool true_clock_ur_flag = false; - string true_clock_file_extension = ini_file.ReadString(section, "true_clock_file_extension"); + std::vector> true_clock_file; + UR_KINDS true_clock_ur_flag = UR_NOT_UR; + std::string true_clock_file_extension = ini_file.ReadString(section, "true_clock_file_extension"); if(true_clock_file_extension == ".sp3"){ - get_sp3_file_contents(directory_path, - ini_file.ReadString(section, "true_clock_file_sort"), + get_sp3_file_contents(directory_path, + ini_file.ReadString(section, "true_clock_file_sort"), ini_file.ReadString(section, "true_clock_first"), - ini_file.ReadString(section, "true_clock_last"), true_clock_file, true_clock_ur_flag); + ini_file.ReadString(section, "true_clock_last"), + true_clock_file, + true_clock_ur_flag); }else{ get_clk_file_contents(directory_path, true_clock_file_extension, @@ -239,23 +289,36 @@ GnssSatellites* InitGnssSatellites(string file_name) } int true_clock_interpolation_number = ini_file.ReadInt(section, "true_clock_interpolation_number"); - vector> estimate_position_file; - bool estimate_position_ur_flag = true; - get_sp3_file_contents(directory_path, - ini_file.ReadString(section, "estimate_position_file_sort"), + std::vector> estimate_position_file; + UR_KINDS estimate_position_ur_flag = UR_NOT_UR; + get_sp3_file_contents(directory_path, + ini_file.ReadString(section, "estimate_position_file_sort"), ini_file.ReadString(section, "estimate_position_first"), - ini_file.ReadString(section, "estimate_position_last"), estimate_position_file, estimate_position_ur_flag); + ini_file.ReadString(section, "estimate_position_last"), + estimate_position_file, + estimate_position_ur_flag); int estimate_position_interpolation_method = ini_file.ReadInt(section, "estimate_position_interpolation_method"); int estimate_position_interpolation_number = ini_file.ReadInt(section, "estimate_position_interpolation_number"); + if(estimate_position_ur_flag != UR_NOT_UR){ + std::string ur_flag = ini_file.ReadString(section, "estimate_ur_observe_or_predict"); + if(ur_flag.find("observe") != std::string::npos){ + estimate_position_ur_flag = (UR_KINDS)((int)UR_OBSERVE1 + (ur_flag.back() - '1')); + } + else{ + estimate_position_ur_flag = (UR_KINDS)((int)UR_PREDICT1 + (ur_flag.back() - '1')); + } + } - vector> estimate_clock_file; - bool estimate_clock_ur_flag = false; - string estimate_clock_file_extension = ini_file.ReadString(section, "estimate_clock_file_extension"); + std::vector> estimate_clock_file; + UR_KINDS estimate_clock_ur_flag = estimate_position_ur_flag; + std::string estimate_clock_file_extension = ini_file.ReadString(section, "estimate_clock_file_extension"); if(estimate_clock_file_extension == ".sp3"){ - get_sp3_file_contents(directory_path, - ini_file.ReadString(section, "estimate_clock_file_sort"), + get_sp3_file_contents(directory_path, + ini_file.ReadString(section, "estimate_clock_file_sort"), ini_file.ReadString(section, "estimate_clock_first"), - ini_file.ReadString(section, "estimate_clock_last"), estimate_clock_file, estimate_clock_ur_flag); + ini_file.ReadString(section, "estimate_clock_last"), + estimate_clock_file, + estimate_clock_ur_flag); }else{ get_clk_file_contents(directory_path, estimate_clock_file_extension, @@ -275,7 +338,7 @@ GnssSatellites* InitGnssSatellites(string file_name) true_clock_file_extension, true_clock_interpolation_number, true_clock_ur_flag, - + estimate_position_file, estimate_position_interpolation_method, estimate_position_interpolation_number, diff --git a/src/Interface/InitInput/Init_HipCatalogue.cpp b/src/Interface/InitInput/Init_HipCatalogue.cpp index f1d3d1655..4e2266b75 100644 --- a/src/Interface/InitInput/Init_HipCatalogue.cpp +++ b/src/Interface/InitInput/Init_HipCatalogue.cpp @@ -1,13 +1,13 @@ #include "Initialize.h" #include "../../Environment/Global/HipparcosCatalogue.h" -HipparcosCatalogue* InitHipCatalogue(string file_name) +HipparcosCatalogue* InitHipCatalogue(std::string file_name) { IniAccess ini_file(file_name); char* section = "HIPPARCOS_CATALOGUE"; double max_magnitude = ini_file.ReadDouble(section, "max_magnitude"); - string catalogue_path = ini_file.ReadString(section, "catalogue_path"); + std::string catalogue_path = ini_file.ReadString(section, "catalogue_path"); HipparcosCatalogue* hip_catalogue; hip_catalogue = new HipparcosCatalogue(max_magnitude, catalogue_path); @@ -16,4 +16,4 @@ HipparcosCatalogue* InitHipCatalogue(string file_name) hip_catalogue->ReadContents(catalogue_path, ','); return hip_catalogue; -} \ No newline at end of file +} diff --git a/src/Interface/InitInput/Init_Log.cpp b/src/Interface/InitInput/Init_Log.cpp index 9fef331f6..d60afd8e7 100644 --- a/src/Interface/InitInput/Init_Log.cpp +++ b/src/Interface/InitInput/Init_Log.cpp @@ -1,10 +1,10 @@ #include "Initialize.h" -Logger* InitLog(string file_name) +Logger* InitLog(std::string file_name) { IniAccess ini_file(file_name); - string log_file_path = ini_file.ReadString("SIM_SETTING", "log_file_path"); + std::string log_file_path = ini_file.ReadString("SIM_SETTING", "log_file_path"); bool log_ini = ini_file.ReadBoolean("SIM_SETTING", "log_inifile"); Logger* log = new Logger("default.csv", log_file_path, file_name, log_ini, true); @@ -12,14 +12,14 @@ Logger* InitLog(string file_name) return log; } -Logger* InitLogMC(string file_name, bool enable) +Logger* InitLogMC(std::string file_name, bool enable) { IniAccess ini_file(file_name); - string log_file_path = ini_file.ReadString("SIM_SETTING", "log_file_path"); + std::string log_file_path = ini_file.ReadString("SIM_SETTING", "log_file_path"); bool log_ini = ini_file.ReadBoolean("SIM_SETTING", "log_inifile"); Logger* log = new Logger("mont.csv", log_file_path, file_name, log_ini, enable); return log; -} \ No newline at end of file +} diff --git a/src/Interface/InitInput/Init_MCSim.cpp b/src/Interface/InitInput/Init_MCSim.cpp index 45b5e3d01..8568c08be 100644 --- a/src/Interface/InitInput/Init_MCSim.cpp +++ b/src/Interface/InitInput/Init_MCSim.cpp @@ -2,7 +2,7 @@ #include "../../Simulation/MCSim/MCSimExecutor.h" #include "../../Simulation/MCSim/InitParameter.h" -MCSimExecutor* InitMCSim(string file_name) +MCSimExecutor* InitMCSim(std::string file_name) { IniAccess ini_file(file_name); char* section = "MC_EXECUTION"; @@ -21,8 +21,8 @@ MCSimExecutor* InitMCSim(string file_name) mc_sim->LogHistory(log_history); section = "MC_RANDOMIZATION"; - vector so_dot_ip_str_vec = ini_file.ReadStrVector(section, "Param"); - vector so_str_vec, ip_str_vec; + std::vector so_dot_ip_str_vec = ini_file.ReadStrVector(section, "Param"); + std::vector so_str_vec, ip_str_vec; enum Phase{ FoundNothingYet, @@ -33,8 +33,8 @@ MCSimExecutor* InitMCSim(string file_name) { // 文字列をSimulationObjectとInitParameterに分割 Phase phase = FoundNothingYet; - stringstream ss(so_dot_ip_str); - string item, so_str, ip_str; + std::stringstream ss(so_dot_ip_str); + std::string item, so_str, ip_str; while (getline(ss, item, MCSimExecutor::separator_)) { if (!item.empty()) @@ -59,7 +59,7 @@ MCSimExecutor* InitMCSim(string file_name) InitParameter::RandomizationType rnd_type; const static unsigned int buf_size = 256; char rnd_type_str[buf_size]; - string key_name = so_dot_ip_str + MCSimExecutor::separator_ + "randomization_type"; + std::string key_name = so_dot_ip_str + MCSimExecutor::separator_ + "randomization_type"; ini_file.ReadChar(section, key_name.c_str(), buf_size, rnd_type_str); if (!strcmp(rnd_type_str, "NoRandomization")) rnd_type = InitParameter::NoRandomization; @@ -87,4 +87,4 @@ MCSimExecutor* InitMCSim(string file_name) } return mc_sim; -} \ No newline at end of file +} diff --git a/src/Interface/InitInput/Init_Orbit.cpp b/src/Interface/InitInput/Init_Orbit.cpp index 2dd52681b..7dbafe44d 100644 --- a/src/Interface/InitInput/Init_Orbit.cpp +++ b/src/Interface/InitInput/Init_Orbit.cpp @@ -12,7 +12,7 @@ class EarthCenteredOrbit; class SimpleCircularOrbit; class RelativeOrbit; -Orbit* InitOrbit(const CelestialInformation* celes_info, string ini_path, double stepSec, double current_jd, double gravity_constant, string section, RelativeInformation* rel_info) +Orbit* InitOrbit(const CelestialInformation* celes_info, std::string ini_path, double stepSec, double current_jd, double gravity_constant, std::string section, RelativeInformation* rel_info) { auto conf = IniAccess(ini_path); const char* section_ = section.c_str(); diff --git a/src/Interface/InitInput/Init_SimTime.cpp b/src/Interface/InitInput/Init_SimTime.cpp index 8e87f0f8f..4d638a6f8 100644 --- a/src/Interface/InitInput/Init_SimTime.cpp +++ b/src/Interface/InitInput/Init_SimTime.cpp @@ -1,7 +1,7 @@ #include "Initialize.h" #include "../../Environment/Global/SimTime.h" -SimTime* InitSimTime(string file_name) +SimTime* InitSimTime(std::string file_name) { IniAccess ini_file(file_name); @@ -9,7 +9,7 @@ SimTime* InitSimTime(string file_name) //Parameters about entire simulation double end_sec = ini_file.ReadDouble(section, "EndTimeSec"); double step_sec = ini_file.ReadDouble(section, "StepTimeSec"); - string start_ymdhms = ini_file.ReadString(section, "StartYMDHMS"); + std::string start_ymdhms = ini_file.ReadString(section, "StartYMDHMS"); double sim_speed = ini_file.ReadDouble(section, "SimulationSpeed"); //Time step parameters for dynamics propagation diff --git a/src/Interface/InitInput/Init_Structure.cpp b/src/Interface/InitInput/Init_Structure.cpp index be45ecd69..7f178456c 100644 --- a/src/Interface/InitInput/Init_Structure.cpp +++ b/src/Interface/InitInput/Init_Structure.cpp @@ -1,10 +1,11 @@ #include "Initialize.h" +#include "../../Library/math/Vector.hpp" #include"../../Simulation/Spacecraft/Structure/KinematicsParams.h" #include"../../Simulation/Spacecraft/Structure/Surface.h" #include"../../Simulation/Spacecraft/Structure/RMMParams.h" -#define MIN_VAL 1e-9 -KinematicsParams InitKinematicsParams(string ini_path) +#define MIN_VAL 1e-6 +KinematicsParams InitKinematicsParams(std::string ini_path) { auto conf = IniAccess(ini_path); char* section = "STRUCTURE"; @@ -27,8 +28,10 @@ KinematicsParams InitKinematicsParams(string ini_path) return kinematics_params; } -vector InitSurfaces(string ini_path) +vector InitSurfaces(std::string ini_path) { + using std::cout; + auto conf = IniAccess(ini_path); char* section = "SURFACES"; @@ -37,9 +40,9 @@ vector InitSurfaces(string ini_path) for (int i = 0; i < num_surface; i++) { - string idx = std::to_string(i); + std::string idx = std::to_string(i); idx = "_" + idx; - string keyword; + std::string keyword; keyword = "area" + idx; double area = conf.ReadDouble(section, keyword.c_str()); @@ -96,8 +99,9 @@ vector InitSurfaces(string ini_path) conf.ReadVector(section, keyword.c_str(), normal); if (norm(normal) > 1.0 + MIN_VAL) //Fixme: magic word { - cout << "Surface Error! " << keyword << ": norm is larger than 1.0\n"; - break; + cout << "Surface Warning! " << keyword << ": norm is larger than 1.0."; + cout << "The vector is normalized.\n"; + normal = normalize(normal); } //Add a surface @@ -107,7 +111,7 @@ vector InitSurfaces(string ini_path) } -RMMParams InitRMMParams(string ini_path) +RMMParams InitRMMParams(std::string ini_path) { auto conf = IniAccess(ini_path); char* section = "RMM"; @@ -120,4 +124,4 @@ RMMParams InitRMMParams(string ini_path) RMMParams rmm_params(rmm_const_b, rmm_rwdev, rmm_rwlimit, rmm_wnvar); return rmm_params; -} \ No newline at end of file +} diff --git a/src/Interface/InitInput/Initialize.h b/src/Interface/InitInput/Initialize.h index f5fdcb489..c59df2e44 100644 --- a/src/Interface/InitInput/Initialize.h +++ b/src/Interface/InitInput/Initialize.h @@ -1,6 +1,9 @@ #ifndef __Initialize_H__ #define __Initialize_H__ +#include +#include + #include "IniAccess.h" #define MAX_CHAR_NUM 256 #define CALC_LABEL "calculation" @@ -14,23 +17,22 @@ #include "../../Simulation/Spacecraft/Structure/Structure.h" #include "../SpacecraftInOut/Ports/PowerPort.h" -#include using libra::Matrix; using libra::Vector; using libra::Quaternion; //Logger class Logger; -Logger* InitLog(string file_name); -Logger* InitLogMC(string file_name, bool enable); +Logger* InitLog(std::string file_name); +Logger* InitLogMC(std::string file_name, bool enable); //Structure class KinematicsParams; class Surface; class RMMParams; -KinematicsParams InitKinematicsParams(string ini_path); -vector InitSurfaces(string ini_path); -RMMParams InitRMMParams(string ini_path); +KinematicsParams InitKinematicsParams(std::string ini_path); +vector InitSurfaces(std::string ini_path); +RMMParams InitRMMParams(std::string ini_path); //Global Environment @@ -39,10 +41,10 @@ class ClockGenerator; class CelestialInformation; class HipparcosCatalogue; class GnssSatellites; -SimTime* InitSimTime(string file_name); -CelestialInformation* InitCelesInfo(string file_name); -HipparcosCatalogue* InitHipCatalogue(string file_name); -GnssSatellites* InitGnssSatellites(string file_name); +SimTime* InitSimTime(std::string file_name); +CelestialInformation* InitCelesInfo(std::string file_name); +HipparcosCatalogue* InitHipCatalogue(std::string file_name); +GnssSatellites* InitGnssSatellites(std::string file_name); //Local Environment class MagEnvironment; @@ -50,9 +52,9 @@ class SRPEnvironment; class Atmosphere; class LocalCelestialInformation; class LocalEnvironment; -MagEnvironment InitMagEnvironment(string ini_path); -SRPEnvironment InitSRPEnvironment(string ini_path); -Atmosphere InitAtmosphere(string ini_path); +MagEnvironment InitMagEnvironment(std::string ini_path); +SRPEnvironment InitSRPEnvironment(std::string ini_path); +Atmosphere InitAtmosphere(std::string ini_path); //Dynamics class Dynamics; @@ -61,10 +63,10 @@ class Orbit; class Temperature; class Node; class RelativeInformation; -Attitude* InitAttitude(string file_name, const Orbit* orbit, const LocalCelestialInformation* celes_info, const double step_sec, const Matrix<3, 3> inertia_tensor, const int sat_id); -Orbit* InitOrbit(const CelestialInformation* celes_info, string ini_path, double stepSec, double current_jd, double gravity_constant, string section = "ORBIT", RelativeInformation* rel_info = (RelativeInformation*)nullptr); -Temperature* InitTemperature(string ini_path, const double rk_prop_step_sec); -Node InitNode(const vector& nodestr); +Attitude* InitAttitude(std::string file_name, const Orbit* orbit, const LocalCelestialInformation* celes_info, const double step_sec, const Matrix<3, 3> inertia_tensor, const int sat_id); +Orbit* InitOrbit(const CelestialInformation* celes_info, std::string ini_path, double stepSec, double current_jd, double gravity_constant, std::string section = "ORBIT", RelativeInformation* rel_info = (RelativeInformation*)nullptr); +Temperature* InitTemperature(std::string ini_path, const double rk_prop_step_sec); +Node InitNode(const vector& nodestr); //Disturbance class RMMParams; @@ -74,12 +76,12 @@ class GGDist; class MagDisturbance; class GeoPotential; class ThirdBodyGravity; -AirDrag InitAirDrag(string ini_path, const vector& surfaces, const Vector<3> cg_b); -SolarRadiation InitSRDist(string ini_path, const vector& surfaces, Vector<3> cg_b); -GGDist InitGGDist(string ini_path); -MagDisturbance InitMagDisturbance(string ini_path, RMMParams rmm_params); -GeoPotential InitGeoPotential(string ini_path); -ThirdBodyGravity InitThirdBodyGravity(string ini_path, string ini_path_celes); +AirDrag InitAirDrag(std::string ini_path, const vector& surfaces, const Vector<3> cg_b); +SolarRadiation InitSRDist(std::string ini_path, const vector& surfaces, Vector<3> cg_b); +GGDist InitGGDist(std::string ini_path); +MagDisturbance InitMagDisturbance(std::string ini_path, RMMParams rmm_params); +GeoPotential InitGeoPotential(std::string ini_path); +ThirdBodyGravity InitThirdBodyGravity(std::string ini_path, std::string ini_path_celes); //Component class Gyro; @@ -97,38 +99,38 @@ class GScalculator; class Telescope; class STT; class GNSSReceiver; -Gyro InitGyro(ClockGenerator* clock_gen, int sensor_id, const string fname, double compo_step_time, const Dynamics* dynamics); -Gyro InitGyro(ClockGenerator* clock_gen, PowerPort* power_port, int sensor_id, const string fname, double compo_step_time, const Dynamics* dynamics); -MagSensor InitMagSensor(ClockGenerator* clock_gen, int sensor_id, const string fname, double compo_step_time, const MagEnvironment* magnet); -MagSensor InitMagSensor(ClockGenerator* clock_gen, PowerPort* power_port, int sensor_id, const string fname, double compo_step_time, const MagEnvironment* magnet); -MagTorquer InitMagTorquer(ClockGenerator* clock_gen, int actuator_id, const string fname, double compo_step_time, const MagEnvironment* mag_env); -MagTorquer InitMagTorquer(ClockGenerator* clock_gen, PowerPort* power_port, int actuator_id, const string fname, double compo_step_time, const MagEnvironment* mag_env); -RWModel InitRWModel(ClockGenerator* clock_gen, int actuator_id, string file_name, double prop_step, double compo_update_step); -RWModel InitRWModel(ClockGenerator* clock_gen, PowerPort* power_port, int actuator_id, string file_name, double prop_step, double compo_update_step); -STT InitSTT(ClockGenerator* clock_gen, int sensor_id, const string fname, double compo_step_time, const Dynamics *dynamics, const LocalEnvironment* local_env); -STT InitSTT(ClockGenerator* clock_gen, PowerPort* power_port, int sensor_id, const string fname, double compo_step_time, const Dynamics *dynamics, const LocalEnvironment* local_env); -SunSensor InitSunSensor(ClockGenerator* clock_gen, int sensor_id, const string fname, const SRPEnvironment* srp); -SunSensor InitSunSensor(ClockGenerator* clock_gen, PowerPort* power_port, int sensor_id, const string fname, const SRPEnvironment* srp); -GNSSReceiver InitGNSSReceiver(ClockGenerator* clock_gen, int id, const string fname, const Dynamics* dynamics, const GnssSatellites* gnss_satellites, const SimTime* simtime); -GNSSReceiver InitGNSSReceiver(ClockGenerator* clock_gen, PowerPort* power_port, int id, const string fname, const Dynamics* dynamics, const GnssSatellites* gnss_satellites, const SimTime* simtime); -SimpleThruster InitSimpleThruster(ClockGenerator* clock_gen, int thruster_id, const string fname, const Structure* structure, const Dynamics* dynamics); -SimpleThruster InitSimpleThruster(ClockGenerator* clock_gen, PowerPort* power_port, int thruster_id, const string fname, const Structure* structure, const Dynamics* dynamics); +Gyro InitGyro(ClockGenerator* clock_gen, int sensor_id, const std::string fname, double compo_step_time, const Dynamics* dynamics); +Gyro InitGyro(ClockGenerator* clock_gen, PowerPort* power_port, int sensor_id, const std::string fname, double compo_step_time, const Dynamics* dynamics); +MagSensor InitMagSensor(ClockGenerator* clock_gen, int sensor_id, const std::string fname, double compo_step_time, const MagEnvironment* magnet); +MagSensor InitMagSensor(ClockGenerator* clock_gen, PowerPort* power_port, int sensor_id, const std::string fname, double compo_step_time, const MagEnvironment* magnet); +MagTorquer InitMagTorquer(ClockGenerator* clock_gen, int actuator_id, const std::string fname, double compo_step_time, const MagEnvironment* mag_env); +MagTorquer InitMagTorquer(ClockGenerator* clock_gen, PowerPort* power_port, int actuator_id, const std::string fname, double compo_step_time, const MagEnvironment* mag_env); +RWModel InitRWModel(ClockGenerator* clock_gen, int actuator_id, std::string file_name, double prop_step, double compo_update_step); +RWModel InitRWModel(ClockGenerator* clock_gen, PowerPort* power_port, int actuator_id, std::string file_name, double prop_step, double compo_update_step); +STT InitSTT(ClockGenerator* clock_gen, int sensor_id, const std::string fname, double compo_step_time, const Dynamics *dynamics, const LocalEnvironment* local_env); +STT InitSTT(ClockGenerator* clock_gen, PowerPort* power_port, int sensor_id, const std::string fname, double compo_step_time, const Dynamics *dynamics, const LocalEnvironment* local_env); +SunSensor InitSunSensor(ClockGenerator* clock_gen, int sensor_id, const std::string fname, const SRPEnvironment* srp); +SunSensor InitSunSensor(ClockGenerator* clock_gen, PowerPort* power_port, int sensor_id, const std::string fname, const SRPEnvironment* srp); +GNSSReceiver InitGNSSReceiver(ClockGenerator* clock_gen, int id, const std::string fname, const Dynamics* dynamics, const GnssSatellites* gnss_satellites, const SimTime* simtime); +GNSSReceiver InitGNSSReceiver(ClockGenerator* clock_gen, PowerPort* power_port, int id, const std::string fname, const Dynamics* dynamics, const GnssSatellites* gnss_satellites, const SimTime* simtime); +SimpleThruster InitSimpleThruster(ClockGenerator* clock_gen, int thruster_id, const std::string fname, const Structure* structure, const Dynamics* dynamics); +SimpleThruster InitSimpleThruster(ClockGenerator* clock_gen, PowerPort* power_port, int thruster_id, const std::string fname, const Structure* structure, const Dynamics* dynamics); -BAT InitBAT(ClockGenerator* clock_gen, int bat_id, const string fname); -SAP InitSAP(ClockGenerator* clock_gen, int sap_id, const string fname, const SRPEnvironment* srp); +BAT InitBAT(ClockGenerator* clock_gen, int bat_id, const std::string fname); +SAP InitSAP(ClockGenerator* clock_gen, int sap_id, const std::string fname, const SRPEnvironment* srp); EMDS InitEMDS(int actuator_id); UWBSensor InitUWBSensor(int sensor_id); -ANT InitANT(int ant_id, const string fname); -GScalculator InitGScalculator(const string fname); -Telescope InitTelescope(ClockGenerator* clock_gen, int sensor_id, const string fname, const Attitude * attitude, const HipparcosCatalogue* hipp, const LocalCelestialInformation *local_celes_info); +ANT InitANT(int ant_id, const std::string fname); +GScalculator InitGScalculator(const std::string fname); +Telescope InitTelescope(ClockGenerator* clock_gen, int sensor_id, const std::string fname, const Attitude * attitude, const HipparcosCatalogue* hipp, const LocalCelestialInformation *local_celes_info); //MCSim class MCSimExecutor; -MCSimExecutor* InitMCSim(string file_name); +MCSimExecutor* InitMCSim(std::string file_name); /* // HILS class HardwareMessage; -HardwareMessage* Init_HardwareMessage(string file_name); +HardwareMessage* Init_HardwareMessage(std::string file_name); class COSMOSWrapper; -COSMOSWrapper* Init_COSMOSWrapper(string file_name); +COSMOSWrapper* Init_COSMOSWrapper(std::string file_name); */ #endif //__Initialize_H__ diff --git a/src/Interface/LogOutput/ILoggable.h b/src/Interface/LogOutput/ILoggable.h index 36a790959..46d9e34cb 100644 --- a/src/Interface/LogOutput/ILoggable.h +++ b/src/Interface/LogOutput/ILoggable.h @@ -1,7 +1,6 @@ #pragma once #include -using namespace std; // 必要ないが、利便性のためにinclude #include "LogUtility.h" @@ -14,10 +13,10 @@ class ILoggable // 抽象クラスとします 多重継承してください public: // csvのヘッダー行の文字列を取得する - virtual string GetLogHeader() const = 0; + virtual std::string GetLogHeader() const = 0; // csvの値行の文字列を取得する - virtual string GetLogValue() const = 0; + virtual std::string GetLogValue() const = 0; bool IsLogEnabled = true; }; diff --git a/src/Interface/LogOutput/LogUtility.h b/src/Interface/LogOutput/LogUtility.h index 5885491ac..4388323ca 100644 --- a/src/Interface/LogOutput/LogUtility.h +++ b/src/Interface/LogOutput/LogUtility.h @@ -4,8 +4,6 @@ #include #include -using namespace std; - #include "../../Library/math/MatVec.hpp" #include "../../Library/math/Quaternion.hpp" using libra::Matrix; @@ -13,47 +11,47 @@ using libra::Vector; using libra::Quaternion; template -inline string WriteScalar(T scalar, int precision=6); -inline string WriteScalar(string name, string unit); +inline std::string WriteScalar(T scalar, int precision=6); +inline std::string WriteScalar(std::string name, std::string unit); template -inline string WriteVector(Vector vec, int precision=6); -inline string WriteVector(string name, string frame, string unit, int n); +inline std::string WriteVector(Vector vec, int precision=6); +inline std::string WriteVector(std::string name, std::string frame, std::string unit, int n); template -inline string WriteMatrix(Matrix mat); -inline string WriteMatrix(string name, string frame, string unit, int r, int c); +inline std::string WriteMatrix(Matrix mat); +inline std::string WriteMatrix(std::string name, std::string frame, std::string unit, int r, int c); -inline string WriteQuaternion(Quaternion quat); +inline std::string WriteQuaternion(Quaternion quat); //Libraries for log writing template -string WriteScalar(T scalar, int precision) +std::string WriteScalar(T scalar, int precision) { - stringstream str_tmp; - str_tmp << setprecision(precision) << scalar << ","; + std::stringstream str_tmp; + str_tmp << std::setprecision(precision) << scalar << ","; return str_tmp.str(); } -string WriteScalar(string name, string unit) +std::string WriteScalar(std::string name, std::string unit) { return name + "[" + unit + "],"; } template -string WriteVector(Vector vec, int precision) +std::string WriteVector(Vector vec, int precision) { - stringstream str_tmp; + std::stringstream str_tmp; for (int n = 0; n < NUM; n++) { - str_tmp << setprecision(precision) << vec[n] << ","; + str_tmp << std::setprecision(precision) << vec[n] << ","; } return str_tmp.str(); } -string WriteVector(string name, string frame, string unit, int n) +std::string WriteVector(std::string name, std::string frame, std::string unit, int n) { - stringstream str_tmp; - string axis[3] = { "(X)", "(Y)", "(Z)" }; + std::stringstream str_tmp; + std::string axis[3] = { "(X)", "(Y)", "(Z)" }; for (int i = 0; i < n; i++) @@ -71,9 +69,9 @@ string WriteVector(string name, string frame, string unit, int n) } template -string WriteMatrix(Matrix mat) +std::string WriteMatrix(Matrix mat) { - stringstream str_tmp; + std::stringstream str_tmp; for (int n = 0; n < ROW; n++) { @@ -84,9 +82,9 @@ string WriteMatrix(Matrix mat) } return str_tmp.str(); } -string WriteMatrix(string name, string frame, string unit, int r, int c) +std::string WriteMatrix(std::string name, std::string frame, std::string unit, int r, int c) { - stringstream str_tmp; + std::stringstream str_tmp; for (int i = 0; i < r; i++) { @@ -98,9 +96,9 @@ string WriteMatrix(string name, string frame, string unit, int r, int c) return str_tmp.str(); } -string WriteQuaternion(Quaternion quat) +std::string WriteQuaternion(Quaternion quat) { - stringstream str_tmp; + std::stringstream str_tmp; for (int i = 0; i < 4; i++) { diff --git a/src/Interface/LogOutput/Logger.cpp b/src/Interface/LogOutput/Logger.cpp index 65ed7903d..844a17964 100644 --- a/src/Interface/LogOutput/Logger.cpp +++ b/src/Interface/LogOutput/Logger.cpp @@ -7,9 +7,9 @@ #include #endif -vector loggables_; +std::vector loggables_; -Logger::Logger(const string &file_name,const string &data_path, const string &ini_file_name, const bool enable_inilog, bool enable) +Logger::Logger(const std::string &file_name,const std::string &data_path, const std::string &ini_file_name, const bool enable_inilog, bool enable) { is_enabled_ = enable; is_open_ = false; @@ -26,7 +26,7 @@ Logger::Logger(const string &file_name,const string &data_path, const string &in if(is_enabled_inilog_ == true) directory_path_ = CreateDirectory(data_path, start_time_c); else directory_path_ = data_path; // Create File - stringstream file_path; + std::stringstream file_path; file_path << directory_path_ << start_time_c << "_" << file_name; if (is_enabled_) { @@ -72,7 +72,7 @@ void Logger::WriteNewLine() Write("\n"); } -void Logger::Write(string log, bool flag) +void Logger::Write(std::string log, bool flag) { if (flag && is_enabled_) { @@ -90,9 +90,9 @@ void Logger::ClearLoggables() loggables_.clear(); } -string Logger::CreateDirectory(const string &data_path, const string & time) +std::string Logger::CreateDirectory(const std::string &data_path, const std::string & time) { - string directory_path_tmp_ = data_path + "/logs_" + time + "/"; + std::string directory_path_tmp_ = data_path + "/logs_" + time + "/"; //Make directory int rtn_mkdir = 0; #ifdef WIN32 @@ -109,32 +109,34 @@ string Logger::CreateDirectory(const string &data_path, const string & time) return directory_path_tmp_; } -void Logger::CopyFileToLogDir(const string &ini_file_name) +void Logger::CopyFileToLogDir(const std::string &ini_file_name) { + using std::ios; + if(is_enabled_inilog_ == false) return; //Copy files to the directory - string file_name = GetFileName(ini_file_name); - string to_file_name = directory_path_ + file_name; - ifstream is(ini_file_name, ios::in | ios::binary); - ofstream os(to_file_name, ios::out | ios::binary); + std::string file_name = GetFileName(ini_file_name); + std::string to_file_name = directory_path_ + file_name; + std::ifstream is(ini_file_name, ios::in | ios::binary); + std::ofstream os(to_file_name, ios::out | ios::binary); os << is.rdbuf(); return; } -string Logger::GetFileName(const string &path) +std::string Logger::GetFileName(const std::string &path) { size_t pos1; pos1 = path.rfind('\\'); - if (pos1 != string::npos) { + if (pos1 != std::string::npos) { return path.substr(pos1 + 1, path.size() - pos1 - 1); } pos1 = path.rfind('/'); - if (pos1 != string::npos) { + if (pos1 != std::string::npos) { return path.substr(pos1 + 1, path.size() - pos1 - 1); } return path; -} \ No newline at end of file +} diff --git a/src/Interface/LogOutput/Logger.h b/src/Interface/LogOutput/Logger.h index b981c3a0d..a9de2c2c3 100644 --- a/src/Interface/LogOutput/Logger.h +++ b/src/Interface/LogOutput/Logger.h @@ -2,8 +2,6 @@ #define __LOGGER_H__ #define _CRT_SECURE_NO_WARNINGS -using namespace std; - #include #include #include @@ -13,10 +11,10 @@ using namespace std; class Logger { public: - Logger(const string &file_name, const string &data_path, const string &ini_file_name, const bool enable_inilog, bool enable = true); + Logger(const std::string &file_name, const std::string &data_path, const std::string &ini_file_name, const bool enable_inilog, bool enable = true); ~Logger(void); - void Write(string log, bool flag = true); + void Write(std::string log, bool flag = true); void AddLoggable(ILoggable* loggable); void ClearLoggables(); void WriteHeaders(bool add_newline = true); @@ -24,21 +22,21 @@ class Logger void WriteNewLine(); inline bool IsEnabled(); inline void Enable(bool enable); - void CopyFileToLogDir(const string &ini_file_name); - inline string GetLogPath() const; + void CopyFileToLogDir(const std::string &ini_file_name); + inline std::string GetLogPath() const; private: - ofstream csv_file_; + std::ofstream csv_file_; char registered_num_; bool is_enabled_; bool is_open_; - vector loggables_; + std::vector loggables_; bool is_enabled_inilog_; bool is_success_make_dir_ = false; - string directory_path_; - string CreateDirectory(const string &data_path, const string & time); - string GetFileName(const string &path); + std::string directory_path_; + std::string CreateDirectory(const std::string &data_path, const std::string & time); + std::string GetFileName(const std::string &path); }; bool Logger::IsEnabled() @@ -51,7 +49,7 @@ void Logger::Enable(bool enable) is_enabled_ = enable; } -string Logger::GetLogPath() const +std::string Logger::GetLogPath() const { return directory_path_; } diff --git a/src/Library/nrlmsise00/Wrapper_nrlmsise00.cpp b/src/Library/nrlmsise00/Wrapper_nrlmsise00.cpp index 94f58e83b..88e12cecf 100644 --- a/src/Library/nrlmsise00/Wrapper_nrlmsise00.cpp +++ b/src/Library/nrlmsise00/Wrapper_nrlmsise00.cpp @@ -185,7 +185,8 @@ int ConvertMonthStrToMonthNum(string month_str) /* --------------------------CalcNRLMSISE00--------------------------- */ /* ------------------------------------------------------------------- */ /* GTD7 Wrapper */ -double CalcNRLMSISE00(double decyear, double latrad, double lonrad, double alt, const vector& table) +double CalcNRLMSISE00(double decyear, double latrad, double lonrad, double alt, const vector& table, + bool is_manual_param, double manual_f107, double manual_f107a, double manual_ap) { struct nrlmsise_output output; struct nrlmsise_input input; @@ -209,37 +210,45 @@ double CalcNRLMSISE00(double decyear, double latrad, double lonrad, double alt, input.g_long = lonrad * RAD2DEG; input.lst = input.sec / 3600.0 + lonrad * RAD2DEG / 15.0; - // f10.7 and ap from table - - // テーブルサイズが0なら,0を返して終了 - if (table.size() == 0) { return 0.0; } - - // search table index - for (i = 0; i < table.size(); i++) + if (is_manual_param) { - if (decyear < decyear_monthly) + input.f107 = manual_f107; + input.f107A = manual_f107a; + input.ap = manual_ap; + } + else + { + // f10.7 and ap from table + // テーブルサイズが0なら,0を返して終了 + if (table.size() == 0) { return 0.0; } + + // search table index + for (i = 0; i < table.size(); i++) { - // 年月日が一致 - if ((date[0] == table[i].year) && (date[1] == table[i].month) && (date[2] == table[i].day)) + if (decyear < decyear_monthly) { - idx = i; - break; + // 年月日が一致 + if ((date[0] == table[i].year) && (date[1] == table[i].month) && (date[2] == table[i].day)) + { + idx = i; + break; + } } - } - else - { - // 年月が一致 - if ((date[0] == table[i].year) && (date[1] == table[i].month)) + else { - idx = i; - break; + // 年月が一致 + if ((date[0] == table[i].year) && (date[1] == table[i].month)) + { + idx = i; + break; + } } } - } - input.f107A = table[idx].Ctr81_adj; - input.f107 = table[idx].F107_adj; - input.ap = table[idx].Ap_avg; + input.f107A = table[idx].Ctr81_adj; + input.f107 = table[idx].F107_adj; + input.ap = table[idx].Ap_avg; + } for (i = 0; i < 7; i++) { aph.a[i] = input.ap; } input.ap_a = &aph; @@ -306,15 +315,16 @@ int GetSpaceWeatherTable_(double decyear, double endsec, const string& filename, int month = atoi(line.substr(5, 2).c_str()); int day = atoi(line.substr(8, 2).c_str()); double decyear_line = ConvertDateToDecyear(year, month, day); - double decyear_ini_ymd = ConvertDateToDecyear(date_ini[0], date_ini[1], date_ini[2]); + // 少なくとも1カ月分はデータを確保するため,シミュレーション開始時刻の一ヶ月前からテーブル値を確保する + double decyear_ini_ymd = ConvertDateToDecyear(date_ini[0], date_ini[1], date_ini[2]) - 31.0 / 365.0; // 一ヶ月引く double decyear_end_ymd = ConvertDateToDecyear(date_end[0], date_end[1], date_end[2]); if (decyear_line < decyear_ini_ymd || decyear_line > decyear_end_ymd) continue; // Read table data - line_data.year = atoi(year_str.c_str()); - line_data.month = atoi(line.substr(5, 2).c_str()); - line_data.day = atoi(line.substr(8, 2).c_str()); + line_data.year = year; + line_data.month = month; + line_data.day = day; line_data.Ap_avg = atof(line.substr(80, 3).c_str()); line_data.F107_adj = atof(line.substr(93, 5).c_str()); line_data.Ctr81_adj = atof(line.substr(101, 5).c_str()); @@ -326,5 +336,5 @@ int GetSpaceWeatherTable_(double decyear, double endsec, const string& filename, table.push_back(line_data); } - return 1; + return table.size(); } diff --git a/src/Library/nrlmsise00/Wrapper_nrlmsise00.h b/src/Library/nrlmsise00/Wrapper_nrlmsise00.h index 2ab21d257..0cb99ac65 100644 --- a/src/Library/nrlmsise00/Wrapper_nrlmsise00.h +++ b/src/Library/nrlmsise00/Wrapper_nrlmsise00.h @@ -27,7 +27,8 @@ struct nrlmsise_table { /* CalcNRLMSISE00 */ /* GTD7 Wrapper */ -double CalcNRLMSISE00(double decyear, double latrad, double lonrad, double alt, const std::vector& table); +double CalcNRLMSISE00(double decyear, double latrad, double lonrad, double alt, const std::vector& table, + bool is_manual_param, double manual_f107, double manual_f107a, double manual_ap); /* GetSpaceWeatherTable_*/ int GetSpaceWeatherTable_(double decyear, double endsec, const std::string& filename, std::vector& table); diff --git a/src/RelativeInformation/RelativeInformation.cpp b/src/RelativeInformation/RelativeInformation.cpp index c925367a2..0f74ce565 100644 --- a/src/RelativeInformation/RelativeInformation.cpp +++ b/src/RelativeInformation/RelativeInformation.cpp @@ -44,14 +44,14 @@ const libra::Vector<3> RelativeInformation::GetRelativeVelocity_i(const int targ return target_sat_vel_i - reference_sat_vel_i; } -string RelativeInformation::GetLogHeader() const +std::string RelativeInformation::GetLogHeader() const { - string str_tmp = ""; + std::string str_tmp = ""; for (int target_sat_id = 0; target_sat_id < dynamics_database_.size(); target_sat_id++) { for (int reference_sat_id = 0; reference_sat_id < target_sat_id; reference_sat_id++) { - str_tmp += WriteVector("sat" + to_string(target_sat_id) + " pos from sat" + to_string(reference_sat_id), "i", "m", 3); + str_tmp += WriteVector("sat" + std::to_string(target_sat_id) + " pos from sat" + std::to_string(reference_sat_id), "i", "m", 3); } } @@ -59,15 +59,15 @@ string RelativeInformation::GetLogHeader() const { for (int reference_sat_id = 0; reference_sat_id < target_sat_id; reference_sat_id++) { - str_tmp += WriteVector("sat" + to_string(target_sat_id) + " velocity from sat" + to_string(reference_sat_id), "i", "m", 3); + str_tmp += WriteVector("sat" + std::to_string(target_sat_id) + " velocity from sat" + std::to_string(reference_sat_id), "i", "m", 3); } } return str_tmp; } -string RelativeInformation::GetLogValue() const +std::string RelativeInformation::GetLogValue() const { - string str_tmp = ""; + std::string str_tmp = ""; for (int target_sat_id = 0; target_sat_id < dynamics_database_.size(); target_sat_id++) { for (int reference_sat_id = 0; reference_sat_id < target_sat_id; reference_sat_id++) diff --git a/src/RelativeInformation/RelativeInformation.h b/src/RelativeInformation/RelativeInformation.h index 7826184a4..5526c87ed 100644 --- a/src/RelativeInformation/RelativeInformation.h +++ b/src/RelativeInformation/RelativeInformation.h @@ -1,4 +1,6 @@ #pragma once +#include + #include "../Interface/LogOutput/ILoggable.h" #include "../Interface/LogOutput/Logger.h" #include "../Dynamics/Dynamics.h" @@ -8,8 +10,8 @@ class RelativeInformation : public ILoggable public: RelativeInformation(); ~RelativeInformation(); - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; void LogSetup(Logger& logger); void RegisterDynamicsInfo(const int sat_id, const Dynamics* dynamics); void RemoveDynamicsInfo(const int sat_id); diff --git a/src/S2E.cpp b/src/S2E.cpp index a0310bc6f..d09677ca9 100644 --- a/src/S2E.cpp +++ b/src/S2E.cpp @@ -37,8 +37,10 @@ int main(int argc, _TCHAR* argv[]) int main(int argc, char* argv[]) #endif { - chrono::system_clock::time_point start, end; - start = chrono::system_clock::now(); + using namespace std::chrono; + + system_clock::time_point start, end; + start = system_clock::now(); std::string data_path = "../../data/"; // 必要なくなった? std::string ini_file = "../../data/SampleSat/ini/SampleSimBase.ini"; @@ -65,8 +67,8 @@ int main(int argc, char* argv[]) simcase.Initialize(); simcase.Main(); - end = chrono::system_clock::now(); - double time = static_cast(chrono::duration_cast(end - start).count() / 1000000.0); + end = system_clock::now(); + double time = static_cast(duration_cast(end - start).count() / 1000000.0); std::cout << std::endl << "Simulation execution time: " << time << "sec"<< std::endl << std::endl; return EXIT_SUCCESS; diff --git a/src/Simulation/Case/SampleCase.cpp b/src/Simulation/Case/SampleCase.cpp index 8bd224dc0..4effb7bf3 100644 --- a/src/Simulation/Case/SampleCase.cpp +++ b/src/Simulation/Case/SampleCase.cpp @@ -3,6 +3,9 @@ #include "../../Interface/InitInput/Initialize.h" #include "../Spacecraft/SampleSpacecraft/SampleSat.h" +using std::string; +using std::cout; + SampleCase::SampleCase(string ini_base):SimulationCase(ini_base) { } @@ -45,7 +48,6 @@ void SampleCase::Main() // Global Environment Update glo_env_->Update(); // Spacecraft Update - sample_sat_->Clear(); //Zero clear force and torque for dynamics sample_sat_->Update(&(glo_env_->GetSimTime())); // Debug output if (glo_env_->GetSimTime().GetState().disp_output) diff --git a/src/Simulation/Case/SampleCase.h b/src/Simulation/Case/SampleCase.h index 585ff733b..c4307a77e 100644 --- a/src/Simulation/Case/SampleCase.h +++ b/src/Simulation/Case/SampleCase.h @@ -6,15 +6,15 @@ class SampleCase : public SimulationCase { public: - SampleCase(string ini_base); + SampleCase(std::string ini_base); virtual ~SampleCase(); void Initialize(); void Main(); // Log for Monte Carlo Simulation - virtual string GetLogHeader() const; - virtual string GetLogValue() const; + virtual std::string GetLogHeader() const; + virtual std::string GetLogValue() const; private: SampleSat* sample_sat_; diff --git a/src/Simulation/Case/SimulationCase.cpp b/src/Simulation/Case/SimulationCase.cpp index 47c1c8903..f20b83ea0 100644 --- a/src/Simulation/Case/SimulationCase.cpp +++ b/src/Simulation/Case/SimulationCase.cpp @@ -1,7 +1,9 @@ +#include + #include "SimulationCase.h" #include "../../Interface/InitInput/Initialize.h" -SimulationCase::SimulationCase(string ini_base) +SimulationCase::SimulationCase(std::string ini_base) { IniAccess simbase_ini = IniAccess(ini_base); char* section = "SIM_SETTING"; @@ -14,13 +16,13 @@ SimulationCase::SimulationCase(string ini_base) sim_config_.gnss_file_ = simbase_ini.ReadString(section, "gnss_file"); glo_env_ = new GlobalEnvironment(&sim_config_); } -SimulationCase::SimulationCase(string ini_base, const MCSimExecutor& mc_sim, const string log_path) +SimulationCase::SimulationCase(std::string ini_base, const MCSimExecutor& mc_sim, const std::string log_path) { IniAccess simbase_ini = IniAccess(ini_base); char* section = "SIM_SETTING"; sim_config_.ini_base_fname_ = ini_base; //Log for Monte Carlo Simulation - string log_file_name = "default" + to_string(mc_sim.GetNumOfExecutionsDone()) + ".csv"; + std::string log_file_name = "default" + std::to_string(mc_sim.GetNumOfExecutionsDone()) + ".csv"; //ToDo: Consider that `enable_inilog = false` is fine or not? sim_config_.main_logger_ = new Logger(log_file_name, log_path, ini_base, false, mc_sim.LogHistory()); sim_config_.num_of_simulated_spacecraft_ = simbase_ini.ReadInt(section, "num_of_simulated_spacecraft"); @@ -35,4 +37,3 @@ SimulationCase::~SimulationCase() { delete glo_env_; } - \ No newline at end of file diff --git a/src/Simulation/Case/SimulationCase.h b/src/Simulation/Case/SimulationCase.h index da61b7887..be6b5a242 100644 --- a/src/Simulation/Case/SimulationCase.h +++ b/src/Simulation/Case/SimulationCase.h @@ -8,15 +8,15 @@ class Logger; class SimulationCase : public ILoggable { public: - SimulationCase(string ini_base); - SimulationCase(string ini_base, const MCSimExecutor& mc_sim, string log_path); //For MonteCarlo + SimulationCase(std::string ini_base); + SimulationCase(std::string ini_base, const MCSimExecutor& mc_sim, std::string log_path); //For MonteCarlo virtual ~SimulationCase(); virtual void Initialize() = 0; virtual void Main() = 0; - virtual string GetLogHeader() const = 0; - virtual string GetLogValue() const = 0; + virtual std::string GetLogHeader() const = 0; + virtual std::string GetLogValue() const = 0; //Get inline SimulationConfig& GetSimConfig(){return sim_config_;} diff --git a/src/Simulation/GroundStation/GroundStation.cpp b/src/Simulation/GroundStation/GroundStation.cpp index d894c983d..74a437306 100644 --- a/src/Simulation/GroundStation/GroundStation.cpp +++ b/src/Simulation/GroundStation/GroundStation.cpp @@ -1,59 +1,59 @@ -#include "GroundStation.h" - -#include "../../Interface/LogOutput/LogUtility.h" -#include "../../Interface/LogOutput/Logger.h" - - - -GroundStation::GroundStation(SimulationConfig* config, int gs_id) - :gs_id_(gs_id) -{ - Initialize(gs_id_,config); -} - -GroundStation::~GroundStation() -{ -} - -void GroundStation::Initialize(int gs_id,SimulationConfig* config) -{ - IniAccess iniAccess = IniAccess(config->ini_base_fname_); - string gs_ini_path = iniAccess.ReadString("SIM_SETTING", "gs_file"); - auto conf = IniAccess(gs_ini_path); - - const string st_gs_id = std::to_string(static_cast(gs_id)); - const char* cs = st_gs_id.data(); - char Section[30] = "GS"; - strcat(Section, cs); - - latitude_ = conf.ReadDouble(Section, "latitude"); - longitude_ = conf.ReadDouble(Section, "longitude"); - height_ = conf.ReadDouble(Section, "height"); - elevation_angle_ = conf.ReadDouble(Section, "elevation_angle"); -} - -void GroundStation::LogSetup(Logger& logger) -{ -} - -void GroundStation::Update(const double& current_jd) // 慣性系での地上局位置を更新する -{ - double current_side = gstime(current_jd); - double theta = FMod2p(longitude_ * DEG2RAD + current_side); //[rad] - - double radiusearthkm; - double f; - getwgsconst(whichconst_gs, radiusearthkm, f); - - double e2 = f * (2 - f); - double c = 1 / sqrt(1 - e2 * sin(latitude_ * DEG2RAD) * sin(latitude_ * DEG2RAD)); - double N = c * radiusearthkm * 1000.0; //[metre] - - double x = (N + height_) * cos(latitude_ * DEG2RAD) * cos(theta); //[metre] - double y = (N + height_) * cos(latitude_ * DEG2RAD) * sin(theta); //[metre] - double z = (N * (1 - e2) + height_) * sin(latitude_ * DEG2RAD); //[metre] - - gs_position_i_(0) = x; - gs_position_i_(1) = y; - gs_position_i_(2) = z; -} +#include + +#include "GroundStation.h" + +#include "../../Interface/LogOutput/LogUtility.h" +#include "../../Interface/LogOutput/Logger.h" + +GroundStation::GroundStation(SimulationConfig* config, int gs_id) + :gs_id_(gs_id) +{ + Initialize(gs_id_,config); +} + +GroundStation::~GroundStation() +{ +} + +void GroundStation::Initialize(int gs_id,SimulationConfig* config) +{ + IniAccess iniAccess = IniAccess(config->ini_base_fname_); + std::string gs_ini_path = iniAccess.ReadString("SIM_SETTING", "gs_file"); + auto conf = IniAccess(gs_ini_path); + + const std::string st_gs_id = std::to_string(static_cast(gs_id)); + const char* cs = st_gs_id.data(); + char Section[30] = "GS"; + strcat(Section, cs); + + latitude_ = conf.ReadDouble(Section, "latitude"); + longitude_ = conf.ReadDouble(Section, "longitude"); + height_ = conf.ReadDouble(Section, "height"); + elevation_angle_ = conf.ReadDouble(Section, "elevation_angle"); +} + +void GroundStation::LogSetup(Logger& logger) +{ +} + +void GroundStation::Update(const double& current_jd) // 慣性系での地上局位置を更新する +{ + double current_side = gstime(current_jd); + double theta = FMod2p(longitude_ * DEG2RAD + current_side); //[rad] + + double radiusearthkm; + double f; + getwgsconst(whichconst_gs, radiusearthkm, f); + + double e2 = f * (2 - f); + double c = 1 / sqrt(1 - e2 * sin(latitude_ * DEG2RAD) * sin(latitude_ * DEG2RAD)); + double N = c * radiusearthkm * 1000.0; //[metre] + + double x = (N + height_) * cos(latitude_ * DEG2RAD) * cos(theta); //[metre] + double y = (N + height_) * cos(latitude_ * DEG2RAD) * sin(theta); //[metre] + double z = (N * (1 - e2) + height_) * sin(latitude_ * DEG2RAD); //[metre] + + gs_position_i_(0) = x; + gs_position_i_(1) = y; + gs_position_i_(2) = z; +} diff --git a/src/Simulation/GroundStation/GroundStation.h b/src/Simulation/GroundStation/GroundStation.h index cae750929..cfa628883 100644 --- a/src/Simulation/GroundStation/GroundStation.h +++ b/src/Simulation/GroundStation/GroundStation.h @@ -1,45 +1,45 @@ -#pragma once - - -#include "../../Interface/InitInput/Initialize.h" -#include "../SimulationConfig.h" -#include "../../Library/math/Vector.hpp" - -//↓TODO: 地上局位置を求めるため,Dynamics/Orbit/EarthCenterOrbit.cppのTransECIToGeo()を参考に直接SGPをいじっているが,これをDynamics外に出すissueがあるので,いずれそれと関連して間接的にいじるように変える必要がある -// https://gitlab.com/ut_issl/s2e/s2e_core_oss/-/issues/4 -#include "../../Library/sgp4/sgp4unit.h" -#include "../../Library/sgp4/sgp4io.h" -#include "../../Library/sgp4/sgp4ext.h" -#include -using namespace std; -#define DEG2RAD 0.017453292519943295769 // PI/180 -static gravconsttype whichconst_gs; -//↑ - -class GroundStation -{ -public: - int gs_id_; //GroundStationのID - double latitude_; //[deg] - double longitude_; //[deg] - double height_; //[m] - double elevation_angle_; //[deg] - - GroundStation(SimulationConfig* config, int gs_id_); - virtual ~GroundStation(); - - // ちょっとコピー周りの対応がめんどいのでとりあえずコピー禁止しとく - // GroundStation(const GroundStation &) = delete; - // GroundStation& operator= (const GroundStation &) = delete; - - virtual void Initialize(int gs_id,SimulationConfig* config); - - virtual void LogSetup(Logger& logger); - - virtual void Update(const double& current_jd); - - Vector<3> GetGSPosition_i() const { return gs_position_i_; } - -protected: - Vector<3> gs_position_i_; // 慣性系での地上局位置[m] -}; +#pragma once + + +#include "../../Interface/InitInput/Initialize.h" +#include "../SimulationConfig.h" +#include "../../Library/math/Vector.hpp" + +//↓TODO: 地上局位置を求めるため,Dynamics/Orbit/EarthCenterOrbit.cppのTransECIToGeo()を参考に直接SGPをいじっているが,これをDynamics外に出すissueがあるので,いずれそれと関連して間接的にいじるように変える必要がある +// https://gitlab.com/ut_issl/s2e/s2e_core_oss/-/issues/4 +#include "../../Library/sgp4/sgp4unit.h" +#include "../../Library/sgp4/sgp4io.h" +#include "../../Library/sgp4/sgp4ext.h" +#include + +#define DEG2RAD 0.017453292519943295769 // PI/180 +static gravconsttype whichconst_gs; +//↑ + +class GroundStation +{ +public: + int gs_id_; //GroundStationのID + double latitude_; //[deg] + double longitude_; //[deg] + double height_; //[m] + double elevation_angle_; //[deg] + + GroundStation(SimulationConfig* config, int gs_id_); + virtual ~GroundStation(); + + // ちょっとコピー周りの対応がめんどいのでとりあえずコピー禁止しとく + // GroundStation(const GroundStation &) = delete; + // GroundStation& operator= (const GroundStation &) = delete; + + virtual void Initialize(int gs_id,SimulationConfig* config); + + virtual void LogSetup(Logger& logger); + + virtual void Update(const double& current_jd); + + Vector<3> GetGSPosition_i() const { return gs_position_i_; } + +protected: + Vector<3> gs_position_i_; // 慣性系での地上局位置[m] +}; diff --git a/src/Simulation/GroundStation/SampleGroundStation/SampleGSComponents.cpp b/src/Simulation/GroundStation/SampleGroundStation/SampleGSComponents.cpp index 85b4826d2..bd2c7974d 100644 --- a/src/Simulation/GroundStation/SampleGroundStation/SampleGSComponents.cpp +++ b/src/Simulation/GroundStation/SampleGroundStation/SampleGSComponents.cpp @@ -5,10 +5,10 @@ SampleGSComponents::SampleGSComponents(const SimulationConfig* config) { IniAccess iniAccess = IniAccess(config_->ini_base_fname_); - string ant_ini_path = iniAccess.ReadString("COMPONENTS_FILE", "ant_gs_file"); + std::string ant_ini_path = iniAccess.ReadString("COMPONENTS_FILE", "ant_gs_file"); config_->main_logger_->CopyFileToLogDir(ant_ini_path); ant_ = new ANT(InitANT(2, ant_ini_path)); - string gscalculator_ini_path = iniAccess.ReadString("COMPONENTS_FILE", "gscalculator_file"); + std::string gscalculator_ini_path = iniAccess.ReadString("COMPONENTS_FILE", "gscalculator_file"); config_->main_logger_->CopyFileToLogDir(gscalculator_ini_path); gscalculator_ = new GScalculator(InitGScalculator(gscalculator_ini_path)); // GScalcはGSごとに固有のものなのでidは不要か } diff --git a/src/Simulation/MCSim/InitParameter.cpp b/src/Simulation/MCSim/InitParameter.cpp index f00e6003c..f00dba8bf 100644 --- a/src/Simulation/MCSim/InitParameter.cpp +++ b/src/Simulation/MCSim/InitParameter.cpp @@ -1,5 +1,7 @@ #include "InitParameter.h" +using namespace std; + random_device InitParameter::rnd_; mt19937 InitParameter::mt_; uniform_real_distribution<>* InitParameter::uniform_dist_; diff --git a/src/Simulation/MCSim/InitParameter.h b/src/Simulation/MCSim/InitParameter.h index ab4f02918..16b4ca1ae 100644 --- a/src/Simulation/MCSim/InitParameter.h +++ b/src/Simulation/MCSim/InitParameter.h @@ -10,7 +10,6 @@ #include "../../Library/math/Vector.hpp" #include "../../Library/math/Quaternion.hpp" -using namespace std; using libra::Vector; using libra::Quaternion; @@ -61,20 +60,20 @@ class InitParameter private: // 実際の値 - vector val_; + std::vector val_; // 平均値または最小値(使われ方はgen_[RandomizationType]関数のコメントを参照) - vector mean_or_min_; + std::vector mean_or_min_; // 標準偏差または最大値(使われ方はgen_[RandomizationType]関数のコメントを参照) - vector sigma_or_max_; + std::vector sigma_or_max_; // For randomization RandomizationType rnd_type_; // 乱数タイプ - static random_device rnd_; // 非決定的乱数生成器(時刻に基づいて乱数を生成し,非決定的なseedを生成する) - static mt19937 mt_; // 決定的乱数生成器 - static uniform_real_distribution<>* uniform_dist_; // 一様分布乱数生成器 - static normal_distribution<>* normal_dist_; // 正規分布乱数生成器 + static std::random_device rnd_; // 非決定的乱数生成器(時刻に基づいて乱数を生成し,非決定的なseedを生成する) + static std::mt19937 mt_; // 決定的乱数生成器 + static std::uniform_real_distribution<>* uniform_dist_; // 一様分布乱数生成器 + static std::normal_distribution<>* normal_dist_; // 正規分布乱数生成器 // 一様分布する1次元乱数を生成する static double Uniform_1d(double lb, double ub); diff --git a/src/Simulation/MCSim/MCSimExecutor.cpp b/src/Simulation/MCSim/MCSimExecutor.cpp index 1eea38b22..38d51b397 100644 --- a/src/Simulation/MCSim/MCSimExecutor.cpp +++ b/src/Simulation/MCSim/MCSimExecutor.cpp @@ -1,5 +1,7 @@ #include "MCSimExecutor.h" +using std::string; + MCSimExecutor::MCSimExecutor(unsigned long long total_num_of_executions) :total_num_of_executions_(total_num_of_executions) { @@ -78,4 +80,4 @@ void MCSimExecutor::RandomizeAllParameters() void MCSimExecutor::SetSeed(unsigned long seed, bool is_deterministic) { InitParameter::SetSeed(seed, is_deterministic); -} \ No newline at end of file +} diff --git a/src/Simulation/MCSim/MCSimExecutor.h b/src/Simulation/MCSim/MCSimExecutor.h index caeb7bc00..c52165ef8 100644 --- a/src/Simulation/MCSim/MCSimExecutor.h +++ b/src/Simulation/MCSim/MCSimExecutor.h @@ -6,7 +6,6 @@ //#include "SimulationObject.h" #include "InitParameter.h" -using namespace std; using libra::Vector; class MCSimExecutor @@ -18,7 +17,7 @@ class MCSimExecutor bool log_history_; // 1 caseごとのログを記録するかどうかのflag // List of InitParameters read from MCSim.ini - map ip_list_; + std::map ip_list_; public: // MCSim.iniにおいてSimulationObjectとInitParameter名を区別するための文字 @@ -61,20 +60,20 @@ class MCSimExecutor template // InitParameterの追加 - void AddInitParameter(string so_name, string ip_name, const Vector& mean_or_min, const Vector& sigma_or_max, InitParameter::RandomizationType rnd_type); + void AddInitParameter(std::string so_name, std::string ip_name, const Vector& mean_or_min, const Vector& sigma_or_max, InitParameter::RandomizationType rnd_type); // 全てのInitParameterをRandomize void RandomizeAllParameters(); template // Randomizeされた後の値を取得しdst_vecに格納 - void GetInitParameterVec(string so_name, string ip_name, Vector& dst_vec) const; + void GetInitParameterVec(std::string so_name, std::string ip_name, Vector& dst_vec) const; // Randomizeされた後の値を取得しdstに格納 - void GetInitParameterDouble(string so_name, string ip_name, double& dst) const; + void GetInitParameterDouble(std::string so_name, std::string ip_name, double& dst) const; // Randomizeされた後の値を取得しdst_quatに格納 - void GetInitParameterQuaternion(string so_name, string ip_name, Quaternion& dst_quat) const; + void GetInitParameterQuaternion(std::string so_name, std::string ip_name, Quaternion& dst_quat) const; }; void MCSimExecutor::Enable(bool enabled) @@ -115,10 +114,10 @@ void MCSimExecutor::LogHistory(bool set) } template -void MCSimExecutor::GetInitParameterVec(string so_name, string ip_name, Vector& dst_vec) const +void MCSimExecutor::GetInitParameterVec(std::string so_name, std::string ip_name, Vector& dst_vec) const { if (!enabled_) return; - string name = so_name + MCSimExecutor::separator_ + ip_name; + std::string name = so_name + MCSimExecutor::separator_ + ip_name; if (ip_list_.find(name) == ip_list_.end()) { // ip_listに登録されていない(MCSim.iniで定義されていない) @@ -131,9 +130,9 @@ void MCSimExecutor::GetInitParameterVec(string so_name, string ip_name, Vector -void MCSimExecutor::AddInitParameter(string so_name, string ip_name, const Vector& mean_or_min, const Vector& sigma_or_max, InitParameter::RandomizationType rnd_type) +void MCSimExecutor::AddInitParameter(std::string so_name, std::string ip_name, const Vector& mean_or_min, const Vector& sigma_or_max, InitParameter::RandomizationType rnd_type) { - string name = so_name + MCSimExecutor::separator_ + ip_name; + std::string name = so_name + MCSimExecutor::separator_ + ip_name; if (ip_list_.find(name) == ip_list_.end()) { // ip_listに登録されていない場合は登録 diff --git a/src/Simulation/MCSim/SimulationObject.cpp b/src/Simulation/MCSim/SimulationObject.cpp index 39f199db0..18d7dd541 100644 --- a/src/Simulation/MCSim/SimulationObject.cpp +++ b/src/Simulation/MCSim/SimulationObject.cpp @@ -1,12 +1,12 @@ #include "SimulationObject.h" -map SimulationObject::so_list_; +std::map SimulationObject::so_list_; -SimulationObject::SimulationObject(string name) +SimulationObject::SimulationObject(std::string name) :name_(name) { // so_listに登録されているかを調べる - map::iterator itr = SimulationObject::so_list_.find(name); + std::map::iterator itr = SimulationObject::so_list_.find(name); if (itr == SimulationObject::so_list_.end()) { @@ -35,12 +35,12 @@ void SimulationObject::SetAllParameters(const MCSimExecutor& mc_sim) } } -void SimulationObject::GetInitParameterDouble(const MCSimExecutor& mc_sim, string ip_name, double& dst) const +void SimulationObject::GetInitParameterDouble(const MCSimExecutor& mc_sim, std::string ip_name, double& dst) const { mc_sim.GetInitParameterDouble(name_, ip_name, dst); } -void SimulationObject::GetInitParameterQuaternion(const MCSimExecutor& mc_sim, string ip_name, Quaternion& dst_quat) const +void SimulationObject::GetInitParameterQuaternion(const MCSimExecutor& mc_sim, std::string ip_name, Quaternion& dst_quat) const { mc_sim.GetInitParameterQuaternion(name_, ip_name, dst_quat); -} \ No newline at end of file +} diff --git a/src/Simulation/MCSim/SimulationObject.h b/src/Simulation/MCSim/SimulationObject.h index 22250da0c..267f0e957 100644 --- a/src/Simulation/MCSim/SimulationObject.h +++ b/src/Simulation/MCSim/SimulationObject.h @@ -10,14 +10,13 @@ #include "InitParameter.h" #include "MCSimExecutor.h" -using namespace std; using libra::Vector; class SimulationObject { public: // コンストラクタ - explicit SimulationObject(string name); + explicit SimulationObject(std::string name); //// コピーコンストラクタ //SimulationObject(const SimulationObject& other); @@ -37,13 +36,13 @@ class SimulationObject template // Randomizeされた後の値を取得しdst_vecに格納 - void GetInitParameterVec(const MCSimExecutor& mc_sim, string ip_name, Vector& dst_vec) const; + void GetInitParameterVec(const MCSimExecutor& mc_sim, std::string ip_name, Vector& dst_vec) const; // Randomizeされた後の値を取得しdstに格納 - void GetInitParameterDouble(const MCSimExecutor& mc_sim, string ip_name, double& dst) const; + void GetInitParameterDouble(const MCSimExecutor& mc_sim, std::string ip_name, double& dst) const; // Randomizeされた後の値を取得しdst_quatに格納 - void GetInitParameterQuaternion(const MCSimExecutor& mc_sim, string ip_name, Quaternion& dst_quat) const; + void GetInitParameterQuaternion(const MCSimExecutor& mc_sim, std::string ip_name, Quaternion& dst_quat) const; // Randomize結果を実際に使われる変数へ格納する処理を行う関数.継承先において定義されるべき純粋仮想関数. virtual void SetParameters(const MCSimExecutor& mc_sim) = 0; @@ -53,15 +52,15 @@ class SimulationObject private: // MCSim.iniにおいて区別するための名称.継承する際にはコンストラクタの引数として設定する. - string name_; + std::string name_; // list of objects with simulation parameters - static map so_list_; + static std::map so_list_; }; template -void SimulationObject::GetInitParameterVec(const MCSimExecutor& mc_sim, string ip_name, Vector& dst_vec) const +void SimulationObject::GetInitParameterVec(const MCSimExecutor& mc_sim, std::string ip_name, Vector& dst_vec) const { mc_sim.GetInitParameterVec(name_, ip_name, dst_vec); -} \ No newline at end of file +} diff --git a/src/Simulation/SimulationConfig.h b/src/Simulation/SimulationConfig.h index a7d0fa0f3..6b11aac5c 100644 --- a/src/Simulation/SimulationConfig.h +++ b/src/Simulation/SimulationConfig.h @@ -1,13 +1,15 @@ #pragma once +#include +#include #include "../Interface/LogOutput/Logger.h" struct SimulationConfig { - string ini_base_fname_; + std::string ini_base_fname_; Logger* main_logger_; int num_of_simulated_spacecraft_; - vector sat_file_; - string gs_file_; - string inter_sat_comm_file_; - string gnss_file_; + std::vector sat_file_; + std::string gs_file_; + std::string inter_sat_comm_file_; + std::string gnss_file_; }; diff --git a/src/Simulation/Spacecraft/SampleSpacecraft/SampleComponents.cpp b/src/Simulation/Spacecraft/SampleSpacecraft/SampleComponents.cpp index b4838aa15..869389078 100644 --- a/src/Simulation/Spacecraft/SampleSpacecraft/SampleComponents.cpp +++ b/src/Simulation/Spacecraft/SampleSpacecraft/SampleComponents.cpp @@ -21,8 +21,10 @@ SampleComponents::SampleComponents( // Components obc_ = new OBC(1, clock_gen, pcu_->GetPowerPort(0)); + hils_port_manager_ = new HilsPortManager(); + // Gyro - string ini_path = iniAccess.ReadString("COMPONENTS_FILE", "gyro_file"); + std::string ini_path = iniAccess.ReadString("COMPONENTS_FILE", "gyro_file"); config_->main_logger_->CopyFileToLogDir(ini_path); gyro_ = new Gyro(InitGyro(clock_gen, pcu_->GetPowerPort(1), 1, ini_path, glo_env_->GetSimTime().GetCompoStepSec(), dynamics_)); // MagSensor @@ -60,6 +62,10 @@ SampleComponents::SampleComponents( pcu_->GetPowerPort(1)->SetVoltage(3.3); pcu_->GetPowerPort(2)->SetVoltage(3.3); + // Examples of HILS + exp_hils_responder_ = new ExpHils(clock_gen, 1, obc_, 3, 9600, hils_port_manager_, 1); + exp_hils_sender_ = new ExpHils(clock_gen, 0, obc_, 4, 9600, hils_port_manager_, 0); + // actuator debug output libra::Vector mag_moment_c{0.01}; //mag_torquer_->SetMagMomentC(mag_moment_c); @@ -79,7 +85,10 @@ SampleComponents::~SampleComponents() delete rw_; delete thruster_; delete pcu_; + delete exp_hils_responder_; + delete exp_hils_sender_; delete obc_; + delete hils_port_manager_; // delete after exp_hils } Vector<3> SampleComponents::GenerateForce_b() diff --git a/src/Simulation/Spacecraft/SampleSpacecraft/SampleComponents.h b/src/Simulation/Spacecraft/SampleSpacecraft/SampleComponents.h index d6b47f4fc..0d2164134 100644 --- a/src/Simulation/Spacecraft/SampleSpacecraft/SampleComponents.h +++ b/src/Simulation/Spacecraft/SampleSpacecraft/SampleComponents.h @@ -12,6 +12,8 @@ #include "../../../Component/AOCS/MagTorquer.h" #include "../../../Component/AOCS/RWModel.h" #include "../../../Component/Propulsion/SimpleThruster.h" +#include "../../../Interface/HilsInOut/HilsPortManager.h" +#include "../../../Component/Abstract/ExpHils.h" using libra::Vector; class OBC; @@ -44,6 +46,7 @@ class SampleComponents private: PCU* pcu_; OBC* obc_; + HilsPortManager* hils_port_manager_; Gyro* gyro_; MagSensor* mag_sensor_; STT* stt_; @@ -52,6 +55,8 @@ class SampleComponents MagTorquer* mag_torquer_; RWModel* rw_; SimpleThruster* thruster_; + ExpHils* exp_hils_responder_; + ExpHils* exp_hils_sender_; const SimulationConfig* config_; const Dynamics* dynamics_; diff --git a/src/Simulation/Spacecraft/SampleSpacecraft/SampleSat.cpp b/src/Simulation/Spacecraft/SampleSpacecraft/SampleSat.cpp index 6026cf05c..670951a78 100644 --- a/src/Simulation/Spacecraft/SampleSpacecraft/SampleSat.cpp +++ b/src/Simulation/Spacecraft/SampleSpacecraft/SampleSat.cpp @@ -28,20 +28,13 @@ void SampleSat::LogSetup(Logger & logger) void SampleSat::Update(const SimTime* sim_time) { - clock_gen_.UpdateComponents(sim_time); - GenerateTorque_b(); - GenerateForce_b(); + // Update Dynamics Spacecraft::Update(sim_time); -} - -void SampleSat::GenerateTorque_b() -{ + // clear force and torques + Clear(); + // Update Components + clock_gen_.UpdateComponents(sim_time); + // Add force and torque generated by components dynamics_->AddTorque_b(components_->GenerateTorque_b()); -} - -void SampleSat::GenerateForce_b() -{ dynamics_->AddForce_b(components_->GenerateForce_b()); } - - diff --git a/src/Simulation/Spacecraft/SampleSpacecraft/SampleSat.h b/src/Simulation/Spacecraft/SampleSpacecraft/SampleSat.h index b43e43b6d..6c65e8c79 100644 --- a/src/Simulation/Spacecraft/SampleSpacecraft/SampleSat.h +++ b/src/Simulation/Spacecraft/SampleSpacecraft/SampleSat.h @@ -18,10 +18,6 @@ class SampleSat : public Spacecraft // 状態量の更新 virtual void Update(const SimTime* sim_time); - //ダイナミクスへの力・トルク出力 - void GenerateTorque_b(); - void GenerateForce_b(); - private: SampleComponents* components_; }; diff --git a/src/Simulation/Spacecraft/Structure/Structure.cpp b/src/Simulation/Spacecraft/Structure/Structure.cpp index f9c1e31b0..3f783fa29 100644 --- a/src/Simulation/Spacecraft/Structure/Structure.cpp +++ b/src/Simulation/Spacecraft/Structure/Structure.cpp @@ -16,11 +16,11 @@ void Structure::Initialize(SimulationConfig* sim_config, const int sat_id) { // Read file name IniAccess conf = IniAccess(sim_config->sat_file_[sat_id]); - string ini_fname = conf.ReadString("STRUCTURE_FILE", "structure_file"); + std::string ini_fname = conf.ReadString("STRUCTURE_FILE", "structure_file"); // Save ini file sim_config->main_logger_->CopyFileToLogDir(ini_fname); // Initialize kinnematics_params_ = new KinematicsParams(InitKinematicsParams(ini_fname)); surfaces_ = InitSurfaces(ini_fname); rmm_params_ = new RMMParams(InitRMMParams(ini_fname)); -} \ No newline at end of file +}