InputEquip_Robot.cs
11.6 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
using JAKA;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static JAKA.JKTYPE;
namespace OnlineStore.DeviceLibrary
{
/// <summary>
/// 机器人
/// </summary>
partial class InputEquip
{
public JAKAServer RobotServer;
string robotIp = "";
void initRobot()
{
robotIp = ConfigAppSettings.GetValue("RobotIp", "192.168.104.21");
RobotServer = new JAKAServer(new string[] { robotIp });
RobotServer.Start();
}
/// <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)
{
SetWarnMsg("无法读取机器人状态,因机器人离线");
Alarm(AlarmType.RobotError);
robotOnline = false;
return false;
}
else
{
ClearSpecifiedAlarm("无法读取机器人状态,因机器人离线");
}
try
{
string[] recv = bean.RobotData.RecvMsg.Split(';');
if (GetCurCmd().Equals(cmd) && recv != null && recv.Length == 2
&& recv[0].Equals(cmd) && recv[1].Equals(JakaCmd.MoveDone)
&& (bean.RobotData.RobotStatus.inpos == 1))
{
LogUtil.info($"RobotMoveEnd:【{cmd}】");
return true;
}
}
catch (Exception ex)
{
LogUtil.error($"RobotMoveEnd:【{cmd}】", ex);
return false;
}
return false;
}
#region 点位命令
void To入料口()
{
string cmd = JakaPoint.入料口.ToString();
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void From入料口回原()
{
string cmd = $"{JakaPoint.入料口.ToString()}{JAKAServer._回原}";
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void To打印机()
{
string cmd = JakaPoint.打印机.ToString();
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void From打印机回原()
{
string cmd = $"{JakaPoint.打印机.ToString()}{JAKAServer._回原}";
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void ToA上暂存区()
{
string cmd = JakaPoint.A上暂存区.ToString();
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void FromA上暂存区回原()
{
string cmd = $"{JakaPoint.A上暂存区.ToString()}{JAKAServer._回原}";
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void ToA下皮带末端(int round = 0)
{
string cmd = JakaPoint.A下皮带末端.ToString();
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd, round);
}
}
void FromA下皮带末端回原()
{
string cmd = $"{JakaPoint.A下皮带末端.ToString()}{JAKAServer._回原}";
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void ToB上暂存区()
{
string cmd = JakaPoint.B上暂存区.ToString();
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void FromB上暂存区回原()
{
string cmd = $"{JakaPoint.B上暂存区.ToString()}{JAKAServer._回原}";
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void ToB下皮带末端(int round=0)
{
string cmd = JakaPoint.B下皮带末端.ToString();
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd, round);
}
}
void FromB下皮带末端回原()
{
string cmd = $"{JakaPoint.B下皮带末端.ToString()}{JAKAServer._回原}";
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void A下ToA周转1_内侧()
{
string cmd = JakaPoint.A下到A周转箱1_内侧.ToString();
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void B下ToA周转1_内侧()
{
string cmd = JakaPoint.B下到A周转箱1_内侧.ToString();
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void FromA周转1_内侧回原()
{
string cmd = $"{JakaPoint.A下到A周转箱1_内侧.ToString()}{JAKAServer._回原}";
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void A下ToA周转2_外侧()
{
string cmd = JakaPoint.A下到A周转箱2_外侧.ToString();
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void B下ToA周转2_外侧()
{
string cmd = JakaPoint.B下到A周转箱2_外侧.ToString();
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void FromA周转2_外侧回原()
{
string cmd = $"{JakaPoint.A下到A周转箱2_外侧.ToString()}{JAKAServer._回原}";
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void A下ToB周转1_内侧()
{
string cmd = JakaPoint.A下到B周转箱1_内侧.ToString();
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void B下ToB周转1_内侧()
{
string cmd = JakaPoint.B下到B周转箱1_内侧.ToString();
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void FromB周转1_内侧回原()
{
string cmd = $"{JakaPoint.A下到B周转箱1_内侧.ToString()}{JAKAServer._回原}";
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void A下ToB周转2_外侧()
{
string cmd = JakaPoint.A下到B周转箱2_外侧.ToString();
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void B下ToB周转2_外侧()
{
string cmd = JakaPoint.B下到B周转箱2_外侧.ToString();
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void FromB周转2_外侧回原()
{
string cmd = $"{JakaPoint.A下到B周转箱2_外侧.ToString()}{JAKAServer._回原}";
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void ToNG箱()
{
string cmd = JakaPoint.到NG口.ToString();
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void To紧急料()
{
string cmd = JakaPoint.到紧急料区域.ToString();
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void B下ToNG箱()
{
string cmd = JakaPoint.B下到NG口.ToString();
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void B下To紧急料()
{
string cmd = JakaPoint.B下到紧急料区域.ToString();
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void FromNG箱回原()
{
string cmd = $"{JakaPoint.到NG口.ToString()}{JAKAServer._回原}";
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
void From紧急料回原()
{
string cmd = $"{JakaPoint.到紧急料区域.ToString()}{JAKAServer._回原}";
if (RobotServer.RobotCmds.ContainsKey(cmd))
{
SendCmd(cmd);
}
}
#endregion
#region 机器人
public string curcmd = "";
DateTime sendTime = DateTime.Now;
bool robotOnline = false;
/// <summary>
/// 获取机器人当前命令
/// </summary>
/// <returns></returns>
string GetCurCmd()
{
JAKA.JAKABean bean;
if (!GetRobotInfo(out bean))
{
return "";
}
return bean.RobotData.CurCmd;
}
/// <summary>
/// 机器人是否在安全位置
/// </summary>
/// <returns></returns>
bool IsInSafePos()
{
JAKA.JAKABean bean;
if (!GetRobotInfo(out bean))
{
return false;
}
if (bean?.GetDigitalOutput(IOType.IO_CABINET, 0, out bool insafe) ?? false)
return insafe;
return false;
}
/// <summary>
/// 发送命令
/// </summary>
/// <param name="cmd"></param>
void SendCmd(string cmd, int round = 0)
{
MoveInfo.WaitList.Add(WaitResultInfo.WaitRobotMove(cmd));
JAKA.JAKABean bean;
if (!GetRobotInfo(out bean))
{
return;
}
if (!bean.RobotData.Online)
{
SetWarnMsg($"无法发送命令,因机器人离线:{robotIp}");
return;
}
else
{
ClearSpecifiedAlarm("无法发送命令,因机器人离线");
}
curcmd = cmd;
RobotServer.SendCmd(bean.RemoteEndPoint, cmd, round);
sendTime = DateTime.Now;
LogUtil.info($"Send RobotMove Cmd:【{cmd}】【{round}】");
}
public bool GetRobotInfo(out JAKA.JAKABean bean)
{
bean = RobotServer.GetJAKABean(robotIp);
if (bean == null)
{
SetWarnMsg($"无法获取机器人信息,因不存在的机器人:{robotIp}");
return false;
}
return true;
}
/// <summary>
/// 机器人运动中止
/// </summary>
public void MotionAbort()
{
if (GetRobotInfo(out JAKA.JAKABean bean))
{
bean.MotionAbort();
}
}
#endregion
}
}