Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (2.39 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 NOLINE                        -42     //! Magic number?
11
#define LINELOST                -1
12

    
13
#define NOBARCODE                 -2
14
#define INTERSECTION                 -25 //! Magic number?
15
#define FULL_LINE                 -26     //! Magic number?
16

    
17

    
18

    
19
/*         lineFollow_init
20
        Must call before lineFollow
21
        Turns analog loop off
22
*/ 
23
void lineFollow_init(void);
24

    
25
/*        lineFollow
26
        Must call lineFollow first
27
        Must be called inside a loop
28
*/
29
int lineFollow(int speed);
30

    
31
/*        turnLeft turnRight mergeLeft mergeRight
32
        Must be called inside a loop
33
        returns 0 when complete
34
*/
35
int turnLeft(void);
36
int turnRight(void);
37
int mergeLeft(void);
38
int mergeRight(void);
39

    
40
/**
41
 * @brief Updates the values stored in the array to white or black based on
42
 * current sensor readings.
43
 *
44
 * @param values The array of five integers to be updated. 
45
 **/
46
void updateLine(int* values); 
47

    
48
/**
49
 * @brief Returns an index of the middle of the line based on line readings.
50
 *
51
 * Two special return values are possible:
52
 *   NOLINE if none of the sensors holds a black value, and
53
 *   FULL_LINE if all of the sensors see black.
54
 *
55
 * Otherwise, returns a value from -4 (farthest left) to 4 (farthest right), with
56
 * 0 the line being centered in the middle.
57
 *
58
 * @param colors The array of 5 readings from the line sensor.  Must be either
59
 *    LWHITE or LBLACK.
60
 * @return Either a special value or an index from -4 to 4.
61
 *
62
 **/
63
int lineLocate(int* colors);
64

    
65
/*        updatebarCode
66
        Reads in and processes
67
        bar code data
68
*/
69
void updateBarCode(void);
70

    
71
/**
72
 * @brief Gets the completed value read by the barcode reader, or NOBARCODE.
73
 *
74
 * Returns a bar code if available (if at the end of a barcode) and resets the
75
 * barcodePosition to 0. Otherwise, return NOBARCODE.  *
76
 * @return The value of the barcode if a complete barcode, else NOBARCODE.
77
 **/
78
int getBarCode(void);
79

    
80

    
81
//! A simple function to return the minimum of two integers.
82
int min(int x, int y);
83
//! A simple function to return the maximum of two integers.
84
int max(int x, int y);
85

    
86
/*        motorLeft
87
        Commands the left motor
88
        Cannot be used to stop
89
        0-126 are backward
90
        127-255 are forward
91
*/
92
void motorLeft(int speed);
93

    
94
/*        motorRight
95
        Commands the right motor
96
        Cannot be used to stop
97
        0-126 are backward
98
        127-255 are forward
99
*/
100
void motorRight(int speed);
101

    
102
/*        lost
103
        Internal counter to detect if the line was lost
104
*/
105
int lost;
106

    
107
int onLine(void);
108

    
109
#endif