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 15:17:02 2015 +0000
Parent:
24:513c88816ed8
Child:
26:5ee2a32949e6
Commit message:
Renamed move_forwardspeed. Removed description of reverse_and_turn

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 15:10:43 2015 +0000
+++ b/functions.cpp	Sun Jun 07 15:17:02 2015 +0000
@@ -122,25 +122,25 @@
     }
 }
 
-void reverse(float speed = move_forwardspeed) {
+void reverse(float speed = moveforwardspeed) {
     printf("Reverse\n");
     MotorLeft.speed(-(speed));
     MotorRight.speed(-(speed));
 }
 
-void turn(float speed = move_forwardspeed) {
+void turn(float speed = moveforwardspeed) {
     printf("Turning\n");
     MotorLeft.speed(speed);
     MotorRight.speed(-(speed));
 }
 
-void reverseandturn(float speed = move_forwardspeed) {
+void reverseandturn(float speed = moveforwardspeed) {
     printf("Reverse and turn\n");
     MotorLeft.speed((speed-0.3));
     MotorRight.speed(-(speed-0.1));
 }
 
-void move_forward(float speed = move_forwardspeed) {
+void move_forward(float speed = moveforwardspeed) {
     MotorLeft.speed(speed);
     MotorRight.speed(speed);
 }
@@ -186,7 +186,7 @@
     MotorRight.speed(0.0);
 }
 
-int detect_object(int range_t = range, float speed = move_forwardspeed) {
+int detect_object(int range_t = range, float speed = moveforwardspeed) {
     // Start a timer - finds an object for 5 seconds
     // if it doesn't find anything returns 0
     Timer usensor_t, inner_t;
@@ -250,14 +250,14 @@
         if(detect == 1) {
             stop();
             turn_leds_on();
-            move_detect(-move_forwardspeed,1,1000);
+            move_detect(-moveforwardspeed,1,1000);
             stop();
             break;
         // If line is detected from back just keep on moving forward
         } else if (detect == -1) {
             stop();
             turn_leds_on();
-            move_detect(move_forwardspeed,1,1000);
+            move_detect(moveforwardspeed,1,1000);
             stop();
             break;
         }
--- a/functions.h	Sun Jun 07 15:10:43 2015 +0000
+++ b/functions.h	Sun Jun 07 15:17:02 2015 +0000
@@ -3,7 +3,7 @@
 // Global parameters
 // Speed at which it move_forwards an object
 // optimum value: 0.4 to 0.8
-extern float move_forwardspeed;
+extern float moveforwardspeed;
 // Speed at which it rotates to find an object
 // optimum value: 0.3 to 0.5
 extern float searchspeed;
@@ -16,7 +16,7 @@
 int read_line1();
 int read_line2();
 int detect_line();
-void move_random(float speed=move_forwardspeed);
+void move_random(float speed=moveforwardspeed);
 void reverse(float speed);
 void turn(float speed);
 void reverse_and_turn(float speed);
--- a/main.cpp	Sun Jun 07 15:10:43 2015 +0000
+++ b/main.cpp	Sun Jun 07 15:17:02 2015 +0000
@@ -33,10 +33,7 @@
 //                          -1 - if line detected from the back
 //
 // reverse(speed)
-//                      -   reverses the robot with move_forwardspeed in same position
-//
-// reverse_and_turn(speed)
-//                      -   reverses while moving in a circular direction
+//                      -   reverses the robot with moveforwardspeed in same position
 //
 // stop()
 //                      -   stops the robot
@@ -60,7 +57,7 @@
 // Global parameters
 // Speed at which it move_forwards an object
 // optimum value: 0.4 to 0.8
-float move_forwardspeed;
+float moveforwardspeed;
 // Speed at which it rotates to find an object
 // optimum value: 0.3 to 0.5
 float searchspeed;
@@ -70,7 +67,7 @@
 
 void initialise()
 {
-    move_forwardspeed = 0.6;
+    moveforwardspeed = 0.6;
     searchspeed = 0.5;
     range = 30;
 
@@ -99,7 +96,7 @@
 
         if (detect_o == 1) {
 
-            move_forward(move_forwardspeed);
+            move_forward(moveforwardspeed);
 
             while (true) {