Buggy bois / Mbed 2 deprecated WORKING_TRIAL

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
mazdo25
Date:
Sun Apr 28 22:20:28 2019 +0000
Parent:
10:acf5cb8d58d5
Commit message:
WOw;

Changed in this revision

Robot.h Show annotated file Show diff for this revision Revisions of this file
WheelControl/Wheel.h Show annotated file Show diff for this revision Revisions of this file
--- a/Robot.h	Sun Apr 28 18:27:46 2019 +0000
+++ b/Robot.h	Sun Apr 28 22:20:28 2019 +0000
@@ -143,58 +143,45 @@
         {
         case 0:
             lineVoltages[lvIndex%numberOfSamples] = (reading * -260.0f); 
-            if (reading <= Reflec*12){endOfLineDetection++;}
+            if (reading <= Reflec*8){endOfLineDetection++;}
             break;
         case 1:
             lineVoltages[lvIndex%numberOfSamples] += (reading * -105.0f);
-            if (reading <= Reflec*12) {endOfLineDetection++;}
+            if (reading <= Reflec*8) {endOfLineDetection++;}
             break;
         case 2:
             lineVoltages[lvIndex%numberOfSamples] += (reading * -32.5f);
-            if (reading <= Reflec*12) {endOfLineDetection++;}
+            if (reading <= Reflec*8) {endOfLineDetection++;}
             break;
         case 3:
             lineVoltages[lvIndex%numberOfSamples] += (reading * 32.5f);
-            if (reading <= Reflec*12) {endOfLineDetection++;}
+            if (reading <= Reflec*8) {endOfLineDetection++;}
             break;
         case 4: 
             lineVoltages[lvIndex%numberOfSamples] += (reading * 75.0f);
-            if (reading <= Reflec*12) {endOfLineDetection++;}
+            if (reading <= Reflec*8) {endOfLineDetection++;}
             break;
         case 5:
             lineVoltages[lvIndex%numberOfSamples] += (reading * 175.0f);
-            if (reading <= Reflec*12) {endOfLineDetection++;}
+            if (reading <= Reflec*8) {endOfLineDetection++;}
             break;
         }
                 
         sensorNumber ++;
-            
         if (sensorNumber >= numberOfSensors)
         {
             sensorNumber = 0;
             if (endOfLineDetection < 6)
             {
                 //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 (brakeC < 8)
+            else
             {
-                leftWheel->setBR(1);
-                rightWheel->setBR(1);
-                leftWheel->brake();
-                rightWheel->brake();
-                brakeC ++;
-            }else {
-                leftWheel->setBR(0);
-                rightWheel->setBR(0);
-                AF = 0.0f;
-                stopMovement();
-                }
+               stopMovement(); 
+            }
         endOfLineDetection = 0;
         }
     }
--- a/WheelControl/Wheel.h	Sun Apr 28 18:27:46 2019 +0000
+++ b/WheelControl/Wheel.h	Sun Apr 28 22:20:28 2019 +0000
@@ -26,7 +26,7 @@
     
     float static const wheelDiameter = 0.18; //used in calculation of Linear velocity i.e never
     
-    Wheel (Encoder* E, PinName M, PinName D, PinName Mode) : Mtr(M), direction(D), polarity(Mode), controller(gain,4.0f,0.00002f,0.0003f)
+    Wheel (Encoder* E, PinName M, PinName D, PinName Mode) : Mtr(M), direction(D), polarity(Mode), controller(gain,4.0f,0.0f,0.0003f)
         {
         maxAngularVel = 0.0f;
         enc = E;
@@ -78,7 +78,7 @@
         maxAngularVel = 75.0f;
         minAngularVel = -1.0f*maxAngularVel;
         controller.setSetPoint(0.0f);
-        updater.attach(callback(this, &Wheel::wheelUpdates),0.0005f);
+        updater.attach(callback(this, &Wheel::wheelUpdates),0.0003f);
     }
     
     void startController()
@@ -93,17 +93,11 @@
     
     void wheelUpdates(void) //sampling rate the ticker is attached I.E the wheel speed is updated everytime this function is called
         {
-            if (br == 0) {
             calculateAngularVelocity();
             //distance += angularVelocity*(wheelDiameter/2)*0.0005f;
             float temp2 = controller.compute(angularVelocity); //another temporary value to store the computed angular velocity
             if (temp2 < 0) {direction = 0;} else {direction = 1;} //change direction according to the computed value
             Mtr.write((1.0f - abs(temp2))); //write the value as a pwm
-            }
-            else
-            {
-                return;
-            }
         }
         
     void adjustAngularVelocity(float W) // W = angular velocity you want, obviously putting a |w| value that is > max angular velocity will set dutcy cycle to max
@@ -145,8 +139,7 @@
     
     void brake()
     {
-        direction = 0;
-        Mtr.write(0);
+        
     }
     
 };
\ No newline at end of file