root / branches / autonomous_recharging / code / projects / libbayboard / lbom.c @ 725
History | View | Annotate | Download (2.8 KB)
1 | 641 | emullini | /**
|
---|---|---|---|
2 | * Copyright (c) 2008 Colony Project
|
||
3 | 725 | gtress | *
|
4 | 641 | emullini | * 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 | 725 | gtress | *
|
13 | 641 | emullini | * The above copyright notice and this permission notice shall be
|
14 | * included in all copies or substantial portions of the Software.
|
||
15 | 725 | gtress | *
|
16 | 641 | emullini | * 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 | 725 | gtress | |
37 | 641 | emullini | #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 | 709 | emullini | * It consists of 4 IR emitters.
|
58 | 641 | emullini | * 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 | 709 | emullini | //set_leds(ALL_ON);
|
69 | DDRC |= _BV(BOM0)|_BV(BOM1)|_BV(BOM2)|_BV(BOM3); |
||
70 | 716 | emullini | PORTC |= 0b11110000;
|
71 | DDRD |= _BV(DDD7); //sets bom carrier to write
|
||
72 | 641 | emullini | bom_mode = type; |
73 | 716 | emullini | bom_on(type); |
74 | 641 | emullini | } |
75 | /** @brief Turns the LBOM on. **/
|
||
76 | 725 | gtress | void bom_on(void){ |
77 | 641 | emullini | //start timer 2 if not already started
|
78 | 716 | emullini | TCCR2A = _BV(COM2A1)|_BV(COM2A0)|_BV(WGM21)|_BV(WGM20); |
79 | 641 | emullini | TCCR2B = _BV(CS20); |
80 | switch(bom_mode){
|
||
81 | case BOM:
|
||
82 | 716 | emullini | OCR2A = 1;
|
83 | 641 | emullini | case BOM1_5:
|
84 | 716 | emullini | OCR2A = 1;
|
85 | 641 | emullini | case RBOM:
|
86 | OCR2A = 127;
|
||
87 | default:
|
||
88 | 716 | emullini | OCR2A = 1;
|
89 | 641 | emullini | } |
90 | } |
||
91 | /** @brief Turns the LBOM off. **/
|
||
92 | void bom_off(void){ |
||
93 | OCR2A = 0;
|
||
94 | } |
||
95 | 709 | emullini | /** @brief Sets which emitters are in use. **/
|
96 | 641 | emullini | void set_leds(int bit_field){ |
97 | 649 | abuchan | DDRC |= (bit_field << 4);
|
98 | 641 | emullini | } |
99 | |||
100 | /** @} **/ //end group |