Statistics
| Revision:

root / trunk / code / projects / linefollowing / lineFollow.h @ 1931

History | View | Annotate | Download (2.55 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 CENTER                        3
10
#define LINELOST                -1
11

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

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

    
18
/**
19
 * @brief Initializes line following.
20
 * 
21
 * Must be called before line following will work.
22
 * Turns the analog loop off.
23
 */
24
void lineFollow_init(void);
25

    
26
/**        lineFollow
27
 *        Must call lineFollow_init first
28
 *        Must be called inside a loop
29
 */
30
int lineFollow(int speed);
31

    
32
/**        turnLeft turnRight mergeLeft mergeRight
33
 *        Must be called inside a loop
34
 *        returns 0 when complete
35
 */
36
int turnLeft(void);
37
int turnRight(void);
38
int mergeLeft(void);
39
int mergeRight(void);
40

    
41
/**
42
 * @brief Updates the values stored in the array to white or black based on
43
 * current sensor readings.
44
 *
45
 * @param values The array of five integers to be updated. 
46
 */
47
void updateLine(int* values); 
48

    
49
/**
50
 * @brief Returns an index of the middle of the line based on line readings.
51
 *
52
 * Two special return values are possible:
53
 *   NOLINE if none of the sensors holds a black value, and
54
 *   FULL_LINE if all of the sensors see black.
55
 *
56
 * Otherwise, returns a value from -4 (farthest left) to 4 (farthest right), with
57
 * 0 the line being centered in the middle.
58
 *
59
 * @param colors The array of 5 readings from the line sensor.  Must be either
60
 *    LWHITE or LBLACK.
61
 * @return Either a special value or an index from -4 to 4.
62
 *
63
 */
64
int lineLocate(int* colors);
65

    
66
/**        updatebarCode
67
 *        Reads in and processes
68
 *        bar code data
69
 */
70
void updateBarCode(void);
71

    
72
/**
73
 * @brief Gets the completed value read by the barcode reader, or NOBARCODE.
74
 *
75
 * Returns a bar code if available (if at the end of a barcode) and resets the
76
 * barcodePosition to 0. Otherwise, return NOBARCODE.  *
77
 * @return The value of the barcode if a complete barcode, else NOBARCODE.
78
 */
79
int getBarCode(void);
80

    
81

    
82
//! A simple function to return the minimum of two integers.
83
int min(int x, int y);
84
//! A simple function to return the maximum of two integers.
85
int max(int x, int y);
86

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

    
89
/**        motorLeft
90
 *        Commands the left motor
91
 *        Cannot be used to stop
92
 *        0-126 are backward
93
 *        127-255 are forward
94
 */
95
void motorLeft(int speed);
96

    
97
/**        motorRight
98
 *        Commands the right motor
99
 *        Cannot be used to stop
100
 *        0-126 are backward
101
 *        127-255 are forward
102
 */
103
void motorRight(int speed);
104

    
105
/**        lost
106
 *        Internal counter to detect if the line was lost
107
 */
108
int lost;
109

    
110
int onLine(void);
111

    
112
#endif