Eindelijk!!!!!
Fork of Movement by
Movement.cpp
- Committer:
- peterknoben
- Date:
- 2017-11-01
- Revision:
- 2:43a6498000e8
- Parent:
- 1:03e2651b4a24
- Child:
- 3:61733f7f1fea
File content as of revision 2:43a6498000e8:
#include "Movement.h" #include "mbed.h" float movement; Movement::Movement(void) { } int * Movement::getdirection(int mode){ //int *getdirection(int direction[2]){ static int direction[2]; if(mode==1){ direction[0]=1; direction[1]=1; } else if(mode==2){ direction[0]=1; direction[1]=-1; } else if(mode==3){ direction[0]=0; direction[1]=0; } else if(mode==4){ direction[0]=-1; direction[1]=-1; } else if(mode==5){ direction[0]=-1; direction[1]=1; } else if(mode==6){ direction[0]=0; direction[1]=0; } else{ //Error, unavailable mode } 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; }