root / branches / autonomous_recharging / code / projects / autonomous_recharging / dragonfly / homing.c @ 820
History | View | Annotate | Download (1.16 KB)
1 |
/**
|
---|---|
2 |
* @file homing.c
|
3 |
* @brief Interpret homing beacon data
|
4 |
*
|
5 |
* Contains functions for translating homing data into directions.
|
6 |
*
|
7 |
* @author Colony Project, CMU Robotics Club
|
8 |
**/
|
9 |
|
10 |
#include "homing.h" |
11 |
#include "recharge_defs.h" |
12 |
|
13 |
#include <serial.h> |
14 |
|
15 |
// values for homing sensor readings
|
16 |
#define LEFT_LOW 6 |
17 |
#define LEFT_HIGH 8 |
18 |
#define CENTER_LOW 17 |
19 |
#define CENTER_HIGH 19 |
20 |
#define RIGHT_LOW 11 |
21 |
#define RIGHT_HIGH 13 |
22 |
|
23 |
/**
|
24 |
* translates homing sensor data into the
|
25 |
* direction the robot needs to turn
|
26 |
* (or if it needs to use the BOM).
|
27 |
*
|
28 |
* @return returns direction flag
|
29 |
**/
|
30 |
int homing_direction(int beaconcount) |
31 |
{ |
32 |
if (beaconcount < LEFT_LOW) //can't use beacon, switch to BOM |
33 |
return HOMING_NONE;
|
34 |
else if(beaconcount >= CENTER_LOW) |
35 |
return HOMING_FORWARD;
|
36 |
else
|
37 |
{ |
38 |
if(beaconcount >= LEFT_LOW && beaconcount <= LEFT_HIGH)
|
39 |
return HOMING_LEFT;
|
40 |
else if (beaconcount >= RIGHT_LOW && beaconcount <= RIGHT_HIGH) |
41 |
return HOMING_RIGHT;
|
42 |
else
|
43 |
{ |
44 |
RECHARGE_DEBUG_PRINT("Unexpected homing sensor value of ");
|
45 |
RECHARGE_DEBUG_PUTI(beaconcount); |
46 |
RECHARGE_DEBUG_PRINT(".\n");
|
47 |
} |
48 |
} |
49 |
return HOMING_NONE;
|
50 |
} |