V0.1

Dependencies:   mbed QEI

Fork of motor_calibration by Kenneth Weisbeek

Revision:
9:6672bbf14f7a
Parent:
8:ebb645b3e15f
Child:
10:4d5af6e84c7a
--- a/main.cpp	Wed Oct 31 18:14:06 2018 +0000
+++ b/main.cpp	Wed Oct 31 18:25:31 2018 +0000
@@ -2,6 +2,8 @@
 #include "QEI.h"
 #define SERIAL_BAUD 115200
 
+/* THIS IS IMPLEMENTED IN THE BIG CODE, DO NOT CHANGE IT HERE, BUT THERE!!! */
+
 //initial allocations
 DigitalOut dirpin(D4); // for translatie
 DigitalOut dirpin_2(D7); // for rotatie
@@ -25,6 +27,8 @@
 volatile double tower_end_position = 0.1; // the tower which he reaches second
 volatile double rotation_start_position = 0.1; // the position where the rotation will remain
 volatile double position;
+float speed = 0.70;
+int dir = 0;
 
 // Functions (2 functions not finished)
 int Counts1(volatile int& a) // a = counts1
@@ -80,20 +84,9 @@
     pwmpin_2 = 0.0;
     } 
 
-
-// main function
-int main()
+// Calibration of translation
+void calibration_translation()
 {
-    pc.baud(115200);                  
-    pc.printf("Start\r\n");
-    
-    pwmpin.period_us(60);
-    
-    // parameters  
-    float speed = 0.70;
-    int dir = 0;
-    
-    // translation
     for(int m = 1; m <= 2; m++) // to do each direction one time
     {
         pc.printf("\r\nTranslatie loop\r\n");
@@ -117,11 +110,11 @@
             }
         
         wait(1.5); // wait 3 seconds before next round of translation/rotation
-        } 
-    pc.printf("before wait\r\n");
-    wait(10.0);
+        }
+    }
     
-    // rotation
+void calibration_rotation()
+{
     rotation_start(dir, speed);
     pc.printf("\r\nRotatie start\r\n");
 
@@ -140,8 +133,30 @@
         
     pos_store(Counts2(counts2));
     pc.printf("position of first tower = %.1f, position of second tower = %.1f, position of rotation motor = %.1f \r\n",tower_1_position,tower_end_position,rotation_start_position);
+    }
+    
+void MOTOR_CAL()
+{
+    // translation
+    calibration_translation();
+    
+    pc.printf("before wait\r\n");
+    wait(3.0);
+    
+    // rotation
+    calibration_rotation();
     
     pc.printf("Motor calibration done");
+    }
     
-        
+
+// main function
+int main()
+{
+    pc.baud(115200);                  
+    pc.printf("Start\r\n");
+    pwmpin.period_us(60);
+    
+    MOTOR_CAL();
+       
     }        
\ No newline at end of file