Project

General

Profile

Statistics
| Branch: | Revision:

scoutos / scout / libscout / src / behaviors / line_follow.h @ 60b98383

History | View | Annotate | Download (2.44 KB)

1

    
2
#ifndef _LINE_FOLLOW_H_
3
#define _LINE_FOLLOW_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
/**
25
 * Helps with debugging.
26
 * 0 - no debug output.
27
 * 1 - print out buckets
28
 * 2 - print out line sensor readings
29
 */
30
#define DBG_LINEFOLLOW 2
31

    
32

    
33
//! A simple function to return the minimum of two integers.
34
int min(int x, int y);
35
//! A simple function to return the maximum of two integers.
36
int max(int x, int y);
37

    
38

    
39
class line_follow 
40
{
41
        public:
42
    /** Actually executes the behavior. */
43
                void init();
44

    
45
    /**        line_follow
46
     *        Must call line_follow_init first
47
     *        Must be called inside a loop
48
     */
49
    int follow_line(int speed);
50

    
51
    /**        turnLeft turnRight
52
     *        Must be called inside a loop
53
     *        returns 0 when complete
54
     */
55
    int turnLeft(void);
56
    int turnRight(void);
57

    
58
    /**
59
     * @brief Updates the values stored in the array to white or black based on
60
     * current sensor readings.
61
     *
62
     * @param values The array of five integers to be updated. 
63
     */
64
    void updateLine(int* values); 
65

    
66
    /**
67
     * @brief Returns an index of the middle of the line based on line readings.
68
     *
69
     * Two special return values are possible:
70
     *   NOLINE if none of the sensors holds a black value, and
71
     *   FULL_LINE if all of the sensors see black.
72
     *
73
     * Otherwise, returns a value from -4 (farthest left) to 4 (farthest right), with
74
     * 0 the line being centered in the middle.
75
     *
76
     * @param colors The array of 5 readings from the line sensor.  Must be either
77
     *    LWHITE or LBLACK.
78
     * @return Either a special value or an index from -4 to 4.
79
     *
80
     */
81
    int lineLocate(int* colors);
82

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

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

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

    
101
    private:
102
    /**        lost
103
     *        Internal counter to detect if the line was lost
104
     */
105
    int lost;
106
};
107
#endif