Revision 641
a first stab at lbom and orb libraries for the new charge bay. it all needs testing.
branches/autonomous_recharging/code/projects/libbayboard/lbom.h | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (c) 2008 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 lbom.h |
|
29 |
* @brief Definitions for using the LBOM |
|
30 |
* |
|
31 |
* This file contains definitions for using the Bearing and |
|
32 |
* Orientation Module (BOM) on the charge bay. |
|
33 |
* |
|
34 |
* @author Colony Project, CMU Robotics Club |
|
35 |
* |
|
36 |
**/ |
|
37 |
|
|
38 |
#ifndef _LBOM_H |
|
39 |
#define _LBOM_H |
|
40 |
|
|
41 |
/** |
|
42 |
* @addtogroup lbom |
|
43 |
* @{ |
|
44 |
**/ |
|
45 |
|
|
46 |
/** @brief Sets up the LBOM to be used. **/ |
|
47 |
void bom_init(char type); |
|
48 |
/** @brief Turns the LBOM on. **/ |
|
49 |
void bom_on(void); |
|
50 |
/** @brief Turns the LBOM off. **/ |
|
51 |
void bom_off(void); |
|
52 |
/** @brief Sets which LEDs are in use. **/ |
|
53 |
void set_leds(int bit_field); |
|
54 |
|
|
55 |
/** @} **/ |
|
56 |
|
|
57 |
#endif |
|
58 |
|
branches/autonomous_recharging/code/projects/libbayboard/orb.c | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (c) 2008 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 |
* @file orb.c |
|
28 |
* @brief Orbs |
|
29 |
* |
|
30 |
* Implemenation for the orbs (tri-colored LEDs) |
|
31 |
* |
|
32 |
* @author Colony Project, CMU Robotics Club |
|
33 |
**/ |
|
34 |
|
|
35 |
#include <avr/io.h> |
|
36 |
#include "orb.h" |
|
37 |
|
|
38 |
|
|
39 |
int main (void){ |
|
40 |
orb_init(); |
|
41 |
set_orb(0, 0, 200); |
|
42 |
while(1); |
|
43 |
return 0; |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* @defgroup orbs Orbs |
|
48 |
* @brief Functions for controlling the color of the orbs. |
|
49 |
* |
|
50 |
* Functions for controlling the color and lighting of the orbs. |
|
51 |
* |
|
52 |
* @{ |
|
53 |
**/ |
|
54 |
|
|
55 |
/** |
|
56 |
* Initializes the PWM for Orb control. This must be called before |
|
57 |
* the orbs are used for them to function. |
|
58 |
**/ |
|
59 |
int orb_init (void) |
|
60 |
{ |
|
61 |
/*data direction registers, blue, green (bit 6) and red (bit 4)*/ |
|
62 |
//DDRB = _BV(DDB4); |
|
63 |
DDRB = 0b00010000; |
|
64 |
|
|
65 |
//DDRD = _BV(DDD4)|_BV(DDD6); |
|
66 |
DDRD = 0b01010000; |
|
67 |
|
|
68 |
|
|
69 |
/*blue is here. it goes on timer 0*/ |
|
70 |
/*timer counter control registers for timer 0*/ |
|
71 |
//TCCR0A = _BV(COM0B1)|_BV(COM0B0)|_BV(WGM01)|_BV(WGM00); |
|
72 |
TCCR0A = 0b00110011; |
|
73 |
|
|
74 |
//TCCR0B = _BV(CS00); |
|
75 |
TCCR0B = 0b00000001; |
|
76 |
OCR0B = 0; |
|
77 |
|
|
78 |
/*green is here. it goes on timer 2*/ |
|
79 |
//TCCR2A = _BV(COM2B1)|_BV(COM2B0)|_BV(WGM21)|_BV(WGM20); |
|
80 |
TCCR2A = 0b00110011; |
|
81 |
|
|
82 |
//TCCR2B = _BV(CS20); |
|
83 |
TCCR2B = 0b00000001; |
|
84 |
OCR2B = 0; |
|
85 |
|
|
86 |
|
|
87 |
/*red is here. it goes on timer 1 which counts to the value in ICR1 instead of 8 bits*/ |
|
88 |
//TCCR1A = _BV(COM1B1)|_BV(COM1B0)|_BV(WGM11); |
|
89 |
TCCR1A = 0b00110001; |
|
90 |
|
|
91 |
//TCCR1B = _BV(WGM13)|_BV(WGM12)|_BV(CS10); |
|
92 |
TCCR1B = 0b00011001; |
|
93 |
ICR1 = 0x9C40; |
|
94 |
OCR1B = 0; |
|
95 |
|
|
96 |
return 0; |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* Set both orbs to the color specified. orb_init must |
|
101 |
* be called before this function may be used. |
|
102 |
* |
|
103 |
* @param red the red component of the color |
|
104 |
* @param green the green component of the color |
|
105 |
* @param blue the blue component of the color |
|
106 |
* |
|
107 |
* @see orb_init |
|
108 |
**/ |
|
109 |
|
|
110 |
int set_orb(int red, int green, int blue){ |
|
111 |
/*blue is here. it goes on timer 0*/ |
|
112 |
blue = blue%256; |
|
113 |
OCR0B = blue; |
|
114 |
|
|
115 |
/*green is here. it goes on timer 2*/ |
|
116 |
green = green%256; |
|
117 |
OCR2B = green; |
|
118 |
|
|
119 |
|
|
120 |
/*red is here. it goes on timer 1*/ |
|
121 |
red = red%256; |
|
122 |
red *= 0x9C40; |
|
123 |
red = (int)(red/256); |
|
124 |
OCR1B = red; |
|
125 |
|
|
126 |
return 0; |
|
127 |
} |
|
128 |
|
|
129 |
/** @} **/ //end group |
branches/autonomous_recharging/code/projects/libbayboard/orb.h | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (c) 2008 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 |
* @file orb.h |
|
28 |
* @brief Contains declarations for managing the orbs. |
|
29 |
* |
|
30 |
* Contains declarations for using the orbs and PWM. |
|
31 |
* |
|
32 |
* @author Colony Project, CMU Robotics Club |
|
33 |
**/ |
|
34 |
|
|
35 |
#ifndef _ORB_H_ |
|
36 |
#define _ORB_H_ |
|
37 |
|
|
38 |
/** |
|
39 |
* @addtogroup orbs |
|
40 |
* @{ |
|
41 |
**/ |
|
42 |
|
|
43 |
/** @brief Enables the orbs **/ |
|
44 |
int orb_init(void); |
|
45 |
/** @brief Set both orbs to a specified color **/ |
|
46 |
int set_orb (int red, int green, int blue); |
|
47 |
/** @brief Set orb1 to a specified color **/ |
|
48 |
|
|
49 |
/** @} **/ //end addtogroup |
|
50 |
|
|
51 |
#endif |
branches/autonomous_recharging/code/projects/libbayboard/lbom.c | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (c) 2008 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 lbom.c |
|
29 |
* @brief Implementation for using the LBOM |
|
30 |
* |
|
31 |
* Contains functions for using the Bearing and Orientation Module (BOM) |
|
32 |
* on the charging station. |
|
33 |
* |
|
34 |
* @author Colony Project, CMU Robotics Club |
|
35 |
**/ |
|
36 |
|
|
37 |
#include <avr/io.h> |
|
38 |
#include "lbom.h" |
|
39 |
|
|
40 |
#define ALL_ON 0b1111 |
|
41 |
#define BOM 0 |
|
42 |
#define BOM1_5 1 |
|
43 |
#define RBOM 2 |
|
44 |
#define BOM0 DDC4 |
|
45 |
#define BOM1 DDC5 |
|
46 |
#define BOM2 DDC6 |
|
47 |
#define BOM3 DDC7 |
|
48 |
|
|
49 |
static char bom_mode; |
|
50 |
|
|
51 |
/** |
|
52 |
* @defgroup lbom LBOM (Bearing and Orientation Module) |
|
53 |
* @brief Functions for dealing with the BOM. |
|
54 |
* |
|
55 |
* The Bearing and Orientation Module / Barrel of Monkeys / BOM |
|
56 |
* is a custom sensor designed and built by the Colony Project. |
|
57 |
* It consists of a ring of 16 IR emitters and 16 IR detectors. |
|
58 |
* The BOM is most often use to determine the direction of other |
|
59 |
* robots. This module contains functions for controlling the BOM. |
|
60 |
* |
|
61 |
* Include bom.h to access these functions. |
|
62 |
* |
|
63 |
* @{ |
|
64 |
**/ |
|
65 |
|
|
66 |
/** @brief Sets up the LBOM to be used. **/ |
|
67 |
void bom_init(char type){ |
|
68 |
set_leds(ALL_ON); |
|
69 |
DDRD |= _BV(DDD7); //sets bom carrier to write |
|
70 |
bom_mode = type; |
|
71 |
bom_on(); |
|
72 |
} |
|
73 |
/** @brief Turns the LBOM on. **/ |
|
74 |
void bom_on(void){ |
|
75 |
//start timer 2 if not already started |
|
76 |
TCCR2A = _BV(COM2A1)|_BV(COM2A0)|_BV(WGM21)|_BV(WGM20); |
|
77 |
TCCR2B = _BV(CS20); |
|
78 |
switch(bom_mode){ |
|
79 |
case BOM: |
|
80 |
OCR2A = 255; |
|
81 |
case BOM1_5: |
|
82 |
OCR2A = 255; |
|
83 |
case RBOM: |
|
84 |
OCR2A = 127; |
|
85 |
default: |
|
86 |
OCR2A = 255; |
|
87 |
} |
|
88 |
} |
|
89 |
/** @brief Turns the LBOM off. **/ |
|
90 |
void bom_off(void){ |
|
91 |
OCR2A = 0; |
|
92 |
} |
|
93 |
/** @brief Sets which LEDs are in use. **/ |
|
94 |
void set_leds(int bit_field){ |
|
95 |
DDRC |= (bitfield << 4); |
|
96 |
} |
|
97 |
|
|
98 |
/** @} **/ //end group |
Also available in: Unified diff