Revision 322
Copied new analog code into recharging branch.
bom.c | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (c) 2007 Colony Project |
|
3 |
* |
|
4 |
* Permission is hereby granted, free of charge, to any person |
|
5 |
* obtaining a copy of this software and associated documentation |
|
6 |
* files (the "Software"), to deal in the Software without |
|
7 |
* restriction, including without limitation the rights to use, |
|
8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
9 |
* copies of the Software, and to permit persons to whom the |
|
10 |
* Software is furnished to do so, subject to the following |
|
11 |
* conditions: |
|
12 |
* |
|
13 |
* The above copyright notice and this permission notice shall be |
|
14 |
* included in all copies or substantial portions of the Software. |
|
15 |
* |
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
23 |
* OTHER DEALINGS IN THE SOFTWARE. |
|
24 |
**/ |
|
25 |
|
|
26 |
|
|
27 |
/** |
|
28 |
* @file bom.c |
|
29 |
* @brief Implementation for using the BOM |
|
30 |
* |
|
31 |
* Contains functions for using the Bearing and Orientation Module (BOM) |
|
32 |
* |
|
33 |
* @author Colony Project, CMU Robotics Club |
|
34 |
**/ |
|
35 |
|
|
1 | 36 |
#include <dragonfly_lib.h> |
2 | 37 |
#include "bom.h" |
3 | 38 |
#include "dio.h" |
... | ... | |
42 | 77 |
#define MONK3 _PIN_E6 //blue |
43 | 78 |
#define MONK2 _PIN_E7 //white |
44 | 79 |
|
45 |
#define BOM_VALUE_THRESHOLD 160
|
|
80 |
#define BOM_VALUE_THRESHOLD 200
|
|
46 | 81 |
|
47 | 82 |
|
48 | 83 |
/** |
... | ... | |
73 | 108 |
* |
74 | 109 |
* @see analog_init |
75 | 110 |
**/ |
76 |
int get_max_bom(void) { |
|
111 |
int get_max_bom(void) |
|
112 |
{ |
|
77 | 113 |
int max_bom_temp = 0; |
78 |
int a, i, j, h; |
|
79 |
h = 255; |
|
114 |
int a, i, j, h = 255; |
|
80 | 115 |
|
81 |
for (j = 0; j < 16; j++) |
|
82 |
{ |
|
83 |
i = lookup[j]; |
|
116 |
//Turn off the loop so that we can actually use analog8 correctly |
|
117 |
analog_stop_loop(); |
|
84 | 118 |
|
85 |
if (i&8) |
|
86 |
output_high(MONK3); |
|
87 |
else |
|
88 |
output_low(MONK3); |
|
119 |
//Iterate through through each LED |
|
120 |
for (j = 0; j < 16; j++) |
|
121 |
{ |
|
122 |
i = lookup[j]; |
|
123 |
|
|
124 |
if (i&8) |
|
125 |
output_high(MONK3); |
|
126 |
else |
|
127 |
output_low(MONK3); |
|
128 |
|
|
129 |
if (i&4) |
|
130 |
output_high(MONK2); |
|
131 |
else |
|
132 |
output_low(MONK2); |
|
133 |
|
|
134 |
if (i&2) |
|
135 |
output_high(MONK1); |
|
136 |
else |
|
137 |
output_low(MONK1); |
|
138 |
|
|
139 |
if (i&1) |
|
140 |
output_high(MONK0); |
|
141 |
else |
|
142 |
output_low(MONK0); |
|
143 |
|
|
144 |
a = analog_get8(MONKI); |
|
145 |
|
|
146 |
if (a < h) |
|
147 |
{ |
|
148 |
h = a; |
|
149 |
max_bom_temp = j; |
|
150 |
} |
|
89 | 151 |
|
90 |
if (i&4)
|
|
91 |
output_high(MONK2); |
|
92 |
else
|
|
93 |
output_low(MONK2);
|
|
152 |
}
|
|
153 |
|
|
154 |
//Restart loop now that we are done using analog8
|
|
155 |
analog_start_loop();
|
|
94 | 156 |
|
95 |
if (i&2) |
|
96 |
output_high(MONK1); |
|
97 |
else |
|
98 |
output_low(MONK1); |
|
99 |
|
|
100 |
if (i&1) |
|
101 |
output_high(MONK0); |
|
102 |
else |
|
103 |
output_low(MONK0); |
|
104 |
|
|
105 |
a = analog8(MONKI); |
|
106 |
|
|
107 |
if (a < h) |
|
108 |
{ |
|
109 |
h = a; |
|
110 |
max_bom_temp = j; |
|
111 |
} |
|
112 |
|
|
113 |
} |
|
114 |
|
|
115 | 157 |
//threshold on the bom analog value. |
116 | 158 |
//defined in bom.h |
117 | 159 |
// if the analog value read is above the threshold, we cannot see a robot |
Also available in: Unified diff