AgvControl.cs
15.4 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
using OnlineStore;
using DeviceLibrary;
using DL.StandardRobot;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.NetworkInformation;
namespace AutoScanAndLabel.UC
{
public partial class AgvControl : UserControl
{
public string serverIp = "";
public AgvControl()
{
InitializeComponent();
serverIp = ConfigHelper.Config.Get(Setting_Init.STD_IP, "127.0.0.1");
AGVManager.Connect(serverIp);
load();
groupBox2.Text = crc.GetString("Res0071", "任务状态") + "[" + serverIp + "]";
AGVManager.Register(MissionStateChanged);
endit(false);
}
~AgvControl()
{
AGVManager.UnRegister(MissionStateChanged);
AGVManager.Close();
}
private void load()
{
txtEnterId.Text = ConfigHelper.Config.Get(Setting_Init.ShelfInAGV, "8");
txtLeaveId.Text = ConfigHelper.Config.Get(Setting_Init.ShelfOutAGV, "10");
txtMoveLSTId.Text = ConfigHelper.Config.Get(Setting_Init.LStation, "7");
txtMoveRSTId.Text = ConfigHelper.Config.Get(Setting_Init.RStation, "9");
txtStandbyId.Text = ConfigHelper.Config.Get(Setting_Init.Standby, "11");
}
MissionState curState;
private void MissionStateChanged(MissionState state)
{
curState = state;
if (!this.IsHandleCreated) return;
this.Invoke(new Action(() =>
{
try
{
lblCurMissionId.Text = crc.GetString("Res0075", "任务编号:") + state.MissionId;
lblCurRunMissionId.Text = crc.GetString("Res0076", "运行编号:") + state.RunMissionId;
switch (state.MissionRunState)
{
case MissionRunState.无效状态:
lblMissionRunstate.Text = crc.GetString("Res0077", "任务状态:") + crc.GetString(MissionRunState.无效状态.ToString(), MissionRunState.无效状态.ToString());
break;
case MissionRunState.正在取消:
lblMissionRunstate.Text = crc.GetString("Res0077", "任务状态:") + crc.GetString(MissionRunState.正在取消.ToString(), MissionRunState.正在取消.ToString());
break;
case MissionRunState.任务在队列中但没有启动:
lblMissionRunstate.Text = crc.GetString("Res0077", "任务状态:") + crc.GetString(MissionRunState.任务在队列中但没有启动.ToString(), MissionRunState.任务在队列中但没有启动.ToString());
break;
case MissionRunState.正在执行:
lblMissionRunstate.Text = crc.GetString("Res0077", "任务状态:") + crc.GetString(MissionRunState.正在执行.ToString(), MissionRunState.正在执行.ToString());
break;
case MissionRunState.暂停执行:
lblMissionRunstate.Text = crc.GetString("Res0077", "任务状态:") + crc.GetString(MissionRunState.暂停执行.ToString(), MissionRunState.暂停执行.ToString());
break;
}
switch (state.MissionResult)
{
case MissionResult.无效状态:
lblMissionResult.Text = crc.GetString("Res0078", "运行结果:") + crc.GetString(MissionResult.无效状态.ToString(), MissionResult.无效状态.ToString());
break;
case MissionResult.任务执行成功:
lblMissionResult.Text = crc.GetString("Res0078", "运行结果:") + crc.GetString(MissionResult.任务执行成功.ToString(), MissionResult.任务执行成功.ToString());
break;
case MissionResult.任务取消:
lblMissionResult.Text = crc.GetString("Res0078", "运行结果:") + crc.GetString(MissionResult.任务取消.ToString(), MissionResult.任务取消.ToString());
break;
case MissionResult.任务执行出错:
lblMissionResult.Text = crc.GetString("Res0078", "运行结果:") + crc.GetString(MissionResult.任务执行出错.ToString(), MissionResult.任务执行出错.ToString());
break;
}
}
catch
{
}
}));
}
public bool InCalling = false;
private bool canCall()
{
return !InCalling && (handleAgv == null || (handleAgv != null && handleAgv.IsCompleted));
}
private void button_rightneedempty_Click(object sender, EventArgs e)
{
if (!RobotManage.isRunning)
{
MessageBox.Show(crc.GetString("Res0079", "机器尚未启动不能呼叫Agv"));
return;
}
if (!canCall())
{
MessageBox.Show(crc.GetString("Res0035", "已呼叫Agv,不能重复呼叫"));
return;
}
if (RobotManage.mainMachine.IOValue(IO_Type.RightEnd_Check).Equals(IO_VALUE.LOW))
{
LogUtil.info("开始入口满料串送入流程");
handleAgv = Task.Run(() =>
{
InCalling = true;
//请求AGV代码放这里
RequestRight();
//等待agv到位
while (!WaitMissionOk())
{
if (!InCalling)
return;
waitTmie();
}
if (InCalling)
RobotManage.mainMachine.RightMoveInfo.NewMove(MoveStep.R40_InShelf);//等待agv到位后执行,启动进入
ShelfOutAgv();
while (RobotManage.mainMachine.RightMoveInfo.MoveStep >= MoveStep.R40_InShelf)
{
if (!InCalling)
return;
waitTmie();
}
while (!WaitMissionOk())
{
if (!InCalling)
return;
waitTmie();
}
ToStandby();
//通知agv上料结束, 也可以把上料结束的代码放到 R40_InShelf的结束步骤里去
InCalling = false;
});
}
else
MessageBox.Show(crc.GetString("Res0080", "当前有料串不能请求进入料串"));
}
private void button_rightleavefull_Click(object sender, EventArgs e)
{
if (!RobotManage.isRunning)
{
MessageBox.Show(crc.GetString("Res0079", "机器尚未启动不能呼叫Agv"));
return;
}
if (!canCall())
{
MessageBox.Show(crc.GetString("Res0035", "已呼叫Agv,不能重复呼叫"));
return;
}
if (RobotManage.mainMachine.IOValue(IO_Type.RightEnd_Check).Equals(IO_VALUE.HIGH))
{
LogUtil.info("开始入口空料串取出流程");
handleAgv = Task.Run(() =>
{
InCalling = true;
//请求AGV代码放这里
RequestRight();
//等待agv到位
while (!WaitMissionOk())
{
if (!InCalling)
return;
waitTmie();
}
if (InCalling)
RobotManage.mainMachine.RightMoveInfo.NewMove(MoveStep.R30_OutShelf);//等待agv到位后执行,启动料串离开
ShelfEnterAgv();
while (RobotManage.mainMachine.RightMoveInfo.MoveStep >= MoveStep.R30_OutShelf)
{
if (!InCalling)
return;
waitTmie();
}
//通知agv上料结束, 也可以把上料结束的代码放到R30_OutShelf的结束步骤里去
while (!WaitMissionOk())
{
if (!InCalling)
return;
waitTmie();
}
ToStandby();
InCalling = false;
});
}
else
MessageBox.Show(crc.GetString("Res0081", "当前没有料串不能请求取料串"));
}
private void RequestLeft()
{
int.TryParse(ConfigHelper.Config.Get(Setting_Init.LStation, "3"), out int val);
autoAddMision(val);
}
private void RequestRight()
{
int.TryParse(ConfigHelper.Config.Get(Setting_Init.RStation, "4"), out int val);
autoAddMision(val);
}
private void ShelfEnterAgv()
{
int.TryParse(ConfigHelper.Config.Get(Setting_Init.ShelfInAGV, "4"), out int val);
autoAddMision(val);
}
private void ShelfOutAgv()
{
int.TryParse(ConfigHelper.Config.Get(Setting_Init.ShelfOutAGV, "4"), out int val);
autoAddMision(val);
}
private void ToStandby()
{
int.TryParse(ConfigHelper.Config.Get(Setting_Init.Standby, "4"), out int val);
autoAddMision(val);
}
private bool WaitMissionOk(uint missionId)
{
return curState != null && curState.RunMissionId.Equals(missionId) && curState.MissionResult.Equals(MissionResult.任务执行成功);
}
private bool WaitMissionOk()
{
bool rtn = WaitMissionOk((uint)AGVManager.CurMissionId);
if (rtn)
{
LogUtil.info("任务编号" + AGVManager.CurMissionId + "执行完成");
}
return rtn;
}
void autoAddMision(int id)
{
if (!InCalling)
return;
AGVManager.AddMission(id);
LogUtil.info("自动任务:发送任务编号" + id);
}
void waitTmie()
{
Thread.Sleep(300);
}
private void button_Leftleavefull_Click(object sender, EventArgs e)
{
if (!RobotManage.isRunning)
{
MessageBox.Show(crc.GetString("Res0079", "机器尚未启动不能呼叫Agv"));
return;
}
if (!canCall())
{
MessageBox.Show(crc.GetString("Res0035", "已呼叫Agv,不能重复呼叫"));
return;
}
if (RobotManage.mainMachine.IOValue(IO_Type.LeftEnd_Check).Equals(IO_VALUE.HIGH))
{
LogUtil.info("开始出口AGV满料串取出流程");
handleAgv = Task.Run(() =>
{
InCalling = true;
//请求AGV代码放这里
RequestLeft();
//等待agv到位
while (!WaitMissionOk())
{
if (!InCalling)
return;
waitTmie();
}
if (InCalling)
RobotManage.mainMachine.LeftMoveInfo.NewMove(MoveStep.L50_OutShelf);//等待agv到位后执行,启动料串离开
ShelfEnterAgv();
while (RobotManage.mainMachine.LeftMoveInfo.MoveStep >= MoveStep.L50_OutShelf)
{
if (!InCalling)
return;
waitTmie();
}
//通知agv上料结束, 也可以把上料结束的代码放到L50_OutShelf的结束步骤里去
//等待agv到位
while (!WaitMissionOk())
{
if (!InCalling)
return;
waitTmie();
}
ToStandby();
InCalling = false;
});
}
else
MessageBox.Show(crc.GetString("Res0081", "当前没有料串不能请求取料串"));
}
Task handleAgv = null;
private void button_leftneedempty_Click(object sender, EventArgs e)
{
if (!RobotManage.isRunning)
{
MessageBox.Show(crc.GetString("Res0079", "机器尚未启动不能呼叫Agv"));
return;
}
if (!canCall())
{
MessageBox.Show(crc.GetString("Res0035", "已呼叫Agv,不能重复呼叫"));
return;
}
if (RobotManage.mainMachine.IOValue(IO_Type.LeftEnd_Check).Equals(IO_VALUE.LOW))
{
LogUtil.info("开始出口空料串送入流程");
handleAgv = Task.Run(() =>
{
InCalling = true;
//请求AGV代码放这里
RequestLeft();
//等待agv到位
while (!WaitMissionOk())
{
if (!InCalling)
return;
waitTmie();
}
if (InCalling)
RobotManage.mainMachine.LeftMoveInfo.NewMove(MoveStep.L60_InShelf);//等待agv到位后执行,启动进入
ShelfOutAgv();
while (RobotManage.mainMachine.LeftMoveInfo.MoveStep >= MoveStep.L60_InShelf)
{
if (!InCalling)
return;
waitTmie();
}
//通知agv上料结束, 也可以把上料结束的代码放到 L60_InShelf的结束步骤里去
while (!WaitMissionOk())
{
if (!InCalling)
return;
waitTmie();
}
ToStandby();
InCalling = false;
});
}
else
MessageBox.Show(crc.GetString("Res0080", "当前有料串不能请求进入料串"));
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
endit(checkBox1.Checked);
}
void endit(bool maul)
{
groupBox3.Enabled = maul;
}
private void button1_Click(object sender, EventArgs e)
{
int.TryParse(txtMissionId.Text, out int val);
AGVManager.AddMission(val);
LogUtil.info("手动发送任务编号:" + val);
}
private void button2_Click(object sender, EventArgs e)
{
InCalling = false;
LogUtil.info("重置呼叫");
}
}
}