Project

General

Profile

Statistics
| Branch: | Revision:

root / scout / libscout / src / behaviors / lineFollow.h @ 9143e077

History | View | Annotate | Download (2.23 KB)

1

    
2
#ifndef _LINEFOLLOW_H_
3
#define _LINEFOLLOW_H_
4

    
5
#include "../Behavior.h"
6

    
7
#define LWHITE                        0
8
#define LGREY                        1
9
#define LBLACK                         2
10
#define BAD_READING     3
11
#define CENTER                        3
12
#define LINELOST                -1
13

    
14
#define INTERSECTION         -25
15

    
16
#define NOLINE                        -50
17
#define FULL_LINE                 -51
18

    
19
#define NUM_READINGS 20
20

    
21
#define LEFT_SENSOR     1
22
#define RIGHT_SENSOR    0
23

    
24
class lineFollow : Behavior
25
{
26
        public:
27
                lineFollow(std::string scoutname) : Behavior(scoutname) {};
28
        /** Actually executes the behavior. */
29
                void init();
30
};
31

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

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

    
45
void addToBuckets(int curColor, int i);
46
void printBuckets();
47

    
48
/**
49
 * @brief Updates the values stored in the array to white or black based on
50
 * current sensor readings.
51
 *
52
 * @param values The array of five integers to be updated. 
53
 */
54
void updateLine(int* values); 
55

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

    
73

    
74
//! A simple function to return the minimum of two integers.
75
int min(int x, int y);
76
//! A simple function to return the maximum of two integers.
77
int max(int x, int y);
78

    
79
/** @todo Alex: I hate these functions, but I'm keeping them so code will still work. But we should delete them sometime. */
80

    
81
/**        motorLeft
82
 *        Commands the left motor
83
 *        Cannot be used to stop
84
 *        0-126 are backward
85
 *        127-255 are forward
86
 */
87
void motorLeft(int speed);
88

    
89
/**        motorRight
90
 *        Commands the right motor
91
 *        Cannot be used to stop
92
 *        0-126 are backward
93
 *        127-255 are forward
94
 */
95
void motorRight(int speed);
96

    
97
/**        lost
98
 *        Internal counter to detect if the line was lost
99
 */
100
int lost;
101

    
102
int onLine(void);
103

    
104
#endif