From 8d4920307ed4bbb6760245728934b91e249fe6c4 Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Tue, 13 Nov 2018 10:41:45 +0200 Subject: prevent sending diagnostics message if the prev one did not run. improve winding --- Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.new | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.new') diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.new b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.new index f33a134e1..537d27775 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.new +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.new @@ -177,14 +177,14 @@ uint32_t CalculateNumberOfSteps (uint32_t Counter, bool direction) float screw_horizontal_speed = 0; float RotationsPerSecond; - if (Counter%InternalWinderCfg.spoolbackingrate == 0) + if (Counter%InternalWinderCfg.spoolbackingrate == 1) { NumberOfSteps -= (Counter/InternalWinderCfg.spoolbackingrate); REPORT_MSG(ScrewNumberOfSteps, "Head Backing ScrewNumberOfSteps"); ScrewNumberOfSteps--; 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 = CurrentControlledSpeed[WINDER_MOTOR] / MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_WINDER].pulseperround; + 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; @@ -194,7 +194,7 @@ uint32_t CalculateNumberOfSteps (uint32_t Counter, bool direction) CurrentControlledSpeed[SCREW_MOTOR] = ScrewSpeed; } - if ((Counter%InternalWinderCfg.SpoolBottomBackingRate == 0)||(Counter%InternalWinderCfg.SpoolBottomBackingRate == 0)) + if ((Counter%InternalWinderCfg.SpoolBottomBackingRate == 0)||(Counter%InternalWinderCfg.SpoolBottomBackingRate == 1)) { if (direction != MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize) { -- cgit v1.3.1 From 53b5ef734132b543838e1663fe96d70457d8a62b Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Sun, 18 Nov 2018 08:16:57 +0200 Subject: my pc changes. HardwareBlower with a heating voltage --- .../Embedded/Common/report/distributor.c | 2 +- .../Embedded/Communication/CommunicationTask.c | 2 +- .../Embedded_SW/Embedded/Drivers/Motors/Motor.c | 2 ++ .../Embedded_SW/Embedded/Drivers/Valves/Valve.c | 3 +- Software/Embedded_SW/Embedded/Main.c | 9 +++--- .../Embedded_SW/Embedded/Modules/Control/control.c | 6 ++-- .../Embedded/Modules/Diagnostics/Diagnostics.c | 23 +++++++++------- .../Embedded/Modules/Heaters/Heaters_print.c | 8 +++++- .../Embedded_SW/Embedded/Modules/IDS/IDS_print.c | 32 +--------------------- .../Embedded/Modules/Thread/Thread_Winder.new | 10 +++---- .../Embedded/Modules/Thread/Thread_print.c | 7 +++++ .../Embedded/StateMachines/Printing/JobSTM.c | 6 +++- .../Embedded/StateMachines/Printing/PrintingSTM.c | 3 +- .../PMR/Messages/Hardware/HardwareBlower.proto | 2 ++ 14 files changed, 56 insertions(+), 59 deletions(-) (limited to 'Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.new') diff --git a/Software/Embedded_SW/Embedded/Common/report/distributor.c b/Software/Embedded_SW/Embedded/Common/report/distributor.c index cbc754a7e..0bd4574e0 100644 --- a/Software/Embedded_SW/Embedded/Common/report/distributor.c +++ b/Software/Embedded_SW/Embedded/Common/report/distributor.c @@ -240,7 +240,7 @@ Void reportService(UArg arg0, UArg arg1) int DistTableEntry;//,msgLen, errCode, par1, par2; ReportInitParams InitParams; - InitParams.DistributorQueueMaxMsgs = 15; + InitParams.DistributorQueueMaxMsgs = 40; InitParams.DistributorTaskPriority = 6; InitParams.MaxNumOfFilterNames = 1; InitParams.MaxNumberOfPrivateDistributors = 2; diff --git a/Software/Embedded_SW/Embedded/Communication/CommunicationTask.c b/Software/Embedded_SW/Embedded/Communication/CommunicationTask.c index b27ab687d..1fffc3c21 100644 --- a/Software/Embedded_SW/Embedded/Communication/CommunicationTask.c +++ b/Software/Embedded_SW/Embedded/Communication/CommunicationTask.c @@ -15,7 +15,7 @@ static void (*callback)(char* buffer, size_t length); Mailbox_Handle CommunicationRxMsgQ = NULL; Mailbox_Handle CommunicationTxMsgQ = NULL; -#define COMMUNICATION_NUM_MSGS 20 +#define COMMUNICATION_NUM_MSGS 50 typedef struct CommRxMessage{ //uint16_t messageId; uint16_t msgSize; diff --git a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.c b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.c index 8374133a7..780e2ede3 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.c +++ b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.c @@ -488,6 +488,8 @@ uint32_t MotorMovetoLimitSwitch (TimerMotors_t _motorId,bool direction, uint32_t MotorSetDirection( _motorId, direction); MotorSetSpeed(_motorId, Freq); MotorMovetoLimitSwitchControlId[_motorId] = AddControlCallback( MotorMoveToLimitSwitchCallBackFunction, eOneMillisecond , FPGA_Read_limit_Switches,(IfTypeMotors*0x100+_motorId), LimitSwitchId, 0 ); + if ( MotorMovetoLimitSwitchControlId[_motorId] == 0xFF) + return ERROR; MotorMovetoLimitSwitchCallback[_motorId] = callback; return OK; diff --git a/Software/Embedded_SW/Embedded/Drivers/Valves/Valve.c b/Software/Embedded_SW/Embedded/Drivers/Valves/Valve.c index c2dca51cd..09c4ccb0c 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Valves/Valve.c +++ b/Software/Embedded_SW/Embedded/Drivers/Valves/Valve.c @@ -361,7 +361,8 @@ uint32_t Control3WayValvesWithCallback (Valves_t _ValveId, bool direction, callb Valve_Set(_ValveId, direction); Valve3WayControlId[_ValveId] = AddControlCallback( Valve3WayCallBackFunction, eTenMillisecond, FPGA_GetDispenserValveBusyOCD,(IfTypeDisopenser*0x100+_ValveId), _ValveId, 0 ); - + if (Valve3WayControlId[_ValveId] == 0xFF) + LOG_ERROR(_ValveId, "Add control callback failed"); return Valve3WayControlId[_ValveId]; } diff --git a/Software/Embedded_SW/Embedded/Main.c b/Software/Embedded_SW/Embedded/Main.c index 2f337b12c..2a8fc78a6 100644 --- a/Software/Embedded_SW/Embedded/Main.c +++ b/Software/Embedded_SW/Embedded/Main.c @@ -166,6 +166,10 @@ int main(void) SysCtlUSBPLLEnable(); +#ifndef EVALUATION_BOARD + DeActivateAllSSR(); +#endif + #ifdef WATCHDOG InitWatchdog(ui32SysClock); #endif @@ -202,12 +206,9 @@ int main(void) SysCtlDelay(1000); Erase_Block(0);*/ //----------------------------------------------------------- -#ifndef EVALUATION_BOARD +#ifndef EVALUATION_BOARD //Turn_the_Blower_On();//Turn on with the Default_Voltage - - DeActivateAllSSR(); - ActivateChiller();//SSR12 #endif //EMAC_initEMAC(); diff --git a/Software/Embedded_SW/Embedded/Modules/Control/control.c b/Software/Embedded_SW/Embedded/Modules/Control/control.c index 78cdd5324..1e9237320 100644 --- a/Software/Embedded_SW/Embedded/Modules/Control/control.c +++ b/Software/Embedded_SW/Embedded/Modules/Control/control.c @@ -202,7 +202,7 @@ uint32_t AddControlCallback( ControlCBFunction Callback, CTRL_TIMING_ENUM CtrlF unsigned int key; uint32_t device_i; - uint32_t deviceId = 0xFFFFFFFF; + uint32_t deviceId = 0xFF; for(device_i = 0;device_i < MAX_TANGO_CONTROL_DEVICES;device_i++) { if (ControlArray[device_i].ControlActive == false) @@ -211,8 +211,8 @@ uint32_t AddControlCallback( ControlCBFunction Callback, CTRL_TIMING_ENUM CtrlF break; } } - if (deviceId == 0xFFFFFFFF) - return 0xFFFFFFFF; + if (deviceId == 0xFF) + return 0xFF; key = GateMutex_enter(gateControlDB); ControlArray[deviceId].ControlTiming = CtrlFrequency; ControlArray[deviceId].ControlCallbackPtr = Callback; diff --git a/Software/Embedded_SW/Embedded/Modules/Diagnostics/Diagnostics.c b/Software/Embedded_SW/Embedded/Modules/Diagnostics/Diagnostics.c index 01e683dae..89793cfcd 100644 --- a/Software/Embedded_SW/Embedded/Modules/Diagnostics/Diagnostics.c +++ b/Software/Embedded_SW/Embedded/Modules/Diagnostics/Diagnostics.c @@ -249,9 +249,10 @@ void DiagnosticLoadTemperature(int HeaterId, int temperature) void DiagnosticLoadSpeedSensor(float value) { SpeedValue[SpeedCounterIndex] = (double)(value); - SpeedCounterIndex++; - if (SpeedCounterIndex>=DIAGNOSTICS_DANCER_LIMIT ) - SpeedCounterIndex = 0; + if (SpeedCounterIndex=DIAGNOSTICS_DANCER_LIMIT ) + // SpeedCounterIndex = 0; } void DiagnosticLoadDancer(int DancerId, uint16_t value) @@ -262,9 +263,10 @@ void DiagnosticLoadDancer(int DancerId, uint16_t value) return; } DancerValue[DancerId][DancerCounterIndex[DancerId]] = value; - DancerCounterIndex[DancerId]++; - if (DancerCounterIndex[DancerId]>=DIAGNOSTICS_DANCER_LIMIT ) - DancerCounterIndex[DancerId] = 0; + if (DancerCounterIndex[DancerId]=DIAGNOSTICS_DANCER_LIMIT ) + // DancerCounterIndex[DancerId] = 0; } void DiagnosticLoadDancerError(int DancerId, double value) { @@ -274,9 +276,10 @@ void DiagnosticLoadDancerError(int DancerId, double value) return; } DancerErrorValue[DancerId][DancerErrorCounterIndex[DancerId]] = value; - DancerErrorCounterIndex[DancerId]++; - if (DancerErrorCounterIndex[DancerId]>=DIAGNOSTICS_DANCER_LIMIT ) - DancerErrorCounterIndex[DancerId] = 0; + if (DancerErrorCounterIndex[DancerId]=DIAGNOSTICS_DANCER_LIMIT ) + // DancerErrorCounterIndex[DancerId] = 0; } void DiagnosticTenMsecCollection(void) @@ -589,7 +592,7 @@ void SendDiagnostics(void) } else { - Report("Diagnostic Messgage",__FILE__,__LINE__,container_size,RpWarning,msec_millisecondCounter, msec_millisecondCounter); + Report("Diagnostic Message",__FILE__,__LINE__,container_size,RpWarning,msec_millisecondCounter, msec_millisecondCounter); } diag_size[diag_index] = container_size; diag_time[diag_index] = msec_millisecondCounter; diff --git a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c index 6222378bb..0e4466d81 100644 --- a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c +++ b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c @@ -358,7 +358,13 @@ uint32_t PrepareHeater(int HeaterId, uint32_t SetTemperatue) #endif InitialHeating = true; HeaterReady[HeaterId] = false; - Turn_the_Blower_Off(); + if (BlowerCfg.enabled == true) + { + Turn_the_Blower_On();//Turn on with the Default_Voltage + if (BlowerCfg.voltage) + Control_Voltage_To_Blower(BlowerCfg.voltage-500); + + } } /* if (HeaterId == HARDWARE_PID_CONTROL_TYPE__DryerHeaterMain) //Dryer Heaters { diff --git a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_print.c b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_print.c index 64855daed..36c9dbf60 100644 --- a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_print.c +++ b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_print.c @@ -150,36 +150,6 @@ void DispenserPrepareReady(void) } DispenserPrepareReady(); return OK; -} -bool IDS_isDispenserUsedNextSegment(void *JobDetails,int DispenserId, int SegmentId) -{ - JobTicket* JobTicket = JobDetails; - int Dispenser_i,n_dispensers; - if (JobTicket->n_segments == 0) - return false; - if (JobTicket->n_segments <= SegmentId) - return false; - if (JobTicket->segments[SegmentId]->brushstops[0]->n_dispensers) - { - n_dispensers = JobTicket->segments[SegmentId]->brushstops[0]->n_dispensers; - for (Dispenser_i = 0;Dispenser_i < n_dispensers;Dispenser_i++) - { - if (DispenserId == JobTicket->segments[SegmentId]->brushstops[0]->dispensers[Dispenser_i]->index) //dispenser is in use next segment - { - if (JobTicket->segments[SegmentId]->brushstops[0]->dispensers[Dispenser_i]->nanolitterpersecond>0) - { - return true; - } - else - { - return false; - } - } - } - } - - return false; - } //******************************************************************************************************************** uint32_t IDS_Valve_PresegmentReady(uint32_t deviceID, uint32_t ReadValue) @@ -240,7 +210,7 @@ uint32_t IDSPreSegmentState(void *JobDetails, int SegmentId) continue; DispenserPreSegmentReady[DispenserId] = false; LOG_ERROR(DispenserId,"Dispenser PreSegment Start"); - if (IDS_isDispenserUsedNextSegment(JobDetails,DispenserId,SegmentId) == false) + if (JobTicket->segments[SegmentId]->brushstops[0]->dispensers[Dispenser_i]->nanolitterpersecond==0) { Control3WayValvesWithCallback ((Valves_t)DispenserId, MidTank_Dispenser, IDS_Valve_PresegmentReady); //direction: MidTank_Dispenser or Dispenser_Mixer LOG_ERROR(DispenserId,"Dispenser Not Used Next Segment"); diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.new b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.new index 537d27775..e21114603 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.new +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.new @@ -177,7 +177,7 @@ uint32_t CalculateNumberOfSteps (uint32_t Counter, bool direction) float screw_horizontal_speed = 0; float RotationsPerSecond; - if (Counter%InternalWinderCfg.spoolbackingrate == 1) + if (Counter%InternalWinderCfg.spoolbackingrate == 0) { NumberOfSteps -= (Counter/InternalWinderCfg.spoolbackingrate); REPORT_MSG(ScrewNumberOfSteps, "Head Backing ScrewNumberOfSteps"); @@ -189,14 +189,14 @@ uint32_t CalculateNumberOfSteps (uint32_t Counter, bool direction) ScrewSpeed = screw_horizontal_speed*RotationsPerSecond; //MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewSpeed); - REPORT_MSG(ScrewSpeed, "CalculateNumberOfSteps ScrewSpeed"); - REPORT_MSG(CurrentControlledSpeed[WINDER_MOTOR], "CalculateNumberOfSteps Winder speed"); + //REPORT_MSG(ScrewSpeed, "CalculateNumberOfSteps ScrewSpeed"); + //REPORT_MSG(CurrentControlledSpeed[WINDER_MOTOR], "CalculateNumberOfSteps Winder speed"); CurrentControlledSpeed[SCREW_MOTOR] = ScrewSpeed; } if ((Counter%InternalWinderCfg.SpoolBottomBackingRate == 0)||(Counter%InternalWinderCfg.SpoolBottomBackingRate == 1)) { - if (direction != MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize) + if (direction == MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize)//because the direction is already reversed at the interrupt { NumberOfSteps += (Counter/InternalWinderCfg.SpoolBottomBackingRate); ScrewNumberOfSteps++; @@ -391,7 +391,7 @@ void ScrewTimerInterrupt(int ARG0) { TimerDisable(Screw_timerBase, TIMER_A); } - Report("ScrewTimerInterrupt duration, speed", __FILE__,__LINE__,ScrewRunningTime, RpMessage, ScrewSpeed, 0); + //Report("ScrewTimerInterrupt duration, speed", __FILE__,__LINE__,ScrewRunningTime, RpMessage, ScrewSpeed, 0); // // Enable all interrupts. // diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c index 3b17cd5dd..40fd14fde 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c @@ -706,16 +706,20 @@ uint32_t ThreadPreSegmentState(void *JobDetails) return OK; } +int REPSegmentId = 0; void ThreadInterSegmentEnded(void) { + LOG_ERROR (REPSegmentId," ThreadSegmentState"); PreSegmentReady(Module_Thread,ModuleDone); } void ThreadSegmentEnded(void) { + LOG_ERROR (REPSegmentId," ThreadSegmentState"); SegmentReady(Module_Thread,ModuleDone); } void ThreadDistanceToSpoolEnded(void) { + LOG_ERROR (REPSegmentId," ThreadSegmentState"); DistanceToSpoolReady(Module_Thread,ModuleDone); } double seglength = 0.0; @@ -723,8 +727,10 @@ double seglength = 0.0; uint32_t ThreadSegmentState(void *JobDetails, int SegmentId) { JobTicket* JobTicket = JobDetails; + REPSegmentId = SegmentId; seglength = JobTicket->segments[SegmentId]->length; CurrentSegmentId = SegmentId; + LOG_ERROR (seglength," ThreadSegmentState"); ThreadUpdateProcessLength (seglength,(void *)ThreadSegmentEnded); return OK; } @@ -733,6 +739,7 @@ uint32_t ThreadSegmentState(void *JobDetails, int SegmentId) uint32_t ThreadDistanceToSpoolState(void ) { seglength = dryerbufferlength; + LOG_ERROR (seglength,"ThreadDistanceToSpoolState"); ThreadUpdateProcessLength (seglength,(void *)ThreadDistanceToSpoolEnded); return OK; } diff --git a/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c b/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c index 67cb7c666..d595f1fe4 100644 --- a/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c +++ b/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c @@ -202,7 +202,10 @@ static ReturnCode PrepareState(void *JobDetails) } if (Configured[Module_Winder]) { - Winder_Prepare(); + if( Winder_Prepare()!= OK) + { + SendJobProgress(0.0, 0, false, "Winder prepare failed !!!!"); + } } return retcode; @@ -488,6 +491,7 @@ void JobRequestFunc(MessageContainer* requestContainer) } if (status == PASSED) { + Report("Job Request ",__FILE__,__LINE__,Ticket->processparameters->dyeingspeed,RpWarning,Ticket->n_segments, Ticket->intersegmentlength); StartJob(CurrentJob); } } diff --git a/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.c b/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.c index 204410bcd..4463304e7 100644 --- a/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.c +++ b/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.c @@ -441,6 +441,7 @@ void StartPrinting(void) void StopPrinting(void) { } +int SegmentId = 0; void PrintSTMMsgHandler(void * msg) { JobMessageStruc *Message = msg; @@ -453,7 +454,6 @@ void PrintSTMMsgHandler(void * msg) //REPORT_ERR ... return; } - static int SegmentId = 0; switch(PrtMessage->messageId) { case PrintRequest: @@ -468,6 +468,7 @@ void PrintSTMMsgHandler(void * msg) break; case SegmentResultsOk: SegmentId++; + LOG_ERROR(SegmentId, "SegmentResultsOk segmentId"); if (SegmentId >= CurrentJob->n_segments) { if (dryerbufferlength == 0) diff --git a/Software/PMR/Messages/Hardware/HardwareBlower.proto b/Software/PMR/Messages/Hardware/HardwareBlower.proto index 22f73f585..f628fea36 100644 --- a/Software/PMR/Messages/Hardware/HardwareBlower.proto +++ b/Software/PMR/Messages/Hardware/HardwareBlower.proto @@ -24,4 +24,6 @@ message HardwareBlower double Voltage = 3; + double HeatingVoltage = 4; + } -- cgit v1.3.1 From 4f6efa33a5693da6e5c3182dce96b8e2d3e9d9aa Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Tue, 20 Nov 2018 11:44:31 +0200 Subject: temparatures not in integer numbers --- .../Embedded/Modules/Diagnostics/Diagnostics.c | 3 +- .../Embedded/Modules/Thread/Thread_Winder.new | 401 --------------------- .../Embedded/Modules/Thread/Thread_Winder.old | 366 ------------------- 3 files changed, 2 insertions(+), 768 deletions(-) delete mode 100644 Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.new delete mode 100644 Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.old (limited to 'Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.new') diff --git a/Software/Embedded_SW/Embedded/Modules/Diagnostics/Diagnostics.c b/Software/Embedded_SW/Embedded/Modules/Diagnostics/Diagnostics.c index 003a2510a..20fce7cf6 100644 --- a/Software/Embedded_SW/Embedded/Modules/Diagnostics/Diagnostics.c +++ b/Software/Embedded_SW/Embedded/Modules/Diagnostics/Diagnostics.c @@ -232,6 +232,7 @@ void DiagnosticsLoadDigitalValues(void) } void DiagnosticLoadTemperature(int HeaterId, int temperature) { + double temp = temperature; if (HeaterId >= MAX_HEATERS_NUM) { LOG_ERROR(HeaterId,"wrong Heater Id"); @@ -241,7 +242,7 @@ void DiagnosticLoadTemperature(int HeaterId, int temperature) { return; } - HeaterTemperature[HeaterId][HeaterCounterIndex[HeaterId]] = temperature/100; + HeaterTemperature[HeaterId][HeaterCounterIndex[HeaterId]] = temp/100; HeaterCounterIndex[HeaterId]++; if (HeaterCounterIndex[HeaterId]>=DIAGNOSTICS_LIMIT ) HeaterCounterIndex[HeaterId] = 0; diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.new b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.new deleted file mode 100644 index e21114603..000000000 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.new +++ /dev/null @@ -1,401 +0,0 @@ -/* - * Thread_Winder.c - * - * Created on: 25 áîøõ 2018 - * Author: shlomo - */ -#include"include.h" -#include "thread.h" - -#include "drivers/Motors/Motor.h" -#include "StateMachines/Printing/PrintingSTM.h" -#include "Modules/Control/Control.h" -#include "Modules/Control/MillisecTask.h" - -#include "modules/General/process.h" - -#include "Common/report/report.h" - -#include "drivers/FPGA/FPGA.h" - -#include "drivers/FPGA/FPGA_SPI_Comm.h" -#include "drivers/FPGA/FPGA_GPIO/FPGA_GPIO.h" - -#include -#include -#include - - -bool Winder_ScrewHoming = false; - -uint32_t Winder_ScrewAtOffsetCallback(uint32_t deviceID, uint32_t BusyFlag); -uint32_t Winder_PrepareStage2(uint32_t deviceID, uint32_t ReadValue); - -bool ScrewCurrentDirection = false; //holds current screw direction -bool BusyfirstCall = true; //Ignores first call after activating the screw - too early -double ScrewSpeed = 0; -double ScrewRunningTime = 0; -bool ScrewDirection = false; -bool SCREW_TimerActivated = false; -//ScrewSpeed -uint32_t ScrewControlId = 0xFF; -uint32_t ScrewNumberOfSteps = 0; //holds the current number of steps for the next screw run - will be used to build the cone -uint32_t DirectionChangeCounter = 0; //holds the current number of runs of the screw - will be used to build the cone - -InternalWinderConfigStruc InternalWinderCfg = {0}; -void ScrewTimerInterruptInit(void); -void ScrewsStopControlTimer (void); -void ScrewsStartControlTimer (void); - -uint32_t Winder_Init(void) -{ - ScrewTimerInterruptInit(); - return OK; -} - - -uint32_t InternalWinderConfigMessage(HardwareWinder* request) -{ - uint32_t status = PASSED; - - InternalWinderCfg.milimetersperrotation = request->millimeterperrotation; - - return status; -} -uint32_t InternalWindingConfigMessage(JobSpool* request) -{ - uint32_t status = PASSED; - - InternalWinderCfg.segmentoffsetpulses = request->segmentoffsetpulses; - InternalWinderCfg.spoolbackingrate = request->backingrate; - InternalWinderCfg.startoffsetpulses = request->startoffsetpulses; - InternalWinderCfg.SpoolBottomBackingRate = request->bottombackingrate; - InternalWinderCfg.NumberOfRotationPerPassage = request->rotationsperpassage; - InternalWinderCfg.diameter = request->diameter; - - return status; -} -/* - *uint32_t Winder_Prepare(void *JobDetails) - - * 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 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 - //MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,InternalWinderCfg.segmentoffsetpulses); - //REPORT_MSG(ScrewSpeed, "Winder_Prepare"); - /* - * 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. - * 2. move back x steps - according to thehw specifications and bobine definitions in the job. move for a predefined number of steps. get a callback when done - * report ready to the job STM - */ - if (FPGA_Read_limit_Switches(GPI_LS_SCREW_RIGHT)==LIMIT) - { - //REPORT_MSG(LIMIT, "Winder_Prepare at limit"); - Winder_PrepareStage2(0,0); - } - else - { - //REPORT_MSG(ScrewSpeed, "Winder_Prepare"); - Winder_ScrewHoming = true; - //REPORT_MSG(MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize, "Winder_Prepare move to limit"); - status = MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_SCREW,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize, ScrewSpeed, GPI_LS_SCREW_RIGHT, Winder_PrepareStage2); - } - return status; -} -/* - * uint32_t Winder_PrepareStage2(uint32_t deviceID, uint32_t ReadValue) - * 2. move back x steps - according to thehw specifications and bobine definitions in the job. move for a predefined number of steps. get a callback when done - * report ready to the job STM - */ - -uint32_t Winder_PrepareStage2(uint32_t deviceID, uint32_t ReadValue) -{ - uint32_t status=OK; - uint32_t numOfSteps = InternalWinderCfg.startoffsetpulses*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep; - - //MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,InternalWinderCfg.segmentoffsetpulses); - //REPORT_MSG(numOfSteps, "Winder_PrepareStage2"); - REPORT_MSG(MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].maxfrequency, "Winder_PrepareStage2"); - - status |= MotorMoveWithCallback(HARDWARE_MOTOR_TYPE__MOTO_SCREW, (1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize),numOfSteps, Winder_ScrewAtOffsetCallback); - //set motor location 0 here - return status; - -} - -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); - - ScrewCurrentDirection = false; - ScrewSpeed = 0; - ScrewControlId = 0xFF; - ScrewNumberOfSteps = 0; - DirectionChangeCounter = 0; - REPORT_MSG(BusyFlag, "Winder_ScrewAtOffsetCallback"); - PrepareReady(Module_Winder, ModuleDone); - return OK; -} - -/* - * this is the main operational function of the screw - run back and forth until stopped - */ -/* - InternalWinderCfg.segmentoffsetpulses = request->segmentoffsetpulses; - InternalWinderCfg.spoolbackingrate = request->backingrate; - InternalWinderCfg.startoffsetpulses = request->startoffsetpulses; - InternalWinderCfg.SpoolBottomBackingRate = request->bottombackingrate; - InternalWinderCfg.NumberOfRotationPerPassage = request->rotationsperpassage; - * -Calculate the number of steps. -Initial home position = ... -Initial out movement = ScrewNumberOfSteps -if DirectionChangeCounter %= backingrate : reduce one from the ScrewNumberOfSteps -if DirectionChangeCounter %= bottombackingrate && direction was out: ADD one to the ScrewNumberOfSteps, -// WRONG? if the flag is raised - lower it and reduce one from the ScrewNumberOfSteps -30:100 - 70 -30:99 - 69 -30:98 - 68 -29:98 - 69 -29:97 -68 -InternalWinderCfg.segmentoffsetpulses - int32_t backingrate; - int32_t bottombackingrate; - -numOfSteps = InternalWinderCfg.startoffsetpulses*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep; -*/ -uint32_t CalculateNumberOfSteps (uint32_t Counter, bool direction) -{ - uint32_t NumberOfSteps = InternalWinderCfg.segmentoffsetpulses;//*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep; - float screw_horizontal_speed = 0; - float RotationsPerSecond; - - if (Counter%InternalWinderCfg.spoolbackingrate == 0) - { - NumberOfSteps -= (Counter/InternalWinderCfg.spoolbackingrate); - REPORT_MSG(ScrewNumberOfSteps, "Head Backing ScrewNumberOfSteps"); - ScrewNumberOfSteps--; - 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 = 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; - - //MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewSpeed); - //REPORT_MSG(ScrewSpeed, "CalculateNumberOfSteps ScrewSpeed"); - //REPORT_MSG(CurrentControlledSpeed[WINDER_MOTOR], "CalculateNumberOfSteps Winder speed"); - CurrentControlledSpeed[SCREW_MOTOR] = ScrewSpeed; - - } - if ((Counter%InternalWinderCfg.SpoolBottomBackingRate == 0)||(Counter%InternalWinderCfg.SpoolBottomBackingRate == 1)) - { - if (direction == MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize)//because the direction is already reversed at the interrupt - { - NumberOfSteps += (Counter/InternalWinderCfg.SpoolBottomBackingRate); - ScrewNumberOfSteps++; - REPORT_MSG(ScrewNumberOfSteps, "Bottom Backing ScrewNumberOfSteps"); - } - - } - return NumberOfSteps; - -} -uint32_t ScrewDirectionChange(uint32_t deviceID, uint32_t BusyFlag) -{ - uint32_t Steps; - double temp; - if (BusyfirstCall) - { - BusyfirstCall = false; - DirectionChangeCounter++; - return OK; - } - //ScrewCurrentDirection: false moves out, true moves home - if (BusyFlag == NOTBUSY) - { - CalculateNumberOfSteps (DirectionChangeCounter++, ScrewCurrentDirection); - Steps = ScrewNumberOfSteps; -/* if (FPGA_Read_limit_Switches(GPI_LS_SCREW_RIGHT)==LIMIT) - { - ScrewCurrentDirection = (1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize); - Steps += InternalWinderCfg.startoffsetpulses*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep; - REPORT_MSG(LIMIT, "Winder at right limit"); - } - else if (FPGA_Read_limit_Switches(GPI_LS_SCREW_LEFT)==LIMIT) - { - ScrewCurrentDirection = (MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize); - REPORT_MSG(LIMIT, "Winder at left limit"); - } -*/ - temp = SYS_CLK_FREQ; - temp *= Steps; - temp /= ScrewSpeed; - //LOG_ERROR(Steps,"ScrewDirectionChange - ScrewNumberOfSteps"); - - if (ScrewRunningTime != temp) - { - REPORT_MSG(temp, "ScrewDirectionChange ScrewRunningTime changed"); - } - ScrewRunningTime = temp;//(SYS_CLK_FREQ*Steps)/ScrewSpeed; - //MotorMove (HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewCurrentDirection,Steps); //process: set point 0, set max speed, move to the specified length, return back. - } - return OK; - -} - -uint32_t WinderPresegmentReady(uint32_t deviceID, uint32_t ReadValue) -{ - return PreSegmentReady(Module_Winder,ModuleDone); -} - -uint32_t Winder_Presegment(void *JobDetails, uint32_t SegmentId) -{ - //JobTicket* JobTicket = JobDetails; - float screw_horizontal_speed = 0; - float RotationsPerSecond; - char Message[80]; - double temp = 0; - if (dyeingspeed == 0) - { - LOG_ERROR (dyeingspeed," job speed zero"); - 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) - { - ScrewCurrentDirection = (1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize); - - // * 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. - screw_horizontal_speed = InternalWinderCfg.segmentoffsetpulses / 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; - - //MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewSpeed); - usnprintf(Message, 80, "SCREW speed Rot/sec %d horizon %d pulses %d",(int)RotationsPerSecond,(int)screw_horizontal_speed,(int)ScrewSpeed); - //LOG_ERROR(segmentfirst_speed,Message); - //Report(Message,__FILE__,__LINE__,Dispenser_i,RpWarning,segmentfirst_speed,0); - SendJobProgress(0.0,0,false, Message); - - CurrentControlledSpeed[SCREW_MOTOR] = ScrewSpeed; - OriginalMotorSpd_2PPS[SCREW_MOTOR] = ScrewSpeed; - //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 - ScrewNumberOfSteps = InternalWinderCfg.segmentoffsetpulses;//*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep; - temp = SYS_CLK_FREQ; - temp *= InternalWinderCfg.segmentoffsetpulses; - temp /= ScrewSpeed; - ScrewRunningTime = temp;//(SYS_CLK_FREQ*InternalWinderCfg.segmentoffsetpulses)/ScrewSpeed; - LOG_ERROR(ScrewNumberOfSteps,"Winder pre segment - ScrewNumberOfSteps"); - LOG_ERROR(ScrewRunningTime,"Winder pre segment - ScrewRunningTime"); -// MotorSetDirection (HARDWARE_MOTOR_TYPE__MOTO_SCREW, ScrewCurrentDirection); - //ScrewDirection = 1-ScrewDirection; - LOG_ERROR(ScrewSpeed,"Winder pre segment - ScrewSpeed"); - //MotorSetSpeedDirect(HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewSpeed); - ScrewsStartControlTimer (); - } - PreSegmentReady(Module_Winder,ModuleDone); - - return OK; -} -uint32_t Winder_End(void) -{ - int pend; - //stop screw - ScrewNumberOfSteps = 0; - if (ScrewControlId != 0xFF) - RemoveControlCallback(ScrewControlId,ScrewDirectionChange); - CurrentControlledSpeed[SCREW_MOTOR] = 0; - ScrewsStopControlTimer(); - - return MotorStop (HARDWARE_MOTOR_TYPE__MOTO_SCREW,Hard_Hiz); -} -void Winder_ScrewHomeLimitSwitchInterrupt(void) -{ - //uint32_t status; - //handle glitch - send information to the next time that the motor stops - if (Winder_ScrewHoming) - { - MotorStop(HARDWARE_MOTOR_TYPE__MOTO_SCREW,Hard_Hiz); //stop ASAP - } - MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_SCREW,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize);//make sure to move the cart out -} -void Winder_ScrewOutLimitSwitchInterrupt(void) -{ - //handle glitch - send information to the next time that the motor stops - //uint32_t status; - MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_SCREW,1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize);//make sure to move the cart out -} - -uint32_t Screw_timerBase = TIMER3_BASE; //Timer handle - -bool Screw_Restart = false; -void ScrewTimerInterruptInit(void) -{ - ROM_TimerConfigure(Screw_timerBase, TIMER_CFG_PERIODIC); // 32 bits Timer - ROM_TimerEnable(Screw_timerBase, TIMER_A); - ROM_IntEnable(INT_TIMER3A); - ROM_TimerIntEnable(Screw_timerBase, TIMER_TIMA_TIMEOUT); - Screw_Restart = false; - -} -void ScrewsStopControlTimer (void) -{ - SCREW_TimerActivated = false; - ROM_TimerDisable(Screw_timerBase, TIMER_A); - //ROM_IntDisable(INT_TIMER3A); - //ROM_TimerIntDisable(Screw_timerBase, TIMER_TIMA_TIMEOUT); -} -void ScrewsStartControlTimer (void) -{ - if (SCREW_TimerActivated == true) - return; - SCREW_TimerActivated = true; - //ROM_TimerConfigure(Screw_timerBase, TIMER_CFG_PERIODIC); // 32 bits Timer - TimerEnable(Screw_timerBase, TIMER_A); - ROM_IntEnable(INT_TIMER3A); - ROM_TimerIntEnable(Screw_timerBase, TIMER_TIMA_TIMEOUT); - ROM_TimerLoadSet(Screw_timerBase, TIMER_A,(int)1200000/*10 millisec*/ ); - Report("ScrewsStartControlTimer direction,speed ", __FILE__,__LINE__,ScrewCurrentDirection, RpMessage, ScrewSpeed, 0); - return; -} -void ScrewTimerInterrupt(int ARG0) -{ - bool dir = ScrewCurrentDirection; - ROM_TimerIntClear(Screw_timerBase, TIMER_TIMA_TIMEOUT); // Clear the timer interrupt - ROM_IntMasterDisable(); - ScrewDirectionChange(0,NOTBUSY); - if (SCREW_TimerActivated == true) - { - MotorSetDirection (HARDWARE_MOTOR_TYPE__MOTO_SCREW, ScrewCurrentDirection); - ScrewCurrentDirection = 1-ScrewCurrentDirection; - MotorSetSpeedDirect(HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewSpeed); - ROM_TimerLoadSet(Screw_timerBase, TIMER_A,(int)ScrewRunningTime); - } - else - { - TimerDisable(Screw_timerBase, TIMER_A); - } - //Report("ScrewTimerInterrupt duration, speed", __FILE__,__LINE__,ScrewRunningTime, RpMessage, ScrewSpeed, 0); - // - // Enable all interrupts. - // - ROM_IntMasterEnable(); - return ; - -} diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.old b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.old deleted file mode 100644 index 1aaeec556..000000000 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.old +++ /dev/null @@ -1,366 +0,0 @@ -/* - * Thread_Winder.c - * - * Created on: 25 áîøõ 2018 - * Author: shlomo - */ -#include"include.h" -#include "thread.h" - -#include "drivers/Motors/Motor.h" -#include "StateMachines/Printing/PrintingSTM.h" -#include "Modules/Control/Control.h" -#include "Modules/Control/MillisecTask.h" - -#include "modules/General/process.h" - -#include "Common/report/report.h" - -#include "drivers/FPGA/FPGA.h" - -#include "drivers/FPGA/FPGA_SPI_Comm.h" -#include "drivers/FPGA/FPGA_GPIO/FPGA_GPIO.h" - -#include -#include -#include - -bool Winder_ScrewHoming = false; -//bool Winder_Active = false; - -uint32_t Winder_ScrewAtOffsetCallback(uint32_t deviceID, uint32_t BusyFlag); -uint32_t Winder_PrepareStage2(uint32_t deviceID, uint32_t ReadValue); - -bool ScrewCurrentDirection = false; //holds current screw direction -bool BusyfirstCall = true; //Ignores first call after activating the screw - too early -double ScrewSpeed = 0; //ScrewSpeed -uint32_t ScrewControlId = 0xFF; -uint32_t ScrewNumberOfSteps = 0; //holds the current number of steps for the next screw run - will be used to build the cone -uint32_t DirectionChangeCounter = 0; //holds the current number of runs of the screw - will be used to build the cone - -InternalWinderConfigStruc InternalWinderCfg = {0}; - -uint32_t Winder_Init(void) -{ - return OK; -} - - -uint32_t InternalWinderConfigMessage(HardwareWinder* request) -{ - uint32_t status = PASSED; - - InternalWinderCfg.milimetersperrotation = request->millimeterperrotation; - - return status; -} -uint32_t InternalWindingConfigMessage(JobSpool* request) -{ - uint32_t status = PASSED; - - InternalWinderCfg.segmentoffsetpulses = request->segmentoffsetpulses; - InternalWinderCfg.spoolbackingrate = request->backingrate; - InternalWinderCfg.startoffsetpulses = request->startoffsetpulses; - InternalWinderCfg.SpoolBottomBackingRate = request->bottombackingrate; - InternalWinderCfg.NumberOfRotationPerPassage = request->rotationsperpassage; - InternalWinderCfg.diameter = request->diameter; - - return status; -} -/* - *uint32_t Winder_Prepare(void *JobDetails) - - * 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 status = 0; - //JobTicket* JobTicket = JobDetails; -// Winder_Active = true; - //float process_speed = JobTicket->processparameters->dyeingspeed; - double ScrewSpeed = 1000;//(process_speed*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].pulleyradius); // we will use pulley radius of the screw for this purpose, as of now - //REPORT_MSG(ScrewSpeed, "Winder_Prepare"); - /* - * 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. - * 2. move back x steps - according to thehw specifications and bobine definitions in the job. move for a predefined number of steps. get a callback when done - * report ready to the job STM - */ - if (FPGA_Read_limit_Switches(GPI_LS_SCREW_RIGHT)==LIMIT) - { - REPORT_MSG(LIMIT, "Winder_Prepare at limit"); - Winder_PrepareStage2(0,0); - } - else - { - REPORT_MSG(ScrewSpeed, "Winder_Prepare"); - Winder_ScrewHoming = true; - //REPORT_MSG(MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize, "Winder_Prepare move to limit"); - status = MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_SCREW,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize, ScrewSpeed, GPI_LS_SCREW_RIGHT, Winder_PrepareStage2); - } - return status; -} -/* - * uint32_t Winder_PrepareStage2(uint32_t deviceID, uint32_t ReadValue) - * 2. move back x steps - according to thehw specifications and bobine definitions in the job. move for a predefined number of steps. get a callback when done - * report ready to the job STM - */ - -uint32_t Winder_PrepareStage2(uint32_t deviceID, uint32_t ReadValue) -{ - uint32_t status=OK; - uint32_t numOfSteps = InternalWinderCfg.startoffsetpulses*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep; - - MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,InternalWinderCfg.segmentoffsetpulses); - //REPORT_MSG(numOfSteps, "Winder_PrepareStage2"); - REPORT_MSG(MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].maxfrequency, "Winder_PrepareStage2"); - - status |= MotorMoveWithCallback(HARDWARE_MOTOR_TYPE__MOTO_SCREW, (1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize),numOfSteps, Winder_ScrewAtOffsetCallback); - //set motor location 0 here - return status; - -} - -uint32_t Winder_ScrewAtOffsetCallback(uint32_t deviceID, uint32_t BusyFlag) -{ - SetMotHome(HARDWARE_MOTOR_TYPE__MOTO_SCREW); //set this point as the spool home - - ScrewCurrentDirection = false; - BusyfirstCall = true; - ScrewSpeed = 0; - ScrewControlId = 0xFF; - ScrewNumberOfSteps = 0; - DirectionChangeCounter = 0; - REPORT_MSG(BusyFlag, "Winder_ScrewAtOffsetCallback"); - - PrepareReady(Module_Winder, ModuleDone); - return OK; -} - -/* - * this is the main operational function of the screw - run back and forth until stopped - */ -/* - -bool ScrewCurrentDirection = false; -bool BusyfirstCall = true; -double ScrewSpeed = 0; -uint32_t ScrewControlId = 0xFF; -uint32_t ScrewNumberOfSteps = 0; -uint32_t DirectionChangeCounter = 0; -*/ -/* - InternalWinderCfg.segmentoffsetpulses = request->segmentoffsetpulses; - InternalWinderCfg.spoolbackingrate = request->backingrate; - InternalWinderCfg.startoffsetpulses = request->startoffsetpulses; - InternalWinderCfg.SpoolBottomBackingRate = request->bottombackingrate; - InternalWinderCfg.NumberOfRotationPerPassage = request->rotationsperpassage; - * -Calculate the number of steps. -Initial home position = ... -Initial out movement = ScrewNumberOfSteps -if DirectionChangeCounter %= backingrate : reduce one from the ScrewNumberOfSteps -if DirectionChangeCounter %= bottombackingrate && direction was out: ADD one to the ScrewNumberOfSteps, -// WRONG? if the flag is raised - lower it and reduce one from the ScrewNumberOfSteps -30:100 - 70 -30:99 - 69 -30:98 - 68 -29:98 - 69 -29:97 -68 -InternalWinderCfg.segmentoffsetpulses - int32_t backingrate; - int32_t bottombackingrate; - -numOfSteps = InternalWinderCfg.startoffsetpulses*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep; -*/ -uint32_t CalculateNumberOfSteps (uint32_t Counter, bool direction) -{ - uint32_t NumberOfSteps = InternalWinderCfg.segmentoffsetpulses*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep; - float screw_horizontal_speed = 0; - float RotationsPerSecond; - - if (Counter) - { - if (Counter%InternalWinderCfg.spoolbackingrate == 1) - { - NumberOfSteps -= (Counter/InternalWinderCfg.spoolbackingrate); - REPORT_MSG(ScrewNumberOfSteps, "Head Backing"); - ScrewNumberOfSteps--; - /* - screw_horizontal_speed = InternalWinderCfg.segmentoffsetpulses / 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 / (InternalWinderCfg.diameter * PI); - RotationsPerSecond = CurrentControlledSpeed[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; - - MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewSpeed); - REPORT_MSG(ScrewSpeed, "CalculateNumberOfSteps"); - CurrentControlledSpeed[SCREW_MOTOR] = ScrewSpeed; - */ - } - if ((Counter%InternalWinderCfg.SpoolBottomBackingRate == 0)||(Counter%InternalWinderCfg.SpoolBottomBackingRate == 1)) - { - if (direction != MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize) - { - NumberOfSteps += (Counter/InternalWinderCfg.SpoolBottomBackingRate); - ScrewNumberOfSteps++; - REPORT_MSG(ScrewNumberOfSteps, "Bottom Backing"); - } - - } - } - return NumberOfSteps; - -} -uint32_t wtick=0,prevwtick = 0; -uint32_t wgap[100]; -uint32_t wgap_counter=0; -uint32_t ScrewDirectionChange(uint32_t deviceID, uint32_t BusyFlag) -{ - uint32_t Steps; - if (BusyfirstCall) - { - BusyfirstCall = false; - return OK; - } -// if (Winder_Active == false) -// return OK; - wtick++; - //ScrewCurrentDirection: false moves out, true moves home - if (BusyFlag == NOTBUSY) - { - if (wtick-prevwtick>10) - { - wgap[wgap_counter++] = wtick-prevwtick; - prevwtick = wtick; - if (wgap_counter >=99) - wgap_counter = 0; - } - else - return OK; - CalculateNumberOfSteps (DirectionChangeCounter++, ScrewCurrentDirection); - Steps = ScrewNumberOfSteps; - if (ScrewCurrentDirection == false) - { - ScrewCurrentDirection = true; - } - else - { - ScrewCurrentDirection = false; - } -/* if (FPGA_Read_limit_Switches(GPI_LS_SCREW_RIGHT)==LIMIT) - { - ScrewCurrentDirection = (1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize); - Steps += InternalWinderCfg.startoffsetpulses*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep; - REPORT_MSG(LIMIT, "Winder at right limit"); - } - else if (FPGA_Read_limit_Switches(GPI_LS_SCREW_LEFT)==LIMIT) - { - ScrewCurrentDirection = (MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize); - REPORT_MSG(LIMIT, "Winder at left limit"); - } -*/ - MotorMove (HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewCurrentDirection,Steps); //process: set point 0, set max speed, move to the specified length, return back. - REPORT_MSG(ScrewCurrentDirection, "ScrewDirectionChange"); - } - return OK; - -} - -uint32_t WinderPresegmentReady(uint32_t deviceID, uint32_t ReadValue) -{ - return PreSegmentReady(Module_Winder,ModuleDone); -} - -uint32_t Winder_Presegment(void *JobDetails, uint32_t SegmentId) -{ - //JobTicket* JobTicket = JobDetails; - float screw_horizontal_speed = 0; - float RotationsPerSecond; - char Message[80]; - - if (dyeingspeed == 0) - { - LOG_ERROR (dyeingspeed," job speed zero"); - 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) - { - ScrewCurrentDirection = (1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize); - - // * 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. - screw_horizontal_speed = InternalWinderCfg.segmentoffsetpulses / 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 / (InternalWinderCfg.diameter * PI); - RotationsPerSecond = CurrentControlledSpeed[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; - - MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewSpeed); - usnprintf(Message, 80, "SCREW speed Rot/sec %d horizon %d pulses %d",(int)RotationsPerSecond,(int)screw_horizontal_speed,(int)ScrewSpeed); - //LOG_ERROR(segmentfirst_speed,Message); - //Report(Message,__FILE__,__LINE__,Dispenser_i,RpWarning,segmentfirst_speed,0); - SendJobProgress(0.0,0,false, Message); - - CurrentControlledSpeed[SCREW_MOTOR] = ScrewSpeed; - //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 - ScrewNumberOfSteps = InternalWinderCfg.segmentoffsetpulses*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep; - MotorMove (HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewCurrentDirection,ScrewNumberOfSteps); //process: set point 0, set max speed, move to the specified length, return back. - wtick = 0;prevwtick = 0; - ScrewControlId = AddControlCallback(ScrewDirectionChange, eOneMillisecond,MotorControlGetnBusyState,(IfTypeMotors*0x100+HARDWARE_MOTOR_TYPE__MOTO_SCREW), HARDWARE_MOTOR_TYPE__MOTO_SCREW, 0); - - // MotorSetSpeedWithCallback (HARDWARE_MOTOR_TYPE__MOTO_SCREW, screw_horizontal_speed,WinderPresegmentReady); - //in a callback: calculate backing rate for top and bottom, update point 0, update passing length, call the appropriate move to 0 / move; - - } - PreSegmentReady(Module_Winder,ModuleDone); - - return OK; -} -uint32_t Winder_End(void) -{ - int pend; - //stop screw - ScrewNumberOfSteps = 0; -// Winder_Active = false; - if (ScrewControlId != 0xFF) - RemoveControlCallback(ScrewControlId,ScrewDirectionChange); - CurrentControlledSpeed[SCREW_MOTOR] = 0; - pend = MillisecFlushMsgQ(HARDWARE_MOTOR_TYPE__MOTO_SCREW); - return MotorStop (HARDWARE_MOTOR_TYPE__MOTO_SCREW,Hard_Hiz); -} -void Winder_ScrewHomeLimitSwitchInterrupt(void) -{ - //uint32_t status; - //handle glitch - send information to the next time that the motor stops - if (Winder_ScrewHoming) - { - MotorStop(HARDWARE_MOTOR_TYPE__MOTO_SCREW,Hard_Hiz); //stop ASAP - } - MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_SCREW,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize);//make sure to move the cart out -} -void Winder_ScrewOutLimitSwitchInterrupt(void) -{ - //handle glitch - send information to the next time that the motor stops - //uint32_t status; - MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_SCREW,1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize);//make sure to move the cart out -} -uint32_t Screw_timerBase = TIMER3_BASE; //Timer handle - -void ScrewTimerInterrupt(int ARG0) -{ - ROM_TimerIntClear(Screw_timerBase, TIMER_TIMA_TIMEOUT); // Clear the timer interrupt - return ; - -} - - -- cgit v1.3.1