a
Dependencies: Roboter m3pi_js mbed
Fork of m3pi_LineFollower by
main.cpp@2:f3f0843285e2, 2010-11-02 (annotated)
- Committer:
- chris
- Date:
- Tue Nov 02 16:58:25 2010 +0000
- Revision:
- 2:f3f0843285e2
- Parent:
- 1:5ddd3faed06d
- Child:
- 3:7f077cf1d755
Changed the instance name from \"pi\" to \"m3pi\", and all reference to it
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 | 2:f3f0843285e2 | 5 | m3pi m3pi (p27,p9,p10); //nRST, TX, RX |
chris | 0:eb1ece444e15 | 6 | |
chris | 0:eb1ece444e15 | 7 | int main() { |
chris | 0:eb1ece444e15 | 8 | |
chris | 2:f3f0843285e2 | 9 | m3pi.locate(0,1); |
chris | 2:f3f0843285e2 | 10 | m3pi.printf("Line Flw"); |
chris | 0:eb1ece444e15 | 11 | |
chris | 0:eb1ece444e15 | 12 | float position_of_line = 0.0; |
chris | 2:f3f0843285e2 | 13 | m3pi.sensor_auto_calibrate(); |
chris | 0:eb1ece444e15 | 14 | float speed = 0.4; |
chris | 0:eb1ece444e15 | 15 | |
chris | 0:eb1ece444e15 | 16 | while (1) { |
chris | 1:5ddd3faed06d | 17 | |
chris | 0:eb1ece444e15 | 18 | // -1.0 is far left, 1.0 is far right |
chris | 2:f3f0843285e2 | 19 | position_of_line = m3pi.line_position(); |
chris | 1:5ddd3faed06d | 20 | |
chris | 0:eb1ece444e15 | 21 | // Line is more than 75% to the left |
chris | 0:eb1ece444e15 | 22 | if (position_of_line < -0.25) { |
chris | 2:f3f0843285e2 | 23 | m3pi.left_motor(speed + 0.3); |
chris | 2:f3f0843285e2 | 24 | m3pi.right_motor(speed - 0.3); |
chris | 0:eb1ece444e15 | 25 | leds = 0xc; |
chris | 1:5ddd3faed06d | 26 | } |
chris | 0:eb1ece444e15 | 27 | // Line is more than 25% to the left |
chris | 0:eb1ece444e15 | 28 | else if (position_of_line < -0.10) { |
chris | 2:f3f0843285e2 | 29 | m3pi.left_motor(speed); |
chris | 2:f3f0843285e2 | 30 | m3pi.right_motor(speed - 0.3); |
chris | 0:eb1ece444e15 | 31 | leds = 0x4; |
chris | 1:5ddd3faed06d | 32 | } |
chris | 0:eb1ece444e15 | 33 | // Line is more than 75% to the right |
chris | 0:eb1ece444e15 | 34 | else if (position_of_line > 0.25) { |
chris | 2:f3f0843285e2 | 35 | m3pi.right_motor(speed + 0.3); |
chris | 2:f3f0843285e2 | 36 | m3pi.left_motor(speed - 0.3); |
chris | 0:eb1ece444e15 | 37 | leds = 0x3; |
chris | 1:5ddd3faed06d | 38 | } |
chris | 1:5ddd3faed06d | 39 | // Line is more than 75% to the right |
chris | 0:eb1ece444e15 | 40 | else if (position_of_line > 0.10) { |
chris | 2:f3f0843285e2 | 41 | m3pi.right_motor(speed); |
chris | 2:f3f0843285e2 | 42 | m3pi.left_motor(speed - 0.3); |
chris | 0:eb1ece444e15 | 43 | leds = 0x2; |
chris | 1:5ddd3faed06d | 44 | } |
chris | 1:5ddd3faed06d | 45 | // Line is inthe middle |
chris | 0:eb1ece444e15 | 46 | else { |
chris | 2:f3f0843285e2 | 47 | m3pi.forward(speed); |
chris | 0:eb1ece444e15 | 48 | leds = 0x0; |
chris | 0:eb1ece444e15 | 49 | } |
chris | 0:eb1ece444e15 | 50 | } |
chris | 0:eb1ece444e15 | 51 | } |