LabelMachine.cs
9.2 KB
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
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public partial class LabelMachine : MachineBase, IRobot
{
private Config_Label _config;
public new Config_Label Config
{
get => _config; set
{
base.Config = value;
_config = value;
}
}
public override string DeviceName { get; set; } = "贴标机构";
public bool canRunning { get; set; }
public bool isBusy { get; set; }
public bool isAlarm { get; set; }
//public RunStatus runStatus { get; set; }
//public bool UserPause { get; set; }
public bool IgnoreSafecheck { get; set; }
public bool IgnoreGratingSignal { get; set; }
AxisBean Label_X_Axis;
AxisBean Label_Y_Axis;
AxisBean Label_Z_Axis;
AxisBean Label_R_Axis;
public bool Init(out string msg)
{
msg = "";
try
{
string configFile = "config\\LabelConfig.csv";
Config = new Config_Label(0, "", configFile);
Config = (Config_Label)CSVConfigReader.LoadConfig<IO_Label_Type>(Config);
#region 初始化伺服轴
Label_X_Axis = new AxisBean(Config.Label_X_Axis, DeviceName);
Label_Y_Axis = new AxisBean(Config.Label_Y_Axis, DeviceName);
Label_Z_Axis = new AxisBean(Config.Label_Z_Axis, DeviceName);
Label_R_Axis = new AxisBean(Config.Label_R_Axis, DeviceName);
#endregion
MoveInfo = new MoveInfo(DeviceName);
ResetMoveInfo = MoveInfo;
LedProcessInit();
}
catch (Exception e)
{
msg = e.Message;
return false;
}
return true;
}
public override void Run()
{
base.Run();
IOMove(IO_Label_Type.Camera_Led, IO_VALUE.HIGH);
}
public override void Stop()
{
IOMove(IO_Label_Type.Camera_Led, IO_VALUE.LOW);
base.Stop();
}
protected override void LoopProcess()
{
mstart = true;
while (mstart)
{
try
{
canRunning = DeviceCheck();
if (canRunning)
{
//BtnProcess();
canRunning = SafeCheck();
}
Thread.Sleep(stepDelaytime);
if (!canRunning || !mstart)
continue;
if (runStatus == RunStatus.Running)
{
//IOMonitor();
WorkProcess();
}
else if (runStatus == RunStatus.HomeReset)
{
HomeReset();
}
}
catch (Exception ex)
{
Msg.add(ex.Message, MsgLevel.warning);
LogUtil.error(DeviceName + " " + ex.ToString());
Thread.Sleep(stepDelaytime*5);
}
finally
{
ProcessMsgEventFire(Msg);
//ProcessMoveinfoEventFire(MoveInfo.List);
Msg.Clear();
}
}
LogUtil.info($"{DeviceName} 主线程已退出.");
}
public bool DeviceCheck()
{
bool ok = true;
if (IOValue(IO_Label_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
{
Alarm(AlarmType.SuddenStop);
Msg.add("急停中", MsgLevel.warning);
ok = false;
}
else if (alarmType == AlarmType.SuddenStop)
{
Msg.add("系统需要重置", MsgLevel.warning);
ok = false;
}
if (alarmType != AlarmType.SuddenStop)
{
TimeSpan span = DateTime.Now - checkAlarmTime;
//在回原点,复位,出入库时,检测报警间隔减小
if ((!runStatus.Equals(RunStatus.Stop) && span.TotalSeconds > 3) || span.TotalSeconds > 1)
{
if (Config.moveAxisList != null)
{
foreach (ConfigMoveAxis configMoveAxis in Config.moveAxisList)
{
if (AxisManager.GetAlarmStatus(configMoveAxis.DeviceName, configMoveAxis.GetAxisValue()) == 1)
{
Msg.add($"{configMoveAxis.Explain}:运动报警", MsgLevel.warning);
ok = false;
}
}
}
}
}
return ok;
}
public void BeginHomeReset(bool firstRun = false)
{
if (!firstRun)
{
StopMove();
Thread.Sleep(500);
}
OpenAllServo();
alarmType = AlarmType.None;
runStatus = RunStatus.HomeReset;
ResetMoveInfo.NewMove(MoveStep.H01_HomeReset);
ResetMoveInfo.log("开始回原");
ResetMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
}
private void HomeReset()
{
if (CheckWait(ResetMoveInfo))
return;
switch (ResetMoveInfo.MoveStep)
{
case MoveStep.H01_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H02_HomeReset);
ResetMoveInfo.log("正在回原, 皮带线阻挡上升,贴标机构阻挡上升,z轴");
CylinderMove(ResetMoveInfo, IO_Label_Type.TrayStop_Down, IO_Label_Type.TrayStop_Up);
CylinderMove(ResetMoveInfo, IO_Label_Type.Label_Stop_Down, IO_Label_Type.Label_Stop_Up);
Label_Z_Axis.HomeMove(ResetMoveInfo);
break;
case MoveStep.H02_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H03_HomeReset);
ResetMoveInfo.log("正在回原 y轴");
IOMove(IO_Label_Type.Line1_Run, IO_VALUE.HIGH);
IOMove(IO_Label_Type.Line2_Run, IO_VALUE.HIGH);
Label_X_Axis.HomeMove(ResetMoveInfo);
break;
case MoveStep.H03_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H04_HomeReset);
ResetMoveInfo.log("正在回原 xyzr轴");
Label_R_Axis.HomeMove(ResetMoveInfo);
Label_Y_Axis.HomeMove(ResetMoveInfo);
break;
case MoveStep.H04_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H05_HomeReset);
ResetMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
break;
case MoveStep.H05_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H06_HomeReset);
ResetMoveInfo.log("正在回原 等待2秒钟");
Label_Y_Axis.AbsMove(ResetMoveInfo, Config.Label_Y_P2, Config.Label_Y_P2_speed);
Label_X_Axis.AbsMove(ResetMoveInfo, Config.Label_X_P2, Config.Label_X_P2_speed);
Label_R_Axis.AbsMove(ResetMoveInfo, Config.Label_R_P2, Config.Label_R_P2_speed);
ResetMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
break;
case MoveStep.H06_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H07_HomeReset);
ResetMoveInfo.log("正在回原 xyzr轴到待机点");
Label_Z_Axis.AbsMove(ResetMoveInfo, Config.Label_Z_P1, Config.Label_Z_P1_speed);
break;
case MoveStep.H07_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.HEND_HomeReset);
ResetMoveInfo.log("正在回原 线体停止,阻挡下降");
IOMove(IO_Label_Type.Line1_Run, IO_VALUE.LOW);
IOMove(IO_Label_Type.Line2_Run, IO_VALUE.LOW);
CylinderMove(ResetMoveInfo, IO_Label_Type.TrayStop_Up, IO_Label_Type.TrayStop_Down);
CylinderMove(ResetMoveInfo, IO_Label_Type.Label_Stop_Up, IO_Label_Type.Label_Stop_Down);
break;
case MoveStep.HEND_HomeReset:
ResetMoveInfo.log("回源完成");
ResetMoveInfo.EndMove();
MoveInfo.NewMove(MoveStep.Lbl_01_Wait_ATray);
runStatus = RunStatus.Running;
break;
}
}
public IO_VALUE Label_TaryStop_Check
{
get => IOValue(IO_Label_Type.Label_TaryStop_Check);
}
public void InLineRunControl(IO_VALUE iO_VALUE)
{
IOMove(IO_Label_Type.Line1_Run, iO_VALUE);
}
}
}