Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / activities_fair_demo / lineFollow.h @ 2001

History | View | Annotate | Download (3.04 KB)

1
#include <dragonfly_lib.h>
2

    
3
#ifndef _LINEFOLLOW_H_
4
#define _LINEFOLLOW_H_
5

    
6
#define LWHITE                        0
7
#define LGREY                        1
8
#define LBLACK                         2
9
#define BAD_READING     3
10
#define CENTER                        3
11
#define LINELOST                -1
12

    
13
#define NOBARCODE                 -2
14
#define INTERSECTION         -25
15

    
16
#define NOLINE                        -50
17
#define FULL_LINE                 -51
18

    
19

    
20
//! Number of consecutive barcode color readings for a significant reading.
21
#define MAX_DURATION    20
22
//! Number of consecutive white barcode readings before a barcode reset.
23
#define TIMEOUT_DURATION    1000
24

    
25
#define NUM_READINGS 20
26

    
27
#define LEFT_SENSOR     1
28
#define RIGHT_SENSOR    0
29

    
30
/**
31
 * @brief Initializes line following.
32
 * 
33
 * Must be called before line following will work.
34
 * Turns the analog loop off.
35
 */
36
void lineFollow_init(void);
37

    
38
/**        lineFollow
39
 *        Must call lineFollow_init first
40
 *        Must be called inside a loop
41
 */
42
int lineFollow(int speed);
43

    
44
/**        turnLeft turnRight mergeLeft mergeRight
45
 *        Must be called inside a loop
46
 *        returns 0 when complete
47
 */
48
int turnLeft(void);
49
int turnRight(void);
50
int mergeLeft(void);
51
int mergeRight(void);
52

    
53
void addToBuckets(int curColor, int i);
54
void printBuckets();
55

    
56
/**
57
 * @brief Updates the values stored in the array to white or black based on
58
 * current sensor readings.
59
 *
60
 * @param values The array of five integers to be updated. 
61
 */
62
void updateLine(int* values); 
63

    
64
/**
65
 * @brief Returns an index of the middle of the line based on line readings.
66
 *
67
 * Two special return values are possible:
68
 *   NOLINE if none of the sensors holds a black value, and
69
 *   FULL_LINE if all of the sensors see black.
70
 *
71
 * Otherwise, returns a value from -4 (farthest left) to 4 (farthest right), with
72
 * 0 the line being centered in the middle.
73
 *
74
 * @param colors The array of 5 readings from the line sensor.  Must be either
75
 *    LWHITE or LBLACK.
76
 * @return Either a special value or an index from -4 to 4.
77
 *
78
 */
79
int lineLocate(int* colors);
80

    
81
/**        updatebarCode
82
 *        Reads in and processes
83
 *        bar code data
84
 */
85
void updateBarCode(void);
86

    
87
/**
88
 * @brief Gets the completed value read by the barcode reader, or NOBARCODE.
89
 *
90
 * Returns a bar code if available (if at the end of a barcode) and resets the
91
 * barcodePosition to 0. Otherwise, return NOBARCODE.  *
92
 * @return The value of the barcode if a complete barcode, else NOBARCODE.
93
 */
94
int getBarCode(void);
95

    
96

    
97
//! A simple function to return the minimum of two integers.
98
int min(int x, int y);
99
//! A simple function to return the maximum of two integers.
100
int max(int x, int y);
101

    
102
/** @todo Alex: I hate these functions, but I'm keeping them so code will still work. But we should delete them sometime. */
103

    
104
/**        motorLeft
105
 *        Commands the left motor
106
 *        Cannot be used to stop
107
 *        0-126 are backward
108
 *        127-255 are forward
109
 */
110
void motorLeft(int speed);
111

    
112
/**        motorRight
113
 *        Commands the right motor
114
 *        Cannot be used to stop
115
 *        0-126 are backward
116
 *        127-255 are forward
117
 */
118
void motorRight(int speed);
119

    
120
/**        lost
121
 *        Internal counter to detect if the line was lost
122
 */
123
int lost;
124

    
125
int onLine(void);
126

    
127
#endif