Gazebo Sim

API Reference

7.9.0
ElevatorStateMachine.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 #ifndef GZ_SIM_SYSTEMS_ELEVATOR_STATE_MACHINE_HH_
24 #define GZ_SIM_SYSTEMS_ELEVATOR_STATE_MACHINE_HH_
25 
26 #include <memory>
27 
28 #include <gz/sim/Entity.hh>
29 #include <gz/transport/Node.hh>
30 
31 #include "afsm/fsm.hpp"
32 
33 namespace gz
34 {
35 namespace sim
36 {
37 // Inline bracket to help doxygen filtering
38 inline namespace GZ_SIM_VERSION_NAMESPACE {
39 namespace systems
40 {
41 // Data forward declarations
42 class ElevatorCommonPrivate;
43 class ElevatorStateMachinePrivate;
44 
45 // Event forward declarations
46 namespace events
47 {
48  struct EnqueueNewTarget;
49  struct NewTarget;
50  struct DoorOpen;
51  struct DoorClosed;
52  struct Timeout;
53  struct CabinAtTarget;
54 } // namespace events
55 
56 // Action forward declarations
57 namespace actions
58 {
59  template <bool>
61  struct NewTarget;
62  struct CabinAtTarget;
63 } // namespace actions
64 
65 // Guard forward declarations
66 namespace guards
67 {
68  template <typename TargetState>
69  struct IsInState;
70  struct CabinAtTarget;
71  struct NoQueuedTarget;
72 } // namespace guards
73 
77  : public ::afsm::def::state_machine<ElevatorStateMachineDef>
78 {
79  // State forward declarations
80  struct IdleState;
81  template <typename E>
82  struct DoorState;
83  struct OpenDoorState;
84  struct CloseDoorState;
85  struct WaitState;
86  struct MoveCabinState;
87 
93 
95  public: ~ElevatorStateMachineDef();
96 
98  public: using initial_state = IdleState;
99 
101  public: using internal_transitions = transition_table <
102  in<events::EnqueueNewTarget, actions::EnqueueNewTarget<true>,
104  in<events::EnqueueNewTarget, actions::EnqueueNewTarget<false>,
106  >;
107 
109  public: using transitions = transition_table<
110  // +--------------------------------------------------------------+
114  not_<guards::CabinAtTarget> >,
115  // +--------------------------------------------------------------+
116  tr<OpenDoorState, events::DoorOpen, WaitState, none, none>,
117  // +--------------------------------------------------------------+
118  tr<WaitState, events::Timeout, CloseDoorState, none, none>,
119  // +--------------------------------------------------------------+
123  not_<guards::NoQueuedTarget> >,
124  // +--------------------------------------------------------------+
127  >;
128 
131 };
132 
134 using ElevatorStateMachine = ::afsm::state_machine<ElevatorStateMachineDef>;
135 
136 } // namespace systems
137 } // namespace GZ_SIM_VERSION_NAMESPACE
138 } // namespace sim
139 } // namespace gz
140 
142 
143 #endif // GZ_SIM_SYSTEMS_ELEVATOR_STATE_MACHINE_HH_