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