Revision 369
First crack at BOMv1.5 driver code. Pindefs are correct and the existing functions still work. At the moment the main function controls the clock and data of the rbom so you can shift things around. TODO: get bom_set_emitters working to correctly shift 16 bits around. Eventually this will have to be merged with the new bom code that James wrote, probably manually.
branches/rbom/code/projects/template/main.c | ||
---|---|---|
1 | 1 |
#include <dragonfly_lib.h> |
2 | 2 |
|
3 | 3 |
int main(void) { |
4 |
dragonfly_init(ALL_ON); |
|
4 |
dragonfly_init(ALL_ON|BOM_15); |
|
5 |
orb_init(); |
|
6 |
orb_enable(); |
|
7 |
bom_on(); |
|
8 |
char state = 0; |
|
9 |
while(1) |
|
10 |
{ |
|
11 |
if(button1_click()) |
|
12 |
state ^= 1; |
|
13 |
if(button2_click()) |
|
14 |
state ^= 2; |
|
15 |
|
|
16 |
if(state&1) |
|
17 |
{ |
|
18 |
orb1_set_color(RED); |
|
19 |
digital_output(_PIN_A1, 1); |
|
20 |
|
|
21 |
} |
|
22 |
else |
|
23 |
{ |
|
24 |
orb1_set_color(BLUE); |
|
25 |
digital_output(_PIN_A1, 0); |
|
26 |
} |
|
27 |
if(state&2) |
|
28 |
{ |
|
29 |
orb2_set_color(GREEN); |
|
30 |
digital_output(_PIN_A0, 1); |
|
31 |
} |
|
32 |
else |
|
33 |
{ |
|
34 |
orb2_set_color(BLUE); |
|
35 |
digital_output(_PIN_A0, 0); |
|
36 |
} |
|
37 |
} |
|
5 | 38 |
return 0; |
6 | 39 |
} |
branches/rbom/code/projects/template/Makefile | ||
---|---|---|
14 | 14 |
# USE_WIRELESS = 1 |
15 | 15 |
|
16 | 16 |
# com1 = serial port. Use lpt1 to connect to parallel port. |
17 |
AVRDUDE_PORT = com4
|
|
17 |
AVRDUDE_PORT = com6
|
|
18 | 18 |
# |
19 | 19 |
# |
20 | 20 |
################################### |
... | ... | |
116 | 116 |
endif |
117 | 117 |
|
118 | 118 |
# Place -I, -L options here |
119 |
CINCS = -I$(COLONYROOT)/code/lib/include/libdragonfly |
|
120 |
CINCS += -L$(COLONYROOT)/code/lib/bin |
|
121 |
ifdef USE_WIRELESS |
|
122 |
CINCS += -I$(COLONYROOT)/code/lib/include/libwireless |
|
123 |
endif |
|
119 |
CINCS = -I../libdragonfly |
|
120 |
CINCS += -L../libdragonfly |
|
124 | 121 |
|
125 | 122 |
#---------------- Compiler Options ---------------- |
126 | 123 |
# -g*: generate debugging information |
branches/rbom/code/projects/libdragonfly/dragonfly_lib.c | ||
---|---|---|
104 | 104 |
orb_init(); |
105 | 105 |
} |
106 | 106 |
|
107 |
if(config & RANGE) |
|
108 |
range_init(); |
|
109 |
|
|
110 |
if(config & BOM_15) |
|
111 |
bom_15_init(); |
|
107 | 112 |
// delay a bit for stability |
108 | 113 |
_delay_ms(1); |
109 | 114 |
} |
branches/rbom/code/projects/libdragonfly/dragonfly_lib.h | ||
---|---|---|
60 | 60 |
#define BUZZER 0x40 |
61 | 61 |
/** @brief Initialize the LCD screen **/ |
62 | 62 |
#define LCD 0x80 |
63 |
/** @brief Initialize everything **/ |
|
64 |
#define ALL_ON 0xFF |
|
63 |
/** @brief Initialize the rangefinders **/ |
|
64 |
#define RANGE 0x0100 |
|
65 |
/** @brief Initialize the rangefinders **/ |
|
66 |
#define BOM_15 0x0200 |
|
67 |
/** @brief Initialize everything (default is BOM v1.0) **/ |
|
68 |
#define ALL_ON 0x01FF |
|
65 | 69 |
|
66 | 70 |
|
67 | 71 |
/** @brief Initialize the board **/ |
branches/rbom/code/projects/libdragonfly/bom.c | ||
---|---|---|
79 | 79 |
|
80 | 80 |
#define BOM_VALUE_THRESHOLD 200 |
81 | 81 |
|
82 |
/* |
|
83 |
*The following pin definitions are for the BOM v1.5 |
|
84 |
*/ |
|
82 | 85 |
|
86 |
#define BOM_MODE _PIN_E2 //dio0 |
|
87 |
#define BOM_STROBE _PIN_E3 //dio1 |
|
88 |
|
|
89 |
#define BOM_DATA _PIN_A0 //servo0 |
|
90 |
#define BOM_CLOCK _PIN_A1 //servo1 |
|
91 |
|
|
92 |
#define BOM_S0 _PIN_E6 //dio3 |
|
93 |
#define BOM_S1 _PIN_E7 //dio2 |
|
94 |
#define BOM_S2 _PIN_E4 //dio1 |
|
95 |
#define BOM_S3 _PIN_E5 //dio0 |
|
96 |
#define BOM_OUT PF0 //analog(yellow) |
|
97 |
|
|
98 |
//this is set to 1 if we are using a BOM1.5, and 0 otherwise |
|
99 |
static char is_bom_15 = 0; |
|
100 |
|
|
83 | 101 |
/** |
84 | 102 |
* @defgroup bom BOM (Bearing and Orientation Module) |
85 | 103 |
* @brief Functions for dealing with the BOM. |
... | ... | |
90 | 108 |
* The BOM is most often use to determine the direction of other |
91 | 109 |
* robots. This module contains functions for controlling the BOM. |
92 | 110 |
* |
111 |
* There are currently two versions of the BOM in operation: v1.0 |
|
112 |
* and v1.5. v1.5 includes new functionality such as addressable |
|
113 |
* emitters, and RSSI range measurement. If a BOM1.5 is connected |
|
114 |
* to a robot, make sure to add a BOM1_5 flag to dragonfly_init(). |
|
115 |
* |
|
93 | 116 |
* Include bom.h to access these functions. |
94 | 117 |
* |
95 | 118 |
* @{ |
96 | 119 |
**/ |
97 | 120 |
|
121 |
|
|
98 | 122 |
/** |
123 |
* Initializes a BOM1.5 to have all emitters on, and in normal mode. |
|
124 |
* With this initialization the BOM1.5 is functionally equivalent to |
|
125 |
* BOM1.0 |
|
126 |
**/ |
|
127 |
void bom_15_init(void) { |
|
128 |
is_bom_15 = 1; |
|
129 |
bom_set_emitters(0xFFFF); |
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* Sets a BOM1.5 to RSSI mode. |
|
134 |
**/ |
|
135 |
void bom_RSSI_mode(void) { |
|
136 |
output_high(BOM_MODE); |
|
137 |
} |
|
138 |
|
|
139 |
/** |
|
140 |
* Sets a BOM1.5 to normal mode. |
|
141 |
**/ |
|
142 |
void bom_normal_mode(void) { |
|
143 |
output_low(BOM_MODE); |
|
144 |
} |
|
145 |
|
|
146 |
/** |
|
147 |
* Sets which emitters come on when a BOM1.5 is turned on. |
|
148 |
* The LSB of the pattern corresponds to emitter 0, and the |
|
149 |
* MSB corresponds to emitter 15 |
|
150 |
**/ |
|
151 |
void bom_set_emitters(int pattern) { |
|
152 |
int mask = 0x8000; |
|
153 |
for(; mask>0; mask=mask>>1) |
|
154 |
{ |
|
155 |
//set the current bit |
|
156 |
digital_output(BOM_DATA, 1); |
|
157 |
//then pulse the clock |
|
158 |
delay_ms(1); |
|
159 |
output_high(BOM_CLOCK); |
|
160 |
delay_ms(1); |
|
161 |
output_low(BOM_CLOCK); |
|
162 |
} |
|
163 |
} |
|
164 |
|
|
165 |
/** |
|
99 | 166 |
* Returns the direction of the maximum BOM reading, |
100 | 167 |
* as an integer in the range 0-15. 0 indicates to the |
101 | 168 |
* robot's right, while the rest of the sensors are |
... | ... | |
113 | 180 |
int a, i, j, h; |
114 | 181 |
h = 255; |
115 | 182 |
|
116 |
//Turn off the loop so that we can actually use analog8 correctly |
|
117 |
analog_stop_loop(); |
|
118 |
|
|
119 |
//Iterate through through each LED |
|
120 | 183 |
for (j = 0; j < 16; j++) |
121 | 184 |
{ |
122 | 185 |
i = lookup[j]; |
123 | 186 |
|
124 | 187 |
if (i&8) |
125 |
output_high(MONK3); |
|
188 |
output_high(is_bom_15?BOM_S3:MONK3);
|
|
126 | 189 |
else |
127 |
output_low(MONK3); |
|
190 |
output_low(is_bom_15?BOM_S3:MONK3);
|
|
128 | 191 |
|
129 | 192 |
if (i&4) |
130 |
output_high(MONK2); |
|
193 |
output_high(is_bom_15?BOM_S2:MONK2);
|
|
131 | 194 |
else |
132 |
output_low(MONK2); |
|
195 |
output_low(is_bom_15?BOM_S2:MONK2);
|
|
133 | 196 |
|
134 | 197 |
if (i&2) |
135 |
output_high(MONK1); |
|
198 |
output_high(is_bom_15?BOM_S1:MONK1);
|
|
136 | 199 |
else |
137 |
output_low(MONK1); |
|
200 |
output_low(is_bom_15?BOM_S1:MONK1);
|
|
138 | 201 |
|
139 | 202 |
if (i&1) |
140 |
output_high(MONK0); |
|
203 |
output_high(is_bom_15?BOM_S0:MONK0);
|
|
141 | 204 |
else |
142 |
output_low(MONK0); |
|
205 |
output_low(is_bom_15?BOM_S0:MONK0);
|
|
143 | 206 |
|
144 |
a = analog_get8(MONKI);
|
|
207 |
a = analog8(is_bom_15?BOM_OUT:MONKI);
|
|
145 | 208 |
|
146 | 209 |
if (a < h) |
147 | 210 |
{ |
... | ... | |
150 | 213 |
} |
151 | 214 |
|
152 | 215 |
} |
153 |
|
|
154 |
//Restart loop now that we are done using analog8 |
|
155 |
analog_start_loop(); |
|
156 | 216 |
|
157 | 217 |
//threshold on the bom analog value. |
158 | 218 |
//defined in bom.h |
... | ... | |
173 | 233 |
**/ |
174 | 234 |
void bom_on(void) |
175 | 235 |
{ |
176 |
output_high(MONKL); |
|
236 |
output_high(is_bom_15?BOM_STROBE:MONKL);
|
|
177 | 237 |
} |
178 | 238 |
|
179 | 239 |
/** |
... | ... | |
184 | 244 |
**/ |
185 | 245 |
void bom_off(void) |
186 | 246 |
{ |
187 |
output_low(MONKL); |
|
247 |
output_low(is_bom_15?BOM_STROBE:MONKL);
|
|
188 | 248 |
} |
189 | 249 |
|
190 | 250 |
/** @} **/ //end group |
branches/rbom/code/projects/libdragonfly/bom.h | ||
---|---|---|
42 | 42 |
* @addtogroup bom |
43 | 43 |
* @{ |
44 | 44 |
**/ |
45 |
|
|
45 |
/** @brief Initializes a BOM v1.5 **/ |
|
46 |
void bom_15_init(void); |
|
47 |
/** @brief Sets the mode of a BOM v1.5**/ |
|
48 |
void bom_RSSI_mode(void); |
|
49 |
/** @brief Sets the mode of a BOM v1.5**/ |
|
50 |
void bom_normal_mode(void); |
|
51 |
/** @brief Sets the emmitter pattern a BOM v1.5**/ |
|
52 |
void bom_set_emitters(int pattern); |
|
46 | 53 |
/** @brief Returns the location of the maximum BOM reading. **/ |
47 | 54 |
int get_max_bom( void ); |
48 | 55 |
/** @brief Turns the BOM on. **/ |
Also available in: Unified diff