Minor BioRobotics BMT Hierbij publish ik mijn code public ter inspiratie voor komende jaarlagen. Het gaat om een serial robot met twee links en een haak als end-effector. Veel plezier ermee!

Dependencies:   mbed QEI HIDScope biquadFilter MODSERIAL FastPWM

Revision:
11:a3fd9d5144bb
Parent:
10:a60b369c1711
Child:
12:f5dc65f1c27b
diff -r a60b369c1711 -r a3fd9d5144bb main.cpp
--- a/main.cpp	Tue Oct 29 13:36:53 2019 +0000
+++ b/main.cpp	Tue Oct 29 13:52:23 2019 +0000
@@ -70,8 +70,8 @@
     FastPWM motor1(D6);                  // motor 1 velocity control (between 0-1)
     FastPWM motor2(D5);                  // motor 2 velocity control (between 0-1)
     DigitalOut motor2DirectionPin(D4);   // motor 2 direction control (1=cw, 0=ccw)
-    bool motor1_calibration_status=true;
-    bool motor2_calibration_status=true;
+    bool motor1_calibrated=false;
+    bool motor2_calibrated=false;
  
 // 3.5 Motor 1 variables ***************************************************************   
     //3.5a PID-controller motor 1
@@ -143,37 +143,43 @@
             return positie_motor2;                                 //geeft positie van motor
         }
         
-    // 4.xa Calibration motor 1
-    void motor1_calibration()
+    // 4.xa Calibration motors
+        
+    void motor_calibration()
     {
+        // Calibration motor 2
         motor1DirectionPin=0; //direction of the motor
         motor1=1.0;
         wait(0.05);
         while (abs(positie_verschil_motor1)>5)
         {
             motor1=0.2  ; 
-            pc.printf("\r\n Motor1 kalibratie = %s", motor1_calibration_status ? "true" : "false");
+            pc.printf("\r\n Motor1 kalibratie = %s", motor1_calibrated ? "true" : "false");
         }
         motor1=0.0;
-        motor1_calibration_status=false;  
-        pc.printf("\r\n Motor1 kalibratie = %s", motor1_calibration_status ? "true" : "false");
+        motor1_calibrated=true;  
+        pc.printf("\r\n Motor1 kalibratie = %s", motor1_calibrated ? "true" : "false");
     
-    }
+    
     
-    // 4.xa Calibration motor 2
-    void motor2_calibration()
-    {
+        // Calibration motor 2
         motor2DirectionPin=0; //direction of the motor
         motor2=1.0;
         wait(1);
         while (abs(positie_verschil_motor2)>5)
         {
             motor2=0.2  ; 
-            pc.printf("\r\n Motor2 kalibratie = %s", motor2_calibration_status ? "true" : "false");
+            pc.printf("\r\n Motor2 kalibratie = %s", motor2_calibrated ? "true" : "false");
         }
         motor2=0.0;
-        motor2_calibration_status=false;  
-        pc.printf("\r\n Motor2 kalibratie = %s", motor2_calibration_status ? "true" : "false");
+        motor2_calibrated=true;  
+        pc.printf("\r\n Motor2 kalibratie = %s", motor2_calibrated ? "true" : "false");
+        
+        if (motor1_calibrated==true&&motor2_calibrated==true) 
+        {
+            pc.printf("\r\n Motor Calibration is done!");
+        }
+        else {pc.printf("\r\n Motor Calibration is not done!");}
     
     }
     
@@ -266,8 +272,7 @@
    
     ticker_mainloop.attach(&main_loop,0.001); // change back to 0.001f //Run the function main_loop 1000 times per second       
     ticker_hidscope.attach(&HIDScope, 0.001); //Ticker for Hidscope, different frequency compared to motors
-    motor1_calibration();
-    motor2_calibration();
+    motor_calibration();
     
     
 // 6.2 While loop in main function**********************************************