Zachary Sunberg / Mbed 2 deprecated SAILORSbot

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
zsunberg
Date:
Wed Jul 13 19:48:12 2016 +0000
Parent:
36:ae0fa5fea38f
Commit message:
put pid code back in

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
robot.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Jul 12 04:01:41 2016 +0000
+++ b/main.cpp	Wed Jul 13 19:48:12 2016 +0000
@@ -20,9 +20,11 @@
     // line_position, speed and other
     // variables in this scope.
     ////////////////////////////////////
-
+    double derivative = line_position - previous_position;
+    double delta = k_p * line_position + k_d * derivative + k_i * integral;
     
-
+    leftspeed = speed + delta;
+    rightspeed = speed - delta;
     // set motor speeds here
     // leftspeed = ???;
     // rightspeed = ???;
@@ -42,7 +44,7 @@
         rightspeed = MIN;
     }
     
-    // Code to check if we need to stop
+    // Code to check if we need to stop (uncomment this if you want)
     if(sensors[0] < 1000 && sensors[1] < 1000 && sensors[2] < 1000 && sensors[3] < 1000 && sensors[4] < 1000){
         //dead end
         leftspeed = 0.0;
@@ -225,6 +227,4 @@
         }
 
     }
-
-    return 0;
 }
--- a/robot.h	Tue Jul 12 04:01:41 2016 +0000
+++ b/robot.h	Wed Jul 13 19:48:12 2016 +0000
@@ -41,7 +41,7 @@
 
 // GAINS/Params
 //////////////////////////////
-double k_p = 0.0;
+double k_p = 0.1;
 double k_i = 0.0;
 double k_d = 0.0;
 double speed = 0.3;