Gazebo Gazebo

API Reference

6.16.0
ActionsImpl.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 /*
19  * \author Nick Lamprianidis <nlamprian@gmail.com>
20  * \date January 2021
21  */
22 
23 #include "../ElevatorStateMachine.hh"
24 
25 namespace ignition
26 {
27 namespace gazebo
28 {
29 // Inline bracket to help doxygen filtering
30 inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
31 namespace systems
32 {
33 namespace actions
34 {
38 template <bool trigger>
39 struct EnqueueNewTarget
40 {
46  public: template <typename Event, typename Fsm, typename Source,
47  typename Target>
48  void operator()(const Event &_event, Fsm &_fsm, Source & /*_source*/,
49  Target & /*_target*/)
50  {
51  _fsm.dataPtr->EnqueueNewTarget(_event.target);
52  if (trigger)
53  _fsm.process_event(events::NewTarget());
54  }
55 };
56 
59 struct NewTarget
60 {
66  public: template <typename Event, typename Fsm, typename Source,
67  typename Target>
68  void operator()(const Event & /*_event*/, Fsm &_fsm, Source & /*_source*/,
69  Target & /*_target*/)
70  {
71  std::lock_guard<std::recursive_mutex> lock(_fsm.dataPtr->system->mutex);
72  if (_fsm.dataPtr->targets.front() == _fsm.dataPtr->system->state)
73  _fsm.dataPtr->targets.pop_front();
74  }
75 };
76 
80 {
86  public: template <typename Event, typename Fsm, typename Source,
87  typename Target>
88  void operator()(const Event & /*_event*/, Fsm &_fsm, Source & /*_source*/,
89  Target & /*_target*/)
90  {
91  std::lock_guard<std::recursive_mutex> lock(_fsm.dataPtr->system->mutex);
92  _fsm.dataPtr->targets.pop_front();
93  }
94 };
95 
96 } // namespace actions
97 } // namespace systems
98 } // namespace IGNITION_GAZEBO_VERSION_NAMESPACE
99 } // namespace gazebo
100 } // namespace ignition
This library is part of the Gazebo project.
Action that cleans up the target queue when a new target is processed.
Definition: ActionsImpl.hh:59
Action that cleans up the target queue when the cabin reaches the target floor level.
Definition: ActionsImpl.hh:79
STL class.
void operator()(const Event &_event, Fsm &_fsm, Source &, Target &)
Function call operator.
Definition: ActionsImpl.hh:48
void operator()(const Event &, Fsm &_fsm, Source &, Target &)
Function call operator.
Definition: ActionsImpl.hh:68
void operator()(const Event &, Fsm &_fsm, Source &, Target &)
Function call operator.
Definition: ActionsImpl.hh:88
Event that signifies a new target will be processed.
Definition: EventsImpl.hh:47