root / trunk / code / projects / linefollowing / lineFollow.h @ 1974
History | View | Annotate | Download (3.09 KB)
1 | 1954 | whchang | #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 | 1974 | azirbel | #define GREY_THRESHOLD 250 |
24 | 1954 | whchang | //! Anything higher than this value is black
|
25 | 1974 | azirbel | #define BLACK_THRESHOLD 650 |
26 | 1954 | whchang | |
27 | 1960 | azirbel | #define NUM_READINGS 20 |
28 | 1954 | whchang | |
29 | #define LEFT_SENSOR 1 |
||
30 | #define RIGHT_SENSOR 0 |
||
31 | |||
32 | /**
|
||
33 | * @brief Initializes line following.
|
||
34 | *
|
||
35 | * Must be called before line following will work.
|
||
36 | * Turns the analog loop off.
|
||
37 | */
|
||
38 | void lineFollow_init(void); |
||
39 | |||
40 | /** lineFollow
|
||
41 | * Must call lineFollow_init first
|
||
42 | * Must be called inside a loop
|
||
43 | */
|
||
44 | int lineFollow(int speed); |
||
45 | |||
46 | /** turnLeft turnRight mergeLeft mergeRight
|
||
47 | * Must be called inside a loop
|
||
48 | * returns 0 when complete
|
||
49 | */
|
||
50 | int turnLeft(void); |
||
51 | int turnRight(void); |
||
52 | int mergeLeft(void); |
||
53 | int mergeRight(void); |
||
54 | |||
55 | /**
|
||
56 | * @brief Updates the values stored in the array to white or black based on
|
||
57 | * current sensor readings.
|
||
58 | *
|
||
59 | * @param values The array of five integers to be updated.
|
||
60 | */
|
||
61 | void updateLine(int* values); |
||
62 | |||
63 | /**
|
||
64 | * @brief Returns an index of the middle of the line based on line readings.
|
||
65 | *
|
||
66 | * Two special return values are possible:
|
||
67 | * NOLINE if none of the sensors holds a black value, and
|
||
68 | * FULL_LINE if all of the sensors see black.
|
||
69 | *
|
||
70 | * Otherwise, returns a value from -4 (farthest left) to 4 (farthest right), with
|
||
71 | * 0 the line being centered in the middle.
|
||
72 | *
|
||
73 | * @param colors The array of 5 readings from the line sensor. Must be either
|
||
74 | * LWHITE or LBLACK.
|
||
75 | * @return Either a special value or an index from -4 to 4.
|
||
76 | *
|
||
77 | */
|
||
78 | int lineLocate(int* colors); |
||
79 | |||
80 | /** updatebarCode
|
||
81 | * Reads in and processes
|
||
82 | * bar code data
|
||
83 | */
|
||
84 | void updateBarCode(void); |
||
85 | |||
86 | /**
|
||
87 | * @brief Gets the completed value read by the barcode reader, or NOBARCODE.
|
||
88 | *
|
||
89 | * Returns a bar code if available (if at the end of a barcode) and resets the
|
||
90 | * barcodePosition to 0. Otherwise, return NOBARCODE. *
|
||
91 | * @return The value of the barcode if a complete barcode, else NOBARCODE.
|
||
92 | */
|
||
93 | int getBarCode(void); |
||
94 | |||
95 | |||
96 | //! A simple function to return the minimum of two integers.
|
||
97 | int min(int x, int y); |
||
98 | //! A simple function to return the maximum of two integers.
|
||
99 | int max(int x, int y); |
||
100 | |||
101 | /** @todo Alex: I hate these functions, but I'm keeping them so code will still work. But we should delete them sometime. */
|
||
102 | |||
103 | /** motorLeft
|
||
104 | * Commands the left motor
|
||
105 | * Cannot be used to stop
|
||
106 | * 0-126 are backward
|
||
107 | * 127-255 are forward
|
||
108 | */
|
||
109 | void motorLeft(int speed); |
||
110 | |||
111 | /** motorRight
|
||
112 | * Commands the right motor
|
||
113 | * Cannot be used to stop
|
||
114 | * 0-126 are backward
|
||
115 | * 127-255 are forward
|
||
116 | */
|
||
117 | void motorRight(int speed); |
||
118 | |||
119 | /** lost
|
||
120 | * Internal counter to detect if the line was lost
|
||
121 | */
|
||
122 | int lost;
|
||
123 | |||
124 | int onLine(void); |
||
125 | |||
126 | #endif |