diff options
Diffstat (limited to 'Software/Embedded_SW/Embedded/Modules/Thread')
3 files changed, 68 insertions, 46 deletions
diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c index ccc9623a3..c7dd4f7ae 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c @@ -107,7 +107,7 @@ uint32_t Winder_PrepareStage2(uint32_t deviceID, uint32_t ReadValue) uint32_t status=OK; uint32_t numOfSteps = InternalWinderCfg.startoffsetpulses*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep; - MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].maxfrequency); + MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,InternalWinderCfg.segmentoffsetpulses); //REPORT_MSG(numOfSteps, "Winder_PrepareStage2"); REPORT_MSG(MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].maxfrequency, "Winder_PrepareStage2"); diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h index 2961bd105..c5e3edc85 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h @@ -27,6 +27,7 @@ uint32_t InternalWindingConfigMessage(JobSpool* request); uint32_t ThreadConfigBreakSensor(void *request); uint32_t ThreadGetMotorSpeed(threadMotorsEnum MotorId); +double ThreadGetMotorCalculatedError(int DancerId); uint32_t ThreadPrepareState(void *JobDetails); uint32_t ThreadPreSegmentState(void *JobDetails); uint32_t ThreadSegmentState(void *JobDetails, int SegmentId); diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c index 05c6c9003..54309a187 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c @@ -70,10 +70,12 @@ double TotalProcessedLength = 0.0; double LengthCalculationMultiplier; uint32_t PoolerPreviousPosition = 0, PoolerCurrentPosition = 0; -double PoolerCurrentProcessedLength = 0.0; double PoolerTotalProcessedLength = 0.0; double PoolerLengthCalculationMultiplier; +double TempPoolerTotalProcessedLength = 0.0; +double TempTotalProcessedLength = 0.0; + bool PrepareState = false; int CurrentSegmentId = 0; typedef void (* ProcessedLengthFunc)(void); @@ -132,22 +134,21 @@ void ThreadUpdateProcessLength (double length, void *Funcptr) { CurrentRequestedLength = length*100;//Centimetres CurrentProcessedLength = 0; - PoolerCurrentProcessedLength = 0; ProcessedLengthFuncPtr = (ProcessedLengthFunc)Funcptr; initialpos = 0xFFFF; Poolerinitialpos = 0xFFFF; } - +char Lenstr[150]; uint32_t ThreadLengthCBFunction(uint32_t IfIndex, uint32_t ReadValue) { uint32_t positionDiff = 0; double length = 0.0; - char str[150]; + int index = MAX_THREAD_MOTORS_NUM; - if (ThreadControlActive == false) - return OK; - if (PrepareState == true) - return OK; + // if (ThreadControlActive == false) + // return OK; + // if (PrepareState == true) + // return OK; if (IfIndex>>8 != IfTypeThread) { LOG_ERROR (IfIndex, "Wrong Interface type"); @@ -184,14 +185,15 @@ uint32_t ThreadLengthCBFunction(uint32_t IfIndex, uint32_t ReadValue) static int pooler_counter = 0; pooler_counter++; TotalProcessedLength+= (length/100); + TempTotalProcessedLength = TotalProcessedLength; if (pooler_counter%10 == 0) { if (PrepareState == true) { //later - add temperatures - TemperatureListString(str); + TemperatureListString(Lenstr); - SendJobProgress(0.0,0,false, str); + SendJobProgress(0.0,0,false, Lenstr); } else { @@ -201,9 +203,9 @@ uint32_t ThreadLengthCBFunction(uint32_t IfIndex, uint32_t ReadValue) } if (CurrentProcessedLength>=CurrentRequestedLength ) { - usnprintf(str, 100, "Total processed length: Feeder: %d Pooler %d",(int)TotalProcessedLength,(int)PoolerTotalProcessedLength); - SendJobProgress(0.0,0,false, str); - Report(str,__FILE__,__LINE__,(int)TotalProcessedLength,RpWarning,(int)PoolerTotalProcessedLength,0); + usnprintf(Lenstr, 100, "Total processed length: Feeder: %d Pooler %d",(int)TotalProcessedLength,(int)PoolerTotalProcessedLength); + SendJobProgress(0.0,0,false, Lenstr); + Report(Lenstr,__FILE__,__LINE__,(int)TotalProcessedLength,RpWarning,(int)PoolerTotalProcessedLength,0); // segment/intersegment/distance to spool finished if (ProcessedLengthFuncPtr) ProcessedLengthFuncPtr(); @@ -247,7 +249,8 @@ uint32_t PoolerThreadLengthCBFunction(uint32_t IfIndex, uint32_t ReadValue) PoolerPreviousPosition = PoolerCurrentPosition; length = (double)(positionDiff)*PoolerLengthCalculationMultiplier; - PoolerCurrentProcessedLength+=length; + PoolerTotalProcessedLength+= (length/100); + TempPoolerTotalProcessedLength = PoolerTotalProcessedLength; return OK; } @@ -310,14 +313,16 @@ uint32_t ThreadControlSpeedReadFunction(uint32_t IfIndex, uint32_t ReadValue) } return OK; } -double calculatedError[200]; //double eNormalizedError[100]; -int MotorId[200]; -int readValue[200]; //int TranslatedreadValue[100]; -int AveragereadValue[200]; -int calculatedspeed[200]; +/*double calculatedError[1000]; +int MotorId[1000]; +int readValue[1000]; +int AveragereadValue[1000]; +int calculatedspeed[1000]; +int timestamp[1000];*/ int controlIndex = 0; +bool keepdata = true; /*int32_t KeepReadValue = 0; void testDancersControl() { @@ -343,6 +348,8 @@ void testDancersControl() ThreadControlActive = false; }*/ bool dancerinvalid = false; +int MotorFailedSample[MAX_THREAD_MOTORS_NUM] = {0,0,0,0,0}; +char Message[60]; uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) { //#define MAX_CONTROL_SAMPLES 6 @@ -375,11 +382,13 @@ uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) DancerId = ThreadMotorIdToDancerId[index]; if (ReadValue < 10) { + MotorFailedSample[index]++; REPORT_MSG(ReadValue, "Dancer value read too small."); return OK; } if (ReadValue == 0x3FFF) { + MotorFailedSample[index]++; if (dancerinvalid == false) { dancerinvalid = true; @@ -429,10 +438,11 @@ uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) //Stop Execution if the dancer moves too much if ((abs(avreageSampleValue)> DancerStopActivityLimit[index])&&(JobCounter > eOneSecond)) { + keepdata = false; usnprintf(Message, 60, "Dancer %d limit %d value %d Zero %d",DancerId,DancerStopActivityLimit[index],avreageSampleValue,DancersCfg[DancerId].zeropoint); //JobAbortedByUser = true; ThreadControlActive = false; - JobEndReason = JOB_WINDER_DANCER_FAIL+index; + JobEndReason = JOB_WINDER_DANCER_FAIL+DancerId; SendJobProgress(0.0,0,false, Message); //EndState(CurrentJob,Message ); SegmentReady(Module_Thread,ModuleFail); @@ -454,35 +464,25 @@ uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) //KeepNormalizedError = NormalizedError; } calculated_speed = (1-MotorControlConfig[index].m_calculatedError)*OriginalMotorSpd_2PPS[index]; - /*if (index == FEEDER_MOTOR) - { - if (KeepReadValue != TranslatedReadValue) - { - eNormalizedError[controlIndex] = NormalizedError; - calculatedError[controlIndex] = MotorControlConfig[index].m_calculatedError; - readValue[controlIndex] = ReadValue; - TranslatedreadValue[controlIndex] = TranslatedReadValue; - AveragereadValue[controlIndex] = avreageSampleValue; - calculatedspeed[controlIndex] = calculated_speed; - controlIndex++; - if (controlIndex >= 99) controlIndex = 0; - KeepReadValue = TranslatedReadValue; - } - }*/ if (abs(calculated_speed-CurrentControlledSpeed[index])>2) { - calculatedError[controlIndex] = MotorControlConfig[index].m_calculatedError; - //double eNormalizedError[100]; - MotorId[controlIndex] = index; - readValue[controlIndex] = ReadValue; - //int TranslatedreadValue[100]; - AveragereadValue[controlIndex] = avreageSampleValue; - calculatedspeed[controlIndex] = calculated_speed; - if (controlIndex++>=199) - controlIndex = 0; + /*if (keepdata == true) + { + calculatedError[controlIndex] = MotorControlConfig[index].m_calculatedError; + MotorId[controlIndex] = index; + readValue[controlIndex] = ReadValue; + AveragereadValue[controlIndex] = avreageSampleValue; + calculatedspeed[controlIndex] = calculated_speed; + timestamp[controlIndex] = HibernateRTCSSGet(); + if (controlIndex++>=999) + controlIndex = 0; + }*/ CurrentControlledSpeed[index] = calculated_speed; MotorSetSpeed(ThreadMotorIdToMotorId[index], calculated_speed); } + else + MotorFailedSample[index]++; + } return OK; @@ -493,6 +493,21 @@ uint32_t ThreadGetMotorSpeed(threadMotorsEnum MotorId) { return CurrentControlledSpeed[MotorId]; } +//******************************************************************************************************************** +double ThreadGetMotorCalculatedError(int DancerId) +{ + switch (DancerId) + { + case FEEDER_DANCER: + return (double)MotorControlConfig[FEEDER_MOTOR].m_calculatedError; + case POOLER_DANCER: + return (double)MotorControlConfig[POOLER_MOTOR].m_calculatedError; + case WINDER_DANCER: + return (double)MotorControlConfig[WINDER_MOTOR].m_calculatedError; + + } + return 0; +} //******************************************************************************************************************** uint32_t ThreadInitialTestStub(HardwareMotor * request) @@ -564,7 +579,7 @@ uint32_t ThreadEmptyCBFunction(uint32_t IfIndex, uint32_t ReadValue) PoolerSpeedControlId = 0xFF; } //SetMotHome(ThreadMotorIdToMotorId[Motor_i]); - LengthCalculationMultiplier = (MotorsCfg[ThreadMotorIdToMotorId[Motor_i]].pulleyradius*2*PI)/(MotorsCfg[ThreadMotorIdToMotorId[Motor_i]].pulseperround*MotorsCfg[ThreadMotorIdToMotorId[Motor_i]].microstep); + PoolerLengthCalculationMultiplier = (MotorsCfg[ThreadMotorIdToMotorId[Motor_i]].pulleyradius*2*PI)/(MotorsCfg[ThreadMotorIdToMotorId[Motor_i]].pulseperround*MotorsCfg[ThreadMotorIdToMotorId[Motor_i]].microstep); PoolerSpeedControlId = AddControlCallback(PoolerThreadLengthCBFunction, eHundredMillisecond,MotorGetPositionFromFPGA,(IfTypeThread*0x100+Motor_i),ThreadMotorIdToMotorId[Motor_i],Motor_i); } if (Motor_i == FEEDER_MOTOR) // dryer motor is speed controlled. later a speed sensor will be utilized, but for now it will not be controlled @@ -715,11 +730,17 @@ uint32_t ThreadDistanceToSpoolState(void ) return OK; } +char Endstr[150]; //******************************************************************************************************************** uint32_t ThreadEndState(void *JobDetails) { int Motor_i; ThreadControlActive = false; + + usnprintf(Endstr, 100, "Total _processed length: Feeder: %d Pooler %d",(int)TotalProcessedLength,(int)PoolerTotalProcessedLength); + SendJobProgress(0.0,0,false, Endstr); + Report(Endstr,__FILE__,__LINE__,(int)TotalProcessedLength,RpWarning,(int)PoolerTotalProcessedLength,0); + ThreadUpdateProcessLength (0.0,(void *)NULL); SetOriginMotorSpeed(0); |
