From 61b72c2bcb2798f7b0d96f1b4ccb5e176b2051dc Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Wed, 2 Dec 2020 19:56:02 +0200 Subject: thread loading fixes --- .../Embedded/Modules/Thread/ThreadLoad.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c') diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c b/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c index f2ca4e8d7..f327ef3b2 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c @@ -258,12 +258,14 @@ { CallbackCounter--; } - if ((abs(angle)>14000 )&&(BusyFlag == NOTBUSY)) // OK - take another round + if ((abs(angle)<200 )&&(BusyFlag == NOTBUSY)) // OK { Report("Thread_Load_Set_Load_Arm_To_Stopper time",__FILE__,msec_millisecondCounter - UnloadingStart,msec_millisecondCounter,RpMessage,UnloadingStart,0); Report("Thread_Load_Set_Load_Arm_To_Stopper_Callback",__FILE__,__LINE__,LoadStages,RpMessage,CallbackCounter,0); NumberOfDrierLoaderCycles=0; + MCU_E2PromProgram(EEPROM_STORAGE_DRYER_CYCLES,0); + //storeLoadArmParameters(); LoadStages++; @@ -272,7 +274,7 @@ else { load.color = fastBILNK; - usnprintf(LoadErrorMsg, 100, "Stage %s - %s timeout",LoadStagesStr[LoadStages], MotorStr[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM]); + usnprintf(LoadErrorMsg, 100, "*Stage %s - %s timeout",LoadStagesStr[LoadStages], MotorStr[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM]); Report(LoadErrorMsg,__FILE__,__LINE__,LoadStages,RpWarning,TimeoutsCounter,0); LoadStatus = ERROR; @@ -317,7 +319,7 @@ { TimeoutsCounter = 0; load.color = fastBILNK; - usnprintf(LoadErrorMsg, 100, "Stage %s - %s timeout",LoadStagesStr[LoadStages], MotorStr[MotorId]); + usnprintf(LoadErrorMsg, 100, "/Stage %s - %s timeout",LoadStagesStr[LoadStages], MotorStr[MotorId]); Report(LoadErrorMsg,__FILE__,__LINE__,LoadStages,RpWarning,TimeoutsCounter,0); LoadStatus = ERROR; @@ -687,7 +689,7 @@ TimeoutsCounter = 0; CallbackCounter = 0; load.color = fastBILNK; - usnprintf(LoadErrorMsg, 100, "Stage %s - Dryer load arm timeout",LoadStagesStr[LoadStages]); + usnprintf(LoadErrorMsg, 100, "$Stage %s - Dryer load arm timeout",LoadStagesStr[LoadStages]); Report(LoadErrorMsg,__FILE__,__LINE__,LoadStages,RpWarning,TimeoutsCounter,0); LoadStatus = ERROR; MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM, 200); @@ -729,6 +731,13 @@ { LoadArmRounds -= CurrentlyLoaded; } + if (LoadArmRounds == CurrentlyLoaded) + { + Report("Thread_Load_Dryer_Loading no need for cycles",__FILE__,__LINE__,LoadStages,RpMessage,CallbackCounter,0); + LoadStages++; + ThreadLoadStateMachine(LoadStages); + return OK; + } ThreadMotorIdToMotorId[FEEDER_MOTOR] = HARDWARE_MOTOR_TYPE__MOTO_RDRIVING ; ThreadMotorIdToMotorId[DRYER_MOTOR] = HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING; @@ -932,7 +941,7 @@ MotorStop(HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING,Hard_Hiz); load.color = fastBILNK; - usnprintf(LoadErrorMsg, 100, "Stage %s - Dryer load arm timeout",LoadStagesStr[LoadStages]); + usnprintf(LoadErrorMsg, 100, "&Stage %s - Dryer load arm timeout",LoadStagesStr[LoadStages]); Report(LoadErrorMsg,__FILE__,__LINE__,LoadStages,RpWarning,TimeoutsCounter,0); Report("Dryer unloading timeout(1) or no movement",__FILE__,temp,DrierPrevLocation,RpWarning,ReadValue,0); LoadStatus = ERROR; @@ -1489,6 +1498,8 @@ uint32_t ThreadLoadingRestartReport(void) //sending after a failure in the final if (ThreadLoadingToken[0] == 0) return OK; + if (LoadStages == THREAD_LOAD_INIT) + return OK; ThreadLoadingRestartFlag = true; response.has_state = true; -- cgit v1.3.1 From 389aef8ec68dd58a9b40c95c5b55d339a5f67528 Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Thu, 3 Dec 2020 12:31:12 +0200 Subject: thread load merge --- .../Embedded/Drivers/Motors/MotorActions.c | 34 +++++++++++----------- .../Embedded/Modules/Thread/ThreadLoad.c | 13 +++++++-- 2 files changed, 27 insertions(+), 20 deletions(-) (limited to 'Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c') diff --git a/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c b/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c index 81e62746a..75f68d00c 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c +++ b/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c @@ -249,10 +249,10 @@ uint32_t MotorRunWithCallback (TimerMotors_t MotorId,bool direction, uint32_t Fr MotorControlCallback[MotorId] = MotorMoveCallBackFunction; return MotorControlId[MotorId]; } -uint32_t MotorRunCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO +uint32_t MotorRunCallBackFunction(uint32_t IfIndex, uint32_t ReadValue) //TODO { uint32_t MotorId,encoder,temp = 0; - uint32_t Busy = BUSY; + uint32_t RunningContinues = true; int angle; if (IfIndex>>8 != IfTypeMotors) @@ -314,17 +314,17 @@ uint32_t MotorRunCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO { Report("MotorRunCallBackFunction temp curr prev small",__FILE__,encoder,InitialArmLocation,RpWarning,temp,0); failCounter++; - if (failCounter>=20) + if (failCounter>=5) { Report("arm stopped",__FILE__,failCounter,encoder,RpWarning,temp,0); MotorStop(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Hard_Hiz); - Busy = NOTBUSY; + RunningContinues = false; } } else { failCounter = 0; - Busy = BUSY; + RunningContinues = true; } if (CallbackCalls%50 == 0) { @@ -347,7 +347,7 @@ uint32_t MotorRunCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO } MotorTimeout[MotorId]+=MotorTimeLag[MotorId]; - if ((Busy == NOTBUSY)||((MotorTimeout[MotorId]>=MotorTimeLimit[MotorId])&&(MotorTimeLimit[MotorId]>0))) + if ((RunningContinues == false)||((MotorTimeout[MotorId]>=MotorTimeLimit[MotorId])&&(MotorTimeLimit[MotorId]>0))) { if (MotorId == HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) { @@ -355,17 +355,17 @@ uint32_t MotorRunCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO if (abs(angle)<400) { - Busy = NOTBUSY; + RunningContinues = false; } else { - Busy = BUSY; + RunningContinues = true; } Report("arm stopped call",__FILE__,failCounter,encoder,RpWarning,abs(DrierZeroPosition-encoder),0); - Report("arm stopped call 2",__FILE__,MotorTimeout[MotorId],Busy,RpWarning,angle,0); + Report("arm stopped call 2",__FILE__,MotorTimeout[MotorId],RunningContinues,RpWarning,angle,0); } //stop this control loop - Report("MotorControlGetnBusyState stop",__FILE__,MotorId,Busy,RpMessage,MotorCallback[MotorId],0); + Report("MotorControlGetnBusyState stop",__FILE__,MotorId,RunningContinues,RpMessage,MotorCallback[MotorId],0); SafeRemoveControlCallback(MotorControlId[MotorId], MotorRunCallBackFunction ); MotorControlCallback[MotorId] = 0; MotorControlId[MotorId] = 0xFF; @@ -374,13 +374,13 @@ uint32_t MotorRunCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO if ((MotorTimeout[MotorId]>=MotorTimeLimit[MotorId])&&(MotorTimeLimit[MotorId]>0)) { Report("motor timeout",__FILE__,__LINE__,MotorId,RpMessage,MotorTimeout[MotorId],0); - Busy = BUSY; + RunningContinues = true; } Report("MotorRunCallBackFunction curr prev return",__FILE__,encoder,temp,RpWarning,AccumulatedArmMovement,0); //call the module callback if (MotorCallback[MotorId]) { - MotorCallback[MotorId](MotorId,Busy); + MotorCallback[MotorId](MotorId,RunningContinues); } } @@ -620,8 +620,8 @@ uint32_t MotorMovetoEncoderPosition (TimerMotors_t MotorId, callback_fptr callb currentposition = Control_Read_Dryer_Position(0,0); MCU_E2PromRead(EEPROM_STORAGE_DRYER_CENTER,&DrierZeroPosition); Report("MotorMovetoEncoderPosition",__FILE__,__LINE__,DrierZeroPosition,RpWarning,currentposition,0); - Report("MotorMovetoEncoderPosition callback",__FILE__,__LINE__,callback,RpWarning,speed,0); - if (abs(currentposition - DrierZeroPosition)<5) + Report("MotorMovetoEncoderPosition callback",__FILE__,__LINE__,direction,RpWarning,speed,0); + if (abs(currentposition - DrierZeroPosition)<2) { if (callback) callback(MotorId,0); @@ -669,7 +669,7 @@ uint32_t MotorMoveCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO { Read_Dryer_ENC_Position(); if (CallbackCalls<50) - return; + return OK; if (CallbackCalls%200 == 0) { Report("MotorMoveCallBackFunction",__FILE__,__LINE__,MotorId,RpWarning,Read_Dryer_ENC_Position(0,0),0); @@ -1170,11 +1170,11 @@ uint32_t LoadingArmReset_Callback(uint32_t MotorId, uint32_t ReadValue) //if (fabs(angle)<0.2) { ReportWithPackageFilter(DiagnosticsFilter,"drier center proximity",__FILE__,temp,Arm_Drier_Center,RpMessage,angle,0); - if (angle<400) + if (angle>0) direction = 1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize; else direction = MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize; - MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,LoadingArmReset_Callback_Stopper_Callback,/*3000*/16000,direction,10); + MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,LoadingArmReset_Callback_Stopper_Callback,/*3000*/16000,direction,5); } else diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c b/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c index f327ef3b2..ffbb504db 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c @@ -247,7 +247,8 @@ } uint32_t Thread_Load_Set_Load_Arm_To_Stopper_Callback(uint32_t deviceID, uint32_t BusyFlag) { - uint32_t angle, temp = Read_Dryer_ENC_Position(); + uint32_t temp = Read_Dryer_ENC_Position(); + int angle; ReportWithPackageFilter(DiagnosticsFilter,"Thread_Load_Set_Load_Arm_To_Stopper_Callback",__FILE__,(int)numberOfCycles,(int)DrierPrevLocation,RpMessage,temp,0); @@ -258,7 +259,7 @@ { CallbackCounter--; } - if ((abs(angle)<200 )&&(BusyFlag == NOTBUSY)) // OK + if (abs(angle)<10 ) // OK { Report("Thread_Load_Set_Load_Arm_To_Stopper time",__FILE__,msec_millisecondCounter - UnloadingStart,msec_millisecondCounter,RpMessage,UnloadingStart,0); @@ -274,7 +275,7 @@ else { load.color = fastBILNK; - usnprintf(LoadErrorMsg, 100, "*Stage %s - %s timeout",LoadStagesStr[LoadStages], MotorStr[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM]); + usnprintf(LoadErrorMsg, 100, "^Stage %s - %s timeout",LoadStagesStr[LoadStages], MotorStr[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM]); Report(LoadErrorMsg,__FILE__,__LINE__,LoadStages,RpWarning,TimeoutsCounter,0); LoadStatus = ERROR; @@ -1531,6 +1532,12 @@ uint32_t TryThreadLoadingFunc(MessageContainer* requestContainer) { responseContainer = createContainer(MESSAGE_TYPE__TryThreadLoadingResponse, requestContainer->token, true, &Cresponse, &try_thread_loading_response__pack, &try_thread_loading_response__get_packed_size); responseContainer.continuous = false; + if (JobIsActive()||(MachineReadyForHeating == false)||(FPGABurningActive==true)) + { + responseContainer.has_error = true; + responseContainer.error = ERROR_CODE__GENERAL_ERROR; + responseContainer.errormessage = "The machine is not ready for loading"; + } uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer)); size_t container_size = message_container__pack(&responseContainer, container_buffer); my_free(responseContainer.data.data); -- cgit v1.3.1