control flow doet nog niks

Dependencies:   Encoder HIDScope MODSERIAL mbed

Revision:
7:4df9f6ebe744
Parent:
6:9c8e91bb1316
Child:
8:00c3992af9f4
--- a/main.cpp	Sat Oct 10 20:38:38 2015 +0000
+++ b/main.cpp	Mon Oct 12 08:44:50 2015 +0000
@@ -58,6 +58,7 @@
     DigitalOut ledblue(LED3);
 
 // REFERENCE SIGNAL SETTINGS
+    double input_threshold = 0.25;   // the minimum value the signal must have to change the reference.
     // Define signal amplification  (needed with EMG, used in control loop, precise amp determination is a work in progress!!!!)    ??
     double signalamp1 = 1;
     double signalamp2 = 1;
@@ -150,8 +151,8 @@
 }
 
 
-// This functions takes a 0->1 input converts it to -1->1 and uses passing by reference (&c_reference)
-// to create a reference that moves with a variable speed. It is now set up for potmeter values.  
+// This functions takes a 0->1 input, uses passing by reference (&c_reference)
+// to create a reference that moves with a variable speed. It is now optimised for 0->1 values
 double reference_f(double input, double &c_reference)
 {
     double reference = c_reference + input * controlstep * Vmax ;
@@ -250,9 +251,11 @@
 void motor1_control()
 {
     
-    double input1 = potright.read()*signalamp1;
-    if(input1 < 0.25) {input1 = 0;}
+    double input1 = potright.read()*signalamp1; // this line must be seperated for emg usage
+    // first data limiter
+    if(input1 < input_threshold) {input1 = 0;}
     if(input1 > 1) {input1 = 1;}
+    // reverse direction
     if(reverse_rechts == true) {input1 = -input1;}
     double reference1 = reference_f(input1, c_reference1);      // determine the reference that has been set by the inputsignal
     double rads1 = get_radians(motor1_enc.getPosition());    // determine the position of the motor
@@ -272,8 +275,10 @@
 void motor2_control()
 {
     double input2 = potleft.read()*signalamp2;      // replace potleft with filter
-    if(input2 < 0.25) {input2 = 0;}
+    // first input limiter
+    if(input2 < input_threshold) {input2 = 0;}
     if(input2 > 1) {input2 = 1;}
+    // reverse direction
     if(reverse_links == true) {input2 = -input2;}
     double reference2 = reference_f(input2, c_reference2);      // determine the reference that has been set by the clamped inputsignal
     double rads2 = get_radians(motor2_enc.getPosition());    // determine the position of the motor
@@ -327,11 +332,11 @@
         // reverse buttons
         if(reverse_button_links.read() == 0)
         {
-            reverse_links = !reverse_links;     
-            wait(reverse_button_links.read() == 1);
-            wait(0.3);             
+           reverse_links = !reverse_links;     
+           wait(reverse_button_links.read() == 1);
+           wait(0.3);             
         }
-        if(reverse_button_rechts.read() == 0)
+         if(reverse_button_rechts.read() == 0)
         {
             reverse_rechts = !reverse_rechts;     
             wait(reverse_button_rechts.read() == 1);
@@ -341,29 +346,14 @@
         if(loop_start == true && calib_start == false)        // check if start button = true then start the main control loops
         {
             LED(1,1,0); // turn blue led on
-                     
-            if(motor1_go)
-            {
-                motor1_go = false;
-                motor1_control();
-            }
-            if(motor2_go)
-            {
-                motor2_go = false;
-                motor2_control();
-            }
+            if(motor1_go) { motor1_go = false; motor1_control();}
+            if(motor2_go) { motor2_go = false; motor2_control();}
         }
-        if(loop_start == false && calib_start == true)          // start calibration procedures
-        {
-           LED(1,0,1); // turn green led on
-        }
-        if(loop_start == true && calib_start == true)           // check if both buttons are enabled and stop everything
-        {
-            LED(0,1,1); // turn red led on
-        }
-        else
-        {
-           LED(1,1,1); // turn leds off (both buttons false)
-        }
+        // turn green led on // start calibration procedures
+        if(loop_start == false && calib_start == true) { LED(1,0,1);}
+        // turn red led on
+        if(loop_start == true && calib_start == true) { LED(0,1,1);}
+        // turn leds off (both buttons false)
+        else { LED(1,1,1);}
     }
 }
\ No newline at end of file