generated from ut-issl/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
139 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[ClockSensor] | ||
prescaler = 10 // period = prescaler * CompoUpdateIntervalSec [s] | ||
bias_s = 0.005 // [s] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* @file clock_sensor.cpp | ||
* @brief An example to emulate a sensor to measure simulation elapsed time | ||
*/ | ||
|
||
#include "clock_sensor.hpp" | ||
|
||
#include <setting_file_reader/initialize_file_access.hpp> | ||
|
||
ClockSensor::ClockSensor(const int prescaler, s2e::environment::ClockGenerator* clock_generator, | ||
const s2e::environment::SimulationTime& simulation_time, const double bias_s) | ||
: Component(prescaler, clock_generator), simulation_time_(simulation_time), bias_s_(bias_s), time_output_s_(0.0) {} | ||
|
||
void ClockSensor::MainRoutine(const int time_count) { | ||
UNUSED(time_count); | ||
time_output_s_ = simulation_time_.GetElapsedTime_s() + bias_s_; | ||
} | ||
|
||
std::string ClockSensor::GetLogHeader() const { | ||
std::string str_tmp = ""; | ||
std::string section = "clock_sensor_"; | ||
str_tmp += s2e::logger::WriteScalar(section + "observed_time", "sec"); | ||
|
||
return str_tmp; | ||
} | ||
|
||
std::string ClockSensor::GetLogValue() const { | ||
std::string str_tmp = ""; | ||
|
||
str_tmp += s2e::logger::WriteScalar(time_output_s_); | ||
|
||
return str_tmp; | ||
} | ||
|
||
ClockSensor InitClockSensor(s2e::environment::ClockGenerator* clock_generator, const s2e::environment::SimulationTime& simulation_time, | ||
const std::string file_name) { | ||
s2e::setting_file_reader::IniAccess ini_file(file_name); | ||
|
||
const double bias_s = ini_file.ReadDouble("ClockSensor", "bias_s"); | ||
const int prescaler = ini_file.ReadInt("ClockSensor", "prescaler"); | ||
ClockSensor clock_sensor(prescaler, clock_generator, simulation_time, bias_s); | ||
|
||
return clock_sensor; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* @file clock_sensor.hpp | ||
* @brief An example to emulate a sensor to measure simulation elapsed time | ||
*/ | ||
|
||
#ifndef S2E_COMPONENTS_CLOCK_SENSOR_HPP_ | ||
#define S2E_COMPONENTS_CLOCK_SENSOR_HPP_ | ||
|
||
#include <components/base/component.hpp> | ||
#include <environment/global/simulation_time.hpp> | ||
#include <logger/loggable.hpp> | ||
|
||
/** | ||
* @class ClockSensor | ||
* @brief An example to emulate a sensor to measure simulation elapsed time | ||
*/ | ||
class ClockSensor : public s2e::components::Component, public s2e::logger::ILoggable { | ||
public: | ||
/** | ||
* @fn ClockSensor | ||
* @brief Constructor | ||
* @param [in] prescaler: Frequency scale factor for update | ||
* @param [in] clock_generator: Clock generator | ||
* @param [in] simulation_time: Simulation time information | ||
* @param [in] bias_s: Bias value for clock observation [s] | ||
*/ | ||
ClockSensor(const int prescaler, s2e::environment::ClockGenerator* clock_generator, const s2e::environment::SimulationTime& simulation_time, | ||
const double bias_s); | ||
|
||
private: | ||
// Override functions for Component | ||
/** | ||
* @fn MainRoutine | ||
* @brief Main routine for sensor observation | ||
*/ | ||
void MainRoutine(const int time_count) override; | ||
|
||
// Override ILoggable | ||
/** | ||
* @fn GetLogHeader | ||
* @brief Override GetLogHeader function of ILoggable | ||
*/ | ||
virtual std::string GetLogHeader() const override; | ||
/** | ||
* @fn GetLogValue | ||
* @brief Override GetLogValue function of ILoggable | ||
*/ | ||
virtual std::string GetLogValue() const override; | ||
|
||
const s2e::environment::SimulationTime& simulation_time_; //!< Simulation time information | ||
double bias_s_; //!< Bias value for clock observation [s] | ||
double time_output_s_; //!< Output of measured time information [s] | ||
}; | ||
|
||
/** | ||
* @fn InitGyroSensor | ||
* @brief Initialize functions for gyro sensor without power port | ||
* @param [in] clock_generator: Clock generator | ||
* @param [in] simulation_time: Simulation time information | ||
* @param [in] file_name: Path to the initialize file | ||
*/ | ||
ClockSensor InitClockSensor(s2e::environment::ClockGenerator* clock_generator, const s2e::environment::SimulationTime& simulation_time, | ||
const std::string file_name); | ||
|
||
#endif // S2E_COMPONENTS_CLOCK_SENSOR_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters