diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2019-09-16 17:48:16 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2019-09-16 17:48:16 +0300 |
| commit | 161fe6f6d2b29ba3deb641cdc049ad0d8f58004e (patch) | |
| tree | 20318bb7ea4a243b8c2e9757e4635e8d5f5cb728 /Software/Embedded_SW/Embedded/Modules/Thread | |
| parent | 30fcfa4100a9d00e887c6e17e32e427b05296ce7 (diff) | |
| parent | b674a2e7751daa80c0d74207968bf8e3d18d7faf (diff) | |
| download | Tango-161fe6f6d2b29ba3deb641cdc049ad0d8f58004e.tar.gz Tango-161fe6f6d2b29ba3deb641cdc049ad0d8f58004e.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Embedded_SW/Embedded/Modules/Thread')
6 files changed, 873 insertions, 267 deletions
diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread.h b/Software/Embedded_SW/Embedded/Modules/Thread/Thread.h index 97f3811c7..56fb79c23 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread.h +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread.h @@ -9,6 +9,7 @@ #include "PMR/Hardware/HardwareDancerType.pb-c.h" #include "PMR/Hardware/HardwareWinder.pb-c.h" #include "PMR/Hardware/HardwarePidControl.pb-c.h" +#include "PMR/Hardware/HardwareConfiguration.pb-c.h" #include "PMR/Printing/JobSpool.pb-c.h" #include "PMR/Printing/JobSpoolType.pb-c.h" @@ -17,6 +18,7 @@ #include "thread_ex.h" +#define NORMAL_COEF_DIVIDER 100 typedef struct { uint32_t startoffsetpulses; @@ -51,12 +53,15 @@ extern HardwarePidControlType ThreadMotorIdToControlId[MAX_THREAD_MOTORS_NUM]; extern bool BreakSensorenabled; extern int32_t BreakSensordebouncetimemilli; +extern bool SampleWinding; + + //extern MotorDriverConfigStruc MotorsCfg[NUM_OF_MOTORS]; extern HardwarePidControl MotorsControl[MAX_THREAD_MOTORS_NUM]; //extern InternalWinderConfigStruc InternalWinderCfg; extern HardwareDancer DancersCfg[MAX_SYSTEM_DANCERS]; -extern uint32_t CurrentControlledSpeed[MAX_THREAD_MOTORS_NUM]; -extern int OriginalMotorSpd_2PPS[MAX_THREAD_MOTORS_NUM]; +extern double CurrentControlledSpeed[MAX_THREAD_MOTORS_NUM]; +extern double OriginalMotorSpd_2PPS[MAX_THREAD_MOTORS_NUM]; #define MAX_CONTROL_SAMPLES 10 extern int32_t MotorSamples[MAX_THREAD_MOTORS_NUM][MAX_CONTROL_SAMPLES]; @@ -64,15 +69,17 @@ extern int MotorSamplePointer[MAX_THREAD_MOTORS_NUM]; extern double NormalizedErrorCoEfficient[MAX_THREAD_MOTORS_NUM]; extern int DancerStopActivityLimit[MAX_THREAD_MOTORS_NUM]; extern MotorControlConfig_t MotorControlConfig[MAX_THREAD_MOTORS_NUM]; -extern int32_t MotorSpeedSamples[MAX_THREAD_MOTORS_NUM][MAX_CONTROL_SAMPLES]; +extern double MotorSpeedSamples[MAX_THREAD_MOTORS_NUM][MAX_CONTROL_SAMPLES]; extern int MotorSpeedSamplePointer[MAX_THREAD_MOTORS_NUM]; uint32_t InternalWinderConfigMessage(HardwareWinder* request); -uint32_t MotorsConfigMessage(HardwareMotor * request); +uint32_t MotorsConfigMessage( HardwareConfiguration* HW_request); uint32_t InternalWindingConfigMessage(JobSpool* request); uint32_t ThreadInitialTestStub(HardwareMotor * request); uint32_t MotorPidRequestMessage(HardwarePidControl* request); +void SetKeepWindingCone(bool value); +void SetWinderBackToBaseTime(uint32_t value); uint32_t DancerConfigMessage(HardwareDancer * request); diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c b/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c index ab5075ab9..1575123e4 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c @@ -17,6 +17,9 @@ #include "Modules/General/process.h" #include "Modules/control/pidalgo.h" +#include "Modules/heaters/heaters_ex.h" +#include "StateMachines/Initialization/InitSequence.h" + #include "PMR/Hardware/HardwareMotor.pb-c.h" #include "PMR/Hardware/HardwareMotorType.pb-c.h" #include "PMR/Hardware/HardwareDancerType.pb-c.h" @@ -48,20 +51,27 @@ 8 THREAD_LOAD_CLOSE_ROCKERS, 9 THREAD_LOAD_CLOSE_DANCERS, //SEND DANCER MOTORS TO PRESET LOCATION, CHECK THAT THE DANCERS ARE ON THE THREAD 10 THREAD_LOAD_CLOSE_LIDS, - 11 THREAD_LOAD_RESUME_HEATING, - 12 THREAD_LOAD_JOG_FEEDER_TO_MIDDLE_POINT, //JOG THE FEEDER MOTOR UNTIL THE FEEDER DANCER IS AT MIDDLE POSITION - 13 THREAD_LOAD_DRYER_LOADING, //START FEEDER PID, ROTATE LOADING ARM COUNTER THREAD DIRECTION X CIRCLES ACCORDING TO RML. FEEDER SPEED IS 40 + 11 THREAD_LOAD_JOG_FEEDER_TO_MIDDLE_POINT, //JOG THE FEEDER MOTOR UNTIL THE FEEDER DANCER IS AT MIDDLE POSITION + 12 THREAD_LOAD_DRYER_LOADING, //START FEEDER PID, ROTATE LOADING ARM COUNTER THREAD DIRECTION X CIRCLES ACCORDING TO RML. FEEDER SPEED IS 40 //KEEP NOTATION HOW MANY ROTATIONS IN THE DRYER + 13 THREAD_LOAD_RESUME_HEATING, 14 THREAD_LOAD_JOG_THREAD, //JOG THREAD SHORTLY TO MAKE SURE SPOOL IS RUNNING. REPORT END OF LOADING 15 THREAD_LOAD_END }THREAD_LOAD_STAGES_ENUM;*/ THREAD_LOAD_STAGES_ENUM LoadStages = THREAD_LOAD_INIT; ProcessParameters ProcessParametersClear,ProcessParametersRecover; + + int32_t keepmicrostep; + int32_t keepkvalrun,keepkvalhold; + uint8_t CallbackCounter = 0; + uint8_t TimeoutsCounter = 0; + uint8_t NumberOfDrierLoaderCycles = 0; uint32_t status = OK; - uint32_t ControlId = 0xFF; + uint32_t LoadingControlId = 0xFF,PullerControlId = 0xFF,WinderControlId = 0xFF; uint32_t ThreadLoadStateMachine( THREAD_LOAD_STAGES_ENUM LoadStages); uint32_t ThreadLoadControlCBFunction(uint32_t index, uint32_t ReadValue); + uint32_t Thread_Load_Dryer_UnLoading(void); typedef struct { @@ -92,7 +102,7 @@ FRESULT Fresult = FR_OK; REPORT_MSG(LoadStages, "Thread Load State Machine step"); - LoadArmInfo.LoadArmBackLash = 10; + LoadArmInfo.LoadArmBackLash = 5; LoadArmInfo.LoadArmRounds = 0xFF; Fresult = f_mkdir(SW_INFO_DIR); if ((Fresult == FR_OK)||(Fresult == FR_EXIST)) @@ -108,6 +118,7 @@ } Report("Thread_Load_Init",__FILE__,__LINE__,LoadArmInfo.LoadArmBackLash,RpMessage,LoadArmInfo.LoadArmRounds,0); + StopInitSequence(); memcpy (&ProcessParametersRecover,&ProcessParametersKeep,sizeof(ProcessParameters)); //NumberOfDrierLoaderCycles = loadLoadArmParameters(); LoadStages++; @@ -132,6 +143,7 @@ ProcessParametersClear.headzone5temp = 0; ProcessParametersClear.headzone6temp = 0; ProcessParametersClear.dyeingspeed = 40; + ProcessParametersClear.dryerbufferlength = ProcessParametersKeep.dryerbufferlength; if (HandleProcessParameters(&ProcessParametersClear)!= OK) { LOG_ERROR (LoadStages, "Thread_Load_Init failed"); @@ -145,7 +157,7 @@ Control_Voltage_To_Blower(BlowerCfg.voltage-500); Control_Dryer_Fan(STOP,75);//use START or STOP, 0 - 100% LoadStages++; - //ThreadLoadStateMachine(LoadStages); + ThreadLoadStateMachine(LoadStages); } return OK; } @@ -162,24 +174,44 @@ } else*/ { - Report("Thread_Load_Set_Load_Arm_To_Start_Position_Callback",__FILE__,__LINE__,LoadStages,RpMessage,NumberOfDrierLoaderCycles,0); + Report("Thread_Load_Set_Load_Arm_To_Start_Position_Callback",__FILE__,__LINE__,LoadStages,RpMessage,CallbackCounter,0); //storeLoadArmParameters(); SetMotHome(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM); //set this point as the spool home LoadStages++; - //ThreadLoadStateMachine(LoadStages); + ThreadLoadStateMachine(LoadStages); } return OK; } uint32_t Thread_Load_Set_Load_Arm_To_Stopper_Callback(uint32_t deviceID, uint32_t BusyFlag) { + + if(PullerControlId != 0xFF) + { + MotorStop(ThreadMotorIdToMotorId[POOLER_MOTOR],Hard_Hiz); + RemoveControlCallback(PullerControlId, ThreadLoadControlCBFunction ); + PullerControlId = 0xFF; + } + if(WinderControlId != 0xFF) + { + MotorStop(ThreadMotorIdToMotorId[WINDER_MOTOR],Hard_Hiz); + RemoveControlCallback(WinderControlId, ThreadLoadControlCBFunction ); + WinderControlId = 0xFF; + } + /*Task_sleep(5) + MotorStop(ThreadMotorIdToMotorId[FEEDER_MOTOR],Hard_Hiz); + MotorStop(ThreadMotorIdToMotorId[FEEDER_MOTOR],Hard_Hiz);*/ + + MotorStop(HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING,Hard_Hiz); + // Report("Thread Load State Machine Callback.",__FILE__,__LINE__,LoadStages,RpMessage,NumberOfDrierLoaderCycles,0); - Report("Thread_Load_Set_Load_Arm_To_Stopper_Callback",__FILE__,__LINE__,LoadStages,RpMessage,NumberOfDrierLoaderCycles,0); + CallbackCounter = 0; + Report("Thread_Load_Set_Load_Arm_To_Stopper_Callback",__FILE__,__LINE__,LoadStages,RpMessage,CallbackCounter,0); NumberOfDrierLoaderCycles=0; //storeLoadArmParameters(); LoadStages++; SetMotHome(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM); //set this point as the spool home - //ThreadLoadStateMachine(LoadStages); + ThreadLoadStateMachine(LoadStages); return OK; } uint32_t Thread_Load_Set_Load_Arm_To_Start_Position(void) @@ -205,13 +237,21 @@ //Use Notation How Many Rotations In The Drier, Or Check Against Stopper. Move Slowly return OK; } - uint8_t CallbackCounter = 0; - uint8_t TimeoutsCounter = 0; + uint32_t Thread_Load_Jog_Feeder_To_Middle_Point_Callback(uint32_t deviceID, uint32_t BusyFlag) + { + CallbackCounter--; + Report("Thread_Load_Jog_Feeder_To_Middle_Point_Callback",__FILE__,__LINE__,LoadStages,RpMessage,CallbackCounter,0); + //storeLoadArmParameters(); + LoadStages++; + ThreadLoadStateMachine(LoadStages); + + return OK; + } uint32_t Thread_Load_HomingCallback(uint32_t MotorId, uint32_t ReadValue) { - Report("Thread Load State Machine Callback.",__FILE__,__LINE__,LoadStages,RpMessage,NumberOfDrierLoaderCycles,0); - REPORT_MSG(MotorId, "Thread_Load_HomingCallback Motor Id"); + Report("Thread_Load_HomingCallback",__FILE__,__LINE__,LoadStages,RpMessage,CallbackCounter,0); +// REPORT_MSG(MotorId, "Thread_Load_HomingCallback Motor Id"); if (CallbackCounter) { CallbackCounter--; @@ -230,16 +270,20 @@ else { LoadStages++; - if (LoadStages == THREAD_LOAD_LIFT_ROCKERS) + if (LoadStages == THREAD_LOAD_CLOSE_ROCKERS) + { + MotorSetMicroStep(HARDWARE_MOTOR_TYPE__MOTO_RLOADING, keepmicrostep); + MotorSetMicroStep(HARDWARE_MOTOR_TYPE__MOTO_LLOADING, keepmicrostep); + MotorSetKvalRun(HARDWARE_MOTOR_TYPE__MOTO_RLOADING, keepkvalrun); + MotorSetKvalRun(HARDWARE_MOTOR_TYPE__MOTO_LLOADING, keepkvalrun); + } + if (LoadStages == THREAD_LOAD_CLOSE_DANCERS) { - MotorSetMicroStep(HARDWARE_MOTOR_TYPE__MOTO_RLOADING, MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_RLOADING].microstep); - MotorSetMicroStep(HARDWARE_MOTOR_TYPE__MOTO_LLOADING, MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LLOADING].microstep); - MotorSetKvalRun(HARDWARE_MOTOR_TYPE__MOTO_RLOADING, MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_RLOADING].microstep); - MotorSetKvalRun(HARDWARE_MOTOR_TYPE__MOTO_LLOADING, MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LLOADING].microstep); + MotorSetKvalHold(HARDWARE_MOTOR_TYPE__MOTO_RDANCER, keepkvalhold); } if (LoadStages != THREAD_LOAD_INITIAL_TENSION) //on this stage we should wait for user call { - //ThreadLoadStateMachine(LoadStages); + ThreadLoadStateMachine(LoadStages); } } } @@ -274,26 +318,30 @@ uint32_t Thread_Load_Lift_Dancers(void) { REPORT_MSG(LoadStages, "Thread Load State Machine step"); + keepkvalhold = MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_RDANCER].kvalhold; + MotorSetKvalHold(HARDWARE_MOTOR_TYPE__MOTO_RDANCER, 40); CallbackCounter++; MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_RDANCER,1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_RDANCER].directionthreadwize, 15, Motor_Id_to_LS_IdUp[HARDWARE_MOTOR_TYPE__MOTO_RDANCER], Thread_Load_HomingCallback,15000); CallbackCounter++; - MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_LDANCER1,1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LDANCER1].directionthreadwize, 500, Motor_Id_to_LS_IdUp[HARDWARE_MOTOR_TYPE__MOTO_LDANCER1], Thread_Load_HomingCallback,20000); + MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_LDANCER1,1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LDANCER1].directionthreadwize, 500, Motor_Id_to_LS_IdUp[HARDWARE_MOTOR_TYPE__MOTO_LDANCER1], Thread_Load_HomingCallback,25000); return OK; } uint32_t Thread_Load_Lift_Rockers(void) //Machine Is Ready. Send Message, Start Timer To Close Lids, Wait For Operator Response { + keepmicrostep = MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_RLOADING].microstep; + keepkvalrun = MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_RLOADING].kvalrun; REPORT_MSG(LoadStages, "Thread Load State Machine step"); - MotorSetMicroStep(HARDWARE_MOTOR_TYPE__MOTO_RLOADING, 1); - MotorSetMicroStep(HARDWARE_MOTOR_TYPE__MOTO_LLOADING, 1); - MotorSetKvalRun(HARDWARE_MOTOR_TYPE__MOTO_RLOADING, 35); - MotorSetKvalRun(HARDWARE_MOTOR_TYPE__MOTO_LLOADING, 35); + MotorSetMicroStep(HARDWARE_MOTOR_TYPE__MOTO_RLOADING, 8); + MotorSetMicroStep(HARDWARE_MOTOR_TYPE__MOTO_LLOADING, 8); + MotorSetKvalRun(HARDWARE_MOTOR_TYPE__MOTO_RLOADING, 70); + MotorSetKvalRun(HARDWARE_MOTOR_TYPE__MOTO_LLOADING, 70); Task_sleep(10); CallbackCounter++; - MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_RLOADING,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_RLOADING].directionthreadwize, 50, Motor_Id_to_LS_IdUp[HARDWARE_MOTOR_TYPE__MOTO_RLOADING], Thread_Load_HomingCallback,25000); + MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_RLOADING,1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_RLOADING].directionthreadwize, 250, Motor_Id_to_LS_IdUp[HARDWARE_MOTOR_TYPE__MOTO_RLOADING], Thread_Load_HomingCallback,35000); CallbackCounter++; - MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_LLOADING,1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LLOADING].directionthreadwize, 50, Motor_Id_to_LS_IdUp[HARDWARE_MOTOR_TYPE__MOTO_LLOADING], Thread_Load_HomingCallback,25000); + MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_LLOADING,1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LLOADING].directionthreadwize, 250, Motor_Id_to_LS_IdUp[HARDWARE_MOTOR_TYPE__MOTO_LLOADING], Thread_Load_HomingCallback,35000); return OK; } @@ -315,9 +363,9 @@ { REPORT_MSG(LoadStages, "Thread Load State Machine step"); CallbackCounter++; - MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_RLOADING,1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_RLOADING].directionthreadwize, 300, Motor_Id_to_LS_IdDown[HARDWARE_MOTOR_TYPE__MOTO_RLOADING], Thread_Load_HomingCallback,12000); + MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_RLOADING,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_RLOADING].directionthreadwize, 250, Motor_Id_to_LS_IdDown[HARDWARE_MOTOR_TYPE__MOTO_RLOADING], Thread_Load_HomingCallback,25000); CallbackCounter++; - MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_LLOADING,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LLOADING].directionthreadwize, 300, Motor_Id_to_LS_IdDown[HARDWARE_MOTOR_TYPE__MOTO_LLOADING], Thread_Load_HomingCallback,12000); + MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_LLOADING,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LLOADING].directionthreadwize, 250, Motor_Id_to_LS_IdDown[HARDWARE_MOTOR_TYPE__MOTO_LLOADING], Thread_Load_HomingCallback,25000); return OK; } @@ -360,7 +408,7 @@ { Control_Dryer_Fan(START,75);//use START or STOP, 0 - 100% LoadStages++; - //ThreadLoadStateMachine(LoadStages); + ThreadLoadStateMachine(LoadStages); } return OK; } @@ -369,20 +417,19 @@ { REPORT_MSG(LoadStages, "Thread Load State Machine step"); CallbackCounter++; - MotorMovetoDancerPosition (HARDWARE_MOTOR_TYPE__MOTO_RDRIVING,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_RDRIVING].directionthreadwize, 200, FEEDER_DANCER ,true, Thread_Load_HomingCallback,10000); + MotorMovetoDancerPosition (HARDWARE_MOTOR_TYPE__MOTO_RDRIVING,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_RDRIVING].directionthreadwize, 100, FEEDER_DANCER ,true, Thread_Load_Jog_Feeder_To_Middle_Point_Callback,2000); return OK; } - uint32_t Thread_Load_Dryer_Loading_Callback(uint32_t MotorId, uint32_t ReadValue) + uint32_t Thread_Load_Dryer_MovetoEncoderPosition_Callback(uint32_t MotorId, uint32_t ReadValue) { - Report("Thread Load State Machine Callback.",__FILE__,__LINE__,LoadStages,RpMessage,NumberOfDrierLoaderCycles,0); - REPORT_MSG(MotorId, "Thread_Load_Dryer_Loading_Callback Motor Id"); - MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,0,0); - if(ControlId != 0xFF) + Report("Thread_Load_Dryer_MovetoEncoderPosition_Callback",__FILE__,__LINE__,LoadStages,RpMessage,CallbackCounter,0); + MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM, 200); + if(LoadingControlId != 0xFF) { MotorStop(ThreadMotorIdToMotorId[FEEDER_MOTOR],Hard_Hiz); - RemoveControlCallback(ControlId, ThreadLoadControlCBFunction ); - ControlId = 0xFF; + RemoveControlCallback(LoadingControlId, ThreadLoadControlCBFunction ); + LoadingControlId = 0xFF; } if (CallbackCounter) { @@ -392,26 +439,45 @@ LoadStages++; if (LoadStages != THREAD_LOAD_INITIAL_TENSION) //on this satge we should wait for user call { - //ThreadLoadStateMachine(LoadStages); + ThreadLoadStateMachine(LoadStages); } } } else LOG_ERROR(MotorId, "Thread_Load_HomingCallback Callback is already 0"); + + return OK; + } + uint32_t Thread_Load_Dryer_Loading_Callback(uint32_t MotorId, uint32_t ReadValue) + { + Report("Thread_Load_Dryer_Loading_Callback",__FILE__,__LINE__,LoadStages,RpMessage,NumberOfDrierLoaderCycles,0); + Report("Thread_Load_Dryer_Loading_Callback details",__FILE__,__LINE__,MotorId,RpMessage,CallbackCounter,0); + /*if(LoadingControlId != 0xFF) + { + MotorStop(ThreadMotorIdToMotorId[FEEDER_MOTOR],Hard_Hiz); + RemoveControlCallback(LoadingControlId, ThreadLoadControlCBFunction ); + LoadingControlId = 0xFF; + }*/ + MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Thread_Load_Dryer_MovetoEncoderPosition_Callback,10000); return OK; } uint32_t Thread_Load_Dryer_Loading(void) { REPORT_MSG(LoadStages, "Thread Load State Machine step"); - LoadArmInfo.LoadArmRounds = 20; - uint32_t numberOfSteps = 0; + LoadArmInfo.LoadArmRounds = (int)dryerbufferlength; + if (LoadArmInfo.LoadArmRounds <= 2) + LoadArmInfo.LoadArmRounds = 20; + float numberOfSteps = 0; //Start Feeder Pid, Rotate Loading Arm Counter Thread Direction X Circles According To Rml. Feeder Speed Is 40 SetOriginMotorSpeed(19); // OriginalMotorSpd_2PPS[FEEDER_MOTOR] = 1000; // CurrentControlledSpeed[FEEDER_MOTOR] = 1000; numberOfSteps = MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulseperround*LoadArmInfo.LoadArmRounds*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].microstep*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulleyradius; + numberOfSteps -= 100; + //numberOfSteps = MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulseperround*3.3*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].microstep*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulleyradius; + Report("Thread Load State Machine step.",__FILE__,LoadStages,numberOfSteps,RpMessage,(int)(MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].microstep*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulleyradius),0); MotorControlConfig[FEEDER_MOTOR].m_params.MAX = 1; MotorControlConfig[FEEDER_MOTOR].m_params.MIN = MotorsControl[FEEDER_MOTOR].outputproportionalpowerlimit*-1; MotorControlConfig[FEEDER_MOTOR].m_params.Kd = MotorsControl[FEEDER_MOTOR].derivativetime; @@ -431,25 +497,29 @@ MotorControlConfig[FEEDER_MOTOR].m_SetParam = 0;//need to update SetParams on presegment stage MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_RDRIVING,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_RDRIVING].directionthreadwize); - ControlId = AddControlCallback(ThreadLoadControlCBFunction, eOneMillisecond,Control_Read_Dancer_Position,(IfTypeThread*0x100+FEEDER_MOTOR),FEEDER_DANCER,FEEDER_MOTOR); + MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM, MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulseperround/4); + + LoadingControlId = AddControlCallback(ThreadLoadControlCBFunction, eOneMillisecond,Control_Read_Dancer_Position,(IfTypeThread*0x100+FEEDER_MOTOR),FEEDER_DANCER,FEEDER_MOTOR); + Report("AddControlCallback feeder",__FILE__,__LINE__,LoadingControlId,RpMessage,IfTypeThread*0x100+FEEDER_MOTOR,0); CallbackCounter++; + Report("Thread_Load_Dryer_Loading",__FILE__,__LINE__,LoadStages,RpMessage,CallbackCounter,0); MotorMoveWithCallback (HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM, MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize, numberOfSteps, Thread_Load_Dryer_Loading_Callback, 100000); //Keep Notation How Many Rotations In The Dryer //LoadArmInfo.LoadArmBackLash = 0; - LoadArmInfo.LoadArmRounds = 0xFF; - FileWrite(&LoadArmInfo, sizeof(LoadArmInfo),LoadArmPath); + LoadArmInfo.LoadArmRounds = (int)dryerbufferlength; + //FileWrite(&LoadArmInfo, sizeof(LoadArmInfo),LoadArmPath,BIOS_WAIT_FOREVER); return OK; } uint32_t Thread_Load_Jog_ThreadStop(uint32_t index, uint32_t ReadValue) { REPORT_MSG(LoadStages, "Thread Load State Machine step"); - SafeRemoveControlCallback(ControlId, Thread_Load_Jog_ThreadStop ); - ControlId = 0xFF; + SafeRemoveControlCallback(LoadingControlId, Thread_Load_Jog_ThreadStop ); + LoadingControlId = 0xFF; ThreadAbortJoggingFunc(); LoadStages++; - //ThreadLoadStateMachine(LoadStages); + ThreadLoadStateMachine(LoadStages); return OK; } uint32_t Thread_Load_Jog_Thread(void) @@ -457,18 +527,122 @@ { REPORT_MSG(LoadStages, "Thread Load State Machine step"); ThreadJoggingFunc(20); - ControlId = AddControlCallback(Thread_Load_Jog_ThreadStop, eOneSecond*5,Control_Read_Dancer_Position,(IfTypeThread*0x100+FEEDER_MOTOR),FEEDER_DANCER,FEEDER_MOTOR); + LoadingControlId = AddControlCallback(Thread_Load_Jog_ThreadStop, eOneSecond*5,Control_Read_Dancer_Position,(IfTypeThread*0x100+FEEDER_MOTOR),FEEDER_DANCER,FEEDER_MOTOR); return OK; } uint32_t Thread_Load_End(void) { REPORT_MSG(LoadStages,"Loading Ended"); + if(LoadingControlId != 0xFF) + { + MotorStop(ThreadMotorIdToMotorId[FEEDER_MOTOR],Hard_Hiz); + RemoveControlCallback(LoadingControlId, ThreadLoadControlCBFunction ); + LoadingControlId = 0xFF; + } + if(PullerControlId != 0xFF) + { + MotorStop(ThreadMotorIdToMotorId[POOLER_MOTOR],Hard_Hiz); + RemoveControlCallback(PullerControlId, ThreadLoadControlCBFunction ); + PullerControlId = 0xFF; + } + if(WinderControlId != 0xFF) + { + MotorStop(ThreadMotorIdToMotorId[WINDER_MOTOR],Hard_Hiz); + RemoveControlCallback(WinderControlId, ThreadLoadControlCBFunction ); + WinderControlId = 0xFF; + } + + MotorStopAction(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM); + MotorStopAction(HARDWARE_MOTOR_TYPE__MOTO_RLOADING); + MotorStopAction(HARDWARE_MOTOR_TYPE__MOTO_LLOADING); + MotorStopAction(HARDWARE_MOTOR_TYPE__MOTO_RDANCER); + MotorStopAction(HARDWARE_MOTOR_TYPE__MOTO_LDANCER1); + MotorStopAction(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LID); + MotorStopAction(HARDWARE_MOTOR_TYPE__MOTO_DH_LID); + MotorStop(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Hard_Stop); + LoadStages = THREAD_LOAD_INIT; + return OK; + } + uint32_t Thread_Load_Dryer_UnLoading(void) + { + REPORT_MSG(LoadStages, "Thread UnLoad State Machine step"); + LoadArmInfo.LoadArmRounds = 0; + uint32_t numberOfSteps = 0; + //Start Feeder Pid, Rotate Loading Arm Counter Thread Direction X Circles According To Rml. Feeder Speed Is 40 + SetOriginMotorSpeed(19); +// OriginalMotorSpd_2PPS[FEEDER_MOTOR] = 1000; +// CurrentControlledSpeed[FEEDER_MOTOR] = 1000; + + numberOfSteps = MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulseperround*LoadArmInfo.LoadArmRounds*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].microstep*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulleyradius; + MotorControlConfig[POOLER_MOTOR].m_params.MAX = 1; + MotorControlConfig[POOLER_MOTOR].m_params.MIN = MotorsControl[POOLER_MOTOR].outputproportionalpowerlimit*-1; + MotorControlConfig[POOLER_MOTOR].m_params.Kd = MotorsControl[POOLER_MOTOR].derivativetime; + MotorControlConfig[POOLER_MOTOR].m_params.Kp = MotorsControl[POOLER_MOTOR].proportionalgain; + MotorControlConfig[POOLER_MOTOR].m_params.Ki = 0;//MotorsControl[POOLER_MOTOR].integraltime; + MotorControlConfig[POOLER_MOTOR].m_params.IntegralErrorMultiplier = MotorsControl[POOLER_MOTOR].setpointramprateorsoftstartramp; + MotorControlConfig[POOLER_MOTOR].m_params.ProportionalErrorMultiplier = MotorsControl[POOLER_MOTOR].outputonoffhysteresisvalue; + MotorControlConfig[POOLER_MOTOR].m_params.epsilon = MotorsControl[POOLER_MOTOR].epsilon; + MotorControlConfig[POOLER_MOTOR].m_params.dt = MotorsControl[POOLER_MOTOR].controloutputtype; + MotorControlConfig[POOLER_MOTOR].m_ingnoreValue = MotorsControl[POOLER_MOTOR].sensorcorrectionadjustment; // the minimal change required to change the motor speed in pulses + MotorControlConfig[POOLER_MOTOR].m_calculatedError = 0; + MotorControlConfig[POOLER_MOTOR].m_integral = 0; + MotorControlConfig[POOLER_MOTOR].m_isEnabled = true; + MotorControlConfig[POOLER_MOTOR].m_isReady = true; + MotorControlConfig[POOLER_MOTOR].m_mesuredParam = 0; + MotorControlConfig[POOLER_MOTOR].m_preError = 0; + MotorControlConfig[POOLER_MOTOR].m_SetParam = 0;//need to update SetParams on presegment stage + MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_LDRIVING,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LDRIVING].directionthreadwize); + + PullerControlId = AddControlCallback(ThreadLoadControlCBFunction, eOneMillisecond,Control_Read_Dancer_Position,(IfTypeThread*0x100+POOLER_MOTOR),POOLER_DANCER,POOLER_MOTOR); + Report("AddControlCallback Puller",__FILE__,__LINE__,PullerControlId,RpMessage,IfTypeThread*0x100+POOLER_MOTOR,0); +//////////////////////// + MotorControlConfig[WINDER_MOTOR].m_params.MAX = 1; + MotorControlConfig[WINDER_MOTOR].m_params.MIN = MotorsControl[WINDER_MOTOR].outputproportionalpowerlimit*-1; + MotorControlConfig[WINDER_MOTOR].m_params.Kd = MotorsControl[WINDER_MOTOR].derivativetime; + MotorControlConfig[WINDER_MOTOR].m_params.Kp = MotorsControl[WINDER_MOTOR].proportionalgain; + MotorControlConfig[WINDER_MOTOR].m_params.Ki = 0;//MotorsControl[WINDER_MOTOR].integraltime; + MotorControlConfig[WINDER_MOTOR].m_params.IntegralErrorMultiplier = MotorsControl[WINDER_MOTOR].setpointramprateorsoftstartramp; + MotorControlConfig[WINDER_MOTOR].m_params.ProportionalErrorMultiplier = MotorsControl[WINDER_MOTOR].outputonoffhysteresisvalue; + MotorControlConfig[WINDER_MOTOR].m_params.epsilon = MotorsControl[WINDER_MOTOR].epsilon; + MotorControlConfig[WINDER_MOTOR].m_params.dt = MotorsControl[WINDER_MOTOR].controloutputtype; + MotorControlConfig[WINDER_MOTOR].m_ingnoreValue = MotorsControl[WINDER_MOTOR].sensorcorrectionadjustment; // the minimal change required to change the motor speed in pulses + MotorControlConfig[WINDER_MOTOR].m_calculatedError = 0; + MotorControlConfig[WINDER_MOTOR].m_integral = 0; + MotorControlConfig[WINDER_MOTOR].m_isEnabled = true; + MotorControlConfig[WINDER_MOTOR].m_isReady = true; + MotorControlConfig[WINDER_MOTOR].m_mesuredParam = 0; + MotorControlConfig[WINDER_MOTOR].m_preError = 0; + MotorControlConfig[WINDER_MOTOR].m_SetParam = 0;//need to update SetParams on presegment stage + MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_WINDER,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_WINDER].directionthreadwize); + + WinderControlId = AddControlCallback(ThreadLoadControlCBFunction, eOneMillisecond,Control_Read_Dancer_Position,(IfTypeThread*0x100+WINDER_MOTOR),WINDER_DANCER,WINDER_MOTOR); + Report("AddControlCallback Winder",__FILE__,__LINE__,WinderControlId,RpMessage,IfTypeThread*0x100+WINDER_MOTOR,0); + +//////////////////////// + MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING].directionthreadwize); + MotorSetSpeed(HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING, OriginalMotorSpd_2PPS[DRYER_MOTOR]); + + CallbackCounter++; + //MotorMoveWithCallback (HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM, MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize, + // numberOfSteps, Thread_Load_Dryer_Loading_Callback, 100000); + Report("Thread_Load_Set_Load_Arm_To_Start_Position",__FILE__,__LINE__,LoadStages,RpMessage,NumberOfDrierLoaderCycles,0); + LoadArmInfo.LoadArmBackLash = 5; + + status |= MotorMoveToStopper(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM, (1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize), + MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulseperround/4, Thread_Load_Set_Load_Arm_To_Stopper_Callback,LoadArmInfo.LoadArmBackLash,1000); + + //Keep Notation How Many Rotations In The Dryer + //LoadArmInfo.LoadArmBackLash = 0; + LoadArmInfo.LoadArmRounds = (int)dryerbufferlength; + FileWrite(&LoadArmInfo, sizeof(LoadArmInfo),LoadArmPath,BIOS_WAIT_FOREVER); return OK; } uint32_t ThreadLoadStateMachine( THREAD_LOAD_STAGES_ENUM ReadValue) { REPORT_MSG(ReadValue,"ThreadLoadStateMachine"); + if (LoadStages!=ReadValue) + LoadStages = ReadValue; switch (ReadValue) { case THREAD_LOAD_INIT: @@ -481,7 +655,8 @@ break; case THREAD_LOAD_SET_LOAD_ARM_TO_START_POSITION://USE NOTATION HOW MANY ROTATIONS IN THE DRYER, OR CHECK AGAINS STOPPER. MOVE SLOWLY //LoadStages++; - Thread_Load_Set_Load_Arm_To_Start_Position(); + //Thread_Load_Set_Load_Arm_To_Start_Position(); + Thread_Load_Dryer_UnLoading(); break; case THREAD_LOAD_CENTER_HEAD_ROCKERS: //LoadStages++; @@ -515,10 +690,6 @@ //LoadStages++; Thread_Load_Close_Lids(); break; - case THREAD_LOAD_RESUME_HEATING: - //LoadStages++; - Thread_Load_Resume_Heating(); - break; case THREAD_LOAD_JOG_FEEDER_TO_MIDDLE_POINT://JOG THE FEEDER MOTOR UNTIL THE FEEDER DANCER IS AT MIDDLE POSITION //LoadStages++; Thread_Load_Jog_Feeder_To_Middle_Point(); @@ -528,11 +699,16 @@ //LoadStages++; Thread_Load_Dryer_Loading(); break; + case THREAD_LOAD_RESUME_HEATING: + //LoadStages++; + Thread_Load_Resume_Heating(); + break; case THREAD_LOAD_JOG_THREAD: //JOG THREAD SHORTLY TO MAKE SURE SPOOL IS RUNNING. REPORT END OF LOADING //LoadStages++; Thread_Load_Jog_Thread(); break; case THREAD_LOAD_END: + LoadStages = THREAD_LOAD_END; Thread_Load_End(); break; default: @@ -541,6 +717,20 @@ } return OK; } +uint32_t ThreadLoadButton(THREAD_LOAD_STAGES_ENUM ReadValue) +{ + Report("ThreadLoadButton",__FILE__,__LINE__,LoadStages,RpMessage,ReadValue,0); + if (LoadStages > ReadValue) + { + ThreadLoadStateMachine(LoadStages+1); + } + else + { + ThreadLoadStateMachine(ReadValue); + } + return OK; +} +uint32_t LoadCounter = 0; uint32_t ThreadLoadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) { @@ -553,7 +743,14 @@ uint32_t ThreadLoadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) uint32_t calculated_speed; double NormalizedError; - DancerId = FEEDER_DANCER;//ThreadMotorIdToDancerId[index]; + if (IfIndex>>8 != IfTypeThread) + { + LOG_ERROR (IfIndex, "Wrong Interface type"); + return 0xFFFFFFFF; + } + index = IfIndex&0xFF; + + DancerId = ThreadMotorIdToDancerId[index]; if (ReadValue < 10) { Report("Dancer value read too small.",__FILE__,__LINE__,DancerId,RpError,ReadValue,0); @@ -564,17 +761,11 @@ uint32_t ThreadLoadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) return OK; } TranslatedReadValue = ReadValue - DancersCfg[DancerId].zeropoint; - if (IfIndex>>8 != IfTypeThread) - { - LOG_ERROR (IfIndex, "Wrong Interface type"); - return 0xFFFFFFFF; - } - index = IfIndex&0xFF; - /*if (index == POOLER_MOTOR) + if (index == POOLER_MOTOR) { //pooler dancer is right sided: data is opposite TranslatedReadValue = (-1*TranslatedReadValue); - }*/ + } //TranslatedReadValue = 0;//test MotorSamples[index][MotorSamplePointer[index]] = TranslatedReadValue;//(-1 * TranslatedReadValue); MotorSamplePointer[index]++; @@ -589,16 +780,21 @@ uint32_t ThreadLoadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) MotorControlConfig[index].m_mesuredParam = NormalizedError; MotorControlConfig[index].m_calculatedError = AdvancedPIDAlgorithmCalculation((float)MotorControlConfig[index].m_SetParam , (float)MotorControlConfig[index].m_mesuredParam, &MotorControlConfig[index].m_params, &MotorControlConfig[index].m_preError, &MotorControlConfig[index].m_integral); - /*if (index != FEEDER_MOTOR) //feeder unit handles errors opposite to left unit + if (index != FEEDER_MOTOR) //feeder unit handles errors opposite to left unit { MotorControlConfig[index].m_calculatedError = (-1*MotorControlConfig[index].m_calculatedError); - }*/ + } calculated_speed = (1-MotorControlConfig[index].m_calculatedError)*OriginalMotorSpd_2PPS[index]; - if (abs(calculated_speed-CurrentControlledSpeed[index])> MotorControlConfig[index].m_ingnoreValue) + if (fabs(calculated_speed-CurrentControlledSpeed[index])> MotorControlConfig[index].m_ingnoreValue) { CurrentControlledSpeed[index] = calculated_speed; MotorSetSpeed(ThreadMotorIdToMotorId[index], calculated_speed); } +/* LoadCounter++; + if ((LoadCounter % 5001) == 0) + { + Report("MotorSpeedUpdated",__FILE__,index,abs(TranslatedReadValue),RpWarning,(int)CurrentControlledSpeed[index],0); + }*/ return OK; } void ThreadLoadRequest(MessageContainer* requestContainer) diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c index f8b0efb17..20045e5fb 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c @@ -36,6 +36,7 @@ uint32_t Winder_PrepareStage2(uint32_t deviceID, uint32_t ReadValue); void ScrewTimerInterruptInit(void); void ScrewsStopControlTimer (void); void ScrewsStartControlTimer (void); +void ScrewTimerInterrupt(int); bool Winder_ScrewHoming = false; bool ScrewCurrentDirection = false; //holds current screw direction @@ -43,26 +44,43 @@ uint32_t ScrewDirectionChangeCounter = 1; //holds the current number of runs of //uint32_t ScrewChangeCounter = 0; //uint32_t ScrewChangeLimit = 0; uint32_t CalculationDirectionChangeCounter = 1; //holds the current number of runs of the screw - will be used to build the cone -uint16_t WinderMotorSpeed[MAX_WINDER_SPEED_CALCULATION]; +double WinderMotorSpeed[MAX_WINDER_SPEED_CALCULATION]; uint16_t WinderMotorSpeedCounter = 0; bool WinderMotorSpeedRollOver = false; -double ScrewSpeed = 0; +#define DEFAULT_SCREW_SPEED 1200 +double ScrewSpeed = DEFAULT_SCREW_SPEED; double ScrewRunningTime = 0; uint32_t ScrewNumberOfSteps = 0; //holds the current number of steps for the next screw run - will be used to build the cone bool SCREW_TimerActivated = false; uint32_t ScrewControlId = 0xFF; -InternalWinderConfigStruc InternalWinderCfg = {0}; +static bool KeepWindingCone = false; +static uint32_t WindingConeLocation; +static uint32_t WinderBackToBaseTime = 800; +InternalWinderConfigStruc InternalWinderCfg = {0}; +#define READ_SCREW_ENCODER +#ifdef READ_SCREW_ENCODER uint32_t ScrewLocationLimitSwitch = 0,ScrewLocationStart = 0; uint32_t ScrewLocationRun[3]; - +#endif +bool SampleWinding = false; uint32_t Winder_Init(void) { ScrewTimerInterruptInit(); return OK; } +void SetKeepWindingCone(bool value) +{ + KeepWindingCone = value; + ReportWithPackageFilter(ThreadFilter,"set KeepWindingCone",__FILE__,__LINE__,WindingConeLocation,RpWarning,KeepWindingCone, 0); +} +void SetWinderBackToBaseTime(uint32_t value) +{ + WinderBackToBaseTime = value; + ReportWithPackageFilter(ThreadFilter,"Set WinderBackToBaseTime",__FILE__,__LINE__,WinderBackToBaseTime,RpWarning,KeepWindingCone, 0); +} uint32_t InternalWinderConfigMessage(HardwareWinder* request) { @@ -72,6 +90,8 @@ uint32_t InternalWinderConfigMessage(HardwareWinder* request) return status; } +char ScrewStr[150]; + uint32_t InternalWindingConfigMessage(JobSpool* request) { uint32_t status = PASSED; @@ -82,6 +102,9 @@ uint32_t InternalWindingConfigMessage(JobSpool* request) InternalWinderCfg.SpoolBottomBackingRate = request->bottombackingrate; InternalWinderCfg.NumberOfRotationPerPassage = 3.1415926*2;//request->rotationsperpassage; InternalWinderCfg.diameter = request->diameter; + usnprintf(ScrewStr, 150, "WindingConfig start,offset,head,tail {, %d, %d, %d, %d, %d}",InternalWinderCfg.startoffsetpulses,(int)InternalWinderCfg.segmentoffsetpulses, + (int)InternalWinderCfg.spoolbackingrate,(int)InternalWinderCfg.SpoolBottomBackingRate); + Report(ScrewStr,__FILE__,__LINE__,(int)InternalWinderCfg.diameter,RpWarning,(int)(InternalWinderCfg.NumberOfRotationPerPassage*1000), 0); return status; } @@ -91,12 +114,14 @@ uint32_t InternalWindingConfigMessage(JobSpool* request) * 1. move home to the limit switch (check that the cart is clear from the limit switch, start moving, with acceleration to maximal speed. enable interrupt on the limit switch, upon interrupt stop. * report ready to the job STM */ -uint32_t Winder_Prepare(void) +uint32_t Winder_Prepare(void *JobDetails) { + JobTicket* JobTicket = JobDetails; + uint32_t status = 0; //JobTicket* JobTicket = JobDetails; //float process_speed = JobTicket->processparameters->dyeingspeed; - double ScrewSpeed = 1500;//(process_speed*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].pulleyradius); // we will use pulley radius of the screw for this purpose, as of now + double ScrewSpeed = DEFAULT_SCREW_SPEED;//(process_speed*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].pulleyradius); // we will use pulley radius of the screw for this purpose, as of now //MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,InternalWinderCfg.segmentoffsetpulses); //REPORT_MSG(ScrewSpeed, "Winder_Prepare"); /* @@ -113,9 +138,25 @@ uint32_t Winder_Prepare(void) return ERROR; }*/ +#ifdef READ_SCREW_ENCODER ScrewLocationRun[0] = 0; ScrewLocationRun[1] = 0; +#endif + if (( KeepWindingCone == false)||(WindingConeLocation == 0)) + { + WindingConeLocation = InternalWinderCfg.startoffsetpulses; + ReportWithPackageFilter(ThreadFilter,"WindingConeLocation set",__FILE__,__LINE__,WindingConeLocation,RpWarning,KeepWindingCone, 0); + } + else + { + ReportWithPackageFilter(ThreadFilter,"WindingConeLocation use previous",__FILE__,__LINE__,WindingConeLocation,RpWarning,KeepWindingCone, 0); + } + if (JobTicket->has_samplewinding == true) + { + SampleWinding = JobTicket->samplewinding; + SampleWinding = true; + } if (FPGA_Read_limit_Switches(GPI_LS_SCREW_RIGHT)==LIMIT) { //REPORT_MSG(LIMIT, "Winder_Prepare at limit"); @@ -139,14 +180,15 @@ uint32_t Winder_Prepare(void) 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; + uint32_t numOfSteps = WindingConeLocation*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep; //MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,InternalWinderCfg.segmentoffsetpulses); //REPORT_MSG(numOfSteps, "Winder_PrepareStage2"); - //Read_Screw_Encoder(); - //ScrewLocationLimitSwitch = Screw_RotEnc.Position; - //REPORT_MSG(ScrewLocationLimitSwitch, "Winder_PrepareStage2 Encoder Location"); - +#ifdef READ_SCREW_ENCODER + Read_Screw_Encoder(); + ScrewLocationLimitSwitch = Screw_RotEnc.Position; + REPORT_MSG(ScrewLocationLimitSwitch, "Winder_PrepareStage2 Encoder Location"); +#endif REPORT_MSG(millisecondCounter/*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].maxfrequency*/, "Winder_PrepareStage2"); if (ReadValue != LIMIT) @@ -166,21 +208,29 @@ uint32_t Winder_PrepareStage2(uint32_t deviceID, uint32_t ReadValue) uint32_t Winder_ScrewAtOffsetCallback(uint32_t deviceID, uint32_t BusyFlag) { - //SetMotHome(HARDWARE_MOTOR_TYPE__MOTO_SCREW); //set this point as the spool home //MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,temp_MaxFrequency); - //Read_Screw_Encoder(); - //ScrewLocationStart = Screw_RotEnc.Position; + MotorStop (HARDWARE_MOTOR_TYPE__MOTO_SCREW,Soft_Hiz); //per L6470 errata between mov and run commands + Task_sleep(5); +#ifdef READ_SCREW_ENCODER + Reset_Screw_Encoder(); + Task_sleep(5); + Read_Screw_Encoder(); + Task_sleep(5); + ScrewLocationStart = Screw_RotEnc.Position; REPORT_MSG(ScrewLocationStart, "Winder_ScrewAtOffsetCallback Encoder Location"); +#endif + SetMotHome(HARDWARE_MOTOR_TYPE__MOTO_SCREW); //set this point as the spool home ScrewCurrentDirection = false; +#ifdef READ_SCREW_ENCODER ScrewLocationRun[ScrewCurrentDirection] = Screw_RotEnc.Position; +#endif ScrewSpeed = 0; ScrewControlId = 0xFF; ScrewNumberOfSteps = 0; REPORT_MSG(millisecondCounter, "Winder_ScrewAtOffsetCallback"); - MotorStop (HARDWARE_MOTOR_TYPE__MOTO_SCREW,Soft_Hiz); //per L6470 errata between mov and run commands PrepareReady(Module_Winder, ModuleDone); return OK; } @@ -212,26 +262,32 @@ InternalWinderCfg.segmentoffsetpulses numOfSteps = InternalWinderCfg.startoffsetpulses*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep; */ -char ScrewStr[100]; + //char TempScrewStr[100]; double WinderReferenceSpeed=0; -int32_t TotalWinderSpeed=0; +double TotalWinderSpeed=0; bool Add100 = false; double Rotations = 6.0; +int flipflop = 0; +uint32_t motspeed; +float speedf; +int WinderCalculation = 0; +#ifdef READ_SCREW_ENCODER +float WinderRunAverage = 0.0,WinderRunSum = 0.0; +int WinderRunSamples = 0; +#endif uint32_t Screw100msecDirectionChange(uint32_t deviceID, uint32_t BusyFlag) { //uint32_t Steps; double temp,tempScrewSpeed; double screw_horizontal_speed = 0; double RotationsPerSecond; - int32_t Averagewinderspeed = 0; + //double Averagewinderspeed = 0; - //ScrewChangeCounter++; - //if ((ScrewChangeCounter>3)&&(ScrewChangeCounter<(ScrewChangeLimit-2))) //do not take the winder speed near the limits - { - TotalWinderSpeed-=WinderMotorSpeed[WinderMotorSpeedCounter]; - WinderMotorSpeed[WinderMotorSpeedCounter] = CurrentControlledSpeed[WINDER_MOTOR]; - TotalWinderSpeed+=WinderMotorSpeed[WinderMotorSpeedCounter]; +// { +// TotalWinderSpeed-=WinderMotorSpeed[WinderMotorSpeedCounter]; +// WinderMotorSpeed[WinderMotorSpeedCounter] = CurrentControlledSpeed[WINDER_MOTOR]; +// TotalWinderSpeed+=WinderMotorSpeed[WinderMotorSpeedCounter]; if (WinderMotorSpeedCounter++>=MAX_WINDER_SPEED_CALCULATION) { if (WinderMotorSpeedRollOver == false) @@ -239,21 +295,53 @@ uint32_t Screw100msecDirectionChange(uint32_t deviceID, uint32_t BusyFlag) Add100 = true; LOG_ERROR(Add100, "Add100 = true"); } - WinderMotorSpeedCounter=0; +// WinderMotorSpeedCounter=0; WinderMotorSpeedRollOver=true; } +// } + if (flipflop == 0) + { + MotorGetSpeedFromFPGA1(HARDWARE_MOTOR_TYPE__MOTO_SCREW); + } + else if (flipflop == 1) + { + speedf = MotorGetSpeedFromFPGA_Res(HARDWARE_MOTOR_TYPE__MOTO_SCREW); } + flipflop ++; if (ScrewDirectionChangeCounter == CalculationDirectionChangeCounter) return OK; + //deley TODO + flipflop = 0; ScrewCurrentDirection = 1-ScrewCurrentDirection; CalculationDirectionChangeCounter++; - //REPORT_MSG(ScrewLocationRun[1] - ScrewLocationRun[0], "Screw Run NumberOfSteps"); - //usnprintf(ScrewStr, 100, "Winder Encoder: 0 0x%x 1 0x%x diff %d ",ScrewLocationRun[0],ScrewLocationRun[1],abs(ScrewLocationRun[1] - ScrewLocationRun[0])); + if (SampleWinding) + return OK; + //double calcsteps = (ScrewRunningTime/SYS_CLK_FREQ)*ScrewSpeed; +#ifdef READ_SCREW_ENCODER + int WinderRun; + WinderRun = abs(ScrewLocationRun[1] - ScrewLocationRun[0]); + if /*((WinderRun < 50000)&&(Add100 == false))*/(Add100 == false) + { + WinderRunSum+=WinderRun; + WinderRunSamples++; + WinderRunAverage = WinderRunSum/WinderRunSamples; + if ((fabs(WinderRun-WinderRunAverage)>=30)||(WinderRunSamples%100 == 0)) + { + usnprintf(ScrewStr, 150, "curr,sum,avg,samples {Winder Encoder:, %d, %d, %d, %d, %d}",WinderRun,(int)WinderRunSum,(int)WinderRunAverage,(int)WinderRunSamples, + (int)(100*WinderRun/ScrewNumberOfSteps)); + Report(ScrewStr,__FILE__,__LINE__,CalculationDirectionChangeCounter,RpWarning,ScrewLocationStart, 0); + } + } + //Report(ScrewStr,__FILE__,__LINE__,CalculationDirectionChangeCounter,RpWarning,ScrewLocationStart, 0); + //REPORT_MSG(abs(ScrewLocationRun[1] - ScrewLocationRun[0]), "Screw Run NumberOfSteps"); + //usnprintf(ScrewStr, 100, "Winder Encoder: 0 0x%x 1 0x%x diff %d intent %d rot %d",ScrewLocationRun[0],ScrewLocationRun[1],abs(ScrewLocationRun[1] - ScrewLocationRun[0]),ScrewNumberOfSteps,Rotations*10); + //usnprintf(ScrewStr, 150, "Winder Encoder:id, diff, intended, winderspeed, rotation, speed, time, mot speed {, %d, %d, %d, %d, %d, %d, %d, %d, }",CalculationDirectionChangeCounter, + // abs(ScrewLocationRun[1] - ScrewLocationRun[0]),ScrewNumberOfSteps,(int)(WinderReferenceSpeed),(int)(Rotations*10),(int)ScrewSpeed,(int)ScrewRunningTime,(int)speedf); //usnprintf(ScrewStr, 100, "Winder Encoder: 0 %d 1 %d diff %d ",ScrewLocationRun[0],ScrewLocationRun[1],ScrewLocationRun[1] - ScrewLocationRun[0]); - //Report(ScrewStr,__FILE__,__LINE__,ScrewLocationLimitSwitch,RpWarning,ScrewLocationStart, 0); - + //Report(ScrewStr,__FILE__,__LINE__,CalculationDirectionChangeCounter,RpWarning,ScrewLocationStart, 0); +#endif if (ScrewCurrentDirection == 1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize) //next time going out { if (Add100 == true) //once per job @@ -265,8 +353,8 @@ uint32_t Screw100msecDirectionChange(uint32_t deviceID, uint32_t BusyFlag) if ((CalculationDirectionChangeCounter/2)%InternalWinderCfg.spoolbackingrate == 0) { ScrewNumberOfSteps--; - REPORT_MSG(ScrewNumberOfSteps, "Head Backing ScrewNumberOfSteps"); - + WindingConeLocation--; + // ReportWithPackageFilter(ThreadFilter,"Head Backing",__FILE__,__LINE__,CalculationDirectionChangeCounter,RpWarning,ScrewNumberOfSteps, 0); } } else //next time going back @@ -274,42 +362,46 @@ uint32_t Screw100msecDirectionChange(uint32_t deviceID, uint32_t BusyFlag) if ((CalculationDirectionChangeCounter/2)%InternalWinderCfg.SpoolBottomBackingRate == 0) { ScrewNumberOfSteps++; - REPORT_MSG(ScrewNumberOfSteps, "Bottom Backing ScrewNumberOfSteps"); + // Report("Bottom Backing ",__FILE__,__LINE__,CalculationDirectionChangeCounter,RpWarning,ScrewNumberOfSteps, 0); } } - if (WinderMotorSpeedRollOver) + /* if (WinderMotorSpeedRollOver) { - /*for (i=0;i<MAX_WINDER_SPEED_CALCULATION;i++) + if (WinderCalculation%60000 == 0)//100 minutes { - TotalWinderSpeed+=WinderMotorSpeed[i]; - }*/ - Averagewinderspeed = TotalWinderSpeed/MAX_WINDER_SPEED_CALCULATION; - //REPORT_MSG(winderspeed, "WinderSpeedUpdated"); - //Report("WinderSpeedUpdated",__FILE__,__LINE__,TotalWinderSpeed,RpWarning,Averagewinderspeed,0); - - WinderReferenceSpeed = Averagewinderspeed; - } + Averagewinderspeed = TotalWinderSpeed/MAX_WINDER_SPEED_CALCULATION; + //Report("WinderSpeedUpdated",__FILE__,__LINE__,(int)TotalWinderSpeed,RpWarning,(int)Averagewinderspeed,0); + WinderReferenceSpeed = Averagewinderspeed; + } + WinderCalculation++; + }*/ + //WinderReferenceSpeed = 1000; + //ScrewNumberOfSteps = 1000; screw_horizontal_speed = ScrewNumberOfSteps / Rotations;//InternalWinderCfg.NumberOfRotationPerPassage; - if (Rotations > 6.6)//7.0) - Rotations = 6.0; + // if (Rotations > 6.6)//7.0) + // Rotations = 6.0; RotationsPerSecond = WinderReferenceSpeed / (double)MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_WINDER].pulseperround; tempScrewSpeed = screw_horizontal_speed*RotationsPerSecond; //ROM_IntMasterDisable(); + tempScrewSpeed = ScrewSpeed; + CurrentControlledSpeed[SCREW_MOTOR] = ScrewSpeed; + temp = SYS_CLK_FREQ; temp *= ScrewNumberOfSteps; temp /= tempScrewSpeed; if ((ScrewRunningTime != temp)||(ScrewSpeed != tempScrewSpeed)) { ScrewSpeed = tempScrewSpeed; + //ScrewSpeed = DEFAULT_SCREW_SPEED; ScrewRunningTime = temp;//(SYS_CLK_FREQ*Steps)/ScrewSpeed; //ROM_IntMasterEnable(); //usnprintf(TempScrewStr, 100, "Winder: Horizon,Rotation, PPR, RPP{ %d, %d ,%d, %d} ",(int)screw_horizontal_speed,(int)RotationsPerSecond,(int)InternalWinderCfg.NumberOfRotationPerPassage,(int)MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_WINDER].pulseperround); - //usnprintf(ScrewStr, 100, "Winder: Steps,Speed, Time, WinderSpeed{ %d, %d ,%d, %d} ",(int)ScrewNumberOfSteps,(int)ScrewSpeed,(int)temp,(int)WinderReferenceSpeed); +// usnprintf(ScrewStr, 100, "Winder: Steps,Speed, Time, WinderSpeed{ %d, %d ,%d, %d} ",(int)ScrewNumberOfSteps,(int)ScrewSpeed,(int)temp,(int)WinderReferenceSpeed); // Report(logmsg[index],__FILE__,__LINE__,index,RpWarning,index, Counter[index]); // #warning PID is now only proportional (above) //Report(TempScrewStr,__FILE__,__LINE__,0,RpWarning,0, 0); - //Report(ScrewStr,__FILE__,__LINE__,ScrewCurrentDirection,RpWarning,CalculationDirectionChangeCounter, 0); +// Report(ScrewStr,__FILE__,__LINE__,ScrewCurrentDirection,RpWarning,CalculationDirectionChangeCounter, 0); //REPORT_MSG(temp , "new winder speed"); //Report("new winder speed",__FILE__,ScrewNumberOfSteps,temp,RpWarning,ScrewSpeed,0); } @@ -324,10 +416,14 @@ uint32_t WinderPresegmentReady(uint32_t deviceID, uint32_t ReadValue) { return PreSegmentReady(Module_Winder,ModuleDone); } +uint32_t WinderSamplesSegmentCallback(uint32_t SegmentDetails, uint32_t SegmentId) +{ + ScrewTimerInterrupt(0); + return OK; +} uint32_t Winder_Presegment(void *SegmentDetails, uint32_t SegmentId) { - //JobTicket* JobTicket = JobDetails; double screw_horizontal_speed = 0; double RotationsPerSecond; double temp = 0; @@ -337,63 +433,150 @@ uint32_t Winder_Presegment(void *SegmentDetails, uint32_t SegmentId) return ERROR; } - if (SegmentId == 0) // do all this only in the beginning of the job. do not touch after that (assuming spool does not change mid job) + if ((SegmentId == 0)||(SampleWinding)) // do all this only in the beginning of the job. do not touch after that (assuming spool does not change mid job) { - ScrewCurrentDirection = (1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize); + ScrewCurrentDirection = 1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize; + if ((SegmentId > 0)&&(SampleWinding)) + { + InternalWinderCfg.segmentoffsetpulses = 120; + MotorGotoWithBusyCallback (HARDWARE_MOTOR_TYPE__MOTO_SCREW,true, (InternalWinderCfg.segmentoffsetpulses*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep*(SegmentId-1)), WinderSamplesSegmentCallback,2000); //TODO + Report("ScrewsMotorGoTo direction,speed ", __FILE__,__LINE__,InternalWinderCfg.segmentoffsetpulses*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep*(SegmentId-1), RpMessage, ScrewSpeed, 0); + InternalWinderCfg.spoolbackingrate = 2000; //no cone for samples + InternalWinderCfg.SpoolBottomBackingRate = 2000; //no cone shape for samples + InternalWinderCfg.NumberOfRotationPerPassage = 100; // a very slow movement of the screw + JobSegment* Segment = SegmentDetails; + InternalWinderCfg.NumberOfRotationPerPassage = 100; // a very slow movement of the screw + ScrewSpeed = InternalWinderCfg.segmentoffsetpulses/(((Segment->length *100)/dyeingspeed)/3); + ScrewNumberOfSteps = InternalWinderCfg.segmentoffsetpulses;//*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep; - // * speed is set by the winding parameters and by winder rotational speed (read POSITION every 10msec) - // * calculate - // * 1. calculate speed according to JobTicket->processparameters->dyeingspeed - // * calculation input: traverse length in milimeters/pulses, number of rotations per traverse ==> length of traverse per rotation. - ScrewNumberOfSteps = InternalWinderCfg.segmentoffsetpulses;//*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep; - ScrewNumberOfSteps -= 100; - screw_horizontal_speed = ScrewNumberOfSteps / InternalWinderCfg.NumberOfRotationPerPassage; - // calculation input#2: number of rotations per second - (basically: speed/winder perimeter. later - according to winder actual speed - calculate according to winder position accumulation in the last second. - //RotationsPerSecond = dyeingspeed / (MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_WINDER].pulleyradius * PI); - RotationsPerSecond = OriginalMotorSpd_2PPS[WINDER_MOTOR] / MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_WINDER].pulseperround; - // calculation input#3: speed = rotation per second * traverse per rotation = traverse per second. speed set: traverse per second (mm) * pulses per mm. - ScrewSpeed = screw_horizontal_speed*RotationsPerSecond; + //three passages during the segment + } + else if (SampleWinding) //first segment + { + //InternalWinderCfg.segmentoffsetpulses = 120; + InternalWinderCfg.spoolbackingrate = 2000; //no cone for samples + InternalWinderCfg.SpoolBottomBackingRate = 2000; //no cone shape for samples + InternalWinderCfg.NumberOfRotationPerPassage = 100; // a very slow movement of the screw + JobSegment* Segment = SegmentDetails; + InternalWinderCfg.NumberOfRotationPerPassage = 100; // a very slow movement of the screw + ScrewSpeed = InternalWinderCfg.segmentoffsetpulses/(((Segment->length *100)/dyeingspeed)/20); + ScrewNumberOfSteps = InternalWinderCfg.segmentoffsetpulses;//*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep; + } + else if ((SegmentId == 0)&&(SampleWinding == false)) + { + /* + // * speed is set by the winding parameters and by winder rotational speed (read POSITION every 10msec) + // * calculate + // * 1. calculate speed according to JobTicket->processparameters->dyeingspeed + // * calculation input: traverse length in milimeters/pulses, number of rotations per traverse ==> length of traverse per rotation. + ScrewNumberOfSteps = InternalWinderCfg.segmentoffsetpulses;//MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep; + ScrewNumberOfSteps -= 100; + screw_horizontal_speed = ScrewNumberOfSteps / InternalWinderCfg.NumberOfRotationPerPassage; + // calculation input#2: number of rotations per second - (basically: speed/winder perimeter. later - according to winder actual speed - calculate according to winder position accumulation in the last second. + //RotationsPerSecond = dyeingspeed / (MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_WINDER].pulleyradius * PI); + RotationsPerSecond = OriginalMotorSpd_2PPS[WINDER_MOTOR] / MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_WINDER].pulseperround; + // calculation input#3: speed = rotation per second * traverse per rotation = traverse per second. speed set: traverse per second (mm) * pulses per mm. + ScrewSpeed = screw_horizontal_speed*RotationsPerSecond; + ScrewSpeed = DEFAULT_SCREW_SPEED; - //MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewSpeed); - usnprintf(ScrewStr, 100, "SCREW speed Rot/sec %d horizon %d pulses %d",(int)RotationsPerSecond,(int)screw_horizontal_speed,(int)ScrewSpeed); + //MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewSpeed); + usnprintf(ScrewStr, 100, "SCREW speed Rot/sec %d horizon %d pulses %d",(int)RotationsPerSecond,(int)screw_horizontal_speed,(int)ScrewSpeed); + //REPORT_MSG(segmentfirst_speed,ScrewStr); + Report(ScrewStr,__FILE__,__LINE__,RotationsPerSecond,RpWarning,ScrewSpeed,0); + SendJobProgress(0.0,0,false, ScrewStr); + */ + // * speed is set by the winding parameters and by winder rotational speed (read POSITION every 10msec) + // * calculate + // * 1. calculate speed according to JobTicket->processparameters->dyeingspeed + // * calculation input: traverse length in pulses, number of rotations per traverse ==> length of traverse per rotation. + ScrewNumberOfSteps = InternalWinderCfg.segmentoffsetpulses;//*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep; + screw_horizontal_speed = InternalWinderCfg.segmentoffsetpulses / InternalWinderCfg.NumberOfRotationPerPassage; //steps per winder cycle + // calculation input#2: number of rotations per second - speed/winder diameter. WE USE HERE 39 MM AS ATHE WINDER DIAMETER - SOME AVERAGE BETWEEN EMPTY AND FULL + RotationsPerSecond = (dyeingspeed*10.0)/(19.50*PI); + // calculation input#3: speed = rotation per second * traverse per rotation = traverse per second. speed set: traverse per second (mm) * pulses per mm. + ScrewSpeed = screw_horizontal_speed*RotationsPerSecond; + ScrewNumberOfSteps -= 100; + Add100 = false; + LOG_ERROR(Add100, "Add100 = false"); + } + usnprintf(ScrewStr, 100, "SCREW speed Rot/sec %d horizon %d pulses %d",(int)RotationsPerSecond*100,(int)screw_horizontal_speed*100,(int)ScrewSpeed); //REPORT_MSG(segmentfirst_speed,ScrewStr); Report(ScrewStr,__FILE__,__LINE__,RotationsPerSecond,RpWarning,ScrewSpeed,0); SendJobProgress(0.0,0,false, ScrewStr); + ScrewDirectionChangeCounter = 1; + CalculationDirectionChangeCounter = 1; + memset (WinderMotorSpeed,0,sizeof(WinderMotorSpeed) ); + WinderMotorSpeedCounter=0; + TotalWinderSpeed = 0; + WinderMotorSpeedRollOver=false; + + /////////////////////// CurrentControlledSpeed[SCREW_MOTOR] = ScrewSpeed; OriginalMotorSpd_2PPS[SCREW_MOTOR] = ScrewSpeed; WinderReferenceSpeed = OriginalMotorSpd_2PPS[WINDER_MOTOR]; //screw_horizontal_speed = InternalWinderCfg.milimetersperrotation - // * 2. determine optimal micro-step setting - // * 3. calculate cart travel length from winding parameters - // * 4. start move of travel length - // * 5. register motor nBusy callback. this callback will flip between move(traverse length, hardstop) and goto(0), with handline og the coneshape and adjusting maxspeed + // * 2. determine optimal micro-step setting + // * 3. calculate cart travel length from winding parameters + // * 4. start move of travel length + // * 5. register motor nBusy callback. this callback will flip between move(traverse length, hardstop) and goto(0), with handline og the coneshape and adjusting maxspeed temp = SYS_CLK_FREQ; temp *= ScrewNumberOfSteps; temp /= ScrewSpeed; ScrewRunningTime = temp;//(SYS_CLK_FREQ*InternalWinderCfg.segmentoffsetpulses)/ScrewSpeed; - REPORT_MSG(ScrewNumberOfSteps,"Winder pre segment - ScrewNumberOfSteps"); - REPORT_MSG(ScrewRunningTime,"Winder pre segment - ScrewRunningTime"); -// MotorSetDirection (HARDWARE_MOTOR_TYPE__MOTO_SCREW, ScrewCurrentDirection); + REPORT_MSG((int)ScrewNumberOfSteps,"Winder pre segment - ScrewNumberOfSteps"); + REPORT_MSG((int)ScrewRunningTime,"Winder pre segment - ScrewRunningTime"); + //MotorSetDirection (HARDWARE_MOTOR_TYPE__MOTO_SCREW, ScrewCurrentDirection); //ScrewDirection = 1-ScrewDirection; REPORT_MSG(SegmentId,"Winder pre segment - SegmentId"); REPORT_MSG(ScrewSpeed,"Winder pre segment - ScrewSpeed"); //MotorSetSpeedDirect(HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewSpeed); ScrewsStartControlTimer (); - ScrewControlId = AddControlCallback(Screw100msecDirectionChange, eHundredMillisecond,TemplateDataReadCBFunction,0,0,0); - ScrewDirectionChangeCounter = 1; - CalculationDirectionChangeCounter = 1; - memset (WinderMotorSpeed,0,sizeof(WinderMotorSpeed) ); - WinderMotorSpeedCounter=0; - TotalWinderSpeed = 0; - WinderMotorSpeedRollOver=false; - Add100 = false; - LOG_ERROR(Add100, "Add100 = false"); } + if (SegmentId == 0) + { + ScrewControlId = AddControlCallback(Screw100msecDirectionChange, eHundredMillisecond,TemplateDataReadCBFunction,0,0,0); + } PreSegmentReady(Module_Winder,ModuleDone); return OK; } +uint32_t ScrewDTSControlId = 0xFF; +uint32_t WinderDistanceToSpoolEnded(uint32_t deviceID, uint32_t ReadValue) +{ + REPORT_MSG ((int)msec_millisecondCounter,"WinderDistanceToSpoolEnded called"); + return OK; +} +uint32_t ScrewDTSCallback(uint32_t deviceID, uint32_t BusyFlag) +{ + REPORT_MSG ((int)msec_millisecondCounter,"ScrewDTSCallback called"); + SafeRemoveControlCallback(ScrewDTSControlId, ScrewDTSCallback); + + if (ScrewControlId != 0xFF) + { + RemoveControlCallback(ScrewControlId,Screw100msecDirectionChange); + ScrewControlId = 0xFF; + } + CurrentControlledSpeed[SCREW_MOTOR] = 0; + ScrewsStopControlTimer(); + //move the cart to the edge so the spool can be easily replaced + //MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_SCREW,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize, 1000, GPI_LS_SCREW_RIGHT, NULL,0); + //MotorStop(HARDWARE_MOTOR_TYPE__MOTO_SCREW,Hard_Hiz); + MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_SCREW,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize, ScrewSpeed, GPI_LS_SCREW_RIGHT, WinderDistanceToSpoolEnded,2000); + + return OK; +} +uint32_t WinderDistanceToSpoolState(void ) +{ + double DTS_Time = (dryerbufferCentimeters/dyeingspeed)*1000;//distance to spool time in milliseconds + REPORT_MSG ((int)DTS_Time,"WinderDistanceToSpoolState"); + + ScrewDTSControlId = AddControlCallback(ScrewDTSCallback, DTS_Time-WinderBackToBaseTime,TemplateDataReadCBFunction,0,0,0); + REPORT_MSG ((int)msec_millisecondCounter,"ScrewDTSCallback start"); + + return OK; +} + uint32_t Winder_End(void) { //stop screw @@ -458,20 +641,22 @@ void ScrewsStartControlTimer (void) return; } -int random = 0; + void ScrewTimerInterrupt(int ARG0) { ROM_TimerIntClear(Screw_timerBase, TIMER_TIMA_TIMEOUT); // Clear the timer interrupt ROM_IntMasterDisable(); - //Read_Screw_Encoder(); - //ScrewLocationRun[ScrewCurrentDirection] = Screw_RotEnc.Position; if (SCREW_TimerActivated == true) { ROM_TimerLoadSet(Screw_timerBase, TIMER_A,(int)ScrewRunningTime); MotorSetDirection (HARDWARE_MOTOR_TYPE__MOTO_SCREW, ScrewCurrentDirection); - MotorSetSpeedDirect(HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewSpeed+random); + MotorSetSpeedDirect(HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewSpeed); +#ifdef READ_SCREW_ENCODER + Read_Screw_Encoder(); + ScrewLocationRun[ScrewCurrentDirection] = Screw_RotEnc.Position; +#endif // ScrewChangeCounter = 0; // ScrewChangeLimit = ScrewRunningTime/12000000; ScrewDirectionChangeCounter++; @@ -481,7 +666,9 @@ void ScrewTimerInterrupt(int ARG0) TimerDisable(Screw_timerBase, TIMER_A); } ROM_IntMasterEnable(); - Rotations+=0.01; + //Report("ScrewsStartControlTimer direction,speed ", __FILE__,__LINE__,ScrewCurrentDirection, RpMessage, ScrewSpeed, 0); + //MotorSetSpeed(HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewSpeed); + //Rotations+=0.03; return ; diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h index 91eedeb6b..fabb823fc 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h @@ -22,13 +22,14 @@ typedef enum threadMotorsEnum }threadMotorsEnum; extern double TotalProcessedLength; +extern double PoolerTotalProcessedLength; void ThreadSetBreakSensorLimit(int limit); uint32_t InternalWindingConfigMessage(JobSpool* request); uint32_t ThreadConfigBreakSensor(void *request); -uint32_t ThreadGetMotorSpeed(threadMotorsEnum MotorId); +double ThreadGetMotorSpeed(threadMotorsEnum MotorId); double ThreadGetMotorCalculatedError(int DancerId); uint32_t ThreadPrepareState(void *JobDetails); uint32_t ThreadPreSegmentState(void *SegmentDetails, uint32_t SegmentId); @@ -42,31 +43,32 @@ uint32_t LoadDancerConfigMessage(void); //uint32_t MotorPidRequestMessage(HardwarePidControl* request); uint32_t Winder_Init(void); -uint32_t Winder_Prepare(void); +uint32_t Winder_Prepare(void *JobDetails); uint32_t Winder_Presegment(void *JobDetails, uint32_t SegmentId); +uint32_t WinderDistanceToSpoolState(void ); uint32_t Winder_End(void); typedef enum { - THREAD_LOAD_INIT, - THREAD_LOAD_REDUCE_HEAT, //HEATERS OFF, DRYER BLOWER OFF, BLOWER LOW, - THREAD_LOAD_SET_LOAD_ARM_TO_START_POSITION,//USE NOTATION HOW MANY ROTATIONS IN THE DRYER, OR CHECK AGAINST STOPPER. MOVE SLOWLY - THREAD_LOAD_CENTER_HEAD_ROCKERS, //puthead cleaning rockers to middle position - THREAD_LOAD_OPEN_COVERS, //OPEN DYEING HEAD COVER AND DRYER LID - THREAD_LOAD_LIFT_DANCERS, - THREAD_LOAD_LIFT_ROCKERS, //MACHINE IS READY. SEND MESSAGE, START TIMER TO CLOSE LIDS, WAIT FOR OPERATOR RESPONSE - THREAD_LOAD_INITIAL_TENSION,//CHECK SPOOL PRESENCERUN WINDER UNTIL BREAK SENSOR IS IDENTIFIEING MOVEMENT FOR A SECOND - THREAD_LOAD_CLOSE_ROCKERS, - THREAD_LOAD_CLOSE_DANCERS, //SEND DANCER MOTORS TO PRESET LOCATION, CHECK THAT THE DANCERS ARE ON THE THREAD - THREAD_LOAD_CLOSE_LIDS, - THREAD_LOAD_RESUME_HEATING, - THREAD_LOAD_JOG_FEEDER_TO_MIDDLE_POINT,//JOG THE FEEDER MOTOR UNTIL THE FEEDER DANCER IS AT MIDDLE POSITION - THREAD_LOAD_DRYER_LOADING, //START FEEDER PID, ROTATE LOADING ARM COUNTER THREAD DIRECTION X CIRCLES ACCORDING TO RML. FEEDER SPEED IS 40 + /*01*/ THREAD_LOAD_INIT, + /*02*/ THREAD_LOAD_REDUCE_HEAT, //HEATERS OFF, DRYER BLOWER OFF, BLOWER LOW, + /*03*/ THREAD_LOAD_SET_LOAD_ARM_TO_START_POSITION,//USE NOTATION HOW MANY ROTATIONS IN THE DRYER, OR CHECK AGAINST STOPPER. MOVE SLOWLY + /*04*/ THREAD_LOAD_CENTER_HEAD_ROCKERS, //puthead cleaning rockers to middle position + /*05*/ THREAD_LOAD_OPEN_COVERS, //OPEN DYEING HEAD COVER AND DRYER LID + /*06*/ THREAD_LOAD_LIFT_DANCERS, + /*07*/ THREAD_LOAD_LIFT_ROCKERS, //MACHINE IS READY. SEND MESSAGE, START TIMER TO CLOSE LIDS, WAIT FOR OPERATOR RESPONSE + /*08*/ THREAD_LOAD_INITIAL_TENSION,//CHECK SPOOL PRESENCERUN WINDER UNTIL BREAK SENSOR IS IDENTIFIEING MOVEMENT FOR A SECOND + /*09*/ THREAD_LOAD_CLOSE_ROCKERS, + /*10*/ THREAD_LOAD_CLOSE_DANCERS, //SEND DANCER MOTORS TO PRESET LOCATION, CHECK THAT THE DANCERS ARE ON THE THREAD + /*11*/ THREAD_LOAD_CLOSE_LIDS, + /*12*/ THREAD_LOAD_JOG_FEEDER_TO_MIDDLE_POINT,//JOG THE FEEDER MOTOR UNTIL THE FEEDER DANCER IS AT MIDDLE POSITION + /*13*/ THREAD_LOAD_DRYER_LOADING, //START FEEDER PID, ROTATE LOADING ARM COUNTER THREAD DIRECTION X CIRCLES ACCORDING TO RML. FEEDER SPEED IS 40 //KEEP NOTATION HOW MANY ROTATIONS IN THE DRYER - THREAD_LOAD_JOG_THREAD, //JOG THREAD SHORTLY TO MAKE SURE SPOOL IS RUNNING. REPORT END OF LOADING - THREAD_LOAD_END + /*14*/ THREAD_LOAD_RESUME_HEATING, + /*15*/ THREAD_LOAD_JOG_THREAD, //JOG THREAD SHORTLY TO MAKE SURE SPOOL IS RUNNING. REPORT END OF LOADING + /*16*/ THREAD_LOAD_END }THREAD_LOAD_STAGES_ENUM; -uint32_t ThreadLoadStateMachine( THREAD_LOAD_STAGES_ENUM ReadValue); +uint32_t ThreadLoadButton(THREAD_LOAD_STAGES_ENUM ReadValue); bool ThreadLoadingActive(void); diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_init.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_init.c index 4454565c1..38c0f86f1 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_init.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_init.c @@ -17,12 +17,15 @@ #include "Common/SWUpdate/FileSystem.h" #include "drivers/Flash_Memory/fatfs/ff.h" #include "drivers/SSI_Comm/Dancer/Dancer.h" +#include "drivers/Flash_ram/FlashProgram.h" + +#include "drivers/Flash_ram/MCU_E2Prom.h" #include "thread.h" MotorDriverConfigStruc MotorsCfg[NUM_OF_MOTORS]={0}; HardwarePidControl MotorsControl[MAX_THREAD_MOTORS_NUM] = {0}; -int32_t MotorSpeedSamples[MAX_THREAD_MOTORS_NUM][MAX_CONTROL_SAMPLES] = {0}; +double MotorSpeedSamples[MAX_THREAD_MOTORS_NUM][MAX_CONTROL_SAMPLES] = {0}; int MotorSpeedSamplePointer[MAX_THREAD_MOTORS_NUM] = {0}; int32_t MotorSamples[MAX_THREAD_MOTORS_NUM][MAX_CONTROL_SAMPLES] = {0}; @@ -39,11 +42,19 @@ int32_t BreakSensordebouncetimemilli = BREAK_SENSOR_LIMIT; HardwarePidControlType ThreadMotorIdToControlId[MAX_THREAD_MOTORS_NUM] = {HARDWARE_PID_CONTROL_TYPE__MotorFeeder,HARDWARE_PID_CONTROL_TYPE__MotorDryer,HARDWARE_PID_CONTROL_TYPE__MotorPooler,HARDWARE_PID_CONTROL_TYPE__MotorWinder,0}; //******************************************************************************************************************** -uint32_t MotorsConfigMessage(HardwareMotor * request) +uint32_t MotorsConfigMessage(HardwareConfiguration * HWrequest) { uint32_t status = PASSED; - TimerMotors_t Motor_i; - Motor_i = request->hardwaremotortype; + TimerMotors_t Motor_i,MotorId; + HardwareMotor *request; + if (HWrequest == NULL) + return ERROR; + for (MotorId = 0; MotorId < HWrequest->n_motors ; MotorId++) + { + request = HWrequest->motors[MotorId]; + if (request == NULL) + return ERROR; + Motor_i = request->hardwaremotortype; MotorsCfg[Motor_i].configword = request->configword; MotorsCfg[Motor_i].hardwaremotortype = request->hardwaremotortype; MotorsCfg[Motor_i].minfrequency = request->minfrequency; @@ -56,7 +67,7 @@ uint32_t MotorsConfigMessage(HardwareMotor * request) MotorsCfg[Motor_i].pulseperround = request->pulseperround; MotorsCfg[Motor_i].pulleyradius = request->pulleyradius; MotorsCfg[Motor_i].configword = request->configword; - if(MotorDriverResponse[Motor_i].DriverType == VoltageCombinedMotDriver) + if(MotorDriverResponse[Motor_i].DriverType == CombinrdMotDriver) { MotorsCfg[Motor_i].directionthreadwize = !(request->directionthreadwize);//PowerSTEP01 } @@ -79,13 +90,21 @@ uint32_t MotorsConfigMessage(HardwareMotor * request) MotorsCfg[Motor_i].fnslpdec = request->fnslpdec; MotorsCfg[Motor_i].fsspd = request->fsspd; - status = MotorConfig( Motor_i, &MotorsCfg[Motor_i]); + MotorsCfg[Motor_i].gatecfg1 = request->gatecfg1; + MotorsCfg[Motor_i].gatecfg2 = request->gatecfg2; + MotorsCfg[Motor_i].tvalhold = request->tvalhold; + MotorsCfg[Motor_i].tvalrun = request->tvalrun ; + MotorsCfg[Motor_i].tvalacc = request->tvalacc ; + MotorsCfg[Motor_i].tvaldec = request->tvaldec ; + MotorsCfg[Motor_i].tfast = request->tfast ; + MotorsCfg[Motor_i].tonmin = request->tonmin ; + MotorsCfg[Motor_i].toffmin = request->toffmin ; + + status = MotorConfig( Motor_i, &MotorsCfg[Motor_i]); // if (Motor_i == MOTOR_RDRIVING) // ThreadInitialTestStub(request); - + } return status; -// } -// else return Motor_i; } uint32_t MotorPidRequestMessage(HardwarePidControl* request) @@ -106,18 +125,18 @@ uint32_t MotorPidRequestMessage(HardwarePidControl* request) #ifdef TEST_LONGER_PID_THREAD MotorsControl[Motor_i].pvinputfilterfactormode = 10; //test longer control #endif - for (i = 0;i < MotorsControl[Motor_i].pvinputfilterfactormode; i++) + for (i = 0;i < (int)MotorsControl[Motor_i].pvinputfilterfactormode; i++) { MotorSamples[Motor_i][i] = 0; //reset the samples value for control beginning MotorSpeedSamples[Motor_i][i] = 0; } NormalizedErrorCoEfficient[Motor_i] = (2*PI*DancersCfg[ThreadMotorIdToDancerId[Motor_i]].armlength); temp = 1<<(DancersCfg[ThreadMotorIdToDancerId[Motor_i]].resolutionbits); - temp=(10*(temp-1)*DancersCfg[ThreadMotorIdToDancerId[Motor_i]].maximalmovementmm); + temp=(NORMAL_COEF_DIVIDER*(temp-1)*DancersCfg[ThreadMotorIdToDancerId[Motor_i]].maximalmovementmm); NormalizedErrorCoEfficient[Motor_i] = NormalizedErrorCoEfficient[Motor_i] / temp; // uint32_t MotorSamples[MAX_THREAD_MOTORS_NUM][MAX_CONTROL_SAMPLES]; temp = 1<<(DancersCfg[ThreadMotorIdToDancerId[Motor_i]].resolutionbits); - temp = (temp*DancersCfg[ThreadMotorIdToDancerId[Motor_i]].maximalmovementmm*2); + temp = (temp*DancersCfg[ThreadMotorIdToDancerId[Motor_i]].maximalmovementmm*3/2); DancerStopActivityLimit[Motor_i] = temp/(2*PI*DancersCfg[ThreadMotorIdToDancerId[Motor_i]].armlength); return OK; } @@ -145,12 +164,24 @@ uint32_t StoreDancerConfigMessage() DancerConfig.n_dancers++; DancersCfg[Dancer_i].zeropoint = DancerConfig.dancers[Dancer_i]->zeropoint; } + MCU_E2PromProgram(EEPROM_STORAGE_DANCER_0,DancersCfg[0].zeropoint); + MCU_E2PromProgram(EEPROM_STORAGE_DANCER_1,DancersCfg[1].zeropoint); + MCU_E2PromProgram(EEPROM_STORAGE_DANCER_2,DancersCfg[2].zeropoint); + Report("Store eeprom 0",__FILE__,DancersCfg[0].zeropoint,(int)DancersCfg[1].zeropoint,RpWarning,(int)DancersCfg[2].zeropoint,0); + response_buffer = my_malloc(hardware_configuration__get_packed_size(&DancerConfig)); if (response_buffer) { response_size = hardware_configuration__pack(&DancerConfig, response_buffer); } - Fresult = FileWrite(response_buffer,response_size,DancerConfigPath); + Fresult = FileWrite(response_buffer,response_size,DancerConfigPath,BIOS_WAIT_FOREVER); + EraseFlashSection(DANCERS_MAP_IN_FLASH,1024); + for (Dancer_i = 0; Dancer_i < MAX_SYSTEM_DANCERS; Dancer_i++) + { + ReadAppAndProgram(DANCERS_MAP_IN_FLASH, sizeof(Dancers), Dancers); + } + + my_free(response_buffer); return Fresult; @@ -163,6 +194,10 @@ uint32_t LoadDancerConfigMessage() HardwareConfiguration *DancerConfig; int Dancer_i; + HardwareDancer DancersCfg1[MAX_SYSTEM_DANCERS] = {0}; + HardwareDancer DancersCfg2[MAX_SYSTEM_DANCERS] = {0}; + + memcpy(DancersCfg1,(void *)DANCERS_MAP_IN_FLASH,sizeof(DancersCfg1)); Fresult = FileRead(DancerConfigPath, &Bytes, &buffer); if (Fresult == FR_OK) @@ -170,11 +205,20 @@ uint32_t LoadDancerConfigMessage() DancerConfig = hardware_configuration__unpack(NULL, Bytes, buffer); for (Dancer_i = 0; Dancer_i < DancerConfig->n_dancers ; Dancer_i++) { - DancersCfg[Dancer_i].zeropoint = DancerConfig->dancers[Dancer_i]->zeropoint; + DancersCfg2[Dancer_i].zeropoint = DancerConfig->dancers[Dancer_i]->zeropoint; } hardware_configuration__free_unpacked(DancerConfig,NULL); free (buffer); } + MCU_E2PromRead(EEPROM_STORAGE_DANCER_0,&DancersCfg[0].zeropoint); + MCU_E2PromRead(EEPROM_STORAGE_DANCER_1,&DancersCfg[1].zeropoint); + MCU_E2PromRead(EEPROM_STORAGE_DANCER_2,&DancersCfg[2].zeropoint); + + + Report("Dancer 0 Store data flash, internal flash, eeprom ",__FILE__,DancersCfg[0].zeropoint,(int)DancersCfg1[0].zeropoint,RpWarning,(int)DancersCfg2[0].zeropoint,0); + Report("Dancer 1 Store data flash, internal flash, eeprom ",__FILE__,DancersCfg[1].zeropoint,(int)DancersCfg1[1].zeropoint,RpWarning,(int)DancersCfg2[1].zeropoint,0); + Report("Dancer 2 Store data flash, internal flash, eeprom ",__FILE__,DancersCfg[2].zeropoint,(int)DancersCfg1[2].zeropoint,RpWarning,(int)DancersCfg2[2].zeropoint,0); + return Fresult; } diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c index c292f7dcd..59542ec38 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c @@ -39,7 +39,7 @@ //by recieved esign flow of the user from the UI /////////////////////////////////////////////////////////////////////////////////////////// -uint32_t CurrentControlledSpeed[MAX_THREAD_MOTORS_NUM] = {0}; +double CurrentControlledSpeed[MAX_THREAD_MOTORS_NUM] = {0}; TimerMotors_t ThreadMotorIdToMotorId[MAX_THREAD_MOTORS_NUM] = {HARDWARE_MOTOR_TYPE__MOTO_RDRIVING,HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING,HARDWARE_MOTOR_TYPE__MOTO_LDRIVING,HARDWARE_MOTOR_TYPE__MOTO_WINDER,HARDWARE_MOTOR_TYPE__MOTO_SCREW}; HardwareDancerType ThreadMotorIdToDancerId[MAX_THREAD_MOTORS_NUM] = {FEEDER_DANCER,NUM_OF_DANCERS,POOLER_DANCER,WINDER_DANCER,NUM_OF_DANCERS}; @@ -48,7 +48,7 @@ uint32_t SpeedControlId=0xFF; uint32_t PoolerSpeedControlId=0xFF; double DancerError[NUM_OF_DANCERS] = {0.0}; -int OriginalMotorSpd_2PPS[MAX_THREAD_MOTORS_NUM] = {0}; +double OriginalMotorSpd_2PPS[MAX_THREAD_MOTORS_NUM] = {0}; uint32_t JobCounter = 0; MotorControlConfig_t MotorControlConfig[MAX_THREAD_MOTORS_NUM]; @@ -67,6 +67,7 @@ double PoolerLengthCalculationMultiplier; double TempPoolerTotalProcessedLength = 0.0; double TempTotalProcessedLength = 0.0; +bool InitialProcess = false; bool PrepareState = false; // job parameters bool EnableLubrication = false; @@ -114,7 +115,10 @@ uint32_t Control_Delta_Position_Pass(uint32_t Current_Read,uint32_t Previous_Rea if (Current_Read < Previous_Read) + { Time_Pass = (MAX_COUNTER - Previous_Read) + Current_Read + 1; + Report("Length rollover",__FILE__,__LINE__,(int)Current_Read,RpWarning,(int)Previous_Read,0); + } else Time_Pass = Current_Read - Previous_Read; @@ -137,20 +141,20 @@ void ThreadUpdateProcessLength (double length, void *Funcptr) CurrentRequestedLength = length*100;//Centimetres CurrentProcessedLength = 0; ProcessedLengthFuncPtr = (ProcessedLengthFunc)Funcptr; - initialpos = 0xFFFF; - Poolerinitialpos = 0xFFFF; } char Lenstr[150]; uint32_t ThreadLengthCBFunction(uint32_t IfIndex, uint32_t ReadValue) { - uint32_t positionDiff = 0; + uint32_t positionDiff = 0,prevprev; double length = 0.0; int index = MAX_THREAD_MOTORS_NUM; - // if (ThreadControlActive == false) - // return OK; - // if (PrepareState == true) - // return OK; +#ifndef FEEDER_LENGTH_CALCULATION + if (ThreadControlActive == false) + return OK; + if (PrepareState == true) + return OK; +#endif if (IfIndex>>8 != IfTypeThread) { LOG_ERROR (IfIndex, "Wrong Interface type"); @@ -165,30 +169,42 @@ uint32_t ThreadLengthCBFunction(uint32_t IfIndex, uint32_t ReadValue) return 0xFFFFFFFF; } CurrentPosition = MotorGetPosition(ThreadMotorIdToMotorId[index]); -// if (CurrentPosition == 0) -// return OK; //unusable data - if (initialpos == 0xFFFF) + if (CurrentPosition != 0) { + if (initialpos == 0xFFFF) + { + PreviousPosition = CurrentPosition; + initialpos = 0; + } + prevprev = PreviousPosition; + positionDiff = Control_Delta_Position_Pass(CurrentPosition,PreviousPosition); + //positionDiff = positionDiff / MotorsCfg[ThreadMotorIdToMotorId[index]].microstep; PreviousPosition = CurrentPosition; - initialpos = 0; - } - positionDiff = Control_Delta_Position_Pass(CurrentPosition,PreviousPosition); - //positionDiff = positionDiff / MotorsCfg[ThreadMotorIdToMotorId[index]].microstep; - PreviousPosition = CurrentPosition; - // total length = (position diff / full cycle) * pulley perimeter - //(positionDiff/pulseperround)*((2*PI*motor_Radius) + // total length = (position diff / full cycle) * pulley perimeter + //(positionDiff/pulseperround)*((2*PI*motor_Radius) - //positionDiff = positionDiff / MotorsCfg[ThreadMotorIdToMotorId[index]].microstep; - length = (double)(positionDiff)*LengthCalculationMultiplier; + //positionDiff = positionDiff / MotorsCfg[ThreadMotorIdToMotorId[index]].microstep; + length = (double)(positionDiff)*LengthCalculationMultiplier; - CurrentProcessedLength+=length; + if (length > 1000) + { + usnprintf(Lenstr, 100, "length huge: length %d, diff 0x%x, pos 0x%x prev 0x%x",(int)length*100,(int)positionDiff,PreviousPosition,prevprev); + SendJobProgress(0.0,0,false, Lenstr); + Report(Lenstr,__FILE__,__LINE__,(int)TotalProcessedLength,RpWarning,(int)PoolerTotalProcessedLength,0); + length = 0; - static int pooler_counter = 0; - pooler_counter++; - TotalProcessedLength+= (length/100); + } + + } + TotalProcessedLength += (length/100); TempTotalProcessedLength = TotalProcessedLength; - if (pooler_counter%10 == 0) +#ifdef FEEDER_LENGTH_CALCULATION + CurrentProcessedLength+=length; + + static int feeder_counter = 0; + feeder_counter++; + if (feeder_counter%10 == 0) { if (PrepareState == true) { @@ -213,18 +229,22 @@ uint32_t ThreadLengthCBFunction(uint32_t IfIndex, uint32_t ReadValue) ProcessedLengthFuncPtr(); } -return OK; +#endif + + return OK; } uint32_t PoolerThreadLengthCBFunction(uint32_t IfIndex, uint32_t ReadValue) { - uint32_t positionDiff = 0; + uint32_t positionDiff = 0,prevprev; double length = 0.0; int index = MAX_THREAD_MOTORS_NUM; +#ifdef FEEDER_LENGTH_CALCULATION if (ThreadControlActive == false) return OK; if (PrepareState == true) return OK; +#endif if (IfIndex>>8 != IfTypeThread) { LOG_ERROR (IfIndex, "Wrong Interface type"); @@ -239,20 +259,68 @@ uint32_t PoolerThreadLengthCBFunction(uint32_t IfIndex, uint32_t ReadValue) return 0xFFFFFFFF; } PoolerCurrentPosition = MotorGetPosition(ThreadMotorIdToMotorId[index]); -// if (CurrentPosition == 0) -// return OK; //unusable data - if (Poolerinitialpos == 0xFFFF) - { + //if (PoolerCurrentPosition != 0) + //{ + if (Poolerinitialpos == 0xFFFF) + { + PoolerPreviousPosition = PoolerCurrentPosition; + Poolerinitialpos = 0; + } + prevprev = PoolerPreviousPosition; + positionDiff = Control_Delta_Position_Pass(PoolerCurrentPosition,PoolerPreviousPosition); + //positionDiff = positionDiff / MotorsCfg[ThreadMotorIdToMotorId[index]].microstep; PoolerPreviousPosition = PoolerCurrentPosition; - Poolerinitialpos = 0; - } - positionDiff = Control_Delta_Position_Pass(PoolerCurrentPosition,PoolerPreviousPosition); - //positionDiff = positionDiff / MotorsCfg[ThreadMotorIdToMotorId[index]].microstep; - PoolerPreviousPosition = PoolerCurrentPosition; - length = (double)(positionDiff)*PoolerLengthCalculationMultiplier; + // total length = (position diff / full cycle) * pulley perimeter + //(positionDiff/pulseperround)*((2*PI*motor_Radius) + + //positionDiff = positionDiff / MotorsCfg[ThreadMotorIdToMotorId[index]].microstep; + length = (double)(positionDiff)*PoolerLengthCalculationMultiplier; + + if (length > 1000) + { + usnprintf(Lenstr, 100, "length huge: length %d, diff 0x%x, pos 0x%x prev 0x%x",(int)length*100,(int)positionDiff,PreviousPosition,prevprev); + SendJobProgress(0.0,0,false, Lenstr); + Report(Lenstr,__FILE__,__LINE__,(int)TotalProcessedLength,RpWarning,(int)PoolerTotalProcessedLength,0); + length = 0; + + } + + //} + PoolerTotalProcessedLength+= (length/100); TempPoolerTotalProcessedLength = PoolerTotalProcessedLength; +#ifndef FEEDER_LENGTH_CALCULATION + CurrentProcessedLength+=length; + + static int puller_counter = 0; + puller_counter++; + if (puller_counter%10 == 0) + { + if (PrepareState == true) + { + //later - add temperatures + TemperatureListString(Lenstr); + + SendJobProgress(0.0,0,false, Lenstr); + } + else + { + SendJobProgress(PoolerTotalProcessedLength,0,false, NULL); + } + + } + if ((CurrentProcessedLength>=CurrentRequestedLength )&&(CurrentRequestedLength > 0.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(); + + } +#endif return OK; } @@ -267,7 +335,7 @@ uint32_t ThreadSpeedControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) int index=MAX_THREAD_MOTORS_NUM; int32_t i, avreageSampleValue = 0; //double tempcalcspeed = 0; - uint32_t calculated_speed; + double calculated_speed; float speed = getSensorSpeedData(); if (IfIndex>>8 != IfTypeThread) { @@ -277,11 +345,11 @@ uint32_t ThreadSpeedControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) index = IfIndex&0xFF; SpeedSamples[MotorSamplePointer[index]] = speed;//(-1 * TranslatedReadValue); MotorSamplePointer[index]++; - if (MotorSamplePointer[index] >= MotorsControl[index].pvinputfilterfactormode) + if (MotorSamplePointer[index] >= (int)MotorsControl[index].pvinputfilterfactormode) MotorSamplePointer[index] = 0; - for (i=0;i<MotorsControl[index].pvinputfilterfactormode;i++) + for (i=0;i<(int)MotorsControl[index].pvinputfilterfactormode;i++) avreageSampleValue += SpeedSamples[i]; - avreageSampleValue = avreageSampleValue / MotorsControl[index].pvinputfilterfactormode; + avreageSampleValue = avreageSampleValue / (int)MotorsControl[index].pvinputfilterfactormode; if(MotorControlConfig[index].m_isEnabled && (MotorControlConfig[index].m_SetParam != 0)) { MotorControlConfig[index].m_mesuredParam = ReadValue; @@ -289,7 +357,7 @@ uint32_t ThreadSpeedControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) &MotorControlConfig[index].m_params, &MotorControlConfig[index].m_preError, &MotorControlConfig[index].m_integral); //SetMotorFreq (index, MotorControlConfig[index].m_calculatedError); calculated_speed = (1-MotorControlConfig[index].m_calculatedError)*OriginalMotorSpd_2PPS[index]; - if (abs(calculated_speed-CurrentControlledSpeed[index])>2) + if (fabs(calculated_speed-CurrentControlledSpeed[index])>2) { CurrentControlledSpeed[index] = calculated_speed; MotorSetSpeed(ThreadMotorIdToMotorId[index], calculated_speed); @@ -297,7 +365,7 @@ uint32_t ThreadSpeedControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) } return OK; } -uint32_t _speed; +float _speed; uint32_t ThreadControlSpeedReadFunction(uint32_t IfIndex, uint32_t ReadValue) { int index; @@ -315,9 +383,14 @@ uint32_t ThreadControlSpeedReadFunction(uint32_t IfIndex, uint32_t ReadValue) } return OK; } + +int controlIndex = 0; +bool keepdata = true; +int32_t KeepReadValue = 0; //double eNormalizedError[100]; //int TranslatedreadValue[100]; -/*#define MAX_THREAD_CONTROL_LOG 100 +#ifdef TEST_PID_THREAD +#define MAX_THREAD_CONTROL_LOG 100 double calculatedError[MAX_THREAD_CONTROL_LOG+1]; double NormError[MAX_THREAD_CONTROL_LOG+1]; double mIntegral[MAX_THREAD_CONTROL_LOG+1]; @@ -325,10 +398,8 @@ int MotorId[MAX_THREAD_CONTROL_LOG+1]; int readValue[MAX_THREAD_CONTROL_LOG+1]; int AveragereadValue[MAX_THREAD_CONTROL_LOG+1]; int calculatedspeed[MAX_THREAD_CONTROL_LOG+1]; -int timestamp[MAX_THREAD_CONTROL_LOG+1];*/ -int controlIndex = 0; -bool keepdata = true; -/*int32_t KeepReadValue = 0; +int timestamp[MAX_THREAD_CONTROL_LOG+1]; + void testDancersControl() { int mm20,mm10,mm5,mm2,mm1; @@ -337,8 +408,20 @@ void testDancersControl() mm5 = mm20/4; mm10 = mm20/2; mm1 = mm20/20; + char time[150]; + int len; ThreadControlActive = true; - SetOriginMotorSpeed(30.0); + SetOriginMotorSpeed(50.0); + MotorControlConfig[FEEDER_MOTOR].m_params.epsilon = 0; + MotorsControl[FEEDER_MOTOR].controloutputtype = 0.001; + MotorControlConfig[FEEDER_MOTOR].m_params.dt = 0.001; + DancersCfg[HARDWARE_DANCER_TYPE__RightDancer].zeropoint = 10000; + MotorsControl[FEEDER_MOTOR].pvinputfilterfactormode = 1; + len = usnprintf(time, 150, "params: speed 50, divider %d p %d * %d i %d * %d Dt*1000 %d Norm Coef %d initial speed %d",NORMAL_COEF_DIVIDER,(int)MotorsControl[FEEDER_MOTOR].proportionalgain,(int)MotorsControl[FEEDER_MOTOR].outputonoffhysteresisvalue, + (int)MotorsControl[FEEDER_MOTOR].integraltime,(int)MotorsControl[FEEDER_MOTOR].setpointramprateorsoftstartramp,(int)(MotorsControl[FEEDER_MOTOR].controloutputtype*1000), + (int)(NormalizedErrorCoEfficient[FEEDER_MOTOR]*1000000000),OriginalMotorSpd_2PPS[FEEDER_MOTOR]); + Report(time,__FILE__,__LINE__,111,RpError,111,0); + Task_sleep(100); ThreadControlCBFunction(IfTypeThread*0x100+FEEDER_MOTOR, DancersCfg[HARDWARE_DANCER_TYPE__RightDancer].zeropoint - mm20); ThreadControlCBFunction(IfTypeThread*0x100+FEEDER_MOTOR, DancersCfg[HARDWARE_DANCER_TYPE__RightDancer].zeropoint - mm10); ThreadControlCBFunction(IfTypeThread*0x100+FEEDER_MOTOR, DancersCfg[HARDWARE_DANCER_TYPE__RightDancer].zeropoint - mm5); @@ -351,10 +434,12 @@ void testDancersControl() ThreadControlCBFunction(IfTypeThread*0x100+FEEDER_MOTOR, DancersCfg[HARDWARE_DANCER_TYPE__RightDancer].zeropoint + mm10); ThreadControlCBFunction(IfTypeThread*0x100+FEEDER_MOTOR, DancersCfg[HARDWARE_DANCER_TYPE__RightDancer].zeropoint + mm20); ThreadControlActive = false; -}*/ +} +#endif bool dancerinvalid = false; int MotorFailedSample[MAX_THREAD_MOTORS_NUM] = {0,0,0,0,0}; -char TMessage[60]; +char TMessage[150]; +//char time[150]; uint16_t BreakSensorCounter = 0; uint16_t BreakSensorLatchCounter = 0; uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) @@ -366,16 +451,17 @@ uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) //read value is the dancer angle int i,index=MAX_THREAD_MOTORS_NUM; int DancerId; - int32_t TranslatedReadValue, avreageSampleValue = 0,avreageMotorSampleValue = 0; + int32_t TranslatedReadValue, avreageSampleValue = 0;//,avreageMotorSampleValue = 0; //double tempcalcspeed = 0; - uint32_t calculated_speed; + double calculated_speed; double NormalizedError; if (ThreadControlActive == false) return OK; +#ifndef TEST_PID_THREAD if (PrepareState == true) return OK; - +#endif if (IfIndex>>8 != IfTypeThread) { LOG_ERROR (IfIndex, "Wrong Interface type"); @@ -404,6 +490,7 @@ uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) } return OK; } + KeepReadValue = ReadValue; TranslatedReadValue = ReadValue - DancersCfg[DancerId].zeropoint; if (index == POOLER_MOTOR) { @@ -414,15 +501,15 @@ uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) //TranslatedReadValue = 0;//test MotorSamples[index][MotorSamplePointer[index]] = TranslatedReadValue;//(-1 * TranslatedReadValue); MotorSamplePointer[index]++; - if (MotorSamplePointer[index] >= MotorsControl[index].pvinputfilterfactormode) + if (MotorSamplePointer[index] >= (int)MotorsControl[index].pvinputfilterfactormode) MotorSamplePointer[index] = 0; #ifdef TEST_LONGER_PID_THREAD else // test: handle tension once in pvinputfilterfactormode milliseconds return OK; #endif - for (i=0;i<MotorsControl[index].pvinputfilterfactormode;i++) + for (i=0;i<(int)MotorsControl[index].pvinputfilterfactormode;i++) avreageSampleValue += MotorSamples[index][i]; - avreageSampleValue = avreageSampleValue / MotorsControl[index].pvinputfilterfactormode; + avreageSampleValue = avreageSampleValue / (int)MotorsControl[index].pvinputfilterfactormode; if (BreakSensorenabled == true) { @@ -457,6 +544,25 @@ uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) } BreakSensorCounter = 0; } + if (CurrentControlledSpeed[index] < (OriginalMotorSpd_2PPS[index]/3)) + { + BreakSensorCounter++; + BreakSensorLatchCounter++; + if (BreakSensorCounter>=BreakSensordebouncetimemilli) + { + //consider applying the debouce parameters later + usnprintf(TMessage, 60, "thread speed too low"); + JobEndReason = JOB_THREAD_BREAK; + ThreadControlActive = false; + SendJobProgress(0.0,0,false, TMessage); + SendSegmentFail(); + //AlarmHandlingSetAlarm(EVENT_TYPE__THREAD_BREAK,true); + //EndState(CurrentJob,"ReadBreakSensor Error" ); + LOG_ERROR(index, "thread speed too low Error"); + return OK; + } + } + } } } @@ -466,6 +572,7 @@ uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) { keepdata = false; usnprintf(TMessage, 60, "Dancer %d limit %d value %d Zero %d",DancerId,DancerStopActivityLimit[index],avreageSampleValue,DancersCfg[DancerId].zeropoint); + Report(TMessage,__FILE__,__LINE__,avreageSampleValue,RpWarning,DancerStopActivityLimit[index],0); //JobAbortedByUser = true; ThreadControlActive = false; //MotorGetStatusFromFPGA(ThreadMotorIdToMotorId[index]); @@ -501,9 +608,13 @@ uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) { //KeepNormalizedError = NormalizedError; } - if ((JobCounter % 1000) == 0) + /*if ((JobCounter % 100) == 0) { - if (JobCounter >= 20000) + //if (index == WINDER_MOTOR) //feeder unit handles errors opposite to left unit + //{ + // Report("MotorSpeedUpdated",__FILE__,index,OriginalMotorSpd_2PPS[index],RpWarning,CurrentControlledSpeed[index],0); + //} + /`*if (JobCounter >= 3000) { MotorSpeedSamples[index][MotorSpeedSamplePointer[index]] = CurrentControlledSpeed[index];//(-1 * TranslatedReadValue); MotorSpeedSamplePointer[index]++; @@ -514,31 +625,51 @@ uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) avreageMotorSampleValue = avreageMotorSampleValue / MAX_CONTROL_SAMPLES; //Report("MotorSpeedUpdated",__FILE__,index,OriginalMotorSpd_2PPS[index],RpWarning,avreageMotorSampleValue,0); OriginalMotorSpd_2PPS[index] = avreageMotorSampleValue; - } - } + }*`/ + }*/ calculated_speed = (1-MotorControlConfig[index].m_calculatedError)*OriginalMotorSpd_2PPS[index]; //calculated_speed = (1-MotorControlConfig[index].m_calculatedError)*CurrentControlledSpeed[index]; - if (abs(calculated_speed-CurrentControlledSpeed[index])> MotorControlConfig[index].m_ingnoreValue) +#ifndef TEST_PID_THREAD + if (fabs(calculated_speed-CurrentControlledSpeed[index])> MotorControlConfig[index].m_ingnoreValue) +#else + if (index == FEEDER_MOTOR) //feeder unit handles errors opposite to left unit +#endif { - /*if (keepdata == true) - { - calculatedError[controlIndex] = MotorControlConfig[index].m_calculatedError; - MotorId[controlIndex] = index; - readValue[controlIndex] = ReadValue; - AveragereadValue[controlIndex] = avreageSampleValue; - calculatedspeed[controlIndex] = calculated_speed; - NormError[controlIndex] - = MotorControlConfig[index].m_mesuredParam; - mIntegral[controlIndex] = MotorControlConfig[index].m_integral; - timestamp[controlIndex] = msec_millisecondCounter; - if (controlIndex++>=MAX_THREAD_CONTROL_LOG) - controlIndex = 0; - }*/ CurrentControlledSpeed[index] = calculated_speed; MotorSetSpeed(ThreadMotorIdToMotorId[index], calculated_speed); + /*if (((JobCounter % 2000) == index*100)&&(index == WINDER_MOTOR)) //feeder unit handles errors opposite to left unit + { + Report("MotorSpeedUpdated",__FILE__,index,(int)OriginalMotorSpd_2PPS[index],RpWarning,(int)CurrentControlledSpeed[index],0); + }*/ +#ifdef TEST_PID_THREAD + int len; + if ((JobCounter % 2000) == index*100) + //if (keepdata == true) + { + /*calculatedError[controlIndex] = MotorControlConfig[index].m_calculatedError; + MotorId[controlIndex] = index; + readValue[controlIndex] = ReadValue; + AveragereadValue[controlIndex] = avreageSampleValue; + calculatedspeed[controlIndex] = calculated_speed; + NormError[controlIndex] = MotorControlConfig[index].m_mesuredParam; + mIntegral[controlIndex] = MotorControlConfig[index].m_integral; + timestamp[controlIndex] = msec_millisecondCounter;*/ + len = usnprintf(TMessage, 150, "read %d avg %d error(6) %d integral(9) %d,delta(9) %d, calc(3) %d speed %d", + ReadValue,avreageSampleValue,(int)(MotorControlConfig[index].m_mesuredParam*1000000), + (int)(MotorControlConfig[index].m_integral*1000000000),(int)((MotorControlConfig[index].m_mesuredParam*MotorControlConfig[index].m_params.dt)*1000000000), + (int)(MotorControlConfig[index].m_calculatedError*1000),(int)calculated_speed); + Report(TMessage,__FILE__,__LINE__,DancerId,RpError,ReadValue,0); + //Task_sleep(100); + //if (controlIndex++>=MAX_THREAD_CONTROL_LOG) + // controlIndex = 0; + } +#endif } else + { MotorFailedSample[index]++; + //LOG_ERROR(index,"No change in speed"); + } } @@ -546,7 +677,7 @@ uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) } //******************************************************************************************************************** -uint32_t ThreadGetMotorSpeed(threadMotorsEnum MotorId) +double ThreadGetMotorSpeed(threadMotorsEnum MotorId) { return CurrentControlledSpeed[MotorId]; } @@ -576,7 +707,6 @@ uint32_t ThreadInitialTestStub(HardwareMotor * request) ThreadPreSegmentState(request,0); return OK; } -bool InitialProcess = false; //******************************************************************************************************************** uint32_t ThreadPrepareState(void *JobDetails) @@ -627,6 +757,7 @@ bool InitialProcess = false; 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 { + Report("Feeder Control",__FILE__,Motor_i,MotorControlConfig[Motor_i].m_params.Kp,RpWarning,MotorControlConfig[Motor_i].m_params.Ki,0); if (SpeedControlId != 0xFF) { RemoveControlCallback(SpeedControlId,ThreadLengthCBFunction); @@ -638,6 +769,7 @@ bool InitialProcess = false; } if (Motor_i == POOLER_MOTOR) // dryer motor is speed controlled. later a speed sensor will be utilized, but for now it will not be controlled { + Report("Puller Control",__FILE__,Motor_i,MotorControlConfig[Motor_i].m_params.Kp,RpWarning,MotorControlConfig[Motor_i].m_params.Ki,0); if (PoolerSpeedControlId != 0xFF) { if (RemoveControlCallback(PoolerSpeedControlId,PoolerThreadLengthCBFunction)!=OK) @@ -657,8 +789,10 @@ bool InitialProcess = false; ControlIdtoMotorId[Motor_i] = 0xFF; CurrentControlledSpeed[Motor_i] = 0; } +#ifndef TEST_PID_THREAD ControlIdtoMotorId[Motor_i] = AddControlCallback(ThreadControlCBFunction, eOneMillisecond,Control_Read_Dancer_Position,(IfTypeThread*0x100+Motor_i),ThreadMotorIdToDancerId[Motor_i],Motor_i); //AddControlCallback(ThreadControlSpeedReadFunction, eHundredMillisecond,MotorGetSpeedFromFPGA,(IfTypeThread*0x100+Motor_i),ThreadMotorIdToMotorId[Motor_i],Motor_i); +#endif } if (Motor_i == POOLER_MOTOR) // dryer motor is speed controlled. later a speed sensor will be utilized, but for now it will n//ot be controlled { @@ -669,10 +803,13 @@ bool InitialProcess = false; CurrentControlledSpeed[Motor_i] = 0; ControlIdtoMotorId[Motor_i] = 0xFF; } +#ifndef TEST_PID_THREAD ControlIdtoMotorId[Motor_i] = AddControlCallback(ThreadControlCBFunction, eOneMillisecond,Control_Read_Dancer_Position,(IfTypeThread*0x100+Motor_i),ThreadMotorIdToDancerId[Motor_i],Motor_i); +#endif } if (Motor_i == WINDER_MOTOR) // dryer motor is speed controlled. later a speed sensor will be utilized, but for now it will n//ot be controlled { + Report("Winder Control",__FILE__,Motor_i,MotorControlConfig[Motor_i].m_params.Kp,RpWarning,MotorControlConfig[Motor_i].m_params.Ki,0); if (ControlIdtoMotorId[Motor_i] != 0xFF) { if(RemoveControlCallback(ControlIdtoMotorId[Motor_i],ThreadControlCBFunction)!=OK) @@ -680,17 +817,23 @@ bool InitialProcess = false; CurrentControlledSpeed[Motor_i] = 0; ControlIdtoMotorId[Motor_i] = 0xFF; } +#ifndef TEST_PID_THREAD ControlIdtoMotorId[Motor_i] = AddControlCallback(ThreadControlCBFunction, eOneMillisecond,Control_Read_Dancer_Position,(IfTypeThread*0x100+Motor_i),ThreadMotorIdToDancerId[Motor_i],Motor_i); +#endif } // if (HW_Motor_Id == HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING) // dryer motor is speed controlled. later a speed sensor will be utilized, but for now it will not be controlled // AddControlCallback(ThreadSpeedControlCBFunction, eOneMillisecond,TemplateDataReadCBFunction,(IfTypeThread*0x100+Motor_i),ThreadMotorIdToMotorId[Motor_i],0); if (Motor_i == HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING) // dryer motor is speed controlled. later a speed sensor will be utilized, but for now it will not be controlled continue; } - //testDancersControl(); +#ifdef TEST_PID_THREAD + testDancersControl(); +#endif PrepareReady(Module_Thread,ModuleDone); //set 3 dancers to the profile positions InitialProcess = true; + initialpos = 0xFFFF; + Poolerinitialpos = 0xFFFF; return OK; } @@ -708,10 +851,18 @@ void SetOriginMotorSpeed(float process_speed) //MotorControlConfig[Motor_i].m_SetParam = motor_speed; OriginalMotorSpd_2PPS[Motor_i] = (int) motor_speed; CurrentControlledSpeed[Motor_i] = (int) motor_speed; + //Report("Original Speed",__FILE__,Motor_i,motor_speed,RpWarning,process_speed,0); + for (i = 0; i <= MAX_CONTROL_SAMPLES; i++) MotorSpeedSamples[Motor_i][i] = motor_speed; } } +void ThreadPreSegmentEnded(void) +{ + InitialProcess = false; + REPORT_MSG (0,"First ThreadPreSegmentEnded"); + PreSegmentReady(Module_Thread,ModuleDone); +} //******************************************************************************************************************** uint32_t ThreadPreSegmentState(void *SegmentDetails, uint32_t SegmentId) @@ -731,8 +882,10 @@ uint32_t ThreadPreSegmentState(void *SegmentDetails, uint32_t SegmentId) SetOriginMotorSpeed(process_speed); ThreadControlActive = true; PrepareState = false; +#ifndef TEST_PID_THREAD // set the new speed in the dryer motor to the speed of the new segment MotorSetSpeed(HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING, OriginalMotorSpd_2PPS[DRYER_MOTOR]); +#endif #ifdef HUNDRED_MICROSECONDS_DANCER_READ MillisecLogInit(); #endif @@ -764,6 +917,14 @@ uint32_t ThreadPreSegmentState(void *SegmentDetails, uint32_t SegmentId) PreSegmentState = true; DTSState = false; } + /*else if (InitialProcess==true) + { + ThreadUpdateProcessLength (dryerbufferMeters,(void *)ThreadPreSegmentEnded); + REPORT_MSG (dryerbufferCentimeters," ThreadPreSegmentState DTS length (sample)"); + SegmentState = false; + PreSegmentState = true; + DTSState = false; + }*/ else { ThreadUpdateProcessLength (0,(void *)NULL); @@ -821,9 +982,14 @@ uint32_t ThreadSegmentState(void *SegmentDetails, int SegmentId) //******************************************************************************************************************** uint32_t ThreadDistanceToSpoolState(void ) { - seglength = dryerbufferlength; + seglength = dryerbufferMeters; REPORT_MSG (seglength,"ThreadDistanceToSpoolState"); +//#ifdef FEEDER_LENGTH_CALCULATION ThreadUpdateProcessLength (seglength,(void *)ThreadDistanceToSpoolEnded); +/*#else + ThreadUpdateProcessLength (0,(void *)NULL); //move DTS to job start + DistanceToSpoolReady(Module_Thread,ModuleDone); +#endif*/ SegmentState = false; PreSegmentState = false; DTSState = true; @@ -869,6 +1035,10 @@ char Endstr[150]; else LOG_ERROR (ControlIdtoMotorId[Motor_i],"Remove Control failed"); } + } + Task_sleep(10); + for ( Motor_i = 0;Motor_i <= WINDER_MOTOR;Motor_i++) + { MotorStop(ThreadMotorIdToMotorId[Motor_i],Hard_Hiz); } MotorStop(HARDWARE_MOTOR_TYPE__MOTO_RLOADING,Hard_Hiz); |
