MotorController
control.h
1 #ifndef CONTROL_H
2 #define CONTROL_H
3 
4 /******************************************************************************/
5 /* Includes */
6 /******************************************************************************/
7 #include "hal.h"
8 
9 /******************************************************************************/
10 /* Constants */
11 /******************************************************************************/
12 #define CONTROL_STACK_SIZE 1024
13 #define INT_POS_STACK_SIZE 1024
14 
15 /******************************************************************************/
16 /* Types */
17 /******************************************************************************/
18 typedef struct {
19  int32_t mean_dist; /* Distance to travel (command received from master), in mm */
20  uint16_t heading; /* Heading to reach (command received from master), in range [0, 5760] */
21  int16_t heading_dist_sync_ref; /* Distance from which rotation can start (if linear and angular movements are performed at the same time), in mm */
22 } goal_t;
23 
24 /******************************************************************************/
25 /* Variables */
26 /******************************************************************************/
27 /**
28  * Goal values received from master.
29  */
30 extern volatile goal_t goal;
31 
32 /**
33  * Boolean value indicating whether a new (linear) command has been received.
34  */
35 extern volatile bool dist_command_received;
36 
37 /**
38  * Distance currently travelled since last (linear) command has been received, in mm.
39  */
40 extern volatile int32_t current_distance;
41 
42 /**
43  * Boolean value indicating that motors must be stopped.
44  */
45 extern volatile uint8_t master_stop;
46 
47 /**
48  * Boolean value indicating whether current translation is finished.
49  */
50 extern volatile bool translation_ended;
51 
52 /**
53  * Boolean value indicating whether current rotation is finished.
54  */
55 extern volatile bool rotation_ended;
56 
57 extern binary_semaphore_t reset_orientation_sem;
58 extern volatile int8_t reset_orientation_direction;
59 extern volatile int16_t reset_orientation_orientation;
60 
61 extern THD_WORKING_AREA(wa_control, CONTROL_STACK_SIZE);
62 extern THD_WORKING_AREA(wa_int_pos, INT_POS_STACK_SIZE);
63 extern THD_WORKING_AREA(wa_reset_pos, INT_POS_STACK_SIZE);
64 
65 extern THD_FUNCTION(control_thread, p);
66 extern THD_FUNCTION(int_pos_thread, p);
67 extern THD_FUNCTION(reset_pos_thread, p);
68 
69 
70 /******************************************************************************/
71 /* Local Functions */
72 /******************************************************************************/
73 
74 float compute_target(float, float, float, float, float);
75 
76 #endif /* CONTROL_H */
Definition: control.h:18