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