MoveEquip.cs
18.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
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
/// <summary>
/// 流水线自动料仓-移栽装置类
/// </summary>
public partial class MoveEquip : EquipBase
{
public MoveEquip_Config Config;
public MoveEquip(string cid, MoveEquip_Config config)
{
this.DeviceID = config.Id;
this.Config = config;
baseConfig = config;
IsDebug = config.IsDebug.Equals(1);
Name = (" " + "_移栽_" + DeviceID + " ").ToUpper();
Init();
MoveInfo = new LineMoveInfo(DeviceID, "移栽-" + DeviceID + "-MoveInfo");
SecondMoveInfo = new LineMoveInfo(DeviceID, "移栽-" + DeviceID + "-SecondMoveInfo");
UseAxis = config.UpDownUseAxis.Equals(1);
if (UseAxis)
{
Config.UpDown_Axis.TargetSpeed = Config.UpdownAxis_TargetSpeed;
Config.UpDown_Axis.AddSpeed = Config.UpdownAxis_AddSpeed;
Config.UpDown_Axis.DelSpeed = Config.UpdownAxis_DelSpeed;
Config.UpDown_Axis.HomeAddSpeed = Config.UpdownAxis_HomeAddSpeed;
Config.UpDown_Axis.HomeHighSpeed = Config.UpdownAxis_HomeHighSpeed;
Config.UpDown_Axis.HomeLowSpeed = Config.UpdownAxis_HomeLowSpeed;
portName = Config.UpDown_Axis.DeviceName;
slvAddr = config.UpDown_Axis.GetAxisValue();
}
}
/// <summary>
/// 开始运行
/// </summary>
public override bool StartRun()
{
preTrayNum = 0;
currMoveTrayNum = 0;
mainTimer.Enabled = false;
MoveInfo.EndMove();
SecondMoveInfo.EndMove();
lineStatus = LineStatus.StoreOnline;
//TODO 调试时暂时注释
runStatus = LineRunStatus.HomeMoving;
return ReturnHome();
}
public bool StartDebugRun()
{
preTrayNum = 0;
currMoveTrayNum = 0;
mainTimer.Enabled = false;
MoveInfo.EndMove();
SecondMoveInfo.EndMove();
lineStatus = LineStatus.StoreOnline;
//TODO 调试时暂时注释
runStatus = LineRunStatus.HomeMoving;
bool result = ReturnHome();
if (result)
{
mainTimer.Enabled = true;
}
return result;
}
/// <summary>
/// 停止运行
/// </summary>
public override void StopRun()
{
preTrayNum = 0;
currMoveTrayNum = 0;
if (mainTimer != null)
{
mainTimer.Enabled = false;
}
StopMove();
//停止运行时,把所有IO 置零
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
IOMove(IO_Type.TopCylinder_UP, IO_VALUE.LOW);
IOMove(IO_Type.TopCylinder_Down, IO_VALUE.LOW);
IOMove(IO_Type.BeforeAfterCylinder_Before, IO_VALUE.LOW);
IOMove(IO_Type.BeforeAfterCylinder_After, IO_VALUE.LOW);
IOMove(IO_Type.UpDownCylinder_Up, IO_VALUE.LOW);
IOMove(IO_Type.UpDownCylinder_Down, IO_VALUE.LOW);
IOMove(IO_Type.ClampCylinder_Slack, IO_VALUE.LOW);
IOMove(IO_Type.ClampCylinder_Tighten, IO_VALUE.LOW);
runStatus = LineRunStatus.Wait;
}
public override void TimerProcess()
{
if (isInPro)
{
return;
}
isInPro = true;
try
{
if (IsDebug)
{
isInPro = false;
return;
}
BusyMoveProcess();
//判断流水线打开了才可以运行
if (SecondMoveInfo.MoveType.Equals(LineMoveType.None))
{
LineBean lineBean = LineManager.Line;
if (lineBean.isCanProcessLine() && IOManager.IOValue(IO_Type.DriveMotor_Run, 0).Equals(IO_VALUE.HIGH) && lineBean.runStatus >= LineRunStatus.Runing && lineBean.IsSleep.Equals(false))
{
// LogUtil.info("StartCheckFixture");
StartCheckFixture();
}
}
IOTimeOutProcess();
OutStoreListPro();
}
catch (Exception ex)
{
LogUtil.error(Name + "TimerProcess出错:" + ex.ToString());
}
isInPro = false;
}
/// <summary>
/// 出库队列处理
/// </summary>
private void OutStoreListPro()
{
//料仓出库完成,移栽装置开始出库检测
if (IsDebug.Equals(false) && MoveInfo.MoveType.Equals(LineMoveType.None) && runStatus.Equals(LineRunStatus.Runing))
{
InOutParam waitOutParma = null;
lock (waitOutListLock)
{
if (waitOutStoreList.Count > 0)
{
waitOutParma = waitOutStoreList[0];
waitOutStoreList.RemoveAt(0);
}
}
if (waitOutParma != null)
{
LogUtil.info(Name + "开始 执行排队中的出库【" + waitOutParma.ToStr() + "】");
//出库
bool result = StartOutStoreMove(waitOutParma);
if (!result)
{
LogUtil.info(Name + " 执行排队中的出库【" + waitOutParma.ToStr() + "】失败,重新加入等待队列");
AddWaitOutInfo(waitOutParma);
}
}
}
}
public void AddWaitOutInfo(InOutParam param)
{
lock (waitOutListLock)
{
//判断是否已经加入,不重复加
List<InOutParam> paramList = (from m in waitOutStoreList where m.PosId.Equals(param.PosId) select m).ToList<InOutParam>();
if (paramList.Count > 0)
{
LogUtil.error(Name + "出库【" + param.ToStr() + "】加入等待出库队列失败,此库位已存在列表中");
}
else
{
waitOutStoreList.Add(param);
}
}
}
/// <summary>
/// 移栽装置原点返回
/// </summary>
public bool ReturnHome()
{
mainTimer.Stop();
if (!RunAxis(true,Config.UpDown_Axis))
{
return false;
}
alarmType = LineAlarmType.None;
runStatus = LineRunStatus.HomeMoving;
LogInfo("开始原点返回: (上下气缸回原点,阻挡气缸输入=0 )开始");
MoveInfo.NewMove(LineMoveType.ReturnHome);
//移载装置原点状态:顶升气缸下降端,前后气缸后退端,上下气缸上升端,夹料气缸放松端,阻挡气缸输入=0
UpdownHomeMove();
// CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
if (IsDebug)
{
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.HIGH);
}
else
{
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
}
return true;
}
/// <summary>
/// 移栽装置重置
/// </summary>
public override bool Reset()
{
WarnMsg = "";
//如果正在出库中,需要减去托盘号
if (MoveInfo.MoveType.Equals(LineMoveType.OutStore))
{
LogInfo("重置之前发现在出库执行中,减去托盘数;");
//减去需要的盘数
TrayManager.DelNeedEmptyTrayNum();
MoveInfo.EndMove();
}
if (!RunAxis(true, Config.UpDown_Axis))
{
return false;
}
alarmType = LineAlarmType.None;
//重置时清理盘号,从头开始判断
preTrayNum = 0;
currMoveTrayNum = 0;
LogInfo("开始重置:清零上一个托盘号,(上下气缸回原点,阻挡气缸输入=0 )开始;");
runStatus = LineRunStatus.Reset;
SecondMoveInfo.EndMove();
MoveInfo.NewMove(LineMoveType.Reset);
UpdownHomeMove();
// CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
if (IsDebug)
{
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.HIGH);
}
else
{
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
}
isInPro = false;
return true;
}
/// <summary>
/// 重置处理
/// </summary>
protected override void ResetProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait(MoveInfo);
}
else if (SecondMoveInfo.IsInWait)
{
CheckWait(SecondMoveInfo);
}
if (!MoveInfo.IsInWait && !SecondMoveInfo.IsInWait)
{
//流水线各装置复原位,夹料气缸状态不变
//阻挡气缸全部=0
//上下气缸上升,、
//上升到位,顶升气缸下降,前后气缸回退
//复位时夹紧气缸需要发送,不然后面出入库会有问题
switch (MoveInfo.MoveStep)
{
case LineMoveStep.MH_UpDownHomeMove:
MoveInfo.NextMoveStep(LineMoveStep.MH_UpDownCylinder_Up);
LogInfo("重置: (上下轴原点返回完成,上下轴走到待机点 )开始");
UpdownUpMove();
break;
case LineMoveStep.MH_UpDownCylinder_Up:
MoveInfo.NextMoveStep(LineMoveStep.MH_OtherCylinder_Back);
LogInfo("重置: (上升到位,顶升气缸下降,前后气缸回退 )开始");
CylinderMove(MoveInfo, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After);
CylinderMove(MoveInfo, IO_Type.ClampCylinder_Slack, IO_Type.ClampCylinder_Tighten);
break;
case LineMoveStep.MH_OtherCylinder_Back:
LogInfo("重置完成!");
runStatus = LineRunStatus.Runing;
MoveInfo.EndMove();
SecondMoveInfo.EndMove();
break;
//TODO 需要继续之前的的出入库处理
//ContinueInOutStore();
default: break;
}
}
}
/// <summary>
/// 原点返回处理
/// </summary>
protected override void ReturnHomeProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait(MoveInfo);
}
if (SecondMoveInfo.IsInWait)
{
CheckWait(SecondMoveInfo);
}
if (!MoveInfo.IsInWait && !SecondMoveInfo.IsInWait)
{
switch (MoveInfo.MoveStep)
{
case LineMoveStep.MH_UpDownHomeMove:
MoveInfo.NextMoveStep(LineMoveStep.MH_UpDownCylinder_Up);
LogInfo("原点返回: (上下轴原点返回完成,上下轴走到待机点 )开始");
UpdownUpMove();
break;
case LineMoveStep.MH_UpDownCylinder_Up:
LogInfo("原点返回:(上升到位,顶升气缸下降,前后气缸回退 )开始");
MoveInfo.NextMoveStep(LineMoveStep.MH_OtherCylinder_Back);
CylinderMove(MoveInfo, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After);
CylinderMove(MoveInfo, IO_Type.ClampCylinder_Slack, IO_Type.ClampCylinder_Tighten);
break;
case LineMoveStep.MH_OtherCylinder_Back:
MoveInfo.EndMove();
SecondMoveInfo.EndMove();
LogInfo("原点返回完成!");
runStatus = LineRunStatus.Runing;
//如果是调试模式,移栽装置两个阻挡气缸落下,并且不再移动
if (IsDebug)
{
lineStatus = LineStatus.Debugging;
}
else
{
lineStatus = LineStatus.StoreOnline;
}
break;
default: break;
}
}
}
protected override void StopMoveProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait(MoveInfo);
}
if (SecondMoveInfo.IsInWait)
{
CheckWait(SecondMoveInfo);
}
if (!MoveInfo.IsInWait && !SecondMoveInfo.IsInWait)
{
switch (MoveInfo.MoveStep)
{
//流水线各装置复原位,夹料气缸状态不变 //阻挡气缸全部=0 //上下气缸上升,、 //上升到位,顶升气缸下降,前后气缸回退
case LineMoveStep.MH_UpDownCylinder_Up:
{
MoveInfo.NextMoveStep(LineMoveStep.MH_OtherCylinder_Back);
LogInfo("停止运动: (上升到位,顶升气缸下降,前后气缸回退 )开始");
IOMove(IO_Type.UpDownCylinder_Up, IO_VALUE.LOW);
CylinderMove(MoveInfo, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After);
break;
}
case LineMoveStep.MH_OtherCylinder_Back:
{
LogInfo("停止运行完成!");
if (UseAxis)
{
LogInfo("停止运动:停止伺服");
ACServerManager.SuddenStop(Config.UpDown_Axis);
CloseAxis();
}
runStatus = LineRunStatus.Runing;
MoveInfo.EndMove();
break;
}
default: break;
}
}
}
/// <summary>
/// 停止运动
/// </summary>
public override void StopMove()
{
//如果正在出库中,需要减去托盘号
if (MoveInfo.MoveType.Equals(LineMoveType.OutStore))
{
LogInfo("停止运动时出库执行中,减去托盘数;");
//减去需要的盘数
TrayManager.DelNeedEmptyTrayNum();
MoveInfo.EndMove();
}
runStatus = LineRunStatus.Busy;
SecondMoveInfo.EndMove();
LogInfo("停止运动:(上下气缸上升端,阻挡气缸输入=0 )开始 ");
MoveInfo.NewMove(LineMoveType.StopMove);
MoveInfo.NextMoveStep(LineMoveStep.MH_UpDownCylinder_Up);
UpdownUpMove();
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
}
#region 上下气缸伺服运动
/// <summary>
/// 上下气缸移动到上升端
/// </summary>
private void UpdownUpMove()
{
if (UseAxis)
{
ACAxisMove(Config.UpDown_Axis, Config.UpDownAxisP1, Config.UpdownAxis_P1Speed);
}
else
{
CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
}
}
private void UpdownDownMove(int trayHeight)
{
if (UseAxis)
{
int position = Config.GetUpdownPosition(trayHeight);
ACAxisMove(Config.UpDown_Axis, position, Config.UpdownAxis_DownSpeed);
}
else
{
CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Up, IO_Type.UpDownCylinder_Down);
}
}
private void UpdownDownBoxMove(int trayHeight)
{
if (UseAxis)
{
int position = Config.GetUpdownBoxPosition(trayHeight);
ACAxisMove(Config.UpDown_Axis, position, Config.UpdownAxis_DownSpeed);
}
else
{
CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Up, IO_Type.UpDownCylinder_Down);
}
}
private void UpdownHomeMove()
{
if (UseAxis)
{
MoveInfo.NextMoveStep(LineMoveStep.MH_UpDownHomeMove);
ACAxisHomeMove(Config.UpDown_Axis);
}
else
{
MoveInfo.NextMoveStep(LineMoveStep.MH_UpDownCylinder_Up);
CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
}
}
#endregion
}
}