SMACC2
Loading...
Searching...
No Matches
smacc2_event_generator_library
eg_random_generator
include
eg_random_generator
eg_random_generator.hpp
Go to the documentation of this file.
1
// Copyright 2021 RobosoftAI Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#pragma once
16
#include <boost/statechart/event.hpp>
17
#include <functional>
18
#include <
smacc2/common.hpp
>
19
#include <
smacc2/smacc_event_generator.hpp
>
20
#include <
smacc2/smacc_updatable.hpp
>
21
#include <typeinfo>
22
23
namespace
smacc2
24
{
25
namespace
state_reactors
26
{
27
template
<
typename
TSource,
typename
TState>
28
struct
EventA
:
sc::event
<EventA<TSource, TState>>
29
{
30
};
31
32
template
<
typename
TSource,
typename
TState>
33
struct
EventB
:
sc::event
<EventB<TSource, TState>>
34
{
35
};
36
37
template
<
typename
TSource,
typename
TState>
38
struct
EventC
:
sc::event
<EventC<TSource, TState>>
39
{
40
};
41
42
enum class
RandomGenerateReactorMode
43
{
44
INPUT_EVENT_TRIGGERED
,
45
ONE_SHOT
,
46
ON_UPDATE
47
};
48
49
//-----------------------------------------------------------------------
50
class
EgRandomGenerator
:
public
SmaccEventGenerator
,
public
ISmaccUpdatable
51
{
52
public
:
53
EgRandomGenerator
(
54
RandomGenerateReactorMode
mode
,
double
evAMin
= 1,
double
evAMax
= 4,
double
evBMin
= 5,
55
double
evBMax
= 8,
double
evCMin
= 9,
double
evCMax
= 12);
56
57
void
onEntry
()
override
;
58
59
template
<
typename
TState,
typename
TSource>
60
void
onStateAllocation
()
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
}
66
67
void
postRandomEvents
();
68
69
void
update
()
override
;
70
71
RandomGenerateReactorMode
mode_
;
72
73
private
:
74
std::function<
void
()>
postEventA
;
75
std::function<
void
()>
postEventB
;
76
std::function<
void
()>
postEventC
;
77
78
double
evAMin_
;
79
double
evAMax_
;
80
double
evBMin_
;
81
double
evBMax_
;
82
double
evCMin_
;
83
double
evCMax_
;
84
85
double
minValue
;
86
double
maxValue
;
87
};
88
}
// namespace state_reactors
89
}
// namespace smacc2
boost::statechart::event
smacc2::ISmaccUpdatable
Definition
smacc_updatable.hpp:33
smacc2::SmaccEventGenerator
Definition
smacc_event_generator.hpp:37
smacc2::state_reactors::EgRandomGenerator
Definition
eg_random_generator.hpp:51
smacc2::state_reactors::EgRandomGenerator::evBMax_
double evBMax_
Definition
eg_random_generator.hpp:81
smacc2::state_reactors::EgRandomGenerator::postRandomEvents
void postRandomEvents()
Definition
eg_random_generator.cpp:50
smacc2::state_reactors::EgRandomGenerator::evBMin_
double evBMin_
Definition
eg_random_generator.hpp:80
smacc2::state_reactors::EgRandomGenerator::update
void update() override
Definition
eg_random_generator.cpp:79
smacc2::state_reactors::EgRandomGenerator::evAMin_
double evAMin_
Definition
eg_random_generator.hpp:78
smacc2::state_reactors::EgRandomGenerator::evCMax_
double evCMax_
Definition
eg_random_generator.hpp:83
smacc2::state_reactors::EgRandomGenerator::onStateAllocation
void onStateAllocation()
Definition
eg_random_generator.hpp:60
smacc2::state_reactors::EgRandomGenerator::maxValue
double maxValue
Definition
eg_random_generator.hpp:86
smacc2::state_reactors::EgRandomGenerator::postEventC
std::function< void()> postEventC
Definition
eg_random_generator.hpp:76
smacc2::state_reactors::EgRandomGenerator::onEntry
void onEntry() override
Definition
eg_random_generator.cpp:71
smacc2::state_reactors::EgRandomGenerator::postEventA
std::function< void()> postEventA
Definition
eg_random_generator.hpp:74
smacc2::state_reactors::EgRandomGenerator::minValue
double minValue
Definition
eg_random_generator.hpp:85
smacc2::state_reactors::EgRandomGenerator::postEventB
std::function< void()> postEventB
Definition
eg_random_generator.hpp:75
smacc2::state_reactors::EgRandomGenerator::evCMin_
double evCMin_
Definition
eg_random_generator.hpp:82
smacc2::state_reactors::EgRandomGenerator::mode_
RandomGenerateReactorMode mode_
Definition
eg_random_generator.hpp:71
smacc2::state_reactors::EgRandomGenerator::evAMax_
double evAMax_
Definition
eg_random_generator.hpp:79
common.hpp
smacc2::state_reactors::RandomGenerateReactorMode
RandomGenerateReactorMode
Definition
eg_random_generator.hpp:43
smacc2::state_reactors::RandomGenerateReactorMode::ON_UPDATE
@ ON_UPDATE
smacc2::state_reactors::RandomGenerateReactorMode::ONE_SHOT
@ ONE_SHOT
smacc2::state_reactors::RandomGenerateReactorMode::INPUT_EVENT_TRIGGERED
@ INPUT_EVENT_TRIGGERED
smacc2
Definition
callback_counter_semaphore.hpp:30
smacc_event_generator.hpp
smacc_updatable.hpp
smacc2::default_events::EvTopicMessage
Definition
smacc_default_events.hpp:155
smacc2::state_reactors::EventA
Definition
eg_random_generator.hpp:29
smacc2::state_reactors::EventB
Definition
eg_random_generator.hpp:34
smacc2::state_reactors::EventC
Definition
eg_random_generator.hpp:39
Generated by
1.9.8