Rev 1407 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1331 | giacomo | 1 | /* |
2 | * Project: HARTIK (HA-rd R-eal TI-me K-ernel) |
||
3 | * |
||
4 | * Coordinators: Giorgio Buttazzo <giorgio@sssup.it> |
||
5 | * Gerardo Lamastra <gerardo@sssup.it> |
||
6 | * |
||
7 | * |
||
8 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
9 | * |
||
10 | * http://www.sssup.it |
||
11 | * http://retis.sssup.it |
||
12 | * http://hartik.sssup.it |
||
13 | */ |
||
14 | |||
15 | #include <stdlib.h> |
||
16 | #include <string.h> |
||
17 | #include <math.h> |
||
18 | #include <kernel/kern.h> |
||
19 | #include <kernel/func.h> |
||
20 | #include <semaphore.h> |
||
21 | #include "modules/sem.h" |
||
22 | #include "modules/hartport.h" |
||
1390 | mauro | 23 | #include <drivers/keyb.h> |
1331 | giacomo | 24 | |
25 | #include <servo.h> |
||
1407 | giacomo | 26 | #include <drivers/udpip.h> |
1331 | giacomo | 27 | |
28 | /* COM Port Constants */ |
||
1359 | giacomo | 29 | #define COM_PORT COM1 |
1331 | giacomo | 30 | #define COM_SPEED 115200 |
31 | |||
1359 | giacomo | 32 | #define com(i) ((i) / 12) ? COM1 : COM2 |
1331 | giacomo | 33 | #define pin(i) (i) % 12 |
34 | |||
35 | /* Angle bounds */ |
||
36 | #define POS_X_MIN 0 |
||
37 | #define POS_X_MAX 200 |
||
38 | #define POS_Y_MIN -200 |
||
39 | #define POS_Y_MAX 200 |
||
40 | #define POS_Z_MIN -150 |
||
41 | #define POS_Z_MAX 150 |
||
42 | |||
1333 | giacomo | 43 | typedef struct { |
44 | int adc_in; |
||
45 | unsigned char pwm; |
||
46 | } LEG_CFG_STATE; |
||
47 | |||
1336 | giacomo | 48 | typedef struct { /*describe the position of leg*/ |
1331 | giacomo | 49 | int x; |
50 | int y; |
||
51 | int z; |
||
1333 | giacomo | 52 | } LEG_POS_STATE; |
1331 | giacomo | 53 | |
1336 | giacomo | 54 | typedef struct { /*describe the servo angles*/ |
1333 | giacomo | 55 | int a; |
56 | int b; |
||
57 | int c; |
||
58 | } LEG_ANG_STATE; |
||
59 | |||
1331 | giacomo | 60 | typedef struct { |
1333 | giacomo | 61 | LEG_CFG_STATE cfg[6]; |
62 | LEG_ANG_STATE ang[6]; |
||
1331 | giacomo | 63 | char power; |
64 | } HEXAPOD_STATE; |
||
65 | |||
66 | /*****************************************/ |
||
67 | |||
1333 | giacomo | 68 | #define EVT_SET_MASK_LEG_ANGLE 0x01 |
69 | |||
1396 | giacomo | 70 | #define EVT_STATUS_FREE 0x00 |
1333 | giacomo | 71 | #define EVT_STATUS_WAIT 0x01 |
72 | #define EVT_STATUS_EXEC 0x02 |
||
73 | #define EVT_STATUS_DONE 0x03 |
||
74 | |||
75 | struct action_event { |
||
76 | |||
77 | unsigned char type; |
||
78 | unsigned char status; |
||
79 | struct timespec time; |
||
80 | unsigned char mask; |
||
1336 | giacomo | 81 | LEG_ANG_STATE ang; //Servo angle data |
82 | unsigned char pwm; |
||
1333 | giacomo | 83 | struct action_event *next; |
84 | |||
85 | }; |
||
86 | |||
87 | struct action_event *get_first_old_event(struct timespec *time); |
||
88 | |||
1331 | giacomo | 89 | extern sem_t mx_status; |
90 | extern HEXAPOD_STATE status; |
||
91 | |||
92 | void init_send(void); |
||
93 | void end_send(void); |
||
94 | |||
95 | void init_key(void); |
||
1336 | giacomo | 96 | |
1337 | giacomo | 97 | /* Calibration */ |
98 | |||
99 | void calibrate_init(void); |
||
100 | void calibrate_step(int step); |
||
1336 | giacomo | 101 | int adjust(int angle_sec, int leg, int num); |
102 | |||
1337 | giacomo | 103 | /* Actions */ |
104 | |||
1396 | giacomo | 105 | int init_action_event(int number_of_events); |
1337 | giacomo | 106 | int insert_action_event(struct action_event *e); |
1396 | giacomo | 107 | int delete_action_event(int event); |
1337 | giacomo | 108 | struct action_event * get_first_old_event(struct timespec *time); |
109 | |||
1407 | giacomo | 110 | /* Tracer */ |
111 | |||
112 | int trace_init(int buffer_size); |
||
113 | int trace_consumption(int sensor, int value); |
||
1408 | giacomo | 114 | int trace_send(); |
1407 | giacomo | 115 |