Silvie van den Bogaard
/
determine_x_setpoint
Determines the setpoint in x direction of the robot. Robot specific variables still have to be set.
main.cpp
- Committer:
- Duif
- Date:
- 2018-10-15
- Revision:
- 2:8f1765df595c
- Parent:
- 1:f120a8734106
- Child:
- 3:ded7541b44da
File content as of revision 2:8f1765df595c:
//Determining the setpoint that the thing will have to follow #include "mbed.h" #include "MODSERIAL.h" Ticker SetX; DigitalIn button(SW2); DigitalIn direction(SW3); 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 = 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 + dir*s*v*dt //function that determines the setpoint of the x coordinate 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() { 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); } }