6 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 //~~~~~~~~~~ definition of interrupt priority ~~~~~~~~~~~
8 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 #define SERVO_PRIORITY 7 // 0 is the biggest priority
10 #define IRC_PRIORITY 5 // higher priority than servo
13 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14 //~~~~~~~ definition of macros for bit operations ~~~~~~~
15 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16 #define sbit(WORD,BIT) (WORD|=(1<<BIT)) //set bit
17 #define cbit(WORD,BIT) (WORD&=~(1<<BIT)) //clear bit
18 #define tbit(WORD,BIT) (WORD&(1<<BIT)) //test bit
20 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21 //~~~~~~~~~ definition of CAN bus cominication ~~~~~~~~~~
22 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 #define CAN_SPEED 1000000 //< CAN bus speed
25 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26 //~~~~~~~~~~~~ definition of some constants ~~~~~~~~~~~~~
27 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29 #define SERVO_DOOR 0 //< position of servo conector
30 #define CHELAE_R 1 //< position of right chelae
32 #define SERVO_DOOR_MAX 0xA0 //< maximum HW servo value of DOOR
33 #define SERVO_DOOR_MIN 0x00 //< minimum HW servo value of DOOR
34 #define CHELAE_R_MAX 0xE0 //< maximum HW servo value of RIGHT CHELAE
35 #define CHELAE_R_MIN 0x30 //< minimum HW servo value of RIGHT CHELAE
39 typedef enum {//mark which unit we want controlled
44 typedef enum {// events of each state of state machine
52 typedef void (*state_fcn)(struct fsm *fsm, events my_event);//pointer to function returning void and two input parametr
53 typedef void (*move_eng)(uint8_t direct,uint8_t velocity);//pointer to function returning void and two input parametr
55 /// fsm structure for pusher and lift
57 state_fcn current_state; // current state
58 state_fcn last_state; // last state
59 int32_t act_pos; // actual position
60 int32_t req_pos; // requested position
61 int32_t last_irc; // last IRC position
62 volatile uint32_t can_req_position; // next requested position
63 volatile int32_t * irc; // pointer to IRC value
64 uint32_t timeout_glob; // global timeout
65 uint32_t timeout_switch; // switch inactive timeout
66 uint8_t type; // fsm typedef
67 uint8_t motor_dir; // motor direction
68 move_eng set_engine; // engine set function
69 uint32_t lenght; // total length fs lift/pusher
70 uint32_t sw_pin; // engine sensor
71 uint16_t ans_can; // CAN position answer
72 uint8_t speed_home; // homing speed
73 uint8_t speed_normal; // normal speed
74 uint8_t speed_slow; // normal speed
75 bool switch_front; // up or front end switch
76 bool switch_back; // down or back end switch
77 uint8_t init_flag; // init status flag
78 uint32_t p; ///< PI controller constants * 1000
79 uint32_t last_move_time; ///< Last timer_msec when act_pos changed
82 extern volatile uint32_t timer_msec;
83 extern volatile uint32_t timer_usec; /* incremented by 10 @100kHz */
85 void set_holder(unsigned char range);
87 #define LIFT_LIFT_PROTECT_PUSHER_TOP 0x03C0 //< maximum Lift height where we must protect pusher
88 #define LIFT_PUSHER_PROTECT_TOP 0x0C5 //< maximum pusher extrusion at protected area
90 volatile uint8_t can_flags; //< can flags bit
92 void can_send_status(void);