Skip to content

Commit

Permalink
Update for s2e v8
Browse files Browse the repository at this point in the history
  • Loading branch information
200km committed Oct 5, 2024
1 parent 7611fe7 commit 1eba680
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ option(USE_C2A "Use C2A" OFF)
option(BUILD_64BIT "Build 64bit" OFF)

# Mac user setting
option(APPLE_SILICON "Build with Apple Silicon" ON)
option(APPLE_SILICON "Build with Apple Silicon" OFF)
# Force build with 64bit for APPLE
if(APPLE)
option(BUILD_64BIT "Build 64bit" ON)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ This repository provides the following samples.

## How to use this branch

- This branch is a sample code for [How To Make New Simulation Scenario](https://github.com/ut-issl/s2e-documents/blob/develop/Tutorials/HowToMakeNewSimulationScenario.md) in the `s2e-documents`.
- This branch is a sample code for [How To Use Monte Carlo Simulation](https://github.com/ut-issl/s2e-documents/blob/develop/Tutorials/HowToUseMonteCarloSimulation.md) in the `s2e-documents`.
- Please follow the tutorial to learn how to use the sample code.
30 changes: 10 additions & 20 deletions settings/user_simulation_base.ini
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,24 @@ simulation_speed_setting = 0

[MONTE_CARLO_EXECUTION]
// Whether Monte-Carlo Simulation is executed or not
monte_carlo_enable = DISABLE
monte_carlo_enable = ENABLE

// Whether you want output the log file for each step
log_enable = ENABLE

// Number of execution
number_of_executions = 100
number_of_executions = 10


[MONTE_CARLO_RANDOMIZATION]
parameter(0) = attitude0.debug
attitude0.debug.randomization_type = CartesianUniform
attitude0.debug.mean_or_min(0) = 0.0
attitude0.debug.mean_or_min(1) = 0.0
attitude0.debug.mean_or_min(2) = 0.0
attitude0.debug.sigma_or_max(0) = 10.0
attitude0.debug.sigma_or_max(1) = 10.0
attitude0.debug.sigma_or_max(2) = 10.0

parameter(1) = attitude0.omega_b
attitude0.omega_b.randomization_type = NoRandomization
attitude0.omega_b.mean_or_min(0) = 0.0
attitude0.omega_b.mean_or_min(1) = 0.0
attitude0.omega_b.mean_or_min(2) = 0.0
attitude0.omega_b.sigma_or_max(0) = 0.05817764 // 3-sigma = 10 [deg/s]
attitude0.omega_b.sigma_or_max(1) = 0.05817764 // 3-sigma = 10 [deg/s]
attitude0.omega_b.sigma_or_max(2) = 0.05817764 // 3-sigma = 10 [deg/s]

parameter(0) = attitude0.angular_velocity_b_rad_s
attitude0.angular_velocity_b_rad_s.randomization_type = CartesianUniform
attitude0.angular_velocity_b_rad_s.mean_or_min(0) = 0.0
attitude0.angular_velocity_b_rad_s.mean_or_min(1) = 0.0
attitude0.angular_velocity_b_rad_s.mean_or_min(2) = 0.0
attitude0.angular_velocity_b_rad_s.sigma_or_max(0) = 0.05817764 // 3-sigma = 10 [deg/s]
attitude0.angular_velocity_b_rad_s.sigma_or_max(1) = 0.05817764 // 3-sigma = 10 [deg/s]
attitude0.angular_velocity_b_rad_s.sigma_or_max(2) = 0.05817764 // 3-sigma = 10 [deg/s]

[CELESTIAL_INFORMATION]
// Whether global celestial information is logged or not
Expand Down
26 changes: 22 additions & 4 deletions src/s2e_user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
#include <string>

// Simulator includes
#include "logger/logger.hpp"
#include "logger/initialize_log.hpp"

// Add custom include files
#include "simulation/monte_carlo_simulation/initialize_monte_carlo_simulation.hpp"
#include "./simulation/case/user_case.hpp"

void print_path(std::string path) {
Expand Down Expand Up @@ -66,9 +67,26 @@ int main(int argc, char *argv[])
std::cout << "\tIni file: ";
print_path(ini_file);

auto simulation_case = UserCase(ini_file);
simulation_case.Initialize();
simulation_case.Main();
s2e::simulation::MonteCarloSimulationExecutor *mc_simulator = s2e::simulation::InitMonteCarloSimulation(ini_file);
s2e::logger::Logger *log_mc_simulator = s2e::logger::InitMonteCarloLog(ini_file, mc_simulator->IsEnabled());

while (mc_simulator->WillExecuteNextCase()) {
auto simulation_case = UserCase(ini_file, *mc_simulator, log_mc_simulator->GetLogPath());
// Initialize
log_mc_simulator->AddLogList(&simulation_case);
if (mc_simulator->GetNumberOfExecutionsDone() == 0) log_mc_simulator->WriteHeaders();
simulation_case.Initialize();

// Main
log_mc_simulator->WriteValues(); // log initial value
simulation_case.Main();
mc_simulator->AtTheEndOfEachCase();
log_mc_simulator->WriteValues(); // log final value
log_mc_simulator->ClearLogList();
}

delete log_mc_simulator;
delete mc_simulator;

end = system_clock::now();
double time = static_cast<double>(duration_cast<microseconds>(end - start).count() / 1000000.0);
Expand Down
20 changes: 19 additions & 1 deletion src/simulation/case/user_case.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

#include "user_case.hpp"

UserCase::UserCase(const std::string initialise_base_file) : s2e::simulation::SimulationCase(initialise_base_file) {}
#include <./simulation/monte_carlo_simulation/simulation_object.hpp>

UserCase::UserCase(const std::string initialize_base_file, s2e::simulation::MonteCarloSimulationExecutor &monte_carlo_simulator, const std::string log_path)
: SimulationCase(initialize_base_file, monte_carlo_simulator, log_path), monte_carlo_simulator_(monte_carlo_simulator) {}

UserCase::~UserCase() { delete spacecraft_; }

Expand All @@ -15,6 +18,12 @@ void UserCase::InitializeTargetObjects() {
const int spacecraft_id = 0;
spacecraft_ = new UserSatellite(&simulation_configuration_, global_environment_, spacecraft_id);

// Monte Carlo Simulation
monte_carlo_simulator_.SetSeed();
monte_carlo_simulator_.RandomizeAllParameters();
s2e::simulation::SimulationObject::SetAllParameters(monte_carlo_simulator_);
monte_carlo_simulator_.AtTheBeginningOfEachCase();

// Register the log output
spacecraft_->LogSetup(*(simulation_configuration_.main_logger_));
}
Expand All @@ -26,11 +35,20 @@ void UserCase::UpdateTargetObjects() {

std::string UserCase::GetLogHeader() const {
std::string str_tmp = "";

str_tmp += s2e::logger::WriteScalar("elapsed_time", "s");
str_tmp += s2e::logger::WriteVector("spacecraft_angular_velocity", "b", "rad/s", 3);
str_tmp += s2e::logger::WriteVector("spacecraft_quaternion", "i2b", "-", 4);

return str_tmp;
}

std::string UserCase::GetLogValue() const {
std::string str_tmp = "";

str_tmp += s2e::logger::WriteScalar(global_environment_->GetSimulationTime().GetElapsedTime_s());
str_tmp += s2e::logger::WriteVector(spacecraft_->GetDynamics().GetAttitude().GetAngularVelocity_b_rad_s(), 3);
str_tmp += s2e::logger::WriteQuaternion(spacecraft_->GetDynamics().GetAttitude().GetQuaternion_i2b());

return str_tmp;
}
7 changes: 6 additions & 1 deletion src/simulation/case/user_case.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define S2E_SIMULATION_CASE_USER_CASE_HPP_

#include <./simulation/case/simulation_case.hpp>
#include <./simulation/monte_carlo_simulation/monte_carlo_simulation_executor.hpp>

#include "../spacecraft/user_satellite.hpp"

Expand All @@ -19,8 +20,11 @@ class UserCase : public s2e::simulation::SimulationCase {
/**
* @fn UserCase
* @brief Constructor
* @param[in] initialize_base_file: Initialize base file path
* @param[in] monte_carlo_simulator: Monte Carlo simulator
* @param[in] log_path: Log output file path
*/
UserCase(const std::string initialise_base_file);
UserCase(const std::string initialize_base_file, s2e::simulation::MonteCarloSimulationExecutor &monte_carlo_simulator, const std::string log_path);
/**
* @fn ~UserCase
* @brief Destructor
Expand All @@ -40,6 +44,7 @@ class UserCase : public s2e::simulation::SimulationCase {

private:
UserSatellite *spacecraft_; //!< Instance of spacecraft
s2e::simulation::MonteCarloSimulationExecutor &monte_carlo_simulator_; //!< Monte Carlo simulator

/**
* @fn InitializeTargetObjects
Expand Down

0 comments on commit 1eba680

Please sign in to comment.