├── example ├── logs │ └── .gitkeep ├── settings │ ├── environment │ │ ├── cspice │ │ │ └── .gitkeep │ │ ├── space_weather │ │ │ └── .gitkeep │ │ ├── star_catalogue │ │ │ └── .gitkeep │ │ ├── gnss │ │ │ └── final_products │ │ │ │ └── .gitkeep │ │ └── sample_gnss.ini │ ├── sample_inter_satellite_communication.ini │ ├── sample_satellite │ │ ├── components │ │ │ ├── pcu_initial_study.ini │ │ │ ├── thermal_components.ini │ │ │ ├── attitude_observer.ini │ │ │ ├── rw_disturbance_csv_files │ │ │ │ ├── radial_force_harmonics_coefficients.csv │ │ │ │ └── radial_torque_harmonics_coefficients.csv │ │ │ ├── wings_command_sender_to_c2a │ │ │ │ ├── example.ops │ │ │ │ └── wings_command_sender_to_c2a.ini │ │ │ ├── force_generator.ini │ │ │ ├── torque_generator.ini │ │ │ ├── orbit_observer.ini │ │ │ ├── thruster.ini │ │ │ ├── sun_sensor.ini │ │ │ ├── angular_velocity_observer.ini │ │ │ ├── star_sensor.ini │ │ │ ├── battery.ini │ │ │ ├── telescope.ini │ │ │ ├── magnetometer.ini │ │ │ ├── gnss_receiver.ini │ │ │ ├── gyro_sensor.ini │ │ │ ├── solar_array_panel.ini │ │ │ ├── magnetorquer.ini │ │ │ └── component_interference.ini │ │ ├── thermal_csv_files │ │ │ ├── cij.csv │ │ │ ├── heaters.csv │ │ │ ├── rij.csv │ │ │ ├── heatload.csv │ │ │ └── node.csv │ │ ├── disturbance.ini │ │ └── local_environment.ini │ └── sample_ground_station │ │ ├── ground_station.ini │ │ └── components │ │ └── ground_station_calculator.ini ├── src │ └── simulation │ │ ├── spacecraft │ │ ├── sample_spacecraft.cpp │ │ ├── sample_port_configuration.hpp │ │ └── sample_spacecraft.hpp │ │ ├── ground_station │ │ ├── sample_ground_station.cpp │ │ ├── sample_ground_station_components.cpp │ │ ├── sample_ground_station.hpp │ │ └── sample_ground_station_components.hpp │ │ └── case │ │ ├── sample_case.hpp │ │ └── sample_case.cpp └── CMakeSettings.json ├── scripts ├── Plot │ ├── .gitignore │ ├── data │ │ └── sample_6u_cubesat.stl │ ├── graph.toml │ ├── Pipfile │ ├── make_miller_projection_map.py │ ├── gen_graph.sh │ ├── plot_air_density.py │ ├── plot_ground_position.py │ └── plot_satellite_orbit_on_miller.py ├── VisualStudio │ └── make_libnrlmsise.bat ├── Common │ ├── download_EGM96coefficients.sh │ ├── download_nrlmsise00_src_and_table.sh │ └── download_HIPcatalogue.sh ├── Docker_Ubuntu │ ├── setup_docker.sh │ └── download_cspice_Linux_gcc.sh └── Mac │ └── download_cspice_Mac.sh ├── src ├── components │ ├── products │ │ └── .gitkeep │ ├── real │ │ ├── thermal │ │ │ └── .gitkeep │ │ ├── cdh │ │ │ └── c2a_communication.hpp │ │ ├── aocs │ │ │ ├── reaction_wheel_ode.cpp │ │ │ └── mtq_magnetometer_interference.hpp │ │ ├── power │ │ │ └── power_control_unit.cpp │ │ └── communication │ │ │ └── antenna_radiation_pattern.cpp │ ├── ports │ │ ├── gpio_port.cpp │ │ ├── gpio_port.hpp │ │ └── uart_port.cpp │ ├── base │ │ ├── gpio_connection_with_obc.cpp │ │ ├── interface_gpio_component.hpp │ │ ├── interface_tickable.hpp │ │ ├── gpio_connection_with_obc.hpp │ │ └── component.cpp │ ├── examples │ │ ├── example_i2c_target_for_hils.cpp │ │ ├── example_change_structure.cpp │ │ └── example_change_structure.hpp │ ├── CMakeLists.txt │ └── ideal │ │ └── angular_velocity_observer.cpp ├── logger │ ├── CMakeLists.txt │ ├── initialize_log.hpp │ ├── loggable.hpp │ └── initialize_log.cpp ├── utilities │ ├── CMakeLists.txt │ ├── macros.hpp │ ├── endian_define.hpp │ ├── quantization.cpp │ ├── endian.cpp │ ├── endian.hpp │ ├── quantization.hpp │ ├── slip.hpp │ ├── ring_buffer.hpp │ └── ring_buffer.cpp ├── setting_file_reader │ ├── CMakeLists.txt │ ├── wings_operation_file.hpp │ └── wings_operation_file.cpp ├── environment │ ├── local │ │ └── CMakeLists.txt │ └── global │ │ ├── CMakeLists.txt │ │ ├── clock_generator.cpp │ │ ├── clock_generator.hpp │ │ └── global_environment.cpp ├── disturbances │ └── CMakeLists.txt ├── math_physics │ ├── math │ │ ├── s2e_math.hpp │ │ ├── s2e_math.cpp │ │ ├── test_s2e_math.cpp │ │ ├── test_matrix_vector.cpp │ │ ├── vector.cpp │ │ ├── matrix_vector.hpp │ │ └── ordinary_differential_equation_template_functions.hpp │ ├── atmosphere │ │ ├── simple_air_density_model.hpp │ │ └── harris_priester_model.hpp │ ├── randomization │ │ ├── global_randomization.cpp │ │ ├── minimal_standard_linear_congruential_generator.cpp │ │ ├── global_randomization.hpp │ │ ├── normal_randomization.cpp │ │ ├── minimal_standard_linear_congruential_generator_with_shuffle.cpp │ │ ├── random_walk_template_functions.hpp │ │ ├── random_walk.hpp │ │ └── minimal_standard_linear_congruential_generator.hpp │ ├── numerical_integration │ │ ├── interface_ode.hpp │ │ ├── runge_kutta_template.hpp │ │ ├── runge_kutta_fehlberg.hpp │ │ ├── runge_kutta_4.hpp │ │ ├── embedded_runge_kutta.hpp │ │ ├── embedded_runge_kutta_implementation.hpp │ │ └── dormand_prince_5.hpp │ ├── time_system │ │ ├── gps_time.cpp │ │ └── date_time_format.cpp │ ├── CMakeLists.txt │ ├── geomagnetic │ │ └── igrf.h │ ├── orbit │ │ ├── sgp4 │ │ │ ├── sgp4io.h │ │ │ └── sgp4ext.h │ │ ├── relative_orbit_models.hpp │ │ ├── test_interpolation_orbit.cpp │ │ └── interpolation_orbit.cpp │ ├── gnss │ │ ├── test_bias_sinex_file_reader.cpp │ │ ├── test_gnss_satellite_number.cpp │ │ └── gnss_satellite_number.cpp │ ├── control_utilities │ │ └── first_order_lag.hpp │ └── planet_rotation │ │ └── moon_rotation_utilities.hpp ├── simulation │ ├── spacecraft │ │ ├── structure │ │ │ ├── kinematics_parameters.cpp │ │ │ ├── surface.cpp │ │ │ ├── residual_magnetic_moment.cpp │ │ │ ├── initialize_structure.hpp │ │ │ └── structure.cpp │ │ ├── installed_components.cpp │ │ └── installed_components.hpp │ ├── multiple_spacecraft │ │ ├── inter_spacecraft_communication.cpp │ │ └── inter_spacecraft_communication.hpp │ ├── monte_carlo_simulation │ │ └── initialize_monte_carlo_simulation.hpp │ ├── CMakeLists.txt │ └── simulation_configuration.hpp └── dynamics │ ├── CMakeLists.txt │ ├── attitude │ └── initialize_attitude.hpp │ └── orbit │ ├── kepler_orbit_propagation.cpp │ ├── sgp4_orbit_propagation.hpp │ ├── kepler_orbit_propagation.hpp │ └── initialize_orbit.hpp ├── .github ├── CODEOWNERS ├── workflows │ ├── actionlint.yml │ ├── validate-renovate.yml │ ├── labeler.yml │ ├── validate-scripts.yml │ └── check-format.yml ├── ISSUE_TEMPLATE │ ├── action_item.md │ └── bug_report.md └── PULL_REQUEST_TEMPLATE.md ├── data └── img │ └── arkedgespace_logo.png ├── compile_flags.txt ├── .vscode └── settings.json ├── ExtLibraries ├── inih │ ├── CMakeLists.txt │ └── LICENSE.txt ├── README.md ├── CMakeLists.txt ├── CMakeSettings.json └── lunar_gravity_field │ └── CMakeLists.txt ├── .gitattributes ├── renovate.json ├── .gitignore ├── LICENSE └── common.cmake /example/logs/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/Plot/.gitignore: -------------------------------------------------------------------------------- 1 | *.png 2 | -------------------------------------------------------------------------------- /src/components/products/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/components/real/thermal/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @ut-issl/aocs @sksat 2 | -------------------------------------------------------------------------------- /example/settings/environment/cspice/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /example/settings/environment/space_weather/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /example/settings/environment/star_catalogue/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /example/settings/environment/gnss/final_products/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /example/settings/sample_inter_satellite_communication.ini: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/img/arkedgespace_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ut-issl/s2e-core/HEAD/data/img/arkedgespace_logo.png -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/pcu_initial_study.ini: -------------------------------------------------------------------------------- 1 | [PCU_INITIAL_STUDY_1] 2 | prescaler = 10 3 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/thermal_csv_files/cij.csv: -------------------------------------------------------------------------------- 1 | [W/K],BUS,SAP,SPACE 2 | BUS,0,0.5,0 3 | SAP,0.5,0,0 4 | SPACE,0,0,0 5 | -------------------------------------------------------------------------------- /scripts/Plot/data/sample_6u_cubesat.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ut-issl/s2e-core/HEAD/scripts/Plot/data/sample_6u_cubesat.stl -------------------------------------------------------------------------------- /example/settings/sample_satellite/thermal_csv_files/heaters.csv: -------------------------------------------------------------------------------- 1 | id,power_rating[W],lower_threshold[degC],upper_threshold[degC] 2 | 1,30,26,27 3 | -------------------------------------------------------------------------------- /compile_flags.txt: -------------------------------------------------------------------------------- 1 | -m32 2 | -std=c++14 3 | -Wall 4 | -Wextra 5 | -I./src 6 | -I../ExtLibraries/cspice/include 7 | -I../ExtLibraries/nrlmsise00/src/ 8 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cmake.sourceDirectory": "${workspaceFolder}/example", 3 | "cmake.buildDirectory": "${workspaceFolder}/example/build/" 4 | } -------------------------------------------------------------------------------- /example/settings/sample_satellite/thermal_csv_files/rij.csv: -------------------------------------------------------------------------------- 1 | [m^2],BUS,SAP,SPACE 2 | BUS,0,0.00316,0.047084 3 | SAP,0.00316,0,0.01684 4 | SPACE,0.047084,0.01684,0 5 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/thermal_csv_files/heatload.csv: -------------------------------------------------------------------------------- 1 | NodeID/Times[s],0,500,501,1000,1001,1500 2 | 0,10,10,20,20,10,10 3 | 1,0,0,0,0,0,0 4 | 2,0,0,0,0,0,0 5 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/thermal_components.ini: -------------------------------------------------------------------------------- 1 | [THERMAL_COMPONENT_1] 2 | is_debug = 0 3 | is_zeus_correct_enabled = 1 4 | file_path = data/ini/thermal_csv_files/ -------------------------------------------------------------------------------- /ExtLibraries/inih/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(INIH) 2 | cmake_minimum_required(VERSION 3.13) 3 | 4 | add_library(${PROJECT_NAME} STATIC 5 | ini.c 6 | cpp/INIReader.cpp 7 | ) 8 | 9 | include(../../common.cmake) 10 | -------------------------------------------------------------------------------- /src/logger/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(LOGGER) 2 | cmake_minimum_required(VERSION 3.13) 3 | 4 | add_library(${PROJECT_NAME} OBJECT 5 | logger.cpp 6 | initialize_log.cpp 7 | ) 8 | 9 | include(../../common.cmake) 10 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | *.md text 4 | *.txt text 5 | *.json text 6 | 7 | *.cpp text 8 | *.h text 9 | *.hpp text 10 | 11 | *.sh text eol=lf 12 | *.bat text eol=crlf 13 | 14 | *.ini text 15 | *.csv text 16 | -------------------------------------------------------------------------------- /scripts/Plot/graph.toml: -------------------------------------------------------------------------------- 1 | [[graph]] 2 | title = "position" 3 | type = "sat_position_i" 4 | value = ["X", "Y", "Z"] 5 | unit = "m" 6 | 7 | [[graph]] 8 | title = "velocity" 9 | type = "sat_velocity_i" 10 | value = ["X", "Y", "Z"] 11 | unit = "m/s" 12 | -------------------------------------------------------------------------------- /src/utilities/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(UTILITIES) 2 | cmake_minimum_required(VERSION 3.13) 3 | 4 | add_library(${PROJECT_NAME} OBJECT 5 | endian.cpp 6 | slip.cpp 7 | quantization.cpp 8 | ring_buffer.cpp 9 | ) 10 | 11 | include(../../common.cmake) 12 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/attitude_observer.ini: -------------------------------------------------------------------------------- 1 | [ATTITUDE_OBSERVER] 2 | // Standard deviation of force direction error [deg] 3 | error_angle_standard_deviation_deg = 1 4 | 5 | [COMPONENT_BASE] 6 | // Prescaler with respect to the component update period 7 | prescaler = 1 8 | -------------------------------------------------------------------------------- /src/setting_file_reader/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(SETTING_FILE_READER) 2 | cmake_minimum_required(VERSION 3.13) 3 | 4 | add_library(${PROJECT_NAME} OBJECT 5 | initialize_file_access.cpp 6 | c2a_command_database.cpp 7 | wings_operation_file.cpp 8 | ) 9 | 10 | include(../../common.cmake) 11 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/rw_disturbance_csv_files/radial_force_harmonics_coefficients.csv: -------------------------------------------------------------------------------- 1 | 1.01,2.18E-07 2 | 14.5,8.10E-09 3 | 10.67,4.46E-09 4 | 8.73,4.32E-09 5 | 6.78,3.50E-09 6 | 1.99,2.96E-09 7 | 9.63,2.92E-09 8 | 11.65,2.70E-09 9 | 14.88,1.90E-09 10 | 11.95,1.77E-09 11 | 7.76,1.51E-09 12 | 6.33,1.25E-09 13 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/rw_disturbance_csv_files/radial_torque_harmonics_coefficients.csv: -------------------------------------------------------------------------------- 1 | 1.01,6.30E-09 2 | 14.49,3.70E-10 3 | 13.82,1.47E-10 4 | 8.88,1.23E-10 5 | 6.78,1.05E-10 6 | 9.62,9.70E-11 7 | 13.44,9.50E-11 8 | 11.65,8.70E-11 9 | 1.98,7.10E-11 10 | 13.07,5.30E-11 11 | 5.8,4.50E-11 12 | 14.87,3.70E-11 13 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/thermal_csv_files/node.csv: -------------------------------------------------------------------------------- 1 | Node_id,Node_label,"node_type (0: diffusive, 1: boundary, 2: arithmetic)",heater_node_id,capacity[J/K],alpha,area[m^2],normal_v_b_x,normal_v_b_y,normal_v_b_z,initial_temperature[K] 2 | 0,BUS,0,1,880,0.2,0.06,1,0,0,300 3 | 1,SAP,0,0,100,0,0.02,0,0,1,250 4 | 2,SPACE,1,0,0,0,0,0,0,0,2.73 5 | -------------------------------------------------------------------------------- /src/environment/local/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(LOCAL_ENVIRONMENT) 2 | cmake_minimum_required(VERSION 3.13) 3 | 4 | add_library(${PROJECT_NAME} OBJECT 5 | atmosphere.cpp 6 | local_environment.cpp 7 | geomagnetic_field.cpp 8 | solar_radiation_pressure_environment.cpp 9 | earth_albedo.cpp 10 | local_celestial_information.cpp 11 | ) 12 | 13 | include(../../../common.cmake) 14 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/wings_command_sender_to_c2a/example.ops: -------------------------------------------------------------------------------- 1 | .# ===== Example ===== 2 | .# 3 | .# コメントは読み飛ばされる 4 | .# 5 | .MOBC_RT.NOP 6 | wait_sec 5 7 | MOBC_RT.MM_START_TRANSITION 2 8 | wait_sec 3 9 | check_value # check_valueは今は使えず読み飛ばされる 10 | let mode_id = 2 # letはいまはつかえない 11 | AOBC_RT.MM_START_TRANSITION {mode_id} # letを前提とした{}付きの引数があるとコマンドは送信されない 12 | .# 13 | -------------------------------------------------------------------------------- /scripts/Plot/Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | url = "https://pypi.org/simple" 3 | verify_ssl = true 4 | name = "pypi" 5 | 6 | [packages] 7 | basemap = "==1.4.1" 8 | matplotlib = "==3.7.2" 9 | numpy = "==1.24.3" 10 | pandas = "==2.0.3" 11 | numpy-stl = "==3.1.2" 12 | numpy-quaternion = "==2023.0.4" 13 | python-utils = "==3.5.2" 14 | 15 | [dev-packages] 16 | 17 | [requires] 18 | python_version = "3.8" 19 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/force_generator.ini: -------------------------------------------------------------------------------- 1 | [FORCE_GENERATOR] 2 | // Standard deviation of force magnitude error [N] 3 | force_magnitude_standard_deviation_N = 0.01 4 | 5 | // Standard deviation of force direction error [deg] 6 | force_direction_standard_deviation_deg = 1 7 | 8 | [COMPONENT_BASE] 9 | // Prescaler with respect to the component update period 10 | prescaler = 1 11 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/torque_generator.ini: -------------------------------------------------------------------------------- 1 | [TORQUE_GENERATOR] 2 | // Standard deviation of torque magnitude error [Nm] 3 | torque_magnitude_standard_deviation_Nm = 0.01 4 | 5 | // Standard deviation of torque direction error [deg] 6 | torque_direction_standard_deviation_deg = 1 7 | 8 | [COMPONENT_BASE] 9 | // Prescaler with respect to the component update period 10 | prescaler = 1 11 | -------------------------------------------------------------------------------- /src/utilities/macros.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file macros.hpp 3 | * @brief Definition of commonly used macros 4 | */ 5 | 6 | #ifndef S2E_LIBRARY_UTILITIES_MACROS_HPP_ 7 | #define S2E_LIBRARY_UTILITIES_MACROS_HPP_ 8 | 9 | namespace s2e::utilities { 10 | 11 | #define UNUSED(x) (void)(x) //!< Macro to avoid unused warnings 12 | 13 | } // namespace s2e::utilities 14 | 15 | #endif // S2E_LIBRARY_UTILITIES_MACROS_HPP_ 16 | -------------------------------------------------------------------------------- /src/environment/global/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(GLOBAL_ENVIRONMENT) 2 | cmake_minimum_required(VERSION 3.13) 3 | 4 | add_library(${PROJECT_NAME} OBJECT 5 | global_environment.cpp 6 | celestial_information.cpp 7 | hipparcos_catalogue.cpp 8 | gnss_satellites.cpp 9 | simulation_time.cpp 10 | clock_generator.cpp 11 | earth_rotation.cpp 12 | moon_rotation.cpp 13 | ) 14 | 15 | include(../../../common.cmake) 16 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/wings_command_sender_to_c2a/wings_command_sender_to_c2a.ini: -------------------------------------------------------------------------------- 1 | [WINGS_COMMAND_SENDER_TO_C2A] 2 | command_send_enable = ENABLE 3 | prescaler = 1 4 | c2a_command_database_file = SETTINGS_DIR_FROM_EXE/sample_satellite/components/wings_command_sender_to_c2a/SAMPLE_MOBC_CMD_DB_CMD_DB.csv 5 | wings_operation_file = SETTINGS_DIR_FROM_EXE/sample_satellite/components/wings_command_sender_to_c2a/example.ops 6 | -------------------------------------------------------------------------------- /src/disturbances/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(DISTURBANCE) 2 | cmake_minimum_required(VERSION 3.13) 3 | 4 | add_library(${PROJECT_NAME} OBJECT 5 | air_drag.cpp 6 | disturbances.cpp 7 | geopotential.cpp 8 | gravity_gradient.cpp 9 | magnetic_disturbance.cpp 10 | solar_radiation_pressure_disturbance.cpp 11 | surface_force.cpp 12 | third_body_gravity.cpp 13 | lunar_gravity_field.cpp 14 | ) 15 | include(../../common.cmake) 16 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ], 5 | "regexManagers": [ 6 | { 7 | "fileMatch": [".github/workflows/build.yml"], 8 | "matchStrings": [ 9 | "datasource=(?.*?) depName=(?.*?)( versioning=(?.*?))?\n .*?_VERSION: (?.*)\n" 10 | ], 11 | "versioningTemplate": "{{#if versioning}}{{versioning}}{{else}}semver{{/if}}" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /.github/workflows/actionlint.yml: -------------------------------------------------------------------------------- 1 | name: reviewdog / actionlint 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - '.github/workflows/**' 7 | 8 | jobs: 9 | actionlint: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v4.2.2 13 | - uses: reviewdog/action-actionlint@v1.69.1 14 | with: 15 | github_token: ${{ secrets.GITHUB_TOKEN }} 16 | reporter: github-pr-review 17 | fail_on_error: true 18 | -------------------------------------------------------------------------------- /src/utilities/endian_define.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file endian_define.hpp 3 | * @brief Define macro to change the endian definition 4 | */ 5 | 6 | #ifndef S2E_LIBRARY_UTILITIES_ENDIAN_DEFINE_HPP_ 7 | #define S2E_LIBRARY_UTILITIES_ENDIAN_DEFINE_HPP_ 8 | 9 | #ifndef IS_LITTLE_ENDIAN 10 | 11 | #define IS_LITTLE_ENDIAN //!< Activate the define for Little-endian environment 12 | 13 | #endif // IS_LITTLE_ENDIAN 14 | 15 | #endif // #ifndef S2E_LIBRARY_UTILITIES_ENDIAN_DEFINE_HPP_ 16 | -------------------------------------------------------------------------------- /scripts/VisualStudio/make_libnrlmsise.bat: -------------------------------------------------------------------------------- 1 | rem 2 | rem make_libnrlmsise.bat 3 | rem 4 | rem Creates nrlmsise00.lib for MS Visual C++ 5 | rem 6 | 7 | set cl= /c /O2 -D_COMPLEX_DEFINED -DMSDOS -DNON_ANSI_STDIO 8 | 9 | cd ../../../ExtLibraries/nrlmsise00/src 10 | 11 | cl nrlmsise-00.c nrlmsise-00_data.c 12 | 13 | link -lib /out:libnrlmsise00.lib nrlmsise-00.obj nrlmsise-00_data.obj 14 | 15 | move libnrlmsise00.lib ..\lib\ 16 | 17 | del *.obj 18 | 19 | exit 0 -------------------------------------------------------------------------------- /src/math_physics/math/s2e_math.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file s2e_math.hpp 3 | * @brief Math functions 4 | */ 5 | 6 | #ifndef S2E_LIBRARY_MATH_S2E_MATH_HPP_ 7 | #define S2E_LIBRARY_MATH_S2E_MATH_HPP_ 8 | 9 | #include 10 | 11 | namespace s2e::math { 12 | 13 | /** 14 | * @fn WrapTo2Pi 15 | * @brief Wrap angle value into [0, 2pi] 16 | * @param angle_rad: Angle [rad] 17 | */ 18 | double WrapTo2Pi(const double angle_rad); 19 | 20 | } // namespace s2e::math 21 | 22 | #endif // S2E_LIBRARY_MATH_S2E_MATH_HPP_ 23 | -------------------------------------------------------------------------------- /.github/workflows/validate-renovate.yml: -------------------------------------------------------------------------------- 1 | name: validate / renovate.json 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - 'renovate.json' 7 | - '.github/workflows/validate-renovate.yml' 8 | 9 | jobs: 10 | validate-renovate: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v4.2.2 15 | - uses: actions/setup-node@v6.0.0 16 | 17 | - name: install 18 | run: | 19 | npm install -g renovate 20 | - name: validate 21 | run: | 22 | renovate-config-validator 23 | -------------------------------------------------------------------------------- /example/settings/sample_ground_station/ground_station.ini: -------------------------------------------------------------------------------- 1 | [GROUND_STATION_0] 2 | // Position of the ground station 3 | latitude_deg = 26.140837 4 | longitude_deg = 127.661483 5 | height_m = 3.4 6 | 7 | // The minimum limit of elevation to work the station 8 | elevation_limit_angle_deg = 5.0 9 | 10 | [COMPONENT_FILES] 11 | ground_station_antenna_file = SETTINGS_DIR_FROM_EXE/sample_ground_station/components/ground_station_antenna.ini 12 | ground_station_calculator_file = SETTINGS_DIR_FROM_EXE/sample_ground_station/components/ground_station_calculator.ini 13 | -------------------------------------------------------------------------------- /src/simulation/spacecraft/structure/kinematics_parameters.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file kinematics_parameters.cpp 3 | * @brief Definition of Kinematics information 4 | */ 5 | 6 | #include "kinematics_parameters.hpp" 7 | 8 | namespace s2e::spacecraft { 9 | 10 | KinematicsParameters::KinematicsParameters(math::Vector<3> center_of_gravity_b_m, double mass_kg, math::Matrix<3, 3> inertia_tensor_b_kgm2) 11 | : center_of_gravity_b_m_(center_of_gravity_b_m), mass_kg_(mass_kg), inertia_tensor_b_kgm2_(inertia_tensor_b_kgm2) {} 12 | 13 | } // namespace s2e::spacecraft 14 | -------------------------------------------------------------------------------- /scripts/Common/download_EGM96coefficients.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd `dirname $0` 3 | 4 | #set variables 5 | DIR_GEOPOTENTIAL=../../../ExtLibraries/GeoPotential 6 | 7 | mkdir -p $DIR_GEOPOTENTIAL 8 | 9 | # #establish anonymous ftp connection and download the file 10 | # ftp -n -v -A< $DIR_GEOPOTENTIAL/egm96_to360.ascii 21 | -------------------------------------------------------------------------------- /src/utilities/quantization.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file quantization.cpp 3 | * @brief Functions for quantization 4 | */ 5 | 6 | #include "quantization.hpp" 7 | 8 | namespace s2e::utilities { 9 | 10 | double quantization(const double continuous_number, const double resolution) { 11 | int bin_num = (int)((double)continuous_number / resolution); 12 | return (double)bin_num * resolution; 13 | } 14 | 15 | float quantization_float(const double continuous_number, const double resolution) { return (float)quantization(continuous_number, resolution); } 16 | 17 | } // namespace s2e::utilities 18 | -------------------------------------------------------------------------------- /src/simulation/multiple_spacecraft/inter_spacecraft_communication.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file inter_spacecraft_communication.cpp 3 | * @brief Base class of inter satellite communication 4 | */ 5 | 6 | #include "inter_spacecraft_communication.hpp" 7 | 8 | #include 9 | 10 | namespace s2e::simulation { 11 | 12 | InterSpacecraftCommunication::InterSpacecraftCommunication(const SimulationConfiguration* simulation_configuration) { 13 | UNUSED(simulation_configuration); 14 | } 15 | 16 | InterSpacecraftCommunication::~InterSpacecraftCommunication() {} 17 | 18 | } // namespace s2e::simulation 19 | -------------------------------------------------------------------------------- /ExtLibraries/README.md: -------------------------------------------------------------------------------- 1 | # ExtLibraries 2 | 3 | ## Overview 4 | - S2E uses the following external libraries 5 | - [SPICE Toolkit](https://naif.jpl.nasa.gov/naif/toolkit.html) 6 | - For celestial body's information 7 | - [NRLMSISE00](https://www.brodo.de/space/nrlmsise/) 8 | - For precise air density model around the earth 9 | - [EGM96](https://cddis.nasa.gov/926/egm96/egm96.html) 10 | - For geopotential coefficient table 11 | - others 12 | 13 | ## Note 14 | - Currently, we cannot access the original download page of the `egm96_to360.ascii` coefficient table file. Therefore, we decided to provide the table file in this repository. 15 | -------------------------------------------------------------------------------- /src/math_physics/math/s2e_math.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file s2e_math.cpp 3 | * @brief Math functions 4 | */ 5 | 6 | #include "s2e_math.hpp" 7 | 8 | #include 9 | 10 | namespace s2e::math { 11 | double WrapTo2Pi(const double angle_rad) { 12 | double angle_out = angle_rad; 13 | if (angle_out < 0.0) { 14 | while (angle_out < 0.0) { 15 | angle_out += math::tau; 16 | } 17 | } else if (angle_out > math::tau) { 18 | while (angle_out > math::tau) { 19 | angle_out -= math::tau; 20 | } 21 | } else { 22 | // nothing to do 23 | } 24 | return angle_out; 25 | } 26 | } // namespace s2e::math 27 | -------------------------------------------------------------------------------- /.github/workflows/labeler.yml: -------------------------------------------------------------------------------- 1 | name: labeler 2 | 3 | on: 4 | push: 5 | branches: 6 | - develop 7 | pull_request: 8 | paths: 9 | - .github/workflows/labeler.yml 10 | - .github/labels.yml 11 | 12 | jobs: 13 | labeler: 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - uses: actions/checkout@v4.2.2 18 | 19 | - name: Run Labeler 20 | uses: crazy-max/ghaction-github-labeler@v5.3.0 21 | with: 22 | github-token: ${{ secrets.GITHUB_TOKEN }} 23 | yaml-file: .github/labels.yml 24 | skip-delete: false 25 | dry-run: ${{ github.ref != 'refs/heads/develop' }} 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/action_item.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Action Item 3 | about: Create an action item 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Details 11 | Provide a detailed description of the issue. 12 | 13 | ## Closing conditions 14 | Provide the conditions that must be met for the issue to be closed. 15 | 16 | ## Supplementary information 17 | Provide any supplementary information. 18 | 19 | ## Note 20 | - Provide a conclusion before closing the issue. 21 | 26 | -------------------------------------------------------------------------------- /scripts/Plot/make_miller_projection_map.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from mpl_toolkits.basemap import Basemap 3 | import matplotlib.pyplot as plt 4 | 5 | # miller projection 6 | def make_miller_projection_map(): 7 | map = Basemap(projection='mill',lon_0=180) 8 | # plot coastlines, draw label meridians and parallels. 9 | map.drawcoastlines() 10 | map.drawparallels(np.arange(-90,90,30),labels=[1,0,0,0]) 11 | map.drawmeridians(np.arange(map.lonmin,map.lonmax+30,60),labels=[0,0,0,1]) 12 | # fill continents 'coral' (with zorder=0), color wet areas 'aqua' 13 | map.drawmapboundary(fill_color='aqua') 14 | map.fillcontinents(color='coral',lake_color='aqua') 15 | return map 16 | -------------------------------------------------------------------------------- /src/simulation/spacecraft/structure/surface.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file surface.cpp 3 | * @brief Definition of spacecraft surface 4 | */ 5 | 6 | #include "surface.hpp" 7 | 8 | namespace s2e::spacecraft { 9 | 10 | Surface::Surface(const math::Vector<3> position_b_m, const math::Vector<3> normal_b, const double area_m2, const double reflectivity, 11 | const double specularity, const double air_specularity) 12 | : position_b_m_(position_b_m), 13 | normal_b_(normal_b), 14 | area_m2_(area_m2), 15 | reflectivity_(reflectivity), 16 | specularity_(specularity), 17 | air_specularity_(air_specularity) {} 18 | 19 | } // namespace s2e::spacecraft 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # CMake and VS directories 2 | CMakeBuilds/ 3 | .vs/ 4 | .vscode/ 5 | src/.vscode/ 6 | 7 | 8 | # Docker 9 | build/ 10 | 11 | # Log files 12 | **/logs/ 13 | 14 | # CSIPCE 15 | scripts/tmp_cspice/ 16 | 17 | # Executables 18 | *.exe 19 | *.out 20 | *.app 21 | 22 | # OSX 23 | .DS_Store 24 | .AppleDouble 25 | .LSOverride 26 | Icon 27 | 28 | # Thumbnails 29 | ._* 30 | 31 | # Files that might appear on external disk 32 | .Spotlight-V100 33 | .Trashes 34 | 35 | # Python 36 | __pycache__/ 37 | 38 | # Setting files 39 | **/settings/environment/cspice 40 | **/settings/environment/space_weather 41 | **/settings/environment/gravity_field 42 | **/settings/environment/star_catalogue 43 | -------------------------------------------------------------------------------- /src/simulation/spacecraft/installed_components.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file installed_components.cpp 3 | * @brief Definition of InstalledComponents class 4 | */ 5 | 6 | #include "installed_components.hpp" 7 | 8 | #include 9 | 10 | namespace s2e::spacecraft { 11 | 12 | math::Vector<3> InstalledComponents::GenerateForce_b_N() { 13 | math::Vector<3> force_b_N_(0.0); 14 | return force_b_N_; 15 | } 16 | 17 | math::Vector<3> InstalledComponents::GenerateTorque_b_Nm() { 18 | math::Vector<3> torque_b_Nm_(0.0); 19 | return torque_b_Nm_; 20 | } 21 | 22 | void InstalledComponents::LogSetup(logger::Logger& logger) { UNUSED(logger); } 23 | 24 | } // namespace s2e::spacecraft 25 | -------------------------------------------------------------------------------- /src/utilities/endian.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file endian.cpp 3 | * @brief Function to consider the endian 4 | */ 5 | 6 | #include "endian.hpp" 7 | 8 | #include 9 | 10 | namespace s2e::utilities { 11 | 12 | void *endian_memcpy(void *dst, const void *src, size_t size) { 13 | #ifdef IS_LITTLE_ENDIAN 14 | uint8_t *src_ = (uint8_t *)src; 15 | uint8_t *dst_ = (uint8_t *)dst; 16 | size_t i; 17 | 18 | if (size > 0) { 19 | size--; 20 | } 21 | 22 | for (i = 0; i <= size; i++) { 23 | *(dst_ + (size - i)) = *(src_ + i); 24 | } 25 | 26 | return dst; 27 | #else 28 | return memcpy(dst, src, size); 29 | #endif // IS_LITTLE_ENDIAN 30 | } 31 | 32 | } // namespace s2e::utilities 33 | -------------------------------------------------------------------------------- /src/utilities/endian.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file endian.hpp 3 | * @brief Function to consider the endian 4 | */ 5 | 6 | #ifndef S2E_LIBRARY_UTILITIES_ENDIAN_HPP_ 7 | #define S2E_LIBRARY_UTILITIES_ENDIAN_HPP_ 8 | 9 | #include 10 | #include 11 | 12 | #include "endian_define.hpp" // for IS_LITTLE_ENDIAN 13 | 14 | namespace s2e::utilities { 15 | 16 | /** 17 | * @fn endian_memcpy 18 | * @brief Memory copy considering endian 19 | * @param [out] dst: Copy destination 20 | * @param [in] src: Copy source 21 | * @param [in] count: Copy data size 22 | */ 23 | void *endian_memcpy(void *dst, const void *src, size_t count); 24 | 25 | } // namespace s2e::utilities 26 | 27 | #endif // S2E_LIBRARY_UTILITIES_ENDIAN_HPP_ 28 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/orbit_observer.ini: -------------------------------------------------------------------------------- 1 | [ORBIT_OBSERVER] 2 | // Noise definition frame 3 | // INERTIAL: Inertial frame 4 | // RTN: RTN frame 5 | noise_frame = INERTIAL 6 | 7 | // Standard deviation of position and velocity noise [m, m/s] 8 | // The frame definition can be selected above 9 | noise_standard_deviation(0) = 1000 // Position-X 10 | noise_standard_deviation(1) = 2000 // Position-Y 11 | noise_standard_deviation(2) = 3000 // Position-Z 12 | noise_standard_deviation(3) = 30 // Velocity-X 13 | noise_standard_deviation(4) = 20 // Velocity-Y 14 | noise_standard_deviation(5) = 10 // Velocity-Z 15 | 16 | 17 | [COMPONENT_BASE] 18 | // Prescaler with respect to the component update period 19 | prescaler = 1 20 | -------------------------------------------------------------------------------- /src/math_physics/atmosphere/simple_air_density_model.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file simple_air_density_model.hpp 3 | * @brief Simple earth's atmospheric density model 4 | */ 5 | #ifndef S2E_LIBRARY_ATMOSPHERE_SIMPLE_AIR_DENSITY_MODEL_HPP_ 6 | #define S2E_LIBRARY_ATMOSPHERE_SIMPLE_AIR_DENSITY_MODEL_HPP_ 7 | 8 | namespace s2e::atmosphere { 9 | 10 | /** 11 | * @fn CalcAirDensityWithSimpleModel 12 | * @brief Calculate atmospheric density with simplest method 13 | * @param [in] altitude_m: Altitude of spacecraft [m] 14 | * @return Atmospheric density [kg/m^3] 15 | */ 16 | double CalcAirDensityWithSimpleModel(const double altitude_m); 17 | 18 | } // namespace s2e::atmosphere 19 | 20 | #endif // S2E_LIBRARY_ATMOSPHERE_SIMPLE_AIR_DENSITY_MODEL_HPP_ 21 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/thruster.ini: -------------------------------------------------------------------------------- 1 | [THRUSTER_1] 2 | prescaler = 10; 3 | 4 | // Position of thruster head at body frame [m] 5 | thruster_position_b_m(0) = 0.0125 6 | thruster_position_b_m(1) = 0.0000 7 | thruster_position_b_m(2) = -0.1815 8 | 9 | // Thrust direction vector at body frame [m] 10 | thruster_direction_b(0) = 0 11 | thruster_direction_b(1) = 0 12 | thruster_direction_b(2) = 1 13 | 14 | // Maximum thrust [N] 15 | thrust_magnitude_N = 0.050 16 | 17 | // Standard deviation of thrust error [N] 18 | thrust_error_standard_deviation_N = 0.001 19 | 20 | // Standard deviation of thrust direction error [deg] 21 | direction_error_standard_deviation_deg = 1 22 | 23 | [POWER_PORT] 24 | minimum_voltage_V = 3.3 25 | assumed_power_consumption_W = 1.0 26 | -------------------------------------------------------------------------------- /src/math_physics/randomization/global_randomization.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @class global_randomization.cpp 3 | * @brief Class to manage global randomization 4 | */ 5 | 6 | #include "global_randomization.hpp" 7 | 8 | namespace s2e::randomization { 9 | 10 | GlobalRandomization global_randomization; 11 | 12 | GlobalRandomization::GlobalRandomization() { seed_ = 0xdeadbeef; } 13 | 14 | void GlobalRandomization::SetSeed(const long seed) { 15 | base_randomizer_.Initialize(seed); 16 | // double dl = base_randomizer_; 17 | } 18 | 19 | long GlobalRandomization::MakeSeed() { 20 | double rand = base_randomizer_; 21 | long seed = (long)((rand - 0.5) * kMaxSeed); 22 | if (seed == 0) { 23 | seed = 0xdeadbeef; 24 | } 25 | return seed; 26 | } 27 | 28 | } // namespace s2e::randomization 29 | -------------------------------------------------------------------------------- /example/settings/sample_ground_station/components/ground_station_calculator.ini: -------------------------------------------------------------------------------- 1 | [GROUND_STATION_CALCULATOR] 2 | // Polarization loss [dB] 3 | loss_polarization_dB = 0.0 4 | 5 | // Atmospheric loss [dB] 6 | loss_atmosphere_dB = -0.5 7 | 8 | // Rain fall loss [dB] 9 | loss_rainfall_dB = -0.12 10 | 11 | // Other losses [dB] 12 | loss_others_dB = 0.0 13 | 14 | // Required Eb/N0 [dB](The following value is QPSK and BER=1e-6) 15 | ebn0_dB = 10.8 16 | 17 | // Deterioration of hardware [dB] 18 | hardware_deterioration_dB = 1.5 19 | 20 | // Codig gain [dB](The following value is RS(E16)+Convolution and BER=1e-6) 21 | coding_gain_dB = -8.17 22 | 23 | // Required margin to calclate maximum bitrate [dB] 24 | margin_requirement_dB = 3.0 25 | 26 | // Downlink bitrate to calculate receive margin [bps] 27 | downlink_bitrate_bps = 100000 28 | -------------------------------------------------------------------------------- /src/dynamics/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(DYNAMICS) 2 | cmake_minimum_required(VERSION 3.13) 3 | 4 | add_library(${PROJECT_NAME} OBJECT 5 | orbit/orbit.cpp 6 | orbit/sgp4_orbit_propagation.cpp 7 | orbit/rk4_orbit_propagation.cpp 8 | orbit/relative_orbit.cpp 9 | orbit/kepler_orbit_propagation.cpp 10 | orbit/encke_orbit_propagation.cpp 11 | orbit/time_series_file_orbit_propagation.cpp 12 | orbit/initialize_orbit.cpp 13 | 14 | thermal/node.cpp 15 | thermal/temperature.cpp 16 | thermal/heater.cpp 17 | thermal/heater_controller.cpp 18 | thermal/heatload.cpp 19 | 20 | attitude/attitude.cpp 21 | attitude/attitude_rk4.cpp 22 | attitude/attitude_with_cantilever_vibration.cpp 23 | attitude/controlled_attitude.cpp 24 | attitude/initialize_attitude.cpp 25 | 26 | dynamics.cpp ) 27 | 28 | include(../../common.cmake) 29 | -------------------------------------------------------------------------------- /src/simulation/monte_carlo_simulation/initialize_monte_carlo_simulation.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file initialize_monte_carlo_simulation.hpp 3 | * @brief Initialize function for Monte-Carlo Simulator 4 | */ 5 | 6 | #ifndef S2E_SIMULATION_MONTE_CARLO_SIMULATION_INITIALIZE_MONTE_CARLO_SIMULATION_HPP_ 7 | #define S2E_SIMULATION_MONTE_CARLO_SIMULATION_INITIALIZE_MONTE_CARLO_SIMULATION_HPP_ 8 | 9 | #include "initialize_monte_carlo_parameters.hpp" 10 | #include "monte_carlo_simulation_executor.hpp" 11 | 12 | namespace s2e::simulation { 13 | 14 | /** 15 | * @fn InitMonteCarloSimulation 16 | * @brief Initialize function for Monte-Carlo Simulator 17 | */ 18 | MonteCarloSimulationExecutor* InitMonteCarloSimulation(std::string file_name); 19 | 20 | } // namespace s2e::simulation 21 | 22 | #endif // S2E_SIMULATION_MONTE_CARLO_SIMULATION_INITIALIZE_MONTE_CARLO_SIMULATION_HPP_ 23 | -------------------------------------------------------------------------------- /src/simulation/spacecraft/structure/residual_magnetic_moment.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file residual_magnetic_moment.cpp 3 | * @brief Definition of RMM (Residual Magnetic Moment) 4 | */ 5 | 6 | #include "residual_magnetic_moment.hpp" 7 | 8 | namespace s2e::spacecraft { 9 | 10 | ResidualMagneticMoment::ResidualMagneticMoment(const math::Vector<3> constant_value_b_Am2_, const double random_walk_standard_deviation_Am2, 11 | const double random_walk_limit_Am2, const double random_noise_standard_deviation_Am2) 12 | : constant_value_b_Am2_(constant_value_b_Am2_), 13 | random_walk_standard_deviation_Am2_(random_walk_standard_deviation_Am2), 14 | random_walk_limit_Am2_(random_walk_limit_Am2), 15 | random_noise_standard_deviation_Am2_(random_noise_standard_deviation_Am2) {} 16 | 17 | } // namespace s2e::spacecraft 18 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Related issues 2 | Mention any issues that this pull request is related (e.g., #1). Consider using the `development` field if you want to close the issue automatically when this pull request is merged. 3 | 4 | ## Description 5 | Provide a detailed description of this pull request. 6 | 7 | ## Test results 8 | Provide the test results and a link to the detailed results log. 9 | 10 | ## Impact 11 | Describe the scope of influence of the changes, e.g., `The behavior of feature ** changes.` 12 | 13 | ## Supplementary information 14 | Provide any supplementary information. 15 | 16 | 23 | -------------------------------------------------------------------------------- /src/components/ports/gpio_port.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file gpio_port.cpp 3 | * @brief Class to emulate GPIO(General Purpose Input and Output) port 4 | */ 5 | 6 | #include "gpio_port.hpp" 7 | 8 | namespace s2e::components { 9 | 10 | GpioPort::GpioPort(const unsigned int port_id, IGPIOCompo* component) : kPortId(port_id) { 11 | high_low_state_ = GPIO_LOW; 12 | component_ = component; 13 | } 14 | 15 | GpioPort::~GpioPort() {} 16 | 17 | int GpioPort::DigitalWrite(const bool is_high) { 18 | if (high_low_state_ != is_high) { 19 | // Call interaction function when detecting the change of the HIGH/LOW state 20 | if (component_ != nullptr) { 21 | component_->GpioStateChanged(kPortId, is_high); 22 | } 23 | } 24 | high_low_state_ = is_high; 25 | return 0; 26 | } 27 | 28 | bool GpioPort::DigitalRead() { return high_low_state_; } 29 | 30 | } // namespace s2e::components 31 | -------------------------------------------------------------------------------- /src/logger/initialize_log.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file initialize_log.hpp 3 | * @brief Initialize function for Log output 4 | */ 5 | 6 | #ifndef S2E_LIBRARY_LOGGER_INITIALIZE_LOG_HPP_ 7 | #define S2E_LIBRARY_LOGGER_INITIALIZE_LOG_HPP_ 8 | 9 | #include 10 | 11 | namespace s2e::logger { 12 | 13 | /** 14 | * @fn InitLog 15 | * @brief Initialize normal logger (default.csv) 16 | * @param [in] file_name: File name of the log file 17 | */ 18 | Logger* InitLog(std::string file_name); 19 | 20 | /** 21 | * @fn InitMonteCarloLog 22 | * @brief Initialize logger for Monte-Carlo simulation (mont.csv) 23 | * @param [in] file_name: File name of the log file 24 | * @param [in] enable: Enable flag for logging 25 | */ 26 | Logger* InitMonteCarloLog(std::string file_name, bool enable); 27 | 28 | } // namespace s2e::logger 29 | 30 | #endif // S2E_LIBRARY_LOGGER_INITIALIZE_LOG_HPP_ 31 | -------------------------------------------------------------------------------- /ExtLibraries/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(ExtLibraries) 2 | 3 | cmake_minimum_required(VERSION 3.18) 4 | 5 | # build config 6 | option(BUILD_64BIT "Build 64bit" OFF) 7 | 8 | # Mac user setting 9 | option(APPLE_SILICON "Build with Apple Silicon" OFF) 10 | # Force build with 64bit for APPLE 11 | if(APPLE) 12 | option(BUILD_64BIT "Build 64bit" ON) 13 | endif() 14 | 15 | if(NOT DEFINED EXT_LIB_DIR) 16 | set(EXT_LIB_DIR "${CMAKE_CURRENT_LIST_DIR}/../../ExtLibraries/") 17 | endif() 18 | 19 | if(NOT DEFINED SETTINGS_DIR) 20 | set(SETTINGS_DIR "${CMAKE_CURRENT_LIST_DIR}/../settings/") 21 | endif() 22 | 23 | # windows path 24 | string(REPLACE "\\" "/" EXT_LIB_DIR ${EXT_LIB_DIR}) 25 | string(REPLACE "\\" "/" SETTINGS_DIR ${SETTINGS_DIR}) 26 | 27 | message("ExtLibraries install dir: ${EXT_LIB_DIR}") 28 | 29 | add_subdirectory(nrlmsise00) 30 | add_subdirectory(cspice) 31 | add_subdirectory(lunar_gravity_field) 32 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/sun_sensor.ini: -------------------------------------------------------------------------------- 1 | [SUN_SENSOR_1] 2 | prescaler = 10; 3 | 4 | // Quaternion from body frame to component frame 5 | // The sight direction is Z-axis at the component frame 6 | quaternion_b2c(0) = 0.0 7 | quaternion_b2c(1) = 0.0 8 | quaternion_b2c(2) = 0.0 9 | quaternion_b2c(3) = 1.0 10 | 11 | // Field of View [deg] 12 | field_of_view_deg = 55.0 13 | 14 | // Standard deviation of normal noise[deg] 15 | white_noise_standard_deviation_deg = 0.5 16 | 17 | // Standard deviation of bias noise[deg] 18 | bias_standard_deviation_deg = 0.5 19 | 20 | // Threshold of light-receiving intensity[%] 21 | // Defined as a percentage to the solar constant 22 | // If it becomes smaller than this, it becomes impossible to get the sun direction 23 | intensity_lower_threshold_percent = 30.0 24 | 25 | [POWER_PORT] 26 | minimum_voltage_V = 3.3 27 | assumed_power_consumption_W = 1.0 28 | -------------------------------------------------------------------------------- /src/components/base/gpio_connection_with_obc.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file gpio_connection_with_obc.cpp 3 | * @brief Base class for GPIO communication with OBC flight software 4 | * TODO: consider relation with IGPIOCompo 5 | */ 6 | 7 | #include "gpio_connection_with_obc.hpp" 8 | 9 | namespace s2e::components { 10 | 11 | GpioConnectionWithObc::GpioConnectionWithObc(const std::vector port_id, OnBoardComputer* obc) : port_id_(port_id), obc_(obc) { 12 | for (size_t i = 0; i < port_id_.size(); i++) { 13 | obc_->GpioConnectPort(port_id_[i]); 14 | } 15 | } 16 | 17 | GpioConnectionWithObc::~GpioConnectionWithObc() {} 18 | 19 | bool GpioConnectionWithObc::Read(const int index) { return obc_->GpioComponentRead(port_id_[index]); } 20 | 21 | void GpioConnectionWithObc::Write(const int index, const bool is_high) { obc_->GpioComponentWrite(port_id_[index], is_high); } 22 | 23 | } // namespace s2e::components 24 | -------------------------------------------------------------------------------- /ExtLibraries/CMakeSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Win32", 5 | "generator": "Visual Studio 17 2022", 6 | "configurationType": "Debug", 7 | "inheritEnvironments": [ 8 | "msvc_x86" 9 | ], 10 | "buildRoot": "${thisFileDir}\\CMakeBuilds", 11 | "installRoot": "${thisFileDir}\\CMakeBuilds", 12 | "cmakeCommandArgs": "", 13 | "buildCommandArgs": "", 14 | "ctestCommandArgs": "" 15 | }, 16 | { 17 | "name": "Win64", 18 | "generator": "Visual Studio 17 2022 Win64", 19 | "configurationType": "Debug", 20 | "inheritEnvironments": [ 21 | "msvc_x64" 22 | ], 23 | "buildRoot": "${thisFileDir}\\CMakeBuilds", 24 | "installRoot": "${thisFileDir}\\CMakeBuilds", 25 | "cmakeCommandArgs": "", 26 | "buildCommandArgs": "", 27 | "ctestCommandArgs": "" 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /scripts/Common/download_nrlmsise00_src_and_table.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd `dirname $0` 3 | 4 | #set variables 5 | DIR_NRLMSISE00=../../../ExtLibraries/nrlmsise00/ 6 | URL_NRLMSISE00=git://git.linta.de/~brodo/nrlmsise-00.git 7 | URL_TABLE=ftp://ftp.agi.com/pub/DynamicEarthData/SpaceWeather-v1.2.txt 8 | 9 | mkdir -p $DIR_NRLMSISE00/table/ 10 | mkdir -p $DIR_NRLMSISE00/src/ 11 | mkdir -p $DIR_NRLMSISE00/lib/ 12 | 13 | 14 | # download source and space weather table for nrlmsise00 model 15 | curl $URL_TABLE > $DIR_NRLMSISE00/table/SpaceWeather.txt 16 | cd $DIR_NRLMSISE00 17 | git clone $URL_NRLMSISE00 src 18 | 19 | 20 | # build and make library 21 | cd src 22 | # modify compile option to 32bit 23 | sed -i -e "/CFLAGS/s/-Wall/-m32 -Wall/" ./makefile 24 | make 25 | ar rcs libnrlmsise00.a nrlmsise-00.o nrlmsise-00_data.o 26 | mv libnrlmsise00.a ../lib/libnrlmsise00.a 27 | # rm nrlmsise-00.o nrlmsise-00_data.o nrlmsise-00_test.o nrlmsise-test.exe 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: ['bug'] 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Details 11 | ### Description 12 | Describe the bug in detail. 13 | 14 | ### Conditions of occurrence 15 | Describe the environment, conditions, parameters, etc. under which the bug occurred. 16 | 17 | ### Additional information 18 | Provide any relevant files, links, etc. if available. 19 | 20 | ## Tasks 21 | - [ ] Fix xxx 22 | - [ ] Do yyy 23 | 24 | ## Impact 25 | Describe the scope of the bug's influence, e.g., `All tools are not working.` 26 | 27 | ## Supplementary notes 28 | Provide any extra notes if necessary. 29 | 30 | ## Notes 31 | - Provide a conclusion before closing the issue. 32 | 37 | -------------------------------------------------------------------------------- /src/simulation/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(SIMULATION) 2 | cmake_minimum_required(VERSION 3.13) 3 | 4 | add_library(${PROJECT_NAME} OBJECT 5 | case/simulation_case.cpp 6 | 7 | monte_carlo_simulation/monte_carlo_simulation_executor.cpp 8 | monte_carlo_simulation/simulation_object.cpp 9 | monte_carlo_simulation/initialize_monte_carlo_parameters.cpp 10 | monte_carlo_simulation/initialize_monte_carlo_simulation.cpp 11 | 12 | spacecraft/spacecraft.cpp 13 | spacecraft/installed_components.cpp 14 | spacecraft/structure/structure.cpp 15 | spacecraft/structure/kinematics_parameters.cpp 16 | spacecraft/structure/residual_magnetic_moment.cpp 17 | spacecraft/structure/surface.cpp 18 | spacecraft/structure/initialize_structure.cpp 19 | 20 | ground_station/ground_station.cpp 21 | 22 | hils/hils_port_manager.cpp 23 | 24 | multiple_spacecraft/inter_spacecraft_communication.cpp 25 | multiple_spacecraft/relative_information.cpp 26 | ) 27 | 28 | include(../../common.cmake) 29 | -------------------------------------------------------------------------------- /example/src/simulation/spacecraft/sample_spacecraft.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file sample_spacecraft.cpp 3 | * @brief An example of user side spacecraft class 4 | */ 5 | 6 | #include "sample_spacecraft.hpp" 7 | 8 | #include 9 | #include 10 | 11 | #include "sample_components.hpp" 12 | 13 | namespace s2e::sample { 14 | 15 | SampleSpacecraft::SampleSpacecraft(const simulation::SimulationConfiguration* simulation_configuration, 16 | const environment::GlobalEnvironment* global_environment, const unsigned int spacecraft_id) 17 | : spacecraft::Spacecraft(simulation_configuration, global_environment, spacecraft_id) { 18 | sample_components_ = 19 | new SampleComponents(dynamics_, structure_, local_environment_, global_environment, simulation_configuration, &clock_generator_, spacecraft_id); 20 | components_ = sample_components_; 21 | } 22 | 23 | } // namespace s2e::sample 24 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/angular_velocity_observer.ini: -------------------------------------------------------------------------------- 1 | [COMPONENT_BASE] 2 | prescaler = 1 3 | 4 | [SENSOR_BASE_ANGULAR_VELOCITY_OBSERVER] 5 | // Constant bias noise at component frame [rad/s] 6 | constant_bias_c_rad_s(0) = 0.0 7 | constant_bias_c_rad_s(1) = 0.0 8 | constant_bias_c_rad_s(2) = 0.0 9 | 10 | // Standard deviation for random walk noise[rad/s] 11 | random_walk_standard_deviation_c_rad_s(0) = 0.0 12 | random_walk_standard_deviation_c_rad_s(1) = 0.0 13 | random_walk_standard_deviation_c_rad_s(2) = 0.0 14 | 15 | // Limit of random walk noise[rad/s] 16 | random_walk_limit_c_rad_s(0) = 0.0 17 | random_walk_limit_c_rad_s(1) = 0.0 18 | random_walk_limit_c_rad_s(2) = 0.0 19 | 20 | // Standard deviation of normal random noise[rad/s] 21 | normal_random_standard_deviation_c_rad_s(0) = 1e-3 22 | normal_random_standard_deviation_c_rad_s(1) = 1e-3 23 | normal_random_standard_deviation_c_rad_s(2) = 1e-3 24 | 25 | // Range [rad/s] 26 | range_to_constant_rad_s = 5.0 // smaller than range_to_zero 27 | range_to_zero_rad_s = 10.0 28 | -------------------------------------------------------------------------------- /src/utilities/quantization.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file quantization.hpp 3 | * @brief Functions for quantization 4 | */ 5 | 6 | #ifndef S2E_LIBRARY_UTILITIES_QUANTIZATION_HPP_ 7 | #define S2E_LIBRARY_UTILITIES_QUANTIZATION_HPP_ 8 | 9 | namespace s2e::utilities { 10 | 11 | /** 12 | * @fn quantization 13 | * @brief Default constructor without any initialization 14 | * @param [in] continuous_number: Target number 15 | * @param [in] resolution: Resolution of the quantization 16 | * @return Quantized value (double) 17 | */ 18 | double quantization(const double continuous_number, const double resolution); 19 | 20 | /** 21 | * @fn quantization_float 22 | * @brief Default constructor without any initialization 23 | * @param [in] continuous_number: Target number 24 | * @param [in] resolution: Resolution of the quantization 25 | * @return Quantized value (float) 26 | */ 27 | float quantization_float(const double continuous_number, const double resolution); 28 | 29 | } // namespace s2e::utilities 30 | 31 | #endif // S2E_LIBRARY_UTILITIES_QUANTIZATION_HPP_ 32 | -------------------------------------------------------------------------------- /src/math_physics/math/test_s2e_math.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file test_quaternion.cpp 3 | * @brief Test codes for Quaternion class with GoogleTest 4 | */ 5 | #include 6 | 7 | #include "constants.hpp" 8 | #include "s2e_math.hpp" 9 | 10 | /** 11 | * @brief Test for constructor with number 12 | */ 13 | TEST(S2eMath, WrapTo2Pi) { 14 | const double accuracy = 1.0e-7; 15 | 16 | double input_angle_rad = 0.0; 17 | double wrapped_angle_rad = s2e::math::WrapTo2Pi(input_angle_rad); 18 | EXPECT_NEAR(0.0, wrapped_angle_rad, accuracy); 19 | 20 | input_angle_rad = -1.0e-5; 21 | wrapped_angle_rad = s2e::math::WrapTo2Pi(input_angle_rad); 22 | EXPECT_NEAR(s2e::math::tau + input_angle_rad, wrapped_angle_rad, accuracy); 23 | 24 | input_angle_rad = s2e::math::tau + 1.0e-5; 25 | wrapped_angle_rad = s2e::math::WrapTo2Pi(input_angle_rad); 26 | EXPECT_NEAR(1.0e-5, wrapped_angle_rad, accuracy); 27 | 28 | input_angle_rad = 10 * s2e::math::tau + 1.0e-5; 29 | wrapped_angle_rad = s2e::math::WrapTo2Pi(input_angle_rad); 30 | EXPECT_NEAR(1.0e-5, wrapped_angle_rad, accuracy); 31 | } 32 | -------------------------------------------------------------------------------- /src/components/base/interface_gpio_component.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file interface_gpio_component.hpp 3 | * @brief Interface class for components which have GPIO port 4 | */ 5 | 6 | #ifndef S2E_COMPONENTS_BASE_CLASSES_INTERFACE_GPIO_COMPONENT_HPP_ 7 | #define S2E_COMPONENTS_BASE_CLASSES_INTERFACE_GPIO_COMPONENT_HPP_ 8 | 9 | namespace s2e::components { 10 | 11 | /** 12 | * @class IGPIOCompo 13 | * @brief Interface class for components which have GPIO port 14 | */ 15 | class IGPIOCompo { 16 | public: 17 | /** 18 | * @fn ~IGPIOCompo 19 | * @brief Destructor 20 | */ 21 | virtual ~IGPIOCompo(){}; 22 | 23 | /** 24 | * @fn GpioStateChanged 25 | * @brief Pure virtual function called at the GPIO state is changed like interrupt function. 26 | * @param[in] port_id: GPIO port ID 27 | * @param[in] is_positive_edge: Flag to express positive edge or not 28 | */ 29 | virtual void GpioStateChanged(const int port_id, const bool is_positive_edge) = 0; 30 | }; 31 | 32 | } // namespace s2e::components 33 | 34 | #endif // S2E_COMPONENTS_BASE_CLASSES_INTERFACE_GPIO_COMPONENT_HPP_ 35 | -------------------------------------------------------------------------------- /src/simulation/multiple_spacecraft/inter_spacecraft_communication.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file inter_spacecraft_communication.h 3 | * @brief Base class of inter satellite communication 4 | */ 5 | 6 | #ifndef S2E_SIMULATION_MULTIPLE_SPACECRAFT_INTER_SPACECRAFT_COMMUNICATION_HPP_ 7 | #define S2E_SIMULATION_MULTIPLE_SPACECRAFT_INTER_SPACECRAFT_COMMUNICATION_HPP_ 8 | 9 | #include "../simulation_configuration.hpp" 10 | 11 | namespace s2e::simulation { 12 | 13 | /** 14 | * @class InterSpacecraftCommunication 15 | * @brief Base class of inter satellite communication 16 | */ 17 | class InterSpacecraftCommunication { 18 | public: 19 | /** 20 | * @fn InterSpacecraftCommunication 21 | * @brief Constructor 22 | */ 23 | InterSpacecraftCommunication(const SimulationConfiguration* simulation_configuration); 24 | /** 25 | * @fn ~InterSpacecraftCommunication 26 | * @brief Destructor 27 | */ 28 | ~InterSpacecraftCommunication(); 29 | 30 | private: 31 | }; 32 | 33 | } // namespace s2e::simulation 34 | 35 | #endif // S2E_SIMULATION_MULTIPLE_SPACECRAFT_INTER_SPACECRAFT_COMMUNICATION_HPP_ 36 | -------------------------------------------------------------------------------- /ExtLibraries/lunar_gravity_field/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(lunar_gravity_field) 2 | 3 | cmake_minimum_required(VERSION 3.18) 4 | 5 | include(FetchContent) 6 | 7 | set(LUNAR_GRAVITY_FIELD_INSTALL_DIR ${SETTINGS_DIR}/environment/gravity_field) 8 | 9 | set(LUNAR_GRAVITY_FIELD_URL_BASE https://pds-geosciences.wustl.edu/grail/grail-l-lgrs-5-rdr-v1/grail_1001/shadr) 10 | set(LUNAR_GRAVITY_FIELD_FILE gggrx_1200a_sha.tab) 11 | set(LUNAR_GRAVITY_FIELD_TMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/tmp) 12 | 13 | function(download_file_without_validate base_url file) 14 | message("downloading ${file}") 15 | FetchContent_Declare( 16 | ${file} 17 | SOURCE_DIR ${LUNAR_GRAVITY_FIELD_TMP_DIR} 18 | URL ${base_url}/${file} 19 | DOWNLOAD_NO_EXTRACT true 20 | ) 21 | FetchContent_MakeAvailable(${file}) 22 | endfunction() 23 | 24 | ## download table 25 | download_file_without_validate(${LUNAR_GRAVITY_FIELD_URL_BASE} ${LUNAR_GRAVITY_FIELD_FILE}) 26 | 27 | ## install table 28 | install(FILES ${LUNAR_GRAVITY_FIELD_TMP_DIR}/${LUNAR_GRAVITY_FIELD_FILE} 29 | DESTINATION ${LUNAR_GRAVITY_FIELD_INSTALL_DIR} 30 | ) 31 | -------------------------------------------------------------------------------- /src/math_physics/numerical_integration/interface_ode.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file interface_ode.hpp 3 | * @brief Interface class for ordinary differential equation 4 | */ 5 | 6 | #ifndef S2E_LIBRARY_NUMERICAL_INTEGRATION_INTERFACE_ODE_HPP_ 7 | #define S2E_LIBRARY_NUMERICAL_INTEGRATION_INTERFACE_ODE_HPP_ 8 | 9 | #include "../math/vector.hpp" 10 | 11 | namespace s2e::numerical_integration { 12 | 13 | /** 14 | * @class InterfaceOde 15 | * @brief Interface class for ordinary differential equation 16 | */ 17 | template 18 | class InterfaceOde { 19 | public: 20 | /** 21 | * @fn DerivativeFunction 22 | * @brief Pure virtual function to define the difference equation 23 | * @param [in] independent_variable: Independent variable 24 | * @param [in] state: State vector 25 | * @return Differentiated value of state vector 26 | */ 27 | virtual math::Vector DerivativeFunction(const double independent_variable, const math::Vector& state) const = 0; 28 | }; 29 | 30 | } // namespace s2e::numerical_integration 31 | 32 | #endif // S2E_LIBRARY_NUMERICAL_INTEGRATION_INTERFACE_ODE_HPP_ 33 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/star_sensor.ini: -------------------------------------------------------------------------------- 1 | [STAR_SENSOR_1] 2 | prescaler = 10; 3 | 4 | // Quaternion from body frame to component frame 5 | // The sight direction is X-axis at component frame 6 | quaternion_b2c(0) = 0 7 | quaternion_b2c(1) = 0 8 | quaternion_b2c(2) = 0 9 | quaternion_b2c(3) = 1 10 | 11 | // Standard deviation of normal random noise at orthogonal direction of sight[rad] 12 | standard_deviation_orthogonal_direction_rad = 0 13 | 14 | // Standard deviation of normal random noise at sight direction [rad] 15 | standard_deviation_sight_direction_rad = 0 16 | 17 | // Output delay [sec] 18 | output_delay_s = 1 19 | 20 | // Output Interval [sec] 21 | output_interval_s = 1 22 | 23 | // Sun exclusion harf angle [deg] 24 | sun_exclusion_angle_deg = 10 25 | 26 | // Earth exclusion harf angle [deg] 27 | earth_exclusion_angle_deg = 10 28 | 29 | // Moon forbidden harf angle [deg] 30 | moon_exclusion_angle_deg = 10 31 | 32 | // Limit angular rate to capture stars[deg/s] 33 | angular_rate_limit_deg_s = 10.0 34 | 35 | [POWER_PORT] 36 | minimum_voltage_V = 3.3 // V 37 | assumed_power_consumption_W = 1.0 //W 38 | -------------------------------------------------------------------------------- /scripts/Plot/gen_graph.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | 3 | csv="$1" 4 | for graph in $(cat graph.toml | tomlq -c '.graph[]'); do 5 | #echo "$graph" | jq -c ".value[]" 6 | title=$(echo "$graph" | jq -rc ".title") 7 | typ=$(echo "$graph" | jq -rc ".type") 8 | unit=$(echo "$graph" | jq -rc ".unit") 9 | 10 | for v in $(echo "$graph" | jq -rc ".value[]"); do 11 | cname="$typ($v)" # [$unit]" 12 | header=$(head -n1 "$csv") 13 | 14 | # get column number 15 | cnum=$(echo "$header" | sed 's/,/\n/g' | sed -n "/$cname/=") 16 | # generate each plot command 17 | echo "\"${csv}\" using 1:$cnum with lines title \"${title}($v)\"" >> tmp 18 | done 19 | echo "" >> tmp 20 | 21 | # generate script 22 | f="${title}.plt" 23 | echo 'set datafile separator ","' > $f 24 | ## concatinate to single plot 25 | echo -n 'plot ' >> $f 26 | cat tmp | sed -z 's/\n\n//g' | sed -z 's/\n/, \\\n /g' >> $f 27 | rm tmp 28 | 29 | # generate png 30 | echo "set term png" > tmp 31 | echo "set output \"imgs/${title}.png\"" >> tmp 32 | cat tmp $f > tmp.plt 33 | rm tmp 34 | cat tmp.plt 35 | 36 | mkdir -p ./imgs 37 | gnuplot tmp.plt 38 | rm tmp.plt 39 | done 40 | -------------------------------------------------------------------------------- /src/simulation/spacecraft/structure/initialize_structure.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file initialize_structure.hpp 3 | * @brief Initialize functions for spacecraft structure 4 | */ 5 | 6 | #ifndef S2E_SIMULATION_SPACECRAFT_STRUCTURE_INITIALIZE_STRUCTURE_HPP_ 7 | #define S2E_SIMULATION_SPACECRAFT_STRUCTURE_INITIALIZE_STRUCTURE_HPP_ 8 | 9 | #include 10 | 11 | namespace s2e::spacecraft { 12 | 13 | /** 14 | * @fn InitKinematicsParameters 15 | * @brief Initialize the kinematics parameters with an ini file 16 | */ 17 | KinematicsParameters InitKinematicsParameters(std::string file_name); 18 | /** 19 | * @fn InitSurfaces 20 | * @brief Initialize the multiple surfaces with an ini file 21 | */ 22 | std::vector InitSurfaces(std::string file_name); 23 | /** 24 | * @fn InitResidualMagneticMoment 25 | * @brief Initialize the RMM(Residual Magnetic Moment) parameters with an ini file 26 | */ 27 | ResidualMagneticMoment InitResidualMagneticMoment(std::string file_name); 28 | 29 | } // namespace s2e::spacecraft 30 | 31 | #endif // S2E_SIMULATION_SPACECRAFT_STRUCTURE_INITIALIZE_STRUCTURE_HPP_ 32 | -------------------------------------------------------------------------------- /src/logger/loggable.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file loggable.hpp 3 | * @brief Abstract class to manage logging 4 | */ 5 | 6 | #ifndef S2E_LIBRARY_LOGGER_LOGGABLE_HPP_ 7 | #define S2E_LIBRARY_LOGGER_LOGGABLE_HPP_ 8 | 9 | #include 10 | 11 | #include "log_utility.hpp" // This is not necessary but include here for convenience 12 | 13 | namespace s2e::logger { 14 | 15 | /** 16 | * @class ILoggable 17 | * @brief Abstract class to manage logging 18 | * @note We wan to make this as an interface class, but to handle enable flag, we made this as abstract class 19 | */ 20 | class ILoggable { 21 | public: 22 | /** 23 | * @fn GetLogHeader 24 | * @brief Get headers to write in CSV output file 25 | * @return The headers 26 | */ 27 | virtual std::string GetLogHeader() const = 0; 28 | 29 | /** 30 | * @fn GetLogValue 31 | * @brief Get values to write in CSV output file 32 | * @return The output values 33 | */ 34 | virtual std::string GetLogValue() const = 0; 35 | 36 | bool is_log_enabled_ = true; //!< Log enable flag 37 | }; 38 | 39 | } // namespace s2e::logger 40 | 41 | #endif // S2E_LIBRARY_LOGGER_LOGGABLE_HPP_ 42 | -------------------------------------------------------------------------------- /example/CMakeSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Win32", 5 | "generator": "Visual Studio 17 2022", 6 | "configurationType": "Debug", 7 | "inheritEnvironments": [ 8 | "msvc_x86" 9 | ], 10 | "includePath": [ 11 | "${workspaceRoot}\\src" 12 | ], 13 | "buildRoot": "${thisFileDir}\\CMakeBuilds", 14 | "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", 15 | "cmakeCommandArgs": "", 16 | "buildCommandArgs": "", 17 | "ctestCommandArgs": "" 18 | }, 19 | { 20 | "name": "Win64", 21 | "generator": "Visual Studio 17 2022 Win64", 22 | "configurationType": "Debug", 23 | "inheritEnvironments": [ 24 | "msvc_x64" 25 | ], 26 | "includePath": [ 27 | "${workspaceRoot}\\src" 28 | ], 29 | "buildRoot": "${thisFileDir}\\CMakeBuilds", 30 | "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", 31 | "cmakeCommandArgs": "", 32 | "buildCommandArgs": "", 33 | "ctestCommandArgs": "" 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /src/math_physics/randomization/minimal_standard_linear_congruential_generator.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file randomize0.cpp 3 | * @brief Randomization with Park and Miller's multiplicative congruential method 4 | * @note ran0 function in "NUMERICAL RECIPES in C, p.206" 5 | */ 6 | 7 | #include "minimal_standard_linear_congruential_generator.hpp" 8 | using s2e::randomization::MinimalStandardLcg; 9 | 10 | #include 11 | 12 | const double MinimalStandardLcg::a_m_ = 1.0 / MinimalStandardLcg::kM; 13 | 14 | MinimalStandardLcg::MinimalStandardLcg() : seed_(0xdeadbeef) {} 15 | 16 | MinimalStandardLcg::MinimalStandardLcg(const long seed) : seed_(seed) { 17 | if (seed == 0) { 18 | throw std::invalid_argument("MinimalStandardLcg:: seed is 0."); 19 | } 20 | } 21 | void MinimalStandardLcg::Initialize(const long seed) { 22 | if (seed == 0) { 23 | throw std::invalid_argument("MinimalStandardLcg:: seed is 0."); 24 | } 25 | seed_ = seed; 26 | } 27 | 28 | MinimalStandardLcg::operator double() { 29 | long k = seed_ / q_; 30 | seed_ = kA * (seed_ - k * q_) - r_ * k; 31 | if (seed_ < 0) { 32 | seed_ += kM; 33 | } 34 | return a_m_ * seed_; 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Intelligent Space Systems Laboratory, The University of Tokyo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/logger/initialize_log.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file initialize_log.cpp 3 | * @brief Initialize function for Log output 4 | */ 5 | 6 | #include "initialize_log.hpp" 7 | 8 | #include "../setting_file_reader/initialize_file_access.hpp" 9 | 10 | namespace s2e::logger { 11 | 12 | Logger* InitLog(std::string file_name) { 13 | setting_file_reader::IniAccess ini_file(file_name); 14 | 15 | std::string log_file_path = ini_file.ReadString("SIMULATION_SETTINGS", "log_file_save_directory"); 16 | bool log_ini = ini_file.ReadEnable("SIMULATION_SETTINGS", "save_initialize_files"); 17 | 18 | Logger* log = new Logger("default.csv", log_file_path, file_name, log_ini, true); 19 | 20 | return log; 21 | } 22 | 23 | Logger* InitMonteCarloLog(std::string file_name, bool enable) { 24 | setting_file_reader::IniAccess ini_file(file_name); 25 | 26 | std::string log_file_path = ini_file.ReadString("SIMULATION_SETTINGS", "log_file_save_directory"); 27 | bool log_ini = ini_file.ReadEnable("SIMULATION_SETTINGS", "save_initialize_files"); 28 | 29 | Logger* log = new Logger("monte_carlo.csv", log_file_path, file_name, log_ini, enable); 30 | 31 | return log; 32 | } 33 | 34 | } // namespace s2e::logger 35 | -------------------------------------------------------------------------------- /example/src/simulation/spacecraft/sample_port_configuration.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file sample_port_configuration.hpp 3 | * @brief An example of port configuration management 4 | */ 5 | 6 | #ifndef S2E_SIMULATION_SAMPLE_SPACECRAFT_SAMPLE_PORT_CONFIGURATION_HPP_ 7 | #define S2E_SIMULATION_SAMPLE_SPACECRAFT_SAMPLE_PORT_CONFIGURATION_HPP_ 8 | 9 | namespace s2e::sample { 10 | 11 | /** 12 | * @enum PowerPortConfig 13 | * @brief ID list of electrical power switch ports 14 | * @details Register sequential same with port_id. Use kNone1, kNone2 if the number is skipped. 15 | */ 16 | enum class PowerPortConfig { 17 | kObcBus, 18 | kGyro5v, 19 | kComponentMax //!< Maximum port number. Do not remove. Place on the bottom. 20 | }; 21 | 22 | /** 23 | * @enum UARTPortConfig 24 | * @brief ID list of serial communication ports with UART 25 | * @details Register sequential same with port_id. Use kNone1, kNone2 if the number is skipped. 26 | */ 27 | enum class UARTPortConfig { 28 | kGyro = 0, 29 | kUartComponentMax //!< Maximum port number. Do not remove. Place on the bottom. 30 | }; 31 | 32 | } // namespace s2e::sample 33 | 34 | #endif // S2E_SIMULATION_SAMPLE_SPACECRAFT_SAMPLE_PORT_CONFIGURATION_HPP_ 35 | -------------------------------------------------------------------------------- /scripts/Docker_Ubuntu/setup_docker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 環境操作用ユーティリティ 4 | 5 | function build { 6 | echo "Dockerイメージを作成します" 7 | # docker build -t issl:latest . 8 | cd .. 9 | docker build -f Docker_Ubuntu/Dockerfile -t issl:latest . 10 | cd ./Docker_Ubuntu 11 | } 12 | 13 | # function run { 14 | # echo "イメージからコンテナを作成します" 15 | # docker run -it -d --cap-add=SYS_PTRACE --security-opt="seccomp=unconfined" -v /$(realpath ../../../../work):/home/s2e/work --name issl-1 -p 2222:22 issl:latest 16 | # } 17 | 18 | function enter { 19 | echo "コンテナ内のbashにアタッチします" 20 | winpty docker run -it --rm -p 2222:22 -v /$(realpath ../../../../work):/home/s2e/work issl:latest /bin/bash 21 | } 22 | 23 | function run_core { 24 | docker run -it -d --cap-add=SYS_PTRACE --security-opt="seccomp=unconfined" -v /$(realpath ../../../s2e-core):/home/s2e/work/s2e-core --name issl-1 -p 2222:22 issl:latest 25 | } 26 | 27 | subcommand="$1" 28 | shift 29 | 30 | case $subcommand in 31 | build) 32 | build 33 | ;; 34 | run_core) 35 | run_core 36 | ;; 37 | enter) 38 | enter 39 | ;; 40 | *) 41 | echo "default" 42 | ;; 43 | esac 44 | -------------------------------------------------------------------------------- /.github/workflows/validate-scripts.yml: -------------------------------------------------------------------------------- 1 | name: Validate scripts 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - develop 8 | pull_request: 9 | paths: 10 | - '.github/workflows/validate-scripts.yml' 11 | - 'scripts/**' 12 | 13 | jobs: 14 | validate_script: 15 | runs-on: ubuntu-latest 16 | strategy: 17 | fail-fast: false 18 | matrix: 19 | script_dir: ['./scripts/Plot'] 20 | 21 | steps: 22 | - uses: actions/checkout@v4.2.2 23 | 24 | - name: read python version from Pipfile 25 | id: python-version 26 | working-directory: ${{ matrix.script_dir }} 27 | run: | 28 | ver=$(grep python_version ./Pipfile | sed -e 's/^python_version\s=\s"\(.*\)"$/\1/') 29 | echo "version=${ver}" >> "$GITHUB_OUTPUT" 30 | 31 | - uses: actions/setup-python@v5.6.0 32 | with: 33 | python-version: ${{ steps.python-version.outputs.version }} 34 | 35 | - name: install pipenv 36 | run: pip install pipenv 37 | 38 | - name: install Plot script dependencies 39 | working-directory: ${{ matrix.script_dir }} 40 | run: | 41 | pipenv install 42 | pipenv graph 43 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/battery.ini: -------------------------------------------------------------------------------- 1 | [BATTERY_1] 2 | prescaler = 10 3 | 4 | // Number of series of the battery module 5 | number_of_series = 3 6 | 7 | // Number of parallel of the battery module 8 | number_of_parallel = 2 9 | 10 | // Current capacity of a battery cell [Ah] 11 | cell_capacity_Ah = 3.2 12 | 13 | // Polynomial approximation of the battery voltage 14 | approximation_order = 7 15 | cell_discharge_curve_coefficients(0) = 4.2 16 | cell_discharge_curve_coefficients(1)= -1.11372443 17 | cell_discharge_curve_coefficients(2)= 3.255553766 18 | cell_discharge_curve_coefficients(3)= -5.717011044 19 | cell_discharge_curve_coefficients(4)= 5.031000929 20 | cell_discharge_curve_coefficients(5)= -2.315028915 21 | cell_discharge_curve_coefficients(6)= 0.5338229034 22 | cell_discharge_curve_coefficients(7)= -0.04872142307 23 | 24 | // Initial Discharge Of Depth (DoD) of the battery module 25 | initial_dod = 20.0 26 | 27 | // Constant charge current [C] 28 | constant_charge_current_rate_C = 0.2 29 | 30 | // Constant charge voltage [V] 31 | constant_voltage_charge_voltage_V = 12.3 32 | 33 | // Battery internal registance + wire/connector resistance between BAT and PCU [Ohm] 34 | battery_resistance_Ohm = 0.4 35 | -------------------------------------------------------------------------------- /src/setting_file_reader/wings_operation_file.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file wings_operation_file.hpp 3 | * @brief Classes and functions to read and manage WINGS's operation file (.ops) 4 | */ 5 | 6 | #ifndef S2E_LIBRARY_INITIALIZE_WINGS_OPERATION_FILE_HPP_ 7 | #define S2E_LIBRARY_INITIALIZE_WINGS_OPERATION_FILE_HPP_ 8 | 9 | #include 10 | #include 11 | 12 | #include "c2a_command_database.hpp" 13 | 14 | namespace s2e::setting_file_reader { 15 | 16 | /** 17 | * @class WingsOperationFile 18 | * @brief A class to handle WINGS operation file 19 | */ 20 | class WingsOperationFile { 21 | public: 22 | /** 23 | * @fn WingsOperationFile 24 | * @brief Constructor 25 | * @param[in] file_path: File path of the operation file 26 | */ 27 | WingsOperationFile(const std::string file_path); 28 | 29 | /** 30 | * @fn GetLatestLine 31 | * @brief Return latest line command 32 | */ 33 | std::string GetLatestLine(); 34 | 35 | private: 36 | std::vector lines_; //!!< List of read operation command line 37 | size_t line_pointer_ = 0; //!< Line pointer 38 | }; 39 | 40 | } // namespace s2e::setting_file_reader 41 | 42 | #endif // S2E_LIBRARY_INITIALIZE_WINGS_OPERATION_FILE_HPP_ 43 | -------------------------------------------------------------------------------- /src/math_physics/time_system/gps_time.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file gps_time.cpp 3 | * @brief A class to define GPS time expression 4 | */ 5 | 6 | #include "gps_time.hpp" 7 | 8 | namespace s2e::time_system { 9 | 10 | const DateTime GpsTime::kEpochOfGpsTimeInDateTime_ = DateTime("1980/1/6 00:00:00.0"); 11 | const EpochTime GpsTime::kEpochOfGpsTimeInEpochTime_ = EpochTime(kEpochOfGpsTimeInDateTime_); 12 | const EpochTime GpsTime::kLeapSecondAheadFromUtc_ = EpochTime(18, 0); //!< Leap second ahead from UTC @ May 2023 13 | 14 | void GpsTime::CalcGpsWeekTime() { 15 | EpochTime time_diff = epoch_time_ - kEpochOfGpsTimeInEpochTime_; 16 | week_ = (size_t)(time_diff.GetTime_s() / kSecondsInWeek_); 17 | elapsed_time_from_week_s_ = (double)(time_diff.GetTime_s() - week_ * kSecondsInWeek_) + time_diff.GetFraction_s(); 18 | } 19 | 20 | void GpsTime::CalcEpochTime() { 21 | size_t integer_time_s = (size_t)elapsed_time_from_week_s_; 22 | double fraction_s = elapsed_time_from_week_s_ - (double)(integer_time_s); 23 | time_t time_s = week_ * kSecondsInWeek_ + integer_time_s; 24 | EpochTime time_diff(time_s, fraction_s); 25 | 26 | epoch_time_ = kEpochOfGpsTimeInEpochTime_ + time_diff; 27 | } 28 | 29 | } // namespace s2e::time_system 30 | -------------------------------------------------------------------------------- /example/src/simulation/ground_station/sample_ground_station.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file sample_ground_station.cpp 3 | * @brief An example of user defined ground station class 4 | */ 5 | 6 | #include "sample_ground_station.hpp" 7 | 8 | #include "sample_ground_station_components.hpp" 9 | 10 | namespace s2e::sample { 11 | 12 | SampleGroundStation::SampleGroundStation(const simulation::SimulationConfiguration* configuration, const unsigned int ground_station_id) 13 | : ground_station::GroundStation(configuration, ground_station_id) { 14 | components_ = new SampleGsComponents(configuration); 15 | } 16 | 17 | SampleGroundStation::~SampleGroundStation() { delete components_; } 18 | 19 | void SampleGroundStation::LogSetup(logger::Logger& logger) { 20 | ground_station::GroundStation::LogSetup(logger); 21 | components_->CompoLogSetUp(logger); 22 | } 23 | 24 | void SampleGroundStation::Update(const environment::EarthRotation& celestial_rotation, const SampleSpacecraft& spacecraft) { 25 | ground_station::GroundStation::Update(celestial_rotation, spacecraft); 26 | components_->GetGsCalculator()->Update(spacecraft, spacecraft.GetInstalledComponents().GetAntenna(), *this, *(components_->GetAntenna())); 27 | } 28 | 29 | } // namespace s2e::sample 30 | -------------------------------------------------------------------------------- /src/utilities/slip.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file slip.hpp 3 | * @brief Functions for SLIP(Serial Line Internet Protocol) encoding 4 | */ 5 | 6 | #ifndef S2E_LIBRARY_UTILITIES_SLIP_HPP_ 7 | #define S2E_LIBRARY_UTILITIES_SLIP_HPP_ 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace s2e::utilities { 14 | 15 | /** 16 | * @fn decode_slip 17 | * @brief Decode SLIP data 18 | * @param [in] in: Input data 19 | * @return Decoded data 20 | */ 21 | std::vector decode_slip(std::vector in); 22 | /** 23 | * @fn decode_slip_with_header 24 | * @brief Decode SLIP data with Header 25 | * @param [in] in: Input data 26 | * @return Decoded data 27 | */ 28 | std::vector decode_slip_with_header(std::vector in); 29 | 30 | /** 31 | * @fn encode_slip 32 | * @brief Encode SLIP data 33 | * @param [in] in: Input data 34 | * @return Encoded data 35 | */ 36 | std::vector encode_slip(std::vector in); 37 | /** 38 | * @fn encode_slip_with_header 39 | * @brief Encode SLIP data 40 | * @param [in] in: Input data 41 | * @return Encoded data 42 | */ 43 | std::vector encode_slip_with_header(std::vector in); 44 | 45 | } // namespace s2e::utilities 46 | 47 | #endif // S2E_LIBRARY_UTILITIES_SLIP_HPP_ 48 | -------------------------------------------------------------------------------- /src/components/real/cdh/c2a_communication.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @file c2a_communication.h 3 | * @brief C2A communication functions 4 | */ 5 | 6 | #ifndef C2A_COMMUNICATION_H_ 7 | #define C2A_COMMUNICATION_H_ 8 | 9 | // If the character encoding of C2A is UTF-8, the following functions are not necessary, 10 | // and users can directory use SendFromObc_C2A and ReceivedByObc_C2A UART 11 | // TODO: Delete these functions since C2A is changed to use UTF-8 12 | 13 | // C2A communication functions 14 | int OBC_C2A_SendFromObc(int port_id, unsigned char* buffer, int offset, int length); 15 | int OBC_C2A_ReceivedByObc(int port_id, unsigned char* buffer, int offset, int length); 16 | 17 | // I2C 18 | int OBC_C2A_I2cWriteCommand(int port_id, const unsigned char i2c_address, const unsigned char* data, const unsigned char length); 19 | int OBC_C2A_I2cWriteRegister(int port_id, const unsigned char i2c_address, const unsigned char* data, const unsigned char length); 20 | int OBC_C2A_I2cReadRegister(int port_id, const unsigned char i2c_address, unsigned char* data, const unsigned char length); 21 | 22 | // GPIO 23 | int OBC_C2A_GpioWrite(int port_id, const bool is_high); 24 | bool OBC_C2A_GpioRead(int port_id); // return false when the port_id is not used 25 | 26 | #endif // C2A_COMMUNICATION_H_ 27 | -------------------------------------------------------------------------------- /src/dynamics/attitude/initialize_attitude.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file initialize_attitude.hpp 3 | * @brief Initialize function for attitude 4 | */ 5 | 6 | #ifndef S2E_DYNAMICS_ATTITUDE_INITIALIZE_ATTITUDE_HPP_ 7 | #define S2E_DYNAMICS_ATTITUDE_INITIALIZE_ATTITUDE_HPP_ 8 | 9 | #include "attitude.hpp" 10 | #include "attitude_rk4.hpp" 11 | #include "attitude_with_cantilever_vibration.hpp" 12 | #include "controlled_attitude.hpp" 13 | 14 | namespace s2e::dynamics::attitude { 15 | 16 | /** 17 | * @fn InitAttitude 18 | * @brief Initialize function for Attitude 19 | * @param [in] file_name: Path to the initialize file 20 | * @param [in] orbit: Orbit information 21 | * @param [in] local_celestial_information: Celestial information 22 | * @param [in] step_width_s: Step width [sec] 23 | * @param [in] inertia_tensor_kgm2: Inertia tensor [kg m^2] 24 | * @param [in] spacecraft_id: Satellite ID 25 | */ 26 | Attitude* InitAttitude(std::string file_name, const orbit::Orbit* orbit, const environment::LocalCelestialInformation* local_celestial_information, 27 | const double step_width_s, const math::Matrix<3, 3>& inertia_tensor_kgm2, const int spacecraft_id); 28 | 29 | } // namespace s2e::dynamics::attitude 30 | 31 | #endif // S2E_DYNAMICS_ATTITUDE_INITIALIZE_ATTITUDE_HPP_ 32 | -------------------------------------------------------------------------------- /src/components/real/aocs/reaction_wheel_ode.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @file reaction_wheel_ode.cpp 3 | * @brief Ordinary differential equation of angular velocity of reaction wheel with first-order lag 4 | */ 5 | #include "reaction_wheel_ode.hpp" 6 | 7 | #include 8 | 9 | namespace s2e::components { 10 | 11 | ReactionWheelOde::ReactionWheelOde(const double step_width_s, const double velocity_limit_rad_s, const double initial_angular_velocity_rad_s) 12 | : OrdinaryDifferentialEquation<1>(step_width_s), velocity_limit_rad_s_(velocity_limit_rad_s) { 13 | this->Setup(0.0, math::Vector<1>(initial_angular_velocity_rad_s)); 14 | } 15 | 16 | void ReactionWheelOde::DerivativeFunction(double x, const math::Vector<1> &state, math::Vector<1> &rhs) { 17 | UNUSED(x); 18 | double angular_velocity_rad_s = state[0]; 19 | 20 | // Check velocity limit 21 | if (angular_velocity_rad_s > velocity_limit_rad_s_) { 22 | if (angular_acceleration_rad_s2_ > 0.0) { 23 | angular_acceleration_rad_s2_ = 0.0; 24 | } 25 | } else if (angular_velocity_rad_s < -1.0 * velocity_limit_rad_s_) { 26 | if (angular_acceleration_rad_s2_ < 0.0) { 27 | angular_acceleration_rad_s2_ = 0.0; 28 | } 29 | } 30 | 31 | rhs[0] = angular_acceleration_rad_s2_; 32 | } 33 | 34 | } // namespace s2e::components 35 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/telescope.ini: -------------------------------------------------------------------------------- 1 | [TELESCOPE_1] 2 | // Frame conversion quaternion from body-fixed frame to component frame 3 | // +X axis of the component frame: Line of sight direction 4 | // +Y axis of the component frame: +Y axis of the image sensor 5 | // +Z axis of the component frame: +Z axis of the image sensor 6 | quaternion_b2c(0) = 0 7 | quaternion_b2c(1) = 0 8 | quaternion_b2c(2) = 0 9 | quaternion_b2c(3) = 1 10 | 11 | // Sun exclusion angle [0, 90] 12 | sun_exclusion_angle_deg = 60 13 | 14 | // Earth exclusion angle [0, 90] 15 | earth_exclusion_angle_deg = 60 16 | 17 | // Moon exclusion angle [0, 90] 18 | moon_exclusion_angle_deg = 60 19 | 20 | // Number of pixel in the X direction of image sensor 21 | x_number_of_pixel = 2048 22 | 23 | // Number of pixel in the Y direction of image sensor 24 | y_number_of_pixel = 2048 25 | 26 | // Field of View(FoV) angle per pixel in the X direction of image sensor 27 | // x_number_of_pixel * x_fov_deg_per_pixel should be smallser than 90 deg. 28 | x_fov_deg_per_pixel = 0.02 29 | 30 | // Field of View(FoV) angle per pixel in the Y direction of image sensor 31 | // y_number_of_pixel * y_fov_deg_per_pixel should be smallser than 90 deg. 32 | y_fov_deg_per_pixel = 0.02 33 | 34 | // Number of stars to show log output 35 | number_of_stars_for_log = 3 36 | -------------------------------------------------------------------------------- /src/dynamics/orbit/kepler_orbit_propagation.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file kepler_orbit_propagation.cpp 3 | * @brief Class to propagate spacecraft orbit with Kepler equation 4 | */ 5 | #include "kepler_orbit_propagation.hpp" 6 | 7 | #include 8 | 9 | #include "../../math_physics/math/s2e_math.hpp" 10 | 11 | namespace s2e::dynamics::orbit { 12 | 13 | KeplerOrbitPropagation::KeplerOrbitPropagation(const environment::CelestialInformation* celestial_information, const double current_time_jd, 14 | KeplerOrbit kepler_orbit) 15 | : Orbit(celestial_information), KeplerOrbit(kepler_orbit) { 16 | UpdateState(current_time_jd); 17 | } 18 | 19 | KeplerOrbitPropagation::~KeplerOrbitPropagation() {} 20 | 21 | void KeplerOrbitPropagation::Propagate(const double end_time_s, const double current_time_jd) { 22 | UNUSED(end_time_s); 23 | 24 | if (!is_calc_enabled_) return; 25 | 26 | UpdateState(current_time_jd); 27 | } 28 | 29 | // Private Function 30 | void KeplerOrbitPropagation::UpdateState(const double current_time_jd) { 31 | CalcOrbit(current_time_jd); 32 | spacecraft_position_i_m_ = position_i_m_; 33 | spacecraft_velocity_i_m_s_ = velocity_i_m_s_; 34 | TransformEciToEcef(); 35 | TransformEcefToGeodetic(); 36 | } 37 | 38 | } // namespace s2e::dynamics::orbit 39 | -------------------------------------------------------------------------------- /src/math_physics/atmosphere/harris_priester_model.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file harris_priester_model.hpp 3 | * @brief Harris-Priester earth's atmospheric density model 4 | * @note Ref: O. Montenbruck and E. Gill, Satellite Orbits, Chp. 3.5 5 | */ 6 | #ifndef S2E_LIBRARY_HARRIS_PRIESTER_MODEL_HPP_ 7 | #define S2E_LIBRARY_HARRIS_PRIESTER_MODEL_HPP_ 8 | 9 | #include 10 | #include 11 | 12 | namespace s2e::atmosphere { 13 | 14 | /** 15 | * @fn CalcAirDensityWithHarrisPriester 16 | * @brief Calculate atmospheric density with Harris-Priester method 17 | * @param [in] geodetic_position: Spacecraft geodetic position 18 | * @param [in] sun_direction_eci: Sun direction unit vector in ECI frame 19 | * @param [in] f10_7: F10.7 radiation index (not used now) 20 | * @param [in] exponent_parameter: n in the equation. n=2 for low inclination orbit and n=6 for polar orbit. 21 | * @return Atmospheric density [kg/m^3] 22 | */ 23 | double CalcAirDensityWithHarrisPriester_kg_m3(const geodesy::GeodeticPosition geodetic_position, const math::Vector<3> sun_direction_eci, 24 | const double f10_7 = 100.0, const double exponent_parameter = 4); 25 | 26 | } // namespace s2e::atmosphere 27 | 28 | #endif // S2E_LIBRARY_HARRIS_PRIESTER_HPP_ 29 | -------------------------------------------------------------------------------- /example/src/simulation/spacecraft/sample_spacecraft.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file sample_spacecraft.hpp 3 | * @brief An example of user side spacecraft class 4 | */ 5 | 6 | #ifndef S2E_SIMULATION_SAMPLE_SPACECRAFT_SAMPLE_SPACECRAFT_HPP_ 7 | #define S2E_SIMULATION_SAMPLE_SPACECRAFT_SAMPLE_SPACECRAFT_HPP_ 8 | 9 | #include 10 | 11 | #include "sample_components.hpp" 12 | 13 | class SampleComponents; 14 | 15 | namespace s2e::sample { 16 | 17 | /** 18 | * @class SampleSpacecraft 19 | * @brief An example of user side spacecraft class 20 | */ 21 | class SampleSpacecraft : public spacecraft::Spacecraft { 22 | public: 23 | /** 24 | * @fn SampleSpacecraft 25 | * @brief Constructor 26 | */ 27 | SampleSpacecraft(const simulation::SimulationConfiguration* simulation_configuration, const environment::GlobalEnvironment* global_environment, 28 | const unsigned int spacecraft_id); 29 | 30 | /** 31 | * @fn GetInstalledComponents 32 | * @brief Get components installed on the spacecraft 33 | */ 34 | inline const SampleComponents& GetInstalledComponents() const { return *sample_components_; } 35 | 36 | private: 37 | SampleComponents* sample_components_; 38 | }; 39 | 40 | } // namespace s2e::sample 41 | 42 | #endif // S2E_SIMULATION_SAMPLE_SPACECRAFT_SAMPLE_SPACECRAFT_HPP_ 43 | -------------------------------------------------------------------------------- /scripts/Mac/download_cspice_Mac.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # set variables 4 | DIR_CSPICE=../../../ßExtLibraries/cspice 5 | DIR_TMP=./tmp 6 | URL_CSPICE=https://naif.jpl.nasa.gov/pub/naif/toolkit/C/MacIntel_OSX_AppleC_32bit/packages/ 7 | URL_KERNEL=https://naif.jpl.nasa.gov/pub/naif/generic_kernels/ 8 | 9 | # make directory 10 | mkdir -p $DIR_TMP 11 | mkdir -p $DIR_CSPICE/generic_kernels/lsk 12 | mkdir -p $DIR_CSPICE/generic_kernels/pck 13 | mkdir -p $DIR_CSPICE/generic_kernels/spk/planets 14 | mkdir -p $DIR_CSPICE/cspice_unix/ 15 | 16 | # download generic kernels 17 | curl $URL_KERNEL/lsk/a_old_versions/naif0010.tls > $DIR_CSPICE/generic_kernels/lsk/naif0010.tls 18 | curl $URL_KERNEL/pck/de-403-masses.tpc > $DIR_CSPICE/generic_kernels/pck/de-403-masses.tpc 19 | curl $URL_KERNEL/pck/gm_de431.tpc > $DIR_CSPICE/generic_kernels/pck/gm_de431.tpc 20 | curl $URL_KERNEL/pck/pck00010.tpc > $DIR_CSPICE/generic_kernels/pck/pck00010.tpc 21 | curl $URL_KERNEL/spk/planets/de430.bsp > $DIR_CSPICE/generic_kernels/spk/planets/de430.bsp 22 | 23 | # download and unzip cspice.tar.Z 24 | curl $URL_CSPICE/cspice.tar.Z > $DIR_TMP/cspice.tar.Z 25 | tar -zxvf $DIR_TMP/cspice.tar.Z -C $DIR_TMP 26 | 27 | # move include and lib directory 28 | cp -r $DIR_TMP/cspice/include $DIR_CSPICE 29 | cp -r $DIR_TMP/cspice/lib $DIR_CSPICE/cspice_unix/lib 30 | 31 | # delete tmp file 32 | rm -r $DIR_TMP -------------------------------------------------------------------------------- /src/math_physics/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(MATH_PHYSICS) 2 | cmake_minimum_required(VERSION 3.13) 3 | 4 | add_library(${PROJECT_NAME} OBJECT 5 | atmosphere/simple_air_density_model.cpp 6 | atmosphere/harris_priester_model.cpp 7 | atmosphere/wrapper_nrlmsise00.cpp 8 | 9 | geodesy/geodetic_position.cpp 10 | 11 | geomagnetic/igrf.cpp 12 | 13 | gnss/sp3_file_reader.cpp 14 | gnss/gnss_satellite_number.cpp 15 | gnss/antex_file_reader.cpp 16 | gnss/bias_sinex_file_reader.cpp 17 | 18 | gravity/gravity_potential.cpp 19 | 20 | randomization/global_randomization.cpp 21 | randomization/normal_randomization.cpp 22 | randomization/minimal_standard_linear_congruential_generator.cpp 23 | randomization/minimal_standard_linear_congruential_generator_with_shuffle.cpp 24 | 25 | math/quaternion.cpp 26 | math/vector.cpp 27 | math/s2e_math.cpp 28 | math/interpolation.cpp 29 | 30 | optics/gaussian_beam_base.cpp 31 | 32 | orbit/orbital_elements.cpp 33 | orbit/kepler_orbit.cpp 34 | orbit/relative_orbit_models.cpp 35 | orbit/interpolation_orbit.cpp 36 | orbit/sgp4/sgp4ext.cpp 37 | orbit/sgp4/sgp4io.cpp 38 | orbit/sgp4/sgp4unit.cpp 39 | 40 | planet_rotation/moon_rotation_utilities.cpp 41 | 42 | time_system/date_time_format.cpp 43 | time_system/epoch_time.cpp 44 | time_system/gps_time.cpp 45 | ) 46 | 47 | include(../../common.cmake) 48 | -------------------------------------------------------------------------------- /src/math_physics/geomagnetic/igrf.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file igrf.h 3 | * @brief Functions for IGRF (International Geo-magnetic reference frame) calculation 4 | * @note The most of this code was copied from https://www.gsj.jp/data/openfile/no0423/index.html 5 | */ 6 | 7 | #ifndef __igrf_H__ 8 | #define __igrf_H__ 9 | 10 | extern double testglobal[3]; 11 | 12 | void set_file_path(const char *fname); 13 | void field(double are, double aflat, double ara, int maxoda); 14 | void tcoef(double *agh, double *aght, double atzero, int kexta, double aext[3]); 15 | void tyear(double ayear); 16 | void mfldg(double alat, double alon, double ahi, double *ax, double *ay, double *az, double *af); 17 | void mfldc(double athe, double alon, double ar, double *ax, double *ay, double *az, double *af); 18 | void gcomp(double *axg, double *ayg, double *azg); 19 | void gigrf(int gen, double year); 20 | void igrfc(double fido, double fkeido, double hght, double *tf); 21 | void igrfresult(double *mag, double *theta); 22 | void igrfm(double fm[6]); 23 | void sigrf(double year); 24 | void sdgrf(double year); 25 | void spgrf(double year); 26 | void igrfelement(double *mag, double *thetarad); 27 | int TransMagaxisToECI(const double *mag, double *pos, double lonrad, double thetarad, double gmst); 28 | void IgrfCalc(double decyear, double latrad, double lonrad, double alt, double side, double *mag); 29 | 30 | #endif //__igrf_H__ -------------------------------------------------------------------------------- /scripts/Docker_Ubuntu/download_cspice_Linux_gcc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd `dirname $0` 3 | 4 | # set variables 5 | DIR_CSPICE=../../../ExtLibraries/cspice 6 | DIR_TMP=./tmp 7 | URL_CSPICE=https://naif.jpl.nasa.gov/pub/naif/toolkit/C/PC_Linux_GCC_32bit/packages/ 8 | URL_KERNEL=https://naif.jpl.nasa.gov/pub/naif/generic_kernels/ 9 | 10 | # make directory 11 | mkdir -p $DIR_TMP 12 | mkdir -p $DIR_CSPICE/generic_kernels/lsk 13 | mkdir -p $DIR_CSPICE/generic_kernels/pck 14 | mkdir -p $DIR_CSPICE/generic_kernels/spk/planets 15 | mkdir -p $DIR_CSPICE/cspice_unix/ 16 | 17 | # download generic kernels 18 | curl $URL_KERNEL/lsk/a_old_versions/naif0010.tls > $DIR_CSPICE/generic_kernels/lsk/naif0010.tls 19 | curl $URL_KERNEL/pck/de-403-masses.tpc > $DIR_CSPICE/generic_kernels/pck/de-403-masses.tpc 20 | curl $URL_KERNEL/pck/gm_de431.tpc > $DIR_CSPICE/generic_kernels/pck/gm_de431.tpc 21 | curl $URL_KERNEL/pck/pck00010.tpc > $DIR_CSPICE/generic_kernels/pck/pck00010.tpc 22 | curl $URL_KERNEL/spk/planets/de430.bsp > $DIR_CSPICE/generic_kernels/spk/planets/de430.bsp 23 | 24 | # download and unzip cspice.tar.Z 25 | curl $URL_CSPICE/cspice.tar.Z > $DIR_TMP/cspice.tar.Z 26 | tar -zxvf $DIR_TMP/cspice.tar.Z -C $DIR_TMP 27 | 28 | # move include and lib directory 29 | cp -r $DIR_TMP/cspice/include $DIR_CSPICE 30 | cp -r $DIR_TMP/cspice/lib $DIR_CSPICE/cspice_unix/lib 31 | 32 | # delete tmp file 33 | rm -r $DIR_TMP 34 | -------------------------------------------------------------------------------- /.github/workflows/check-format.yml: -------------------------------------------------------------------------------- 1 | name: check format 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - develop 8 | pull_request: 9 | paths: 10 | - '.github/workflows/check-format.yml' 11 | - '.clang-format' 12 | - 'src/**' 13 | 14 | jobs: 15 | clang-format: 16 | runs-on: ubuntu-latest 17 | 18 | steps: 19 | - uses: actions/checkout@v4.2.2 20 | with: 21 | fetch-depth: 2 22 | 23 | - name: install clang-format 24 | run: | 25 | sudo apt-get update 26 | sudo apt-get install -y clang-format 27 | clang-format --version 28 | 29 | - name: check clang-format version 30 | run: | 31 | clang-format --version 32 | md5sum "$(which git-clang-format)" 33 | head "$(which git-clang-format)" 34 | 35 | - name: check format(push) 36 | if: github.event_name == 'push' 37 | run: | 38 | git-clang-format --commit HEAD^ --diff | tee format.patch 39 | 40 | - name: check format(pull_request) 41 | if: github.event_name == 'pull_request' 42 | run: | 43 | git-clang-format --commit ${{ github.event.pull_request.base.sha }} --diff | tee format.patch 44 | 45 | - name: check 46 | run: | 47 | git apply --allow-empty format.patch 48 | git status 49 | git diff --exit-code 50 | -------------------------------------------------------------------------------- /src/math_physics/orbit/sgp4/sgp4io.h: -------------------------------------------------------------------------------- 1 | #ifndef _sgp4io_ 2 | #define _sgp4io_ 3 | /* ---------------------------------------------------------------- 4 | * 5 | * sgp4io.h; 6 | * 7 | * this file contains a function to read two line element sets. while 8 | * not formerly part of the sgp4 mathematical theory, it is 9 | * required for practical implemenation. 10 | * 11 | * companion code for 12 | * fundamentals of astrodynamics and applications 13 | * 2007 14 | * by david vallado 15 | * 16 | * (w) 719-573-2600, email dvallado@agi.com 17 | * 18 | * current : 19 | * 20 apr 07 david vallado 20 | * misc updates for manual operation 21 | * changes : 22 | * 14 aug 06 david vallado 23 | * original baseline 24 | * ---------------------------------------------------------------- */ 25 | 26 | #include 27 | #include 28 | 29 | #include "sgp4ext.h" // for several misc routines 30 | #include "sgp4unit.h" // for sgp4init and getgravconst 31 | 32 | // ------------------------- function declarations ------------------------- 33 | 34 | void twoline2rv(char[130], char[130], char, char, gravconsttype, double&, double&, double&, elsetrec&); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/environment/global/clock_generator.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file clock_generator.cpp 3 | * @brief Class to generate clock for classes which have ITickable 4 | */ 5 | 6 | #include "clock_generator.hpp" 7 | 8 | namespace s2e::environment { 9 | 10 | ClockGenerator::~ClockGenerator() {} 11 | 12 | void ClockGenerator::RegisterComponent(components::ITickable* tickable) { components_.push_back(tickable); } 13 | 14 | void ClockGenerator::RemoveComponent(components::ITickable* tickable) { 15 | for (auto itr = components_.begin(); itr != components_.end();) { 16 | if (*itr == tickable) { 17 | components_.erase(itr++); 18 | break; 19 | } else { 20 | ++itr; 21 | } 22 | } 23 | } 24 | 25 | void ClockGenerator::TickToComponents() { 26 | // Update for each component 27 | for (auto itr = components_.begin(); itr != components_.end(); ++itr) { 28 | // Run MainRoutine 29 | (*itr)->Tick(timer_count_); 30 | // Run FastUpdate (Processes that are executed more frequently than MainRoutine) 31 | if ((*itr)->GetNeedsFastUpdate()) { 32 | (*itr)->FastTick(timer_count_); 33 | } 34 | } 35 | timer_count_++; // TODO: Consider if "timer_count" is necessary 36 | } 37 | 38 | void ClockGenerator::UpdateComponents(const SimulationTime* simulation_time) { 39 | if (simulation_time->GetCompoUpdateFlag()) { 40 | TickToComponents(); 41 | } 42 | } 43 | 44 | } // namespace s2e::environment 45 | -------------------------------------------------------------------------------- /scripts/Common/download_HIPcatalogue.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd `dirname $0` 3 | 4 | #set variables 5 | DIR_TMP=./tmp_hipcatalogue/ 6 | DIR_HIPCATALOGUE=../../settings/environment/star_catalogue/ 7 | 8 | mkdir -p $DIR_TMP 9 | mkdir -p $DIR_HIPCATALOGUE 10 | 11 | # #establish anonymous ftp connection and download the file 12 | # ftp -n -v -A< $DIR_TMP/hip_main.dat 23 | 24 | #unzip the downloaded file 25 | #gzip -d -v $DIR_TMP/hip_main.dat.gz 26 | 27 | #extract reqired datum and put them into the csv file 28 | cut -f 2,6,9,10 -d "|" $DIR_TMP/hip_main.dat>$DIR_TMP/tmp.csv 29 | 30 | #edit the delimeter from '|' to ',' 31 | find $DIR_TMP/tmp.csv | xargs sed -i "s/|/,/g" 32 | 33 | #remove spaces 34 | find $DIR_TMP/tmp.csv | xargs sed -i "s/[ ]//g" 35 | 36 | #remove some datum which have no information about RA and DE 37 | find $DIR_TMP/tmp.csv | xargs sed -i "/,,/d" 38 | 39 | #sort datum from the smallest Vmag to largest Vmag 40 | sort -t, -k2n $DIR_TMP/tmp.csv>$DIR_HIPCATALOGUE/hip_main.csv 41 | 42 | #add header 43 | HEADER=HIP_ID[],VMAG[],RA[deg],DE[deg] 44 | find $DIR_HIPCATALOGUE/hip_main.csv | xargs sed -i "1i$HEADER" 45 | 46 | #remove tmp directry 47 | rm -rf $DIR_TMP 48 | -------------------------------------------------------------------------------- /src/simulation/spacecraft/structure/structure.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file structure.cpp 3 | * @brief Definition of spacecraft structure 4 | */ 5 | 6 | #include "structure.hpp" 7 | 8 | #include 9 | #include 10 | 11 | namespace s2e::spacecraft { 12 | 13 | Structure::Structure(const simulation::SimulationConfiguration* simulation_configuration, const int spacecraft_id) { 14 | Initialize(simulation_configuration, spacecraft_id); 15 | } 16 | 17 | Structure::~Structure() { 18 | delete kinematics_parameters_; 19 | delete residual_magnetic_moment_; 20 | } 21 | 22 | void Structure::Initialize(const simulation::SimulationConfiguration* simulation_configuration, const int spacecraft_id) { 23 | // Read file name 24 | setting_file_reader::IniAccess conf = setting_file_reader::IniAccess(simulation_configuration->spacecraft_file_list_[spacecraft_id]); 25 | std::string ini_fname = conf.ReadString("SETTING_FILES", "structure_file"); 26 | // Save ini file 27 | simulation_configuration->main_logger_->CopyFileToLogDirectory(ini_fname); 28 | // Initialize 29 | kinematics_parameters_ = new KinematicsParameters(InitKinematicsParameters(ini_fname)); 30 | surfaces_ = InitSurfaces(ini_fname); 31 | residual_magnetic_moment_ = new ResidualMagneticMoment(InitResidualMagneticMoment(ini_fname)); 32 | } 33 | 34 | } // namespace s2e::spacecraft 35 | -------------------------------------------------------------------------------- /src/math_physics/randomization/global_randomization.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file global_randomization.hpp 3 | * @brief Class to manage global randomization 4 | */ 5 | 6 | #ifndef S2E_LIBRARY_RANDOMIZATION_GLOBAL_RANDOMIZATION_HPP_ 7 | #define S2E_LIBRARY_RANDOMIZATION_GLOBAL_RANDOMIZATION_HPP_ 8 | 9 | #include "./minimal_standard_linear_congruential_generator.hpp" 10 | 11 | namespace s2e::randomization { 12 | 13 | /** 14 | * @class global_randomization.hpp 15 | * @brief Class to manage global randomization 16 | * @note Used to make randomized seed for other randomization 17 | */ 18 | class GlobalRandomization { 19 | public: 20 | /** 21 | * @fn GlobalRandomization 22 | * @brief Constructor 23 | */ 24 | GlobalRandomization(); 25 | /** 26 | * @fn SetSeed 27 | * @brief Set randomized seed value 28 | */ 29 | void SetSeed(const long seed); 30 | /** 31 | * @fn MakeSeed 32 | * @brief Set randomized seed value 33 | */ 34 | long MakeSeed(); 35 | 36 | private: 37 | static const unsigned int kMaxSeed = 0xffffffff; //!< Maximum value of seed 38 | MinimalStandardLcg base_randomizer_; //!< Base of global randomization 39 | long seed_; //!< Seed of global randomization 40 | }; 41 | 42 | extern GlobalRandomization global_randomization; //!< Global randomization 43 | 44 | } // namespace s2e::randomization 45 | 46 | #endif // S2E_LIBRARY_RANDOMIZATION_GLOBAL_RANDOMIZATION_HPP_ 47 | -------------------------------------------------------------------------------- /src/setting_file_reader/wings_operation_file.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file wings_operation_file.cpp 3 | * @brief Classes and functions to read and manage WINGS's operation file (.ops) 4 | */ 5 | 6 | #include "wings_operation_file.hpp" 7 | 8 | #include 9 | 10 | namespace s2e::setting_file_reader { 11 | 12 | WingsOperationFile::WingsOperationFile(const std::string file_path) { 13 | // File open 14 | std::ifstream file(file_path); 15 | if (!file.is_open()) { 16 | std::cerr << "WINGS Operation file open error." << std::endl; 17 | } 18 | 19 | // Read all lines 20 | std::string line; 21 | while (std::getline(file, line)) { 22 | // Remove pose point 23 | if (!line.empty() && line[0] == '.') { 24 | line = line.substr(1); 25 | } 26 | // Remove space 27 | if (!line.empty() && line[0] == ' ') { 28 | line = line.substr(1); 29 | } 30 | // Remove comment 31 | size_t comment_position = line.find('#'); 32 | if (comment_position != std::string::npos) { 33 | line = line.substr(0, comment_position); 34 | } 35 | // add line 36 | if (line.length() > 2) { 37 | lines_.push_back(line); 38 | } 39 | } 40 | } 41 | 42 | std::string WingsOperationFile::GetLatestLine() { 43 | if (line_pointer_ >= lines_.size()) return "EOL"; 44 | 45 | std::string line = lines_[line_pointer_]; 46 | line_pointer_++; 47 | 48 | return line; 49 | } 50 | 51 | } // namespace s2e::setting_file_reader 52 | -------------------------------------------------------------------------------- /src/math_physics/numerical_integration/runge_kutta_template.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file runge_kutta_template.hpp 3 | * @brief Implementations for RungeKutta class 4 | */ 5 | #ifndef S2E_LIBRARY_NUMERICAL_INTEGRATION_RUNGE_KUTTA_TEMPLATE_HPP_ 6 | #define S2E_LIBRARY_NUMERICAL_INTEGRATION_RUNGE_KUTTA_TEMPLATE_HPP_ 7 | 8 | #include "./runge_kutta.hpp" 9 | 10 | namespace s2e::numerical_integration { 11 | 12 | template 13 | void RungeKutta::Integrate() { 14 | CalcSlope(); 15 | 16 | this->previous_state_ = this->current_state_; 17 | for (size_t i = 0; i < number_of_stages_; i++) { 18 | this->current_state_ = this->current_state_ + weights_[i] * this->step_width_ * slope_[i]; 19 | } 20 | this->current_independent_variable_ += this->step_width_; 21 | } 22 | 23 | template 24 | void RungeKutta::CalcSlope() { 25 | slope_.assign(number_of_stages_, math::Vector(0.0)); 26 | 27 | for (size_t i = 0; i < number_of_stages_; i++) { 28 | math::Vector state = this->current_state_; 29 | for (size_t j = 0; j < i; j++) { 30 | state = state + rk_matrix_[i][j] * this->step_width_ * slope_[j]; 31 | } 32 | double independent_variable = this->current_independent_variable_ + nodes_[i] * this->step_width_; 33 | slope_[i] = this->ode_.DerivativeFunction(independent_variable, state); 34 | } 35 | } 36 | 37 | } // namespace s2e::numerical_integration 38 | 39 | #endif // S2E_LIBRARY_NUMERICAL_INTEGRATION_RUNGE_KUTTA_TEMPLATE_HPP_ 40 | -------------------------------------------------------------------------------- /src/math_physics/randomization/normal_randomization.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file normal_randomization.cpp 3 | * @brief Class to generate random value with normal distribution with Box-Muller method 4 | * @note Ref: NUMERICAL RECIPES in C, p.216-p.217 5 | */ 6 | #include "normal_randomization.hpp" 7 | using s2e::randomization::NormalRand; 8 | 9 | #include //DBL_EPSILON 10 | #include //sqrt, log; 11 | 12 | NormalRand::NormalRand() : average_(0.0), standard_deviation_(1.0), holder_(0.0), is_empty_(true) {} 13 | 14 | NormalRand::NormalRand(double average, double standard_deviation) 15 | : average_(average), standard_deviation_(standard_deviation), holder_(0.0), is_empty_(true) {} 16 | 17 | NormalRand::NormalRand(double average, double standard_deviation, long seed) throw() 18 | : average_(average), standard_deviation_(standard_deviation), randomizer_(seed), holder_(0.0), is_empty_(true) {} 19 | 20 | NormalRand::operator double() { 21 | if (is_empty_) { 22 | double v1, v2, rsq; 23 | do { 24 | v1 = 2.0 * double(randomizer_) - 1.0; 25 | v2 = 2.0 * randomizer_ - 1.0; 26 | rsq = v1 * v1 + v2 * v2; 27 | } while (rsq >= 1.0 || rsq < DBL_EPSILON); 28 | double fac = std::sqrt(-2.0 * std::log(rsq) / rsq); 29 | 30 | holder_ = v1 * fac; 31 | is_empty_ = false; 32 | 33 | return v2 * fac * standard_deviation_ + average_; 34 | } else { 35 | is_empty_ = true; 36 | return holder_ * standard_deviation_ + average_; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /example/src/simulation/ground_station/sample_ground_station_components.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file sample_ground_station_components.cpp 3 | * @brief An example of ground station related components list 4 | */ 5 | #include "sample_ground_station_components.hpp" 6 | 7 | #include 8 | 9 | namespace s2e::sample { 10 | 11 | SampleGsComponents::SampleGsComponents(const simulation::SimulationConfiguration* configuration) : configuration_(configuration) { 12 | setting_file_reader::IniAccess iniAccess = setting_file_reader::IniAccess(configuration_->ground_station_file_list_[0]); 13 | 14 | std::string ant_ini_path = iniAccess.ReadString("COMPONENT_FILES", "ground_station_antenna_file"); 15 | configuration_->main_logger_->CopyFileToLogDirectory(ant_ini_path); 16 | antenna_ = new components::Antenna(components::InitAntenna(1, ant_ini_path)); 17 | std::string gs_calculator_ini_path = iniAccess.ReadString("COMPONENT_FILES", "ground_station_calculator_file"); 18 | configuration_->main_logger_->CopyFileToLogDirectory(gs_calculator_ini_path); 19 | gs_calculator_ = new components::GroundStationCalculator(components::InitGsCalculator(gs_calculator_ini_path)); 20 | } 21 | 22 | SampleGsComponents::~SampleGsComponents() { 23 | delete antenna_; 24 | delete gs_calculator_; 25 | } 26 | 27 | void SampleGsComponents::CompoLogSetUp(logger::Logger& logger) { 28 | // logger.AddLogList(ant_); 29 | logger.AddLogList(gs_calculator_); 30 | } 31 | 32 | } // namespace s2e::sample 33 | -------------------------------------------------------------------------------- /example/settings/environment/sample_gnss.ini: -------------------------------------------------------------------------------- 1 | [GNSS_SATELLITES] 2 | directory_path = SETTINGS_DIR_FROM_EXE/environment/gnss/final_products/ 3 | calculation = DISABLE 4 | logging = DISABLE 5 | 6 | // Supporting the following products 7 | // - IGS precise orbits and clocks final products for GPS and GLONASS 8 | // - https://igs.org/products/#orbits_clocks 9 | // - MGEX precise orbits and clocks final products for all navigation satellite systems 10 | // - https://igs.org/mgex/data-products/#orbit_clock 11 | // We use new long file name. 12 | // - Orbit file: [file_name_header]_YYYYDDD0000_01D_[orbit_data_period]_ORB.SP3 13 | // - Clock file: [file_name_header]_YYYYDDD0000_01D_[clock_file_name_hooter] 14 | // - Users can also use clock information in the orbit SP3 file 15 | 16 | // Header information of the reference files 17 | // Choose from ***0OPSFIN or ***0MGXFIN 18 | // ***: ID of the analysis center or IGS 19 | file_name_header = IGS0OPSFIN 20 | 21 | // Data period in the orbit reference files 22 | // - bbb: Period of the data in the file (ex. 15M = 15 mins.) 23 | orbit_data_period = 15M 24 | 25 | // Footer information of the clock reference files 26 | // bbb_ccc.ddd 27 | // - bbb: Period of the data in the file (ex. 15M = 15 mins.) 28 | // - ccc.ddd: ORB.SP3 or CLK.CLK 29 | clock_file_name_footer = 15M_ORB.SP3 // or 30S_CLK.CLK or 05M_CLK.CLK 30 | 31 | // Duration of the input product files 32 | // YYYYDDD 33 | // - YYYY: Year 34 | // - DDD: Day of year 35 | start_date = 2023126 36 | end_date = 2023129 37 | -------------------------------------------------------------------------------- /src/math_physics/randomization/minimal_standard_linear_congruential_generator_with_shuffle.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file randomize1.cpp 3 | * @brief Randomization with Park and Miller's multiplicative congruential method combined with mixed method 4 | * @note ran1 function in "NUMERICAL RECIPES in C, p.207-208" 5 | */ 6 | 7 | #include "minimal_standard_linear_congruential_generator_with_shuffle.hpp" 8 | using s2e::randomization::MinimalStandardLcgWithShuffle; 9 | 10 | MinimalStandardLcgWithShuffle::MinimalStandardLcgWithShuffle() : table_position_(0) { Initialize(); } 11 | 12 | MinimalStandardLcgWithShuffle::MinimalStandardLcgWithShuffle(const long seed) : minimal_lcg_(seed), table_position_(0) { Initialize(); } 13 | 14 | void MinimalStandardLcgWithShuffle::InitSeed(const long seed) { 15 | minimal_lcg_.Initialize(seed); 16 | Initialize(); 17 | } 18 | 19 | void MinimalStandardLcgWithShuffle::Initialize() { 20 | // Warmup of minimal_lcg_ 21 | for (int i = 0; i < 8; i++) { 22 | double temp = minimal_lcg_; 23 | static_cast(temp); 24 | } 25 | // Fill mixing table 26 | for (size_t i = 0; i < kTableSize; i++) { 27 | mixing_table_[i] = minimal_lcg_; 28 | } 29 | } 30 | 31 | MinimalStandardLcgWithShuffle::operator double() { 32 | double out = mixing_table_[table_position_]; 33 | mixing_table_[table_position_] = minimal_lcg_; // Compensate next random value 34 | table_position_ = (size_t)out * MinimalStandardLcg::kM; 35 | table_position_ %= kTableSize; // y <- [0 : kTableSize-1] 36 | 37 | return out; 38 | } 39 | -------------------------------------------------------------------------------- /src/math_physics/randomization/random_walk_template_functions.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file random_walk_template_functions.hpp 3 | * @brief Class to calculate random wark value (template functions) 4 | */ 5 | 6 | #ifndef S2E_LIBRARY_RANDOMIZATION_RANDOM_WALK_TEMPLATE_FUNCTIONS_HPP_ 7 | #define S2E_LIBRARY_RANDOMIZATION_RANDOM_WALK_TEMPLATE_FUNCTIONS_HPP_ 8 | 9 | #include 10 | #include 11 | 12 | namespace s2e::randomization { 13 | 14 | template 15 | RandomWalk::RandomWalk(double step_width_s, const math::Vector& standard_deviation, const math::Vector& limit) 16 | : math::OrdinaryDifferentialEquation(step_width_s), limit_(limit) { 17 | // Set standard deviation 18 | for (size_t i = 0; i < N; ++i) { 19 | normal_randomizer_[i].SetParameters(0.0, standard_deviation[i], s2e::randomization::global_randomization.MakeSeed()); 20 | } 21 | } 22 | 23 | template 24 | void RandomWalk::DerivativeFunction(double x, const math::Vector& state, math::Vector& rhs) { 25 | UNUSED(x); // TODO: consider the x is really need for this function 26 | 27 | for (size_t i = 0; i < N; ++i) { 28 | if (state[i] > limit_[i]) 29 | rhs[i] = -fabs(normal_randomizer_[i]); 30 | else if (state[i] < -limit_[i]) 31 | rhs[i] = fabs(normal_randomizer_[i]); 32 | else 33 | rhs[i] = normal_randomizer_[i]; 34 | } 35 | } 36 | 37 | } // namespace s2e::randomization 38 | 39 | #endif // S2E_LIBRARY_RANDOMIZATION_RANDOM_WALK_TEMPLATE_FUNCTIONS_HPP_ 40 | -------------------------------------------------------------------------------- /src/simulation/simulation_configuration.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file simulation_configuration.hpp 3 | * @brief Definition of struct for simulation setting information 4 | */ 5 | 6 | #ifndef S2E_SIMULATION_SIMULATION_CONFIGURATION_HPP_ 7 | #define S2E_SIMULATION_SIMULATION_CONFIGURATION_HPP_ 8 | 9 | #include 10 | #include 11 | 12 | #include "../logger/logger.hpp" 13 | 14 | namespace s2e::simulation { 15 | 16 | /** 17 | * @struct SimulationConfiguration 18 | * @brief Simulation setting information 19 | */ 20 | struct SimulationConfiguration { 21 | std::string initialize_base_file_name_; //!< Base file name for initialization 22 | logger::Logger* main_logger_; //!< Main logger 23 | 24 | unsigned int number_of_simulated_spacecraft_; //!< Number of simulated spacecraft 25 | std::vector spacecraft_file_list_; //!< File name list for spacecraft initialization 26 | 27 | unsigned int number_of_simulated_ground_station_; //!< Number of simulated spacecraft 28 | std::vector ground_station_file_list_; //!< File name for ground station initialization 29 | 30 | std::string inter_sc_communication_file_; //!< File name for inter-satellite communication initialization 31 | std::string gnss_file_; //!< File name for GNSS initialization 32 | 33 | /** 34 | * @fn ~SimulationConfiguration 35 | * @brief Destructor 36 | */ 37 | ~SimulationConfiguration() { delete main_logger_; } 38 | }; 39 | 40 | } // namespace s2e::simulation 41 | 42 | #endif // S2E_SIMULATION_SIMULATION_CONFIGURATION_HPP_ 43 | -------------------------------------------------------------------------------- /src/math_physics/gnss/test_bias_sinex_file_reader.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "bias_sinex_file_reader.hpp" 4 | 5 | using namespace s2e::gnss; 6 | 7 | TEST(BiasSinex, Constructor) { 8 | // File read error check 9 | BiasSinexFileReader bias_sinex_file_fault("false_file_path.BSX"); 10 | EXPECT_FALSE(bias_sinex_file_fault.GetFileReadSuccessFlag()); 11 | 12 | // File read check 13 | std::string test_file_name = "/src/math_physics/gnss/example.BSX"; 14 | BiasSinexFileReader bias_sinex_file(CORE_DIR_FROM_EXE + test_file_name); 15 | EXPECT_TRUE(bias_sinex_file.GetFileReadSuccessFlag()); 16 | 17 | // Check data 18 | EXPECT_EQ(3234, bias_sinex_file.GetNumberOfBiasData()); 19 | 20 | // Check first data 21 | BiasSolutionData bias_solution = bias_sinex_file.GetBiasData(0); 22 | EXPECT_EQ(BiasIdentifier::kDsb, bias_solution.GetIdentifier()); 23 | EXPECT_EQ(BiasTargetSignal::kP1P2, bias_solution.GetTargetSignal()); 24 | EXPECT_EQ(BiasUnit::kNs, bias_solution.GetUnit()); 25 | EXPECT_NEAR(-6.75076755510313E+00, bias_solution.GetBias(), 1e-10); 26 | EXPECT_NEAR(2.642146E-01, bias_solution.GetBiasStandardDeviation(), 1e-5); 27 | 28 | // Check final data 29 | bias_solution = bias_sinex_file.GetBiasData(3234 - 1); 30 | EXPECT_EQ(BiasIdentifier::kIsb, bias_solution.GetIdentifier()); 31 | EXPECT_EQ(BiasTargetSignal::kP1P2, bias_solution.GetTargetSignal()); 32 | EXPECT_EQ(BiasUnit::kNs, bias_solution.GetUnit()); 33 | EXPECT_NEAR(0.0, bias_solution.GetBias(), 1e-10); 34 | EXPECT_NEAR(0.0, bias_solution.GetBiasStandardDeviation(), 1e-6); 35 | } 36 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/magnetometer.ini: -------------------------------------------------------------------------------- 1 | [MAGNETOMETER_1] 2 | prescaler = 10 3 | 4 | //Quaternion from body frame to component frame 5 | quaternion_b2c(0) = 0.0 6 | quaternion_b2c(1) = 0.0 7 | quaternion_b2c(2) = 0.0 8 | quaternion_b2c(3) = 1.0 9 | 10 | [SENSOR_BASE_MAGNETOMETER_1] 11 | // Sensor Base 12 | // Scale Factor Matrix (3×3) 13 | // (0) = (0,0), (1) = (0,1), (2) = (0,2), 14 | scale_factor_c(0) = 1.0 15 | scale_factor_c(1) = 0.0 16 | scale_factor_c(2) = 0.0 17 | scale_factor_c(3) = 0.0 18 | scale_factor_c(4) = 1.0 19 | scale_factor_c(5) = 0.0 20 | scale_factor_c(6) = 0.0 21 | scale_factor_c(7) = 0.0 22 | scale_factor_c(8) = 1.0 23 | 24 | // Constant bias noise at component frame [nT] 25 | constant_bias_c_nT(0) = 10.0 26 | constant_bias_c_nT(1) = 10.0 27 | constant_bias_c_nT(2) = 10.0 28 | 29 | // Standard deviation for random walk noise[nT] 30 | random_walk_standard_deviation_c_nT(0) = 0.0 31 | random_walk_standard_deviation_c_nT(1) = 0.0 32 | random_walk_standard_deviation_c_nT(2) = 0.0 33 | 34 | // Limit of random walk noise[nT] 35 | random_walk_limit_c_nT(0) = 0.0 36 | random_walk_limit_c_nT(1) = 0.0 37 | random_walk_limit_c_nT(2) = 0.0 38 | 39 | // Standard deviation of normal random noise[nT] 40 | normal_random_standard_deviation_c_nT(0) = 10.0 41 | normal_random_standard_deviation_c_nT(1) = 10.0 42 | normal_random_standard_deviation_c_nT(2) = 10.0 43 | 44 | // Range [nT] 45 | range_to_constant_nT = 1.0e6 // smaller than Range_to_zero 46 | range_to_zero_nT = 1.5e6 47 | 48 | [POWER_PORT] 49 | minimum_voltage_V = 3.3 // V 50 | assumed_power_consumption_W = 1.0 //W 51 | -------------------------------------------------------------------------------- /src/components/base/interface_tickable.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file interface_tickable.hpp 3 | * @brief Interface class for time update of components 4 | */ 5 | 6 | #ifndef S2E_COMPONENTS_BASE_CLASSES_INTERFACE_TICKABLE_HPP_ 7 | #define S2E_COMPONENTS_BASE_CLASSES_INTERFACE_TICKABLE_HPP_ 8 | 9 | namespace s2e::components { 10 | 11 | /** 12 | * @class ITickable 13 | * @brief Interface class for time update of components 14 | */ 15 | class ITickable { 16 | public: 17 | /** 18 | * @fn Tick 19 | * @brief Pure virtual function to update clock of components 20 | */ 21 | virtual void Tick(const unsigned int count) = 0; 22 | /** 23 | * @fn FastTick 24 | * @brief Pure virtual function to update clock faster than the base component update period of components 25 | * @note Usec ase: Calculate high-frequency disturbances 26 | */ 27 | virtual void FastTick(const unsigned int fast_count) = 0; 28 | 29 | // Whether or not high-frequency disturbances need to be calculated 30 | /** 31 | * @fn GetNeedsFastUpdate 32 | * @brief Return fast update flag 33 | */ 34 | inline bool GetNeedsFastUpdate() { return needs_fast_update_; } 35 | /** 36 | * @fn SetNeedsFastUpdate 37 | * @brief Set fast update flag 38 | */ 39 | inline void SetNeedsFastUpdate(const bool need_fast_update) { needs_fast_update_ = need_fast_update; } 40 | 41 | protected: 42 | bool needs_fast_update_ = false; //!< Whether or not high-frequency disturbances need to be calculated 43 | }; 44 | 45 | } // namespace s2e::components 46 | 47 | #endif // S2E_COMPONENTS_BASE_CLASSES_INTERFACE_TICKABLE_HPP_ 48 | -------------------------------------------------------------------------------- /src/components/ports/gpio_port.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file gpio_port.hpp 3 | * @brief Class to emulate GPIO(General Purpose Input and Output) port 4 | */ 5 | 6 | #ifndef S2E_COMPONENTS_PORTS_GPIO_PORT_HPP_ 7 | #define S2E_COMPONENTS_PORTS_GPIO_PORT_HPP_ 8 | 9 | #include 10 | 11 | namespace s2e::components { 12 | 13 | #define GPIO_HIGH true 14 | #define GPIO_LOW false 15 | 16 | /** 17 | * @class GpioPort 18 | * @brief Class to emulate GPIO(General Purpose Input and Output) port 19 | */ 20 | class GpioPort { 21 | public: 22 | /** 23 | * @fn GpioPort 24 | * @brief Constructor 25 | * @param [in] port_id_: ID of the GPIO port 26 | * @param [in] component: Component which has the GPIO port 27 | */ 28 | GpioPort(const unsigned int port_id_, IGPIOCompo* component = nullptr); 29 | /** 30 | * @fn ~GpioPort 31 | * @brief Destructor 32 | */ 33 | ~GpioPort(); 34 | 35 | /** 36 | * @fn DigitalWrite 37 | * @brief Change the GPIO state 38 | * @param [in] is_high: Use GPIO_HIGH or GPIO_LOW 39 | * @return always zero 40 | */ 41 | int DigitalWrite(const bool is_high); 42 | 43 | /** 44 | * @fn DigitalRead 45 | * @brief Read the GPIO state 46 | * @return GPIO_HIGH or GPIO_LOW 47 | */ 48 | bool DigitalRead(); 49 | 50 | private: 51 | const unsigned int kPortId; //!< Port ID 52 | IGPIOCompo* component_; //!< Component which has the GPIO port 53 | bool high_low_state_; //!< GPIO High/Low state 54 | }; 55 | 56 | } // namespace s2e::components 57 | 58 | #endif // S2E_COMPONENTS_PORTS_GPIO_PORT_HPP_ 59 | -------------------------------------------------------------------------------- /src/math_physics/orbit/relative_orbit_models.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file relative_orbit_models.hpp 3 | * @brief Functions for relative orbit 4 | */ 5 | 6 | #ifndef S2E_LIBRARY_ORBIT_RELATIVE_ORBIT_MODEL_HPP_ 7 | #define S2E_LIBRARY_ORBIT_RELATIVE_ORBIT_MODEL_HPP_ 8 | 9 | #include "../math/matrix.hpp" 10 | #include "../math/vector.hpp" 11 | 12 | namespace s2e::orbit { 13 | 14 | /** 15 | * @enum RelativeOrbitModel 16 | * @brief Relative orbit model 17 | */ 18 | enum class RelativeOrbitModel { kHill = 0 }; 19 | 20 | /** 21 | * @enum StmModel 22 | * @brief State Transition Matrix for the relative orbit 23 | */ 24 | enum class StmModel { kHcw = 0 }; 25 | 26 | // Dynamics Models 27 | /** 28 | * @fn CalcHillSystemMatrix 29 | * @brief Calculate Hill System Matrix 30 | * @param [in] orbit_radius_m: Orbit radius [m] 31 | * @param [in] gravity_constant_m3_s2: Gravity constant of the center body [m3/s2] 32 | * @return System matrix 33 | */ 34 | math::Matrix<6, 6> CalcHillSystemMatrix(const double orbit_radius_m, const double gravity_constant_m3_s2); 35 | 36 | // STMs 37 | /** 38 | * @fn CalcHcwStm 39 | * @brief Calculate HCW State Transition Matrix 40 | * @param [in] orbit_radius_m: Orbit radius [m] 41 | * @param [in] gravity_constant_m3_s2: Gravity constant of the center body [m3/s2] 42 | * @param [in] elapsed_time_s: Elapsed time [s] 43 | * @return State Transition Matrix 44 | */ 45 | math::Matrix<6, 6> CalcHcwStm(const double orbit_radius_m, const double gravity_constant_m3_s2, const double elapsed_time_s); 46 | 47 | } // namespace s2e::orbit 48 | 49 | #endif // S2E_LIBRARY_ORBIT_RELATIVE_ORBIT_MODEL_HPP_ 50 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/gnss_receiver.ini: -------------------------------------------------------------------------------- 1 | [GNSS_RECEIVER_1] 2 | prescaler = 10 3 | 4 | // Position of antenna at body frame [m] 5 | antenna_position_b_m(0) = 0.0125 6 | antenna_position_b_m(1) = 0.0000 7 | antenna_position_b_m(2) = 0.1815 8 | 9 | // Quaternion from body frame to component frame of the antenna 10 | // Note: The antenna boresight direction is +Z direction at the component frame 11 | quaternion_b2c(0) = 0.0 12 | quaternion_b2c(1) = 0.0 13 | quaternion_b2c(2) = 0.0 14 | quaternion_b2c(3) = 1.0 15 | 16 | // Antenna model 17 | // SIMPLE: We assume that GNSS satellites are visible when antenna directs anti-earth direction 18 | // CONE: We calculate the number of GNSS satellites in the antenna, 19 | // and the position is observable when more than 4 satellites are in the antenna. 20 | // Note : We need to enable the GNSS satellite calculation when we use this mode. 21 | // All satellites managed in the GnssSatellite class are used in this model. 22 | antenna_model = SIMPLE 23 | 24 | // Antenna half width [deg] 25 | antenna_half_width_deg = 60 26 | 27 | // Random noise for simple position observation 28 | white_noise_standard_deviation_position_ecef_m(0) = 2000.0 29 | white_noise_standard_deviation_position_ecef_m(1) = 1000.0 30 | white_noise_standard_deviation_position_ecef_m(2) = 1500.0 31 | 32 | white_noise_standard_deviation_velocity_ecef_m_s(0) = 1.0 33 | white_noise_standard_deviation_velocity_ecef_m_s(1) = 1.5 34 | white_noise_standard_deviation_velocity_ecef_m_s(2) = 2.0 35 | 36 | [POWER_PORT] 37 | minimum_voltage_V = 3.3 38 | assumed_power_consumption_W = 1.0 39 | -------------------------------------------------------------------------------- /ExtLibraries/inih/LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | The "inih" library is distributed under the New BSD license: 3 | 4 | Copyright (c) 2009, Ben Hoyt 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | * Neither the name of Ben Hoyt nor the names of its contributors 15 | may be used to endorse or promote products derived from this software 16 | without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY BEN HOYT ''AS IS'' AND ANY 19 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL BEN HOYT BE LIABLE FOR ANY 22 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /src/math_physics/gnss/test_gnss_satellite_number.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file test_gnss_satellite_number.cpp 3 | * @brief Test functions for GNSS satellite number handling with GoogleTest 4 | */ 5 | #include 6 | 7 | #include "gnss_satellite_number.hpp" 8 | 9 | using namespace s2e::gnss; 10 | 11 | /** 12 | * @brief Test satellite number to index 13 | */ 14 | TEST(GnssSatelliteNumber, SatelliteNumberToIndex) { 15 | EXPECT_EQ(ConvertGnssSatelliteNumberToIndex("G01"), 0); 16 | EXPECT_EQ(ConvertGnssSatelliteNumberToIndex("R02"), kGlonassIndexBegin + 1); 17 | EXPECT_EQ(ConvertGnssSatelliteNumberToIndex("E10"), kGalileoIndexBegin + 9); 18 | EXPECT_EQ(ConvertGnssSatelliteNumberToIndex("C40"), kBeidouIndexBegin + 39); 19 | EXPECT_EQ(ConvertGnssSatelliteNumberToIndex("J03"), kQzssIndexBegin + 2); 20 | EXPECT_EQ(ConvertGnssSatelliteNumberToIndex("I04"), kNavicIndexBegin + 3); 21 | EXPECT_EQ(ConvertGnssSatelliteNumberToIndex("err"), UINT32_MAX); 22 | } 23 | 24 | /** 25 | * @brief Test index to satellite number 26 | */ 27 | TEST(GnssSatelliteNumber, IndexToSatelliteNumber) { 28 | EXPECT_EQ(ConvertIndexToGnssSatelliteNumber(0), "G01"); 29 | EXPECT_EQ(ConvertIndexToGnssSatelliteNumber(kGlonassIndexBegin + 9), "R10"); 30 | EXPECT_EQ(ConvertIndexToGnssSatelliteNumber(kGalileoIndexBegin + 21), "E22"); 31 | EXPECT_EQ(ConvertIndexToGnssSatelliteNumber(kBeidouIndexBegin + 50), "C51"); 32 | EXPECT_EQ(ConvertIndexToGnssSatelliteNumber(kQzssIndexBegin + 0), "J01"); 33 | EXPECT_EQ(ConvertIndexToGnssSatelliteNumber(kNavicIndexBegin + 5), "I06"); 34 | EXPECT_EQ(ConvertIndexToGnssSatelliteNumber(5000), "err"); 35 | } 36 | -------------------------------------------------------------------------------- /src/components/real/aocs/mtq_magnetometer_interference.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file mtq_magnetometer_interference.hpp 3 | * @brief Class for MTQ Magnetometer interference 4 | */ 5 | 6 | #ifndef S2E_COMPONENTS_REAL_AOCS_MTQ_MAGNETOMETER_INTERFERENCE_HPP_ 7 | #define S2E_COMPONENTS_REAL_AOCS_MTQ_MAGNETOMETER_INTERFERENCE_HPP_ 8 | 9 | #include "magnetometer.hpp" 10 | #include "magnetorquer.hpp" 11 | 12 | namespace s2e::components { 13 | 14 | /** 15 | * @class MtqMagnetometerInterference 16 | * @brief Class for MTQ Magnetometer interference 17 | */ 18 | class MtqMagnetometerInterference { 19 | public: 20 | /** 21 | * @fn MtqMagnetometerInterference 22 | * @brief Constructor 23 | * @param[in] ini_file: initialize file 24 | */ 25 | MtqMagnetometerInterference(const std::string file_name, Magnetometer& magnetometer, const Magnetorquer& magnetorquer, 26 | const size_t initialize_id = 0); 27 | 28 | /** 29 | * @fn UpdateInterference 30 | * @brief Update MTQ-Magnetometer interference 31 | */ 32 | void UpdateInterference(void); 33 | 34 | protected: 35 | size_t polynomial_degree_; //!< Polynomial degree 36 | std::vector> additional_bias_by_mtq_coefficients_; //!< Polynomial coefficients of additional bias noise 37 | math::Vector<3> previous_added_bias_c_nT_{0.0}; 38 | 39 | Magnetometer& magnetometer_; //!< Magnetometer 40 | const Magnetorquer& magnetorquer_; //!< Magnetorquer 41 | }; 42 | 43 | } // namespace s2e::components 44 | 45 | #endif // S2E_COMPONENTS_REAL_AOCS_MTQ_MAGNETOMETER_INTERFERENCE_HPP_ 46 | -------------------------------------------------------------------------------- /src/math_physics/orbit/test_interpolation_orbit.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file test_interpolation_orbit.cpp 3 | * @brief Test codes for InterpolationOrbit class with GoogleTest 4 | */ 5 | #include 6 | 7 | #include 8 | 9 | #include "interpolation_orbit.hpp" 10 | 11 | using namespace s2e::orbit; 12 | 13 | /** 14 | * @brief Test for Constructor function 15 | */ 16 | TEST(InterpolationOrbit, Constructor) { 17 | size_t degree = 9; 18 | InterpolationOrbit interpolation_orbit(degree); 19 | 20 | EXPECT_EQ(degree, interpolation_orbit.GetDegree()); 21 | for (size_t i = 0; i < degree; i++) { 22 | EXPECT_DOUBLE_EQ(-1.0, interpolation_orbit.GetTimeList()[i]); 23 | } 24 | } 25 | 26 | /** 27 | * @brief Test for PushAndPop function 28 | */ 29 | TEST(InterpolationOrbit, PushAndPop) { 30 | size_t degree = 5; 31 | InterpolationOrbit interpolation_orbit(degree); 32 | 33 | EXPECT_EQ(degree, interpolation_orbit.GetDegree()); 34 | for (size_t i = 0; i < degree; i++) { 35 | double time = (double)i; 36 | s2e::math::Vector<3> position{i * 2.0}; 37 | bool ret = interpolation_orbit.PushAndPopData(time, position); 38 | EXPECT_TRUE(ret); 39 | } 40 | for (size_t i = 0; i < degree; i++) { 41 | EXPECT_DOUBLE_EQ((double)i, interpolation_orbit.GetTimeList()[i]); 42 | for (size_t axis = 0; axis < 3; axis++) { 43 | EXPECT_DOUBLE_EQ(2.0 * i, interpolation_orbit.GetPositionDataList(axis)[i]); 44 | } 45 | } 46 | 47 | // False test 48 | double time = 2.0; 49 | s2e::math::Vector<3> position{-100.0}; 50 | bool ret = interpolation_orbit.PushAndPopData(time, position); 51 | EXPECT_FALSE(ret); 52 | } 53 | -------------------------------------------------------------------------------- /src/math_physics/orbit/interpolation_orbit.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file interpolation_orbit.cpp 3 | * @brief Orbit calculation with mathematical interpolation 4 | */ 5 | 6 | #include "interpolation_orbit.hpp" 7 | 8 | namespace s2e::orbit { 9 | 10 | InterpolationOrbit::InterpolationOrbit(const size_t degree) { 11 | std::vector time; 12 | time.assign(degree, -1.0); 13 | std::vector position; 14 | position.assign(degree, 0.0); 15 | math::Interpolation temp(time, position); 16 | for (size_t axis = 0; axis < 3; axis++) { 17 | interpolation_position_.push_back(temp); 18 | } 19 | } 20 | 21 | bool InterpolationOrbit::PushAndPopData(const double time, const math::Vector<3> position) { 22 | bool result; 23 | for (size_t axis = 0; axis < 3; axis++) { 24 | result = interpolation_position_[axis].PushAndPopData(time, position[axis]); 25 | if (result == false) { 26 | return false; 27 | } 28 | } 29 | return true; 30 | } 31 | 32 | math::Vector<3> InterpolationOrbit::CalcPositionWithTrigonometric(const double time, const double period) const { 33 | math::Vector<3> output_position; 34 | for (size_t axis = 0; axis < 3; axis++) { 35 | output_position[axis] = interpolation_position_[axis].CalcTrigonometric(time, period); 36 | } 37 | return output_position; 38 | } 39 | 40 | math::Vector<3> InterpolationOrbit::CalcPositionWithPolynomial(const double time) const { 41 | math::Vector<3> output_position; 42 | for (size_t axis = 0; axis < 3; axis++) { 43 | output_position[axis] = interpolation_position_[axis].CalcPolynomial(time); 44 | } 45 | return output_position; 46 | } 47 | 48 | } // namespace s2e::orbit 49 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/gyro_sensor.ini: -------------------------------------------------------------------------------- 1 | [GYRO_SENSOR_1] 2 | prescaler = 10 3 | 4 | // Quaternion from body frame to component frame 5 | // Including misalignment 6 | quaternion_b2c(0) = 0.0 7 | quaternion_b2c(1) = 0.0 8 | quaternion_b2c(2) = 0.0 9 | quaternion_b2c(3) = 1.0 10 | 11 | [SENSOR_BASE_GYRO_SENSOR_1] 12 | // Scale Factor Matrix (3×3) 13 | // (0) = (0,0), (1) = (0,1), (2) = (0,2), 14 | scale_factor_c(0) = 1.0 15 | scale_factor_c(1) = 0.0 16 | scale_factor_c(2) = 0.0 17 | scale_factor_c(3) = 0.0 18 | scale_factor_c(4) = 1.0 19 | scale_factor_c(5) = 0.0 20 | scale_factor_c(6) = 0.0 21 | scale_factor_c(7) = 0.0 22 | scale_factor_c(8) = 1.0 23 | 24 | // Constant bias noise at component frame [rad/s] 25 | constant_bias_c_rad_s(0) = 1.0e-3 26 | constant_bias_c_rad_s(1) = -1.0e-3 27 | constant_bias_c_rad_s(2) = 2.0e-3 28 | 29 | // Standard deviation for random walk noise[rad/s] 30 | random_walk_standard_deviation_c_rad_s(0) = 0.0 31 | random_walk_standard_deviation_c_rad_s(1) = 0.0 32 | random_walk_standard_deviation_c_rad_s(2) = 0.0 33 | 34 | // Limit of random walk noise[rad/s] 35 | random_walk_limit_c_rad_s(0) = 0.0 36 | random_walk_limit_c_rad_s(1) = 0.0 37 | random_walk_limit_c_rad_s(2) = 0.0 38 | 39 | // Standard deviation of normal random noise[rad/s] 40 | normal_random_standard_deviation_c_rad_s(0) = 1e-3 41 | normal_random_standard_deviation_c_rad_s(1) = 1e-3 42 | normal_random_standard_deviation_c_rad_s(2) = 1e-3 43 | 44 | // Range [rad/s] 45 | range_to_constant_rad_s = 5.0 // smaller than Range_to_zero 46 | range_to_zero_rad_s = 10.0 47 | 48 | [POWER_PORT] 49 | minimum_voltage_V = 3.3 // V 50 | assumed_power_consumption_W = 1.0 //W 51 | -------------------------------------------------------------------------------- /src/components/ports/uart_port.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file uart_port.cpp 3 | * @brief Class to emulate UART communication port 4 | */ 5 | 6 | #include "uart_port.hpp" 7 | 8 | namespace s2e::components { 9 | 10 | UartPort::UartPort() : UartPort(kDefaultBufferSize, kDefaultBufferSize) {} 11 | 12 | UartPort::UartPort(const unsigned int rx_buffer_size, const unsigned int tx_buffer_size) { 13 | unsigned int checked_rx_buffer_size = rx_buffer_size; 14 | unsigned int checked_tx_buffer_size = tx_buffer_size; 15 | if (rx_buffer_size <= 0) checked_rx_buffer_size = kDefaultBufferSize; 16 | if (tx_buffer_size <= 0) checked_tx_buffer_size = kDefaultBufferSize; 17 | rx_buffer_ = new utilities::RingBuffer(checked_rx_buffer_size); 18 | tx_buffer_ = new utilities::RingBuffer(checked_tx_buffer_size); 19 | } 20 | 21 | UartPort::~UartPort() { 22 | delete rx_buffer_; 23 | delete tx_buffer_; 24 | } 25 | 26 | int UartPort::WriteTx(const unsigned char* buffer, const unsigned int offset, const unsigned int data_length) { 27 | return tx_buffer_->Write(buffer, offset, data_length); 28 | } 29 | 30 | int UartPort::WriteRx(const unsigned char* buffer, const unsigned int offset, const unsigned int data_length) { 31 | return rx_buffer_->Write(buffer, offset, data_length); 32 | } 33 | 34 | int UartPort::ReadTx(unsigned char* buffer, const unsigned int offset, const unsigned int data_length) { 35 | return tx_buffer_->Read(buffer, offset, data_length); 36 | } 37 | 38 | int UartPort::ReadRx(unsigned char* buffer, const unsigned int offset, const unsigned int data_length) { 39 | return rx_buffer_->Read(buffer, offset, data_length); 40 | } 41 | 42 | } // namespace s2e::components 43 | -------------------------------------------------------------------------------- /src/math_physics/numerical_integration/runge_kutta_fehlberg.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file runge_kutta_fehlberg.hpp 3 | * @brief Class for Classical Runge-Kutta-Fehlberg method 4 | */ 5 | 6 | #ifndef S2E_LIBRARY_NUMERICAL_INTEGRATION_RUNGE_KUTTA_FEHLBERG_HPP_ 7 | #define S2E_LIBRARY_NUMERICAL_INTEGRATION_RUNGE_KUTTA_FEHLBERG_HPP_ 8 | 9 | #include "embedded_runge_kutta.hpp" 10 | 11 | namespace s2e::numerical_integration { 12 | 13 | /** 14 | * @class RungeKuttaFehlberg 15 | * @brief Class for Classical Runge-Kutta-Fehlberg method 16 | */ 17 | template 18 | class RungeKuttaFehlberg : public EmbeddedRungeKutta { 19 | public: 20 | /** 21 | * @fn RungeKuttaFehlberg 22 | * @brief Constructor 23 | * @param [in] step_width: Step width 24 | */ 25 | RungeKuttaFehlberg(const double step_width, const InterfaceOde& ode); 26 | /** 27 | * @fn CalcInterpolationState 28 | * @brief Calculate interpolation state 29 | * @param [in] sigma: Sigma value (0 < sigma < 1) for interpolation 30 | * @return : interpolated state x(t0 + sigma * h) 31 | */ 32 | math::Vector CalcInterpolationState(const double sigma) const override; 33 | 34 | private: 35 | /** 36 | * @fn CalcInterpolationWeights 37 | * @brief Calculate weights for interpolation 38 | * @param [in] sigma: Sigma value (0 < sigma < 1) for interpolation 39 | * @return : weights for interpolation 40 | */ 41 | std::vector CalcInterpolationWeights(const double sigma) const; 42 | }; 43 | 44 | } // namespace s2e::numerical_integration 45 | 46 | #include "runge_kutta_fehlberg_implementation.hpp" 47 | 48 | #endif // S2E_LIBRARY_NUMERICAL_INTEGRATION_RUNGE_KUTTA_FEHLBERG_HPP_ 49 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/solar_array_panel.ini: -------------------------------------------------------------------------------- 1 | [SOLAR_ARRAY_PANEL_1] 2 | prescaler = 10 3 | 4 | // Area of a solar cell [m2] 5 | cell_area_m2 = 0.0026 6 | 7 | // Normal vector at body fixed frame 8 | normal_vector_b(0) = 0.0 9 | normal_vector_b(1) = 1.0 10 | normal_vector_b(2) = 0.0 11 | 12 | // Power conversion efficiency 13 | cell_efficiency = 0.3 14 | 15 | // Power transmission efficiency from SAP to PCU 16 | transmission_efficiency = 0.8 17 | 18 | // Number of series of SAP 19 | number_of_series = 7 20 | 21 | // Number of parallel of SAP 22 | number_of_parallel = 6 23 | 24 | 25 | [SOLAR_ARRAY_PANEL_2] 26 | prescaler = 10 27 | 28 | // Area of a solar cell [m2] 29 | cell_area_m2 = 0.0026 30 | 31 | // Normal vector at body fixed frame 32 | normal_vector_b(0) = 1.0 33 | normal_vector_b(1) = 0.0 34 | normal_vector_b(2) = 0.0 35 | 36 | // Power conversion efficiency 37 | cell_efficiency = 0.3 38 | 39 | // Power transmission efficiency from SAP to PCU 40 | transmission_efficiency = 0.8 41 | 42 | // Number of series of SAP 43 | number_of_series = 7 44 | 45 | // Number of parallel of SAP 46 | number_of_parallel = 1 47 | 48 | 49 | [SOLAR_ARRAY_PANEL_3] 50 | prescaler = 10 51 | 52 | // Area of a solar cell [m2] 53 | cell_area_m2 = 0.0026 54 | 55 | // Normal vector at body fixed frame 56 | normal_vector_b(0) = -1.0 57 | normal_vector_b(1) = 0.0 58 | normal_vector_b(2) = 0.0 59 | 60 | // Power conversion efficiency 61 | cell_efficiency = 0.3 62 | 63 | // Power transmission efficiency from SAP to PCU 64 | transmission_efficiency = 0.8 65 | 66 | // Number of series of SAP 67 | number_of_series = 7 68 | 69 | // Number of parallel of SAP 70 | number_of_parallel = 1 71 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/disturbance.ini: -------------------------------------------------------------------------------- 1 | [GEOPOTENTIAL] 2 | // Enable only when the center object is defined as the Earth 3 | calculation = DISABLE 4 | logging = ENABLE 5 | degree = 4 6 | coefficients_file_path = SETTINGS_DIR_FROM_EXE/environment/gravity_field/egm96_to360.ascii 7 | 8 | [LUNAR_GRAVITY_FIELD] 9 | // Enable only when the center object is defined as the Moon 10 | calculation = DISABLE 11 | logging = ENABLE 12 | degree = 10 13 | coefficients_file_path = SETTINGS_DIR_FROM_EXE/environment/gravity_field/gggrx_1200a_sha.tab 14 | 15 | 16 | [MAGNETIC_DISTURBANCE] 17 | // Enable only when the center object is defined as the Earth 18 | calculation = ENABLE 19 | logging = ENABLE 20 | 21 | 22 | [AIR_DRAG] 23 | // Enable only when the center object is defined as the Earth 24 | calculation = ENABLE 25 | logging = ENABLE 26 | 27 | // Condition of air drag 28 | wall_temperature_degC = 30 // Surface Temperature[degC] 29 | molecular_temperature_degC = 3 // Atmosphere Temperature[degC] 30 | molecular_weight_g_mol = 18.0 // Molecular weight of the thermosphere[g/mol] 31 | 32 | 33 | [SOLAR_RADIATION_PRESSURE_DISTURBANCE] 34 | calculation = ENABLE 35 | logging = ENABLE 36 | 37 | 38 | [GRAVITY_GRADIENT] 39 | calculation = ENABLE 40 | logging = ENABLE 41 | 42 | 43 | [THIRD_BODY_GRAVITY] 44 | calculation = DISABLE 45 | logging = ENABLE 46 | 47 | // The number of gravity-generating bodies other than the central body 48 | number_of_third_body = 1 49 | 50 | // List of gravity-generating bodies other than the central body 51 | // All these bodies must be included in the "selected_body_name" of "[CelestialInformation]" 52 | third_body_name(0) = SUN 53 | third_body_name(1) = MOON 54 | third_body_name(2) = MARS 55 | -------------------------------------------------------------------------------- /src/math_physics/control_utilities/first_order_lag.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file first_order_lag.hpp 3 | * @brief A class to emulate the first order lag 4 | */ 5 | 6 | #ifndef S2E_LIBRARY_CONTROL_UTILITIES_FIRST_ORDER_LAG_HPP_ 7 | #define S2E_LIBRARY_CONTROL_UTILITIES_FIRST_ORDER_LAG_HPP_ 8 | 9 | namespace s2e::control_utilities { 10 | 11 | /** 12 | * @class FirstOderLag 13 | * @brief A class to emulate the first order lag 14 | */ 15 | class FirstOrderLag { 16 | public: 17 | /** 18 | * @fn FirstOderLag 19 | * @brief Default constructor 20 | */ 21 | FirstOrderLag(const double time_step_s = 1.0, const double time_constant_s = 1.0, const double gain = 1.0) 22 | : time_step_s_(time_step_s), time_constant_s_(time_constant_s), gain_(gain) {} 23 | 24 | /** 25 | * @fn Update 26 | * @brief Update State 27 | */ 28 | inline double Update(const double input) { 29 | if (time_step_s_ + time_constant_s_ <= 0.0) return 0.0; 30 | const double c_out = time_constant_s_ / (time_step_s_ + time_constant_s_); 31 | const double c_in = (gain_ * time_step_s_) / (time_step_s_ + time_constant_s_); 32 | output_ = c_out * output_ + c_in * input; 33 | 34 | return output_; 35 | } 36 | 37 | /** 38 | * @fn GetOutput 39 | * @brief Return output 40 | */ 41 | inline double GetOutput() const { return output_; } 42 | 43 | private: 44 | double output_ = 0.0; //!< Output of the system 45 | const double time_step_s_; //!< Time step [s] 46 | const double time_constant_s_; //!< Time constant [s] 47 | const double gain_; //!< Gain 48 | }; 49 | 50 | } // namespace s2e::control_utilities 51 | 52 | #endif // S2E_LIBRARY_CONTROL_UTILITIES_FIRST_ORDER_LAG_HPP_ 53 | -------------------------------------------------------------------------------- /common.cmake: -------------------------------------------------------------------------------- 1 | # C++ 2 | set_target_properties(${PROJECT_NAME} PROPERTIES LANGUAGE CXX) 3 | set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17) 4 | set_target_properties(${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS FALSE) 5 | 6 | # common include 7 | target_include_directories(${PROJECT_NAME} PUBLIC ${S2E_DIR}/src) 8 | target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) 9 | 10 | # Directory path setting 11 | target_compile_definitions(${PROJECT_NAME} PRIVATE "SETTINGS_DIR_FROM_EXE=\"${SETTINGS_DIR_FROM_EXE}\"") 12 | target_compile_definitions(${PROJECT_NAME} PRIVATE "EXT_LIB_DIR_FROM_EXE=\"${EXT_LIB_DIR_FROM_EXE}\"") 13 | target_compile_definitions(${PROJECT_NAME} PRIVATE "CORE_DIR_FROM_EXE=\"${CORE_DIR_FROM_EXE}\"") 14 | 15 | # Compile option 16 | if(MSVC) 17 | target_compile_options(${PROJECT_NAME} PUBLIC "/MP") # multi process build 18 | 19 | target_compile_options(${PROJECT_NAME} PUBLIC "/W4") 20 | if(NOT USE_HILS) # /MT option conflicts /clr option in the HILS config. 21 | target_compile_options(${PROJECT_NAME} PUBLIC "/MT") 22 | endif() 23 | target_compile_options(${PROJECT_NAME} PUBLIC "/source-charset:utf-8") 24 | else() 25 | target_compile_options(${PROJECT_NAME} PUBLIC "-Wall") 26 | target_compile_options(${PROJECT_NAME} PUBLIC "-Wextra") 27 | target_compile_options(${PROJECT_NAME} PUBLIC "-Wpedantic") 28 | 29 | # link option 30 | target_link_options(${PROJECT_NAME} PUBLIC "-rdynamic") 31 | 32 | if(NOT BUILD_64BIT) 33 | # 32bit 34 | target_compile_options(${PROJECT_NAME} PUBLIC "-m32") 35 | target_link_options(${PROJECT_NAME} PUBLIC "-m32") 36 | endif() 37 | # debug 38 | target_compile_options(${PROJECT_NAME} PUBLIC "-g") 39 | endif() 40 | -------------------------------------------------------------------------------- /src/math_physics/math/test_matrix_vector.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file test_quaternion.cpp 3 | * @brief Test codes for Quaternion class with GoogleTest 4 | */ 5 | #include 6 | 7 | #include "constants.hpp" 8 | #include "matrix_vector.hpp" 9 | 10 | /** 11 | * @brief Test for Matrix * Vector 12 | */ 13 | TEST(MatrixVector, MultiplyMatrixVector) { 14 | const size_t R = 3; 15 | const size_t C = 2; 16 | 17 | s2e::math::Matrix m; 18 | s2e::math::Vector v; 19 | 20 | m[0][0] = 1.0; 21 | m[0][1] = 2.0; 22 | m[1][0] = -1.0; 23 | m[1][1] = 0.0; 24 | m[2][0] = 3.0; 25 | m[2][1] = 1.0; 26 | 27 | v[0] = 7.0; 28 | v[1] = 1.0; 29 | 30 | s2e::math::Vector result = m * v; 31 | 32 | EXPECT_DOUBLE_EQ(9.0, result[0]); 33 | EXPECT_DOUBLE_EQ(-7.0, result[1]); 34 | EXPECT_DOUBLE_EQ(22.0, result[2]); 35 | } 36 | 37 | /** 38 | * @brief Test for CalcInverseMatrix 39 | */ 40 | TEST(MatrixVector, CalcInverseMatrix) { 41 | const size_t N = 3; 42 | 43 | s2e::math::Matrix m; 44 | 45 | m[0][0] = 1.0; 46 | m[0][1] = 1.0; 47 | m[0][2] = -1.0; 48 | m[1][0] = -2.0; 49 | m[1][1] = -1.0; 50 | m[1][2] = 1.0; 51 | m[2][0] = -1.0; 52 | m[2][1] = -2.0; 53 | m[2][2] = 1.0; 54 | 55 | s2e::math::Matrix inverse = s2e::math::CalcInverseMatrix(m); 56 | 57 | EXPECT_NEAR(-1.0, inverse[0][0], 1e-10); 58 | EXPECT_NEAR(-1.0, inverse[0][1], 1e-10); 59 | EXPECT_NEAR(0.0, inverse[0][2], 1e-10); 60 | EXPECT_NEAR(-1.0, inverse[1][0], 1e-10); 61 | EXPECT_NEAR(0.0, inverse[1][1], 1e-10); 62 | EXPECT_NEAR(-1.0, inverse[1][2], 1e-10); 63 | EXPECT_NEAR(-3.0, inverse[2][0], 1e-10); 64 | EXPECT_NEAR(-1.0, inverse[2][1], 1e-10); 65 | EXPECT_NEAR(-1.0, inverse[2][2], 1e-10); 66 | } 67 | -------------------------------------------------------------------------------- /src/math_physics/randomization/random_walk.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file random_walk.hpp 3 | * @brief Class to calculate random wark value 4 | */ 5 | 6 | #ifndef S2E_LIBRARY_RANDOMIZATION_RANDOM_WALK_HPP_ 7 | #define S2E_LIBRARY_RANDOMIZATION_RANDOM_WALK_HPP_ 8 | 9 | #include "../math/ordinary_differential_equation.hpp" 10 | #include "../math/vector.hpp" 11 | #include "./normal_randomization.hpp" 12 | 13 | namespace s2e::randomization { 14 | 15 | /** 16 | * @class RandomWalk 17 | * @brief Class to calculate random wark value 18 | */ 19 | template 20 | class RandomWalk : public math::OrdinaryDifferentialEquation { 21 | public: 22 | /** 23 | * @fn RandomWalk 24 | * @brief Constructor 25 | * @param step_width_s: Step width 26 | * @param standard_deviation: Standard deviation of random walk excitation noise 27 | * @param limit: Limit of random walk 28 | */ 29 | RandomWalk(double step_width_s, const math::Vector& standard_deviation, const math::Vector& limit); 30 | 31 | /** 32 | * @fn DerivativeFunction 33 | * @brief Override function of OrdinaryDifferentialEquation to define the difference equation 34 | * @param [in] x: Independent variable (e.g. time) 35 | * @param [in] state: State vector 36 | * @param [out] rhs: Differentiated value of state vector 37 | */ 38 | virtual void DerivativeFunction(double x, const math::Vector& state, math::Vector& rhs); 39 | 40 | private: 41 | math::Vector limit_; //!< Limit of random walk 42 | NormalRand normal_randomizer_[N]; //!< Random walk excitation noise 43 | }; 44 | 45 | } // namespace s2e::randomization 46 | 47 | #include "random_walk_template_functions.hpp" // template function definisions. 48 | 49 | #endif // S2E_LIBRARY_RANDOMIZATION_RANDOM_WALK_HPP_ -------------------------------------------------------------------------------- /scripts/Plot/plot_air_density.py: -------------------------------------------------------------------------------- 1 | # 2 | # Plot air density at the spacecraft position 3 | # 4 | # arg[1] : read_file_tag : time tag for default CSV output log file. ex. 220627_142946 5 | # 6 | 7 | # 8 | # Import 9 | # 10 | # plots 11 | import matplotlib.pyplot as plt 12 | # local function 13 | from common import find_latest_log_tag 14 | from common import add_log_file_arguments 15 | from common import read_scalar_from_csv 16 | # arguments 17 | import argparse 18 | 19 | # Arguments 20 | aparser = argparse.ArgumentParser() 21 | aparser = add_log_file_arguments(aparser) 22 | aparser.add_argument('--no-gui', action='store_true') 23 | args = aparser.parse_args() 24 | 25 | 26 | # 27 | # Read Arguments 28 | # 29 | # log file path 30 | path_to_logs = args.logs_dir 31 | 32 | read_file_tag = args.file_tag 33 | if read_file_tag == None: 34 | print("file tag does not found. use latest.") 35 | read_file_tag = find_latest_log_tag(path_to_logs) 36 | 37 | print("log: " + read_file_tag) 38 | 39 | # 40 | # CSV file name 41 | # 42 | read_file_name = path_to_logs + '/' + 'logs_' + read_file_tag + '/' + read_file_tag + '_default.csv' 43 | 44 | # 45 | # Data read and edit 46 | # 47 | # Read S2E CSV 48 | time = read_scalar_from_csv(read_file_name, 'elapsed_time[s]') 49 | 50 | air_density_at_spacecraft_position_kg_m3 = read_scalar_from_csv(read_file_name, 'air_density_at_spacecraft_position[kg/m3]') 51 | 52 | # 53 | # Plot 54 | # 55 | plt.figure(0) 56 | plt.plot(time[0], air_density_at_spacecraft_position_kg_m3[0], marker=".", c="red") 57 | plt.title("Air density at the spacecraft position") 58 | plt.xlabel("Time [s]") 59 | plt.ylabel("Air density [kg/m3]") 60 | 61 | # Data save 62 | if args.no_gui: 63 | plt.savefig(read_file_tag + "_air_density.png") # save last figure only 64 | else: 65 | plt.show() 66 | -------------------------------------------------------------------------------- /example/src/simulation/case/sample_case.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file sample_case.hpp 3 | * @brief Example of user defined simulation case 4 | */ 5 | 6 | #ifndef S2E_SIMULATION_SAMPLE_CASE_SAMPLE_CASE_HPP_ 7 | #define S2E_SIMULATION_SAMPLE_CASE_SAMPLE_CASE_HPP_ 8 | 9 | #include 10 | 11 | #include "../ground_station/sample_ground_station.hpp" 12 | #include "../spacecraft/sample_spacecraft.hpp" 13 | 14 | namespace s2e::sample { 15 | 16 | /** 17 | * @class SampleCase 18 | * @brief An example of user defined simulation class 19 | */ 20 | class SampleCase : public simulation::SimulationCase { 21 | public: 22 | /** 23 | * @fn SampleCase 24 | * @brief Constructor 25 | */ 26 | SampleCase(const std::string initialise_base_file); 27 | 28 | /** 29 | * @fn ~SampleCase 30 | * @brief Destructor 31 | */ 32 | virtual ~SampleCase(); 33 | 34 | /** 35 | * @fn GetLogHeader 36 | * @brief Override function of GetLogHeader 37 | */ 38 | virtual std::string GetLogHeader() const; 39 | /** 40 | * @fn GetLogValue 41 | * @brief Override function of GetLogValue 42 | */ 43 | virtual std::string GetLogValue() const; 44 | 45 | private: 46 | SampleSpacecraft* sample_spacecraft_; //!< Instance of spacecraft 47 | SampleGroundStation* sample_ground_station_; //!< Instance of ground station 48 | 49 | /** 50 | * @fn InitializeTargetObjects 51 | * @brief Override function of InitializeTargetObjects in SimulationCase 52 | */ 53 | void InitializeTargetObjects(); 54 | 55 | /** 56 | * @fn UpdateTargetObjects 57 | * @brief Override function of Main in SimulationCase 58 | */ 59 | void UpdateTargetObjects(); 60 | }; 61 | 62 | } // namespace s2e::sample 63 | 64 | #endif // S2E_SIMULATION_SAMPLE_CASE_SAMPLE_CASE_HPP_ 65 | -------------------------------------------------------------------------------- /scripts/Plot/plot_ground_position.py: -------------------------------------------------------------------------------- 1 | # 2 | # Plot Ground Position in the image sensor 3 | # 4 | # arg[1] : read_file_tag : time tag for default CSV output log file. ex. 220627_142946 5 | # 6 | 7 | # 8 | # Import 9 | # 10 | # plots 11 | import matplotlib.pyplot as plt 12 | # local function 13 | from common import find_latest_log_tag 14 | from common import add_log_file_arguments 15 | from common import read_scalar_from_csv 16 | # arguments 17 | import argparse 18 | 19 | # Arguments 20 | aparser = argparse.ArgumentParser() 21 | aparser = add_log_file_arguments(aparser) 22 | aparser.add_argument('--no-gui', action='store_true') 23 | args = aparser.parse_args() 24 | 25 | 26 | # 27 | # Read Arguments 28 | # 29 | # log file path 30 | path_to_logs = args.logs_dir 31 | 32 | read_file_tag = args.file_tag 33 | if read_file_tag == None: 34 | print("file tag does not found. use latest.") 35 | read_file_tag = find_latest_log_tag(path_to_logs) 36 | 37 | print("log: " + read_file_tag) 38 | 39 | # 40 | # CSV file name 41 | # 42 | read_file_name = path_to_logs + '/' + 'logs_' + \ 43 | read_file_tag + '/' + read_file_tag + '_default.csv' 44 | 45 | # 46 | # Data read and edit 47 | # 48 | # Read S2E CSV 49 | x_data = read_scalar_from_csv( 50 | read_file_name, 'telescope_ground_position_x[pix]') 51 | y_data = read_scalar_from_csv( 52 | read_file_name, 'telescope_ground_position_y[pix]') 53 | # 54 | # Plot 55 | # 56 | plt.figure(figsize=(10, 7)) 57 | plt.scatter(x_data, y_data, s=2, alpha=1.0) 58 | plt.title("Scatter plot of ground position in the image sensor") 59 | plt.xlabel("X [pix]") 60 | plt.ylabel("Y [pix]") 61 | plt.grid(True) 62 | 63 | # Data save 64 | if args.no_gui: 65 | # save last figure only 66 | plt.savefig(read_file_tag + "_ground_position.png") 67 | else: 68 | plt.show() 69 | -------------------------------------------------------------------------------- /src/simulation/spacecraft/installed_components.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file installed_components.hpp 3 | * @brief Definition of InstalledComponents class 4 | */ 5 | 6 | #ifndef S2E_SIMULATION_SPACECRAFT_INSTALLED_COMPONENTS_HPP_ 7 | #define S2E_SIMULATION_SPACECRAFT_INSTALLED_COMPONENTS_HPP_ 8 | 9 | #include 10 | #include 11 | 12 | namespace s2e::spacecraft { 13 | 14 | /** 15 | * @class InstalledComponents 16 | * @brief Base class to express components list installed on a spacecraft 17 | */ 18 | class InstalledComponents { 19 | public: 20 | /** 21 | * @fn ~InstalledComponents 22 | * @brief Destructor 23 | */ 24 | virtual ~InstalledComponents() {} 25 | 26 | /** 27 | * @fn GenerateForce_b_N 28 | * @brief Return force generated by components in unit Newton in body fixed frame 29 | * @details Users need to override this function to add force generated by components 30 | */ 31 | virtual math::Vector<3> GenerateForce_b_N(); 32 | 33 | /** 34 | * @fn GenerateTorque_b_Nm 35 | * @brief Return torque generated by components in unit Newton-meter in body fixed frame 36 | * @details Users need to override this function to add torque generated by components 37 | */ 38 | virtual math::Vector<3> GenerateTorque_b_Nm(); 39 | 40 | /** 41 | * @fn ComponentInterference 42 | * @brief Handle component interference effect 43 | */ 44 | virtual void ComponentInterference() {} 45 | 46 | /** 47 | * @fn LogSetup 48 | * @brief Setup the logger for components 49 | * @details Users need to override this function to add logger for components 50 | */ 51 | virtual void LogSetup(logger::Logger& logger); 52 | }; 53 | 54 | } // namespace s2e::spacecraft 55 | 56 | #endif // S2E_SIMULATION_SPACECRAFT_INSTALLED_COMPONENTS_HPP_ 57 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/magnetorquer.ini: -------------------------------------------------------------------------------- 1 | [MAGNETORQUER_1] 2 | prescaler = 10 3 | 4 | //Quaternion from body frame to component frame 5 | quaternion_b2c(0) = 0.0 6 | quaternion_b2c(1) = 0.0 7 | quaternion_b2c(2) = 0.0 8 | quaternion_b2c(3) = 1.0 9 | 10 | // Scale Factor Matrix (3×3) 11 | // (0) = (0,0), (1) = (0,1), (2) = (0,2), 12 | scale_factor_c(0) = 1.0 13 | scale_factor_c(1) = 0.0 14 | scale_factor_c(2) = 0.0 15 | scale_factor_c(3) = 0.0 16 | scale_factor_c(4) = 1.0 17 | scale_factor_c(5) = 0.0 18 | scale_factor_c(6) = 0.0 19 | scale_factor_c(7) = 0.0 20 | scale_factor_c(8) = 1.0 21 | 22 | // Maximum magnetic moment on component frame [Am^2] 23 | max_output_magnetic_moment_c_Am2(0) = 0.1 24 | max_output_magnetic_moment_c_Am2(1) = 0.1 25 | max_output_magnetic_moment_c_Am2(2) = 0.1 26 | 27 | // Minimum magnetic moment on component frame [Am^2] 28 | min_output_magnetic_moment_c_Am2(0) = -0.1 29 | min_output_magnetic_moment_c_Am2(1) = -0.1 30 | min_output_magnetic_moment_c_Am2(2) = -0.1 31 | 32 | // Constant bias noise on component frame [Am^2] 33 | constant_bias_noise_c_Am2(0) = 0.0 34 | constant_bias_noise_c_Am2(1) = 0.0 35 | constant_bias_noise_c_Am2(2) = 0.0 36 | 37 | // Standard deviation for random walk noise[Am^2] 38 | random_walk_standard_deviation_c_Am2(0) = 0.0 39 | random_walk_standard_deviation_c_Am2(1) = 0.0 40 | random_walk_standard_deviation_c_Am2(2) = 0.0 41 | 42 | // Limit of random walk noise[Am^2] 43 | random_walk_limit_c_Am2(0) = 0.0 44 | random_walk_limit_c_Am2(1) = 0.0 45 | random_walk_limit_c_Am2(2) = 0.0 46 | 47 | // Standard deviation of normal random noise[Am^2] 48 | white_noise_standard_deviation_c_Am2(0) = 0.0 49 | white_noise_standard_deviation_c_Am2(1) = 0.0 50 | white_noise_standard_deviation_c_Am2(2) = 0.0 51 | 52 | [POWER_PORT] 53 | minimum_voltage_V = 3.3 // V 54 | assumed_power_consumption_W = 1.0 //W 55 | -------------------------------------------------------------------------------- /src/math_physics/math/vector.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file vector.cpp 3 | * @brief Class for mathematical vector 4 | */ 5 | 6 | #include "vector.hpp" 7 | 8 | #include "constants.hpp" 9 | 10 | namespace s2e::math { 11 | Vector<3, double> ConvertFrameOrthogonal2Polar(const Vector<3, double>& orthogonal) { 12 | Vector<3, double> polar; // vector on the polar coordinate 13 | polar.FillUp(0.0); 14 | polar[0] = orthogonal.CalcNorm(); 15 | // Skip when zero vector 16 | if (polar[0] == 0.0) { 17 | return polar; 18 | } 19 | polar[1] = acos(orthogonal[2] / polar[0]); 20 | // Skip phi calculation when the orthogonal is on the Z-axis 21 | if ((orthogonal[0] == 0.0) && (orthogonal[1] == 0.0)) { 22 | return polar; 23 | } 24 | polar[2] = atan2(orthogonal[1], orthogonal[0]); 25 | if (polar[2] < 0.0) { 26 | polar[2] += numbers::tau; 27 | } 28 | 29 | return polar; 30 | } 31 | 32 | Vector<3, double> GenerateOrthogonalUnitVector(const Vector<3, double>& v) { 33 | Vector<3> orthogonal_vector; 34 | if (v[0] * v[0] <= v[1] * v[1] && v[0] * v[0] <= v[1] * v[1]) { 35 | orthogonal_vector[0] = 0.0; 36 | orthogonal_vector[1] = v[2]; 37 | orthogonal_vector[2] = -v[1]; 38 | orthogonal_vector = orthogonal_vector.CalcNormalizedVector(); 39 | return (orthogonal_vector); 40 | } else if (v[1] * v[1] <= v[0] * v[0] && v[1] * v[1] <= v[2] * v[2]) { 41 | orthogonal_vector[0] = -v[2]; 42 | orthogonal_vector[1] = 0.0; 43 | orthogonal_vector[2] = v[0]; 44 | orthogonal_vector = orthogonal_vector.CalcNormalizedVector(); 45 | return (orthogonal_vector); 46 | } else { 47 | orthogonal_vector[0] = v[1]; 48 | orthogonal_vector[1] = -v[0]; 49 | orthogonal_vector[2] = 0.0; 50 | orthogonal_vector = orthogonal_vector.CalcNormalizedVector(); 51 | return (orthogonal_vector); 52 | } 53 | } 54 | } // namespace s2e::math 55 | -------------------------------------------------------------------------------- /src/components/examples/example_i2c_target_for_hils.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file example_i2c_target_for_hils.cpp 3 | * @brief Example of component emulation for I2C target side communication in HILS environment 4 | */ 5 | 6 | #include "example_i2c_target_for_hils.hpp" 7 | 8 | namespace s2e::components { 9 | 10 | ExampleI2cTargetForHils::ExampleI2cTargetForHils(const int prescaler, environment::ClockGenerator* clock_generator, const int sils_port_id, 11 | unsigned char i2c_address, OnBoardComputer* obc, const unsigned int hils_port_id, 12 | simulation::HilsPortManager* hils_port_manager) 13 | : Component(prescaler, clock_generator), I2cTargetCommunicationWithObc(sils_port_id, hils_port_id, i2c_address, obc, hils_port_manager) {} 14 | 15 | ExampleI2cTargetForHils::~ExampleI2cTargetForHils() {} 16 | 17 | void ExampleI2cTargetForHils::MainRoutine(const int time_count) { 18 | UNUSED(time_count); 19 | 20 | // update telemetry data 21 | const unsigned char kTlmSize = 5; 22 | unsigned char tlm[kTlmSize] = {0}; 23 | for (unsigned char i = 0; i < kTlmSize; i++) { 24 | tlm[i] = 'A' + tlm_counter_ + i; 25 | } 26 | WriteRegister(0, tlm, kTlmSize); 27 | tlm_counter_++; 28 | if (tlm_counter_ > kNumAlphabet - kTlmSize) { 29 | tlm_counter_ = 0; // ABCDE, ..., VWXYZ, ABCDE, ... 30 | } 31 | 32 | ReceiveCommand(); 33 | int additional_frame_num = kStoredFrameSize - GetStoredFrameCounter(); 34 | if (additional_frame_num <= 0) return; 35 | 36 | // store telemetry in converter up to kStoredFrameSize 37 | for (int i = 0; i < additional_frame_num; i++) { 38 | SendTelemetry(kTlmSize); 39 | std::cout << "I2C Target sends to converter: " << tlm[0] << tlm[1] << tlm[2] << tlm[3] << tlm[4] << std::endl; 40 | } 41 | 42 | return; 43 | } 44 | 45 | } // namespace s2e::components 46 | -------------------------------------------------------------------------------- /example/src/simulation/case/sample_case.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file sample_case.cpp 3 | * @brief Example of user defined simulation case 4 | */ 5 | 6 | #include "sample_case.hpp" 7 | 8 | namespace s2e::sample { 9 | 10 | SampleCase::SampleCase(std::string initialise_base_file) : simulation::SimulationCase(initialise_base_file) {} 11 | 12 | SampleCase::~SampleCase() { 13 | delete sample_spacecraft_; 14 | delete sample_ground_station_; 15 | } 16 | 17 | void SampleCase::InitializeTargetObjects() { 18 | // Instantiate the target of the simulation 19 | // `spacecraft_id` corresponds to the index of `spacecraft_file` in simulation_base.ini 20 | const int spacecraft_id = 0; 21 | sample_spacecraft_ = new SampleSpacecraft(&simulation_configuration_, global_environment_, spacecraft_id); 22 | const int ground_station_id = 0; 23 | sample_ground_station_ = new SampleGroundStation(&simulation_configuration_, ground_station_id); 24 | 25 | // Register the log output 26 | sample_spacecraft_->LogSetup(*(simulation_configuration_.main_logger_)); 27 | sample_ground_station_->LogSetup(*(simulation_configuration_.main_logger_)); 28 | } 29 | 30 | void SampleCase::UpdateTargetObjects() { 31 | // Spacecraft Update 32 | sample_spacecraft_->Update(&(global_environment_->GetSimulationTime())); 33 | // Ground Station Update 34 | sample_ground_station_->Update(global_environment_->GetCelestialInformation().GetEarthRotation(), *sample_spacecraft_); 35 | } 36 | 37 | std::string SampleCase::GetLogHeader() const { 38 | std::string str_tmp = ""; 39 | 40 | str_tmp += logger::WriteScalar("time", "s"); 41 | 42 | return str_tmp; 43 | } 44 | 45 | std::string SampleCase::GetLogValue() const { 46 | std::string str_tmp = ""; 47 | 48 | str_tmp += logger::WriteScalar(global_environment_->GetSimulationTime().GetElapsedTime_s()); 49 | 50 | return str_tmp; 51 | } 52 | 53 | } // namespace s2e::sample 54 | -------------------------------------------------------------------------------- /src/utilities/ring_buffer.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ring_buffer.hpp 3 | * @brief Class to emulate ring buffer 4 | */ 5 | 6 | #ifndef S2E_LIBRARY_UTILITIES_RING_BUFFER_HPP_ 7 | #define S2E_LIBRARY_UTILITIES_RING_BUFFER_HPP_ 8 | 9 | namespace s2e::utilities { 10 | 11 | typedef unsigned char byte; 12 | 13 | /** 14 | * @class RingBuffer 15 | * @brief Class to emulate ring buffer 16 | */ 17 | class RingBuffer { 18 | public: 19 | /** 20 | * @fn RingBuffer 21 | * @brief Constructor 22 | * @param [in] buffer_size: Buffer size 23 | */ 24 | RingBuffer(int buffer_size); 25 | /** 26 | * @fn ~RingBuffer 27 | * @brief Destructor 28 | */ 29 | ~RingBuffer(); 30 | 31 | /** 32 | * @fn Write 33 | * @brief Write data of (buffer[offset] to buffer[offset + data_length]) to the ring buffer's write pointer 34 | * @param [in] buffer: Data 35 | * @param [in] offset: Data offset for buffer 36 | * @param [in] data_length: Data length for buffer 37 | * @return Number of bytes written 38 | */ 39 | int Write(const byte* buffer, const unsigned int offset, const unsigned int data_length); 40 | /** 41 | * @fn Read 42 | * @brief Read data at the read pointer of the ring buffer and store the data to the buffer[offset] to buffer[offset + data_length] 43 | * @param [in] buffer: Data 44 | * @param [in] offset: Data offset for buffer 45 | * @param [in] data_length: Data length for buffer 46 | * @return Number of bytes read 47 | */ 48 | int Read(byte* buffer, const unsigned int offset, const unsigned int data_length); 49 | 50 | private: 51 | unsigned int buffer_size_; //!< Buffer size 52 | byte* buffer_; //!< Buffer 53 | unsigned int read_pointer_; //!< Read pointer 54 | unsigned int write_pointer_; //!< Write pointer 55 | }; 56 | 57 | } // namespace s2e::utilities 58 | 59 | #endif // S2E_LIBRARY_UTILITIES_RING_BUFFER_HPP_ 60 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/local_environment.ini: -------------------------------------------------------------------------------- 1 | [MAGNETIC_FIELD_ENVIRONMENT] 2 | calculation = ENABLE 3 | logging = ENABLE 4 | coefficient_file = SETTINGS_DIR_FROM_EXE/environment/magnetic_field/igrf13.coef 5 | magnetic_field_random_walk_standard_deviation_nT = 10.0 6 | magnetic_field_random_walk_limit_nT = 400.0 7 | magnetic_field_white_noise_standard_deviation_nT = 50.0 8 | 9 | 10 | [SOLAR_RADIATION_PRESSURE_ENVIRONMENT] 11 | calculation = ENABLE 12 | logging = ENABLE 13 | // The number of shadow generating bodies other than the central body 14 | number_of_third_shadow_source_ = 1 15 | // List of shadow generating bodies other than the central body 16 | // All these bodies must be included in the "selected_body_name" of "[CelestialInformation]" 17 | third_shadow_source_name(0) = MOON 18 | 19 | 20 | [EARTH_ALBEDO] 21 | calculation = DISABLE 22 | // Earth albedo factor: Percentage of sunlight reflected off the Earth surface. Value between 0.0 and 1.0 23 | earth_albedo_factor = 0.3 24 | 25 | 26 | [ATMOSPHERE] 27 | calculation = ENABLE 28 | logging = ENABLE 29 | 30 | // Atmosphere model 31 | // STANDARD: Model using scale height 32 | // NRLMSISE00: NRLMSISE00 model 33 | // HARRIS_PRIESTER: Harris-Priester model 34 | model = STANDARD 35 | nrlmsise00_table_file = SETTINGS_DIR_FROM_EXE/environment/space_weather/SpaceWeather-v1.2.txt 36 | // Whether using user-defined f10.7 and ap value 37 | // Ref of f10.7: https://www.swpc.noaa.gov/phenomena/f107-cm-radio-emissions 38 | // Ref of ap: http://wdc.kugi.kyoto-u.ac.jp/kp/kpexp-j.html 39 | is_manual_parameter_used = ENABLE 40 | manual_daily_f107 = 150.0 // User defined f10.7 (1 day) 41 | manual_average_f107 = 150.0 // User defined f10.7 (30 days average) 42 | manual_ap = 3.0 // User defined ap 43 | air_density_standard_deviation = 0.0 // Standard deviation of the air density 44 | 45 | 46 | [LOCAL_CELESTIAL_INFORMATION] 47 | logging = ENABLE 48 | -------------------------------------------------------------------------------- /src/dynamics/orbit/sgp4_orbit_propagation.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file sgp4_orbit_propagation.hpp 3 | * @brief Class to propagate spacecraft orbit with SGP4 method with TLE 4 | */ 5 | 6 | #ifndef S2E_DYNAMICS_ORBIT_SGP4_ORBIT_PROPAGATION_HPP_ 7 | #define S2E_DYNAMICS_ORBIT_SGP4_ORBIT_PROPAGATION_HPP_ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #include "orbit.hpp" 15 | 16 | namespace s2e::dynamics::orbit { 17 | 18 | /** 19 | * @class Sgp4OrbitPropagation 20 | * @brief Class to propagate spacecraft orbit with SGP4 method with TLE 21 | */ 22 | class Sgp4OrbitPropagation : public Orbit { 23 | public: 24 | /** 25 | * @fn Sgp4OrbitPropagation 26 | * @brief Constructor 27 | * @param [in] celestial_information: Celestial information 28 | * @param [in] tle1: The first line of TLE 29 | * @param [in] tle2: The second line of TLE 30 | * @param [in] wgs_setting: Wold Geodetic System 31 | * @param [in] current_time_jd: Current Julian day [day] 32 | */ 33 | Sgp4OrbitPropagation(const environment::CelestialInformation* celestial_information, char* tle1, char* tle2, const int wgs_setting, 34 | const double current_time_jd); 35 | 36 | // Override Orbit 37 | /** 38 | * @fn Propagate 39 | * @brief Propagate orbit 40 | * @param [in] end_time_s: End time of simulation [sec] 41 | * @param [in] current_time_jd: Current Julian day [day] 42 | */ 43 | virtual void Propagate(const double end_time_s, const double current_time_jd); 44 | 45 | private: 46 | gravconsttype gravity_constant_setting_; //!< Gravity constant value type 47 | elsetrec sgp4_data_; //!< Structure data for SGP4 library 48 | }; 49 | 50 | } // namespace s2e::dynamics::orbit 51 | 52 | #endif // S2E_DYNAMICS_ORBIT_SGP4_ORBIT_PROPAGATION_HPP_ 53 | -------------------------------------------------------------------------------- /src/math_physics/numerical_integration/runge_kutta_4.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file runge_kutta_4.hpp 3 | * @brief Class for Classical 4th order Runge-Kutta method 4 | */ 5 | 6 | #ifndef S2E_LIBRARY_NUMERICAL_INTEGRATION_RUNGE_KUTTA_4_HPP_ 7 | #define S2E_LIBRARY_NUMERICAL_INTEGRATION_RUNGE_KUTTA_4_HPP_ 8 | 9 | #include 10 | 11 | #include "runge_kutta.hpp" 12 | 13 | namespace s2e::numerical_integration { 14 | 15 | /** 16 | * @class RungeKutta4 17 | * @brief Class for Classical 4th order Runge-Kutta method 18 | */ 19 | template 20 | class RungeKutta4 : public RungeKutta { 21 | public: 22 | /** 23 | * @fn RungeKutta 24 | * @brief Constructor 25 | * @param [in] step_width: Step width 26 | */ 27 | RungeKutta4(const double step_width, const InterfaceOde& ode) : RungeKutta(step_width, ode) { 28 | // Classical 4th order Runge-Kutta (4-order, 4-stage) 29 | this->number_of_stages_ = 4; 30 | this->approximation_order_ = 4; 31 | this->nodes_.assign(this->number_of_stages_, 0.0); 32 | this->weights_.assign(this->number_of_stages_, 0.0); 33 | this->rk_matrix_.assign(this->number_of_stages_, std::vector(this->number_of_stages_, 0.0)); 34 | 35 | this->nodes_[1] = this->nodes_[2] = 0.5; 36 | this->nodes_[3] = 1.0; 37 | 38 | this->weights_[0] = this->weights_[3] = 1.0 / 6.0; 39 | this->weights_[1] = this->weights_[2] = 1.0 / 3.0; 40 | 41 | this->rk_matrix_[1][0] = this->rk_matrix_[2][1] = 0.5; 42 | this->rk_matrix_[3][2] = 1.0; 43 | 44 | this->CalcSlope(); 45 | } 46 | 47 | // We did not implement the interpolation for RK4 48 | math::Vector CalcInterpolationState(const double sigma) const override { 49 | UNUSED(sigma); 50 | return this->current_state_; 51 | } 52 | }; 53 | 54 | } // namespace s2e::numerical_integration 55 | 56 | #endif // S2E_LIBRARY_NUMERICAL_INTEGRATION_RUNGE_KUTTA_4_HPP_ 57 | -------------------------------------------------------------------------------- /src/dynamics/orbit/kepler_orbit_propagation.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file kepler_orbit_propagation.hpp 3 | * @brief Class to propagate spacecraft orbit with Kepler equation 4 | */ 5 | 6 | #ifndef S2E_DYNAMICS_ORBIT_KEPLER_ORBIT_PROPAGATION_HPP_ 7 | #define S2E_DYNAMICS_ORBIT_KEPLER_ORBIT_PROPAGATION_HPP_ 8 | 9 | #include "../../math_physics/orbit/kepler_orbit.hpp" 10 | #include "orbit.hpp" 11 | 12 | namespace s2e::dynamics::orbit { 13 | 14 | /** 15 | * @class KeplerOrbitPropagation 16 | * @brief Class to propagate spacecraft orbit with Kepler equation 17 | */ 18 | class KeplerOrbitPropagation : public Orbit, public s2e::orbit::KeplerOrbit { 19 | public: 20 | // Initialize with orbital elements 21 | /** 22 | * @fn KeplerOrbitPropagation 23 | * @brief Constructor 24 | * @param [in] celestial_information: Celestial information 25 | * @param [in] current_time_jd: Current Julian day [day] 26 | * @param [in] kepler_orbit: Kepler orbit 27 | */ 28 | KeplerOrbitPropagation(const environment::CelestialInformation* celestial_information, const double current_time_jd, 29 | s2e::orbit::KeplerOrbit kepler_orbit); 30 | /** 31 | * @fn ~KeplerOrbitPropagation 32 | * @brief Destructor 33 | */ 34 | ~KeplerOrbitPropagation(); 35 | 36 | // Override Orbit 37 | /** 38 | * @fn Propagate 39 | * @brief Propagate orbit 40 | * @param [in] end_time_s: End time of simulation [sec] 41 | * @param [in] current_time_jd: Current Julian day [day] 42 | */ 43 | virtual void Propagate(const double end_time_s, const double current_time_jd); 44 | 45 | private: 46 | /** 47 | * @fn UpdateState 48 | * @brief Propagate orbit 49 | * @param [in] current_time_jd: Current Julian day [day] 50 | */ 51 | void UpdateState(const double current_time_jd); 52 | }; 53 | 54 | } // namespace s2e::dynamics::orbit 55 | 56 | #endif // S2E_DYNAMICS_ORBIT_KEPLER_ORBIT_PROPAGATION_HPP_ 57 | -------------------------------------------------------------------------------- /src/dynamics/orbit/initialize_orbit.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file initialize_orbit.hpp 3 | * @brief Initialize function for Orbit class 4 | */ 5 | 6 | #ifndef S2E_DYNAMICS_ORBIT_INITIALIZE_ORBIT_HPP_ 7 | #define S2E_DYNAMICS_ORBIT_INITIALIZE_ORBIT_HPP_ 8 | 9 | #include 10 | 11 | #include "orbit.hpp" 12 | 13 | namespace s2e::simulation { 14 | class RelativeInformation; 15 | } 16 | 17 | namespace s2e::dynamics::orbit { 18 | 19 | /** 20 | * @fn InitOrbit 21 | * @brief Initialize function for Orbit class 22 | * @param [in] celestial_information: Celestial information 23 | * @param [in] initialize_file: Path to initialize file 24 | * @param [in] step_width_s: Step width [sec] 25 | * @param [in] current_time_jd: Current Julian day [day] 26 | * @param [in] gravity_constant_m3_s2: Gravity constant [m3/s2] 27 | * @param [in] section: Section name 28 | * @param [in] relative_information: Relative information 29 | */ 30 | Orbit* InitOrbit(const environment::CelestialInformation* celestial_information, std::string initialize_file, double step_width_s, 31 | double current_time_jd, double gravity_constant_m3_s2, std::string section = "ORBIT", 32 | simulation::RelativeInformation* relative_information = (simulation::RelativeInformation*)nullptr); 33 | 34 | /** 35 | * @fn InitializePosVel 36 | * @brief Initialize position and velocity depends on initialize mode 37 | * @param [in] initialize_file: Path to initialize file 38 | * @param [in] current_time_jd: Current Julian day [day] 39 | * @param [in] gravity_constant_m3_s2: Gravity constant [m3/s2] 40 | * @param [in] section: Section name 41 | */ 42 | math::Vector<6> InitializePosVel(std::string initialize_file, double current_time_jd, double gravity_constant_m3_s2, std::string section = "ORBIT"); 43 | 44 | } // namespace s2e::dynamics::orbit 45 | 46 | #endif // S2E_DYNAMICS_ORBIT_INITIALIZE_ORBIT_HPP_ 47 | -------------------------------------------------------------------------------- /example/src/simulation/ground_station/sample_ground_station.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file sample_ground_station.hpp 3 | * @brief An example of user defined ground station class 4 | */ 5 | 6 | #ifndef S2E_SIMULATION_SAMPLE_GROUND_STATION_SAMPLE_GROUND_STATION_HPP_ 7 | #define S2E_SIMULATION_SAMPLE_GROUND_STATION_SAMPLE_GROUND_STATION_HPP_ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "../spacecraft/sample_spacecraft.hpp" 16 | 17 | namespace s2e::sample { 18 | 19 | class SampleGsComponents; 20 | 21 | /** 22 | * @class SampleGroundStation 23 | * @brief An example of user defined ground station class 24 | */ 25 | class SampleGroundStation : public ground_station::GroundStation { 26 | public: 27 | /** 28 | * @fn SampleGroundStation 29 | * @brief Constructor 30 | */ 31 | SampleGroundStation(const simulation::SimulationConfiguration* configuration, const unsigned int ground_station_id); 32 | /** 33 | * @fn ~SampleGroundStation 34 | * @brief Destructor 35 | */ 36 | ~SampleGroundStation(); 37 | 38 | /** 39 | * @fn LogSetup 40 | * @brief Override function of LogSetup in GroundStation class 41 | */ 42 | virtual void LogSetup(logger::Logger& logger); 43 | /** 44 | * @fn Update 45 | * @brief Override function of Update in GroundStation class 46 | */ 47 | virtual void Update(const environment::EarthRotation& celestial_rotation, const SampleSpacecraft& spacecraft); 48 | 49 | private: 50 | using GroundStation::Update; 51 | SampleGsComponents* components_; //!< Ground station related components 52 | }; 53 | 54 | } // namespace s2e::sample 55 | 56 | #endif // S2E_SIMULATION_SAMPLE_GROUND_STATION_SAMPLE_GROUND_STATION_HPP_ 57 | -------------------------------------------------------------------------------- /src/components/examples/example_change_structure.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file example_change_structure.cpp 3 | * @brief Class to show an example to change satellite structure information 4 | */ 5 | 6 | #include "example_change_structure.hpp" 7 | 8 | #include 9 | 10 | namespace s2e::components { 11 | 12 | ExampleChangeStructure::ExampleChangeStructure(environment::ClockGenerator* clock_generator, spacecraft::Structure* structure) 13 | : Component(1, clock_generator), structure_(structure) {} 14 | 15 | ExampleChangeStructure::~ExampleChangeStructure() {} 16 | 17 | void ExampleChangeStructure::MainRoutine(const int time_count) { 18 | if (time_count > 1000) { 19 | // Mass 20 | structure_->GetToSetKinematicsParameters().SetMass_kg(100.0); 21 | 22 | // Center of gravity 23 | math::Vector<3> cg(0.0); 24 | cg[0] = 0.01; 25 | cg[1] = -0.01; 26 | cg[2] = 0.02; 27 | structure_->GetToSetKinematicsParameters().SetCenterOfGravityVector_b_m(cg); 28 | 29 | // RMM 30 | math::Vector<3> rmm(0.0); 31 | rmm[0] = 0.1; 32 | rmm[1] = -0.1; 33 | rmm[2] = 0.2; 34 | structure_->GetToSetResidualMagneticMoment().SetRmmConstant_b_Am2(rmm); 35 | 36 | // Surface 37 | structure_->GetToSetSurfaces()[0].SetArea_m2(0.5); 38 | 39 | // Inertia Tensor 40 | math::Matrix<3, 3> inertia_tensor_b_kgm2(0.0); 41 | inertia_tensor_b_kgm2[0][0] = 0.2; 42 | inertia_tensor_b_kgm2[1][1] = 0.2; 43 | inertia_tensor_b_kgm2[2][2] = 0.2; 44 | structure_->GetToSetKinematicsParameters().SetInertiaTensor_b_kgm2(inertia_tensor_b_kgm2); 45 | } 46 | } 47 | 48 | std::string ExampleChangeStructure::GetLogHeader() const { 49 | std::string str_tmp = ""; 50 | 51 | return str_tmp; 52 | } 53 | 54 | std::string ExampleChangeStructure::GetLogValue() const { 55 | std::string str_tmp = ""; 56 | 57 | return str_tmp; 58 | } 59 | 60 | } // namespace s2e::components 61 | -------------------------------------------------------------------------------- /src/components/examples/example_change_structure.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file example_change_structure.hpp 3 | * @brief Class to show an example to change satellite structure information 4 | */ 5 | 6 | #ifndef S2E_COMPONENTS_EXAMPLES_EXAMPLE_CHANGE_STRUCTURE_HPP_ 7 | #define S2E_COMPONENTS_EXAMPLES_EXAMPLE_CHANGE_STRUCTURE_HPP_ 8 | 9 | #include 10 | #include 11 | 12 | #include "../base/component.hpp" 13 | 14 | namespace s2e::components { 15 | 16 | /** 17 | * @class ExampleChangeStructure 18 | * @brief Class to show an example to change satellite structure information 19 | */ 20 | class ExampleChangeStructure : public Component, public logger::ILoggable { 21 | public: 22 | /** 23 | * @fn ExampleChangeStructure 24 | * @brief Constructor with power port 25 | * @param [in] clock_generator: Clock generator 26 | * @param [in] structure: Structure information 27 | */ 28 | ExampleChangeStructure(environment::ClockGenerator* clock_generator, spacecraft::Structure* structure); 29 | /** 30 | * @fn ~ChangeStructure 31 | * @brief Destructor 32 | */ 33 | ~ExampleChangeStructure(); 34 | 35 | // Override functions for Component 36 | /** 37 | * @fn MainRoutine 38 | * @brief Main routine for sensor observation 39 | */ 40 | void MainRoutine(const int time_count) override; 41 | 42 | // Override ILoggable 43 | /** 44 | * @fn GetLogHeader 45 | * @brief Override GetLogHeader function of ILoggable 46 | */ 47 | virtual std::string GetLogHeader() const override; 48 | /** 49 | * @fn GetLogValue 50 | * @brief Override GetLogValue function of ILoggable 51 | */ 52 | virtual std::string GetLogValue() const override; 53 | 54 | protected: 55 | spacecraft::Structure* structure_; //!< Structure information 56 | }; 57 | 58 | } // namespace s2e::components 59 | 60 | #endif // S2E_COMPONENTS_EXAMPLES_EXAMPLE_CHANGE_STRUCTURE_HPP_ 61 | -------------------------------------------------------------------------------- /src/components/base/gpio_connection_with_obc.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file gpio_connection_with_obc.hpp 3 | * @brief Base class for GPIO communication with OBC flight software 4 | * TODO: consider relation with IGPIOCompo 5 | */ 6 | 7 | #ifndef S2E_COMPONENTS_BASE_GPIO_CONNECTION_WITH_OBC_HPP_ 8 | #define S2E_COMPONENTS_BASE_GPIO_CONNECTION_WITH_OBC_HPP_ 9 | 10 | #include "../real/cdh/on_board_computer.hpp" 11 | 12 | namespace s2e::components { 13 | 14 | /** 15 | * @class GpioConnectionWithObc 16 | * @brief Base class for GPIO communication with OBC flight software 17 | * @note Components which want to communicate with OBC using GPIO have to inherit this. 18 | */ 19 | class GpioConnectionWithObc { 20 | public: 21 | /** 22 | * @fn GpioConnectionWithObc 23 | * @brief Constructor for SILS mode 24 | * @param [in] port_id: Port ID GPIO line 25 | * @param [in] obc: The communication target OBC 26 | */ 27 | GpioConnectionWithObc(const std::vector port_id, OnBoardComputer* obc); 28 | /** 29 | * @fn ~GpioConnectionWithObc 30 | * @brief Destructor 31 | */ 32 | ~GpioConnectionWithObc(); 33 | 34 | protected: 35 | /** 36 | * @fn Read 37 | * @brief Read the GPIO state 38 | * @param [in] index: element index for port_id_ vector, not the GPIO port ID for OBC 39 | * @return High(True) or Low(False) of GPIO state 40 | */ 41 | bool Read(const int index); 42 | /** 43 | * @fn Write 44 | * @brief Write the GPIO state 45 | * @param [in] index: element index for port_id_ vector, not the GPIO port ID for OBC 46 | * @param [in] is_high: High(True) or Low(False) of GPIO state 47 | */ 48 | void Write(const int index, const bool is_high); 49 | 50 | private: 51 | std::vector port_id_; //!< Port ID GPIO line 52 | OnBoardComputer* obc_; //!< The communication target OBC 53 | }; 54 | 55 | } // namespace s2e::components 56 | 57 | #endif // S2E_COMPONENTS_BASE_GPIO_CONNECTION_WITH_OBC_HPP_ 58 | -------------------------------------------------------------------------------- /src/math_physics/numerical_integration/embedded_runge_kutta.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file embedded_runge_kutta.hpp 3 | * @brief Base Class for Embedded Runge-Kutta method 4 | */ 5 | 6 | #ifndef S2E_LIBRARY_NUMERICAL_INTEGRATION_EMBEDDED_RUNGE_KUTTA_HPP_ 7 | #define S2E_LIBRARY_NUMERICAL_INTEGRATION_EMBEDDED_RUNGE_KUTTA_HPP_ 8 | 9 | #include "runge_kutta.hpp" 10 | 11 | namespace s2e::numerical_integration { 12 | 13 | /** 14 | * @class EmbeddedRungeKutta 15 | * @brief Class for Embedded Runge-Kutta method 16 | */ 17 | template 18 | class EmbeddedRungeKutta : public RungeKutta { 19 | public: 20 | /** 21 | * @fn EmbeddedRungeKutta 22 | * @brief Constructor 23 | * @param [in] step_width: Step width 24 | */ 25 | EmbeddedRungeKutta(const double step_width, const InterfaceOde& ode) : RungeKutta(step_width, ode) {} 26 | 27 | /** 28 | * @fn Integrate 29 | * @brief Update the state vector with the numerical integration with multiple order to evaluate the error 30 | */ 31 | virtual void Integrate(); 32 | 33 | /** 34 | * @fn ControlStepWidth 35 | * @brief Step width control 36 | * @param[in] error_tolerance: Error tolerance (epsilon in the equation) 37 | */ 38 | void ControlStepWidth(const double error_tolerance); 39 | 40 | /** 41 | * @fn GetLocalTruncationError 42 | * @return Norm of estimated local truncation error 43 | */ 44 | inline double GetLocalTruncationError() const { return local_truncation_error_; } 45 | 46 | protected: 47 | // Parameters should be defined by child class 48 | std::vector higher_order_weights_; //!< Weights vector for higher order approximation 49 | 50 | // Error 51 | double local_truncation_error_; //!< Norm of estimated local truncation error 52 | }; 53 | 54 | } // namespace s2e::numerical_integration 55 | 56 | #include "embedded_runge_kutta_implementation.hpp" 57 | 58 | #endif // S2E_LIBRARY_NUMERICAL_INTEGRATION_EMBEDDED_RUNGE_KUTTA_HPP_ 59 | -------------------------------------------------------------------------------- /src/math_physics/numerical_integration/embedded_runge_kutta_implementation.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file embedded_runge_kutta_implementation.hpp 3 | * @brief Implementation of Embedded Runge-Kutta method 4 | */ 5 | #ifndef S2E_LIBRARY_NUMERICAL_INTEGRATION_EMBEDDED_RUNGE_KUTTA_IMPLEMENTATION_HPP_ 6 | #define S2E_LIBRARY_NUMERICAL_INTEGRATION_EMBEDDED_RUNGE_KUTTA_IMPLEMENTATION_HPP_ 7 | 8 | #include "embedded_runge_kutta.hpp" 9 | 10 | namespace s2e::numerical_integration { 11 | 12 | template 13 | void EmbeddedRungeKutta::Integrate() { 14 | this->CalcSlope(); 15 | 16 | this->previous_state_ = this->current_state_; 17 | math::Vector lower_current_state = this->current_state_; //!< eta in the equation 18 | math::Vector higher_current_state = this->current_state_; //!< eta_hat in the equation 19 | for (size_t i = 0; i < this->number_of_stages_; i++) { 20 | lower_current_state = lower_current_state + this->weights_[i] * this->step_width_ * this->slope_[i]; 21 | higher_current_state = higher_current_state + higher_order_weights_[i] * this->step_width_ * this->slope_[i]; 22 | } 23 | 24 | // Error evaluation 25 | math::Vector truncation_error = lower_current_state - higher_current_state; 26 | local_truncation_error_ = truncation_error.CalcNorm(); 27 | 28 | // State update 29 | this->current_state_ = higher_current_state; 30 | this->current_independent_variable_ += this->step_width_; 31 | } 32 | 33 | template 34 | void EmbeddedRungeKutta::ControlStepWidth(const double error_tolerance) { 35 | double updated_step_width = pow(error_tolerance / local_truncation_error_, 1.0 / ((double)(this->approximation_order_ + 1))) * this->step_width_; 36 | if (updated_step_width <= 0.0) return; // TODO: Error handling 37 | this->step_width_ = updated_step_width; 38 | } 39 | 40 | } // namespace s2e::numerical_integration 41 | 42 | #endif // S2E_LIBRARY_NUMERICAL_INTEGRATION_EMBEDDED_RUNGE_KUTTA_IMPLEMENTATION_HPP_ 43 | -------------------------------------------------------------------------------- /src/math_physics/randomization/minimal_standard_linear_congruential_generator.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file minimal_standard_linear_congruential_generator.hpp 3 | * @brief Randomization with Park and Miller's multiplicative congruential method 4 | * @note ran0 function in "NUMERICAL RECIPES in C, p.206" 5 | */ 6 | 7 | #ifndef S2E_LIBRARY_RANDOMIZATION_MINIMAL_STANDARD_LINEAR_CONGRUENTIAL_GENERATOR_HPP_ 8 | #define S2E_LIBRARY_RANDOMIZATION_MINIMAL_STANDARD_LINEAR_CONGRUENTIAL_GENERATOR_HPP_ 9 | 10 | namespace s2e::randomization { 11 | 12 | /** 13 | * @class MinimalStandardLcg 14 | * @brief Randomization with Park and Miller's multiplicative congruential and mixed method 15 | */ 16 | class MinimalStandardLcg { 17 | public: 18 | static const long kA = 16807; //!< Coefficient a for multiplication 19 | static const long kM = 2147483647; //!< Divisor for modulo 20 | 21 | /** 22 | * @fn MinimalStandardLcg 23 | * @brief Default constructor with default seed value 24 | */ 25 | MinimalStandardLcg(); 26 | /** 27 | * @fn MinimalStandardLcg 28 | * @brief Default constructor with seed value 29 | * @param [in] seed: Seed of randomization 30 | */ 31 | explicit MinimalStandardLcg(const long seed); 32 | 33 | /** 34 | * @fn Initialize 35 | * @brief Set seed value 36 | * @param [in] seed: Seed of randomization 37 | */ 38 | void Initialize(const long seed); 39 | 40 | /** 41 | * @fn Cast operator of double type 42 | * @brief Generate randomized value when casting 43 | * @return Generated randomized value 44 | */ 45 | operator double(); 46 | 47 | private: 48 | static const double a_m_; //!< A/M 49 | static const long q_ = 127773; //!< Integer part of A/M 50 | static const long r_ = 2836; //!< m mod a 51 | 52 | long seed_; //!< Seed of randomization 53 | }; 54 | 55 | } // namespace s2e::randomization 56 | 57 | #endif // S2E_LIBRARY_RANDOMIZATION_MINIMAL_STANDARD_LINEAR_CONGRUENTIAL_GENERATOR_HPP_ 58 | -------------------------------------------------------------------------------- /example/src/simulation/ground_station/sample_ground_station_components.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file sample_ground_station_components.hpp 3 | * @brief An example of ground station related components list 4 | */ 5 | 6 | #ifndef S2E_SIMULATION_SAMPLE_GROUND_STATION_SAMPLE_GROUND_STATION_COMPONENTS_HPP_ 7 | #define S2E_SIMULATION_SAMPLE_GROUND_STATION_SAMPLE_GROUND_STATION_COMPONENTS_HPP_ 8 | 9 | #include 10 | #include 11 | 12 | namespace s2e::sample { 13 | 14 | /** 15 | * @class SampleGsComponents 16 | * @brief An example of ground station related components list class 17 | */ 18 | class SampleGsComponents { 19 | public: 20 | /** 21 | * @fn SampleGsComponents 22 | * @brief Constructor 23 | */ 24 | SampleGsComponents(const simulation::SimulationConfiguration* configuration); 25 | /** 26 | * @fn ~SampleGsComponents 27 | * @brief Destructor 28 | */ 29 | ~SampleGsComponents(); 30 | /** 31 | * @fn CompoLogSetUp 32 | * @brief Log setup for ground station components 33 | */ 34 | void CompoLogSetUp(logger::Logger& logger); 35 | 36 | // Getter 37 | /** 38 | * @fn GetAntenna 39 | * @brief Return antenna 40 | */ 41 | inline components::Antenna* GetAntenna() const { return antenna_; } 42 | /** 43 | * @fn GetGsCalculator 44 | * @brief Return ground station calculator 45 | */ 46 | inline components::GroundStationCalculator* GetGsCalculator() const { return gs_calculator_; } 47 | 48 | private: 49 | components::Antenna* antenna_; //!< Antenna on ground station 50 | components::GroundStationCalculator* gs_calculator_; //!< Ground station calculation algorithm 51 | const simulation::SimulationConfiguration* configuration_; //!< Simulation setting 52 | }; 53 | 54 | } // namespace s2e::sample 55 | 56 | #endif // S2E_SIMULATION_SAMPLE_GROUND_STATION_SAMPLE_GROUND_STATION_COMPONENTS_HPP_ 57 | -------------------------------------------------------------------------------- /src/math_physics/math/matrix_vector.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file matrix_vector.hpp 3 | * @brief Template library for Matrix-Vector calculation 4 | */ 5 | 6 | #ifndef S2E_LIBRARY_MATH_MATRIX_VECTOR_HPP_ 7 | #define S2E_LIBRARY_MATH_MATRIX_VECTOR_HPP_ 8 | 9 | #include "matrix.hpp" 10 | #include "vector.hpp" 11 | 12 | namespace s2e::math { 13 | 14 | /** 15 | * @fn operator* 16 | * @brief Multiply matrix and vector 17 | * @param [in] matrix: Target matrix 18 | * @param [in] vector: Target vector 19 | * @return Result of multiplied matrix 20 | */ 21 | template 22 | Vector operator*(const Matrix& matrix, const Vector& vector); 23 | 24 | /** 25 | * @fn CalcInverseMatrix 26 | * @brief Calculate inverse matrix 27 | * @param [in] matrix: Target matrix 28 | * @return Inverse matrix 29 | */ 30 | template 31 | Matrix CalcInverseMatrix(const Matrix& matrix); 32 | 33 | /** 34 | * @fn LuDecomposition 35 | * @brief LU decomposition 36 | * @note Warning: a is overwritten. 37 | * @param [in/out] matrix: Target matrix 38 | * @param [in] index: Array to store row/column switch information 39 | * @return Result of LU decomposed matrix 40 | */ 41 | template 42 | Matrix& LuDecomposition(Matrix& matrix, size_t index[]); 43 | 44 | /** 45 | * @fn SolveLinearSystemWithLu 46 | * @brief Solve linear system of equation with LU decomposition 47 | * @param [in] matrix: LU decomposed coefficient matrix 48 | * @param [in] index: Array to store row/column switch information 49 | * @param [in] vector: Right hand side vector of the linear system 50 | * @return Result vector 51 | */ 52 | template 53 | Vector& SolveLinearSystemWithLu(const Matrix& matrix, const size_t index[], Vector& vector); 54 | 55 | } // namespace s2e::math 56 | 57 | #include "matrix_vector_template_functions.hpp" 58 | 59 | #endif // S2E_LIBRARY_MATH_MATRIX_VECTOR_HPP_ 60 | -------------------------------------------------------------------------------- /src/components/base/component.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file component.cpp 3 | * @brief Base class for component emulation. All components have to inherit this. 4 | */ 5 | 6 | #include "component.hpp" 7 | 8 | namespace s2e::components { 9 | 10 | Component::Component(const unsigned int prescaler, environment::ClockGenerator* clock_generator, const unsigned int fast_prescaler) 11 | : clock_generator_(clock_generator) { 12 | power_port_ = new PowerPort(); 13 | clock_generator_->RegisterComponent(this); 14 | prescaler_ = (prescaler > 0) ? prescaler : 1; 15 | fast_prescaler_ = (fast_prescaler > 0) ? fast_prescaler : 1; 16 | } 17 | 18 | Component::Component(const unsigned int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, 19 | const unsigned int fast_prescaler) 20 | : clock_generator_(clock_generator), power_port_(power_port) { 21 | clock_generator_->RegisterComponent(this); 22 | prescaler_ = (prescaler > 0) ? prescaler : 1; 23 | fast_prescaler_ = (fast_prescaler > 0) ? fast_prescaler : 1; 24 | } 25 | 26 | Component::Component(const Component& object) { 27 | prescaler_ = object.prescaler_; 28 | fast_prescaler_ = object.fast_prescaler_; 29 | needs_fast_update_ = object.needs_fast_update_; 30 | clock_generator_ = object.clock_generator_; 31 | clock_generator_->RegisterComponent(this); 32 | power_port_ = object.power_port_; 33 | } 34 | 35 | Component::~Component() { clock_generator_->RemoveComponent(this); } 36 | 37 | void Component::Tick(const unsigned int count) { 38 | if (count % prescaler_ > 0) return; 39 | if (power_port_->GetIsOn()) { 40 | MainRoutine(count); 41 | } else { 42 | PowerOffRoutine(); 43 | } 44 | } 45 | 46 | void Component::FastTick(const unsigned int fast_count) { 47 | if (fast_count % fast_prescaler_ > 0) return; 48 | if (power_port_->GetIsOn()) { 49 | FastUpdate(); 50 | } else { 51 | PowerOffRoutine(); 52 | } 53 | } 54 | 55 | } // namespace s2e::components 56 | -------------------------------------------------------------------------------- /src/math_physics/planet_rotation/moon_rotation_utilities.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file moon_rotation_utilities.hpp 3 | * @brief Functions to calculate the moon rotation frame conversion 4 | * @note Ref: A Standardized Lunar Coordinate System for the Lunar Reconnaissance Orbiter and Lunar Datasets 5 | * https://lunar.gsfc.nasa.gov/library/LunCoordWhitePaper-10-08.pdf 6 | * https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/planets/de430_moon_coord.pdf 7 | */ 8 | 9 | #ifndef S2E_LIBRARY_PLANET_ROTATION_MOON_MEAN_EARTH_PRINCIPAL_AXIS_FRAME_HPP_ 10 | #define S2E_LIBRARY_PLANET_ROTATION_MOON_MEAN_EARTH_PRINCIPAL_AXIS_FRAME_HPP_ 11 | 12 | #include "math_physics/math/matrix.hpp" 13 | #include "math_physics/math/vector.hpp" 14 | 15 | namespace s2e::planet_rotation { 16 | 17 | /** 18 | * @fn CalcDcmEciToPrincipalAxis 19 | * @brief Calculate DCM from ECI to PA (Principal Axis) moon fixed frame 20 | * @param[in] moon_position_eci_m: Moon position vector @ ECI frame [m] 21 | * @param[in] moon_velocity_eci_m_s: Moon velocity vector @ ECI frame [m/s] 22 | */ 23 | math::Matrix<3, 3> CalcDcmEciToPrincipalAxis(const math::Vector<3> moon_position_eci_m, const math::Vector<3> moon_velocity_eci_m_s); 24 | 25 | /** 26 | * @fn CalcDcmEciToMeanEarth 27 | * @brief Calculate DCM from ECI to ME (Mean Earth) moon fixed frame 28 | * @param[in] moon_position_eci_m: Moon position vector @ ECI frame [m] 29 | * @param[in] moon_velocity_eci_m_s: Moon velocity vector @ ECI frame [m/s] 30 | */ 31 | math::Matrix<3, 3> CalcDcmEciToMeanEarth(const math::Vector<3> moon_position_eci_m, const math::Vector<3> moon_velocity_eci_m_s); 32 | 33 | /** 34 | * @fn CalcDcmMeToPrincipalAxis 35 | * @brief Calculate DCM from ME (Mean Earth) moon fixed frame to PA (Principal Axis) moon fixed frame 36 | */ 37 | math::Matrix<3, 3> CalcDcmMeanEarthToPrincipalAxis(); 38 | 39 | } // namespace s2e::planet_rotation 40 | 41 | #endif // S2E_LIBRARY_PLANET_ROTATION_MOON_MEAN_EARTH_PRINCIPAL_AXIS_FRAME_HPP_ 42 | -------------------------------------------------------------------------------- /src/environment/global/clock_generator.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file clock_generator.hpp 3 | * @brief Class to generate clock for classes which have ITickable 4 | */ 5 | 6 | #ifndef S2E_ENVIRONMENT_GLOBAL_CLOCK_GENERATOR_HPP_ 7 | #define S2E_ENVIRONMENT_GLOBAL_CLOCK_GENERATOR_HPP_ 8 | 9 | #include 10 | #include 11 | 12 | #include "simulation_time.hpp" 13 | 14 | namespace s2e::environment { 15 | 16 | /** 17 | * @class ClockGenerator 18 | * @brief Class to generate clock for classes which have ITickable 19 | */ 20 | class ClockGenerator { 21 | public: 22 | /** 23 | * @fn ~ClockGenerator 24 | * @brief Destructor 25 | */ 26 | ~ClockGenerator(); 27 | 28 | /** 29 | * @fn RegisterComponent 30 | * @brief Register component which has ITickable 31 | * @param [in] tickable: Component class 32 | */ 33 | void RegisterComponent(components::ITickable* tickable); 34 | /** 35 | * @fn RemoveComponent 36 | * @brief Removed registered component 37 | * @param [in] tickable: Registered component class 38 | */ 39 | void RemoveComponent(components::ITickable* tickable); 40 | /** 41 | * @fn TickToComponents 42 | * @brief Execute tick function of all registered components 43 | */ 44 | void TickToComponents(); 45 | /** 46 | * @fn UpdateComponents 47 | * @brief Execute TickToComponents when component update timing 48 | * @param [in] simulation_time: Simulation time 49 | */ 50 | void UpdateComponents(const SimulationTime* simulation_time); 51 | /** 52 | * @fn ClearTimerCount 53 | * @brief Clear time count 54 | */ 55 | inline void ClearTimerCount(void) { timer_count_ = 0; } 56 | 57 | private: 58 | std::vector components_; //!< Component list fot tick 59 | unsigned int timer_count_; //!< Timer count TODO: change to long? 60 | }; 61 | 62 | } // namespace s2e::environment 63 | 64 | #endif // S2E_ENVIRONMENT_GLOBAL_CLOCK_GENERATOR_HPP_ 65 | -------------------------------------------------------------------------------- /src/utilities/ring_buffer.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ring_buffer.cpp 3 | * @brief Class to emulate ring buffer 4 | */ 5 | 6 | #include "ring_buffer.hpp" 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | namespace s2e::utilities { 14 | 15 | RingBuffer::RingBuffer(int buffer_size) : buffer_size_(buffer_size) { 16 | buffer_ = new byte[buffer_size]; 17 | write_pointer_ = 0; 18 | read_pointer_ = 0; 19 | } 20 | 21 | RingBuffer::~RingBuffer() { delete[] buffer_; } 22 | 23 | int RingBuffer::Write(const byte* buffer, const unsigned int offset, const unsigned int data_length) { 24 | unsigned int write_count = 0; 25 | while (write_count != data_length) { 26 | unsigned int write_len = std::min(buffer_size_ - write_pointer_, data_length - write_count); 27 | memcpy(&buffer_[write_pointer_], &buffer[offset + write_count], write_len); 28 | write_pointer_ = (write_pointer_ + write_len == buffer_size_) ? 0 : write_pointer_ + write_len; 29 | write_count += write_len; 30 | } 31 | 32 | return write_count; 33 | } 34 | 35 | int RingBuffer::Read(byte* buffer, const unsigned int offset, const unsigned int data_length) { 36 | unsigned int read_count = 0; 37 | // There are four behaviors depending on whether the RP overtakes the WP, or 38 | // whether all of the RP to the WP are requested by data_length. 39 | while (read_count != data_length && write_pointer_ != read_pointer_) { 40 | unsigned int read_len = (write_pointer_ > read_pointer_) ? std::min(write_pointer_ - read_pointer_, data_length - read_count) 41 | : std::min(buffer_size_ - read_pointer_, data_length - read_count); 42 | memcpy(&buffer[offset + read_count], &buffer_[read_pointer_], read_len); 43 | read_pointer_ = (read_pointer_ + read_len == buffer_size_) ? 0 : read_pointer_ + read_len; 44 | read_count += read_len; 45 | } 46 | 47 | return read_count; 48 | } 49 | 50 | } // namespace s2e::utilities 51 | -------------------------------------------------------------------------------- /scripts/Plot/plot_satellite_orbit_on_miller.py: -------------------------------------------------------------------------------- 1 | # 2 | # Plot Satellite Position on Miller Projection Map 3 | # 4 | # arg[1] : read_file_tag : time tag for default CSV output log file. ex. 220627_142946 5 | # 6 | 7 | # 8 | # Import 9 | # 10 | # plots 11 | import matplotlib.pyplot as plt 12 | # local function 13 | from make_miller_projection_map import make_miller_projection_map 14 | from common import find_latest_log_tag 15 | from common import add_log_file_arguments 16 | from common import read_scalar_from_csv 17 | # arguments 18 | import argparse 19 | 20 | # Arguments 21 | aparser = argparse.ArgumentParser() 22 | aparser = add_log_file_arguments(aparser) 23 | aparser.add_argument('--no-gui', action='store_true') 24 | args = aparser.parse_args() 25 | 26 | # 27 | # Read Arguments 28 | # 29 | 30 | # log file path 31 | path_to_logs = args.logs_dir 32 | 33 | read_file_tag = args.file_tag 34 | if read_file_tag == None: 35 | print("file tag does not found. use latest.") 36 | read_file_tag = find_latest_log_tag(path_to_logs) 37 | 38 | print("log: " + read_file_tag) 39 | 40 | # 41 | # CSV file name 42 | # 43 | read_file_name = path_to_logs + '/' + 'logs_' + read_file_tag + '/' + read_file_tag + '_default.csv' 44 | 45 | # 46 | # Base Map projection 47 | # 48 | map = make_miller_projection_map() 49 | 50 | # 51 | # Data read and edit 52 | # 53 | # Read S2E CSV 54 | sc_lat_deg = read_scalar_from_csv(read_file_name, 'spacecraft_latitude[rad]') * 180/3.14 55 | sc_lon_deg = read_scalar_from_csv(read_file_name, 'spacecraft_longitude[rad]') * 180/3.14 56 | sc_map_lon, sc_map_lat = map(sc_lon_deg, sc_lat_deg) 57 | 58 | # 59 | # Plot 60 | # 61 | # Plot SC position with color 62 | for i in range(len(sc_map_lat)): 63 | map.plot(sc_map_lon[i], sc_map_lat[i], color='blue', marker='o', markersize=3, linestyle='None') 64 | 65 | plt.title('Satellite Orbit on Miller Projection Map: logs_' + read_file_tag) 66 | plt.show() 67 | 68 | if args.no_gui: 69 | plt.savefig(read_file_tag + "_orbit_on_miller.png") 70 | else: 71 | plt.show() 72 | -------------------------------------------------------------------------------- /src/components/real/power/power_control_unit.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @file power_control_unit.cpp 3 | * @brief Component emulation of Power Control Unit 4 | */ 5 | #include "power_control_unit.hpp" 6 | 7 | namespace s2e::components { 8 | 9 | PowerControlUnit::PowerControlUnit(environment::ClockGenerator* clock_generator) : Component(1, clock_generator) {} 10 | 11 | PowerControlUnit::PowerControlUnit(int prescaler, environment::ClockGenerator* clock_generator) : Component(prescaler, clock_generator) {} 12 | 13 | PowerControlUnit::~PowerControlUnit() {} 14 | 15 | void PowerControlUnit::MainRoutine(const int time_count) { 16 | UNUSED(time_count); 17 | 18 | // double current_ = power_ports_[1]->GetCurrentConsumption_A(); 19 | } 20 | 21 | int PowerControlUnit::ConnectPort(const int port_id, const double current_limit_A) { 22 | // The port is already used 23 | if (power_ports_[port_id] != nullptr) return -1; 24 | 25 | power_ports_[port_id] = new PowerPort(port_id, current_limit_A); 26 | return 0; 27 | } 28 | 29 | int PowerControlUnit::ConnectPort(const int port_id, const double current_limit_A, const double minimum_voltage_V, 30 | const double assumed_power_consumption_W) { 31 | // The port is already used 32 | if (power_ports_[port_id] != nullptr) return -1; 33 | 34 | power_ports_[port_id] = new PowerPort(port_id, current_limit_A, minimum_voltage_V, assumed_power_consumption_W); 35 | return 0; 36 | } 37 | 38 | int PowerControlUnit::ClosePort(const int port_id) { 39 | // The port not used 40 | if (power_ports_[port_id] == nullptr) return -1; 41 | 42 | PowerPort* port = power_ports_.at(port_id); 43 | delete port; 44 | power_ports_.erase(port_id); 45 | return 0; 46 | } 47 | 48 | std::string PowerControlUnit::GetLogHeader() const { 49 | std::string str_tmp = ""; 50 | return str_tmp; 51 | } 52 | 53 | std::string PowerControlUnit::GetLogValue() const { 54 | std::string str_tmp = ""; 55 | return str_tmp; 56 | } 57 | 58 | } // namespace s2e::components 59 | -------------------------------------------------------------------------------- /src/components/real/communication/antenna_radiation_pattern.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @file antenna_radiation_pattern.cpp 3 | * @brief Class to manage antenna radiation pattern 4 | */ 5 | 6 | #include "antenna_radiation_pattern.hpp" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace s2e::components { 13 | 14 | AntennaRadiationPattern::AntennaRadiationPattern() { gain_dBi_.assign(length_theta_, std::vector(length_phi_, 0.0)); } 15 | 16 | AntennaRadiationPattern::AntennaRadiationPattern(const std::string file_path, const size_t length_theta, const size_t length_phi, 17 | const double theta_max_rad, const double phi_max_rad) 18 | : length_theta_(length_theta), length_phi_(length_phi), theta_max_rad_(theta_max_rad), phi_max_rad_(phi_max_rad) { 19 | setting_file_reader::IniAccess gain_file(file_path); 20 | gain_file.ReadCsvDouble(gain_dBi_, (std::max)(length_theta_, length_phi_)); 21 | } 22 | 23 | AntennaRadiationPattern::~AntennaRadiationPattern() {} 24 | 25 | double AntennaRadiationPattern::GetGain_dBi(const double theta_rad, const double phi_rad) const { 26 | // Argument check 27 | double theta_rad_clipped = theta_rad; 28 | double phi_rad_clipped = phi_rad; 29 | if (theta_rad_clipped < 0.0) theta_rad_clipped = 0.0; 30 | if (theta_rad_clipped > theta_max_rad_) theta_rad_clipped = theta_max_rad_; 31 | if (phi_rad_clipped < 0.0) phi_rad_clipped = 0.0; 32 | if (phi_rad_clipped > phi_max_rad_) phi_rad_clipped = phi_max_rad_; 33 | 34 | // Calc index 35 | size_t theta_idx = (size_t)(length_theta_ * theta_rad_clipped / theta_max_rad_ + 0.5); 36 | if (theta_idx >= length_theta_) theta_idx = length_theta_ - 1; 37 | size_t phi_idx = (size_t)(length_phi_ * phi_rad_clipped / phi_max_rad_ + 0.5); 38 | if (phi_idx >= length_phi_) phi_idx = length_phi_ - 1; 39 | 40 | return gain_dBi_[theta_idx][phi_idx]; 41 | } 42 | 43 | } // namespace s2e::components 44 | -------------------------------------------------------------------------------- /src/math_physics/numerical_integration/dormand_prince_5.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file dormand_prince_5.hpp 3 | * @brief Class for 5th order Dormand and Prince method 4 | * @note Ref: J. R. Dormand and P. J. Prince, "A family of embedded Runge-Kutta formulae", 1980 5 | * J. R. Dormand and P. J. Prince, "Runge-Kutta Triples", 1986 6 | * O. Montenbruck and E. Gill, "State interpolation for on-board navigation systems", 2001 7 | */ 8 | 9 | #ifndef S2E_LIBRARY_NUMERICAL_INTEGRATION_DORMAND_PRINCE_5_HPP_ 10 | #define S2E_LIBRARY_NUMERICAL_INTEGRATION_DORMAND_PRINCE_5_HPP_ 11 | 12 | #include "embedded_runge_kutta.hpp" 13 | 14 | namespace s2e::numerical_integration { 15 | 16 | /** 17 | * @class DormandPrince5 18 | * @brief Class for 5th order Dormand and Prince method 19 | */ 20 | template 21 | class DormandPrince5 : public EmbeddedRungeKutta { 22 | public: 23 | /** 24 | * @fn DormandPrince5 25 | * @brief Constructor 26 | * @param [in] step_width: Step width 27 | * @param [in] ode: Ordinary differential equation 28 | */ 29 | DormandPrince5(const double step_width, const InterfaceOde& ode); 30 | /** 31 | * @fn CalcInterpolationState 32 | * @brief Calculate interpolation state 33 | * @param [in] sigma: Sigma value (0 < sigma < 1) for interpolation 34 | * @return : interpolated state x(t0 + sigma * h) 35 | */ 36 | math::Vector CalcInterpolationState(const double sigma) const override; 37 | 38 | private: 39 | std::vector> coefficients_; //!< Coefficients to calculate interpolation weights 40 | /** 41 | * @fn CalcInterpolationWeights 42 | * @brief Calculate weights for interpolation 43 | * @param [in] sigma: Sigma value (0 < sigma < 1) for interpolation 44 | * @return : weights for interpolation 45 | */ 46 | std::vector CalcInterpolationWeights(const double sigma) const; 47 | }; 48 | 49 | } // namespace s2e::numerical_integration 50 | 51 | #include "dormand_prince_5_implementation.hpp" 52 | 53 | #endif // S2E_LIBRARY_NUMERICAL_INTEGRATION_DORMAND_PRINCE_5_HPP_ 54 | -------------------------------------------------------------------------------- /example/settings/sample_satellite/components/component_interference.ini: -------------------------------------------------------------------------------- 1 | [MTQ_MAGNETOMETER_INTERFERENCE_0] 2 | 3 | // x: MTQ output vector at MTQ component frame [Am2] 4 | // y: Additional bias at magnetometer component frame [nT] 5 | // A1, A2, ...: Polynomial coefficients defined in this file 6 | // ** measns Hadamard product 7 | // y = A1 * x + A2 * x ** x + A3 * x ** x ** x ... 8 | 9 | polynomial_degree = 1 10 | 11 | // We do not have zero coefficients 12 | 13 | // 1st coefficients of additional bias A1 [nT/Am2] 14 | additional_bias_by_mtq_coefficients_1(0) = 10000.0 // MTQ X -> Magnetometer X 15 | additional_bias_by_mtq_coefficients_1(1) = -20000.0 // MTQ X -> Magnetometer Y 16 | additional_bias_by_mtq_coefficients_1(2) = 30000.0 // MTQ X -> Magnetometer Z 17 | additional_bias_by_mtq_coefficients_1(3) = 40000.0 // MTQ Y -> Magnetometer X 18 | additional_bias_by_mtq_coefficients_1(4) = -50000.0 // MTQ Y -> Magnetometer Y 19 | additional_bias_by_mtq_coefficients_1(5) = 60000.0 // MTQ Y -> Magnetometer Z 20 | additional_bias_by_mtq_coefficients_1(6) = 70000.0 // MTQ Z -> Magnetometer X 21 | additional_bias_by_mtq_coefficients_1(7) = -80000.0 // MTQ Z -> Magnetometer Y 22 | additional_bias_by_mtq_coefficients_1(8) = 90000.0 // MTQ Z -> Magnetometer Z 23 | 24 | // 2nd coefficients of additional bias A2 [nT/Am2^2] 25 | additional_bias_by_mtq_coefficients_2(0) = -10000.0 // MTQ X -> Magnetometer X 26 | additional_bias_by_mtq_coefficients_2(1) = 20000.0 // MTQ X -> Magnetometer Y 27 | additional_bias_by_mtq_coefficients_2(2) = -30000.0 // MTQ X -> Magnetometer Z 28 | additional_bias_by_mtq_coefficients_2(3) = -40000.0 // MTQ Y -> Magnetometer X 29 | additional_bias_by_mtq_coefficients_2(4) = 50000.0 // MTQ Y -> Magnetometer Y 30 | additional_bias_by_mtq_coefficients_2(5) = -60000.0 // MTQ Y -> Magnetometer Z 31 | additional_bias_by_mtq_coefficients_2(6) = -70000.0 // MTQ Z -> Magnetometer X 32 | additional_bias_by_mtq_coefficients_2(7) = 80000.0 // MTQ Z -> Magnetometer Y 33 | additional_bias_by_mtq_coefficients_2(8) = -90000.0 // MTQ Z -> Magnetometer Z 34 | -------------------------------------------------------------------------------- /src/math_physics/gnss/gnss_satellite_number.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file gnss_satellite_number.cpp 3 | * @brief Manage satellite number defined in RINEX v4 4 | */ 5 | 6 | #include "gnss_satellite_number.hpp" 7 | 8 | namespace s2e::gnss { 9 | 10 | size_t ConvertGnssSatelliteNumberToIndex(const std::string satellite_number) { 11 | switch (satellite_number.front()) { 12 | case 'G': 13 | return stoi(satellite_number.substr(1)) + kGpsIndexBegin - 1; 14 | case 'R': 15 | return stoi(satellite_number.substr(1)) + kGlonassIndexBegin - 1; 16 | case 'E': 17 | return stoi(satellite_number.substr(1)) + kGalileoIndexBegin - 1; 18 | case 'C': 19 | return stoi(satellite_number.substr(1)) + kBeidouIndexBegin - 1; 20 | case 'J': 21 | return stoi(satellite_number.substr(1)) + kQzssIndexBegin - 1; 22 | case 'I': 23 | return stoi(satellite_number.substr(1)) + kNavicIndexBegin - 1; 24 | default: 25 | return UINT32_MAX; 26 | break; 27 | } 28 | } 29 | 30 | std::string ConvertIndexToGnssSatelliteNumber(const size_t index) { 31 | std::string output; 32 | size_t prn_number = 0; 33 | 34 | if (index < kGlonassIndexBegin) { 35 | output = 'G'; 36 | prn_number = index - kGpsIndexBegin + 1; 37 | } else if (index < kGalileoIndexBegin) { 38 | output = 'R'; 39 | prn_number = index - kGlonassIndexBegin + 1; 40 | } else if (index < kBeidouIndexBegin) { 41 | output = 'E'; 42 | prn_number = index - kGalileoIndexBegin + 1; 43 | } else if (index < kQzssIndexBegin) { 44 | output = 'C'; 45 | prn_number = index - kBeidouIndexBegin + 1; 46 | } else if (index < kNavicIndexBegin) { 47 | output = 'J'; 48 | prn_number = index - kQzssIndexBegin + 1; 49 | } else if (index < kTotalNumberOfGnssSatellite) { 50 | output = 'I'; 51 | prn_number = index - kNavicIndexBegin + 1; 52 | } else { 53 | return "err"; 54 | } 55 | 56 | if (prn_number < 10) { 57 | output += '0'; 58 | } 59 | output += std::to_string(prn_number); 60 | 61 | return output; 62 | } 63 | 64 | } // namespace s2e::gnss 65 | -------------------------------------------------------------------------------- /src/math_physics/time_system/date_time_format.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file date_time_format.cpp 3 | * @brief Class to handle Gregorian date and time format 4 | */ 5 | 6 | #define _CRT_SECURE_NO_WARNINGS // for sscanf 7 | 8 | #include "date_time_format.hpp" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace s2e::time_system { 15 | 16 | DateTime::DateTime(const std::string date_time) { 17 | sscanf(date_time.c_str(), "%zu/%zu/%zu %zu:%zu:%lf", &year_, &month_, &day_, &hour_, &minute_, &second_); 18 | } 19 | 20 | DateTime::DateTime(const EpochTime epoch_time) { 21 | // No leap second calculation 22 | const int mday[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 23 | 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //!< Number of days in a month 24 | int days, sec, mon, day; 25 | 26 | // leap year if year%4==0 in 1901-2099 27 | days = (int)(epoch_time.GetTime_s() / 86400); 28 | sec = (int)(epoch_time.GetTime_s() - (time_t)days * 86400); 29 | 30 | for (day = days % 1461, mon = 0; mon < 48; mon++) { 31 | if (day >= mday[mon]) 32 | day -= mday[mon]; 33 | else 34 | break; 35 | } 36 | 37 | year_ = 1970 + days / 1461 * 4 + mon / 12; 38 | month_ = mon % 12 + 1; 39 | day_ = day + 1; 40 | hour_ = sec / 3600; 41 | minute_ = sec % 3600 / 60; 42 | second_ = sec % 60 + epoch_time.GetFraction_s(); 43 | } 44 | 45 | std::string DateTime::GetAsString() const { 46 | std::stringstream stream; 47 | stream << std::setw(4) << std::setfill('0') << (int)year_ << "/"; 48 | stream << std::setw(2) << std::setfill('0') << (int)month_ << "/"; 49 | stream << std::setw(2) << std::setfill('0') << (int)day_ << " "; 50 | 51 | stream << std::setw(2) << std::setfill('0') << (int)hour_ << ":"; 52 | stream << std::setw(2) << std::setfill('0') << (int)minute_ << ":"; 53 | stream << second_; 54 | std::string output = stream.str(); 55 | return output; 56 | } 57 | 58 | } // namespace s2e::time_system 59 | -------------------------------------------------------------------------------- /src/components/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(COMPONENT) 2 | cmake_minimum_required(VERSION 3.13) 3 | 4 | set(SOURCE_FILES 5 | base/component.cpp 6 | base/uart_communication_with_obc.cpp 7 | base/i2c_controller.cpp 8 | base/i2c_target_communication_with_obc.cpp 9 | base/gpio_connection_with_obc.cpp 10 | 11 | real/aocs/gyro_sensor.cpp 12 | real/aocs/magnetometer.cpp 13 | real/aocs/magnetorquer.cpp 14 | real/aocs/reaction_wheel_ode.cpp 15 | real/aocs/reaction_wheel.cpp 16 | real/aocs/reaction_wheel_jitter.cpp 17 | real/aocs/star_sensor.cpp 18 | real/aocs/sun_sensor.cpp 19 | real/aocs/gnss_receiver.cpp 20 | real/aocs/mtq_magnetometer_interference.cpp 21 | 22 | real/cdh/on_board_computer.cpp 23 | real/cdh/on_board_computer_with_c2a.cpp 24 | 25 | real/communication/antenna.cpp 26 | real/communication/antenna_radiation_pattern.cpp 27 | real/communication/ground_station_calculator.cpp 28 | 29 | examples/example_change_structure.cpp 30 | examples/example_serial_communication_with_obc.cpp 31 | examples/example_serial_communication_for_hils.cpp 32 | examples/example_i2c_controller_for_hils.cpp 33 | examples/example_i2c_target_for_hils.cpp 34 | 35 | ideal/force_generator.cpp 36 | ideal/torque_generator.cpp 37 | ideal/angular_velocity_observer.cpp 38 | ideal/attitude_observer.cpp 39 | ideal/orbit_observer.cpp 40 | 41 | real/mission/telescope.cpp 42 | 43 | real/power/power_control_unit.cpp 44 | real/power/battery.cpp 45 | real/power/pcu_initial_study.cpp 46 | real/power/solar_array_panel.cpp 47 | real/power/csv_scenario_interface.cpp 48 | 49 | real/propulsion/simple_thruster.cpp 50 | 51 | ports/gpio_port.cpp 52 | ports/power_port.cpp 53 | ports/uart_port.cpp 54 | ports/i2c_port.cpp 55 | ) 56 | 57 | if(USE_HILS) 58 | set(SOURCE_FILES 59 | ${SOURCE_FILES} 60 | ports/hils_uart_port.cpp 61 | ports/hils_i2c_target_port.cpp 62 | ) 63 | endif() 64 | 65 | if(USE_C2A_COMMAND_SENDER) 66 | set(SOURCE_FILES 67 | ${SOURCE_FILES} 68 | real/communication/wings_command_sender_to_c2a.cpp 69 | ) 70 | endif() 71 | 72 | add_library(${PROJECT_NAME} OBJECT 73 | ${SOURCE_FILES} 74 | ) 75 | 76 | include(../../common.cmake) 77 | -------------------------------------------------------------------------------- /src/math_physics/orbit/sgp4/sgp4ext.h: -------------------------------------------------------------------------------- 1 | #ifndef _sgp4ext_ 2 | #define _sgp4ext_ 3 | /* ---------------------------------------------------------------- 4 | * 5 | * sgp4ext.h 6 | * 7 | * this file contains extra routines needed for the main test program for 8 | * sgp4. these routines are derived from the astro libraries. 9 | * 10 | * companion code for 11 | * fundamentals of astrodynamics and applications 12 | * 2007 13 | * by david vallado 14 | * 15 | * (w) 719-573-2600, email dvallado@agi.com 16 | * 17 | * current : 18 | * 20 apr 07 david vallado 19 | * misc documentation updates 20 | * changes : 21 | * 14 aug 06 david vallado 22 | * original baseline 23 | * ---------------------------------------------------------------- */ 24 | 25 | #include 26 | #include 27 | 28 | // ------------------------- function declarations ------------------------- 29 | 30 | int RotationX(const double* bfr, double* aft, double theta); 31 | int RotationY(const double* bfr, double* aft, double theta); 32 | int RotationZ(const double* bfr, double* aft, double theta); 33 | double AcTan(double sinx, double cosx); 34 | double FMod2p(double x); 35 | double sgn(double); 36 | 37 | double mag(double[]); 38 | 39 | void cross(double[], double[], double[]); 40 | 41 | double dot(double[], double[]); 42 | 43 | double angle(double[], double[]); 44 | 45 | void newtonnu(double ecc, double nu, double& e0, double& m); 46 | 47 | void rv2coe(double[], double[], double, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&); 48 | 49 | void jday(int, int, int, int, int, double, double&); 50 | 51 | void days2mdhms(int, double, int&, int&, int&, int&, double&); 52 | 53 | void invjday(double, int&, int&, int&, int&, int&, double&); 54 | void JdToDecyear(double jd, double* decyear); 55 | 56 | float juldayTEST(int, int, int); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/math_physics/math/ordinary_differential_equation_template_functions.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ordinary_differential_equation_template_functions.hpp 3 | * @brief Class for Ordinary Differential Equation (template functions) 4 | */ 5 | #ifndef S2E_LIBRARY_MATH_ORDINARY_DIFFERENTIA_EQUATION_TEMPLATE_FUNCTIONS_HPP_ 6 | #define S2E_LIBRARY_MATH_ORDINARY_DIFFERENTIA_EQUATION_TEMPLATE_FUNCTIONS_HPP_ 7 | 8 | namespace s2e::math { 9 | 10 | template 11 | OrdinaryDifferentialEquation::OrdinaryDifferentialEquation(double step_width_s) 12 | : independent_variable_(0.0), state_(0.0), derivative_(0.0), step_width_s_(step_width_s) {} 13 | 14 | template 15 | void OrdinaryDifferentialEquation::Setup(double initial_independent_variable, const Vector& initial_state) { 16 | independent_variable_ = initial_independent_variable; 17 | state_ = initial_state; 18 | } 19 | 20 | template 21 | OrdinaryDifferentialEquation& OrdinaryDifferentialEquation::operator++() { 22 | Update(); 23 | return *this; 24 | } 25 | 26 | template 27 | void OrdinaryDifferentialEquation::Update() { 28 | DerivativeFunction(independent_variable_, state_, derivative_); // Current derivative calculation 29 | 30 | // 4th order Runge-Kutta method 31 | Vector k1(derivative_); 32 | k1 *= step_width_s_; 33 | Vector k2((double)state_.GetLength()); 34 | DerivativeFunction(independent_variable_ + 0.5 * step_width_s_, state_ + 0.5 * k1, k2); 35 | k2 *= step_width_s_; 36 | Vector k3((double)state_.GetLength()); 37 | DerivativeFunction(independent_variable_ + 0.5 * step_width_s_, state_ + 0.5 * k2, k3); 38 | k3 *= step_width_s_; 39 | Vector k4((double)state_.GetLength()); 40 | DerivativeFunction(independent_variable_ + step_width_s_, state_ + k3, k4); 41 | k4 *= step_width_s_; 42 | 43 | state_ += (1.0 / 6.0) * (k1 + 2.0 * (k2 + k3) + k4); // Update state vector 44 | independent_variable_ += step_width_s_; // Update independent variable 45 | } 46 | 47 | } // namespace s2e::math 48 | 49 | #endif // S2E_LIBRARY_MATH_ORDINARY_DIFFERENTIA_EQUATION_TEMPLATE_FUNCTIONS_HPP_ 50 | -------------------------------------------------------------------------------- /src/components/ideal/angular_velocity_observer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @file angular_velocity_observer.cpp 3 | * @brief Ideal component which can observe angular velocity 4 | */ 5 | 6 | #include "angular_velocity_observer.hpp" 7 | 8 | #include 9 | 10 | namespace s2e::components { 11 | 12 | AngularVelocityObserver::AngularVelocityObserver(const int prescaler, environment::ClockGenerator* clock_generator, Sensor& sensor_base, 13 | const dynamics::attitude::Attitude& attitude) 14 | : Component(prescaler, clock_generator), Sensor(sensor_base), attitude_(attitude) {} 15 | 16 | void AngularVelocityObserver::MainRoutine(const int time_count) { 17 | UNUSED(time_count); 18 | angular_velocity_b_rad_s_ = Measure(attitude_.GetAngularVelocity_b_rad_s()); 19 | } 20 | 21 | std::string AngularVelocityObserver::GetLogHeader() const { 22 | std::string str_tmp = ""; 23 | 24 | std::string sensor_name = "angular_velocity_observer_"; 25 | str_tmp += logger::WriteVector(sensor_name + "measured_value", "b", "rad/s", 3); 26 | 27 | return str_tmp; 28 | } 29 | 30 | std::string AngularVelocityObserver::GetLogValue() const { 31 | std::string str_tmp = ""; 32 | 33 | str_tmp += logger::WriteVector(angular_velocity_b_rad_s_); 34 | 35 | return str_tmp; 36 | } 37 | 38 | AngularVelocityObserver InitializeAngularVelocityObserver(environment::ClockGenerator* clock_generator, const std::string file_name, 39 | double component_step_time_s, const dynamics::attitude::Attitude& attitude) { 40 | setting_file_reader::IniAccess ini_file(file_name); 41 | 42 | int prescaler = ini_file.ReadInt("COMPONENT_BASE", "prescaler"); 43 | if (prescaler <= 1) prescaler = 1; 44 | 45 | // Sensor 46 | Sensor<3> sensor_base = ReadSensorInformation<3>(file_name, component_step_time_s * (double)(prescaler), "ANGULAR_VELOCITY_OBSERVER", "rad_s"); 47 | 48 | AngularVelocityObserver observer(prescaler, clock_generator, sensor_base, attitude); 49 | 50 | return observer; 51 | } 52 | 53 | } // namespace s2e::components 54 | -------------------------------------------------------------------------------- /src/environment/global/global_environment.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file global_environment.cpp 3 | * @brief Class to manage the global environment 4 | */ 5 | 6 | #include "global_environment.hpp" 7 | 8 | #include "setting_file_reader/initialize_file_access.hpp" 9 | 10 | namespace s2e::environment { 11 | 12 | GlobalEnvironment::GlobalEnvironment(const simulation::SimulationConfiguration* simulation_configuration) { Initialize(simulation_configuration); } 13 | 14 | GlobalEnvironment::~GlobalEnvironment() { 15 | delete simulation_time_; 16 | delete celestial_information_; 17 | delete hipparcos_catalogue_; 18 | delete gnss_satellites_; 19 | } 20 | 21 | void GlobalEnvironment::Initialize(const simulation::SimulationConfiguration* simulation_configuration) { 22 | // Get ini file path 23 | setting_file_reader::IniAccess iniAccess = setting_file_reader::IniAccess(simulation_configuration->initialize_base_file_name_); 24 | std::string simulation_time_ini_path = simulation_configuration->initialize_base_file_name_; 25 | 26 | // Initialize 27 | celestial_information_ = InitCelestialInformation(simulation_configuration->initialize_base_file_name_); 28 | simulation_time_ = InitSimulationTime(simulation_time_ini_path); 29 | hipparcos_catalogue_ = InitHipparcosCatalogue(simulation_configuration->initialize_base_file_name_); 30 | gnss_satellites_ = InitGnssSatellites(simulation_configuration->gnss_file_, celestial_information_->GetEarthRotation(), *simulation_time_); 31 | 32 | // Calc initial value 33 | celestial_information_->UpdateAllObjectsInformation(*simulation_time_); 34 | } 35 | 36 | void GlobalEnvironment::Update() { 37 | simulation_time_->UpdateTime(); 38 | celestial_information_->UpdateAllObjectsInformation(*simulation_time_); 39 | gnss_satellites_->Update(*simulation_time_); 40 | } 41 | 42 | void GlobalEnvironment::LogSetup(logger::Logger& logger) { 43 | logger.AddLogList(simulation_time_); 44 | logger.AddLogList(celestial_information_); 45 | logger.AddLogList(gnss_satellites_); 46 | } 47 | 48 | void GlobalEnvironment::Reset(void) { simulation_time_->ResetClock(); } 49 | 50 | } // namespace s2e::environment 51 | --------------------------------------------------------------------------------