Robot code for searching an object and charging at it.
Dependencies: HCSR04 Motor mbed
Diff: main.cpp
- Revision:
- 6:af897173cb75
- Parent:
- 5:68a2b79cf204
- Child:
- 7:d94d23c55015
- Child:
- 9:7770a84228c0
--- a/main.cpp Sat May 23 15:08:23 2015 +0000 +++ b/main.cpp Sat May 23 16:09:43 2015 +0000 @@ -59,21 +59,19 @@ float searchspeed; // Range of detection // optimum value: 30 to 50 -int range; +unsigned int range; -void initialise() -{ - chargespeed = 0.5; - searchspeed = 0.3; - range = 40; +void initialise() { + chargespeed = 0.6; + searchspeed = 0.5; + range = 30; // Wait for 5 seconds to move away from robot wait(5); } // The main loop - please write your code here -int main() -{ +int main() { // Initialise the code initialise(); @@ -82,17 +80,19 @@ Timer t; t.start(); - while(1) { - // Sample code to detect and object and charge at it - if (detect_object(range, searchspeed)) { - - charge(chargespeed); - wait(3); - stop(); - - } else { - - } + //while(1) { + // Sample code to detect and object and charge at it + if (detect_object(range, searchspeed)) { + + charge(chargespeed); + wait(3); + stop(); + + } else { + } + + stop(); + //} }