SMACC2
Public Member Functions | Public Attributes | Private Attributes | List of all members
smacc2::state_reactors::EgRandomGenerator Class Reference

#include <eg_random_generator.hpp>

Inheritance diagram for smacc2::state_reactors::EgRandomGenerator:
Inheritance graph
Collaboration diagram for smacc2::state_reactors::EgRandomGenerator:
Collaboration graph

Public Member Functions

 EgRandomGenerator (RandomGenerateReactorMode mode, double evAMin=1, double evAMax=4, double evBMin=5, double evBMax=8, double evCMin=9, double evCMax=12)
 
void onEntry () override
 
template<typename TState , typename TSource >
void onStateAllocation ()
 
void postRandomEvents ()
 
void update () override
 
- Public Member Functions inherited from smacc2::SmaccEventGenerator
 SmaccEventGenerator ()
 
virtual ~SmaccEventGenerator ()
 
template<typename TState , typename TSource >
void onStateAllocation ()
 
virtual void onEntry ()
 
virtual void onExit ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
void initialize (ISmaccState *ownerState)
 
virtual void onInitialized ()
 
- Public Member Functions inherited from smacc2::ISmaccUpdatable
 ISmaccUpdatable ()
 
 ISmaccUpdatable (rclcpp::Duration duration)
 
void executeUpdate (rclcpp::Node::SharedPtr node)
 
void setUpdatePeriod (rclcpp::Duration duration)
 

Public Attributes

RandomGenerateReactorMode mode_
 

Private Attributes

std::function< void()> postEventA
 
std::function< void()> postEventB
 
std::function< void()> postEventC
 
double evAMin_
 
double evAMax_
 
double evBMin_
 
double evBMax_
 
double evCMin_
 
double evCMax_
 
double minValue
 
double maxValue
 

Additional Inherited Members

virtual void update ()=0
 

Detailed Description

Definition at line 50 of file eg_random_generator.hpp.

Constructor & Destructor Documentation

◆ EgRandomGenerator()

smacc2::state_reactors::EgRandomGenerator::EgRandomGenerator ( RandomGenerateReactorMode  mode,
double  evAMin = 1,
double  evAMax = 4,
double  evBMin = 5,
double  evBMax = 8,
double  evCMin = 9,
double  evCMax = 12 
)

Definition at line 21 of file eg_random_generator.cpp.

24: mode_(mode),
25 evAMin_(evAMin),
26 evAMax_(evAMax),
27 evBMin_(evBMin),
28 evBMax_(evBMax),
29 evCMin_(evCMin),
30 evCMax_(evCMax)
31{
32 auto values = {evAMin, evAMax, evBMin, evBMax, evCMin, evCMax};
33
34 this->minValue = std::numeric_limits<double>::max();
35 this->maxValue = std::numeric_limits<double>::min();
36 for (auto & v : values)
37 {
38 if (v < minValue)
39 {
40 minValue = v;
41 }
42
43 if (v > maxValue)
44 {
45 maxValue = v;
46 }
47 }
48}

References maxValue, and minValue.

Member Function Documentation

◆ onEntry()

void smacc2::state_reactors::EgRandomGenerator::onEntry ( )
overridevirtual

Reimplemented from smacc2::SmaccEventGenerator.

Definition at line 71 of file eg_random_generator.cpp.

References mode_, smacc2::state_reactors::ONE_SHOT, and postRandomEvents().

Here is the call graph for this function:

◆ onStateAllocation()

template<typename TState , typename TSource >
void smacc2::state_reactors::EgRandomGenerator::onStateAllocation ( )
inline

Definition at line 60 of file eg_random_generator.hpp.

61 {
62 this->postEventA = [this]() { this->postEvent<EventA<TSource, TState>>(); };
63 this->postEventB = [this]() { this->postEvent<EventB<TSource, TState>>(); };
64 this->postEventC = [this]() { this->postEvent<EventC<TSource, TState>>(); };
65 }

References postEventA, postEventB, and postEventC.

◆ postRandomEvents()

void smacc2::state_reactors::EgRandomGenerator::postRandomEvents ( )

Definition at line 50 of file eg_random_generator.cpp.

51{
52 int range = this->maxValue - this->minValue;
53 int result = (rand() % range) + minValue;
54
55 if (result >= evAMin_ && result <= evAMax_)
56 {
57 this->postEventA();
58 }
59
60 if (result >= evBMin_ && result <= evBMax_)
61 {
62 this->postEventB();
63 }
64
65 if (result >= evCMin_ && result <= evCMax_)
66 {
67 this->postEventC();
68 }
69}

References evAMax_, evAMin_, evBMax_, evBMin_, evCMax_, evCMin_, maxValue, minValue, postEventA, postEventB, and postEventC.

Referenced by onEntry(), and update().

Here is the caller graph for this function:

◆ update()

void smacc2::state_reactors::EgRandomGenerator::update ( )
overridevirtual

Implements smacc2::ISmaccUpdatable.

Definition at line 79 of file eg_random_generator.cpp.

References mode_, smacc2::state_reactors::ON_UPDATE, and postRandomEvents().

Here is the call graph for this function:

Member Data Documentation

◆ evAMax_

double smacc2::state_reactors::EgRandomGenerator::evAMax_
private

Definition at line 79 of file eg_random_generator.hpp.

Referenced by postRandomEvents().

◆ evAMin_

double smacc2::state_reactors::EgRandomGenerator::evAMin_
private

Definition at line 78 of file eg_random_generator.hpp.

Referenced by postRandomEvents().

◆ evBMax_

double smacc2::state_reactors::EgRandomGenerator::evBMax_
private

Definition at line 81 of file eg_random_generator.hpp.

Referenced by postRandomEvents().

◆ evBMin_

double smacc2::state_reactors::EgRandomGenerator::evBMin_
private

Definition at line 80 of file eg_random_generator.hpp.

Referenced by postRandomEvents().

◆ evCMax_

double smacc2::state_reactors::EgRandomGenerator::evCMax_
private

Definition at line 83 of file eg_random_generator.hpp.

Referenced by postRandomEvents().

◆ evCMin_

double smacc2::state_reactors::EgRandomGenerator::evCMin_
private

Definition at line 82 of file eg_random_generator.hpp.

Referenced by postRandomEvents().

◆ maxValue

double smacc2::state_reactors::EgRandomGenerator::maxValue
private

Definition at line 86 of file eg_random_generator.hpp.

Referenced by EgRandomGenerator(), and postRandomEvents().

◆ minValue

double smacc2::state_reactors::EgRandomGenerator::minValue
private

Definition at line 85 of file eg_random_generator.hpp.

Referenced by EgRandomGenerator(), and postRandomEvents().

◆ mode_

RandomGenerateReactorMode smacc2::state_reactors::EgRandomGenerator::mode_

Definition at line 71 of file eg_random_generator.hpp.

Referenced by onEntry(), and update().

◆ postEventA

std::function<void()> smacc2::state_reactors::EgRandomGenerator::postEventA
private

Definition at line 74 of file eg_random_generator.hpp.

Referenced by onStateAllocation(), and postRandomEvents().

◆ postEventB

std::function<void()> smacc2::state_reactors::EgRandomGenerator::postEventB
private

Definition at line 75 of file eg_random_generator.hpp.

Referenced by onStateAllocation(), and postRandomEvents().

◆ postEventC

std::function<void()> smacc2::state_reactors::EgRandomGenerator::postEventC
private

Definition at line 76 of file eg_random_generator.hpp.

Referenced by onStateAllocation(), and postRandomEvents().


The documentation for this class was generated from the following files: