Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HIDScope MODSERIAL QEI TextLCD mbed
Fork of TotalControlEmg2 by
Diff: main.cpp
- Revision:
- 57:eea0d7265b22
- Parent:
- 56:1ac2487a9610
--- a/main.cpp Thu Oct 29 13:48:53 2015 +0000 +++ b/main.cpp Thu Oct 29 16:30:51 2015 +0000 @@ -34,7 +34,7 @@ int maxCounts = 0; // max richt motor counts Aim motor int breakPerc = 0; // Break part {0, 1 , 2 ,3}/4 of half revolution volatile int modeL = 1, modeR = 1; // modes left and right -const double servoBreak = 0.0017, servoFree = 0.0020; // Range servo,between servoL en servoR (= pulsewidth pwm servo) +const double servoBreak = 0.00165, servoFree = 0.0020; // Range servo,between servoL en servoR (= pulsewidth pwm servo) const double tControl = 0.01, tLcd = 2, tEmg = 0.005; // ticker time (sec) const double wM2 = 0.31; double thresholdlowL= 0, thresholdmidL = 0, thresholdhighL= 0; @@ -140,18 +140,18 @@ controlFlag = true; } void checkSide(AnalogIn& ks, int dir){ - if((dirM2.read() == dir) && (pwmM2.read()>0)){ // direction motor clashes with killswitch and motor is on - if(ks.read()>0.95){ - pwmM2.write(0); // Aim motor freeze - PRINT("BOEM! CRASH!"); // LCD - pc.printf("BOEM! CRASH! KASTUK!\r\n"); // Terminal - wait(1); - } + if((ks.read()>0.95) && (dirM2.read() == dir)){ + pwmM2.write(0); // Aim motor freeze + PRINT("BOEM! CRASH!"); // LCD + pc.printf("BOEM! CRASH! KASTUK!\r\n"); // Terminal + wait(1); } } void checkAim(){ // check if killswitch clashes with direction motor - checkSide(ksLeft, 1); - checkSide(ksRight, 0); + if(pwmM2.read()>0){ // direction motor clashes with killswitch and motor is on + checkSide(ksLeft, 1); + checkSide(ksRight, 0); + } } void motorAim(int dir){ // Rotate Aim motor with given direction dirM2.write(dir); @@ -181,7 +181,7 @@ else if((modeR == 2)) { // modeR ==2 if(aimState != CCW){ aimState = CCW; // Rotate CCW - pc.printf("Rotate -, CCW\r\n"); + pc.printf("Rotate -, CW\r\n"); PRINT("Rotate CW"); motorAim(0); } @@ -189,7 +189,7 @@ else if((modeL == 2)) { // modeL == 2 if(aimState != CW){ aimState = CW; // Rotate CW - pc.printf("Rotate +, CW\r\n"); + pc.printf("Rotate +, CCW\r\n"); PRINT("Rotate CCW"); motorAim(1); } @@ -216,7 +216,7 @@ pc.printf("---NEW GAME---\r\n"); PRINT("--- NEW GAME ---"); // LCD - if(potL.read() > 0.3 || potR.read() > 0.3){ + if(potL.read() > 0.3 || potR.read() > 0.3){ // check if one of potmeters is on pc.printf("Potentialmeter is on!!!\r\n"); } @@ -300,6 +300,7 @@ lcd.cls(); break; } + // Game stages: case AIM: { pc.printf("Aim with EMG\r\n"); // terminal int i = 0; // counter for lcd @@ -382,7 +383,7 @@ if(lcdFlag){ // every 2 seconds update lcd lcdFlag = false; lcd.cls(); - lcd.printf("Break scale 0 - 4: %i", breakPerc); + lcd.printf("Break scale 0 - 3: %i", breakPerc); } } }