
Robot code for searching an object and charging at it.
Dependencies: HCSR04 Motor mbed
Revision 16:02e533e3a91c, committed 2015-05-30
- Comitter:
- alex0612
- Date:
- Sat May 30 16:05:07 2015 +0000
- Parent:
- 15:a821a0c599b3
- Child:
- 17:47aa9ef2bec6
- Commit message:
- Cleaned main
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat May 30 15:44:01 2015 +0000 +++ b/main.cpp Sat May 30 16:05:07 2015 +0000 @@ -80,33 +80,44 @@ Timer t; t.start(); - int detect = 0; + int detect_l = 0; + int detect_o = 0; while(1) { // Sample code to detect and object and charge at it - if (detect_object(range, searchspeed)) { - while (true) { - charge(chargespeed); + + detect_o = detect_object(range, searchspeed) + + if (detect_o == 1) { + + charge(chargespeed); - detect = detect_line(); + while (true) { + + detect_l = detect_line(); // If line is detected from front then reverse - if(detect == 1) { + if(detect_l == 1) { reverse(searchspeed); wait(2); stop(); - detect = 0 + detect_l = 0 break; // If line is detected from back just keep on moving forward - } else if (detect == -1) { + } else if (detect_l == -1) { wait(2); stop(); - detect = 0 + detect_l = 0 break; } } + } else { + moverandom(); + } + + detect_o = 0; stop(); } }