Revision 58371433
Renaming to line follow and getting rid of old linefollowing files.
scout/libscout/src/behaviors/line_follow.h | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (c) 2011 Colony Project |
|
3 |
* |
|
4 |
* Permission is hereby granted, free of charge, to any person |
|
5 |
* obtaining a copy of this software and associated documentation |
|
6 |
* files (the "Software"), to deal in the Software without |
|
7 |
* restriction, including without limitation the rights to use, |
|
8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
9 |
* copies of the Software, and to permit persons to whom the |
|
10 |
* Software is furnished to do so, subject to the following |
|
11 |
* conditions: |
|
12 |
* |
|
13 |
* The above copyright notice and this permission notice shall be |
|
14 |
* included in all copies or substantial portions of the Software. |
|
15 |
* |
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
23 |
* OTHER DEALINGS IN THE SOFTWARE. |
|
24 |
*/ |
|
1 | 25 |
|
2 | 26 |
#ifndef _LINE_FOLLOW_H_ |
3 | 27 |
#define _LINE_FOLLOW_H_ |
4 | 28 |
|
5 | 29 |
#include "../Behavior.h" |
6 | 30 |
|
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 |
|
|
31 |
#define MOTOR_BASE 50 |
|
32 |
#define SCALE 20 |
|
32 | 33 |
|
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 |
|
34 |
class line_follow : Behavior |
|
40 | 35 |
{ |
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); |
|
36 |
public: |
|
37 |
line_follow(std::string scoutname) : Behavior(scoutname, "line_follow") {}; |
|
65 | 38 |
|
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); |
|
39 |
/** Actually executes the behavior. */ |
|
40 |
void run(); |
|
100 | 41 |
|
101 | 42 |
private: |
102 |
/** lost
|
|
103 |
* Internal counter to detect if the line was lost
|
|
104 |
*/
|
|
105 |
int lost;
|
|
43 |
void turn_left();
|
|
44 |
void turn_right();
|
|
45 |
void follow_line();
|
|
46 |
void halt();
|
|
106 | 47 |
}; |
48 |
|
|
107 | 49 |
#endif |
Also available in: Unified diff