add framedist
[aversive.git] / projects / microb2010 / sensorboard / scanner.h
1
2 #define SCANNER_ENC         ((void *)1)
3
4 /* relative motor position from mirror axis */
5 #define X  4.5
6 #define Y  -1.25
7
8 /* length of motor arm*/
9 #define l1  0.9
10
11 /* length of bielle */
12 #define l2  2.113
13
14 /* length of mirror (rotating axe to bielle) */
15 //#define l3  4.714
16 #define l3  4.1613
17
18 /* distance from telemetre to mirror axis */
19 #define l_mirror  24.0
20
21 /* higth between mirror axis and horizontal laser beam*/
22 #define h_mirror  -1.0
23
24
25 /* transform telemeter unit to cm
26    using linear approximation
27    d_telemetre = a * cm + b
28 */
29 //#define TELEMETRE_A (16.76)
30 //#define TELEMETRE_B (-476.)
31
32
33 #define TELEMETRE_A_INIT 0.067325
34 #define TELEMETRE_B_INIT 23.225
35
36
37 extern double TELEMETRE_A;
38 extern double TELEMETRE_B;
39
40
41
42
43 #define SCAN_L_MIN 15.
44 #define SCAN_L_MAX 40.
45
46 #define SCAN_H_MAX 40.
47 #define SCAN_H_COEF (255./(SCAN_H_MAX+10.))
48
49 #define SCAN_MAX_DIST 70.
50
51 #define MAX_SAMPLE (1500L)
52
53
54 // TRUE encoder value: 3531.75
55 #define SCANNER_STEP_TOUR (14127L)
56
57 //#define PIX_PER_SCAN 30L
58 #define PIX_PER_SCAN (25L)
59
60 void scanner_init(void);
61 void scanner_set_mode(uint8_t mode);
62
63 void scanner_end_process(void);
64
65 void scanner_calibre_laser(void);
66 void scanner_calibre_mirror(void);
67
68
69 void scanner_scan_autonomous(void);
70
71 int32_t encoders_spi_update_scanner(void * number);
72 int32_t encoders_spi_get_value_scanner(void *number);
73
74 void do_scan(void * dummy);
75
76
77
78 struct  scan_params{
79         uint16_t sample_i;
80         float offset_a;
81         float offset_b;
82         int speed;
83         uint8_t filter;
84         int32_t pos_start_scan;
85
86         int32_t last_col_n;
87         int32_t last_row_n;
88         uint8_t last_sample;
89
90         uint8_t debug;
91         uint8_t sample_tab[MAX_SAMPLE+10];
92         volatile uint8_t working;
93         uint8_t must_stop;
94
95
96         uint8_t algo;   
97
98
99         union {
100                 struct {
101                         uint8_t working_zone;
102                         int16_t center_x;
103                         int16_t center_y;
104                 } drop_zone;
105                 
106                 struct {
107                         uint8_t level;
108                         int16_t temple_x;
109                         int16_t temple_y;
110                 } check_temple;
111         };
112
113
114
115         /* 
116            for column drop zone answer
117         */
118         int8_t dropzone_h;
119         int16_t dropzone_x;
120         int16_t dropzone_y;
121
122         uint8_t max_column_detected;
123 };
124
125
126
127 #define STEP_PER_ROUND 14127
128
129 #define TELEMETRE_MIN 66
130 #define TELEMETRE_MAX 466
131
132
133 #define TELEMETRE_MIN_CM (25)
134 #define TELEMETRE_MAX_CM (55)
135
136
137 #define DIM_ANGLE (400/4)
138 #define DIM_DIST ((TELEMETRE_MAX_CM - TELEMETRE_MIN_CM)*3)
139
140
141
142 #define ANGLE_STEP (STEP_PER_ROUND/DIM_ANGLE +1)
143 #define DIST_STEP ((TELEMETRE_MAX - TELEMETRE_MIN) /DIM_DIST +1)
144
145
146 typedef struct _lookup_h_l{
147         uint16_t h:4;
148         uint16_t l:12;
149 }lookup_h_l;
150
151 #define telemetre_to_cm(t)      ((double)(TELEMETRE_A * ((double)(t)) + TELEMETRE_B))
152
153 #define SCAN_DEFAULT_SPEED 600
154
155
156 extern struct scan_params scan_params;
157
158