Revision 1542
Changed Push-Pull to display BOM histogram as well as net IR BOM vector. Changed BOM Tracker to print an x,y pair separated by a comma so the data
can be saved and read in by MATLAB for analysis.
push_pull.c | ||
---|---|---|
3 | 3 |
#include <wl_basic.h> |
4 | 4 |
#include <stdlib.h> |
5 | 5 |
|
6 |
|
|
7 | 6 |
int main (void) { |
8 | 7 |
|
9 |
/* Store current BOM readings and use them as a weighting factor */ |
|
10 |
uint8_t intensity[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
|
8 |
Vector v; |
|
11 | 9 |
|
12 |
/* Arrays for storing the weighted x ("Rightness") and y ("Forwardness") |
|
13 |
* components. Calculated by multiplying the intensity by the x and y |
|
14 |
* component respectively (x and y components are stored in the tables |
|
15 |
* above). */ |
|
16 |
int weighted_x_comp[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
|
17 |
int weighted_y_comp[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
|
18 |
|
|
19 |
/* Accumulators to sum up the net x ("Rightness") and y ("Forwardness") |
|
20 |
* components for the entire robot. */ |
|
21 |
long net_x_comp = 0; |
|
22 |
long net_y_comp = 0; |
|
23 |
|
|
24 |
/* Variables used to normalize the net component values */ |
|
25 |
int total_intensity = 0; |
|
26 |
int normalized_net_x_comp = 0; |
|
27 |
int normalized_net_y_comp = 0; |
|
28 |
|
|
29 |
int i = 0; |
|
30 |
|
|
31 | 10 |
dragonfly_init(ALL_ON); |
32 | 11 |
xbee_init(); |
33 | 12 |
encoders_init(); |
... | ... | |
39 | 18 |
orbs_set_color(RED, RED); |
40 | 19 |
|
41 | 20 |
while (1) { |
42 |
|
|
43 |
/* Make sure to clear our accumulators */ |
|
44 |
net_x_comp = 0; |
|
45 |
net_y_comp = 0; |
|
46 |
total_intensity = 0; |
|
47 |
|
|
48 | 21 |
bom_print_usb(NULL); |
49 | 22 |
|
50 |
bom_refresh(BOM_ALL); |
|
51 |
for (i = 0; i < 16; i++) { |
|
52 |
/* BOM intensity is actually measured as more intense = closer to 0 */ |
|
53 |
intensity[i] = 255 - bom_get(i); |
|
54 |
weighted_x_comp[i] = intensity[i] * x_comp[i]; |
|
55 |
weighted_y_comp[i] = intensity[i] * y_comp[i]; |
|
56 |
net_x_comp += weighted_x_comp[i]; |
|
57 |
net_y_comp += weighted_y_comp[i]; |
|
58 |
total_intensity += intensity[i]; |
|
59 |
} |
|
23 |
bom_get_vector(&v, NULL); |
|
60 | 24 |
|
61 |
if (total_intensity > 0) { |
|
62 |
normalized_net_x_comp = net_x_comp / total_intensity; |
|
63 |
normalized_net_y_comp = net_y_comp / total_intensity; |
|
64 |
} |
|
65 |
|
|
66 |
usb_puts("x: "); |
|
67 |
usb_puti(normalized_net_x_comp); |
|
25 |
usb_puts("x: "); |
|
26 |
usb_puti(v.x); |
|
68 | 27 |
usb_puts("\ty: "); |
69 |
usb_puti(normalized_net_y_comp);
|
|
28 |
usb_puti(v.y);
|
|
70 | 29 |
usb_puts("\n"); |
71 | 30 |
|
72 | 31 |
delay_ms(50); |
73 |
|
|
74 | 32 |
} |
75 | 33 |
|
76 | 34 |
while(1); |
Also available in: Unified diff