aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Modules/Thread
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2018-06-13 15:15:42 +0300
committerShlomo Hecht <shlomo@twine-s.com>2018-06-13 15:15:42 +0300
commitf502659ef54f1f798952089989923d1e76ab06cb (patch)
tree0768bd578808b51650da6ccb2da8750b1aa1b82e /Software/Embedded_SW/Embedded/Modules/Thread
parent2d900a86cae2027dc43d73e92da889d6e1aa3f7b (diff)
downloadTango-f502659ef54f1f798952089989923d1e76ab06cb.tar.gz
Tango-f502659ef54f1f798952089989923d1e76ab06cb.zip
screw handling initial works
Diffstat (limited to 'Software/Embedded_SW/Embedded/Modules/Thread')
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Thread/Thread.h2
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c65
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h4
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Thread/Thread_init.c7
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c10
5 files changed, 54 insertions, 34 deletions
diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread.h b/Software/Embedded_SW/Embedded/Modules/Thread/Thread.h
index 57b7a9d99..dad7a1db6 100644
--- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread.h
+++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread.h
@@ -55,7 +55,7 @@ extern HardwareDancer DancersCfg[MAX_SYSTEM_DANCERS];
extern int32_t MotorSamples[MAX_THREAD_MOTORS_NUM][MAX_CONTROL_SAMPLES];
extern int MotorSamplePointer[MAX_THREAD_MOTORS_NUM];
extern double NormalizedErrorCoEfficient[MAX_THREAD_MOTORS_NUM];
-extern double DancerStopActivityLimit[MAX_THREAD_MOTORS_NUM];
+extern int DancerStopActivityLimit[MAX_THREAD_MOTORS_NUM];
uint32_t InternalWinderConfigMessage(HardwareWinder* request);
diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c
index 164e5eb23..37f60e8cf 100644
--- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c
+++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c
@@ -9,6 +9,7 @@
#include "Drivers/Peripheral_GPIO/GPIO.h"
#include "drivers/Motors/Motor.h"
#include "StateMachines/Printing/PrintingSTM.h"
+#include "Modules/Control/Control.h"
#include "drivers/FPGA/FPGA.h"
@@ -16,10 +17,12 @@
#include "drivers/FPGA/FPGA_GPIO/FPGA_GPIO.h"
bool Winder_ScrewHoming = false;
-uint32_t Winder_ScrewAtOffsetCallback(uint32_t NumberOfSteps);
+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;
+uint32_t ScrewControlId = 0xFF;
uint32_t Winder_Init(void)
{
@@ -75,7 +78,7 @@ uint32_t Winder_Prepare(void *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 * MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].pulseperround)/(2*PI* MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].pulleyradius);
+ double ScrewSpeed = (process_speed*20 );//* MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].pulseperround)/(2*PI* MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].pulleyradius);
/*
* 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.
@@ -90,22 +93,23 @@ uint32_t Winder_Prepare(void *JobDetails)
else
{
Winder_ScrewHoming = true;
-// status = MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_SCREW,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize, ScrewSpeed, GPI_LS_SCREW_RIGHT, 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_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);
}
return status;
}
uint32_t Winder_PrepareStage2(uint32_t deviceID, uint32_t ReadValue)
{
- uint32_t status;
- uint32_t numOfSteps = InternalWinderCfg.segmentoffsetpulses;
+ 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 |= MotorMove(HARDWARE_MOTOR_TYPE__MOTO_SCREW, numOfSteps, Winder_ScrewAtOffsetCallback);
+ //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
return status;
@@ -116,6 +120,24 @@ uint32_t WinderPresegmentReady(uint32_t deviceID, uint32_t ReadValue)
{
return PreSegmentReady(Module_Winder,ModuleDone);
}
+uint32_t ScrewDirectionChange(uint32_t deviceID, uint32_t BusyFlag)
+{
+ //ScrewCurrentDirection: false moves out, true moves home
+ if (BusyFlag == NOTBUSY)
+ {
+ if (ScrewCurrentDirection == false)
+ {
+ ScrewCurrentDirection = true;
+ }
+ else
+ {
+ 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.
+ }
+ return OK;
+
+}
uint32_t Winder_Presegment(void *JobDetails)
{
JobTicket* JobTicket = JobDetails;
@@ -123,8 +145,9 @@ uint32_t Winder_Presegment(void *JobDetails)
float screw_speed = 0;
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);
+ //double ScrewSpeed = (process_speed * MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].pulseperround)/(2*PI* MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].pulleyradius);
/*typedef struct
{
@@ -150,16 +173,19 @@ uint32_t Winder_Presegment(void *JobDetails)
// * 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);
- //MotorMove (InternalWinderCfg.segmentoffsetpulses,screw_speed); process: set point 0, set max speed, move to the specified length, return back.
- MotorSetSpeedWithCallback (HARDWARE_MOTOR_TYPE__MOTO_SCREW, screw_speed,WinderPresegmentReady);
+ // 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;
+ PreSegmentReady(Module_Winder,ModuleDone);
return OK;
}
uint32_t Winder_End(void)
{
//stop screw
+ RemoveControlCallback(ScrewControlId,ScrewDirectionChange);
return StopMotor (HARDWARE_MOTOR_TYPE__MOTO_SCREW,Hard_Hiz);
}
void Winder_ScrewHomeLimitSwitchInterrupt(void)
@@ -176,19 +202,10 @@ 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 NumberOfSteps)
+uint32_t Winder_ScrewAtOffsetCallback(uint32_t deviceID, uint32_t BusyFlag)
{
- if (NumberOfSteps == InternalWinderCfg.segmentoffsetpulses)
- {
- PrepareReady(Module_Winder, ModuleDone);
- return OK;
- }
- else
- {
- //do we want to do something?
- PrepareReady(Module_Winder, ModuleFail);
- return ERROR;
- }
-
+ SetMotHome(HARDWARE_MOTOR_TYPE__MOTO_SCREW); //set this point as the spool home
+ PrepareReady(Module_Winder, ModuleDone);
+ return OK;
}
diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h
index 28a2346c1..8e8ea60e0 100644
--- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h
+++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_ex.h
@@ -2,6 +2,8 @@
#ifndef MODULES_THREAD_THREAD_EX_H_
#define MODULES_THREAD_THREAD_EX_H_
+#include "PMR/Printing/JobSpool.pb-c.h"
+
//typedef enum
//{
#define WINDER_DANCER HARDWARE_DANCER_TYPE__LeftDancer
@@ -10,6 +12,8 @@
#define NUM_OF_DANCERS HARDWARE_DANCER_TYPE__RightDancer+1
//} DANCER_ENUM;
+uint32_t InternalWindingConfigMessage(JobSpool* request);
+
uint32_t ThreadPrepareState(void *JobDetails);
uint32_t ThreadPreSegmentState(void *JobDetails);
uint32_t ThreadSegmentState(void *JobDetails, int SegmentId);
diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_init.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_init.c
index e2d492b47..3c9adbc31 100644
--- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_init.c
+++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_init.c
@@ -17,7 +17,7 @@ HardwarePidControl MotorsControl[MAX_THREAD_MOTORS_NUM] = {0};
int32_t MotorSamples[MAX_THREAD_MOTORS_NUM][MAX_CONTROL_SAMPLES] = {0};
int MotorSamplePointer[MAX_THREAD_MOTORS_NUM] = {0};
double NormalizedErrorCoEfficient[MAX_THREAD_MOTORS_NUM] = {0};
-double DancerStopActivityLimit[MAX_THREAD_MOTORS_NUM] = {0};
+int DancerStopActivityLimit[MAX_THREAD_MOTORS_NUM] = {0};
InternalWinderConfigStruc InternalWinderCfg = {0};
HardwareDancer DancersCfg[MAX_SYSTEM_DANCERS] = {0};
@@ -101,8 +101,9 @@ uint32_t MotorPidRequestMessage(HardwarePidControl* request)
temp=(10*(temp-1)*DancersCfg[ThreadMotorIdToDancerId[Motor_i]].maximalmovementmm);
NormalizedErrorCoEfficient[Motor_i] = NormalizedErrorCoEfficient[Motor_i] / temp;
// uint32_t MotorSamples[MAX_THREAD_MOTORS_NUM][MAX_CONTROL_SAMPLES];
- DancerStopActivityLimit[Motor_i] = ((1<<(DancersCfg[ThreadMotorIdToDancerId[Motor_i]].resolutionbits)*(DancersCfg[ThreadMotorIdToDancerId[Motor_i]].maximalmovementmm)*2));
- DancerStopActivityLimit[Motor_i] = DancerStopActivityLimit[Motor_i]/(2*PI*DancersCfg[ThreadMotorIdToDancerId[Motor_i]].armlength);
+ temp = 1<<(DancersCfg[ThreadMotorIdToDancerId[Motor_i]].resolutionbits);
+ temp = (temp*DancersCfg[ThreadMotorIdToDancerId[Motor_i]].maximalmovementmm*2);
+ DancerStopActivityLimit[Motor_i] = temp/(2*PI*DancersCfg[ThreadMotorIdToDancerId[Motor_i]].armlength);
return OK;
}
uint32_t DancerConfigMessage(HardwareDancer * request)
diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c
index 56e1bf844..fdae44171 100644
--- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c
+++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c
@@ -121,7 +121,6 @@ void ThreadUpdateProcessLength (double length, void *Funcptr)
}
double MotorSentData[1000] = {0};
uint32_t PosDif[1000] = {0};
-uint32_t tick[1000] = {0};
int MotorDataIndex = 0;
@@ -172,15 +171,14 @@ uint32_t ThreadLengthCBFunction(uint32_t IfIndex, uint32_t ReadValue)
PosDif[MotorDataIndex] = CurrentPosition;
//PosDif[MotorDataIndex] = positionDiff;
MotorSentData[MotorDataIndex] = length;
- tick[MotorDataIndex] = UsersysTickGet();
MotorDataIndex+=1;
if (MotorDataIndex == 999) MotorDataIndex = 0;
static int pooler_counter = 0;
pooler_counter++;
if (pooler_counter%10 == 0)
{
- //SendJobProgress(CurrentProcessedLength/CurrentRequestedLength,CurrentSegmentId,false);
- SendJobProgress(/*KeepNormalizedError*/MotorControlConfig[index].m_calculatedError,CurrentSegmentId,false);
+ SendJobProgress(CurrentProcessedLength/CurrentRequestedLength,CurrentSegmentId,false);
+ //SendJobProgress(/*KeepNormalizedError*/MotorControlConfig[index].m_calculatedError,CurrentSegmentId,false);
}
if (pooler_counter>=100)
@@ -486,10 +484,10 @@ uint32_t ThreadPreSegmentState(void *JobDetails)
//#warning rocker disabled
if (MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_RLOADING].has_directionthreadwize)
MotorSetDirection((TimerMotors_t)HARDWARE_MOTOR_TYPE__MOTO_RLOADING,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_RLOADING].directionthreadwize);
- MotorSetSpeed(HARDWARE_MOTOR_TYPE__MOTO_RLOADING, 10);
+ MotorSetSpeed(HARDWARE_MOTOR_TYPE__MOTO_RLOADING, 5);
if (MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LLOADING].has_directionthreadwize)
MotorSetDirection((TimerMotors_t)HARDWARE_MOTOR_TYPE__MOTO_LLOADING,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LLOADING].directionthreadwize);
- MotorSetSpeed(HARDWARE_MOTOR_TYPE__MOTO_LLOADING, 10);
+ MotorSetSpeed(HARDWARE_MOTOR_TYPE__MOTO_LLOADING, 5);
//#warning rocker disabled
// MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_RDRIVING,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_RDRIVING].directionthreadwize, 0, GPI_LS_RLOADMOTOR_UP, EndState); //TODO