diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2018-04-04 23:28:09 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2018-04-04 23:28:09 +0300 |
| commit | 692d71abcd583ade2977d4b6012b9c2a6de7d4d8 (patch) | |
| tree | 8f7788759361f8ad14d8f5609983ab3495248e4f /Software/Embedded_SW/Embedded/Modules/Thread | |
| parent | bb14319440cd873b1ad7713a66c4a2369dffb8e7 (diff) | |
| download | Tango-692d71abcd583ade2977d4b6012b9c2a6de7d4d8.tar.gz Tango-692d71abcd583ade2977d4b6012b9c2a6de7d4d8.zip | |
1. Idle task - test real time usage
2. improve and fix heaters test
3. motor/dancer test preparations
Diffstat (limited to 'Software/Embedded_SW/Embedded/Modules/Thread')
5 files changed, 92 insertions, 53 deletions
diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread.h b/Software/Embedded_SW/Embedded/Modules/Thread/Thread.h index fca12d50e..913b38df8 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread.h +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread.h @@ -69,6 +69,7 @@ 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); diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c index 9474ee44d..eacdd2ed9 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c @@ -53,7 +53,12 @@ uint32_t Winder_PrepareStage2(void) return status; } -uint32_t Winder_Print(void *JobDetails) + +uint32_t WinderPresegmentReady(uint32_t deviceID, uint32_t ReadValue) +{ + return PreSegmentReady(Module_Winder,OK); +} +uint32_t Winder_Presegment(void *JobDetails) { JobTicket* JobTicket = JobDetails; int process_speed = JobTicket->processparameters->dyeingspeed; @@ -87,6 +92,7 @@ uint32_t Winder_Print(void *JobDetails) // * 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; @@ -94,7 +100,7 @@ uint32_t Winder_Print(void *JobDetails) uint32_t Winder_End(void) { //stop screw - StopMotor (MOTOR_SCREW,1); + return StopMotor (MOTOR_SCREW,1); } void Winder_ScrewHomeLimitSwitchInterrupt(void) { 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 db32b7ba7..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}; @@ -47,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; @@ -63,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; @@ -74,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; @@ -90,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 e850ad776..366ce827b 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c @@ -13,6 +13,8 @@ #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" #include "drivers/Heater/TemperatureSensor.h" @@ -21,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}; @@ -49,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); //////////////////////////////////////////////////////////////////////////// @@ -57,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; @@ -90,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; @@ -101,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) @@ -131,71 +127,94 @@ uint32_t Debug_Get_Dancer_Read(uint32_t DancerId, uint32_t Parameter1, uint32_t return (rand() % (103 + 1 + 103) - 103); } #endif +uint32_t ThreadInitialTestStub(HardwareMotor * request) +{ + + + //MotorsConfigMessage(request); + ThreadPrepareState(request); + ThreadPreSegmentState(request); + return OK; +} //******************************************************************************************************************** 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 dryer_speed = process_speed * MotorsCfg[DRYER_MOTOR].ratio2dryerspeed; //set dryer_speed_translation_here +// 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 // set the new speed in the dryer motor to the speed of the new segment - MotorSetSpeed(MOTOR_DRYER_DRIVING, process_speed, MotorsCfg[DRYER_MOTOR].minmicrostep); + 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; } @@ -215,3 +234,4 @@ void ThreadStopPrinting(void) { //PrintingIterate(); } + |
