Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (2.9 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
//! Number of consecutive barcode color readings for a significant reading.
19
#define MAX_DURATION    20
20
//! Number of consecutive white barcode readings before a barcode reset.
21
#define TIMEOUT_DURATION    1000
22
//! Anything lower than this value is white
23
#define GREY_THRESHOLD 100
24
//! Anything higher than this value is black
25
#define BLACK_THRESHOLD 350
26

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

    
35
/**        lineFollow
36
 *        Must call lineFollow_init first
37
 *        Must be called inside a loop
38
 */
39
int lineFollow(int speed);
40

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

    
50
/**
51
 * @brief Updates the values stored in the array to white or black based on
52
 * current sensor readings.
53
 *
54
 * @param values The array of five integers to be updated. 
55
 */
56
void updateLine(int* values); 
57

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

    
75
/**        updatebarCode
76
 *        Reads in and processes
77
 *        bar code data
78
 */
79
void updateBarCode(void);
80

    
81
/**
82
 * @brief Gets the completed value read by the barcode reader, or NOBARCODE.
83
 *
84
 * Returns a bar code if available (if at the end of a barcode) and resets the
85
 * barcodePosition to 0. Otherwise, return NOBARCODE.  *
86
 * @return The value of the barcode if a complete barcode, else NOBARCODE.
87
 */
88
int getBarCode(void);
89

    
90

    
91
//! A simple function to return the minimum of two integers.
92
int min(int x, int y);
93
//! A simple function to return the maximum of two integers.
94
int max(int x, int y);
95

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

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

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

    
114
/**        lost
115
 *        Internal counter to detect if the line was lost
116
 */
117
int lost;
118

    
119
int onLine(void);
120

    
121
#endif