Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (3.12 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
//! Anything lower than this value is white
25
#define GREY_THRESHOLD 500
26
//! Anything higher than this value is black
27
#define BLACK_THRESHOLD 750
28

    
29
#define NUM_READINGS 20
30

    
31
#define LEFT_SENSOR     1
32
#define RIGHT_SENSOR    0
33

    
34
/**
35
 * @brief Initializes line following.
36
 * 
37
 * Must be called before line following will work.
38
 * Turns the analog loop off.
39
 */
40
void lineFollow_init(void);
41

    
42
/**        lineFollow
43
 *        Must call lineFollow_init first
44
 *        Must be called inside a loop
45
 */
46
int lineFollow(int speed);
47

    
48
/**        turnLeft turnRight mergeLeft mergeRight
49
 *        Must be called inside a loop
50
 *        returns 0 when complete
51
 */
52
int turnLeft(void);
53
int turnRight(void);
54
int mergeLeft(void);
55
int mergeRight(void);
56

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

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

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

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

    
97

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

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

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

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

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

    
126
int onLine(void);
127

    
128
#endif