diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2020-12-02 19:56:02 +0200 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2020-12-02 19:56:02 +0200 |
| commit | 61b72c2bcb2798f7b0d96f1b4ccb5e176b2051dc (patch) | |
| tree | d387095cc3ea40a03eb2ddd2e18d47281c32fd3d /Software/Embedded_SW | |
| parent | fbfe1b3cc3024a6b0401fb0a2c53bead70462338 (diff) | |
| download | Tango-61b72c2bcb2798f7b0d96f1b4ccb5e176b2051dc.tar.gz Tango-61b72c2bcb2798f7b0d96f1b4ccb5e176b2051dc.zip | |
thread loading fixes
Diffstat (limited to 'Software/Embedded_SW')
4 files changed, 45 insertions, 27 deletions
diff --git a/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c b/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c index 4722bfe2f..81e62746a 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c +++ b/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c @@ -44,9 +44,6 @@ uint32_t DrierZeroPosition = 0; //bool DrierBackLashDirection = false; uint32_t Arm_Drier_Center = 0; callback_fptr UnloadingReset = NULL; -/*int CallbackCalls=0; -int FirstCall = 0; -#define MAX_CONTROL_SAMPLES 10*/ int32_t ArmSamples[MAX_CONTROL_SAMPLES] = {0}; int ArmSamplePointer = {0}; int StoredavreageSampleValue = 0; @@ -214,6 +211,7 @@ uint32_t MotorGotoWithBusyCallback (TimerMotors_t MotorId,bool direction, uint32 //MotorStop(MotorId,Hard_Hiz ); int sign = direction?1:-1; MotorGoTo(MotorId,Steps*sign ); + CallbackCalls = 0; MotorControlId[MotorId] = AddControlCallback(NULL, MotorMoveCallBackFunction, /*eTenMillisecond*/20, MotorControlGetnBusyState,(IfTypeMotors*0x100+MotorId), MotorId, 0 ); MotorControlCallback[MotorId] = MotorMoveCallBackFunction; return MotorControlId[MotorId]; @@ -232,6 +230,7 @@ uint32_t MotorRunWithCallback (TimerMotors_t MotorId,bool direction, uint32_t Fr MotorTimeout[MotorId] = 0; MotorTimeLag[MotorId] = 20; MotorTimeLimit[MotorId] = timeout; + CallbackCalls = 0; if (MotorId ==HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) { InitialArmLocation = Read_Dryer_ENC_Position(0,0); @@ -289,7 +288,7 @@ uint32_t MotorRunCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO } } } - else //loading - going up + /*else //loading - going up { //previous number is smaller than current if (InitialArmLocation<encoder) @@ -310,32 +309,32 @@ uint32_t MotorRunCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO InitialArmLocation=encoder; } } - } + }*/ if (((temp>1000)||(temp<20))&&(CallbackCalls>10)) { - Report("MotorRunCallBackFunctionMotorRunCallBackFunction temp curr prev small",__FILE__,encoder,InitialArmLocation,RpWarning,temp,0); + Report("MotorRunCallBackFunction temp curr prev small",__FILE__,encoder,InitialArmLocation,RpWarning,temp,0); failCounter++; if (failCounter>=20) { Report("arm stopped",__FILE__,failCounter,encoder,RpWarning,temp,0); MotorStop(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Hard_Hiz); - BusyFlag = NOTBUSY; + Busy = NOTBUSY; } } else { failCounter = 0; - BusyFlag = BUSY; + Busy = BUSY; } if (CallbackCalls%50 == 0) { //encoder = Read_Dryer_ENC_Position(0,0); - Report("MotorRunCallBackFunctionMotorRunCallBackFunction periodic curr prev total",__FILE__,encoder,temp,RpWarning,AccumulatedArmMovement,0); + Report("MotorRunCallBackFunction periodic curr prev total",__FILE__,encoder,temp,RpWarning,AccumulatedArmMovement,0); } if (CallbackCalls%200 == 0) { //encoder = Read_Dryer_ENC_Position(0,0); - Report("MotorRunCallBackFunctionMotorRunCallBackFunction",__FILE__,__LINE__,encoder,RpWarning,CallbackCalls,0); + Report("MotorRunCallBackFunction",__FILE__,__LINE__,encoder,RpWarning,CallbackCalls,0); } } else @@ -348,24 +347,25 @@ uint32_t MotorRunCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO } MotorTimeout[MotorId]+=MotorTimeLag[MotorId]; - if ((BusyFlag == NOTBUSY)||((MotorTimeout[MotorId]>=MotorTimeLimit[MotorId])&&(MotorTimeLimit[MotorId]>0))) + if ((Busy == NOTBUSY)||((MotorTimeout[MotorId]>=MotorTimeLimit[MotorId])&&(MotorTimeLimit[MotorId]>0))) { if (MotorId == HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) { - angle = Calculate_Arm_Distance(Arm_Drier_Center,temp); + angle = Calculate_Arm_Distance(Arm_Drier_Center,encoder); if (abs(angle)<400) { - BusyFlag = NOTBUSY; + Busy = NOTBUSY; } else { - BusyFlag = BUSY; + Busy = BUSY; } Report("arm stopped call",__FILE__,failCounter,encoder,RpWarning,abs(DrierZeroPosition-encoder),0); + Report("arm stopped call 2",__FILE__,MotorTimeout[MotorId],Busy,RpWarning,angle,0); } //stop this control loop - Report("MotorControlGetnBusyState stop",__FILE__,MotorId,BusyFlag,RpMessage,MotorCallback[MotorId],0); + Report("MotorControlGetnBusyState stop",__FILE__,MotorId,Busy,RpMessage,MotorCallback[MotorId],0); SafeRemoveControlCallback(MotorControlId[MotorId], MotorRunCallBackFunction ); MotorControlCallback[MotorId] = 0; MotorControlId[MotorId] = 0xFF; @@ -398,7 +398,7 @@ uint32_t MotorMoveWithCallback (TimerMotors_t MotorId,bool direction, uint32_t S Report("MotorControlGetnBusyState print",__FILE__,__LINE__,MotorDriverResponse[MotorId].Busy,RpMessage,0,0); }*/ ReportWithPackageFilter(GeneralFilter,"MotorMoveWithCallback",__FILE__,direction,MotorId,RpMessage,Steps,0); - + CallbackCalls = 0; //call driver action to device id with the parameter //SetMotorSpeed (deviceId, parameter); MotorCallback[MotorId] = callback; @@ -542,6 +542,7 @@ uint32_t MotorMoveToStopper (TimerMotors_t MotorId,bool direction, uint32_t Spee Task_sleep(10); Initialcurrentposition = Read_Dryer_ENC_Position(); cycles = 0; + CallbackCalls = 0; StoredMotorPosition[MotorId] = Read_Dryer_ENC_Position(); Report("MotorMoveToStopper initial position",__FILE__,__LINE__,StoredMotorPosition[MotorId],RpWarning,Initialcurrentposition,0); MotorSetSpeed (MotorId, Speed); @@ -664,9 +665,11 @@ uint32_t MotorMoveCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO } MotorId = IfIndex&0xFF; CallbackCalls++; - if (MotorId ==HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) { + Read_Dryer_ENC_Position(); + if (CallbackCalls<50) + return; if (CallbackCalls%200 == 0) { Report("MotorMoveCallBackFunction",__FILE__,__LINE__,MotorId,RpWarning,Read_Dryer_ENC_Position(0,0),0); @@ -1157,7 +1160,7 @@ uint32_t LoadingArmReset_Callback(uint32_t MotorId, uint32_t ReadValue) uint32_t temp = Read_Dryer_ENC_Position(); angle = Calculate_Arm_Distance(Arm_Drier_Center,temp); ReportWithPackageFilter(DiagnosticsFilter,"LoadingArmReset_Callback",__FILE__,angle,temp,RpMessage,Arm_Drier_Center,0); - //ReportWithPackageFilter(DiagnosticsFilter,"Diagnostics_Dryer_UnLoading_Callback details",__FILE__,(int)(TotalLoadedLen),D_numberOfCycles,RpMessage,CallbackCounter,0); + //ReportWithPackageFilter(DiagnosticsFilter,"Diagnostics_Dryer_UnLoading_Callback details",__FILE__,__LINE__,ReadValue,RpMessage,0,0); //if ((AccumulatedArmMovement>8000 )&&(ReadValue == NOTBUSY)) // OK - take another round if (ReadValue == NOTBUSY) // OK - take another round { @@ -1189,6 +1192,7 @@ uint32_t LoadingArmReset_Callback(uint32_t MotorId, uint32_t ReadValue) else //timeout or no movement { ReportWithPackageFilter(DiagnosticsFilter,"Unloading drier - halted",__FILE__,__LINE__,Arm_Drier_Center,RpMessage,0,0); + MotorStop(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Hard_Stop); //MCU_E2PromProgram(EEPROM_STORAGE_DRYER_CYCLES,LoadArmRounds-(D_numberOfCycles-2));//it takes two cycles to identify a stop of the arm ReportWithPackageFilter(DiagnosticsFilter,"Dryer unloading timeout(1) or no movement",__FILE__,temp,Arm_Drier_Center,RpWarning,ReadValue,0); @@ -1217,7 +1221,8 @@ uint32_t LoadingArmReset (callback_fptr callback,uint32_t timeout) //TODO ReportWithPackageFilter(DiagnosticsFilter,"LoadingArmReset",__FILE__,__LINE__,timeout,RpMessage, 0,0); MotorRunWithCallback (HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM, 1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize, - MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulseperround/4*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulleyradius, LoadingArmReset_Callback, 300000); + MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulseperround/4*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulleyradius, + LoadingArmReset_Callback, 300000); return OK; diff --git a/Software/Embedded_SW/Embedded/Modules/Diagnostics/DiagnosticsHoming.c b/Software/Embedded_SW/Embedded/Modules/Diagnostics/DiagnosticsHoming.c index 7e1424b8a..d20cd65d5 100644 --- a/Software/Embedded_SW/Embedded/Modules/Diagnostics/DiagnosticsHoming.c +++ b/Software/Embedded_SW/Embedded/Modules/Diagnostics/DiagnosticsHoming.c @@ -615,13 +615,14 @@ uint32_t Diagnostics_Dryer_MovetoEncoderPosition_Callback(uint32_t MotorId, uint uint32_t Diagnostics_Dryer_Loading_Callback(uint32_t MotorId, uint32_t ReadValue) { D_numberOfCycles++; - uint32_t angle, temp = Read_Dryer_ENC_Position(); + int angle; + uint32_t temp = Read_Dryer_ENC_Position(); angle = Calculate_Arm_Distance(D_DrierPrevLocation,temp); ReportWithPackageFilter(DiagnosticsFilter,"Diagnostics_Dryer_Loading_Callback",__FILE__,(int)angle,(int)ReadValue,RpMessage,temp,0); MCU_E2PromProgram(EEPROM_STORAGE_DRYER_CYCLES,D_numberOfCycles); - if ((abs(angle)>14000 )&&(ReadValue == NOTBUSY)) // OK - take another round + if ((abs(angle)<400 )&&(ReadValue == NOTBUSY)) // OK - take another round { D_DrierPrevLocation = temp; ReportWithPackageFilter(DiagnosticsFilter,"Diagnostics_Dryer_Loading_Callback",__FILE__,ReadValue,temp,RpMessage,angle,0); @@ -653,6 +654,7 @@ uint32_t Diagnostics_Dryer_Loading(void) if (dryerbufferlength) LoadArmRounds = (int)dryerbufferlength; MCU_E2PromRead(EEPROM_STORAGE_DRYER_CENTER,&D_DrierPrevLocation); + //MCU_E2PromProgram(EEPROM_DRIER_LOADING_ARM_ANGLE,Calc_angle); ReportWithPackageFilter(DiagnosticsFilter,"Diagnostics_Dryer_Loading request: current ",__FILE__,D_DrierPrevLocation,D_numberOfCycles,RpMessage,LoadArmRounds,0); Drier_Center_read = D_DrierPrevLocation; diff --git a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_Blowers.c b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_Blowers.c index eefd42d75..2f8de1643 100644 --- a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_Blowers.c +++ b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_Blowers.c @@ -260,7 +260,7 @@ void setArcHeadAlarms(uint32_t AlarmId, bool value) } void FlatHeadAlarms(void) { - if (FPGA_Read_limit_Switches(Motor_Id_to_LS_IdUp [HARDWARE_MOTOR_TYPE__MOTO_DH_LID]) != LIMIT) { + if (FPGA_Read_limit_Switches(Motor_Id_to_LS_IdUp [HARDWARE_MOTOR_TYPE__MOTO_DH_LID]) == LIMIT) { if (++count9 == ARC_ALARM_LIMIT) setArcHeadAlarms(EVENT_TYPE__DYEING_HEAD_COVER_IS_OPEN, true); count9 = (count9 > ARC_ALARM_LIMIT)?(ARC_ALARM_LIMIT):(count9); 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; |
