InputEquip.cs
23.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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
using Asa;
using HuichuanLibrary;
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;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using ZebraPrinterHelper;
using log4net.Util;
using System.Drawing;
using static JAKA.JKTYPE;
namespace OnlineStore.DeviceLibrary
{
public partial class InputEquip : EquipBase
{
public InputEquip_Config Config;
public AxisBean[] moveAxisArray;
public BatchMoveBean BatchMove = null;
public AxisBean BatchAxis = null;
public ClampJawBean ClampJaw = null;
public PrintLabelBean PrintLabel = null;
public bool AutoInput = ConfigAppSettings.GetIntValue(Setting_Init.AutoInput).Equals(1);
public int DefautTargetP = 1;
public NGBox NGBox;
public InputEquip(string cid, InputEquip_Config config)
{
Name = (" " + "上料机构" + " ").ToUpper();
if (config.BatchAxis_P4Speed <= 0)
{
config.BatchAxis_P4Speed = config.BatchAxis_P2Speed;
LogUtil.info(Name + "未配置 BatchAxis_P4Speed,使用 BatchAxis_P2Speed 的值" + config.BatchAxis_P2Speed);
}
this.DeviceID = config.Id;
baseConfig = config;
this.Config = config;
string[] offsetMap = ConfigAppSettings.GetValue(Setting_Init.ReelHeightOffset).Split('#');
foreach (var item in offsetMap)
{
string[] maps = item.Split('=');
if (maps != null && maps.Length == 2)
reelHeightOffset.Add(int.Parse(maps[0]), int.Parse(maps[1]));
}
IsDebug = config.IsDebug.Equals(1);
Init();
ledProcessTimer.Elapsed += LedProcess;
IoCheckTimer.Elapsed += IoCheckTimerProcess;
BatchAxis = new AxisBean(config.BatchAxis, Name, true);
moveAxisArray = new AxisBean[] { };
if (config.UseClampJaw.Equals(1))
{
ClampJaw = new ClampJawBean(StoreManager.Config.CLAW_Input);
}
NGBox = new NGBox(config);
//rfid初始化
RFIDIP = RFIDManager.GetRFIP(DeviceID);
//加载周转箱
BoxA = new TurnoverBox("周转箱A", RFIDIP[0], config);
BoxB = new TurnoverBox("周转箱B", RFIDIP[1], config);
turnoverBoxes = new List<TurnoverBox>();
turnoverBoxes.Add(BoxA);
turnoverBoxes.Add(BoxB);
initRobot();
MoveInfo = new DeviceMoveInfo(Name);
BatchMove = new BatchMoveBean(Config, BatchAxis, 1);
PrintLabel = new PrintLabelBean(this);
//Printer.Connect();
addLastDI(IO_Type.Airpressure_Check, IO_VALUE.LOW);
addLastDI(IO_Type.SuddenStop_BTN, IO_VALUE.LOW);
addLastDI(IO_Type.Reset_BTN, IO_VALUE.LOW);
runStatus = RunStatus.Wait;
alarmRedLedType = AlarmType.IoSingleTimeOut;
}
~InputEquip()
{
RobotServer.Stop();
}
#region 启动,复位,停止 处理
public override bool StartRun()
{
if (CanStartRun().Equals(false))
{
return false;
}
if (!OpenAllAxis())
{
CloseAllAxis();
return false;
}
SetAllTimer(false);
MoveInfo.EndMove();
LogInfo("StartRun : 开始启动 ");
runStatus = RunStatus.HomeMoving;
MoveInfo.NewMove(MoveType.RHome, new InOutParam());
if (!BatchMove.Reset())
{
runStatus = RunStatus.Wait;
MoveInfo.EndMove();
SetWarnMsg("启动失败:上料口启动失败");
LogUtil.error("复位失败:上料口启动失败");
return false;
}
StartReset();
SetAllTimer(true);
return true;
}
public override bool Reset()
{
SetAllTimer(false);
StopMove();
if (!OpenAllAxis())
{
CloseAllAxis();
SetAllTimer(true);
return false;
}
LogInfo("Reset 开始重置 ");
runStatus = RunStatus.Reset;
MoveInfo.NewMove(MoveType.Reset, new InOutParam());
if (!BatchMove.Reset())
{
SetWarnMsg("复位失败:上料口复位失败");
MoveInfo.EndMove();
LogUtil.error("复位失败:上料口复位失败");
return false;
}
StartReset();
SetAllTimer(true);
return true;
}
private void StartReset()
{
BoxA.StartReset();
BoxB.StartReset();
PrintLabel.Reset();
//复位时设置状态为none
StartEquip();
SetWarnMsg("");
alarmType = AlarmType.None;
isInSuddenDown = false;
isNoAirpressure_Check = false;
MoveInfo.NextMoveStep(StepEnum.IR01_Wait);
LogInfo($"复位 {MoveInfo.SLog} :批量轴开始复位");
}
protected override void ResetProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait(MoveInfo);
}
if (MoveInfo.IsInWait)
{
return;
}
if (MoveInfo.IsStep(StepEnum.IR01_Wait))
{
if (IsInSafePos())
{
MoveInfo.NextMoveStep(StepEnum.IR07_ClampRelax);
LogInfo($"复位{MoveInfo.SLog}:吸盘关闭");
//Label_CylinderBack(MoveInfo);
ClampRelax(MoveInfo, MoveInfo.MoveParam.PosInfo.barcode);
}
else
{
SetWarnMsg($"复位失败,机器人不在安全位置");
Alarm(AlarmType.SuddenStop);
}
}
else if (MoveInfo.IsStep(StepEnum.IR07_ClampRelax))
{
MoveInfo.NextMoveStep(StepEnum.IR08_WaitBatchMove);
LogInfo($"复位{MoveInfo.SLog}:等待批量轴模块复位完成");
}
else if (MoveInfo.IsStep(StepEnum.IR08_WaitBatchMove))
{
if ((BatchMove.MoveInfo.MoveType.Equals(MoveType.Reset).Equals(false)))
{
LogInfo("复位完成");
runStatus = RunStatus.Runing;
MoveInfo.EndMove();
}
else if (MoveInfo.IsTimeOut(180))
{
if (BatchMove.MoveInfo.MoveType.Equals(MoveType.Reset))
{
WarnMsg = Name + "等待" + BatchMove.Name + "复位完成超时[" + MoveInfo.TimeOutSeconds + "]秒";
LogUtil.error(WarnMsg, MoveInfo.ErrorLogType, MoveInfo.logSeconds());
Alarm(AlarmType.IoSingleTimeOut);
}
}
}
}
private void IR06_UpdownToP1()
{
//MoveInfo.NextMoveStep(StepEnum.IR06_UpdownToP1);
//LogInfo($"复位{MoveInfo.SLog}:升降轴到P1:" + Config.Updown_P1 + ",夹爪原点返回");
//UpdownAxis.AbsMove(MoveInfo, Config.Updown_P1, Config.Updown_P1_Speed);
//if (Config.UseClampJaw.Equals(1))
//{
// ClampJaw.GoHome(MoveInfo);
//}
//else
//{
// //吸盘放松
// ClampRelax(MoveInfo);
//}
}
private void IR02_1_InoutToP1()
{
//MoveInfo.NextMoveStep(StepEnum.IR02_2_InoutToP1);
//LogInfo($"复位{MoveInfo.SLog}:进出轴到待机点:" + Config.Inout_P1);
//InOutAxis.AbsMove(MoveInfo, Config.Inout_P1, Config.Inout_P1_Speed);
}
private void IR04_MiddleToP1()
{
//MoveInfo.NextMoveStep(StepEnum.IR04_MiddleToP1);
//LogInfo($"复位{MoveInfo.SLog}:旋转轴到待机点:" + Config.Middle_P1);
//MiddleAxis.AbsMove(MoveInfo, Config.Middle_P1, Config.Middle_P1_Speed);
}
internal override void StopMove()
{
//StopMove时设置状态为none
BoxA.SetToNone();
BoxB.SetToNone();
MoveInfo.EndMove();
BatchMove.StopMove();
//UpdownAxis.SuddenStop();
//MiddleAxis.SuddenStop();
CloseAllAxis();
}
public override void StopRun()
{
SetAllTimer(false);
runStatus = RunStatus.Wait;
StopEquip();
StopMove();
}
#endregion
#region 方法重写
public override string GetMoveStr()
{
string msg = "";
msg += "runS: " + runStatus + "\n";
msg += "alarm: " + alarmType + " " + LastAlarmTime.ToLongTimeString() + "\n";
msg += "MoveT:" + MoveInfo.MoveType + "\n";
msg += "MoveS:" + MoveInfo.MoveStep + "\n";
msg += "StepMsg:" + StepMsg + "\n";
msg += "ReelInfo:" + PrintLabel?.LabelInfo?.ToStr() + "\n";
return msg;
}
protected override void BaseTimerProcess()
{
if (isInSuddenDown || isNoAirpressure_Check)
{
return;
}
SecurityAccessProcess();
BusyMoveProcess();
IOTimeOutProcess();
//判断流水线打开了才可以运行
List<BatchMoveBean> BatchMoveList = new List<BatchMoveBean>() { BatchMove };
if (!MoveStop)
{
//打标机检查下暂存区状态
if (CheckStartOutPos("A下暂存区", BufferDataManager.AOutStoreInfo, IO_Type.LineA_ReelInPlaceCheck, BatchMoveList))
{
}
else if (CheckStartOutPos("B下暂存区", BufferDataManager.BOutStoreInfo, IO_Type.LineB_ReelInPlaceCheck, BatchMoveList))
{
}
// PrintLabel.PrinteLabelProcess();
if (MoveInfo.MoveType.Equals(MoveType.None) && NoErrorAlarm())
{
if (IsDebug) return;
if (BufferDataManager.LabelInfo != null)
{
InOutParam param = new InOutParam(BufferDataManager.LabelInfo.ToCopy());
//param.ShelfType = moveBean.ShelfType;
StartOutstore(param);
//foreach (BatchMoveBean moveBean in BatchMoveList)
//{
// if (moveBean.ShelfReadyOut(posInfo, shelfAutoLeave))
// {
// }
//}
}
//if (CheckStartOutPos("A下暂存区", BufferDataManager.AOutStoreInfo, IO_Type.LineA_ReelInPlaceCheck, BatchMoveList))
//{
//}
//else if (CheckStartOutPos("B下暂存区", BufferDataManager.BOutStoreInfo, IO_Type.LineB_ReelInPlaceCheck, BatchMoveList))
//{
//}
//else
//{
// //如果有物料且不能放料,需要送一个料串离开
// if (BufferDataManager.AOutStoreInfo != null)
// {
// CheckStartOutPos("A下暂存区", BufferDataManager.AOutStoreInfo, IO_Type.FeedingA_Outstore_UnderArea_ReelCheck, BatchMoveList, true);
// }
// else if (BufferDataManager.BOutStoreInfo != null)
// {
// CheckStartOutPos("B下暂存区", BufferDataManager.BOutStoreInfo, IO_Type.FeedingB_Outstore_UnderArea_ReelCheck, BatchMoveList, true);
// }
//}
}
if (MoveInfo.MoveType.Equals(MoveType.None) && NoErrorAlarm())
{
//若左侧或右侧在等待扫码结束的状态,需要开始去取料
foreach (BatchMoveBean moveBean in BatchMoveList)
{
if (moveBean.MoveInfo.MoveType.Equals(MoveType.InStore) && moveBean.MoveInfo.IsStep(StepEnum.IB13_ScanOK)
&& (BufferDataManager.AInStoreInfo == null || BufferDataManager.BInStoreInfo == null))
{
LogInfo(moveBean.Name + "开始取料:" + moveBean.GetInstoreParam().PosInfo.ToStr());
StartInstore(moveBean.GetInstoreParam());
break;
}
}
}
}
foreach (BatchMoveBean moveBean in BatchMoveList)
{
moveBean.TimerProcess();
}
if (NoErrorAlarm())
{
CheckAxisAlarm();
}
if (string.IsNullOrEmpty(WarnMsg))
WarnMsg = PrintLabel?.WarnMsg;
}
#endregion
private bool CheckStartOutPos(string posType, InOutPosInfo posInfo, String ioType, List<BatchMoveBean> BatchMoveList, bool shelfAutoLeave = false)
{
if (posInfo != null && IOValue(ioType).Equals(IO_VALUE.HIGH) && !posInfo.Labeled)
{
//posInfo.Labeled = true;
InOutParam param = new InOutParam(posInfo.ToCopy());
//param.ShelfType = moveBean.ShelfType;
//StartOutstore(param);
PrintLabel.Start(param);
return true;
//foreach (BatchMoveBean moveBean in BatchMoveList)
//{
// if (moveBean.ShelfReadyOut(posInfo, shelfAutoLeave))
// {
// }
//}
}
return false;
}
internal bool CanStartWork()
{
//是否可以开始新的料串入料
if (BatchMove.MoveInfo.MoveType.Equals(MoveType.InStore))
{
StepEnum step = BatchMove.MoveInfo.MoveStep;
if (step < StepEnum.IB21_BatchToP1)
{
return false;
}
}
return true;
}
private DateTime checkAlarmTime = DateTime.Now;
private void CheckAxisAlarm()
{
if (alarmType.Equals(AlarmType.AxisAlarm) || alarmType.Equals(AlarmType.AxisMoveError))
{
return;
}
TimeSpan span = DateTime.Now - checkAlarmTime;
//在回原点,复位,出入库时,检测报警间隔减小
if (MoveInfo.MoveType.Equals(MoveType.None))
{
if (span.TotalSeconds < 5)
{
return;
}
}
else if (span.TotalSeconds < 1)
{
return;
}
checkAlarmTime = DateTime.Now;
foreach (AxisBean axisInfo in moveAxisArray)
{
if (AxisIsAlarm(axisInfo))
{
return;
}
}
if (AxisIsAlarm(BatchMove.BatchAxis, false))
{
BatchMove.WarnMsg = WarnMsg;
BatchMove.Alarm(AlarmType.AxisAlarm);
return;
}
}
public bool OpenAllAxis(bool isCheck = true)
{
foreach (AxisBean axis in moveAxisArray)
{
string outMsg = "";
if (!axis.Open(true, out outMsg))
{
LogUtil.info(outMsg);
return false;
}
}
return true;
}
public void PrintTest()
{
PrintLabel.PrintProcessTest();
}
public Bitmap PrintView()
{
return PrintLabel.PrintView();
}
public void PrintOnce()
{
PrintLabel.PrintTest();
}
public void CloseAllAxis()
{
foreach (AxisBean axis in moveAxisArray)
{
axis.SuddenStop();
axis.ServoOff();
}
}
public bool IsNoReelAlarm()
{
if (runStatus.Equals(RunStatus.Busy) && alarmType.Equals(AlarmType.IoSingleTimeOut))
{
if (MoveInfo.MoveType.Equals(MoveType.InStore) && MoveInfo.MoveStep.Equals(StepEnum.II01_ClampRelax))
{
return true;
}
else if (MoveInfo.MoveType.Equals(MoveType.OutStore) && MoveInfo.MoveStep.Equals(StepEnum.IO08_ClamWork))
{
return true;
}
else if (MoveInfo.MoveType.Equals(MoveType.OutStore) &&
(MoveInfo.MoveStep.Equals(StepEnum.IO12_ReClamWork) || MoveInfo.MoveStep.Equals(StepEnum.IO18_ReClamWork)))
{
return true;
}
}
return false;
}
public string GetReelInfo()
{
if (MoveInfo.MoveType.Equals(MoveType.OutStore))
{
return MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PosInfo.ToStr() : "";
}
else if (MoveInfo.MoveType.Equals(MoveType.InStore))
{
return MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PosInfo.ToStr() : "";
}
else
{
return "";
}
}
/// <summary>
/// 判断旋转轴是否在暂存区,返回true表示在暂存区
/// </summary>
/// <param name="areaNum">1=A上暂存区,2=A下暂存区,3=B上暂存区,4=B下暂存区</param>
/// <returns></returns>
public bool AxisInWorkingArea(params int[] areaNums)
{
return false;
}
/// <summary>
/// 判断旋转轴是否在料串上方
/// </summary>
/// <param name="shelfType">1=A侧料串,2=B侧料串</param>
/// <returns></returns>
public bool AxisIsInShelfUp(int shelfType)
{
//int middleP = MiddleAxis.GetAclPosition();
//int middleWucha = 20000;
////旋转轴在A暂存区
//if (MiddleAxis.IsInPosition(Config.Middle_P2_ATake, middleWucha))
//{
// if (shelfType.Equals(1))
// {
// return true;
// }
//}
//else if (MiddleAxis.IsInPosition(Config.Middle_P3_BTake, middleWucha))
//{
// if (shelfType.Equals(2))
// {
// return true;
// }
//}
return false;
}
//光栅状态:0正常。1=安全门禁打开,已停止运动
private int CurrSecurityAccess = 0;
protected void SecurityAccessProcess()
{
try
{
if (!baseConfig.DIList.ContainsKey(IO_Type.Shelf_SafetyRasterSignal))
{
return;
}
if (!baseConfig.DIList.ContainsKey(IO_Type.TurnoverBox_SafetyRasterSignal))
{
return;
}
if (!StoreManager.DisSecurityAccess)//未屏蔽光栅
{
if (CurrSecurityAccess.Equals(0))
{
if (IOValue(IO_Type.Shelf_SafetyRasterSignal).Equals(IO_VALUE.LOW))
{
SecurityAccessStop();
}
else if (IOValue(IO_Type.TurnoverBox_SafetyRasterSignal).Equals(IO_VALUE.LOW))
{
SecurityAccessStop();
}
}
else if (CurrSecurityAccess.Equals(1))
{
if (IOValue(IO_Type.Shelf_SafetyRasterSignal).Equals(IO_VALUE.HIGH) &&
IOValue(IO_Type.TurnoverBox_SafetyRasterSignal).Equals(IO_VALUE.HIGH))
{
SecurityAccessReset();
}
}
}
else
{
if (CurrSecurityAccess.Equals(1))
{
{
SecurityAccessReset();
}
}
}
}
catch (Exception ex)
{
LogUtil.error(Name + " 出错 :" + ex.ToString());
}
}
private void SecurityAccessStop()
{
if (!baseConfig.DIList.ContainsKey(IO_Type.Shelf_SafetyRasterSignal))
{
return;
}
if (!baseConfig.DIList.ContainsKey(IO_Type.TurnoverBox_SafetyRasterSignal))
{
return;
}
CurrSecurityAccess = 1;
if (alarmType > (AlarmType.IoSingleTimeOut))
{
return;
}
//ConfigIO di = baseConfig.DIList[IO_Type.SafetyRasterSignal];
//LogUtil.info($"{Name }光栅被遮挡,停止当前运动{MoveInfo.MoveType},MoveStop={MoveStop},报警急停");
//SetWarnMsg("光栅被遮挡,报警急停");
// Alarm(AlarmType.SuddenStop);
MoveStop = true;
BatchMove.MoveStop = true;
string msg = "";
if (MoveInfo.MoveType.Equals(MoveType.None))
{
SetWarnMsg("光栅被遮挡,暂停运动");
LogUtil.info($"{Name}光栅被遮挡,暂停运动,MoveStop={MoveStop},{msg},稍后复位");
}
else
{
SetWarnMsg("光栅被遮挡,暂停当前运动");
LogUtil.info($"{Name}光栅被遮挡,停止当前运动{MoveInfo.MoveType},{MoveInfo.MoveStep},{msg},稍后复位");
}
}
private void SecurityAccessReset()
{
if (!baseConfig.DIList.ContainsKey(IO_Type.Shelf_SafetyRasterSignal))
{
return;
}
if (!baseConfig.DIList.ContainsKey(IO_Type.TurnoverBox_SafetyRasterSignal))
{
return;
}
CurrSecurityAccess = 0;
MoveStop = false;
BatchMove.MoveStop = false;
//ConfigIO di = baseConfig.DIList[IO_Type.SafetyRasterSignal];
if (alarmType > (AlarmType.IoSingleTimeOut))
{
return;
}
//光栅恢复处理
if (WarnMsg.Contains("光栅被遮挡,暂停"))
{
SetWarnMsg("");
}
if (!MoveInfo.MoveType.Equals(MoveType.None))
{
MoveInfo.LastSetpTime = DateTime.Now;
LogUtil.info($"{Name}光栅已恢复,恢复当前运动{MoveInfo.MoveType},{MoveInfo.MoveStep} ");
}
else
{
LogUtil.info($"{Name}光栅已恢复,取消暂停运动");
}
}
}
}