SMACC
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Private Attributes | List of all members
smacc::state_reactors::EgRandomGenerator Class Reference

#include <eg_random_generator.h>

Inheritance diagram for smacc::state_reactors::EgRandomGenerator:
Inheritance graph
Collaboration diagram for smacc::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)
 
virtual void onEntry () override
 
template<typename TState , typename TSource >
void onStateAllocation ()
 
void postRandomEvents ()
 
virtual void update () override
 
- Public Member Functions inherited from smacc::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 smacc::ISmaccUpdatable
 ISmaccUpdatable ()
 
 ISmaccUpdatable (ros::Duration duration)
 
void executeUpdate ()
 
void setUpdatePeriod (ros::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 36 of file eg_random_generator.h.

Constructor & Destructor Documentation

◆ EgRandomGenerator()

smacc::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 7 of file eg_random_generator.cpp.

8 :
9 mode_(mode),
10 evAMin_(evAMin),
11 evAMax_(evAMax),
12 evBMin_(evBMin),
13 evBMax_(evBMax),
14 evCMin_(evCMin),
15 evCMax_(evCMax)
16 {
17
18 auto values = {evAMin, evAMax, evBMin, evBMax, evCMin, evCMax};
19
20 this->minValue = std::numeric_limits<double>::max();
21 this->maxValue = std::numeric_limits<double>::min();
22 for (auto &v : values)
23 {
24 if (v < minValue)
25 {
26 minValue = v;
27 }
28
29 if (v > maxValue)
30 {
31 maxValue = v;
32 }
33 }
34 }

References maxValue, and minValue.

Member Function Documentation

◆ onEntry()

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

Reimplemented from smacc::SmaccEventGenerator.

Definition at line 57 of file eg_random_generator.cpp.

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

Here is the call graph for this function:

◆ onStateAllocation()

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

Definition at line 44 of file eg_random_generator.h.

45 {
46 this->postEventA = [this]() { this->postEvent<EventA<TSource, TState>>(); };
47 this->postEventB = [this]() { this->postEvent<EventB<TSource, TState>>(); };
48 this->postEventC = [this]() { this->postEvent<EventC<TSource, TState>>(); };
49 }

References postEventA, postEventB, and postEventC.

◆ postRandomEvents()

void smacc::state_reactors::EgRandomGenerator::postRandomEvents ( )

Definition at line 36 of file eg_random_generator.cpp.

37 {
38 int range = this->maxValue - this->minValue;
39 int result = (rand() % range) + minValue;
40
41 if (result >= evAMin_ && result <= evAMax_)
42 {
43 this->postEventA();
44 }
45
46 if (result >= evBMin_ && result <= evBMax_)
47 {
48 this->postEventB();
49 }
50
51 if (result >= evCMin_ && result <= evCMax_)
52 {
53 this->postEventC();
54 }
55 }

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 smacc::state_reactors::EgRandomGenerator::update ( )
overridevirtual

Implements smacc::ISmaccUpdatable.

Definition at line 65 of file eg_random_generator.cpp.

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

Here is the call graph for this function:

Member Data Documentation

◆ evAMax_

double smacc::state_reactors::EgRandomGenerator::evAMax_
private

Definition at line 63 of file eg_random_generator.h.

Referenced by postRandomEvents().

◆ evAMin_

double smacc::state_reactors::EgRandomGenerator::evAMin_
private

Definition at line 62 of file eg_random_generator.h.

Referenced by postRandomEvents().

◆ evBMax_

double smacc::state_reactors::EgRandomGenerator::evBMax_
private

Definition at line 65 of file eg_random_generator.h.

Referenced by postRandomEvents().

◆ evBMin_

double smacc::state_reactors::EgRandomGenerator::evBMin_
private

Definition at line 64 of file eg_random_generator.h.

Referenced by postRandomEvents().

◆ evCMax_

double smacc::state_reactors::EgRandomGenerator::evCMax_
private

Definition at line 67 of file eg_random_generator.h.

Referenced by postRandomEvents().

◆ evCMin_

double smacc::state_reactors::EgRandomGenerator::evCMin_
private

Definition at line 66 of file eg_random_generator.h.

Referenced by postRandomEvents().

◆ maxValue

double smacc::state_reactors::EgRandomGenerator::maxValue
private

Definition at line 70 of file eg_random_generator.h.

Referenced by EgRandomGenerator(), and postRandomEvents().

◆ minValue

double smacc::state_reactors::EgRandomGenerator::minValue
private

Definition at line 69 of file eg_random_generator.h.

Referenced by EgRandomGenerator(), and postRandomEvents().

◆ mode_

RandomGenerateReactorMode smacc::state_reactors::EgRandomGenerator::mode_

Definition at line 55 of file eg_random_generator.h.

Referenced by onEntry(), and update().

◆ postEventA

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

Definition at line 58 of file eg_random_generator.h.

Referenced by onStateAllocation(), and postRandomEvents().

◆ postEventB

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

Definition at line 59 of file eg_random_generator.h.

Referenced by onStateAllocation(), and postRandomEvents().

◆ postEventC

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

Definition at line 60 of file eg_random_generator.h.

Referenced by onStateAllocation(), and postRandomEvents().


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