Rachel Ireland-Jones / Mbed OS FinalYear0
Revision:
27:44ab9ebf07eb
Parent:
26:072ab2309eec
Child:
28:b650e7f6c269
--- a/main.cpp	Wed Dec 18 16:11:53 2019 +0000
+++ b/main.cpp	Wed Dec 18 16:58:47 2019 +0000
@@ -44,36 +44,37 @@
 float TAA, TBB = 0.0f;
 float pulseA, pulseB = 0.0f;
 float travA, travB = 0.0f;
-void timeA()
+void timeA() // this funtion calulates the rotation speed and distance of wheel A
 {
     static int n=0;            //Number of pulse sets
-    static int HallState = 0;
+    static int HallState = 0;   //the hall effect current state
     if (n==0) {
         //Reset timer and Start
-        timerA.reset();
-        timerA.start();
-        TA[0] = timerA.read_us();
+        timerA.reset(); //resets timerA
+        timerA.start(); // starts timerA
+        TA[0] = timerA.read_us(); //reads timer from the beginning of the beginning of the first pulse
     }
     switch(HallState) {
         case 0:
             if(HEA1 == NOPULSE) {
-                HallState = 1;
+                HallState = 1; //change state
             }
             break;
         case 1:
             if(HEA1 == PULSE) {
-                HallState = 0;
-                n++;
-                pulseA++;
-                travA = ((176/20.8)/3)*pulseA;
+                HallState = 0; //change state
+                n++; // add 1 to the number of pulses counted (resets after 9 pulsees)
+                pulseA++; // add 1 to the number of pulses counted for the duration
+                travA = ((176/20.8)/3)*pulseA; // gives the distance travelled by wheel A in mm
             }
             break;
     }
-    if (n < 9) return;
-    TA[1] = timerA.read_us();
-    TAA = (TA[1]-TA[0]);
-    // Calculate speeed
-    fA = 2.0f/ (TAA *(float)1.0E-6);
+    if (n < 9) return;  //returns to main until n=9
+    TA[1] = timerA.read_us(); // time after 9 pulses
+    TAA = (TA[1]-TA[0]); // time taken to do 9 pulses (3 shaft rotations)
+
+    fA = 2.0f/ (TAA *(float)1.0E-6); //frequency of shaft rotation
+    //calcultes speed
     if(durA == 0) {
         speedA[durA] = fA/20.8;
         durA++;
@@ -91,7 +92,7 @@
     }
     sumA = sumA/3;
     //Reset count
-    n=0;
+    n=0; //note to mkike put this after each if statements
 }
 
 void timeB()
@@ -144,7 +145,7 @@
     }
     sumB = sumB/3;
     //Reset count
-    nB=0;
+    nB=0; // note to mike put this in if statements
 }
 
 void oneRPS()
@@ -177,21 +178,21 @@
     PWMA.write(dutyA);
     PWMB.write(dutyB);
 }
-void reset()
+void reset()  // this fuction restes distnace travelled and pulses to 0 allowing fo a new distance measurement
 {
     travA = 0;
     travB = 0;
     pulseA = 0;
     pulseB = 0;
 }
-void straight()
+void straight()  // this sets the wheel speed to roughly 1rps so the program doesnt have make major adjustments from the beginning
 {
     dutyA = 0.463f;
     dutyB = 0.457f;
     PWMA.write(dutyA);          //Set duty cycle (%)
     PWMB.write(dutyB);
 }
-void turn()
+void turn() // this sets the weheel speed to roughly what is needed to make the turn so that the program doesnt have to make any major adjustments
 {
     dutyA = 0.5556f;
     dutyB = 0.28f;