root / trunk / code / projects / diagnostic_station / station / test_bom.c @ 1244
History | View | Annotate | Download (2.77 KB)
1 |
#include "test_bom.h" |
---|---|
2 |
#include "global.h" |
3 |
|
4 |
#include "hardware_turntable.h" |
5 |
#include "hardware_rbom.h" |
6 |
#include "comm_robot.h" |
7 |
|
8 |
static uint16_t bom_emitter_position (uint8_t num)
|
9 |
{ |
10 |
switch (num)
|
11 |
{ |
12 |
case 0: return 100; break; |
13 |
case 1: return 200; break; |
14 |
case 2: return 300; break; |
15 |
case 3: return 400; break; |
16 |
case 4: return 500; break; |
17 |
case 5: return 600; break; |
18 |
case 6: return 700; break; |
19 |
case 7: return 800; break; |
20 |
case 8: return 900; break; |
21 |
case 9: return 1000; break; |
22 |
case 10: return 1100; break; |
23 |
case 11: return 1200; break; |
24 |
case 12: return 1300; break; |
25 |
case 13: return 1400; break; |
26 |
case 14: return 1500; break; |
27 |
case 15: return 1600; break; |
28 |
default: return 0; break; |
29 |
} |
30 |
} |
31 |
|
32 |
static uint16_t bom_detector_position (uint8_t num)
|
33 |
{ |
34 |
return bom_emitter_position (num)-50; |
35 |
} |
36 |
|
37 |
|
38 |
void test_bom_bitmask (uint16_t emitter_bitmask, uint16_t detector_bitmask)
|
39 |
{ |
40 |
usb_puts("# Testing BOM" NL);
|
41 |
|
42 |
for (uint8_t n=0; n<16; ++n, emitter_bitmask>>=1, detector_bitmask>>=1) |
43 |
{ |
44 |
if (emitter_bitmask&1) |
45 |
{ |
46 |
uint16_t values[3];
|
47 |
|
48 |
usb_puts("# Testing BOM emitter ");
|
49 |
usb_puti(n); |
50 |
usb_puts(NL); |
51 |
|
52 |
turntable_rotate_to_position (bom_emitter_position (n)); |
53 |
robot_set_bom (1<<n);
|
54 |
|
55 |
rbom_update (); |
56 |
#define TOP 0 |
57 |
#define LEFT 1 |
58 |
#define RIGHT 2 |
59 |
rbom_read (&values[TOP], &values[LEFT], &values[RIGHT]); |
60 |
|
61 |
robot_set_bom (0);
|
62 |
|
63 |
// Send data
|
64 |
usb_puts ("data bom emitter");
|
65 |
usb_puts (" top/" ); usb_puti (values[TOP ]);
|
66 |
usb_puts (" left/" ); usb_puti (values[LEFT ]);
|
67 |
usb_puts (" right/"); usb_puti (values[RIGHT]);
|
68 |
#undef TOP
|
69 |
#undef LEFT
|
70 |
#undef RIGHT
|
71 |
usb_puts (NL); |
72 |
} |
73 |
|
74 |
if (detector_bitmask&1) |
75 |
{ |
76 |
usb_puts("# Testing BOM detector ");
|
77 |
usb_puti(n); |
78 |
usb_puts(NL); |
79 |
turntable_rotate_to_position (bom_detector_position (n)); |
80 |
|
81 |
rbom_set (true);
|
82 |
uint16_t on_value=robot_read_bom (n); |
83 |
rbom_set (false);
|
84 |
uint16_t off_value=robot_read_bom (n); |
85 |
|
86 |
// Send data
|
87 |
usb_puts ("data bom detector ");
|
88 |
usb_puti (n); |
89 |
usb_puts (" on/");
|
90 |
usb_puti (on_value); |
91 |
usb_puts (" off/");
|
92 |
usb_puti (off_value); |
93 |
usb_puts (NL); |
94 |
} |
95 |
} |
96 |
|
97 |
usb_puts("# Testing BOM finished" NL);
|
98 |
} |
99 |
|
100 |
void test_bom (uint8_t num, bool test_emitter, bool test_detector) |
101 |
{ |
102 |
uint16_t emitter_bitmask=0, detector_bitmask=0; |
103 |
|
104 |
if (test_emitter && num<16) emitter_bitmask =1<<num; |
105 |
if (test_detector && num<16) detector_bitmask=1<<num; |
106 |
|
107 |
test_bom_bitmask (emitter_bitmask, detector_bitmask); |
108 |
} |
109 |
|
110 |
void test_bom_all (bool test_emitters, bool test_detectors) |
111 |
{ |
112 |
uint16_t emitter_bitmask=0, detector_bitmask=0; |
113 |
|
114 |
if (test_emitters ) emitter_bitmask =0xFFFF; |
115 |
if (test_detectors) detector_bitmask=0xFFFF; |
116 |
|
117 |
test_bom_bitmask (emitter_bitmask, detector_bitmask); |
118 |
} |