1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
|
/************************************************************************************************
* TimerMotor.h
* this module is used to operate and control over dispensers and winding, using clock object
* the motors which are not connected to the PWM pins and needs microstepping
*
*************************************************************************************************/
#ifndef DRIVERS_MOTOR_H_
#define DRIVERS_MOTOR_H_
#include "include.h"
//#include "Modules/thread/thread.h"
#include "PMR/Hardware/HardwareMotorType.pb-c.h"
#include "PMR/Hardware/HardwareMotor.pb-c.h"
#include <stdint.h>
#include <stdbool.h>
#include "drivers/FPGA/FPGA.h"
#include "drivers/FPGA/FPGA_GPIO/FPGA_GPIO.h"
#define TimerMotors_t HardwareMotorType
static char* MotorStr[30] = {
"Dyeing Head Clean Head",
"Dyeing Head Clean Mech",
"Dyeing Head Lid ",
"Dryer Driving",
"Dryer Lid ",
"Dryer Loadarm",
"Dispenser 1",
"Dispenser 2",
"Dispenser 3",
"Dispenser 4",
"Dispenser 5",
"Dispenser 6",
"Dispenser 7",
"Dispenser 8",
"Screw ",
"Winder ",
"Left Dancer ",
"Middle Dancer",
"Left Driving ",
"Left Rockers ",
"Left pivot ",
"Right Dancer ",
"Right Driving",
"Right Loadarm",
"Right Rockers",
"Spare1 1",
"Spare1 2",
"Spare2 1",
"Spare2 2",
"Spare3 1"};
//#define NUM_OF_MOTORS (HARDWARE_MOTOR_TYPE__MOTO_RLOADING + 1) // TODO After the integration with mulbery change to:
#define NUM_OF_MOTORS HARDWARE_MOTOR_TYPE__MOTO_SPARE2_2+1
#define MINIMAL_MOTOR_SPEED 0.2
//typedef enum
//{
// SetSpeed,
// SetPosition,
// SetHardStop,
// SetSoftStop,
// SetHardStopHiz,
// SetSoftStopHiz,
// GetSpeed,
// GetPosition,
// GetStatus,
//
//}MotorCommand_t;
//typedef struct
//{
// TimerMotors_t id;
// uint32_t minfreq;
// uint32_t maxfreq;
// uint32_t minmicrostep;
// uint32_t maxmicrostep;
// double changeslope;
// double hightimeoutusec;
//}MotorDriverConfigStruc;
typedef struct
{
HardwareMotorType hardwaremotortype;
int32_t minfrequency;
int32_t maxfrequency;
int32_t setmicrostep;
int32_t microstep;
double maxchangeslope;
double highlengthmicrosecond;
bool speedmaster;
int32_t pulseperround;
double pulleyradius;
int32_t configword;
bool directionthreadwize;
int32_t kvalhold;
int32_t kvalrun;
int32_t kvalacc;
int32_t kvaldec;
int32_t overcurrentthreshold;
int32_t stallthreshold;
int32_t thermalcompensationfactor;
bool lowspeedoptimization;
int32_t stslp;
int32_t intspd;
int32_t fnslpacc;
int32_t fnslpdec;
int32_t fsspd;
uint32_t gatecfg1;
uint32_t gatecfg2;
uint32_t tvalhold;
uint32_t tvalrun;
uint32_t tvalacc;
uint32_t tvaldec;
uint32_t tfast;
uint32_t tonmin;
uint32_t toffmin;
bool has_p01configword;//needed for backward compatibility
uint32_t p01configword;
}MotorDriverConfigStruc;
//#define MotorDriverConfigStruc HardwareMotor
typedef struct
{
bool Direction;
//uint32_t Command_Mode;
uint32_t Speed;
uint32_t Position;
uint8_t Stop;
uint8_t KvalHold;
uint8_t KvalRun;
uint8_t KvalAcc;
uint8_t KvalDec;
uint8_t TvalHold;
uint8_t TvalRun;
uint8_t TvalAcc;
uint8_t TvalDec;
int32_t microstep;
uint8_t ocd_th;
}MotorDriverRequestStruct;
typedef struct
{
bool Direction;
float Speed;
uint32_t Position;
uint32_t Status;
uint8_t MicroSteps;
uint32_t ADC; //read the Adc in order to know the motor driver type L6470/ L6472 / powerSTEP01
MOTDRIVER_TYPE DriverType; //current or voltage mode
MOTDRIVER_MODE DriverMode; //current or voltage mode in powerSTEP01
bool Busy;
}MotorDriverResponseStruct;
// PowerStep Status register
typedef union
{
struct
{
bool HiZ : 1; //0
bool Busy : 1; //1
bool SW_F : 1; //2
bool SW_EVN : 1; //3
bool DIR : 1; //4
unsigned short MOT_STATUS : 2; //5-6
bool CMD_ERROR : 1; //7
bool STCK_MOD : 1; //8
bool UVLO_ActiveLow : 1; //9
bool UVLO_ADC_ActiveLow : 1; //10
unsigned short TH_STATUS : 2; //11-12
bool OCD_ActiveLow : 1; //13
bool STALL_B_ActiveLow : 1; //14
bool STALL_A_ActiveLow : 1; //15
}bits;
unsigned short Reg;
}POWERSTEP01_STATUS;
POWERSTEP01_STATUS PStep01Status[NUM_OF_MOTORS];
// L6470 Status register
typedef union
{
struct
{
bool HiZ : 1; //0
bool Busy : 1; //1
bool SW_F : 1; //2
bool SW_EVN : 1; //3
bool DIR : 1; //4
unsigned short MOT_STATUS : 2; //5-6
bool NOTPERF_CMD : 1; //7
bool WRONG_CMD : 1; //8
bool UVLO_ActiveLow : 1; //9
bool TH_WRN_ActiveLow : 1; //10
bool TH_SD_ActiveLow : 1; //11
bool OCD_ActiveLow : 1; //12
bool STEP_LOSS_A_ActiveLow : 1; //13
bool STEP_LOSS_B_ActiveLow : 1; //14
bool SCK_MOD : 1; //15
}bits;
unsigned short Reg;
}L6470_STATUS;
L6470_STATUS VolMotDriverStatus[NUM_OF_MOTORS];
// L6472 Status register
typedef union
{
struct
{
bool HiZ : 1; //0
bool Busy : 1; //1
bool SW_F : 1; //2
bool SW_EVN : 1; //3
bool DIR : 1; //4
unsigned short MOT_STATUS : 2; //5-6
bool NOTPERF_CMD : 1; //7
bool WRONG_CMD : 1; //8
bool UVLO_ActiveLow : 1; //9
bool TH_WRN : 1; //10
bool TH_SD_ActiveLow : 1; //11
bool OCD_ActiveLow : 1; //12
bool X_Bit_13 : 1; //13
bool X_Bit_14 : 1; //14
bool SCK_MOD : 1; //15
}bits;
unsigned short Reg;
}L6472_STATUS;
L6472_STATUS CurMotDriverStatus[NUM_OF_MOTORS];
extern MotorDriverRequestStruct MotorDriverRequest[NUM_OF_MOTORS];
extern MotorDriverResponseStruct MotorDriverResponse[NUM_OF_MOTORS];
extern MotorDriverConfigStruc MotorsCfg[NUM_OF_MOTORS];
//initialize general motors driver database
uint32_t MotorsInit(void);
//set the motor configuration
uint32_t MotorConfig(TimerMotors_t _motorId, MotorDriverConfigStruc *MotorConfig);
uint32_t Motor_ReconfigAllMotors(void);
bool isMotorConfigured(TimerMotors_t _motorId);
TimerMotors_t getMotorId(int FastMotorId);
uint32_t MotorGetDirection(TimerMotors_t _motorId);
uint32_t MotorSetDirection(TimerMotors_t _motorId,bool _direction);
uint32_t MotorSetSpeed(TimerMotors_t _motorId, float _freq);
uint32_t MotorSetSpeedDirect(TimerMotors_t _motorId, float _freq); // call directly and not from millisec task
uint32_t MotorSetMaxSpeed(TimerMotors_t _motorId, uint32_t MaxSpeed);
uint32_t MotorSetMicroStep(TimerMotors_t _motorId, uint32_t microstep);
float MotorGetSpeed(TimerMotors_t _motorId);
uint32_t MotorGetADC(TimerMotors_t _motorId);
uint32_t MotorGetPosition(TimerMotors_t _motorId);
uint32_t MotorGetPositionFromFPGA(TimerMotors_t _motorId);
uint32_t MotorGetPositionFromFPGA_Callback(TimerMotors_t _motorId,uint32_t Data);
//uint32_t MotorGetPositionFromFPGA_Res(TimerMotors_t _motorId);
uint32_t MotorGetSpeedFromFPGA(TimerMotors_t _motorId);
float MotorGetSpeedFromFPGA_Res(TimerMotors_t _motorId);
uint32_t MotorGetSpeedFromFPGA1(TimerMotors_t _motorId);
float MotorGetSpeedFromFPGA_Callback(TimerMotors_t _motorId,uint32_t Data);
uint32_t MotorGetADCFromFPGA(TimerMotors_t _motorId);
uint32_t MotorGetADCFromFPGA_Res(TimerMotors_t _motorId);
uint32_t MotorGetStatusFromFPGA(TimerMotors_t _motorId);
uint32_t MotorGetStatusFromFPGA_Callback(TimerMotors_t _motorId,uint32_t Data);
uint32_t MotorGetStatus(TimerMotors_t _motorId);
uint8_t MotorGetMicroSteps(TimerMotors_t _motorId);
uint8_t MotorGetMicroStepsFromFPGA(TimerMotors_t _motorId);
uint32_t MotorGetnBusyFromFPGA(void); // get all motors nBusy bit status from the FPGAs
bool MotorGetnBusyState(TimerMotors_t _motorId);
int MotorGetFPGAResponse(TimerMotors_t MotorId,uint32_t *Data); //returns -1 on busy or other error
int MotorSendFPGARequest(TimerMotors_t MotorId,uint32_t Data,uint32_t Length); //returns -1 on busy or other error
/*
* Stop Command
* 1 - Hard_Stop/ 2 - Soft_Stop/ 3 - Hard_Hiz/ 4 - Soft_Hiz
*/
typedef enum
{
Hard_Stop,
Soft_Stop,
Hard_Hiz,
Soft_Hiz,
}STOP_TYPE_ENUM;
extern int32_t AccumulatedArmMovement;
uint32_t MotorStop(TimerMotors_t _motorId, STOP_TYPE_ENUM StopType);
uint32_t MotorMove(TimerMotors_t _motorId,bool direction, uint32_t Steps);
uint32_t MotorMoveWithCallback (TimerMotors_t _motorId,bool direction, uint32_t Steps, callback_fptr callback,uint32_t timeout);
uint32_t MotorRunWithCallback (TimerMotors_t MotorId,bool direction, uint32_t Freq, callback_fptr callback,uint32_t timeout);
uint32_t MotorGotoWithCallback (TimerMotors_t MotorId, uint32_t Steps, uint32_t LimitSwitchId,callback_fptr callback,uint32_t timeout); //TODO
uint32_t MotorGotoWithBusyCallback (TimerMotors_t MotorId,bool direction, uint32_t Steps, callback_fptr callback,uint32_t timeout); //TODO
uint32_t MotorGoToDir(TimerMotors_t _motorId,bool direction, uint32_t Steps);
bool MotorControlGetnBusyState(uint32_t _motorId, uint32_t parameter);
uint32_t MotorSetSpeedWithCallback (TimerMotors_t _motorId, uint32_t _freq, callback_fptr callback);
uint32_t SetMotHome(TimerMotors_t _motorId);
uint32_t MotorSetKvalHold(TimerMotors_t _motorId, uint8_t Value);
uint32_t MotorSetKvalRun(TimerMotors_t _motorId, uint8_t Value);
uint32_t MotorSetKvalAcc(TimerMotors_t _motorId, uint8_t Value);
uint32_t MotorSetKvalDec(TimerMotors_t _motorId, uint8_t Value);
void MotorActionsInit(void);
uint32_t MotorGetOverHeatStatus(TimerMotors_t _motorId);
uint32_t MotorGetStallStatus(TimerMotors_t _motorId);
uint32_t MotorGetUnderVoltageStatus(TimerMotors_t _motorId);
uint32_t MotorGetOverCurrentStatus(TimerMotors_t _motorId);
uint32_t MotorGetStatus(TimerMotors_t _motorId);
uint32_t MotorGetStatusFromFPGA_Callback(TimerMotors_t _motorId,uint32_t Data);
typedef enum {
MotorHomingDirectionUp,
MotorHomingDirectionDown,
MotorHomingDirectionNoHoming
}MotorHomingDirectionEnum;
extern FPGA_GPI_ENUM Motor_Id_to_LS_IdDown[NUM_OF_MOTORS];
extern FPGA_GPI_ENUM Motor_Id_to_LS_IdUp[NUM_OF_MOTORS];
extern MotorHomingDirectionEnum Motor_Id_to_LS_Direction[NUM_OF_MOTORS];
uint32_t MotorMovetoLimitSwitch (TimerMotors_t _motorId,bool direction, uint32_t Freq, uint32_t LimitSwitchId, callback_fptr callback,uint32_t timeout);
uint32_t MotorMovetoBreakSensor (TimerMotors_t _motorId,bool direction, uint32_t Freq, callback_fptr callback,uint32_t timeout);
uint32_t MotorMovetoDancerPosition (TimerMotors_t _motorId,bool direction, uint32_t Freq,uint32_t DancerId,bool dancervaluedirection, callback_fptr callback,uint32_t timeout);
uint32_t MotorAbortMovetoLimitSwitch (TimerMotors_t _motorId);
uint32_t MotorMoveToStopper (TimerMotors_t _motorId,bool direction, uint32_t Speed, callback_fptr callback,uint32_t backlash,uint32_t timeout);
uint32_t MotorMovetoEncoderPosition (TimerMotors_t MotorId, callback_fptr callback,uint32_t timeout, bool direction,uint32_t speed);
uint32_t LoadingArmReset (callback_fptr callback,uint32_t timeout);
uint32_t LoadingStopArmReset (void);
float Calculate_Arm_Angle(uint32_t Drier_Center,uint32_t Current_Angle);
int Calculate_Arm_Distance(uint32_t Drier_Center,uint32_t Current_Angle);
uint32_t MotorStopAction (TimerMotors_t MotorId); //Stop the controlled action of a motor
uint32_t MotorGoTo(TimerMotors_t _motorIdn, uint32_t Steps);
void Combined_Motor_Driver_Mode(TimerMotors_t _motorId, MOTDRIVER_MODE New_Mode);// New_mode: Current or Voltage
void Combined_dispenser_Driver_Mode(uint8_t Dispenser_ID, MOTDRIVER_MODE New_Mode);// New_mode: Current or Voltage
uint32_t MotorGetMicroStepsFromFPGA_Res(TimerMotors_t _motorId);
void test_Home_Pos();
#endif /* DRIVERS_MOTOR_H_ */
|