Project

General

Profile

Statistics
| Revision:

root / branches / autonomous_recharging / code / projects / libbayboard / lbom.c @ 882

History | View | Annotate | Download (2.76 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 793 bcoltin
#include "bom.h"
39 641 emullini
40
static char bom_mode;
41 728 abuchan
static char led_mask;
42 641 emullini
43
/**
44
 * @defgroup lbom LBOM (Bearing and Orientation Module)
45
 * @brief Functions for dealing with the BOM.
46
 *
47
 * The Bearing and Orientation Module / Barrel of Monkeys / BOM
48
 * is a custom sensor designed and built by the Colony Project.
49 709 emullini
 * It consists of 4 IR emitters.
50 641 emullini
 * The BOM is most often use to determine the direction of other
51
 * robots. This module contains functions for controlling the BOM.
52
 *
53 785 emullini
 * Include lbom.h to access these functions.
54 641 emullini
 *
55
 * @{
56
 **/
57
58
/** @brief Sets up the LBOM to be used. **/
59
void bom_init(char type){
60 728 abuchan
        set_leds(BOM_ALL_ON);
61 709 emullini
        DDRC |= _BV(BOM0)|_BV(BOM1)|_BV(BOM2)|_BV(BOM3);
62 716 emullini
        DDRD |= _BV(DDD7);                        //sets bom carrier to write
63 729 abuchan
64 641 emullini
        bom_mode = type;
65 728 abuchan
        switch(bom_mode){
66
        case RBOM:
67
                //set the carrier to produce a 31kHz 50% duty cycle signal
68
                TCCR2A = _BV(COM2A1)|_BV(COM2A0)|_BV(WGM21)|_BV(WGM20);
69
                TCCR2B = _BV(CS20);
70
                OCR2A = 127;
71 641 emullini
        case BOM:
72
        case BOM1_5:
73
        default:
74 728 abuchan
                PORTD |= _BV(PD7);
75 641 emullini
        }
76
}
77 729 abuchan
/** @brief Turns the enabled LBOM LEDS on. **/
78 728 abuchan
void bom_on(void){
79
        PORTC |= led_mask;
80
}
81 729 abuchan
82
/** @brief Turns all LBOM LEDS off. **/
83 641 emullini
void bom_off(void){
84 729 abuchan
        PORTC &= ~(BOM_ALL_ON<<4);
85 641 emullini
}
86 729 abuchan
87
/** @brief Sets which emitters are enabled **/
88 641 emullini
void set_leds(int bit_field){
89 728 abuchan
        led_mask = ((bit_field&BOM_ALL_ON) << 4);
90 641 emullini
}
91
92 793 bcoltin
int get_max_bom(void)
93
{
94
        return -1;
95
}
96
97 641 emullini
/** @} **/ //end group