How To Make New Components
1. Overview
- 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.
2. Overview of component expression in S2E
- Source codes emulating components are stored in the
s2e-core/src/componentsdirectory. - All components need to inherit the base class
Componentfor general functions of components, and most of the components also inherit the base classILoggablefor the log output function. Componentclass- 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
MainRoutinefunction is registered in theTickToComponent, and it will be automatically executed in theSpacecraftclass. - 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
PowerOffRoutineis 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
SetPowerStateandGetCurrentare power related functions. If you want to emulate power consumption and switch control, you need to use the functions.
ILoggableclass- This base class has two important virtual functions
GetLogHeaderandGetLogValue, 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
UartCommunicationWithObcorI2cTargetCommunicationWithObc. - 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
3. Make a simple clock sensor without initialize file
- 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, .hppare created in thecomponentsdirectory.- The
ClockSensorclass counts clock with a constant bias noise. - The class inherits the
Componentand theILoggablebase classes as explained above.
- The
-
The
user_components.hppanduser_components.cppare edit similar procedure with the How To Add Components- The constructor of the
ClockSensorrequires arguments asprescaler,clock_generator,simulation_time, andbias_s. prescalerandbias_sare user setting parameters for the sensor, and you can freely set these values.clock_generatoris an argument for theComponentbase class.simulation_timeis a specific argument for theClockSensorto get true time information. TheSimulationTimeclass is managed in theGlobalEnvironment, and theGlobalEnvironmentis instantiated in theSimulationCaseclass.- We need to add the following codes to
user_components.cpp.- Instantiate the
ClockSensorin 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
LogSetUpfunction.
logger.AddLogList(clock_sensor_); - Instantiate the
- The constructor of the
-
Build
s2e-userand 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_svalue, and the update frequency is decided by theprescalerand thecomponent_update_period_sin the base ini file.
- The output of the clock sensor has an offset error defined by the
4. Make an initialize file for the clock sensor
- 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
InitClockSensoris defined in theclock_sensor.hpp.- The initialize function requires arguments as
clock_generator,simulation_time, andfile_name. clock_generatorandsimulation_timeare same argument with the constructor of theClockGenerator.file_nameis the file path to the initialize file for theClockSensor.
- The initialize function requires arguments as
-
Edit the
user_components.hppanduser_components.cppas followsuser_components.cpp- Edit making instance of the
clock_sensorat 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.iniintos2e-user/data/initialize_files/componentsfrom./Tutorial/SampleCodes/clock_sensor -
Edit
user_satellite.inito 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_EXEis defined in theCMakeList.txtto handle the relative path to the initialize files.
- The keyword
-
Build
s2e-userand execute it -
Check the log file
-
Edit the
clock_sensor.iniand rerun thes2e-userto confirm the initialize file can affect the result.