Go to the documentation of this file.
26 #include "../ElevatorStateMachine.hh"
28 #include <gz/common/Console.hh>
35 inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
42 public:
template <
typename Event,
typename FSM>
51 struct ElevatorStateMachineDef::DoorState : state<DoorState<E>>
58 public: DoorState(
double _posEps = 2e-2,
double _velEps = 1e-2)
59 : posEps(_posEps), velEps(_velEps)
64 public:
virtual ~DoorState()
71 public:
template <
typename Event,
typename FSM>
72 void on_enter(
const Event &, FSM &_fsm)
74 const auto &data = _fsm.dataPtr;
75 int32_t floorTarget = data->system->state;
78 double jointTarget = this->JointTarget(data, floorTarget);
79 data->SendCmd(data->system->doorJointCmdPubs[floorTarget], jointTarget);
80 this->triggerEvent = [&_fsm] { _fsm.process_event(E()); };
81 data->system->SetDoorMonitor(
82 floorTarget, jointTarget, this->posEps, this->velEps,
83 std::bind(&DoorState::OnJointTargetReached,
this));
96 private:
virtual double JointTarget(
98 int32_t _floorTarget)
const = 0;
101 private:
void OnJointTargetReached()
103 this->triggerEvent();
107 private:
double posEps;
110 private:
double velEps;
133 private:
virtual double JointTarget(
135 int32_t _floorTarget)
const override
137 return _data->system->doorTargets[_floorTarget];
155 private:
virtual double JointTarget(
157 int32_t )
const override
171 public:
template <
typename Event,
typename FSM>
174 const auto &data = _fsm.dataPtr;
175 ignmsg <<
"The elevator is waiting to close door " << data->system->state
178 this->triggerEvent = [&_fsm] { _fsm.process_event(
events::Timeout()); };
179 data->system->StartDoorTimer(data->system->state,
184 private:
void OnTimeout()
186 this->triggerEvent();
205 : posEps(_posEps), velEps(_velEps)
212 public:
template <
typename Event,
typename FSM>
215 const auto &data = _fsm.dataPtr;
216 int32_t floorTarget = data->targets.front();
217 ignmsg <<
"The elevator is moving the cabin [ " << data->system->state
218 <<
" -> " << floorTarget <<
" ]" <<
std::endl;
220 double jointTarget = data->system->cabinTargets[floorTarget];
221 data->SendCmd(data->system->cabinJointCmdPub, jointTarget);
222 this->triggerEvent = [&_fsm] {
225 data->system->SetCabinMonitor(
226 floorTarget, jointTarget, this->posEps, this->velEps,
227 std::bind(&MoveCabinState::OnJointTargetReached,
this));
231 private:
void OnJointTargetReached()
233 this->triggerEvent();
237 private:
double posEps;
240 private:
double velEps;
This library is part of the Gazebo project.
MoveCabinState(double _posEps=15e-2, double _velEps=1e-2)
Constructor.
Definition: StatesImpl.hh:204
void on_enter(const Event &, FSM &)
Logs the entry to the state.
Definition: StatesImpl.hh:43
void on_enter(const Event &, FSM &_fsm)
Starts the timer that keeps the door at the target floor level open.
Definition: StatesImpl.hh:172
CloseDoorState()=default
Constructor.
void on_enter(const Event &, FSM &_fsm)
Sends the command that moves the cabin joint to the target floor and configures the monitor that chec...
Definition: StatesImpl.hh:213
OpenDoorState()=default
Constructor.
State at which the elevator is moving the cabin to the target floor.
Definition: StatesImpl.hh:194
type_tuple< events::EnqueueNewTarget > deferred_events
This state defers EnqueueNewTargetEvent events.
Definition: StatesImpl.hh:197
State at which the elevator is waiting with a door open.
Definition: StatesImpl.hh:164
State at which the elevator is idling.
Definition: StatesImpl.hh:39
Event that signifies the cabin has reached the target floor level.
Definition: EventsImpl.hh:70
State at which the elevator is closing a door.
Definition: StatesImpl.hh:142
Event that signifies the door at the target floor level has remained open for the required amount of ...
Definition: EventsImpl.hh:65
State at which the elevator is opening a door.
Definition: StatesImpl.hh:117
type_tuple< events::EnqueueNewTarget > deferred_events
This state defers EnqueueNewTargetEvent events.
Definition: StatesImpl.hh:167
type_tuple< events::EnqueueNewTarget > deferred_events
This state defers EnqueueNewTargetEvent events.
Definition: StatesImpl.hh:120