a
Dependencies: Roboter m3pi_js mbed
Fork of m3pi_LineFollower by
main.cpp
- Committer:
- chris
- Date:
- 2011-05-12
- Revision:
- 7:218e861ea777
- Parent:
- 6:8f46c6ac55ca
- Child:
- 8:2cca24684c6d
File content as of revision 7:218e861ea777:
#include "mbed.h" #include "m3pi.h" m3pi m3pi; int main() { // Parameters that affect the performance float speed = 0.2; float correction = 0.1; float threshold = 0.5; m3pi.locate(0,1); m3pi.printf("Line Flw"); wait(2.0); m3pi.sensor_auto_calibrate(); while (1) { // -1.0 is far left, 1.0 is far right, 0.0 in the middle float position_of_line = m3pi.line_position(); // Line is more than the threshold to the right, slow the left motor if (position_of_line > threshold) { m3pi.right_motor(speed); m3pi.left_motor(speed-correction); } // Line is more than 50% to the left, slow the right motor else if (position_of_line < -threshold) { m3pi.left_motor(speed); m3pi.right_motor(speed-correction); } // Line is in the middle else { m3pi.forward(speed); } } }