a
Dependencies: Roboter m3pi_js mbed
Fork of m3pi_LineFollower by
main.cpp@3:7f077cf1d755, 2010-11-07 (annotated)
- Committer:
- chris
- Date:
- Sun Nov 07 10:41:55 2010 +0000
- Revision:
- 3:7f077cf1d755
- Parent:
- 2:f3f0843285e2
- Child:
- 5:c705b7e7e1a8
Updated to latest m3pi library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris | 0:eb1ece444e15 | 1 | #include "mbed.h" |
chris | 0:eb1ece444e15 | 2 | #include "m3pi.h" |
chris | 0:eb1ece444e15 | 3 | |
chris | 0:eb1ece444e15 | 4 | BusOut leds(LED1,LED2,LED3,LED4); |
chris | 3:7f077cf1d755 | 5 | m3pi m3pi(p23,p9,p10); |
chris | 0:eb1ece444e15 | 6 | |
chris | 0:eb1ece444e15 | 7 | int main() { |
chris | 0:eb1ece444e15 | 8 | |
chris | 3:7f077cf1d755 | 9 | |
chris | 2:f3f0843285e2 | 10 | m3pi.locate(0,1); |
chris | 2:f3f0843285e2 | 11 | m3pi.printf("Line Flw"); |
chris | 0:eb1ece444e15 | 12 | |
chris | 0:eb1ece444e15 | 13 | float position_of_line = 0.0; |
chris | 2:f3f0843285e2 | 14 | m3pi.sensor_auto_calibrate(); |
chris | 0:eb1ece444e15 | 15 | float speed = 0.4; |
chris | 0:eb1ece444e15 | 16 | |
chris | 0:eb1ece444e15 | 17 | while (1) { |
chris | 1:5ddd3faed06d | 18 | |
chris | 0:eb1ece444e15 | 19 | // -1.0 is far left, 1.0 is far right |
chris | 2:f3f0843285e2 | 20 | position_of_line = m3pi.line_position(); |
chris | 1:5ddd3faed06d | 21 | |
chris | 0:eb1ece444e15 | 22 | // Line is more than 25% to the left |
chris | 3:7f077cf1d755 | 23 | if (position_of_line < -0.50) { |
chris | 2:f3f0843285e2 | 24 | m3pi.left_motor(speed); |
chris | 2:f3f0843285e2 | 25 | m3pi.right_motor(speed - 0.3); |
chris | 0:eb1ece444e15 | 26 | leds = 0x4; |
chris | 1:5ddd3faed06d | 27 | } |
chris | 0:eb1ece444e15 | 28 | // Line is more than 75% to the right |
chris | 3:7f077cf1d755 | 29 | else if (position_of_line > 0.50) { |
chris | 2:f3f0843285e2 | 30 | m3pi.right_motor(speed); |
chris | 2:f3f0843285e2 | 31 | m3pi.left_motor(speed - 0.3); |
chris | 0:eb1ece444e15 | 32 | leds = 0x2; |
chris | 1:5ddd3faed06d | 33 | } |
chris | 1:5ddd3faed06d | 34 | // Line is inthe middle |
chris | 0:eb1ece444e15 | 35 | else { |
chris | 2:f3f0843285e2 | 36 | m3pi.forward(speed); |
chris | 0:eb1ece444e15 | 37 | leds = 0x0; |
chris | 0:eb1ece444e15 | 38 | } |
chris | 0:eb1ece444e15 | 39 | } |
chris | 0:eb1ece444e15 | 40 | } |