diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2018-06-14 17:48:34 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2018-06-14 17:48:34 +0300 |
| commit | 87973c0cc97ba449e2b17c92ff6eb68e2a28a871 (patch) | |
| tree | 6c92affb59f3b784518f8f683ed332855a3ecddf /Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c | |
| parent | 580cb401e8b31501cb3fbee1b9f59a67ad636633 (diff) | |
| download | Tango-87973c0cc97ba449e2b17c92ff6eb68e2a28a871.tar.gz Tango-87973c0cc97ba449e2b17c92ff6eb68e2a28a871.zip | |
thread winder improvements
Diffstat (limited to 'Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c')
| -rw-r--r-- | Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c | 173 |
1 files changed, 82 insertions, 91 deletions
diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c index 37f60e8cf..f80f26e53 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c @@ -20,65 +20,30 @@ 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; -double ScrewSpeed = 0; +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 uint32_t Winder_Init(void) { return OK; } -uint32_t Winder_Test2(uint32_t deviceID, uint32_t ReadValue); -uint32_t Winder_Test1(uint32_t deviceID, uint32_t ReadValue) -{ - uint32_t status; - uint32_t numOfSteps = InternalWinderCfg.segmentoffsetpulses; - uint32_t position; - /* - * 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 - */ - MotorGetPositionFromFPGA(HARDWARE_MOTOR_TYPE__MOTO_SCREW); - //deley TODO - SysCtlDelay(100000); - position = Fpga_Spi[HARDWARE_MOTOR_TYPE__MOTO_SCREW].RX_MISO;//MotorGetPositionFromFPGA_Res(Motor_Id); - - status = MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_SCREW,1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize, ScrewSpeed/10, GPI_LS_SCREW_LEFT, Winder_Test2); -// status |= MotorMove (HARDWARE_MOTOR_TYPE__MOTO_SCREW, numOfSteps, Winder_ScrewAtOffsetCallback); - //set motor location 0 here - return status; - -} -uint32_t Winder_Test2(uint32_t deviceID, uint32_t ReadValue) -{ - uint32_t status; - uint32_t numOfSteps = InternalWinderCfg.segmentoffsetpulses; - uint32_t position; - /* - * 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 - */ - MotorGetPositionFromFPGA(HARDWARE_MOTOR_TYPE__MOTO_SCREW); - //deley TODO - SysCtlDelay(100000); - position = Fpga_Spi[HARDWARE_MOTOR_TYPE__MOTO_SCREW].RX_MISO;//MotorGetPositionFromFPGA_Res(Motor_Id); - - status = MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_SCREW,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize, ScrewSpeed/10, GPI_LS_SCREW_RIGHT, Winder_Test1); - //status |= MotorMoveSteps (HARDWARE_MOTOR_TYPE__MOTO_SCREW, numOfSteps, Winder_ScrewAtOffsetCallback); - //set motor location 0 here - return status; +/* + *uint32_t Winder_Prepare(void *JobDetails) -} -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; + //JobTicket* JobTicket = JobDetails; - float process_speed = JobTicket->processparameters->dyeingspeed; -// double ScrewSpeed = (50 * MotorsCfg[SCREW_MOTOR].pulseperround * MotorsCfg[SCREW_MOTOR].microstep)/(2*PI* MotorsCfg[SCREW_MOTOR].pulleyradius); - double ScrewSpeed = (process_speed*20 );//* MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].pulseperround)/(2*PI* MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].pulleyradius); + //float process_speed = JobTicket->processparameters->dyeingspeed; + double ScrewSpeed = 500;//(process_speed*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].pulleyradius); // we will use pulley radius of the screw for this purpose, as of now /* * 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. @@ -87,41 +52,67 @@ uint32_t Winder_Prepare(void *JobDetails) */ if (FPGA_Read_limit_Switches(GPI_LS_SCREW_RIGHT)==LIMIT) { - //go to prepare stage 2 Winder_PrepareStage2(0,0); } else { Winder_ScrewHoming = true; - status = MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_SCREW,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize, ScrewSpeed, GPI_LS_SCREW_LEFT, Winder_PrepareStage2); -// status = MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_SCREW,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize, ScrewSpeed/10, GPI_LS_SCREW_RIGHT, Winder_Test1); + 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; - /* - * 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 - */ - //status = MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_SCREW,(1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize));//make sur to move the cart out - //status |= StopMotor(HARDWARE_MOTOR_TYPE__MOTO_SCREW,0); - status |= MotorMoveWithCallback(HARDWARE_MOTOR_TYPE__MOTO_SCREW, (1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize),numOfSteps, Winder_ScrewAtOffsetCallback); - //status |= MotorMoveSteps (HARDWARE_MOTOR_TYPE__MOTO_SCREW, numOfSteps, Winder_ScrewAtOffsetCallback); - //set motor location 0 here + + 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 WinderPresegmentReady(uint32_t deviceID, uint32_t ReadValue) +uint32_t Winder_ScrewAtOffsetCallback(uint32_t deviceID, uint32_t BusyFlag) { - return PreSegmentReady(Module_Winder,ModuleDone); + 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; + + 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; +*/ + uint32_t ScrewDirectionChange(uint32_t deviceID, uint32_t BusyFlag) { + if (BusyfirstCall) + { + BusyfirstCall = false; + return; + } //ScrewCurrentDirection: false moves out, true moves home if (BusyFlag == NOTBUSY) { @@ -133,11 +124,25 @@ uint32_t ScrewDirectionChange(uint32_t deviceID, uint32_t BusyFlag) { ScrewCurrentDirection = false; } - MotorMove (HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewCurrentDirection,InternalWinderCfg.segmentoffsetpulses*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep); //process: set point 0, set max speed, move to the specified length, return back. + MotorMove (HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewCurrentDirection,ScrewNumberOfSteps); //process: set point 0, set max speed, move to the specified length, return back. + DirectionChangeCounter++; } +/* + * calculate new ScrewSpeed and call MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewSpeed); + * + */ + /* + * calculate cone shape according to DirectionChangeCounter and update ScrewNumberOfSteps + */ return OK; } + +uint32_t WinderPresegmentReady(uint32_t deviceID, uint32_t ReadValue) +{ + return PreSegmentReady(Module_Winder,ModuleDone); +} + uint32_t Winder_Presegment(void *JobDetails) { JobTicket* JobTicket = JobDetails; @@ -146,35 +151,26 @@ uint32_t Winder_Presegment(void *JobDetails) float RotationsPerSecond; ScrewCurrentDirection = (1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize); -// double ScrewSpeed = (process_speed * MotorsCfg[SCREW_MOTOR].pulseperround * MotorsCfg[SCREW_MOTOR].microstep)/(2*PI* MotorsCfg[SCREW_MOTOR].pulleyradius); - //double ScrewSpeed = (process_speed * MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].pulseperround)/(2*PI* MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].pulleyradius); -/*typedef struct -{ - uint32_t startoffsetpulses; - uint32_t spoolbackingrate; - uint32_t segmentoffsetpulses; - uint32_t milimetersperrotation; - int32 SpoolBottomBackingRate;// the angle of the bottom of the spool - double NumberOfRotationPerPassage; // how many rotations per spool passage -}InternalWinderConfigStruc; - * */ -// * 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. + // * 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_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 = process_speed / (InternalWinderCfg.diameter * 3.1416); + RotationsPerSecond = process_speed / (InternalWinderCfg.diameter * PI); // calculation input#3: speed = rotation per second * traverse per rotation = traverse per second. speed set: traverse per second (mm) * pulses per mm. - screw_speed = screw_speed*RotationsPerSecond; + ScrewSpeed = screw_speed*RotationsPerSecond; + + MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewSpeed); //screw_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 - MotorMove (HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewCurrentDirection,InternalWinderCfg.segmentoffsetpulses*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep); //process: set point 0, set max speed, move to the specified length, return back. - ScrewControlId = AddControlCallback(ScrewDirectionChange, eTenMilliSecond,MotorControlGetnBusyState,(IfTypeMotors*0x100+HARDWARE_MOTOR_TYPE__MOTO_SCREW), HARDWARE_MOTOR_TYPE__MOTO_SCREW, 0); + 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. + 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_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; @@ -185,6 +181,7 @@ uint32_t Winder_Presegment(void *JobDetails) uint32_t Winder_End(void) { //stop screw + ScrewNumberOfSteps = 0; RemoveControlCallback(ScrewControlId,ScrewDirectionChange); return StopMotor (HARDWARE_MOTOR_TYPE__MOTO_SCREW,Hard_Hiz); } @@ -202,10 +199,4 @@ void Winder_ScrewOutLimitSwitchInterrupt(void) uint32_t status; status = MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_SCREW,1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize);//make sure to move the cart out } -uint32_t Winder_ScrewAtOffsetCallback(uint32_t deviceID, uint32_t BusyFlag) -{ - SetMotHome(HARDWARE_MOTOR_TYPE__MOTO_SCREW); //set this point as the spool home - PrepareReady(Module_Winder, ModuleDone); - return OK; -} |
