Chris Styles
/
m3pi_LineFollower
A simple line following program
Revision 0:eb1ece444e15, committed 2010-11-01
- Comitter:
- chris
- Date:
- Mon Nov 01 23:16:57 2010 +0000
- Child:
- 1:5ddd3faed06d
- Commit message:
- Added some LEDs to show how far off the line the sensors are
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m3pi.lib Mon Nov 01 23:16:57 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/chris/code/m3pi/#330eb028e85b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Nov 01 23:16:57 2010 +0000 @@ -0,0 +1,54 @@ +#include "mbed.h" +#include "m3pi.h" + +BusOut leds(LED1,LED2,LED3,LED4); +m3pi pi (p27,p9,p10); //nRST, TX, RX + +int main() { + + pi.locate(0,1); + pi.printf("Line Flw"); + + float position_of_line = 0.0; + + pi.sensor_auto_calibrate(); + 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); + leds = 0x3; + } + // 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 + else { + pi.forward(speed); + leds = 0x0; + } + + } + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Nov 01 23:16:57 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e