init
Dependencies: MPU6050 PinDetect circular_buffer
MotionFSM/include/Fsm.h@0:b416214256cd, 2017-11-07 (annotated)
- Committer:
- OsmanKameric
- Date:
- Tue Nov 07 16:35:14 2017 +0000
- Revision:
- 0:b416214256cd
FIRST
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
OsmanKameric | 0:b416214256cd | 1 | #ifndef MOTIONFSM_FSM_H_ |
OsmanKameric | 0:b416214256cd | 2 | #define MOTIONFSM_FSM_H_ |
OsmanKameric | 0:b416214256cd | 3 | #include <State.h> |
OsmanKameric | 0:b416214256cd | 4 | #include "mbed.h" |
OsmanKameric | 0:b416214256cd | 5 | |
OsmanKameric | 0:b416214256cd | 6 | #include <Events.h> |
OsmanKameric | 0:b416214256cd | 7 | |
OsmanKameric | 0:b416214256cd | 8 | struct Stop; |
OsmanKameric | 0:b416214256cd | 9 | struct Move; |
OsmanKameric | 0:b416214256cd | 10 | |
OsmanKameric | 0:b416214256cd | 11 | class FsmStates { |
OsmanKameric | 0:b416214256cd | 12 | public: |
OsmanKameric | 0:b416214256cd | 13 | FsmStates(); |
OsmanKameric | 0:b416214256cd | 14 | |
OsmanKameric | 0:b416214256cd | 15 | State* movingState(); |
OsmanKameric | 0:b416214256cd | 16 | State* stacionaryState(); |
OsmanKameric | 0:b416214256cd | 17 | State* currentState(); |
OsmanKameric | 0:b416214256cd | 18 | |
OsmanKameric | 0:b416214256cd | 19 | void currentState(State* state); |
OsmanKameric | 0:b416214256cd | 20 | |
OsmanKameric | 0:b416214256cd | 21 | ~FsmStates(); |
OsmanKameric | 0:b416214256cd | 22 | |
OsmanKameric | 0:b416214256cd | 23 | private: |
OsmanKameric | 0:b416214256cd | 24 | |
OsmanKameric | 0:b416214256cd | 25 | State* movingState_; |
OsmanKameric | 0:b416214256cd | 26 | State* stacionaryState_; |
OsmanKameric | 0:b416214256cd | 27 | State* currentState_; |
OsmanKameric | 0:b416214256cd | 28 | |
OsmanKameric | 0:b416214256cd | 29 | Timer timer; |
OsmanKameric | 0:b416214256cd | 30 | |
OsmanKameric | 0:b416214256cd | 31 | }; |
OsmanKameric | 0:b416214256cd | 32 | |
OsmanKameric | 0:b416214256cd | 33 | class Fsm { |
OsmanKameric | 0:b416214256cd | 34 | public: |
OsmanKameric | 0:b416214256cd | 35 | Fsm(); |
OsmanKameric | 0:b416214256cd | 36 | template <typename Event> |
OsmanKameric | 0:b416214256cd | 37 | void handle(Event& event){ |
OsmanKameric | 0:b416214256cd | 38 | State* state = states_.currentState()->handle(event); |
OsmanKameric | 0:b416214256cd | 39 | states_.currentState(state); |
OsmanKameric | 0:b416214256cd | 40 | } |
OsmanKameric | 0:b416214256cd | 41 | |
OsmanKameric | 0:b416214256cd | 42 | virtual ~Fsm() {} |
OsmanKameric | 0:b416214256cd | 43 | FsmStates states_; |
OsmanKameric | 0:b416214256cd | 44 | private: |
OsmanKameric | 0:b416214256cd | 45 | |
OsmanKameric | 0:b416214256cd | 46 | |
OsmanKameric | 0:b416214256cd | 47 | }; |
OsmanKameric | 0:b416214256cd | 48 | #endif /* ifndef MOTIONFSM_FSM_H_ */ |