Buggy bois / Mbed 2 deprecated headache

Dependencies:   mbed

Revision:
10:acf5cb8d58d5
Parent:
9:cefa177c1353
Child:
11:78c645fb76cd
--- a/Robot.h	Fri Apr 05 16:11:28 2019 +0000
+++ b/Robot.h	Sun Apr 28 18:27:46 2019 +0000
@@ -11,6 +11,7 @@
     float lineVoltages[numberOfSamples];
     int lvIndex;
     int sensorNumber;
+    int brakeC;
     
     Ticker updater;
     Timeout timeToStop;
@@ -24,7 +25,7 @@
     
     public:
     
-    Robot(Wheel* LW, Wheel* RW, lineSensor* SA[]) : controller(2.0f, 0.0f, 0.0f, 0.0003f) //this controller actually does nothing atm
+    Robot(Wheel* LW, Wheel* RW, lineSensor* SA[]) : controller(2.0f, 0.0f, 0.0f, 0.0006f) //this controller actually does nothing atm
     {
         updater.detach();
         timeToStop.detach();
@@ -141,29 +142,28 @@
         switch (sensorNumber)
         {
         case 0:
-            lineVoltages[lvIndex%numberOfSamples] = (reading * -500.0f); 
-            if (reading <= Reflec*4){endOfLineDetection++;}
-            
+            lineVoltages[lvIndex%numberOfSamples] = (reading * -260.0f); 
+            if (reading <= Reflec*12){endOfLineDetection++;}
             break;
         case 1:
-            lineVoltages[lvIndex%numberOfSamples] += (reading * -180.0f);
-            if (reading <= Reflec*4) {endOfLineDetection++;}
+            lineVoltages[lvIndex%numberOfSamples] += (reading * -105.0f);
+            if (reading <= Reflec*12) {endOfLineDetection++;}
             break;
         case 2:
-            lineVoltages[lvIndex%numberOfSamples] += (reading * -50.0f);
-            if (reading <= Reflec*4) {endOfLineDetection++;}
+            lineVoltages[lvIndex%numberOfSamples] += (reading * -32.5f);
+            if (reading <= Reflec*12) {endOfLineDetection++;}
             break;
         case 3:
-            lineVoltages[lvIndex%numberOfSamples] += (reading * 50.0f);
-            if (reading <= Reflec*4) {endOfLineDetection++;}
+            lineVoltages[lvIndex%numberOfSamples] += (reading * 32.5f);
+            if (reading <= Reflec*12) {endOfLineDetection++;}
             break;
         case 4: 
-            lineVoltages[lvIndex%numberOfSamples] += (reading * 150.0f);
-            if (reading <= Reflec*4) {endOfLineDetection++;}
+            lineVoltages[lvIndex%numberOfSamples] += (reading * 75.0f);
+            if (reading <= Reflec*12) {endOfLineDetection++;}
             break;
         case 5:
-            lineVoltages[lvIndex%numberOfSamples] += (reading * 250.0f);
-            if (reading <= Reflec*4) {endOfLineDetection++;}
+            lineVoltages[lvIndex%numberOfSamples] += (reading * 175.0f);
+            if (reading <= Reflec*12) {endOfLineDetection++;}
             break;
         }
                 
@@ -172,17 +172,26 @@
         if (sensorNumber >= numberOfSensors)
         {
             sensorNumber = 0;
-            if (endOfLineDetection < 8)
+            if (endOfLineDetection < 6)
             {
-                AF = scaler(-180.0f,180.0f, 0.2f, 1.0f, lineVoltages[lvIndex%numberOfSamples]);
+                //AF = scaler(-180.0f,180.0f, 0.2f, 1.0f, lineVoltages[lvIndex%numberOfSamples]);
+                leftWheel->setBR(0);
+                rightWheel->setBR(0);
+                AF = 0.7f;
                 adjustRbtAngularVelocity(lineVoltages[lvIndex%numberOfSamples]);
                 lvIndex++;
+                brakeC = 0;
             }
-            else if (AF > 0.1f)
+            else if (brakeC < 8)
             {
-                AF -= AF/2.0f;
-                adjustRbtAngularVelocity(lineVoltages[lvIndex%numberOfSamples-1]);
-            }else{
+                leftWheel->setBR(1);
+                rightWheel->setBR(1);
+                leftWheel->brake();
+                rightWheel->brake();
+                brakeC ++;
+            }else {
+                leftWheel->setBR(0);
+                rightWheel->setBR(0);
                 AF = 0.0f;
                 stopMovement();
                 }
@@ -195,13 +204,13 @@
         updater.detach();
         rightWheel->adjustAngularVelocity(rightWheel->returnMaxAngularVel()*0.3f);
         leftWheel->adjustAngularVelocity(rightWheel->returnMaxAngularVel()*-0.3f);
-        timeToStop.attach(callback(this, &Robot::reAttach),1.3f);
+        timeToStop.attach(callback(this, &Robot::reAttach),1.1f);
         state = 'S';
     }
     
     void reAttach()
     {
-        updater.attach(callback(this, &Robot::robotUpdates),0.00005f);
+        updater.attach(callback(this, &Robot::robotUpdates),0.0001f);
     }
     
     float scaler(float prevMin, float prevMax, float newMin, float newMax, float var)