RobotMoveBean.cs
14.0 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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public class RobotMoveBean
{
internal string RobotIp = "";
internal string Name = "";
internal string DI_TrayCheck = "";
internal LineMoveInfo MoveInfo = null;
internal int robotNum = 1;
public string WarnMsg = "";
internal string NeedShelf = "";
internal TrayInfo CurrTray = null;
internal List<string> MyPointList = new List<string>();
public string CurrPoint = "";
public RobotMoveBean(int num, string ip, string name, string traycheck)
{
this.robotNum = num;
MoveInfo = new LineMoveInfo();
this.RobotIp = ip;
this.Name = name;
this.DI_TrayCheck = traycheck;
int smallStart = 1;
int smallEnd = 46;
int bigStart = 1;
int bigEnd = 6;
if (num.Equals(1))
{
smallStart = 47;
smallEnd = 92;
bigStart = 7;
bigEnd = 12;
}
//大料架=C, 小料架=D
for (int s = smallStart; s <= smallEnd; s++)
{
MyPointList.Add("dp" + s);
}
for (int b = bigStart; b <= bigEnd; b++)
{
MyPointList.Add("cp" + b);
}
CurrTray = new TrayInfo();
}
public bool CanChange(string currShelf)
{
if (CurrTray != null)
{
TimeSpan span = DateTime.Now - CurrTray.updateTime;
if (span.TotalSeconds > 5)
{
return true;
}
else if (!CurrTray.realRFID.Equals(currShelf))
{
return true;
}
else if (span.TotalSeconds > 2 && IOManager.IOValue(DI_TrayCheck).Equals(IO_VALUE.LOW))
{
return true;
}
}
else if (IOManager.IOValue(DI_TrayCheck).Equals(IO_VALUE.LOW))
{
return true;
}
return false;
}
public void Reset()
{
LogUtil.info(Name + "复位");
MoveInfo.EndMove();
//判断机器人是否连接,若未连接,直接连接
if (!ABBControl.IsConnected(RobotIp))
{
ABBControl.StartABBControl(RobotIp);
}
WarnMsg = "";
NeedShelf = "";
CurrTray = new TrayInfo();
}
internal void StopMove()
{
LogUtil.info(Name + " Stop Move ");
NeedShelf = "";
MoveInfo.EndMove();
}
// private Stopwatch DiStop = new Stopwatch();
private Stopwatch abbWatch = new Stopwatch();
private string lockTimer = "";
private DateTime warnmsgDatetime = DateTime.Now;
internal void TimerProcess()
{
if (Monitor.TryEnter(lockTimer, 1))
{
try
{
if (LineManager.checkWatch(abbWatch, 3000, true) || WarnMsg.Contains(RobotIp))
{
if (!ABBControl.IsConnected(RobotIp))
{
WarnMsg = Name + "[" + RobotIp + "]未正常连接";
return;
}
else if (WarnMsg.Contains(RobotIp))
{
WarnMsg = "";
}
}
if (!MoveInfo.MoveType.Equals(LineMoveType.None))
{
BusyProcess();
return;
}
else if (IOManager.IOValue(DI_TrayCheck).Equals(IO_VALUE.LOW))
{
CurrPoint = "";
NeedShelf = "";
// DiStop.Stop();
warnmsgDatetime = DateTime.Now;
return;
}
else if (LineManager.Line.S1IsReady())
{
string outMsg = "";
CurrTray = HttpServer.GetDiskInfo(robotNum, LineManager.Line.S1_CurrShelfId, out outMsg);
//需要取放料,且料架已准备好
if (String.IsNullOrEmpty(CurrTray.getP).Equals(false) && outMsg.Equals(""))
{
if (WarnMsg.Contains("getLocation"))
{
WarnMsg = "";
}
// CurrTray = tray;
if (IsRightRfid(LineManager.Line.S1_CurrShelfId, out NeedShelf))
{
//DiStop.Stop();
string pname = "dp";
if (LineManager.Line.S1_CurrShelfId.StartsWith("C"))
{
pname = "cp";
}
CurrPoint = pname + CurrTray.shelfP;
//判断另一个机器人是否干涉
if (LineManager.Line.ABBCanStart(robotNum, MyPointList.Contains(CurrPoint)))
{
if (!CurrTray.realRFID.Equals(LineManager.Line.S1_CurrShelfId) || LineManager.Line.GetXNrfid(LineManager.Line.S1_CurrShelfId).Equals(""))
{
CurrTray.realRFID = LineManager.Line.S1_CurrShelfId;
LineManager.Line.AddRealShelf(CurrTray.realRFID, CurrTray.rfid);
}
//获取成功,开始放料
MoveInfo.NewMove(LineMoveType.PutTray, MoveStep.T01_GetTray);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(100));
LogUtil.info(Name + MoveInfo.SLog + "开始取料【" + CurrPoint + "】" + CurrTray.ToStr() + "");
ABBControl.SendCmd(RobotIp, ABBControl.Cmd_moveget, CurrTray.getP, "L", ABBControl.DefaultSpeed);
}
}
}
else
{
CurrPoint = "";
NeedShelf = "";
if (!outMsg.Equals("") && (DateTime.Now - warnmsgDatetime).TotalSeconds > 30)
{
WarnMsg = " getLocation " + outMsg;
}
else
{
warnmsgDatetime = DateTime.Now;
}
}
}
}
catch (Exception ex)
{
LogUtil.error(Name + "Timer Process Error :" + ex.ToString());
}
//机器人报警
finally { Monitor.Exit(lockTimer); }
}
else
{
LogUtil.error(Name + "TimerProcess 未得到锁 ", robotNum * 100 + 13);
}
}
private void BusyProcess()
{
if (MoveInfo.IsInWait)
{
LineManager.Line.CheckWait(MoveInfo);
}
if (MoveInfo.IsInWait)
{
return;
}
if (MoveInfo.MoveStep.Equals(MoveStep.Wait))
{
MoveInfo.NextMoveStep(MoveStep.T01_GetTray);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(100));
ABBControl.SendCmd(RobotIp, ABBControl.Cmd_moveget, CurrTray.getP, "L", ABBControl.DefaultSpeed);
//putFinTask = null;
}
else if (MoveInfo.MoveStep.Equals(MoveStep.T01_GetTray))
{
if (ABBControl.GetAbbCmd(RobotIp).Equals(""))
{
//判断另一个机器人是否干涉
//if (LineManager.Line.ABBCanStart(robotNum, MyPointList.Contains(CurrPoint)))
{
MoveInfo.NextMoveStep(MoveStep.T02_PutTray);
LogUtil.debug(Name + MoveInfo.SLog + "【" + CurrPoint + "】取料完成,开始放料");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(100));
ABBControl.SendCmd(RobotIp, ABBControl.Cmd_moveput, CurrPoint, "L", ABBControl.DefaultSpeed);
}
}
else if (MoveInfo.IsTimeOut(180))
{
TimeOutAlarm("等待[" + CurrPoint + "]" + CurrTray.ToStr() + " 取料完成");
}
}
else if (MoveInfo.MoveStep.Equals(MoveStep.T02_PutTray))
{
if (ABBControl.GetAbbCmd(RobotIp).Contains(ABBControl.FINISHED))
{
MoveInfo.NextMoveStep(MoveStep.T03_PutFINISHED);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(10000));
LineManager.Line.S1_ShelfTask = HttpServer.ShelfFinish(CurrTray.realRFID, CurrTray.barcode, CurrTray.shelfP.ToString(), robotNum.ToString());
MoveInfo.EndStepWait();
}
else if (ABBControl.GetAbbCmd(RobotIp).Equals(""))
{
MoveInfo.NextMoveStep(MoveStep.T04_WaitEnd);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(10000));
LineManager.Line.S1_ShelfTask = HttpServer.ShelfFinish(CurrTray.realRFID, CurrTray.barcode, CurrTray.shelfP.ToString(), robotNum.ToString());
EndMove();
}
else if (MoveInfo.IsTimeOut(180))
{
TimeOutAlarm("等待[" + CurrPoint + "]" + CurrTray.ToStr() + " FINISHED");
}
}
else if (MoveInfo.MoveStep.Equals(MoveStep.T03_PutFINISHED))
{
if (ABBControl.GetAbbCmd(RobotIp).Equals(""))
{
EndMove();
}
else if (MoveInfo.IsTimeOut(180))
{
TimeOutAlarm("等待[" + CurrPoint + "]" + CurrTray.ToStr() + " 放料完成");
}
}
else if (MoveInfo.MoveStep.Equals(MoveStep.T04_WaitEnd))
{
EndMove();
}
}
private void EndMove()
{
LogUtil.info(Name + MoveInfo.SLog + "【" + CurrPoint + "】结束放料 " + DateTime.Now.ToLongTimeString() + "");
CurrTray.updateTime = DateTime.Now;
MoveInfo.EndMove();
NeedShelf = "";
}
private void TimeOutAlarm(string msg)
{
WarnMsg = Name + "[" + MoveInfo.MoveType + "][" + MoveInfo.SLog + "]" + msg + "" + CurrPoint + CurrTray.ToStr() + " [" + Math.Round(MoveInfo.StepSpan().TotalSeconds, 1) + "]秒";
LogUtil.error(WarnMsg, robotNum * 100 + 12);
}
internal bool IsRightRfid(string currRfid, out string NeedRfid)
{
if (CurrTray == null)
{
NeedRfid = "";
return false;
}
if (CurrTray.realRFID.Equals(currRfid))
{
NeedRfid = currRfid;
return true;
}
else if (String.IsNullOrEmpty(CurrTray.realRFID))
{
NeedRfid = CurrTray.rfid;
//料架号=000,不放料
if (!currRfid.StartsWith("D") && !currRfid.StartsWith("C"))
{
return false;
}
//如果虚拟料架号一致,返回ture
string xnrfid = LineManager.Line.GetXNrfid(currRfid);
if ((!xnrfid.Equals("") && xnrfid.Equals(CurrTray.rfid)))
{
NeedRfid = currRfid;
return true;
}
if (!String.IsNullOrEmpty(CurrTray.usedRfidList))
{
string[] array = CurrTray.usedRfidList.Split(',');
//若料架已使用过,直接返回false
if (array.Contains(currRfid))
{
return false;
}
}
//当前是第一盘料,使用虚拟料架号
string needType = CurrTray.rfid.Substring(CurrTray.rfid.Length - 1, 1);
string currType = currRfid.Substring(0, 1);
//类型相同,且此料架未绑定
if (needType.Equals(currType) && xnrfid.Equals(""))
{
NeedRfid = currRfid;
return true;
}
return false;
}
else
{
NeedRfid = CurrTray.realRFID;
//真实料架对不上
return false;
}
}
internal string GetRunInfo()
{
string info = "" + Name + ":" + MoveInfo.MoveType + " " + MoveInfo.MoveStep;
if (CurrPoint != "")
{
info += " ,位置=" + CurrPoint + "";
}
if (NeedShelf != "")
{
info += ", 需要料架=" + NeedShelf + "";
}
if (String.IsNullOrEmpty(CurrTray.getP).Equals(false))
{
info += ", " + CurrTray.ToStr() + " ";
}
return info;
}
}
}