From 87973c0cc97ba449e2b17c92ff6eb68e2a28a871 Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Thu, 14 Jun 2018 17:48:34 +0300 Subject: thread winder improvements --- Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c') diff --git a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c index 847b777fa..a1de29b08 100644 --- a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c +++ b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c @@ -31,7 +31,6 @@ #include "drivers/FPGA/FPGA.h" #include "modules/thread/thread_ex.h" -#include "Drivers/Peripheral_GPIO/GPIO.h" Task_Handle Millisecond_Task_Handle; /******************** Definitions ********************************************/ @@ -237,6 +236,7 @@ uint32_t MillisecLoop(uint32_t tick) FPGA_Read_limit_Switches_Registers(); //Read_FPGA_GPI_Rgisters();//FPGA_Read_limit_Switches(); #endif + temp += MotorActivity; if (MotorActivity) { @@ -340,7 +340,6 @@ uint32_t MillisecLoop(uint32_t tick) { for (Sensor_i = 0;Sensor_i < MAX_TEMPERATURE_SENSOR_ID;Sensor_i++) MillisecReadFromTempSensor(Sensor_i, NULL); - ACTIVITY_RED_LED_CHANGE_MODE; } if (Onesecond_Tick) -- cgit v1.3.1 From 8ea30fe7354c7d878c5ff718b7e52a04178cf55b Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Sun, 17 Jun 2018 14:16:18 +0300 Subject: MotorStop, improve IDS, Dispensers pressure --- .../Embedded/Drivers/ADC_Sampling/ADC.c | 1 + .../Embedded/Drivers/ADC_Sampling/ADC.h | 3 ++ .../Embedded_SW/Embedded/Drivers/Motors/Motor.c | 31 ++++++++++-------- .../Embedded_SW/Embedded/Drivers/Motors/Motor.h | 2 +- .../Embedded/Modules/Control/MillisecTask.c | 15 ++++++--- Software/Embedded_SW/Embedded/Modules/IDS/IDS.h | 1 + Software/Embedded_SW/Embedded/Modules/IDS/IDS_ex.h | 1 + .../Embedded_SW/Embedded/Modules/IDS/IDS_init.c | 17 ++++++++++ .../Embedded_SW/Embedded/Modules/IDS/IDS_print.c | 38 ++++++++++++++-------- .../Embedded/Modules/Stubs_Handler/Stub_Motor.c | 2 +- .../Embedded/Modules/Thread/Thread_Winder.c | 4 +-- .../Embedded/Modules/Thread/Thread_print.c | 8 +++-- .../Embedded/StateMachines/Printing/JobSTM.c | 2 +- .../Embedded/StateMachines/Printing/PrintingSTM.c | 6 ++-- 14 files changed, 89 insertions(+), 42 deletions(-) (limited to 'Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c') diff --git a/Software/Embedded_SW/Embedded/Drivers/ADC_Sampling/ADC.c b/Software/Embedded_SW/Embedded/Drivers/ADC_Sampling/ADC.c index f07bd790e..9659e5ff5 100644 --- a/Software/Embedded_SW/Embedded/Drivers/ADC_Sampling/ADC.c +++ b/Software/Embedded_SW/Embedded/Drivers/ADC_Sampling/ADC.c @@ -154,6 +154,7 @@ uint32_t g_pui32ADCSeq[MAX_ADC_DEVICES] = //#define NUM_ADC_CHANNELS (sizeof(g_pui32ADCSeq) / \ sizeof(g_pui32ADCSeq[0])) +int DispenserIdToPressureSensorId[MAX_DISPENSERS] = {CHAN_DISPENSE_PRESSURE_1, CHAN_DISPENSE_PRESSURE_2 , CHAN_DISPENSE_PRESSURE_3 , CHAN_DISPENSE_PRESSURE_4 , CHAN_DISPENSE_PRESSURE_5 , CHAN_DISPENSE_PRESSURE_6 , CHAN_DISPENSE_PRESSURE_7 , CHAN_DISPENSE_PRESSURE_8 }; //const uint8_t Num_ADC_Channels = ( sizeof(g_pui32ADCSeq) / sizeof(g_pui32ADCSeq[0]) ); diff --git a/Software/Embedded_SW/Embedded/Drivers/ADC_Sampling/ADC.h b/Software/Embedded_SW/Embedded/Drivers/ADC_Sampling/ADC.h index 87f776c89..b667025e5 100644 --- a/Software/Embedded_SW/Embedded/Drivers/ADC_Sampling/ADC.h +++ b/Software/Embedded_SW/Embedded/Drivers/ADC_Sampling/ADC.h @@ -12,10 +12,13 @@ //***************************************************************************** #define MAX_ADC_DEVICES 20 +#define MAX_DISPENSERS + //#define MAX_ADC_DEVICES NUM_ADC_CHANNELS #define MAX_DIGITAL_POTENTIOMETER_READ 0x660D +extern int DispenserIdToPressureSensorId[MAX_DISPENSERS]; typedef void (*ProcessCallback)(uint32_t* adcData); void ADCAcquireInit(void); diff --git a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.c b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.c index eb2f25100..761e2e935 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.c +++ b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.c @@ -287,7 +287,7 @@ bool MotorControlGetnBusyState(uint32_t _motorId, uint32_t parameter) /* * Stop Command */ -uint32_t StopMotor(TimerMotors_t _motorId, STOP_TYPE_ENUM StopType) +uint32_t MotorStop(TimerMotors_t _motorId, STOP_TYPE_ENUM StopType) { #ifdef EVALUATION_BOARD Stop_Command = StopType; @@ -342,7 +342,7 @@ uint32_t MotorMoveWithCallback (TimerMotors_t _motorId,bool direction, uint32_t //SetMotorSpeed (deviceId, parameter); MotorMoveModuleCallback = callback; - StopMotor(_motorId,2 ); + MotorStop(_motorId,2 ); MotorMove(_motorId,direction,Steps ); MotorMoveControlId = AddControlCallback( MotorMoveCallBackFunction, eTenMilliSecond, MotorControlGetnBusyState,(IfTypeMotors*0x100+_motorId), _motorId, 0 ); return MotorMoveControlId; @@ -416,20 +416,23 @@ uint32_t MotorMoveToLimitSwitchCallBackFunction(uint32_t IfIndex, bool LimitSwit } MotorId = IfIndex&0xFF; - if (LimitSwitch == LIMIT) - { - //stop this control loop - RemoveControlCallback(MotorMovetoLimitSwitchControlId[MotorId], MotorMoveToLimitSwitchCallBackFunction ); - StopMotor(MotorId,Hard_Hiz); //TODO in run time limit switch just reverse direction + if (MotorMovetoLimitSwitchControlId[MotorId] == 0xFF) + return ERROR; + if (LimitSwitch == LIMIT) + { + //stop this control loop + RemoveControlCallback(MotorMovetoLimitSwitchControlId[MotorId], MotorMoveToLimitSwitchCallBackFunction ); + MotorMovetoLimitSwitchControlId[MotorId] = 0xFF; + MotorStop(MotorId,Hard_Hiz); //TODO in run time limit switch just reverse direction - //possibly: start regular control (speed etc) - //uint32_t ControlId = AddControlCallback(ControlCBFunction Callback, eOneMillisecond, (IfTypeMotors*0x100+_motorId), deviceId, Parameter ); + //possibly: start regular control (speed etc) + //uint32_t ControlId = AddControlCallback(ControlCBFunction Callback, eOneMillisecond, (IfTypeMotors*0x100+_motorId), deviceId, Parameter ); - //call the module callback - if (MotorMovetoLimitSwitchCallback) - MotorMovetoLimitSwitchCallback(MotorId,LimitSwitch); + //call the module callback + if (MotorMovetoLimitSwitchCallback) + MotorMovetoLimitSwitchCallback(MotorId,LimitSwitch); - } + } return OK; } uint32_t MotorMovetoLimitSwitch (TimerMotors_t _motorId,bool direction, uint32_t Freq, uint32_t LimitSwitchId, callback_fptr callback) //TODO @@ -442,6 +445,8 @@ uint32_t MotorMovetoLimitSwitch (TimerMotors_t _motorId,bool direction, uint32_t MotorSetDirection( _motorId, direction); MotorSetSpeed(_motorId, Freq); + if (MotorMovetoLimitSwitchControlId[_motorId] != 0xFF) + return ERROR; MotorMovetoLimitSwitchControlId[_motorId] = AddControlCallback( MotorMoveToLimitSwitchCallBackFunction, eOneMillisecond , FPGA_Read_limit_Switches,(IfTypeMotors*0x100+_motorId), LimitSwitchId, 0 ); MotorMovetoLimitSwitchCallback = callback; diff --git a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h index c59481113..b7e11d21d 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h +++ b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h @@ -160,7 +160,7 @@ typedef enum Soft_Hiz, }STOP_TYPE_ENUM; -uint32_t StopMotor(TimerMotors_t _motorId, STOP_TYPE_ENUM StopType); +uint32_t MotorStop(TimerMotors_t _motorId, STOP_TYPE_ENUM StopType); uint32_t MotorMove(TimerMotors_t _motorId,bool direction, uint32_t Steps); diff --git a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c index a1de29b08..312f970d6 100644 --- a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c +++ b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c @@ -31,6 +31,7 @@ #include "drivers/FPGA/FPGA.h" #include "modules/thread/thread_ex.h" +#include "modules/ids/ids_ex.h" Task_Handle Millisecond_Task_Handle; /******************** Definitions ********************************************/ @@ -134,7 +135,7 @@ void MillisecStart(void) ADCAcquireStart(0,1); } - +uint32_t msec_millisecondCounter = 0; void OneMilliSecondMillisecInterrupt(UArg arg0) { MillisecMessageStruc Message; @@ -148,7 +149,7 @@ void OneMilliSecondMillisecInterrupt(UArg arg0) //send message to the Millisec task Message.messageId = OneMillisec; - Message.tick = UsersysTickGet(); + Message.tick = msec_millisecondCounter++;; Message.msglen = sizeof(MillisecMessageStruc); if (MillisecMsgQ != NULL) Mailbox_post(MillisecMsgQ , &Message, BIOS_NO_WAIT); @@ -226,9 +227,10 @@ uint32_t MillisecLoop(uint32_t tick) //call all modules Millisec functions //test dancers and speed encoders //check all callback units (state machine waiting for completion of a change) - bool Ten_msTick, Hundred_msTick, Onesecond_Tick; + bool Ten_msTick, Hundred_msTick, Onesecond_Tick,O900Millisecond_Tick; Ten_msTick = (tick%eTenMilliSecond == 0) ?true:false; Hundred_msTick = (tick%eHundredMillisecond == 0) ?true:false; + O900Millisecond_Tick = (tick%eOneSecond == 900) ?true:false; Onesecond_Tick = (tick%eOneSecond == 0) ?true:false; //gather Motor data from FPGA #ifndef EVALUATION_BOARD @@ -342,10 +344,15 @@ uint32_t MillisecLoop(uint32_t tick) MillisecReadFromTempSensor(Sensor_i, NULL); } - if (Onesecond_Tick) + if (O900Millisecond_Tick) { ADC_TriggerCollection(); } + if (Onesecond_Tick) + { + for (Sensor_i = 0;Sensor_i < MAX_SYSTEM_DISPENSERS;Sensor_i++) + CalculateDispenserPressure(Sensor_i); + } /* OLD CODE MotorStatus_Data[MOTOR_DRYER_DRIVING] = MotorGetStatusFromFPGA(MOTOR_DRYER_DRIVING); diff --git a/Software/Embedded_SW/Embedded/Modules/IDS/IDS.h b/Software/Embedded_SW/Embedded/Modules/IDS/IDS.h index 2c3910140..c3499454d 100644 --- a/Software/Embedded_SW/Embedded/Modules/IDS/IDS.h +++ b/Software/Embedded_SW/Embedded/Modules/IDS/IDS.h @@ -6,6 +6,7 @@ #include "ids_ex.h" extern uint32_t DispenserIdToMotorId[MAX_SYSTEM_DISPENSERS]; +extern float DispenserPressure[MAX_SYSTEM_DISPENSERS]; uint32_t DispenserConfigMessage(HardwareDispenser * request); extern HardwareDispenser DispensersCfg[ MAX_SYSTEM_DISPENSERS]; diff --git a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_ex.h b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_ex.h index feb38000f..bc9e11749 100644 --- a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_ex.h +++ b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_ex.h @@ -17,5 +17,6 @@ uint32_t IDSSegmentState(void *JobDetails, int SegmentId); uint32_t IDS_DispenserPidRequestMessage(HardwarePidControl* request); +float CalculateDispenserPressure (int DispenserId); #endif /* MODULES_IDS_IDS_EX_H_ */ diff --git a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_init.c b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_init.c index d53ab3d60..81efa5662 100644 --- a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_init.c +++ b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_init.c @@ -12,6 +12,7 @@ #include "PMR/Printing/JobSpoolType.pb-c.h" #include "drivers/Motors/Motor.h" +#include "drivers/ADC_Sampling/adc.h" #define MAX_CONTROL_SAMPLES 10 @@ -19,6 +20,22 @@ HardwareDispenser DispensersCfg[ MAX_SYSTEM_DISPENSERS]; uint32_t DispenserIdToMotorId[MAX_SYSTEM_DISPENSERS] = {HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_1,HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_2,HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_3,HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_4,HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_5,HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_6,HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_7,HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_8}; +float DispenserPressure[MAX_SYSTEM_DISPENSERS] = {0}; + +float CalculateDispenserPressure (int DispenserId) +{ + unsigned short data = 0; + float temp= 0.0; + + data = ADC_GetReading(DispenserIdToPressureSensorId[DispenserId]); + temp = 4096 - data; + temp *= 3; + temp *= 1000; //move to mv + temp /= 4096; + DispenserPressure[DispenserId] = 3000 - temp; + return( DispenserPressure[DispenserId]); + +} uint32_t DispenserConfigMessage(HardwareDispenser * request) diff --git a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_print.c b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_print.c index abd9794b8..1c9323254 100644 --- a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_print.c +++ b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_print.c @@ -159,24 +159,16 @@ uint32_t IDSPreSegmentState(void *JobDetails, int SegmentId) TimerMotors_t HW_Motor_Id; int segmentfirst_speed; int CurrentSegment = 0; - JobBrushStopId = 0; - - for (Dispenser_i = 0;Dispenser_i <= MAX_SYSTEM_DISPENSERS;Dispenser_i++) - { - HW_Motor_Id = DispenserIdToMotorId[Dispenser_i]; - //(Speed*uStep*PPR)/((2*PI*Dispenser_Radius) - segmentfirst_speed = JobTicket->segments[CurrentSegment]->brushstops[JobBrushStopId]->dispensers[Dispenser_i]->pulsepersecond; - double Dispenser_speed = (segmentfirst_speed * MotorsCfg[HW_Motor_Id].pulseperround)/(2*PI* MotorsCfg[HW_Motor_Id].pulleyradius); - //DispenserControlConfig[Dispenser_i].m_SetParam = Dispenser_speed; - OriginalDispenserSpd_2PPS[Dispenser_i] = (int)Dispenser_speed; - } - //ControlStart(); - MotorSetSpeed(HW_Motor_Id, OriginalDispenserSpd_2PPS[HW_Motor_Id]); // activate control fr all motors /* wait for all dispensers to get to the required pressure * move the presegment ready when all dispensers are ready. */ + for (Dispenser_i = 0;Dispenser_i <= MAX_SYSTEM_DISPENSERS;Dispenser_i++) + { + HW_Motor_Id = DispenserIdToMotorId[Dispenser_i]; + MotorStop(HW_Motor_Id,Hard_Stop); + } //call the job state machine when the thread system is ready PreSegmentReady(Module_IDS,ModuleDone); @@ -186,6 +178,24 @@ int CurrentSegment = 0; //******************************************************************************************************************** uint32_t IDSSegmentState(void *JobDetails, int SegmentId) { + JobTicket* JobTicket = JobDetails; + int Dispenser_i; + TimerMotors_t HW_Motor_Id; + int segmentfirst_speed; + int CurrentSegment = 0; + + JobBrushStopId = 0; + + for (Dispenser_i = 0;Dispenser_i <= MAX_SYSTEM_DISPENSERS;Dispenser_i++) + { + HW_Motor_Id = DispenserIdToMotorId[Dispenser_i]; + //(Speed*uStep*PPR)/((2*PI*Dispenser_Radius) + segmentfirst_speed = JobTicket->segments[CurrentSegment]->brushstops[JobBrushStopId]->dispensers[Dispenser_i]->pulsepersecond; +// double Dispenser_speed = (segmentfirst_speed * MotorsCfg[HW_Motor_Id].pulseperround)/(2*PI* MotorsCfg[HW_Motor_Id].pulleyradius); + //DispenserControlConfig[Dispenser_i].m_SetParam = Dispenser_speed; +// OriginalDispenserSpd_2PPS[Dispenser_i] = (int)Dispenser_speed; + MotorSetSpeed(HW_Motor_Id, segmentfirst_speed); + } return OK; } @@ -195,7 +205,7 @@ int CurrentSegment = 0; int Motor_i; for ( Motor_i = 0;Motor_i < MAX_SYSTEM_DISPENSERS;Motor_i++) { - StopMotor(DispenserIdToMotorId[Motor_i],Hard_Hiz); + MotorStop(DispenserIdToMotorId[Motor_i],Hard_Hiz); } return OK; diff --git a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_Motor.c b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_Motor.c index 01c91c72b..cef0e1270 100644 --- a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_Motor.c +++ b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_Motor.c @@ -294,7 +294,7 @@ void Stub_MotorStopRequest(MessageContainer* requestContainer) Mot_Stop(); #else TimerMotors_t Motor_Id = (TimerMotors_t)request->motor_id; //to remove warning - StopMotor(Motor_Id, Stop_Command); + MotorStop(Motor_Id, Stop_Command); #endif diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c index f80f26e53..e99d3df0b 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c @@ -183,14 +183,14 @@ uint32_t Winder_End(void) //stop screw ScrewNumberOfSteps = 0; RemoveControlCallback(ScrewControlId,ScrewDirectionChange); - return StopMotor (HARDWARE_MOTOR_TYPE__MOTO_SCREW,Hard_Hiz); + return MotorStop (HARDWARE_MOTOR_TYPE__MOTO_SCREW,Hard_Hiz); } void Winder_ScrewHomeLimitSwitchInterrupt(void) { uint32_t status; if (Winder_ScrewHoming) { - StopMotor(HARDWARE_MOTOR_TYPE__MOTO_SCREW,Hard_Stop); //stop ASAP + MotorStop(HARDWARE_MOTOR_TYPE__MOTO_SCREW,Hard_Stop); //stop ASAP } status = MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_SCREW,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize);//make sure to move the cart out } diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c index 7b5da0e65..e9cc3ddde 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c @@ -37,6 +37,7 @@ HardwareDancerType ThreadMotorIdToDancerId[MAX_THREAD_MOTORS_NUM] = {FEEDER_DANC uint32_t ControlIdtoMotorId [MAX_THREAD_MOTORS_NUM] = {0xFF}; uint32_t SpeedControlId=0xFF; +double DancerError[NUM_OF_DANCERS] = {0.0}; int OriginalMotorSpd_2PPS[MAX_THREAD_MOTORS_NUM] = {0}; uint32_t JobCounter = 0; typedef struct @@ -304,6 +305,7 @@ uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) } NormalizedError = avreageSampleValue*NormalizedErrorCoEfficient[index]; MotorControlConfig[index].m_mesuredParam = NormalizedError; + DancerError[DancerId] = NormalizedError; MotorControlConfig[index].m_calculatedError = PIDAlgorithmCalculation((float)MotorControlConfig[index].m_SetParam , (float)MotorControlConfig[index].m_mesuredParam, &MotorControlConfig[index].m_params, &MotorControlConfig[index].m_preError, &MotorControlConfig[index].m_integral); if (index != FEEDER_MOTOR) //feeder unit handles errors opposite to left unit @@ -544,10 +546,10 @@ uint32_t ThreadSegmentState(void *JobDetails, int SegmentId) { RemoveControlCallback(ControlIdtoMotorId[Motor_i],ThreadControlCBFunction); } - StopMotor(ThreadMotorIdToMotorId[Motor_i],Hard_Hiz); + MotorStop(ThreadMotorIdToMotorId[Motor_i],Hard_Hiz); } - StopMotor(HARDWARE_MOTOR_TYPE__MOTO_RLOADING,Hard_Hiz); - StopMotor(HARDWARE_MOTOR_TYPE__MOTO_LLOADING,Hard_Hiz); + MotorStop(HARDWARE_MOTOR_TYPE__MOTO_RLOADING,Hard_Hiz); + MotorStop(HARDWARE_MOTOR_TYPE__MOTO_LLOADING,Hard_Hiz); return OK; } diff --git a/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c b/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c index f62bfba26..1e862128f 100644 --- a/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c +++ b/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c @@ -166,7 +166,7 @@ static ReturnCode PrepareState(void *JobDetails) } if (Configured[Module_Winder]) { - Winder_Prepare(JobDetails); + Winder_Prepare(); } return retcode; diff --git a/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.c b/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.c index 57f3ff5a3..c6ea98ba3 100644 --- a/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.c +++ b/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.c @@ -267,17 +267,17 @@ uint32_t EndState(void *JobDetails) if (Configured[Module_IDS]) { //EndWaiting[Module_IDS] = ModuleWaiting; - //IDSEndState(JobDetails); + IDSEndState(JobDetails); } if (Configured[Module_Heaters]) { - EndWaiting[Module_Heaters] = ModuleWaiting; + //EndWaiting[Module_Heaters] = ModuleWaiting; //heaters preparation starts on process parameters handling HeatersEnd(); } if (Configured[Module_Thread]) { - EndWaiting[Module_Thread] = ModuleWaiting; + //EndWaiting[Module_Thread] = ModuleWaiting; ThreadEndState(CurrentJob); } -- cgit v1.3.1 From 3640afb74b3e7b3e232f56a14104866690495c9a Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Mon, 18 Jun 2018 12:31:20 +0300 Subject: Motor Control Fixed, new winder works, CurrentJob holds the job request message --- .../Embedded_SW/Embedded/Drivers/Motors/Motor.c | 51 +++++++----- .../Embedded/Modules/AlarmHandling/AlarmHandling.c | 94 ++++++++++++++++++++++ .../Embedded/Modules/AlarmHandling/AlarmHandling.h | 2 +- .../Embedded/Modules/Control/MillisecTask.c | 2 + .../Embedded/Modules/Thread/Thread_Winder.c | 5 +- .../Embedded/StateMachines/Printing/JobSTM.c | 21 ++++- 6 files changed, 149 insertions(+), 26 deletions(-) (limited to 'Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c') diff --git a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.c b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.c index 9dce895b9..2f4afed73 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.c +++ b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.c @@ -48,21 +48,22 @@ MotorDriverRequestStruct MotorDriverRequest[NUM_OF_MOTORS]; //MotorDriverConfigStruc MotorsCfg[NUM_OF_MOTORS]; TimerMotors_t FastMotorToMotorId[4] = {HARDWARE_MOTOR_TYPE__MOTO_RDRIVING,HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING,HARDWARE_MOTOR_TYPE__MOTO_LDRIVING,HARDWARE_MOTOR_TYPE__MOTO_WINDER}; -callback_fptr MotorMoveModuleCallback = 0; -callback_fptr MotorSetSpeedModuleCallback = 0; -callback_fptr MotorMovetoLimitSwitchCallback = 0; +callback_fptr MotorMoveModuleCallback[NUM_OF_MOTORS]; +callback_fptr MotorSetSpeedModuleCallback[NUM_OF_MOTORS]; +callback_fptr MotorMovetoLimitSwitchCallback[NUM_OF_MOTORS]; uint32_t ControlCallBackFunction(uint32_t deviceID, uint32_t ReadValue); uint32_t MotorMoveCallBackFunction(uint32_t deviceId, uint32_t BusyFlag); uint32_t MotorSetSpeedCallBackFunction(uint32_t deviceId, uint32_t BusyFlag); -uint32_t MotorMoveControlId = 0; -uint32_t MotorSetSpeedControlId = 0; -uint32_t MotorMovetoLimitSwitchControlId[NUM_OF_MOTORS] = {0}; +uint32_t MotorMoveControlId[NUM_OF_MOTORS]; +uint32_t MotorSetSpeedControlId[NUM_OF_MOTORS]; +uint32_t MotorMovetoLimitSwitchControlId[NUM_OF_MOTORS]; //initialize general motors driver database uint32_t MotorsInit(void) { + int i = 0; #ifdef EVALUATION_BOARD //MOTOR Driver L6470 SPI SPI2_Init(); @@ -76,6 +77,16 @@ uint32_t MotorsInit(void) #else FPGA_SetMotorsInit(); #endif + for (i=0;i +#include +#include +#include + +char DiagnosticsToken[36] = {0}; +bool DiagnosticsActive = false; + Task_Handle AlarmHandling_Task_Handle; Mailbox_Handle AlarmHandlingMsgQ = NULL; @@ -33,6 +41,7 @@ Mailbox_Handle AlarmHandlingMsgQ = NULL; typedef enum { AlarmHandlingTrigger, + AlarmHandlingSendDiagnostics }AlarmHandlingMessages; typedef struct AlarmHandlingMessage{ @@ -44,6 +53,42 @@ typedef struct AlarmHandlingMessage{ /******************** CODE ********************************************/ //********************************************************************** +uint32_t StartDiagnosticsRequestFunc(MessageContainer* requestContainer) +{ + uint32_t status = NOT_SUPPORTED; + //MessageContainer responseContainer; + +// ReportInitParams InitParams; + + StartDiagnosticsRequest* request = start_diagnostics_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data); + strcpy (DiagnosticsToken, requestContainer->token); + DiagnosticsActive = true; + + start_diagnostics_request__free_unpacked(request,NULL); + return status; +} +uint32_t StopDiagnosticsRequestFunc(MessageContainer* requestContainer) +{ + + MessageContainer responseContainer; + + StopDiagnosticsRequest* request = stop_diagnostics_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data); + + StopDiagnosticsResponse response = STOP_DIAGNOSTICS_RESPONSE__INIT; + + DiagnosticsActive = false; + + responseContainer = createContainer(MESSAGE_TYPE__StopDiagnosticsResponse, requestContainer->token, false, &response, &stop_diagnostics_response__pack, &stop_diagnostics_response__get_packed_size); + responseContainer.continuous = false; + uint8_t* container_buffer = malloc(message_container__get_packed_size(&responseContainer)); + size_t container_size = message_container__pack(&responseContainer, container_buffer); + free(responseContainer.data.data); + //USBCDCD_sendData(container_buffer, container_size,10); + SendChars(container_buffer, container_size); + //free (container_buffer); + +return OK; +} void AlarmHandlingInit(void) { @@ -72,11 +117,58 @@ void AlarmHandlingIterate(UArg arg0) return ; } +void AlarmHandler_SendDiagnostics(void) +{ + AlarmHandlingMessageStruc Message; + //send message to the Millisec task + Message.messageId = AlarmHandlingSendDiagnostics; + Message.tick = UsersysTickGet(); + Message.msglen = sizeof(AlarmHandlingMessageStruc); + if (AlarmHandlingMsgQ != NULL) + Mailbox_post(AlarmHandlingMsgQ , &Message, BIOS_NO_WAIT); + + + return ; +} uint32_t AlarmHandlingLoop(uint32_t tick) { return OK; } +void SendDiagnostics(void) +{ + MessageContainer responseContainer; + + StartDiagnosticsResponse response = START_DIAGNOSTICS_RESPONSE__INIT; + + if (DiagnosticsActive == false) + return; + + /*DiagnosticsMonitors *monitors; + size_t n_digitalpins; + DigitalPin **digitalpins; + extern bool FPGA_Gpi_Buf[MAX_GPI]; + +void Read_FPGA_GPI_Rgisters(); +bool FPGA_Read_limit_Switches(FPGA_GPI_ENUM Limit_Switch); + + size_t n_componentsstates; + ValueComponentState **componentsstates; + size_t n_events; + Event **events;*/ + + + responseContainer = createContainer(MESSAGE_TYPE__StartDiagnosticsResponse, DiagnosticsToken, false, &response, &start_diagnostics_response__pack, &start_diagnostics_response__get_packed_size); + responseContainer.continuous = true; + + uint8_t* container_buffer = malloc(message_container__get_packed_size(&responseContainer)); + size_t container_size = message_container__pack(&responseContainer, container_buffer); + free(responseContainer.data.data); + //USBCDCD_sendData(container_buffer, container_size,10); +// SendChars(container_buffer, container_size); + //free (container_buffer); + +} /****************************************************************************** * ======== messageTsk ======== * Task for this function is created statically. See the project's .cfg file. @@ -99,6 +191,8 @@ void AlarmHandlingTask(UArg arg0, UArg arg1) case AlarmHandlingTrigger: AlarmHandlingLoop(Message.tick); break; + case AlarmHandlingSendDiagnostics: + SendDiagnostics(); default: break; } diff --git a/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.h b/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.h index c5eb88660..9e1be07e2 100644 --- a/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.h +++ b/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.h @@ -9,7 +9,7 @@ #define MODULES_ALARMHANDLING_ALARMHANDLING_H_ - +void AlarmHandler_SendDiagnostics(void); #endif /* MODULES_ALARMHANDLING_ALARMHANDLING_H_ */ diff --git a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c index 312f970d6..67de0271f 100644 --- a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c +++ b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c @@ -16,6 +16,7 @@ /////////////////////////////////////////////////////////////////////////////////////////// #include "include.h" #include "Modules/General/GeneralHardware.h" +#include "Modules/AlarmHandling/AlarmHandling.h" #include "MillisecTask.h" #include @@ -342,6 +343,7 @@ uint32_t MillisecLoop(uint32_t tick) { for (Sensor_i = 0;Sensor_i < MAX_TEMPERATURE_SENSOR_ID;Sensor_i++) MillisecReadFromTempSensor(Sensor_i, NULL); + AlarmHandler_SendDiagnostics(); } if (O900Millisecond_Tick) diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c index e99d3df0b..3505ff3c6 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c @@ -111,7 +111,7 @@ uint32_t ScrewDirectionChange(uint32_t deviceID, uint32_t BusyFlag) if (BusyfirstCall) { BusyfirstCall = false; - return; + return OK; } //ScrewCurrentDirection: false moves out, true moves home if (BusyFlag == NOTBUSY) @@ -182,7 +182,8 @@ uint32_t Winder_End(void) { //stop screw ScrewNumberOfSteps = 0; - RemoveControlCallback(ScrewControlId,ScrewDirectionChange); + if (ScrewControlId != 0xFF) + RemoveControlCallback(ScrewControlId,ScrewDirectionChange); return MotorStop (HARDWARE_MOTOR_TYPE__MOTO_SCREW,Hard_Hiz); } void Winder_ScrewHomeLimitSwitchInterrupt(void) diff --git a/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c b/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c index 1e862128f..e3405689e 100644 --- a/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c +++ b/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c @@ -54,8 +54,9 @@ Mailbox_Handle JobmsgQ = NULL; #define MAX_TICKET_SIZE 10000 -char CurrentJobBuffer[MAX_TICKET_SIZE]; -JobTicket *CurrentJob = (JobTicket *)CurrentJobBuffer; +//char CurrentJobBuffer[MAX_TICKET_SIZE]; +JobTicket *CurrentJob = NULL;//(JobTicket *)CurrentJobBuffer; +JobRequest *CurrentJobRequest = NULL; //char PreviousJobBuffer[MAX_TICKET_SIZE]; //JobTicket *PreviousJob = (JobTicket *)PreviousJobBuffer; @@ -275,6 +276,11 @@ void JobAbortFunc(MessageContainer* requestContainer) free(responseContainer.data.data); SendChars((char*)container_buffer, container_size); abort_job_request__free_unpacked(request,NULL); + //We keep the job request until it is done + job_request__free_unpacked(CurrentJobRequest,NULL); + CurrentJob = NULL; + CurrentJobRequest = NULL; + } @@ -286,6 +292,9 @@ void JobRequestFunc(MessageContainer* requestContainer) uint8_t* container_buffer; + if (CurrentJobRequest!= NULL) + job_request__free_unpacked(CurrentJobRequest,NULL); + JobRequest* request = job_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data); strcpy (JobToken, requestContainer->token); @@ -298,7 +307,10 @@ void JobRequestFunc(MessageContainer* requestContainer) } else { - memcpy(CurrentJob, Ticket,TicketSize); + //memcpy(CurrentJob, Ticket,TicketSize); + CurrentJob = Ticket; + CurrentJobRequest = request; + status = PASSED; HandleProcessParameters(Ticket->processparameters); InternalWindingConfigMessage(Ticket->spool); @@ -346,7 +358,8 @@ void JobRequestFunc(MessageContainer* requestContainer) size_t container_size = message_container__pack(&responseContainer, container_buffer); free(responseContainer.data.data); SendChars((char*)container_buffer, container_size); - job_request__free_unpacked(request,NULL); + //We keep the job request until it is done + // job_request__free_unpacked(request,NULL); //free(container_buffer); //free(requestContainer); -- cgit v1.3.1