Gazebo Sim

API Reference

8.7.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 gz
26 {
27 namespace sim
28 {
29 // Inline bracket to help doxygen filtering
30 inline namespace GZ_SIM_VERSION_NAMESPACE {
31 namespace systems
32 {
33 namespace actions
34 {
38 template <bool trigger>
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 GZ_SIM_VERSION_NAMESPACE
99 } // namespace sim
100 } // namespace gz