Motor calibration

Dependencies:   BioroboticsMotorControl mbed BioroboticsEMGFilter MODSERIAL

Files at this revision

API Documentation at this revision

Comitter:
MAHCSnijders
Date:
Wed Oct 31 12:53:03 2018 +0000
Parent:
6:656fb0834a1a
Commit message:
FINAL CALIBRATION WHERE EVERYTHING WORKS AND THE SUN IS SHINING

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 656fb0834a1a -r 5cbb59d98416 main.cpp
--- a/main.cpp	Wed Oct 31 12:45:43 2018 +0000
+++ b/main.cpp	Wed Oct 31 12:53:03 2018 +0000
@@ -57,26 +57,24 @@
     if (current_angle2 - motor_threshold <= last_angle2 && last_angle2 <= current_angle2 + motor_threshold)     // If the motor angle is within a margin of the current motor angle
     {
         time_passed_in_this_state2++;
-        calibLED1 = !calibLED1;                              // LED becomes blue
+        calibLED1 = !calibLED1;                              // LED turns blue
     }
     else
     {
-        motor_angle2 = motor2.get_current_angle();
-        motor_angle2 = motor_angle2 - 5*motor_threshold;    // Subtracting five degree angle from the current angle
+        motor_angle2 = current_angle2;
+        motor_angle2 = motor_angle2 - 30*motor_threshold;    // Subtracting five degree angle from the current angle
         motor2.set_target_angle(motor_angle2); 
         time_passed_in_this_state2 = 0;            // Set time passed in this state back to zero
-        calibLED2 = !calibLED2;
+        calibLED2 = !calibLED2;                              // LED turns red
     }
     
     if (time_passed_in_this_state2 >= 10)           // After 5 seconds have passed (10 times Ticker motor_calib)
     {
         motor2.define_current_angle_as_x_radians(-0.733038); // Defines beginstate motor 2 as -42 degrees
         motor_calib2.detach();                      // Stop looping the function
-        calibLED3 = 0;                              // LED becomes red (purple if both motors are calibrated)
-        wait(0.1f);
-        calibLED3 = !calibLED3;
+        calibLED3 = !calibLED3;                              // LED becomes red (purple if both motors are calibrated)
     }
-    
+
     last_angle2 = current_angle2;
 }
 
@@ -87,6 +85,9 @@
     calibLED3 = 1;
     motor1.set_pid_k_values(Kp, Ki, Kd);    // Attach PID-controller values
     motor2.set_pid_k_values(Kp, Ki, Kd);
+    motor1.set_extra_reduction_ratio(-1);
+    motor2.set_extra_reduction_ratio(1);
+    
     motor1.start(pid_period);               // Attach PID sample time
     motor2.start(pid_period);
     motor_calib1.attach(Motor1_Calibration,0.2);    // Ticker for motor calibration fucntion