A simple line following program
Revision 1:5ddd3faed06d, committed 2010-11-01
- Comitter:
- chris
- Date:
- Mon Nov 01 23:21:14 2010 +0000
- Parent:
- 0:eb1ece444e15
- Child:
- 2:f3f0843285e2
- Commit message:
- Tidied up
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Nov 01 23:16:57 2010 +0000
+++ b/main.cpp Mon Nov 01 23:21:14 2010 +0000
@@ -15,40 +15,38 @@
float speed = 0.4;
while (1) {
-
+
// -1.0 is far left, 1.0 is far right
position_of_line = pi.line_position();
-
+
// Line is more than 75% to the left
if (position_of_line < -0.25) {
pi.left_motor(speed + 0.3);
pi.right_motor(speed - 0.3);
leds = 0xc;
- }
+ }
// Line is more than 25% to the left
else if (position_of_line < -0.10) {
pi.left_motor(speed);
pi.right_motor(speed - 0.3);
leds = 0x4;
- }
+ }
// Line is more than 75% to the right
else if (position_of_line > 0.25) {
pi.right_motor(speed + 0.3);
- pi.left_motor(speed - 0.3);
+ pi.left_motor(speed - 0.3);
leds = 0x3;
- }
- // Line is more than 75% to the right
+ }
+ // Line is more than 75% to the right
else if (position_of_line > 0.10) {
pi.right_motor(speed);
pi.left_motor(speed - 0.3);
leds = 0x2;
- }
- // Line is inthe middle
+ }
+ // Line is inthe middle
else {
pi.forward(speed);
leds = 0x0;
}
-
}
-
}
\ No newline at end of file