InletEquip_InStore.cs
13.3 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
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
using Asa;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
partial class InletEquip
{
/// <summary>
/// 等待机器人在安全位置
/// </summary>
/// <param name="moveInfo"></param>
/// <param name="wait"></param>
/// <returns></returns>
protected override bool CheckWaitResult(DeviceMoveInfo moveInfo, WaitResultInfo wait)
{
if (wait.WaitType.Equals(WaitEnum.W102_FeedScanCode))
{
if (LastCodeList.Count > 0)
{
wait.IsEnd = true;
}
}
else if (wait.WaitType.Equals(WaitEnum.W201_RobotMove))
{
if (StoreManager.Client.robotEquip.RobotMoveEnd(curcmd))
{
wait.IsEnd = true;
}
}
return wait.IsEnd;
}
/// <summary>
/// 当前命令
/// </summary>
private string curcmd = "";
private List<string> LastCodeList = new List<string>();
#region 自动入料
private DateTime startInTime = DateTime.Now;
public override bool StartInstore(InOutParam param)
{
if (!NoAlarm())
{
LogInfo("报警中,无法开始自动入料:" + param.PosInfo.ToStr());
return false;
}
if (MoveInfo.MoveType.Equals(MoveType.None))
{
runStatus = RunStatus.Busy;
MoveInfo.NewMove(MoveType.InStore, param);
startInTime = DateTime.Now;
{
MoveInfo.NextMoveStep(StepEnum.Inlet_01_Wait);
MoveLog($"开始入料{MoveInfo.SLog}");
}
return true;
}
return false;
}
private void NextMoveStep(StepEnum step, string msg)
{
MoveInfo.NextMoveStep(step);
MoveLog($" {MoveInfo.SLog}:{msg}");
}
InOutPosInfo lastPosInfo = new InOutPosInfo();
Task getTrayInfoTask = null;
Task getTargetInfoTask = null;
protected override void InstoreProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait(MoveInfo);
}
if (MoveInfo.IsInWait)
{
return;
}
if (MoveInfo.IsStep(StepEnum.Inlet_01_Wait))
{
NextMoveStep(StepEnum.Inlet_02_CheckTray, "检查是否有料盘");
}
else if (MoveInfo.IsStep(StepEnum.Inlet_02_CheckTray))
{
if (HasTrayInPosition())
{
NextMoveStep(StepEnum.Inlet_05_GetTrayInfo, "有料盘,扫码,准备获取料盘信息");
AllowFeedIn(false);
Inlet_05_GetTrayInfo();
}
else//无料盘
{
NextMoveStep(StepEnum.Inlet_03_AllowFeedIn, "无料盘,允许料盘进入,链条运行");
AllowFeedIn(true);
InletRun(true);
AddWaitTrayInPosition(true);
AddWaitTime(5000);
}
}
else if (MoveInfo.IsStep(StepEnum.Inlet_03_AllowFeedIn))
{
NextMoveStep(StepEnum.Inlet_04_TrayInPosition, "料盘到位,拒绝料盘进入,链条停止");
AllowFeedIn(false);
InletRun(false);
}
else if (MoveInfo.IsStep(StepEnum.Inlet_04_TrayInPosition))
{
NextMoveStep(StepEnum.Inlet_05_GetTrayInfo, "料盘已到位,扫码,准备获取料盘信息");
Inlet_05_GetTrayInfo();
}
else if (MoveInfo.IsStep(StepEnum.Inlet_05_GetTrayInfo))
{
if (getTrayInfoTask != null && getTrayInfoTask.IsCompleted)
{
NextMoveStep(StepEnum.Inlet_06_JackUp, "获取料盘信息完成,顶升抬起");
Inlet_06_JackUp();
}
}
else if (MoveInfo.IsStep(StepEnum.Inlet_06_JackUp))
{
if (MoveInfo.MoveParam.PosInfo.IsNG)
{
NextMoveStep(StepEnum.Inlet_08_WaitTrayLeave, "条码NG,等待料盘离开");
AddWaitTrayInPosition(false);
SetCurCmd(RobotEquip.GetCmd_InletUp());
}
else
{
NextMoveStep(StepEnum.Inlet_07_GetTargetInfo, "从服务器获取入库库位");
GetTargetInfo();
}
}
else if (MoveInfo.IsStep(StepEnum.Inlet_07_GetTargetInfo))
{
if (getTargetInfoTask != null && getTargetInfoTask.IsCompleted && lastPosInfo != null)
{
getPosIdMsg = "";
ClearTimeoutAlarm("获取库位号超时");
//InOutPosInfo oldPos = MoveInfo.MoveParam.PosInfo;
//if ((!LastPosInfo.PlateH.Equals(oldPos.PlateH)) || (!LastPosInfo.PlateW.Equals(oldPos.PlateW)))
//{
// MoveLog(" " + MoveInfo.SLog + " 原有料盘尺寸:【" + oldPos.PlateW + "X" + oldPos.PlateH + "】服务器返回尺寸【" + LastPosInfo.PlateW + "X" + LastPosInfo.PlateH + "】 ");
//}
MoveInfo.MoveParam.PosInfo = lastPosInfo;
NextMoveStep(StepEnum.Inlet_08_WaitTrayLeave, $"获取目标仓位成功【{MoveInfo.MoveParam.PosInfo.ToStr()}】,等待料盘离开");
BufferDataManager.TrayInInletInfo = MoveInfo.MoveParam.PosInfo.ToCopy();
AddWaitTrayInPosition(false);
SetCurCmd(RobotEquip.GetCmd_InletUp());
}
else if (MoveInfo.IsTimeOut(15))
{
MoveTimeOut(MoveInfo, "获取库位号超时 " + getPosIdMsg);
}
}
else if (MoveInfo.IsStep(StepEnum.Inlet_08_WaitTrayLeave))
{
NextMoveStep(StepEnum.Inlet_09_WaitRobotInSafe, "料盘离开入料口,等待机器人到安全位置");
SetCurCmd(RobotEquip.GetCmd_Standby());
AddWaitTime(10000);
MoveInfo.OneWaitCanEndStep=true;
}
else if (MoveInfo.IsStep(StepEnum.Inlet_09_WaitRobotInSafe))
{
NextMoveStep(StepEnum.Inlet_10_JackDown, "机器人到达安全位置,顶升下降");
Inlet_10_JackDown();
}
else if (MoveInfo.IsStep(StepEnum.Inlet_10_JackDown))
{
curcmd = "";
MoveInfo.EndMove();
}
}
#endregion
private void SetCurCmd(string cmd)
{
curcmd = cmd;
MoveInfo.WaitList.Add(WaitResultInfo.WaitRobotMove());
}
private void Inlet_05_GetTrayInfo()
{
bool isScan = ConfigAppSettings.GetIntValue(Setting_Init.NeedScanCode).Equals(1);
LastCodeList = new List<string>();
getTrayInfoTask = Task.Factory.StartNew(() =>
{
if (isScan)
{
MoveInfo.OneWaitCanEndStep = true;
MoveInfo.WaitList.Add(WaitResultInfo.WaitFeedScanCode());
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(6000));
try
{
IOMove(IO_Type.Inlet_CamLed, IO_VALUE.HIGH);
LastCodeList = CodeManager.CameraScan(Config.ScanCodeCamera, Name);
if (LastCodeList.Count <= 0)
{
LastCodeList = CodeManager.CameraScan(Config.ScanCodeCamera, Name);
}
}
catch (Exception ex)
{
LogUtil.error("扫码出错", ex);
}
finally
{
IOMove(IO_Type.Inlet_CamLed, IO_VALUE.LOW);
}
}
string code = CodeManager.ProcessCode(LastCodeList);
MoveInfo.MoveParam.PosInfo.barcode = code;
if (string.IsNullOrEmpty(code))
{
MoveInfo.MoveParam.PosInfo.IsNG = true;
MoveInfo.MoveParam.PosInfo.NgMsg = "无有效条码NG";
}
//获取料盘宽度
MoveInfo.MoveParam.PosInfo.PlateW = GetWidth();
//获取厚度
MoveInfo.MoveParam.PosInfo.PlateH = GetHeight();
//扫码
});
AddWaitTime(3000);
}
private int GetWidth()
{
int width = 7;
double val = IOManager.GetADVal(0) * Config.Coeff_Width;
if (Math.Abs(val - 7) < Math.Abs(val - 13))
return width;
else
return 13;
}
private int GetHeight()
{
int height = 8;
return height;
}
private int LastResult = 0;
private string getPosIdMsg = "";
private void GetTargetInfo()
{
InOutPosInfo pos = MoveInfo.MoveParam.PosInfo;
lastPosInfo = null;
List<string> codeList = Regex.Split(pos.barcode, "##", RegexOptions.IgnoreCase).ToList();
getTargetInfoTask = Task.Factory.StartNew(() =>
{
//更新托盘条码信息
try
{
int count = 1;
while (MoveInfo.MoveType.Equals(MoveType.InStore))
{
int ms = 5000;
string lastPosId = "";
//从服务器获取库位号
GetPosResult result = SServerManager.GetPosId(Name, codeList, pos.PlateH, pos.PlateW, pos.rfid, lastPosId);
LastResult = result.Result;
if (result.IsTimeOut)
{
if (count < 5)
{
ms = 2000;
}
Thread.Sleep(ms);
LogUtil.error(Name + "【" + pos.barcode + "】第[" + count + "]次 " + MoveInfo.SLog + " 超时,等待" + ms + "后重新获取");
}
else if (result.Result.Equals(99) || result.Result.Equals(100))
{
if (count < 5)
{
ms = 3000;
}
getPosIdMsg = result.Msg;
Thread.Sleep(ms);
LogUtil.error(Name + "【" + pos.barcode + "】第[" + count + "]次 " + MoveInfo.SLog + " 结果【" + result.Result + "】,等待" + ms + "后重新获取");
}
else if (!result.Result.Equals(0))
{
lastPosInfo = result.Param;
LogUtil.error(Name + "【" + pos.barcode + "】第[" + count + "]次 " + MoveInfo.SLog + " 入库NG:" + result.Msg);
break;
}
else
{
lastPosInfo = result.Param;
break;
}
if (count >= 3)
{
//自动NG
lastPosInfo = new InOutPosInfo(pos.barcode, "", MoveInfo.MoveParam.PosInfo.PlateW, MoveInfo.MoveParam.PosInfo.PlateH);
lastPosInfo.IsNG = true;
lastPosInfo.NgMsg = "获取库位超过三次,直接NG";
break;
}
count++;
}
}
catch (Exception ex)
{
LogUtil.error(Name + "【" + pos.barcode + "】 " + MoveInfo.SLog + " 获取库位号报错:" + ex.ToString());
}
});
}
/// <summary>
/// 入料线体是否有料盘
/// </summary>
/// <returns></returns>
public bool HasTrayInPosition()
{
return IOValue(IO_Type.Inlet_TrayCheck).Equals(IO_VALUE.HIGH);
}
private void Inlet_06_JackUp()
{
if (MoveInfo.MoveParam.PosInfo != null && MoveInfo.MoveParam.PosInfo.PlateW.Equals(7))
{
Inch7JackUp(true);
}
else if (MoveInfo.MoveParam.PosInfo != null && MoveInfo.MoveParam.PosInfo.PlateW.Equals(13))
{
Inch13JackUp(true);
}
}
private void Inlet_10_JackDown()
{
Inch7JackUp(false);
Inch13JackUp(false);
}
}
}