Project

General

Profile

Statistics
| Revision:

root / branches / autonomous_recharging / code / projects / libbayboard / homing.c @ 873

History | View | Annotate | Download (3.54 KB)

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
 * Copyright (c) 2008 Colony Project
27
 * 
28
 * Permission is hereby granted, free of charge, to any person
29
 * obtaining a copy of this software and associated documentation
30
 * files (the "Software"), to deal in the Software without
31
 * restriction, including without limitation the rights to use,
32
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
33
 * copies of the Software, and to permit persons to whom the
34
 * Software is furnished to do so, subject to the following
35
 * conditions:
36
 * 
37
 * The above copyright notice and this permission notice shall be
38
 * included in all copies or substantial portions of the Software.
39
 * 
40
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
41
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
42
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
43
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
44
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
45
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
46
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
47
 * OTHER DEALINGS IN THE SOFTWARE.
48
 **/
49
 
50
 /**
51
 * @file homing.c
52
 * @brief Contains declarations for managing the orbs.
53
 *
54
 * Contains declarations for using the orbs and PWM.
55
 *
56
 * @author Colony Project, CMU Robotics Club
57
 **/
58
//carrier for beacons is on blue timer
59
//manually defined ISRs
60
//high frequency = 200Hz
61
//TIMER1_OVF_vect
62
//enable overflow interrupts
63
#include <avr/interrupt.h>
64
#include <avr/io.h>
65
#include "orb.h"
66
#include "serial.h"
67

    
68
volatile int state = 0;
69
volatile int on = 0;
70

    
71
/**
72
 * @defgroup homing Homing
73
 * @brief Functions for controlling the homing beacons.
74
 * 
75
 * Functions for controlling the homing beacons.
76
 *
77
 * @{
78
 **/
79

    
80
/** @brief Sets up the beacons to be used. **/
81
 
82
void IR_init(void){
83
  
84
  DDRA |= _BV(DDA0)|_BV(DDA1);
85
  DDRB |= _BV(DDB3);
86
  DDRC |= _BV(DDC0)|_BV(DDC1);
87
  
88
  sei();
89

    
90
  TIMSK1 |= _BV(TOIE1);
91

    
92
  TCCR0A |= _BV(COM0A1)|_BV(COM0A0)|_BV(WGM01)|_BV(WGM00);
93
  TCCR0B |= _BV(CS00);
94
  OCR0A = 0x80;
95

    
96
  TCCR1A |= _BV(COM1B1)|_BV(COM1B0)|_BV(WGM11);        
97
  TCCR1B |= _BV(WGM13)|_BV(WGM12)|_BV(CS10);
98
  ICR1 = 0x9C40;
99
  on = 0;
100
  
101
}
102

    
103
/** @brief Turns the beacons on. **/
104

    
105
void IR_on(void){
106
        on = 1;
107
}
108

    
109
/** @brief Turns the beacons off. **/
110

    
111
void IR_off(void){
112
        on = 0;
113
}
114

    
115

    
116
ISR(TIMER1_OVF_vect){
117
  if(on){
118
        if(state == 7)
119
                state = 0;
120
        else
121
                state++;
122
        
123

    
124
        if (state<4)
125
                PORTA ++;
126
        else
127
                PORTA &= 0xFC;
128
  }
129
  else{
130
        PORTA &= 0xFC;
131
  }
132
   
133
}
134

    
135
/** @} **/ //end group