Dependencies: mbed
Revision 1:be295a50eb53, committed 2017-11-01
- Comitter:
- charloverwijk
- Date:
- Wed Nov 01 13:58:51 2017 +0000
- Parent:
- 0:0a4a244cb867
- Commit message:
- State Machine
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Nov 01 08:17:54 2017 +0000 +++ b/main.cpp Wed Nov 01 13:58:51 2017 +0000 @@ -1,9 +1,10 @@ #include "mbed.h" -enum States (Cal1, Cal2, Home, EMG); +enum States (Cal1, Cal2, CalEMG, Home, EMG, Rest, Demo); int State, Counter; bool Position_controller_on; float Looptime = 0.002f; +volatile vorigepositie int main() { @@ -17,17 +18,49 @@ void Loop_funtion() { switch(State){ - case Cal1: //Substract the motorpositions - if (fabs(Huidigepositie - + case Cal1: //Calibration motor 1 + if (Huidigepositie1== 0) + { + SetMotor1(value); //value is waarde encoder voor loodrechte hoeken,. + if (fabs(huidigepositie1-home1)<0.01) { + state=Cal2 + } + } + else { + SetMotor1(0); + Loop_function(); + } break; - case Cal2: //Substract the motorpositions + case Cal2: //Calibration motor 2 + if (Huidigepositie2== 0) + { + if (encoder2.read)<0.01){ + state=CalEMG; + } + else { + SetMotor2(0); + Loop_function(); + } + break; + case CalEMG: // Calibration EMG + calibrationEMG(); //calculates average EMGFiltered at rest and measures max signal EMGFiltered. + //measure mean at restand substract always--> no treshold needed. + //1/MVC + state=SelectDevice; + break; + case SelectDevice: //Looks at the difference between current position and home. Select aansturen EMG or buttons + if button=1; { + state=EMG; + } + if button=0; { + state=Demo; + } break; - case Home: //Looks at the difference between current position and home + case EMG: //Aansturen met EMG break; - - case EMG: //If the EMG is higher then a certain value then the pdotrefx will change otherwise the value will become 0 + case Demo: // Aansturen met toetsenbord break; }