Revision 6fab3966
ID | 6fab3966a8c664beb8621d6ef145904cceef783a |
Fixed the line following code.
Now works with new units
Fixed a bug with reading the line location, correctly centering the line between -3.5 and 3.5 rather than -4 and 3.
Also fixed a bug caused by overflow in absolute speeds sent to motor control, which fixed bouncing in line following.
scout/libscout/src/LinesensorControl.cpp | ||
---|---|---|
85 | 85 |
return last_ret; |
86 | 86 |
} |
87 | 87 |
|
88 |
double ret_val = last_ret = ((double) weighted_total / total_read) - 4;
|
|
88 |
double ret_val = last_ret = ((double) weighted_total / total_read) - 3.5;
|
|
89 | 89 |
return ret_val; |
90 | 90 |
} |
91 | 91 |
|
scout/libscout/src/behaviors/line_follow.cpp | ||
---|---|---|
38 | 38 |
{ |
39 | 39 |
double line_loc = linesensor->readline(); |
40 | 40 |
|
41 |
motor_l = -MOTOR_BASE + SCALE * line_loc; |
|
42 |
motor_r = -MOTOR_BASE - SCALE * line_loc; |
|
41 |
ROS_INFO("Line location: %lf.\n", line_loc); |
|
42 |
|
|
43 |
motor_l = min(max((int) (-MOTOR_BASE + SCALE * line_loc), -128), 127); |
|
44 |
motor_r = min(max((int) (-MOTOR_BASE - SCALE * line_loc), -128), 127); |
|
43 | 45 |
|
44 | 46 |
motors->set_sides(motor_l, motor_r, MOTOR_ABSOLUTE); |
45 | 47 |
} |
scout/libscout/src/behaviors/line_follow.h | ||
---|---|---|
29 | 29 |
#include "../Behavior.h" |
30 | 30 |
#include "../Sensors.h" |
31 | 31 |
|
32 |
#define MOTOR_BASE 50
|
|
33 |
#define SCALE 20
|
|
32 |
#define MOTOR_BASE 60.0f
|
|
33 |
#define SCALE 60.0f
|
|
34 | 34 |
|
35 | 35 |
class line_follow : public Behavior |
36 | 36 |
{ |
Also available in: Unified diff