Determines the setpoint in x direction of the robot. Robot specific variables still have to be set.

Dependencies:   MODSERIAL mbed

Revision:
2:8f1765df595c
Parent:
1:f120a8734106
Child:
3:ded7541b44da
--- a/main.cpp	Mon Oct 08 15:39:06 2018 +0000
+++ b/main.cpp	Mon Oct 15 09:41:10 2018 +0000
@@ -7,29 +7,41 @@
 MODSERIAL pc(USBTX, USBRX); //makes sure the computer is hooked up
 
 //defining of the variables
-static float x_prev = 0; //previous setpoint
-float x_new; //new setpoint
-float x_max; //maximum value of setpoint
-float x_min; //minimum value of setpoint
-float v; //moving speed of setpoint
-volatile int s; //value of the switch
+//static float x_prev = 0; //previous setpoint
+float x_new = 0; //new setpoint
+const float x_max = 20; //maximum value of setpoint
+const float x_min = 0; //minimum value of setpoint
+float v=1; //moving speed of setpoint
+volatile int s;//value of the button and store as switch
+int dir = 1; //determine the direction of the setpoint placement
 
-//equation is x_new = x_prev + s*v*dt
+//equation is x_new = x_prev + dir*s*v*dt
 
 //function that determines the setpoint of the x coordinate
-void EMGOn(){
-    x_new = x_prev + s*v;
-    x_prev = x_new;
-    pc.printf("Set: %f",x_new);
+float EMGOn(int s){
+    if (x_new < x_min)
+        x_new = x_min;
+    if (x_new > x_max)
+        x_new = x_max;
+    else x_new = x_new + dir*s*v;
+    return x_new;
+    }
+    
+void ChangeDirection(){
+    dir = -1*dir;
     }
 
 int main()
 {
-    SetX.attach(EMGOn,1); //ticker to call the EMG function
+    InterruptIn direction(SW3);
+    direction.fall(ChangeDirection); //change the direction of the setpoint
+    
+    //InterruptIn button(SW2);
     pc.baud(115200);
     
     while (true) {  
-    s = button.read(); //read value of the button
-    pc.printf("Value: %i",s); //print the value of the button to check if it is correct
+    s = !button.read();
+    pc.printf("Value: %i, Set: %f \r\n",s,EMGOn(s)); //print the value of the button to check if it is correct
+    wait(0.5f);
     }
 }