-
Notifications
You must be signed in to change notification settings - Fork 304
/
Copy pathActionsImpl.hh
100 lines (94 loc) · 3.31 KB
/
ActionsImpl.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
* \author Nick Lamprianidis <[email protected]>
* \date January 2021
*/
#include "../ElevatorStateMachine.hh"
namespace ignition
{
namespace gazebo
{
// Inline bracket to help doxygen filtering
inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
namespace systems
{
namespace actions
{
/// \brief Action that enqueues a new target in the target queue.
/// \details After the new target has been added in the queue, depending on the
/// template parameter, an events::NewTarget is triggered.
template <bool trigger>
struct EnqueueNewTarget
{
/// \brief Function call operator
/// \param[in] _event Event that triggered the action
/// \param[in] _fsm State machine with which the action is associated
/// \param[in] _source Source state
/// \param[in] _target Target state
public: template <typename Event, typename Fsm, typename Source,
typename Target>
void operator()(const Event &_event, Fsm &_fsm, Source & /*_source*/,
Target & /*_target*/)
{
_fsm.dataPtr->EnqueueNewTarget(_event.target);
if (trigger)
_fsm.process_event(events::NewTarget());
}
};
/// \brief Action that cleans up the target queue when a new target is
/// processed.
struct NewTarget
{
/// \brief Function call operator
/// \param[in] _event Event that triggered the action
/// \param[in] _fsm State machine with which the action is associated
/// \param[in] _source Source state
/// \param[in] _target Target state
public: template <typename Event, typename Fsm, typename Source,
typename Target>
void operator()(const Event & /*_event*/, Fsm &_fsm, Source & /*_source*/,
Target & /*_target*/)
{
std::lock_guard<std::recursive_mutex> lock(_fsm.dataPtr->system->mutex);
if (_fsm.dataPtr->targets.front() == _fsm.dataPtr->system->state)
_fsm.dataPtr->targets.pop_front();
}
};
/// \brief Action that cleans up the target queue when the cabin reaches the
/// target floor level.
struct CabinAtTarget
{
/// \brief Function call operator
/// \param[in] _event Event that triggered the action
/// \param[in] _fsm State machine with which the action is associated
/// \param[in] _source Source state
/// \param[in] _target Target state
public: template <typename Event, typename Fsm, typename Source,
typename Target>
void operator()(const Event & /*_event*/, Fsm &_fsm, Source & /*_source*/,
Target & /*_target*/)
{
std::lock_guard<std::recursive_mutex> lock(_fsm.dataPtr->system->mutex);
_fsm.dataPtr->targets.pop_front();
}
};
} // namespace actions
} // namespace systems
} // namespace IGNITION_GAZEBO_VERSION_NAMESPACE
} // namespace gazebo
} // namespace ignition