Cleaned up the code a bit

Dependencies:   mbed QEI HIDScope biquadFilter MODSERIAL FastPWM

Revision:
1:b56499238c53
Parent:
0:3c2e28fef203
Child:
2:a246ac8f0381
--- a/main.cpp	Fri Oct 11 10:43:31 2019 +0000
+++ b/main.cpp	Fri Oct 11 12:13:40 2019 +0000
@@ -38,7 +38,8 @@
 volatile float psi_1 = 0; //angle of motor_1 in radians
 volatile float psi_1prev = 0; //precious angle of motor_1 in radians
 #define M_PI acos(-1.0)
-const float to_rads =((2*M_PI)/8400); //contant for claculating one tick of the motor to radians, 8400 is a property of the motor -> 8400 counts per revolution
+const float to_rads =((2*M_PI)/131); //contant for claculating one tick of the motor to radians, 8400 is a property of the motor -> 8400 counts per revolution
+volatile int n = 0;
 
 // FUNCTIONS
 float GetValueFromKeyboard() //Gets input from PC
@@ -72,33 +73,6 @@
         }
 }
 
-//void GetDirectionFromkeyboard ()
-//{
-//    start_dir:
-//    
-//    int b;
-//    cin >> b;
-//    switch (b)
-//    {
-//        case 1:
-//        {
-//            pc.printf("\nYour input: [1] -> CCW motion\r\n\r\n--------\r\n\n");
-//            dir_1 = true;
-//            break;
-//            }
-//        case 0:
-//        {
-//            pc.printf("\nYour input: [0] -> CW motion\r\n\r\n--------\r\n\n");
-//            dir_1 = false;
-//            break;
-//            }
-//        default:
-//        {
-//            pc.printf("\nYour input was invalid, please input 1 for CCW or 0 for CW motion.\r\n");
-//            goto start_dir;
-//            }
-//    }
-//}
 
 void PWM_MOTOR_1 (void) //Calculates on and off times
 {
@@ -114,16 +88,6 @@
     msignal_1 = 0; // Turn motor off
     wait_ms(off_time_1); 
     }
-    
-void ReadEnc_1() 
-{ 
-    a_1prev = a_1;
-    b_1prev = b_1;
-    a_1 = enc_1a;
-    b_1 = enc_1b;
-
-    //pc.printf("a_1i = %f, b_1i = %f\r\n", a_1, b_1);
-    }
 
 float Enc_1Radians ()
 {
@@ -135,6 +99,7 @@
         psi_1prev = psi_1;
         if(dir_1)
         {
+            n++;
             psi_1 = psi_1prev + to_rads;
             }
         else
@@ -145,19 +110,27 @@
         }
     return psi_1;
     }
+    
+void ReadEnc_1() 
+{ 
+    a_1prev = a_1;
+    b_1prev = b_1;
+    a_1 = enc_1a;
+    b_1 = enc_1b;
+
+    Enc_1Radians ();
+    //pc.printf("a_1i = %f, b_1i = %f\r\n", a_1, b_1);
+    }
 
 int main()
 {   
     pc.baud(SERIAL_BAUD);
     
     pc.printf("--------\r\nWelcome!\r\n--------\r\n\n");
-    EncTicker.attach(&ReadEnc_1, 0.0001); //Ticker function to read Enc_1 to HIDScope
+    EncTicker.attach(&ReadEnc_1, 0.01); //Ticker function to read Enc_1 to HIDScope
     
     start_main:
-    
-//    pc.printf("Please imput your desired direction value, either 1 for CCW or 0 for CW movement\r\n");
-//    GetDirectionFromkeyboard();
-     
+    pc.printf("n = %i\r\n", n);
     
     wait(0.5);
     
@@ -168,7 +141,6 @@
     
     while (true) 
     {
-        Enc_1Radians ();
         MOTOR_1();
         if (but_1 == 0)
         {