- In the How To Add Components tutorial, we have added existing components to the simulation scenario.
- This tutorial explains how to make a new component into the s2e-user directory.
- Note: You can move the source files for the new component into the s2e-core repository if the component is useful for all S2E users.
- The supported version of this document
- Please confirm that the version of the documents and s2e-core is compatible.
- Source codes emulating components are stored in the
s2e-core/src/components
directory. - All components need to inherit the base class
Component
for general functions of components, and most of the components also inherit the base classILoggable
for the log output function. Component
class- The base class has an important virtual function
MainRoutine
, and subclasses need to define it in their codes.- When an instance of the component class is created, the
MainRoutine
function is registered in theTickToComponent
, and it will be automatically executed in theSpacecraft
class. - The main features of the components such as observation, generate force, noise addition, communication, etc... should be written in this function.
- When an instance of the component class is created, the
PowerOffRoutine
is also important especially for actuators. This function is called when the component power line is turned off. Users can stop force and torque generation and initialize the component states.
- The base class has an important virtual function
- Power related functions
SetPowerState
andGetCurrent
are power related functions. If you want to emulate power consumption and switch control, you need to use the functions.
ILoggable
class- This base class has two important virtual functions
GetLogHeader
andGetLogValue
, for CSV log output. - These functions are registered into the log output list when the components are added in
UserComponents::LogSetUp
- This base class has two important virtual functions
- Communication with OBC
- If users want to emulate the communication(telemetry and command) between the components and the OBC, they can use the base class
UartCommunicationWithObc
orI2cTargetCommunicationWithObc
. - These base classes also support a feature to execute HILS function.
- If users want to emulate the communication(telemetry and command) between the components and the OBC, they can use the base class
- This chapter explains how to make a simple clock sensor, which observes the simulation elapsed time with a bias noise.
- Users can find the sample codes in s2e-user-example/sample/how-to-make-new-components.
- The sample codes already including the initialize file for the
ClockSensor
. Please edit the code a bit to learn the procedure step by step.
- The sample codes already including the initialize file for the
-
The
clock_sensor.cpp, .hpp
are created in thecomponents
directory.- The
ClockSensor
class counts clock with a constant bias noise. - The class inherits the
Component
and theILoggable
base classes as explained above.
- The
-
The
user_components.hpp
anduser_components.cpp
are edit similar procedure with the How To Add Components- The constructor of the
ClockSensor
requires arguments asprescaler
,clock_generator
,simulation_time
, andbias_s
. prescaler
andbias_s
are user setting parameters for the sensor, and you can freely set these values.clock_generator
is an argument for theComponent
base class.simulation_time
is a specific argument for theClockSensor
to get true time information. TheSimulationTime
class is managed in theGlobalEnvironment
, and theGlobalEnvironment
is instantiated in theSimulationCase
class.- We need to add the following codes to
user_components.cpp
.- Instantiate the
ClockSensor
in the constructor.
clock_sensor_ = new ClockSensor(10, clock_generator, global_environment->GetSimulationTime(), 0.001);
- Delete the
clock_sensor_
in the destructor.
delete clock_sensor_;
- Add log set up into the
LogSetUp
function.
logger.AddLogList(clock_sensor_);
- Instantiate the
- The constructor of the
-
Build
s2e-user
and execute it -
Check the log file to confirm the output of the
clock_sensor_observed_time[sec]
- The output of the clock sensor has an offset error defined by the
bias_s
value, and the update frequency is decided by theprescaler
and thecomponent_update_period_s
in the base ini file.
- The output of the clock sensor has an offset error defined by the
- Usually, we want to change the parameters of components such as noise properties, mounting coordinates, and others without rebuilding. So this section explains how to make an initialize file for the
ClockSensor
.
-
The initialize function
InitClockSensor
is defined in theclock_sensor.hpp
.- The initialize function requires arguments as
clock_generator
,simulation_time
, andfile_name
. clock_generator
andsimulation_time
are same argument with the constructor of theClockGenerator
.file_name
is the file path to the initialize file for theClockSensor
.
- The initialize function requires arguments as
-
Edit the
user_components.hpp
anduser_components.cpp
as followsuser_components.cpp
- Edit making instance of the
clock_sensor
at the constructor// Clock Sensor std::string file_name = iniAccess.ReadString("COMPONENT_FILES", "clock_sensor_file"); configuration_->main_logger_->CopyFileToLogDirectory(file_name); clock_sensor_ = new ClockSensor(InitClockSensor(clock_generator, global_environment->GetSimulationTime(), file_name));
- The first line get the file path of the initialize file of the clock sensor.
- The second line copy the initialize file to the log output directory to save the simulation setting.
- The third line make the instance of the
ClockSensor
.
- Edit making instance of the
-
Make
clock_sensor.ini
intos2e-user/data/initialize_files/components
from./Tutorial/SampleCodes/clock_sensor
-
Edit
user_satellite.ini
to add the following line at the [COMPONENT_FILES] section of the fileclock_sensor_file = INI_FILE_DIR_FROM_EXE/components/clock_sensor.ini
- The keyword
INI_FILE_DIR_FROM_EXE
is defined in theCMakeList.txt
to handle the relative path to the initialize files.
- The keyword
-
Build
s2e-user
and execute it -
Check the log file
-
Edit the
clock_sensor.ini
and rerun thes2e-user
to confirm the initialize file can affect the result.