26 #include "../ElevatorStateMachine.hh"
28 #include <gz/common/Console.hh>
35 inline namespace GZ_SIM_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 gzmsg <<
"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 gzmsg <<
"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;