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
|
/************************************************************************************************************************
* Ids_maint.c
* Printing module is responsible for :
* operating the dispensers according to predefined dispensing rate from the UI
**************************************************************************************************************************/
#include "include.h"
#include "ids.h"
#include "ids_ex.h"
#include "../control/control.h"
#include "../control/pidalgo.h"
#include "../thread/thread.h"
#include "PMR/Hardware/Hardwaremotor.pb-c.h"
#include "PMR/Hardware/HardwareDispenser.pb-c.h"
#include "StateMachines/Printing/printingSTM.h"
#include "drivers/FPGA/FPGA_GPIO/FPGA_GPIO.h"
#include "drivers/Motors/Motor.h"
#include "drivers/Valves/Valve.h"
FPGA_GPI_ENUM Dispenser_Id_to_LS_Id[MAX_SYSTEM_DISPENSERS] = {
GPI_LS_DISPENSER_DOWN_1, //MOTO_DISPENSER_1 = 6,
GPI_LS_DISPENSER_DOWN_2, //MOTO_DISPENSER_2 = 7,
GPI_LS_DISPENSER_DOWN_3, //MOTO_DISPENSER_3 = 8,
GPI_LS_DISPENSER_DOWN_4, //MOTO_DISPENSER_4 = 9,
GPI_LS_DISPENSER_DOWN_5, //MOTO_DISPENSER_5 = 10,
GPI_LS_DISPENSER_DOWN_6, //MOTO_DISPENSER_6 = 11,
GPI_LS_DISPENSER_DOWN_7, //MOTO_DISPENSER_7 = 12,
GPI_LS_DISPENSER_DOWN_8, //MOTO_DISPENSER_8 = 13,
};
FPGA_GPI_ENUM Dispenser_Id_to_Alarm_LS_Id[MAX_SYSTEM_DISPENSERS*2] = {
GPI_LS_DISPENSER_UP_1, //MOTO_DISPENSER_1 = 6,
GPI_LS_DISPENSER_UP_2, //MOTO_DISPENSER_2 = 7,
GPI_LS_DISPENSER_UP_3, //MOTO_DISPENSER_3 = 8,
GPI_LS_DISPENSER_UP_4, //MOTO_DISPENSER_4 = 9,
GPI_LS_DISPENSER_UP_5, //MOTO_DISPENSER_5 = 10,
GPI_LS_DISPENSER_UP_6, //MOTO_DISPENSER_6 = 11,
GPI_LS_DISPENSER_UP_7, //MOTO_DISPENSER_7 = 12,
GPI_LS_DISPENSER_UP_8, //MOTO_DISPENSER_8 = 13,
GPI_LS_DISPENSER_25_1, //MOTO_DISPENSER_1 = 6,
GPI_LS_DISPENSER_25_2, //MOTO_DISPENSER_2 = 7,
GPI_LS_DISPENSER_25_3, //MOTO_DISPENSER_3 = 8,
GPI_LS_DISPENSER_25_4, //MOTO_DISPENSER_4 = 9,
GPI_LS_DISPENSER_25_5, //MOTO_DISPENSER_5 = 10,
GPI_LS_DISPENSER_25_6, //MOTO_DISPENSER_6 = 11,
GPI_LS_DISPENSER_25_7, //MOTO_DISPENSER_7 = 12,
GPI_LS_DISPENSER_25_8, //MOTO_DISPENSER_8 = 13,
};
callback_fptr HomingRequestCallback[MAX_SYSTEM_DISPENSERS]={0,0,0,0,0,0,0,0};
bool HomingActive[MAX_SYSTEM_DISPENSERS] = {false,false,false,false,false,false,false,false};
uint32_t IDS_HomeDispenserCallback(uint32_t deviceID, uint32_t ReadValue)
{
uint8_t DispenserId = deviceID-HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_1;
//close dry air valve in the dispenser
Valve_Set(IDS_Id_to_AirValve[DispenserId], Atm_MidTank_OFF);
MotorSetMicroStep(deviceID, MotorsCfg[deviceID].microstep);
if (HomingRequestCallback[DispenserId])
{
HomingRequestCallback[DispenserId](DispenserId,0);
HomingRequestCallback[DispenserId] = NULL;
}
HomingActive[DispenserId]= false;
return OK;
}
uint32_t IDS_HomeDispenser (uint32_t deviceID, uint32_t speed , callback_fptr callback)
{
assert(deviceID < MAX_SYSTEM_DISPENSERS);
if (HomingActive[deviceID] == true)
return ERROR;
else
HomingActive[deviceID] = true;
HomingRequestCallback[deviceID] = callback;
TimerMotors_t MotorId = HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_1 + deviceID;
if ( Dispenser_Id_to_LS_Id[deviceID] != MAX_GPI)
{
//open dispenser valve dispenser to midtank direction
Control3WayValvesWithCallback ((Valves_t)deviceID, MidTank_Dispenser, NULL); //direction: MidTank_Dispenser or Dispenser_Mixer
//Valve_Set((Valves_t) request->index, MidTank_Dispenser);
MotorSetMicroStep(deviceID, 1);
//open dry air valve in the dispenser
Valve_Set(IDS_Id_to_AirValve[deviceID], Atm_MidTank_ON);
MotorMovetoLimitSwitch (MotorId,1-MotorsCfg[MotorId].directionthreadwize, speed, Dispenser_Id_to_LS_Id[deviceID], IDS_HomeDispenserCallback);
return OK;
}
return ERROR;
}
uint32_t IDS_StopHomeDispenser (uint32_t deviceID)
{
assert(deviceID < MAX_SYSTEM_DISPENSERS);
if (HomingActive[deviceID] != true)
return ERROR;
else
HomingActive[deviceID] = false;
TimerMotors_t MotorId = (deviceID)+HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_1;
MotorAbortMovetoLimitSwitch(MotorId);
//close dry air valve in the dispenser
Valve_Set(IDS_Id_to_AirValve[deviceID], Atm_MidTank_OFF);
MotorSetMicroStep(deviceID, MotorsCfg[deviceID].microstep);
return OK;
}
uint32_t IDS_CheckDispenserLimitSwitch (LimitSwitchAlarms LS_Id)
{
int DispenserId;
if (LS_Id <= LimitSwitchAlarmEmpty_8)
{
DispenserId = LS_Id;
}
else
{
DispenserId = LS_Id-LimitSwitchAlarmEmpty_8;
}
if (isMotorConfigured(DispenserId + HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_1)==false)
return true; //false is the alarm value
else
return FPGA_Read_limit_Switches(Dispenser_Id_to_Alarm_LS_Id[LS_Id]);
}
|