diff options
| author | Avi Levkovich <avi@twine-s.com> | 2018-04-09 14:25:30 +0300 |
|---|---|---|
| committer | Avi Levkovich <avi@twine-s.com> | 2018-04-09 14:25:30 +0300 |
| commit | e8e2f174cc7dc1e6c183e855834982d12e92833c (patch) | |
| tree | ea8c5358d7e6928c513814c8619339f0c6790840 /Software/Embedded_SW/Embedded/Modules/Thread | |
| parent | f19e2e305d8baeafc30dde4fc0aa3fa37038869c (diff) | |
| parent | c1ed75027f069e204e52e48bfb610d2d225bbd72 (diff) | |
| download | Tango-e8e2f174cc7dc1e6c183e855834982d12e92833c.tar.gz Tango-e8e2f174cc7dc1e6c183e855834982d12e92833c.zip | |
mERGE
Diffstat (limited to 'Software/Embedded_SW/Embedded/Modules/Thread')
5 files changed, 153 insertions, 71 deletions
diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread.h b/Software/Embedded_SW/Embedded/Modules/Thread/Thread.h index f568f9816..913b38df8 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread.h +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread.h @@ -33,8 +33,11 @@ typedef struct { uint32_t startoffsetpulses; uint32_t spoolbackingrate; - uint32_t segmentoffsetpulses; + uint32_t segmentoffsetpulses;// the spool winding initial length in mm uint32_t milimetersperrotation; + uint32_t SpoolBottomBackingRate;// the angle of the bottom of the spool + double NumberOfRotationPerPassage; // how many rotations per spool passage + double diameter; }InternalWinderConfigStruc; typedef struct @@ -55,7 +58,7 @@ typedef enum threadMotorsEnum SCREW_MOTOR, MAX_THREAD_MOTORS_NUM }threadMotorsEnum; - +#define MAX_THREAD_FEED_MOTORS WINDER_MOTOR+1 extern uint32_t ThreadMotorIdToMotorId[MAX_THREAD_MOTORS_NUM]; @@ -66,9 +69,12 @@ extern InternalWinderConfigStruc InternalWinderCfg; uint32_t InternalWinderConfigMessage(HardwareWinder* request); uint32_t MotorsConfigMessage(HardwareMotor * request); uint32_t InternalWindingConfigMessage(JobSpool* request); +uint32_t ThreadInitialTestStub(HardwareMotor * request); uint32_t DancerConfigMessage(HardwareDancer * request); +uint32_t ThreadPrepareState(void *JobDetails); + #endif //MODULES_THREAD_THREAD_H_ diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c index 05fb0a934..eacdd2ed9 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c @@ -15,11 +15,11 @@ uint32_t Winder_PrepareStage2(void); uint32_t Winder_Init(void) { - + return OK; } uint32_t Winder_Prepare(void) { - uint32_t status; + uint32_t status = 0; /* * 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 @@ -34,9 +34,9 @@ uint32_t Winder_Prepare(void) { Winder_ScrewHoming = true; status = MotorSetDirection(MOTOR_SCREW,1);//make sur to move the cart home - status = MotorSetSpeed(MOTOR_SCREW, MotorsCfg[SCREW_MOTOR].maxfreq, 8); - + status |= MotorSetSpeed(MOTOR_SCREW, MotorsCfg[SCREW_MOTOR].maxfreq, 8); } + return status; } uint32_t Winder_PrepareStage2(void) { @@ -48,22 +48,59 @@ uint32_t Winder_PrepareStage2(void) * report ready to the job STM */ status = MotorSetDirection(MOTOR_SCREW,0);//make sur to move the cart out - status |= MotorMoveSteps (MOTOR_SCREW, numOfSteps, Winder_ScrewAtOffsetCallback); - status |= MotorSetSpeed(MOTOR_SCREW, MotorsCfg[SCREW_MOTOR].maxfreq, 8); - + //status |= MotorMoveSteps (MOTOR_SCREW, numOfSteps, Winder_ScrewAtOffsetCallback); + //set motor location 0 here return status; } -uint32_t Winder_Print(void) + +uint32_t WinderPresegmentReady(uint32_t deviceID, uint32_t ReadValue) { - /* - * speed is set by the winding parameters and by winder rotational speed (read POSITION every 10msec) - * calculate - */ + return PreSegmentReady(Module_Winder,OK); +} +uint32_t Winder_Presegment(void *JobDetails) +{ + JobTicket* JobTicket = JobDetails; + int process_speed = JobTicket->processparameters->dyeingspeed; + int dryer_speed = process_speed * MotorsCfg[DRYER_MOTOR].ratio2dryerspeed; //set dryer_speed_translation_here + float screw_speed = 0; + float RotationsPerSecond; + +/*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. + 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); + // 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; + //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 (InternalWinderCfg.segmentoffsetpulses,screw_speed); process: set point 0, set max speed, move to the specified length, return back. + MotorSetSpeedWithCallback (MOTOR_SCREW, screw_speed, MotorsCfg[SCREW_MOTOR].minmicrostep,WinderPresegmentReady); + //in a callback: calculate backing rate for top and bottom, update point 0, update passing length, call the appropriate move to 0 / move; + + return OK; } uint32_t Winder_End(void) { //stop screw + return StopMotor (MOTOR_SCREW,1); } void Winder_ScrewHomeLimitSwitchInterrupt(void) { @@ -78,13 +115,13 @@ uint32_t Winder_ScrewAtOffsetCallback(uint32_t NumberOfSteps) { if (NumberOfSteps == InternalWinderCfg.segmentoffsetpulses) { - JobPrepareReady(Module_Winder, OK); + PrepareReady(Module_Winder, OK); return OK; } else { //do we want to do something? - JobPrepareReady(Module_Winder, ERROR); + PrepareReady(Module_Winder, ERROR); return ERROR; } diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h index e69de29bb..9b371ae07 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h @@ -0,0 +1,11 @@ + +#ifndef MODULES_THREAD_THREAD_EX_H_ +#define MODULES_THREAD_THREAD_EX_H_ +uint32_t ThreadPreSegmentState(void *JobDetails); +uint32_t ThreadSegmentState(void *JobDetails); +uint32_t ThreadEndState(void *JobDetails); +uint32_t ThreadInitialTestStub(); + + + +#endif diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_init.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_init.c index f32026ca8..5b0f034f4 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_init.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_init.c @@ -12,9 +12,9 @@ #include "thread.h" #define MAX_SYSTEM_DANCERS HARDWARE_DANCER_TYPE__RightDancer+1 -MotorConfigStruc MotorsCfg[MAX_THREAD_MOTORS_NUM]; -InternalWinderConfigStruc InternalWinderCfg; -DancerConfigStruc DancersCfg[MAX_SYSTEM_DANCERS]; +MotorConfigStruc MotorsCfg[MAX_THREAD_MOTORS_NUM]={0}; +InternalWinderConfigStruc InternalWinderCfg = {0}; +DancerConfigStruc DancersCfg[MAX_SYSTEM_DANCERS] = {0}; @@ -33,6 +33,9 @@ uint32_t InternalWindingConfigMessage(JobSpool* request) InternalWinderCfg.segmentoffsetpulses = request->segmentoffsetpulses; InternalWinderCfg.spoolbackingrate = request->backingrate; InternalWinderCfg.startoffsetpulses = request->startoffsetpulses; + InternalWinderCfg.SpoolBottomBackingRate = request->spoolbottombackingrate; + InternalWinderCfg.NumberOfRotationPerPassage = request->numberofrotationperpassage; + InternalWinderCfg.diameter = request->diameter; return status; } @@ -44,7 +47,7 @@ uint32_t MotorsConfigMessage(HardwareMotor * request) int Motor_i; Motor_i = request->hardwaremotortype; - if ((Motor_i)&&(Motor_i< MAX_THREAD_MOTORS_NUM)) + if (Motor_i< MAX_THREAD_MOTORS_NUM) { MotorsCfg[Motor_i].id = request->hardwaremotortype; MotorsCfg[Motor_i].minfreq = request->minfrequency; @@ -60,6 +63,7 @@ uint32_t MotorsConfigMessage(HardwareMotor * request) MotorsCfg[Motor_i].kd = request->kd; MotorsCfg[Motor_i].changeslope = request->changeslope; MotorsCfg[Motor_i].hightimeoutusec = request->highlengthmicrosecond; + ThreadInitialTestStub(request); return status; } else return Motor_i; @@ -71,7 +75,7 @@ uint32_t DancerConfigMessage(HardwareDancer * request) int Dancer_i; Dancer_i = request->hardwaredancertype; - if ((Dancer_i)&&(Dancer_i<MAX_SYSTEM_DANCERS )) + if (Dancer_i<MAX_SYSTEM_DANCERS ) { DancersCfg[Dancer_i].id = Dancer_i; DancersCfg[Dancer_i].fixorgradual = request->gradual; @@ -87,8 +91,8 @@ uint32_t DancerConfigMessage(HardwareDancer * request) uint32_t thread_init(void) { - memset (MotorsCfg,0,sizeof(MotorsCfg)); - memset (&InternalWinderCfg,0,sizeof(InternalWinderConfigStruc)); + //memset (MotorsCfg,0,sizeof(MotorsCfg)); + //memset (&InternalWinderCfg,0,sizeof(InternalWinderConfigStruc)); return OK; } diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c index 5f14a17a7..366ce827b 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c @@ -10,6 +10,10 @@ #include "../control/pidalgo.h" #include "PMR/Hardware/HardwareMotor.pb-c.h" #include "PMR/Hardware/HardwareMotorType.pb-c.h" +#include "PMR/Printing/JobSegment.pb-c.h" +#include "PMR/Printing/JobTicket.pb-c.h" + +#include "StateMachines/Printing/PrintingSTM.h" #include "drivers/Motors/Motor.h" #include "drivers/Danser_SSI/ssi_comm.h" @@ -19,14 +23,6 @@ //the state machine operation is used to operate in runtime correct profile flow execution //by recieved esign flow of the user from the UI /////////////////////////////////////////////////////////////////////////////////////////// -typedef enum -{ - NextState = 0, - Repeat, - Inter, - Home, - Stop -} ReturnCode; uint32_t ThreadMotorIdToMotorId[MAX_THREAD_MOTORS_NUM] = {MOTOR_RDRIVING,MOTOR_DRYER_DRIVING,MOTOR_LDRIVING,MOTOR_WINDER,MOTOR_SCREW}; @@ -47,6 +43,7 @@ typedef struct MotorControlConfig_t MotorControlConfig[MAX_THREAD_MOTORS_NUM]; uint32_t DeviceId2Motor[MAX_THREAD_MOTORS_NUM]; ////////////////////////Slow Motor State//////////////////////////////////// +uint32_t ThreadPreSegmentState(void *JobDetails); //////////////////////////////////////////////////////////////////////////// @@ -55,7 +52,7 @@ uint32_t ThreadSpeedControlCBFunction(uint32_t deviceID, uint32_t ReadValue) //read value is the dancer angle int i,index=MAX_THREAD_MOTORS_NUM; for (i=0;i<MAX_THREAD_MOTORS_NUM;i++) - if (DeviceId2Motor[i] == deviceID) + if (ThreadMotorIdToDancerId[i] == deviceID) { index = i; break; @@ -88,8 +85,9 @@ uint32_t ThreadControlCBFunction(uint32_t deviceID, uint32_t ReadValue) { //read value is the dancer angle int i,index=MAX_THREAD_MOTORS_NUM; + uint32_t TranslatedReadValue = ReadValue - 8740; for (i=0;i<MAX_THREAD_MOTORS_NUM;i++) - if (DeviceId2Motor[i] == deviceID) + if (ThreadMotorIdToDancerId[i] == deviceID) { index = i; break; @@ -99,9 +97,9 @@ uint32_t ThreadControlCBFunction(uint32_t deviceID, uint32_t ReadValue) LOG_ERROR (deviceID, "No motor for device"); return 0xFFFFFFFF; } - if(MotorControlConfig[index].m_isEnabled && (MotorControlConfig[index].m_SetParam != 0)) + if(MotorControlConfig[index].m_isEnabled ) { - MotorControlConfig[index].m_mesuredParam = ReadValue; + MotorControlConfig[index].m_mesuredParam = TranslatedReadValue; MotorControlConfig[index].m_calculatedError = PIDAlgorithmCalculation(MotorControlConfig[index].m_SetParam , MotorControlConfig[index].m_mesuredParam, &MotorControlConfig[index].m_params, &MotorControlConfig[index].m_preError, &MotorControlConfig[index].m_integral); if (MotorControlConfig[index].m_calculatedError >= MotorControlConfig[index].m_params.MAX) @@ -126,72 +124,97 @@ uint32_t ThreadControlCBFunction(uint32_t deviceID, uint32_t ReadValue) uint32_t Debug_Get_Dancer_Read(uint32_t DancerId, uint32_t Parameter1, uint32_t Parameter2) { + return (rand() % (103 + 1 + 103) - 103); } #endif +uint32_t ThreadInitialTestStub(HardwareMotor * request) +{ + + + //MotorsConfigMessage(request); + ThreadPrepareState(request); + ThreadPreSegmentState(request); + return OK; +} //******************************************************************************************************************** - ReturnCode PrepareState(void *JobDetails) + uint32_t ThreadPrepareState(void *JobDetails) { - int Motor_i; + int Motor_i, HW_Motor_Id; //start thread control for all motors for (Motor_i = 0;Motor_i < MAX_THREAD_MOTORS_NUM;Motor_i++) { - MotorControlConfig[Motor_i].m_params.MAX = MotorsCfg[Motor_i].maxfreq; - MotorControlConfig[Motor_i].m_params.MIN = MotorsCfg[Motor_i].minfreq; - MotorControlConfig[Motor_i].m_params.Kd = MotorsCfg[Motor_i].kd; - MotorControlConfig[Motor_i].m_params.Kp = MotorsCfg[Motor_i].kp; - MotorControlConfig[Motor_i].m_params.Ki = MotorsCfg[Motor_i].ki; - MotorControlConfig[Motor_i].m_params.dt = eOneMillisecond; - MotorControlConfig[Motor_i].m_calculatedError = 0; - MotorControlConfig[Motor_i].m_integral = 0; - MotorControlConfig[Motor_i].m_isEnabled = true; - MotorControlConfig[Motor_i].m_isReady = true; - MotorControlConfig[Motor_i].m_mesuredParam = 0; - MotorControlConfig[Motor_i].m_preError = 0; - MotorControlConfig[Motor_i].m_SetParam = 0;//need to update SetParams on presegment stage -#ifdef DEBUG_TEST_FUNCTIONS - if (Motor_i == DRYER_MOTOR) // dryer motor is speed controlled. later a speed sensor will be utilized, but for now it will not be controlled - AddControlCallback(ThreadSpeedControlCBFunction, eOneMillisecond,MotorGetSpeed,ThreadMotorIdToMotorId[Motor_i],0); - else - AddControlCallback(ThreadControlCBFunction, eOneMillisecond,Debug_Get_Dancer_Read,ThreadMotorIdToDancerId[Motor_i],0); -#else - if (Motor_i == DRYER_MOTOR) // dryer motor is speed controlled. later a speed sensor will be utilized, but for now it will not be controlled - continue; - //AddControlCallback(ThreadSpeedControlCBFunction, eOneMillisecond,MotorGetSpeed,ThreadMotorIdToMotorId[Motor_i],0); - else - AddControlCallback(ThreadControlCBFunction, eOneMillisecond,Read_Dancer_Position,ThreadMotorIdToDancerId[Motor_i],0); -#endif + HW_Motor_Id = ThreadMotorIdToMotorId[Motor_i]; + MotorControlConfig[Motor_i].m_params.MAX = MotorsCfg[HW_Motor_Id].maxfreq; + MotorControlConfig[Motor_i].m_params.MIN = MotorsCfg[HW_Motor_Id].minfreq; + MotorControlConfig[Motor_i].m_params.Kd = MotorsCfg[HW_Motor_Id].kd; + MotorControlConfig[Motor_i].m_params.Kp = MotorsCfg[HW_Motor_Id].kp; + MotorControlConfig[Motor_i].m_params.Ki = MotorsCfg[HW_Motor_Id].ki; + MotorControlConfig[Motor_i].m_params.dt = eOneMillisecond; + MotorControlConfig[Motor_i].m_calculatedError = 0; + MotorControlConfig[Motor_i].m_integral = 0; + MotorControlConfig[Motor_i].m_isEnabled = true; + MotorControlConfig[Motor_i].m_isReady = true; + MotorControlConfig[Motor_i].m_mesuredParam = 0; + MotorControlConfig[Motor_i].m_preError = 0; + MotorControlConfig[Motor_i].m_SetParam = 0;//need to update SetParams on presegment stage + #ifdef DEBUG_TEST_FUNCTIONS + 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 + //AddControlCallback(ThreadSpeedControlCBFunction, eOneMillisecond,MotorGetSpeed,ThreadMotorIdToMotorId[Motor_i],0); + // continue; + AddControlCallback(ThreadControlCBFunction, eOneMillisecond,Read_Dancer_Position,ThreadMotorIdToDancerId[Motor_i],Motor_i); + else if ((Motor_i == HARDWARE_MOTOR_TYPE__MOTO_WINDER)||(Motor_i == HARDWARE_MOTOR_TYPE__MOTO_LDRIVING)||(Motor_i == HARDWARE_MOTOR_TYPE__MOTO_RDRIVING)) + AddControlCallback(ThreadControlCBFunction, eOneMillisecond,Read_Dancer_Position,ThreadMotorIdToDancerId[Motor_i],Motor_i); + #else + 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; + //AddControlCallback(ThreadSpeedControlCBFunction, eOneMillisecond,MotorGetSpeed,ThreadMotorIdToMotorId[Motor_i],Motor_i); + else if ((Motor_i == HARDWARE_MOTOR_TYPE__MOTO_WINDER)||(Motor_i == HARDWARE_MOTOR_TYPE__MOTO_LDRIVING)||(Motor_i == HARDWARE_MOTOR_TYPE__MOTO_RDRIVING)) + AddControlCallback(ThreadControlCBFunction, eOneMillisecond,Read_Dancer_Position,ThreadMotorIdToDancerId[Motor_i],Motor_i); + #endif } - + Winder_Prepare(); //set 3 dancers to the profile positions + ControlStart(); return OK; } //******************************************************************************************************************** -ReturnCode PreSegmentState(void *JobDetails) +uint32_t ThreadPreSegmentState(void *JobDetails) { +//set the speed only before the first segment, speed is constant accros job + JobTicket* JobTicket = JobDetails; +// int process_speed = JobTicket->processparameters->dyeingspeed; + int process_speed = 500; + + int dryer_speed = process_speed * MotorsCfg[MOTOR_DRYER_DRIVING].ratio2dryerspeed; //set dryer_speed_translation_here - TimerMotors_t Motor_i; - for (Motor_i = 0;Motor_i < MAX_THREAD_MOTORS_NUM;Motor_i++) - { - MotorControlConfig[Motor_i].m_SetParam = MotorGetSpeed(getMotorId(Motor_i));//need to update SetParams on presegment stage - } // set the new speed in the dryer motor to the speed of the new segment + MotorSetSpeed(MOTOR_DRYER_DRIVING, process_speed, MotorsCfg[MOTOR_DRYER_DRIVING].minmicrostep); + // activate control fr all motors //set speed for both rocker motors //wait for all motors to get to the required speed (set the target speed for the control to check) //call the job state machine when the thread system is ready + PreSegmentReady(Module_Thread,OK); + return OK; } //******************************************************************************************************************** - ReturnCode SegmentState(void *JobDetails) + uint32_t ThreadSegmentState(void *JobDetails) { return OK; } //******************************************************************************************************************** - ReturnCode EndState(void *JobDetails) + uint32_t ThreadEndState(void *JobDetails) { + int Motor_i; + for ( Motor_i = 0;Motor_i < MAX_THREAD_MOTORS_NUM;Motor_i++) + { + StopMotor(ThreadMotorIdToMotorId[Motor_i],Hard_Hiz); + } + return OK; } @@ -211,3 +234,4 @@ void ThreadStopPrinting(void) { //PrintingIterate(); } + |
