Working, Clean

Fork of Movement by Dustin Berendsen

Revision:
3:61733f7f1fea
Parent:
2:43a6498000e8
Child:
4:c81764efe40d
--- a/Movement.cpp	Wed Nov 01 13:42:11 2017 +0000
+++ b/Movement.cpp	Wed Nov 01 22:23:17 2017 +0000
@@ -1,13 +1,109 @@
 #include "Movement.h"
 #include "mbed.h"
 
-float movement;
+float movement_left, movement_right;
 
 Movement::Movement(void)
 {
     
 }
 
+int Movement::getdirectionLeft(int mode){
+    int directionL;
+    if(mode==1 || mode==2){
+        directionL = 1;
+    }
+    else if (mode==4 || mode==5){
+        directionL = -1;
+    }
+    else{
+        directionL = 0;
+    }
+    return directionL;
+}
+
+int Movement::getdirectionRight(int mode){
+    int directionR;
+    if(mode==1 || mode==5){
+        directionR = 1;
+    }
+    else if (mode==2 || mode==4){
+        directionR = -1;
+    }
+    else{
+        directionR = 0;
+    }
+    return directionR;
+}
+
+
+float Movement::getpositionLeft(int SignalNumber, int mode, float max_range){
+    static float positionLeft;                   //Define a position array
+    int directionLeft = getdirectionLeft(mode);
+    float position_math_left;
+    switch(SignalNumber){
+        case 1: //Move slowest
+            movement_left = directionLeft*0.25;
+            position_math_left = positionLeft + movement_left;
+            if (position_math_left >= max_range || position_math_left <=0){
+                positionLeft = positionLeft;
+            }
+            else{
+                positionLeft += movement_left;
+            }
+            break;
+        case 2: //Move slow
+            movement_left = directionLeft *1;
+            position_math_left = positionLeft + movement_left;
+            if (position_math_left >= max_range || position_math_left <=0){
+                positionLeft = positionLeft;
+            }
+            else{
+                positionLeft += movement_left;
+            }
+            break;
+        default : //if something is wrong or no muscles are flexed, standstill
+            positionLeft = positionLeft;
+            break; 
+    }
+    return positionLeft;
+}
+
+float Movement::getpositionRight(int SignalNumber, int mode, float max_range){
+    static float positionRight;                   //Define a position array
+    int directionRight = getdirectionRight(mode);
+    float position_math_right;
+    switch(SignalNumber){
+        case 1: //Move slowest
+            movement_right = directionRight*0.25;
+            position_math_right = positionRight + movement_right;
+            if (position_math_right >= max_range || position_math_right <=0){
+                positionRight = positionRight;
+            }
+            else{
+                positionRight += movement_right;
+            }
+            break;
+        case 2: //Move slow
+            movement_right = directionRight *1;
+            position_math_right = positionRight + movement_right;
+            if (position_math_right >= max_range || position_math_right <=0){
+                positionRight = positionRight;
+            }
+            else{
+                positionRight += movement_right;
+            }
+            break;
+        default : //if something is wrong or no muscles are flexed, standstill
+            positionRight = positionRight;
+            break; 
+    }
+    return positionRight;
+}
+
+
+/*
+
 int * Movement::getdirection(int mode){
 //int *getdirection(int direction[2]){
     static int direction[2];
@@ -40,58 +136,4 @@
     }
     return direction;
 }
-
-
-float Movement::getposition(int SignalNumber, int mode, int side, float max_range){
-    static float position;                   //Define a position array
-    int *direction_math;                        //Define a useable direction array in this function
-    direction_math = getdirection(mode);            //Fill the useable direction array 
-    float position_math;
-    switch(SignalNumber){
-        case 1: //Move slowest
-            movement = direction_math[side] *1;
-            position_math = position + movement;
-            if (position_math >= max_range && position_math <=0){
-                position = position;
-            }
-            else{
-                position += movement;
-            }
-            break;
-        case 2: //Move slow
-            movement = direction_math[side] *2;
-            position_math = position + movement;
-            if (position_math >= max_range && position_math <=0){
-                position = position;
-            }
-            else{
-                position += movement;
-            }
-            break;
-        case 3: //Move fast
-            movement = direction_math[side] *5;
-            position_math = position + movement;
-            if (position_math >= max_range && position_math <=0){
-                position = position;
-            }
-            else{
-                position += movement;
-            }
-            break;
-        case 4: //Move fastest
-            movement = direction_math[side] *10;
-            position_math = position + movement;
-            if (position_math >= max_range && position_math <=0){
-                position = position;
-            }
-            else{
-                position += movement;
-            }
-            break;
-        default : //if something is wrong or no muscles are flexed, standstill
-            position = position;
-            break; 
-    }
-    return position;
-}
-
+*/
\ No newline at end of file