Revision 1953
trunk/code/projects/linefollowing/lineFollow.h | ||
---|---|---|
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 400 |
|
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 |
/** |
|
54 |
* @brief Updates the values stored in the array to white or black based on |
|
55 |
* current sensor readings. |
|
56 |
* |
|
57 |
* @param values The array of five integers to be updated. |
|
58 |
*/ |
|
59 |
void updateLine(int* values); |
|
60 |
|
|
61 |
/** |
|
62 |
* @brief Returns an index of the middle of the line based on line readings. |
|
63 |
* |
|
64 |
* Two special return values are possible: |
|
65 |
* NOLINE if none of the sensors holds a black value, and |
|
66 |
* FULL_LINE if all of the sensors see black. |
|
67 |
* |
|
68 |
* Otherwise, returns a value from -4 (farthest left) to 4 (farthest right), with |
|
69 |
* 0 the line being centered in the middle. |
|
70 |
* |
|
71 |
* @param colors The array of 5 readings from the line sensor. Must be either |
|
72 |
* LWHITE or LBLACK. |
|
73 |
* @return Either a special value or an index from -4 to 4. |
|
74 |
* |
|
75 |
*/ |
|
76 |
int lineLocate(int* colors); |
|
77 |
|
|
78 |
/** updatebarCode |
|
79 |
* Reads in and processes |
|
80 |
* bar code data |
|
81 |
*/ |
|
82 |
void updateBarCode(void); |
|
83 |
|
|
84 |
/** |
|
85 |
* @brief Gets the completed value read by the barcode reader, or NOBARCODE. |
|
86 |
* |
|
87 |
* Returns a bar code if available (if at the end of a barcode) and resets the |
|
88 |
* barcodePosition to 0. Otherwise, return NOBARCODE. * |
|
89 |
* @return The value of the barcode if a complete barcode, else NOBARCODE. |
|
90 |
*/ |
|
91 |
int getBarCode(void); |
|
92 |
|
|
93 |
|
|
94 |
//! A simple function to return the minimum of two integers. |
|
95 |
int min(int x, int y); |
|
96 |
//! A simple function to return the maximum of two integers. |
|
97 |
int max(int x, int y); |
|
98 |
|
|
99 |
/** @todo Alex: I hate these functions, but I'm keeping them so code will still work. But we should delete them sometime. */ |
|
100 |
|
|
101 |
/** motorLeft |
|
102 |
* Commands the left motor |
|
103 |
* Cannot be used to stop |
|
104 |
* 0-126 are backward |
|
105 |
* 127-255 are forward |
|
106 |
*/ |
|
107 |
void motorLeft(int speed); |
|
108 |
|
|
109 |
/** motorRight |
|
110 |
* Commands the right motor |
|
111 |
* Cannot be used to stop |
|
112 |
* 0-126 are backward |
|
113 |
* 127-255 are forward |
|
114 |
*/ |
|
115 |
void motorRight(int speed); |
|
116 |
|
|
117 |
/** lost |
|
118 |
* Internal counter to detect if the line was lost |
|
119 |
*/ |
|
120 |
int lost; |
|
121 |
|
|
122 |
int onLine(void); |
|
123 |
|
|
124 |
#endif |
Also available in: Unified diff