RobotEquip_Partial.cs
14.5 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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
using CodeLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms.VisualStyles;
namespace OnlineStore.DeviceLibrary
{
partial class RobotEquip
{
#region 机器人相关命令
/// <summary>
/// 收到命令反馈
/// </summary>
public const string rtn_ok = "ok";
/// <summary>
/// 命令执行完成反馈
/// </summary>
const string rtn_done = "done";
const string cmd_store = "store";
const string cmd_inlet = "inlet";
const string cmd_outlet = "outlet";
const string cmd_inout = "inout";
const string cmd_ngbox = "ngbox";
const string cmd_high = "high";
const string cmd_low = "low";
const string cmd_up = "up";
const string cmd_down = "down";
const string cmd_standby = "standby";
/// <summary>
/// 获取指定命令
/// </summary>
/// <param name="place">地点</param>
/// <param name="index">编号</param>
/// <param name="point">点位</param>
/// <returns></returns>
public static string GetCmd(string place, string point, int index = 0)
{
StringBuilder sb = new StringBuilder();
if (index == 0)
{
sb.Append(place);
sb.Append("-");
sb.Append(point);
}
else
{
sb.Append(place);
sb.Append(index);
sb.Append("-");
sb.Append(point);
}
return sb.ToString();
}
/// <summary>
/// 机器人移动成功
/// </summary>
/// <param name="cmd"></param>
/// <returns></returns>
public bool RobotMoveEnd(string cmd)
{
JAKA.JAKABean bean;
if (!GetRobotInfo(out bean))
{
return false;
}
if (!bean.RobotData.Online)
{
LogUtil.error($"无法获取机器人状态,因机器人离线:{Config.Robot_IP}");
return false;
}
try
{
string[] recv = bean.RobotData.RecvMsg.Split(',');
if (GetCurCmd().Equals(cmd) && recv != null && recv.Length == 2
&& recv[0].Equals(cmd) &&
recv[1].Equals(rtn_done))
return true;
}
catch (Exception ex)
{
LogUtil.error($"RobotMoveEnd:{cmd}", ex);
return false;
}
return false;
}
public bool RobotMoveEnd()
{
JAKA.JAKABean bean;
if (!GetRobotInfo(out bean))
{
return false;
}
if (!bean.RobotData.Online)
{
LogUtil.error($"无法获取机器人状态,因机器人离线:{Config.Robot_IP}");
return false;
}
try
{
string[] recv = bean.RobotData.RecvMsg.Split(',');
if (recv != null && recv.Length == 2 &&
recv[1].Equals(rtn_done))
return true;
}
catch (Exception ex)
{
LogUtil.error($"RobotMoveEnd:{bean.RobotData.RecvMsg}", ex);
return false;
}
return false;
}
/// <summary>
/// 发送命令
/// </summary>
/// <param name="cmd"></param>
void SendCmd(string cmd)
{
JAKA.JAKABean bean;
if (!GetRobotInfo(out bean))
{
return;
}
if (!bean.RobotData.Online)
{
LogUtil.error($"无法发送命令,因机器人离线:{Config.Robot_IP}");
return;
}
JAKAServer.SendCmd(bean.RemoteEndPoint, cmd);
MoveInfo.WaitList.Add(WaitResultInfo.WaitRobotMove());
}
/// <summary>
/// 获取机器人当前命令
/// </summary>
/// <returns></returns>
string GetCurCmd()
{
JAKA.JAKABean bean;
if (!GetRobotInfo(out bean))
{
return "";
}
if (!bean.RobotData.Online)
{
LogUtil.error($"无法获取当前命令,因机器人离线:{Config.Robot_IP}");
return "";
}
return bean.RobotData.CurCmd;
}
#endregion
#region 机器人命令
public static string GetCmd_InletLow()
{
return GetCmd(cmd_inlet, cmd_low);
}
public static string GetCmd_InletUp()
{
return GetCmd(cmd_inout, cmd_up);
}
public static string GetCmd_OutletHigh()
{
return GetCmd(cmd_outlet, cmd_high);
}
public static string GetCmd_OutletDown()
{
return GetCmd(cmd_inout, cmd_down);
}
public static string GetCmd_NGBoxHigh()
{
return GetCmd(cmd_ngbox, cmd_high);
}
public static string GetCmd_NGBoxDown()
{
return GetCmd(cmd_ngbox, cmd_down);
}
public static string GetCmd_StoreHigh(int index)
{
return GetCmd(cmd_store, cmd_high, index);
}
public static string GetCmd_StoreLow(int index)
{
return GetCmd(cmd_store, cmd_low, index);
}
public static string GetCmd_StoreUp()
{
return GetCmd(cmd_store, cmd_up);
}
public static string GetCmd_StoreDown()
{
return GetCmd(cmd_store, cmd_down);
}
public static string GetCmd_Standby()
{
return GetCmd(cmd_standby, "");
}
#endregion
#region 机器人
public bool GetRobotInfo(out JAKA.JAKABean bean)
{
bean = JAKAServer.GetJAKABean(Config.Robot_IP);
if (bean == null)
{
LogUtil.error($"无法获取机器人信息,因不存在的机器人:{Config.Robot_IP}");
return false;
}
return true;
}
/// <summary>
/// 上电
/// </summary>
/// <param name="on">true:开启</param>
public void PowerOn(bool on)
{
if (GetRobotInfo(out JAKA.JAKABean bean))
{
if (on)
bean.PowerOn();
else
bean.PowerOff();
}
}
/// <summary>
/// 上使能
/// </summary>
/// <param name="enable">true:开启</param>
public void EnableRobot(bool enable)
{
if (GetRobotInfo(out JAKA.JAKABean bean))
{
if (enable)
bean.EnableRobot();
else
bean.DisableRobot();
}
}
/// <summary>
/// 启动程序
/// </summary>
/// <param name="start"></param>
public void StartProg(bool start)
{
if (GetRobotInfo(out JAKA.JAKABean bean))
{
if (start)
bean.Run();
else
bean.Abort();
}
}
/// <summary>
/// 机器人运动中止
/// </summary>
public void MotionAbort()
{
if (GetRobotInfo(out JAKA.JAKABean bean))
{
bean.MotionAbort();
}
}
#endregion
#region 行走机构
int targetIndex = 0;
private void MoveAxisToStore()
{
switch (MoveInfo.MoveParam.PosInfo.PosId.Substring(0, 2))
{
case "01":
targetIndex = 1;
MoveAxis.AbsMove(MoveInfo, Config.MoveAxis_P5_Store1, Config.MoveAxis_P5_Store1_Speed);
break;
case "02":
targetIndex = 2;
MoveAxis.AbsMove(MoveInfo, Config.MoveAxis_P6_Store2, Config.MoveAxis_P6_Store2_Speed);
break;
case "03":
targetIndex = 3;
MoveAxis.AbsMove(MoveInfo, Config.MoveAxis_P7_Store3, Config.MoveAxis_P7_Store3_Speed);
break;
case "04":
targetIndex = 4;
MoveAxis.AbsMove(MoveInfo, Config.MoveAxis_P8_Store4, Config.MoveAxis_P8_Store4_Speed);
break;
case "05":
targetIndex = 5;
MoveAxis.AbsMove(MoveInfo, Config.MoveAxis_P9_Store5, Config.MoveAxis_P9_Store5_Speed);
break;
case "06":
targetIndex = 6;
MoveAxis.AbsMove(MoveInfo, Config.MoveAxis_P10_Store6, Config.MoveAxis_P10_Store6_Speed);
break;
}
}
#endregion
protected override bool CheckWaitResult(DeviceMoveInfo moveInfo, WaitResultInfo wait)
{
if (wait.WaitType.Equals(WaitEnum.W201_RobotMove))
{
if (RobotMoveEnd())
{
wait.IsEnd = true;
}
}
return wait.IsEnd;
}
/// <summary>
/// 设置料仓状态
/// </summary>
/// <param name="deviceStatus">设备上报服务端的状态</param>
/// <param name="runStatus">设备显示的状态</param>
private void SetBoxStatus(DeviceStatus deviceStatus, RunStatus runStatus, InOutPosInfo posInfo = null)
{
if (posInfo != null)
{
lastPosInfo = posInfo;
}
this.deviceStatus = deviceStatus;
this.runStatus = runStatus;
}
#region 入库
private DateTime startInStoreTime = DateTime.Now;
public override bool StartInstore(InOutParam param)
{
if (isInSuddenDown || isNoAirpressure_Check ||
(!runStatus.Equals(RunStatus.Runing))
|| (!MoveInfo.MoveType.Equals(MoveType.None)))
{
LogUtil.error(Name + " 启动入库出错,忙碌或报警中 ,storeStatus=" + runStatus + ",MoveType=" + MoveInfo.MoveType + ",isInSuddenDown=" + isInSuddenDown + ",isNoAirpressure_Check=" + isNoAirpressure_Check);
return false;
}
startInStoreTime = DateTime.Now;
LogInfo(" 启动入库【" + param.PosInfo.ToStr() + "】 ");
param.MoveP = new LineMoveP(Config, param.PosInfo.PosId);
LogInfo("LoadInoutParam:" + JsonHelper.SerializeObject(param.MoveP));
MoveInfo.NewMove(MoveType.InStore, param);
SetBoxStatus(DeviceStatus.InStoreExecute, RunStatus.Busy, param.PosInfo);
MoveInfo.NextMoveStep(StepEnum.InStore_01_Wait);
return true;
}
protected override void InstoreProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait(MoveInfo);
}
if (MoveInfo.IsInWait)
{
return;
}
InstoreExecute();
}
#endregion
#region 出库
private static object outStoreObject = new object();
public void StartExecuctOut(InOutParam param)
{
bool result = false;
result = StartOutstore(param);
if (!result)
{
lock (outStoreObject)
{
if (MoveInfo.MoveType.Equals(MoveType.OutStore) && MoveInfo.MoveParam.PosInfo.PosId.Equals(param.PosInfo.PosId))
{
LogUtil.error(Name + " 出库命令【" + param.PosInfo.ToStr() + "】重复,【" + MoveInfo.MoveParam.PosInfo.PosId + "】出库执行中");
return;
}
List<InOutParam> reviceList = new List<InOutParam>();
reviceList.AddRange(waitOutStoreList);
reviceList = (from m in reviceList where m.PosInfo.PosId.Equals(param.PosInfo.PosId) select m).ToList<InOutParam>();
if (reviceList.Count == 0)
{
LogInfo(" 执行出库【" + param.PosInfo.ToStr() + "】失败,加入等待队列");
waitOutStoreList.Enqueue(param);
}
}
}
}
private DateTime startOutStoreTime = DateTime.Now;
/// <summary>
/// 关闭出库前的碗里检查
/// </summary>
public bool CloseOutStoreCheck = false;
public override bool StartOutstore(InOutParam param)
{
if (isInSuddenDown || isNoAirpressure_Check
|| !runStatus.Equals(RunStatus.Runing)
|| !MoveInfo.MoveType.Equals(MoveType.None))
{
SetWarnMsg(Name + " 启动出库【" + param.PosInfo.ToStr() + "】失败,忙碌或报警中 ,storeStatus:" + runStatus + ",MoveType:" + MoveInfo.MoveType + ",isInSuddenDown:" + isInSuddenDown + ",isNoAirCheck:" + isNoAirpressure_Check);
return false;
}
if (!param.PosInfo.CheckPosition())
{
SetWarnMsg(Name + " 启动出库【" + param.PosInfo.ToStr() + "】出错,找不到库位信息");
return false;
}
startOutStoreTime = DateTime.Now;
param.MoveP = new LineMoveP(Config, param.PosInfo.PosId);
SetBoxStatus(DeviceStatus.OutStoreExecute, RunStatus.Busy, param.PosInfo);
MoveInfo.NewMove(MoveType.OutStore, param);
LogInfo("启动出库【" + param.PosInfo.ToStr() + "】 ");
LogInfo("LoadInoutParam:" + JsonHelper.SerializeObject(param.MoveP));
MoveInfo.NextMoveStep(StepEnum.OutStore_01_Wait);
return true;
}
protected override void OutstoreProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait(MoveInfo);
}
if (MoveInfo.IsInWait)
{
return;
}
OutstoreExecute();
}
#endregion
}
}