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.
Diff: main.cpp
- Revision:
- 16:cefb22c49c2f
- Parent:
- 15:f86310960aab
- Child:
- 17:eb74805e8f9b
--- a/main.cpp Thu Aug 12 16:53:02 2021 +0000 +++ b/main.cpp Thu Aug 12 17:39:38 2021 +0000 @@ -147,10 +147,12 @@ double timeElapsed = testTimer.read(); double timeRemaining = SPIN_T[5] - timeElapsed; int displayTime = int(timeRemaining)+1; - printf("Time remaining %d s\r\n", displayTime); + //mut1.lock(); double printDemandSpeed = demandSpeed_RPM; double printCurrentSpeed = currentSpeedRPM; + int intCurrentSpeed = int(printCurrentSpeed); + printf("Current Speed %d RPM.\t Time remaining %d s\r\n",intCurrentSpeed, displayTime); //mut1.unlock(); //printf("%f\t%f\r\n", currentSpeedRPM,_MagFil); //printf("%f\t%f\r\n", printDemandSpeed,printCurrentSpeed); @@ -172,6 +174,18 @@ } } +bool isSpinning(){ + int pulses1 = encoder.getPulses(); + wait(0.1); + int pulses2 = encoder.getPulses(); + int difference = pulses2 - pulses1; + if (abs(difference) > 10){ + return 1; + }else{ + return 0; + } +} + void MotorControl(){ double Ax, Ay, Az, Mag; static double MagFil, lastAx, lastAy, lastAz; @@ -293,9 +307,12 @@ PWMA.write(0.0); //add check if motor has stopped - ThisThread::sleep_for(500); - EN_FAULTA.write(0);//disable motor - EN_FAULTB.write(0); + printf("Wating for motor to stop.\r\n"); + while(isSpinning()){ + ThisThread::sleep_for(200); + } + //EN_FAULTA.write(0);//disable motor + //EN_FAULTB.write(0); tickerMotorControl.detach(); //detach the semaphore release for motor control tickerPrint.detach(); @@ -348,17 +365,7 @@ semButton.release(); } -bool isSpinning(){ - int pulses1 = encoder.getPulses(); - wait(0.1); - int pulses2 = encoder.getPulses(); - int difference = pulses2 - pulses1; - if (abs(difference) > 10){ - return 1; - }else{ - return 0; - } -} + void ReadButton() { @@ -467,7 +474,7 @@ PHB.write(0); EN_FAULTB.write(0); - EN_FAULTA.write(0); + EN_FAULTA.write(1);//remove incase of restart? STBY.write(1); //calculate filter constant speedFilterConstant = 2*3.141593*SAMPLE_TIME_US/1000000*FILTER_CUTOFF_FREQ;