packml_state_machine.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (Apache License)
3  *
4  * Copyright (c) 2018 Plus One Robotics
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #pragma once
19 #include "packml_sm/common.h"
26 
27 #include <map>
28 #include <functional>
29 #include <boost/msm/back/state_machine.hpp>
30 #include <boost/msm/front/state_machine_def.hpp>
31 #include <boost/msm/front/states.hpp>
32 
33 namespace packml_sm
34 {
35 template <typename T>
37 {
38 public:
39  virtual ~PackmlStateMachine();
40 
41  // AbstractStateMachine
42  virtual bool deactivate() override;
43  virtual bool activate() override;
44  virtual bool setStarting(std::function<int()> state_method) override;
45  virtual bool setExecute(std::function<int()> state_method) override;
46  virtual bool setCompleting(std::function<int()> state_method) override;
47  virtual bool setAborting(std::function<int()> state_method) override;
48  virtual bool setClearing(std::function<int()> state_method) override;
49  virtual bool setStopping(std::function<int()> state_method) override;
50  virtual bool setResetting(std::function<int()> state_method) override;
51  virtual bool setSuspending(std::function<int()> state_method) override;
52  virtual bool setUnsuspending(std::function<int()> state_method) override;
53  virtual bool setHolding(std::function<int()> state_method) override;
54  virtual bool setUnholding(std::function<int()> state_method) override;
55  virtual bool isActive() override;
56 
57 protected:
59 
60  virtual void _start() override;
61  virtual void _clear() override;
62  virtual void _reset() override;
63  virtual void _hold() override;
64  virtual void _unhold() override;
65  virtual void _suspend() override;
66  virtual void _unsuspend() override;
67  virtual void _stop() override;
68  virtual void _abort() override;
69 
70 private:
71  bool is_active_ = false;
72 
73  boost::msm::back::state_machine<T> boost_fsm_;
75 
76  bool setStateMethod(StatesEnum state, std::function<int()> state_method);
77  void sendCommand(CmdEnum command);
78  void handleStateChanged(StateChangeNotifier& state_machine, const StateChangedEventArgs& args);
79  void update(StateMachineEventLoop& event_loop, const EventArgs& args);
81 };
82 
85 }
virtual bool setStarting(std::function< int()> state_method) override
Override to handle setting the starting state method.
virtual void _start() override
Override to call implementations version of start command.
void update(StateMachineEventLoop &event_loop, const EventArgs &args)
virtual bool setHolding(std::function< int()> state_method) override
Override to handle setting the holding state method.
PackmlState * getPackmlState(StatesEnum state)
virtual bool setCompleting(std::function< int()> state_method) override
Override to handle setting the completing state method.
The StateMachineInterface class defines a implementation independent interface to a PackML state mach...
StateMachineEventLoop event_loop_
virtual bool isActive() override
Override to provide an accessor to whether the state machine is currently active. ...
virtual void _reset() override
Override to call implementations version of the reset command.
virtual bool setClearing(std::function< int()> state_method) override
Override to handle setting the clearing state method.
virtual bool setStopping(std::function< int()> state_method) override
Override to handle setting the stopping state method.
virtual void _unsuspend() override
Override to call implementations version of the unsuspend command.
boost::msm::back::state_machine< T > boost_fsm_
virtual bool activate() override
Override to handle activate command.
virtual bool setSuspending(std::function< int()> state_method) override
Override to handle setting the suspending state method.
virtual void _hold() override
Override to call implementations version of the hold command.
virtual bool setUnsuspending(std::function< int()> state_method) override
Override to handle setting the un-suspending state method.
virtual bool setResetting(std::function< int()> state_method) override
Override to handle setting the resetting state method.
virtual void _abort() override
Override to call implementations version of the abort command.
StatesEnum
Definition: common.h:35
virtual void _stop() override
Override to call implementations version of the stop command.
virtual bool setAborting(std::function< int()> state_method) override
Override to handle setting the aborting state method.
void handleStateChanged(StateChangeNotifier &state_machine, const StateChangedEventArgs &args)
bool setStateMethod(StatesEnum state, std::function< int()> state_method)
virtual bool deactivate() override
Override to handle deactivate command.
virtual void _unhold() override
Override to call implementations version of the unhold command.
virtual void _clear() override
Override to call implementations version of clear command.
virtual void _suspend() override
Override to call implementations version of the suspend command.
virtual bool setExecute(std::function< int()> state_method) override
Override to handle setting the execute state method.
virtual bool setUnholding(std::function< int()> state_method) override
Override to handle setting unholding state method.


packml_sm
Author(s): Shaun Edwards
autogenerated on Fri Jul 12 2019 03:30:55