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:
- 4:d04afc466198
- Parent:
- 3:4f215646a42b
- Child:
- 5:e9bb800a3742
--- a/main.cpp Sun Aug 08 14:47:14 2021 +0000 +++ b/main.cpp Sun Aug 08 14:59:54 2021 +0000 @@ -12,9 +12,7 @@ /* Open issues: -- need to figure out how to handle transitions to error states -- Need to test how breaking is performed. -- ensure that motor speed is truely zero before exiting. +- Test how breaking is performed. - Test onboard current limitation */ @@ -248,7 +246,7 @@ double currentSpeed_RPM = 0.3*speed_RPM + 0.7*lastSpeedRPM;//filter speed mut1.lock();//update global variables - _demandSpeed_RPM = demandSpeedRPM; + _demandSpeed_RPM = demandSpeed_RPM; _currentSpeed_RPM = currentSpeed_RPM; mut1.unlock();//end of global variable write @@ -280,7 +278,20 @@ //exit when test has completed if ((Tnow >= SPIN_T[5]) || (localState == STATE_ERROR)){ //either if test time has expired, or if system has gone into an error state - if(deltaPulses == 0){//check if motor has come to a complete stop + Timer timerMotorStopTimeout; + bool isTimeout; + timerMotorStopTimeout.start(); + if(timerMotorStopTimeout.read() > MOTOR_STOP_TIMEOUT){ + isTimeout = 1; + } + else{ + isTimeout = 0; + } + + + if((deltaPulses == 0) || isTimeout){//check if motor has come to a complete stop or if timeout has occured + timerMotorStopTimeout.stop(); + timerMotorStopTimeout.reset(); tickerPrint.detach();//stop the print thread from firing PrintThread.terminate();//terminate print thread??? EN_FAULTA.write(0);//disable motor @@ -299,7 +310,10 @@ printf("Test complete\r\n");//Test completed cleanly } else{ - switch (errorId){ + mut1.lock(); + localErrorId = _errorId; + mut1.unlock(); + switch (localErrorId){ case ERROR_ACCEL://accelerometer detected excess vibration printf("Test terminated.\r\n Please check holder and restart system.\r\n"); break; @@ -310,7 +324,7 @@ break; } } - mut1.lock() + mut1.lock(); _state = STATE_READY;//change state mut1.unlock(); demandSpeed_RPM = 0.0;//update variables @@ -325,7 +339,7 @@ //encoderTimer.reset(); - printf("state = %d\r\n",state); + //printf("state = %d\r\n",state); TestCompleteNotification();//send notification //deactivate motor //CentrifugeTestThread.terminate();//terminate threads @@ -450,8 +464,9 @@ pinButton.rise(ISR_Button_Rise); pinButton.fall(ISR_Button_Fall); */ - - state = STATE_READY;//set state to READY + mut1.lock(); + _state = STATE_READY;//set state to READY + mut1.unlock(); //start all threads MotorControlThread.start(MotorControl);