Robot code for searching an object and charging at it.

Dependencies:   HCSR04 Motor mbed

Files at this revision

API Documentation at this revision

Comitter:
lhartfield
Date:
Sun Jun 07 17:30:06 2015 +0000
Parent:
26:5ee2a32949e6
Child:
29:977f47331d85
Commit message:
Fix to move_detect to avoid missing the line

Changed in this revision

functions.cpp Show annotated file Show diff for this revision Revisions of this file
functions.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/functions.cpp	Sun Jun 07 16:36:03 2015 +0000
+++ b/functions.cpp	Sun Jun 07 17:30:06 2015 +0000
@@ -252,14 +252,14 @@
     return sense;
 }
 
-void move_detect(float speed, int fwd_bck, int time) {
+void move_detect(float speed, int fwd_bck, int time, int wait) {
     Timer t;
     t.start();
     int detect = 0;
     
     if(fwd_bck == 1) {
         move_forward(speed);
-        wait_ms(500);
+        wait_ms(wait);
     } else {
         turn(speed + 0.2);
     }
@@ -270,14 +270,14 @@
         if(detect == 1) {
             stop();
             turn_leds_on();
-            move_detect(-moveforwardspeed,1,1000);
+            move_detect(-moveforwardspeed,1,1000,300);
             stop();
             break;
         // If line is detected from back just keep on moving forward
         } else if (detect == -1) {
             stop();
             turn_leds_on();
-            move_detect(moveforwardspeed,1,1000);
+            move_detect(moveforwardspeed,1,1000,300);
             stop();
             break;
         }
--- a/functions.h	Sun Jun 07 16:36:03 2015 +0000
+++ b/functions.h	Sun Jun 07 17:30:06 2015 +0000
@@ -25,4 +25,4 @@
 void move_forward(float speed = moveforwardspeed);
 void stop();
 int detect_object(int range_t = range, float speed = moveforwardspeed);
-void move_detect(float speed, int fwd_bck, int time);
\ No newline at end of file
+void move_detect(float speed, int fwd_bck, int time, int wait=0);
\ No newline at end of file
--- a/main.cpp	Sun Jun 07 16:36:03 2015 +0000
+++ b/main.cpp	Sun Jun 07 17:30:06 2015 +0000
@@ -91,6 +91,7 @@
 
     while(true) {
         // Sample code to detect and object and move_forward at it
+        
         wait(1);
         
         detect_o = detect_object(range, searchspeed);
@@ -103,7 +104,7 @@
 
                 detect_l = detect_line();
                 // If line is detected from front then reverse
-                if(detect_l == 1) {
+                if(detect_l == 1 || detect_l == -1) {
                     stop();
                     turn_led_right();
                     reverse(searchspeed);
@@ -122,6 +123,6 @@
 
         detect_o = 0;
         stop();
-    }
+    } 
 }