]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/eb_lift/fsm.h
eb_lift: Add new project that is common lift ccntroler for year 2012 and the future...
[eurobot/public.git] / src / eb_lift / fsm.h
1 #ifndef FSM_H
2 #define FSM_H
3
4 #include <types.h>
5 #include <stdbool.h>
6
7 // events of each state of state machine
8 enum event {
9         EVENT_ENTRY,
10         EVENT_DO,
11         EVENT_EXIT
12 }; 
13
14 struct fsm;
15
16 typedef void (*state_fcn)(struct fsm *fsm, enum event my_event);//pointer to function returning void and two input parametr
17
18 struct fsm {
19         state_fcn current_state;                // current state
20         state_fcn last_state;                   // last state
21         int32_t act_pos;                        // actual position
22         int32_t req_pos;                        // requested position
23         int32_t req_spd;
24         int32_t req_target;
25         volatile int32_t can_req_spd;
26         volatile uint32_t can_req_position;     // next requested position
27         int32_t start_pos;
28         uint32_t can_response;                  // when the move is done, the value here equals to the req_pos
29         uint8_t flags;   //< CAN flags bits (defined in can_msg_def.h)
30         uint32_t time_start;    /* For timeout detection */
31         bool trigger_can_send;
32         uint8_t can_req_homing;
33 };
34
35
36 void init_fsm(struct fsm *fsm, state_fcn initial_state);
37 void run_fsm(struct fsm *fsm);
38
39 #endif