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

Dependencies:   MODSERIAL mbed

Files at this revision

API Documentation at this revision

Comitter:
Duif
Date:
Mon Oct 15 09:58:09 2018 +0000
Parent:
2:8f1765df595c
Commit message:
extra explanation about code, working setpoint determination. Can also be used to determine y-setpoint, minor changes are needed. Robot specific variables still have to be set

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 8f1765df595c -r ded7541b44da main.cpp
--- a/main.cpp	Mon Oct 15 09:41:10 2018 +0000
+++ b/main.cpp	Mon Oct 15 09:58:09 2018 +0000
@@ -11,22 +11,23 @@
 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
+float v=1; //moving speed of setpoint (dependant on the waiting time)
 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 + dir*s*v*dt
 
 //function that determines the setpoint of the x coordinate
-float EMGOn(int s){
-    if (x_new < x_min)
+float EMG1On(int s){
+    if (x_new < x_min) //minimum setpoint (set above)
         x_new = x_min;
-    if (x_new > x_max)
+    if (x_new > x_max) //maximum setpoint (set above)
         x_new = x_max;
     else x_new = x_new + dir*s*v;
     return x_new;
     }
-    
+
+//function to change the moving direction of the setpoint
 void ChangeDirection(){
     dir = -1*dir;
     }
@@ -36,12 +37,11 @@
     InterruptIn direction(SW3);
     direction.fall(ChangeDirection); //change the direction of the setpoint
     
-    //InterruptIn button(SW2);
     pc.baud(115200);
     
     while (true) {  
-    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);
+    s = !button.read(); //this has to be replaced with the input from the EMG, this then functions like a button
+    pc.printf("Value: %i, Set: %f \r\n",s,EMG1On(s)); //print the value of the button to check if it is correct
+    wait(0.5f); //together with the speed (v) 
     }
 }