Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (2.66 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 to establish a significant
19
// reading.
20
#define MAX_DURATION    20
21

    
22
/**
23
 * @brief Initializes line following.
24
 * 
25
 * Must be called before line following will work.
26
 * Turns the analog loop off.
27
 */
28
void lineFollow_init(void);
29

    
30
/**        lineFollow
31
 *        Must call lineFollow_init first
32
 *        Must be called inside a loop
33
 */
34
int lineFollow(int speed);
35

    
36
/**        turnLeft turnRight mergeLeft mergeRight
37
 *        Must be called inside a loop
38
 *        returns 0 when complete
39
 */
40
int turnLeft(void);
41
int turnRight(void);
42
int mergeLeft(void);
43
int mergeRight(void);
44

    
45
/**
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
void updateLine(int* values); 
52

    
53
/**
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
int lineLocate(int* colors);
69

    
70
/**        updatebarCode
71
 *        Reads in and processes
72
 *        bar code data
73
 */
74
void updateBarCode(void);
75

    
76
/**
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
int getBarCode(void);
84

    
85

    
86
//! A simple function to return the minimum of two integers.
87
int min(int x, int y);
88
//! A simple function to return the maximum of two integers.
89
int max(int x, int y);
90

    
91
/** @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
void motorLeft(int speed);
100

    
101
/**        motorRight
102
 *        Commands the right motor
103
 *        Cannot be used to stop
104
 *        0-126 are backward
105
 *        127-255 are forward
106
 */
107
void motorRight(int speed);
108

    
109
/**        lost
110
 *        Internal counter to detect if the line was lost
111
 */
112
int lost;
113

    
114
int onLine(void);
115

    
116
#endif