MainMachine.cs
40.0 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
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DeviceLibrary
{
public partial class MainMachine : IRobot
{
public string Name { get; set; } = "MIMO_G2";
private bool _canRunning = true;
public bool canRunning
{
get { return _canRunning; }
set
{
if (_canRunning != value)
{
Msg.setlogones();
}
_canRunning = value;
}
}
public bool isBusy { get; set; } = false;
public bool isAlarm { get; set; } = false;
public RunStatus runStatus { get; set; } = RunStatus.Stop;
public Robot_Config Config { get; set; }
public bool UserPause { get; set; } = false;
public MoveInfo ResetMoveInfo;
/// <summary>
/// 右侧移动信息
/// </summary>
public MoveInfo StringMoveInfo;
public MoveInfo ClampMoveInfo;
public MoveInfo StoreMoveInfo;
public MoveInfo AIOTMoveInfo;
public delegate void ProcessMsg(List<Msg> msg);
public event ProcessMsg ProcessMsgEvent;
internal AxisBean Middle_Axis;
public AxisBean UpDown_Axis;
internal AxisBean InOut_Axis;
internal AxisBean Comp_Axis;
internal AxisBean Batch_Axis;
internal AxisBean Clamp_Axis;
public LineRunMonitor Line;
public CylinderManger SingleDoor;
public CylinderManger FlipDoor;
public LiftMonitor MotorFlipDoorA;
public LiftMonitor MotorFlipDoorB;
public LiftMonitor StringDoor;
ReelTransport boxTransport;
public bool boxTransportIsFree { get => boxTransport.IsComplateOrFree; }
public event Action<string, StoreMoveType, bool> InOutEndProcessEvent;
ServerCommunication ServerCM;
/// <summary>
/// 开始运行的时间
/// </summary>
public DateTime StartTime { get; set; }
/// <summary>
/// 是否在急停中
/// </summary>
public bool isInSuddenDown = false;
/// <summary>
/// 是否启用上料提升轴的料叉检测
/// </summary>
public bool EnableBatchFixCheck { get { return ConfigAppSettings.GetValue("Swicth_BatchFixCheck", false, "是否启用上料提升轴的料叉检测"); } }
public MainMachine(Robot_Config _config)
{
Config = _config;
crc.LanguageChangeEvent += Crc_LanguageChangeEvent;
StringMoveInfo = new MoveInfo($"料串进出机构");
StringMoveInfo.SetStateDelegate(StringProcessState);
ClampMoveInfo = new MoveInfo($"取放料机构");
ClampMoveInfo.SetStateDelegate(ClampState);
StoreMoveInfo = new MoveInfo($"进出库调度");
StoreMoveInfo.SetStateDelegate(StoreState);
ResetMoveInfo = new MoveInfo($"重置");
AIOTMoveInfo = new MoveInfo($"出入库测试");
#region 初始化led灯
RunningLed = new Led(Config.DOList[IO_Type.Run_Led].GetIOAddr(), LedColor.green);
StandbyLed = new Led(Config.DOList[IO_Type.Standby_Led].GetIOAddr(), LedColor.yellow);
AlarmLed = new Led(Config.DOList[IO_Type.Alarm_Led].GetIOAddr(), LedColor.red);
//NG_Led = new Led(Config.DOList[IO_Type.MaterialNG_Led].GetIOAddr());
#endregion
#region 初始化伺服轴
Middle_Axis = new AxisBean(Config.Middle_Axis, Name);
Middle_Axis.interference += Middle_Axis_interference;
UpDown_Axis = new AxisBean(Config.UpDown_Axis, Name);
UpDown_Axis.interference += UpDown_Axis_interference;
InOut_Axis = new AxisBean(Config.InOut_Axis, Name);
Comp_Axis = new AxisBean(Config.Comp_Axis, Name);
Batch_Axis = new AxisBean(Config.Batch_Axis, Name);
Clamp_Axis = new AxisBean(Config.Clamp_Axis, Name);
Clamp_Axis.interference += Clamp_Axis_interference;
Crc_LanguageChangeEvent(null, EventArgs.Empty);
#endregion
Line = new LineRunMonitor($"料串进出机构", Config.DOList[IO_Type.LineRun].GetIOAddr(), Config.DOList[IO_Type.LineRev].GetIOAddr());
SingleDoor = new CylinderManger($"单料门", IO_Type.NGDoor_Open, IO_Type.NGDoor_Close);
//检测翻板门是否为鸣志点击伺服控制
if (Config.FlipDoor_L_Axis == null && Config.FlipDoor_R_Axis == null)
{
FlipDoor = new CylinderManger($"翻板托盘", IO_Type.ReelFlipDoor_Work, IO_Type.ReelFlipDoor_Home);
var c = RobotManage.Config.configList.Find(x => x.ProName == "FlipDoorSpeed");
if (c != null)
RobotManage.Config.configList.Remove(c);
LogUtil.info("加载翻板门类型为:气缸");
}
else if (Config.FlipDoor_L_Axis != null && Config.FlipDoor_R_Axis != null)
{
RobotManage.Config.DOList.Remove(IO_Type.ReelFlipDoor_Work);
RobotManage.Config.DOList.Remove(IO_Type.ReelFlipDoor_Home);
MotorFlipDoorB = new LiftMonitor(IO_Type.ReelFlipDoor_L_Home, IO_Type.ReelFlipDoor_L_Work, IO_Type.SafetyLightCurtains, null, new AxisBean(Config.FlipDoor_L_Axis, Name), Config.FlipDoorLength, Config.FlipDoorLength_speed, 0, "B翻转门");
MotorFlipDoorA = new LiftMonitor(IO_Type.ReelFlipDoor_R_Home, IO_Type.ReelFlipDoor_R_Work, IO_Type.SafetyLightCurtains, null, new AxisBean(Config.FlipDoor_R_Axis, Name), Config.FlipDoorLength, Config.FlipDoorLength_speed, 0, "A翻转门");
MotorFlipDoorB.SlowAftPause = true;
MotorFlipDoorB.SlowAftPause = true;
LogUtil.info("加载翻板门类型为:步进");
}
else
{
throw new Exception("料仓翻板门配置错误");
}
//检测料串门是否为鸣志电机控制
if (Config.StringDoor_Axis != null)
{
RobotManage.Config.DOList.Remove(IO_Type.StringDoor_Open);
RobotManage.Config.DOList.Remove(IO_Type.StringDoor_Close);
var sf = "";
if (ConfigHelper.Config.Get("Device_IO_X08IsStringDoor_SafetyLightCurtains", false))
sf = IO_Type.AGV_OnPosition;
StringDoor = new LiftMonitor(IO_Type.StringDoor_Open, IO_Type.StringDoor_Close, sf, IO_Type.StringDoor_Axis_Break, new AxisBean(Config.StringDoor_Axis, Name), Config.StringDoorLength, Config.StringDoorLength_speed, 0, "折叠门");
StringDoor.DownOverTimeMS = ConfigHelper.Config.Get("Device_StringDoor_DownOverTimeMS", 0);
StringDoor.UpOverTimeMS = ConfigHelper.Config.Get("Device_StringDoor_UpOverTimeMS", 0);
StringDoor.ResumeWaitTimeSec = 5;
LogUtil.info("加载料串门类型为:步进");
}
else
LogUtil.info("加载料串门类型为:气缸");
if (!ConfigHelper.Config.Get("Device_IO_X08IsStringDoor_SafetyLightCurtains", false))
{
RobotManage.Config.DIList.Remove(IO_Type.AGV_OnPosition);
}
if (ConfigHelper.Config.Get("Device_Disable_DoorSafeCheck", false))
{
RobotManage.Config.DIList.Remove(IO_Type.LeftDoorClose_Check);
RobotManage.Config.DIList.Remove(IO_Type.RightDoorClose_Check);
RobotManage.Config.DIList.Remove(IO_Type.BackDoorClose_Check);
RobotManage.Config.DOList.Remove(IO_Type.DoorSafe_Disable);
}
if (!ConfigHelper.Config.Get("Device_IO_HasX29", true))
{
RobotManage.Config.DIList.Remove(IO_Type.NGDoor_Tray_Check);
}
if (!ConfigHelper.Config.Get("Device_IO_HasX20", true))
{
RobotManage.Config.DIList.Remove(IO_Type.WidthCheck_15);
}
boxTransport = new ReelTransport(Config, this);
boxTransport.InOutEndProcessEvent += delegate (string posid, StoreMoveType storeMoveType, bool arg4)
{
InOutEndProcessEvent?.Invoke(posid, storeMoveType, arg4);
};
//BoxTransport_InOutEndProcessEvent;
//ProcessMsgEvent += MainMachine_ProcessMsgEvent;
ConfigHelper.Config.Get("Device_Disable_StringDoor", false);
AlarmBuzzer.SetOnOffAction(() => { IOMove(IO_Type.Alarm_Buzzer, IO_VALUE.HIGH); }, () => { IOMove(IO_Type.Alarm_Buzzer, IO_VALUE.LOW); });
IOMonitor.RegisterIO(IO_Type.SuddenStop_BTN, Config, IO_VALUE.LOW, SuddenStop_BTN, 2500, 100);
IOMonitor.RegisterIO(IO_Type.Reset_BTN, Config, IO_VALUE.HIGH, Reset_BTN, 2500, 100);
IOMonitor.RegisterIO(IO_Type.AutoRun_Single, Config, IO_VALUE.HIGH, Run_BTN, 2500, 100);
IOMonitor.RegisterIO(IO_Type.SafetyLightCurtains, Config, IO_VALUE.LOW, DeviceSuddenStop, 1, 1);
LedProcessInit();
ConfigHelper.Config.Get("CamTestReel_Ability", false);
ConfigHelper.Config.Set("CamTestReel_debug", false);
ConfigHelper.Config.Get("Device_1315_ReelHeight_Compensation", 0);
initAgv();
ServerCM = new ServerCommunication();
}
private void Crc_LanguageChangeEvent(object sender, EventArgs e)
{
StringMoveInfo.Name = crc.GetString(L.string_inout_equipment, "料串进出机构");
ClampMoveInfo.Name = crc.GetString(L.clamp_equipment, "取放料机构");
StoreMoveInfo.Name = crc.GetString(L.store_manage_equipment, "进出库调度");
ResetMoveInfo.Name = crc.GetString(L.reset_equipment, "重置");
AIOTMoveInfo.Name = crc.GetString(L.autotest_inout_equipment, "出入库测试");
}
private (bool, string) Clamp_Axis_interference(int from, int to)
{
if (to > Config.Clamp_P3)
{
if (IOValue(IO_Type.ReelFlipDoor_L_Home).Equals(IO_VALUE.HIGH) && IOValue(IO_Type.ReelFlipDoor_R_Home).Equals(IO_VALUE.HIGH))
return (false, "");
else
return (true, crc.GetString(L.Clamp_Axis_interference_01, "翻板门不在垂直端,不允许下降取料轴"));
if (IOValue(IO_Type.StringPosChecker_Home).Equals(IO_VALUE.HIGH))
return (false, "");
else
return (true, crc.GetString(L.Clamp_Axis_interference_02, "上料定位臂不在避让端,不允许下降取料轴"));
}
else if (to >= Config.Clamp_P3)
{
if (IOValue(IO_Type.ReelFlipDoor_L_Home).Equals(IO_VALUE.HIGH) && IOValue(IO_Type.ReelFlipDoor_R_Home).Equals(IO_VALUE.HIGH))
return (false, "");
else
return (true, crc.GetString(L.Clamp_Axis_interference_03, "翻板门不在垂直端,不允许下降取料轴"));
}
return (false, "");
}
private (bool, string) Middle_Axis_interference(int from, int to)
{
if (RobotManage.DisableUpdownProtect)
return (false, "");
if (InOut_Axis.IsInPosition(Config.InOut_P1))
return (false, "");
return (true, crc.GetString(L.Middle_Axis_interference_01, "进出轴不在待机点时无法移动旋转轴"));
}
private (bool, string) UpDown_Axis_interference(int from, int to)
{
if (RobotManage.DisableUpdownProtect)
return (false, "");
if (InOut_Axis.IsInPosition(Config.InOut_P1))
return (false, "");
return (true, crc.GetString(L.UpDown_Axis_interference_01, "进出轴不在待机点时无法移动升降轴"));
}
public bool hasAlarm = false;
/// <summary>
/// 整机启动变量,设置为false后将退出线程,只在停止时调用
/// </summary>
bool mstart = true;
public void Run()
{
mstart = true;
while (mstart)
{
try
{
canRunning = DeviceCheck();
if (canRunning)
{
BtnProcess();
canRunning = SafeCheck();
//if (canRunning && !lastSafeCheckStatus){}
//lastSafeCheckStatus = canRunning;
}
Thread.Sleep(200);
if (!canRunning || !mstart)
continue;
if (runStatus == RunStatus.Running)
{
ioMonitor();
AGVProcess();
StringProcess();
ClampProcess();
boxTransport.Process();
if (RobotManage.mainMachine.AutoInOutTest)
AutoInOutTestProcess();
else
StoreProcess();
}
else if (runStatus == RunStatus.HomeReset)
{
HomeReset();
}
}
catch (Exception ex)
{
Msg.add(ex.ToString(), MsgLevel.warning);
Msg.setlogones();
}
finally
{
var m = Msg.get();
ProcessMsgEvent?.Invoke(m);
ServerCM.ProcessMsg(m);
StoreStatus currnetstoreStatus = StoreStatus.None;
if (m.Find((aa) => aa.msgLevel == MsgLevel.alarm) == null)
{
hasAlarm = false;
AlarmBuzzer.OFF();
if (ServerCM.storeStatus != StoreStatus.InStoreExecute
&& ServerCM.storeStatus != StoreStatus.OutStoreExecute
&& ServerCM.storeStatus != StoreStatus.ResetMove && ServerCM.storeStatus != StoreStatus.StoreOnline)
{
LogUtil.info($"test storeStatus is {ServerCM.storeStatus} change to StoreOnline");
currnetstoreStatus = StoreStatus.StoreOnline;
}
}
else
{
hasAlarm = true;
AlarmBuzzer.ON();
currnetstoreStatus = isInSuddenDown ? StoreStatus.SuddenStop : StoreStatus.Warning;
}
//ProcessMoveinfoEvent?.Invoke(MoveInfo.List);
if (!UserPause)
Msg.clear();
//else
// currnetstoreStatus = StoreStatus.Debugging;
if (currnetstoreStatus != StoreStatus.None)
ServerCM.storeStatus = currnetstoreStatus;
}
}
RobotManage.isRunning = false;
LogUtil.info("主线程已退出.");
}
public void Start()
{
ServerCM.StartConnectServer();
Run();
}
public void Stop()
{
LogUtil.info("开始停止系统2.");
mstart = false;
AutoInOutTest = false;
ServerCM.StopConnectServer();
Thread.Sleep(300);
Alarm(AlarmType.None);
StopMove(true);
IOMove(IO_Type.LineRun, IO_VALUE.LOW);
LedProcess(null);
}
public void BeginHomeReset(bool firstRun = false)
{
if (!firstRun)
{
StopMove();
Thread.Sleep(500);
}
OpenAllServo();
AxisBean.List.ForEach((x) => { AxisManager.AlarmClear(x.Config.DeviceName, x.Config.GetAxisValue()); });
Alarm(AlarmType.None);
runStatus = RunStatus.HomeReset;
ResetMoveInfo.NewMove(MoveStep.H01_HomeReset);
ResetMoveInfo.log("开始回原");
ResetMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
}
//强制回原
bool forceHome = true;
void HomeReset()
{
if (CheckWait(ResetMoveInfo))
return;
switch (ResetMoveInfo.MoveStep)
{
case MoveStep.H01_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H02_HomeReset_01);
ServerCM.storeStatus = StoreStatus.ResetMove;
if (IOValue(IO_Type.StringBack_Check).Equals(IO_VALUE.LOW) && IOValue(IO_Type.StringFront_Check).Equals(IO_VALUE.LOW))
{
ResetMoveInfo.log("复位时没有料串");
}
else if (!ConfigHelper.Config.Get("Device_IO_X08IsStringDoor_SafetyLightCurtains", false))
{
if (IOValue(IO_Type.StringFront_Check).Equals(IO_VALUE.HIGH))
{
Msg.add(crc.GetString(L.string_not_onposition, "回原时X09,X10信号异常,料串可能不在正确位置,请检查."), MsgLevel.alarm);//0429
RobotManage.UserPause($"回原时X09,X10信号异常,料串可能不在正确位置,请检查");
return;
}
}
if (EnableBatchFixCheck)
{
if (IOValue(IO_Type.StringBack_Check).Equals(IO_VALUE.HIGH))
{
if (IOValue(IO_Type.Laser_Location).Equals(IO_VALUE.LOW))
{
ResetMoveInfo.log($"料串未成功放入料叉上,请检查");
Msg.add(crc.GetString(L.bacth_no_fix, "料串未成功放入料叉上,请检查"), MsgLevel.warning);
RobotManage.UserPause(crc.GetString(L.bacth_no_fix, "料串未成功放入料叉上,请检查"), true);
return;
}
}
}
if (!ConfigHelper.Config.Get("Device_Disable_StringDoor", false))
StringDoorClose(null);
break;
case MoveStep.H02_HomeReset_01:
ResetMoveInfo.NextMoveStep(MoveStep.H02_HomeReset);
ResetMoveInfo.log("进出轴,批量轴回原,料串检测杆退回避让端");
InOut_Axis.HomeMove(ResetMoveInfo, forceHome);
Batch_Axis.HomeMove(null, forceHome);
Batch_Axis.MonitorAxisLoadRate(Setting_Init.Device_BatchMaxLoadRate);
CylinderMove(ResetMoveInfo, IO_Type.StringPosChecker_Home, IO_Type.StringPosChecker_Work, IO_VALUE.LOW);
Msg.add("", MsgLevel.info, ErrInfo.X09_Clear);
SingleDoor.ToLow(ResetMoveInfo);
break;
case MoveStep.H02_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H03_HomeReset);
ResetMoveInfo.log("夹爪轴回原");
Clamp_Axis.HomeMove(ResetMoveInfo, forceHome);
break;
case MoveStep.H03_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H04_HomeReset);
ResetMoveInfo.log("旋转轴,升降轴,回原,料叉P1待机点");
InOut_Axis.AbsMove(ResetMoveInfo, Config.InOut_P1, Config.InOut_P1_speed);
Middle_Axis.HomeMove(ResetMoveInfo, forceHome);
UpDown_Axis.HomeMove(ResetMoveInfo, forceHome);
Batch_Axis.HomeMove(ResetMoveInfo, forceHome);
Batch_Axis.MonitorAxisLoadRate(Setting_Init.Device_BatchMaxLoadRate);
//OpenFlipDoor(ResetMoveInfo);
break;
case MoveStep.H04_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H05_HomeReset);
ResetMoveInfo.log("夹爪轴,P1待机点");
Clamp_Axis.AbsMove(ResetMoveInfo, Config.Clamp_P1, Config.Clamp_P1_speed);
Line.LineRun("n", false, 5);
ResetMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
break;
case MoveStep.H05_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H06_HomeReset);
ResetMoveInfo.log("旋转轴,升降轴,到P1待机点");
Middle_Axis.AbsMove(ResetMoveInfo, Config.Middle_P1, Config.Middle_P1_speed);
UpDown_Axis.AbsMove(ResetMoveInfo, Config.UpDown_P1, Config.UpDown_P1_speed);
Batch_Axis.AbsMove(ResetMoveInfo, Config.Batch_P1, Config.Batch_P1_speed);
break;
case MoveStep.H06_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H07_HomeReset);
ResetMoveInfo.log("压紧轴回原");
Comp_Axis.HomeMove(ResetMoveInfo, forceHome);
break;
case MoveStep.H07_HomeReset:
if (GetWidth() > 0)
{
ResetMoveInfo.NextMoveStep(MoveStep.H08_HomeReset);
ResetMoveInfo.log("夹爪上有料盘,送到NG口");
}
else if (IOValue(IO_Type.ReelFlipDoor_L_Home).Equals(IO_VALUE.LOW) && IOValue(IO_Type.ReelFlipDoor_R_Home).Equals(IO_VALUE.LOW) && NGDoor_Tray_Test_Reel.HasValue && NGDoor_Tray_Test_Reel.Value)
{
ResetMoveInfo.NextMoveStep(MoveStep.H12_HomeReset);
ResetMoveInfo.log("反转托盘上有料盘,送到NG口");
}
else
{
ResetMoveInfo.NextMoveStep(MoveStep.HEND_HomeReset);
ResetMoveInfo.log("夹爪上上没有料盘");
}
break;
case MoveStep.H08_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H09_HomeReset);
CloseFlipDoor(ResetMoveInfo);
break;
case MoveStep.H09_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H10_HomeReset);
ResetMoveInfo.log("夹爪轴下降到NG托盘位置 p3");
Clamp_Axis.AbsMove(ResetMoveInfo, Config.Clamp_P3 - 50 * Config.Clamp_PoToMM, Config.Clamp_P3_speed);
break;
case MoveStep.H10_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H11_HomeReset);
ResetMoveInfo.log("释放夹爪");
CylinderMove(StringMoveInfo, IO_Type.Clamping_Relax, IO_Type.Clamping_Work, IO_VALUE.LOW);
break;
case MoveStep.H11_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H12_HomeReset);
ResetMoveInfo.log("收回夹爪轴到P1");
Clamp_Axis.AbsMove(ResetMoveInfo, Config.Clamp_P1, Config.Clamp_P1_speed);
break;
case MoveStep.H12_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H13_HomeReset);
ResetMoveInfo.log("打开NG口门");
//CylinderMove(null, IO_Type.NGDoor_Close, IO_Type.NGDoor_Open, IO_VALUE.HIGH);
SingleDoor.ToHigh(null);
break;
case MoveStep.H13_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H14_HomeReset);
var h = NGDoor_Tray_Test_Reel;
if (!h.HasValue)
{
Msg.add(crc.GetString(L.x29_low_no_reel, "检测相机打开失败."), MsgLevel.alarm);
}
else if (!h.Value)
{
Msg.add(crc.GetString(L.x29_low_no_reel, "传感器未检测到单料口料盘."), MsgLevel.alarm);
RobotManage.UserPause(crc.GetString("x29_low_no_reel", "传感器未检测到单料口料盘."));
}
//CylinderMove(ResetMoveInfo, IO_Type.NGDoor_Close, IO_Type.NGDoor_Open, IO_VALUE.HIGH);
SingleDoor.ToHigh(ResetMoveInfo);
break;
case MoveStep.H14_HomeReset:
h = NGDoor_Tray_Test_Reel;
if (!h.HasValue)
{
Msg.add(crc.GetString(L.x29_low_no_reel, "检测相机打开失败."), MsgLevel.alarm);
}
else
if (h.Value)
{
Msg.add(crc.GetString(L.x29_higt_has_reel, "系统启动检测到有无信息料盘,等待取走单料口料盘"), MsgLevel.alarm);
if (ConfigHelper.Config.Get("CamTestReel_Ability", false))
{
//ResetMoveInfo.NextMoveStep(MoveStep.H14_HomeReset);
//ResetMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
if (ConfigHelper.Config.Get("Device_ManualCloseSingleDoor", false))
RobotManage.UserPause(crc.GetString("please_take_ngdoor_reel", "等待取走单口料盘"));
}
else
{
RobotManage.UserPause($"系统启动检测到有无信息料盘,等待取走单料口料盘");
}
}
else
{
ResetMoveInfo.NextMoveStep(MoveStep.H15_HomeReset);
ResetMoveInfo.log("料盘已取走");
}
break;
case MoveStep.H15_HomeReset:
if (IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.LOW))
{
Msg.add(crc.GetString(L.wait_put_reel_into_ngdoor, "等待阻挡物离开光栅"), MsgLevel.warning);
}
else
{
ResetMoveInfo.NextMoveStep(MoveStep.H16_HomeReset);
}
break;
case MoveStep.H16_HomeReset:
h = NGDoor_Tray_Test_Reel;
if (!h.HasValue)
{
Msg.add(crc.GetString(L.x29_low_no_reel, "检测相机打开失败."), MsgLevel.alarm);
}
else
if (IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.HIGH) && h.Value)
{
ResetMoveInfo.log("NG口还是检测到料盘");
ResetMoveInfo.NextMoveStep(MoveStep.H14_HomeReset);
}
else if (IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.HIGH) && !h.Value)
{
ResetMoveInfo.NextMoveStep(MoveStep.HEND_HomeReset);
ResetMoveInfo.log("关门NG口门");
//CylinderMove(ResetMoveInfo, IO_Type.NGDoor_Close, IO_Type.NGDoor_Open, IO_VALUE.LOW);
SingleDoor.ToLow(ResetMoveInfo);
OpenFlipDoor(ResetMoveInfo);
}
else
{
Msg.add(crc.GetString(L.wait_put_reel_into_ngdoor, "等待阻挡物离开光栅"), MsgLevel.warning);
}
break;
case MoveStep.HEND_HomeReset:
forceHome = false;
StringMoveInfo.NewMove(MoveStep.Wait);
StoreMoveInfo.NewMove(MoveStep.Wait);
ClampMoveInfo.NewMove(MoveStep.Wait);
boxTransport.Reset();
ResetMoveInfo.log("回原完成");
ResetMoveInfo.EndMove();
OutSingleJobList.ClearLastPosid("");
OutStoreJobList.ClearLastPosid("");
if (IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH) && boxTransport.IsComplateOrFree && ClampMoveInfo.MoveStep == MoveStep.Wait)
{
StoreMoveInfo.NewMove(MoveStep.StoreOut_NGPre);
StoreMoveInfo.MoveParam.PosID = "NG";
StoreMoveInfo.MoveParam.PlateH = 56;
StoreMoveInfo.MoveParam.PlateW = 7;
StoreMoveInfo.MoveParam.IsNg = true;
StoreMoveInfo.MoveParam.NgMsg = crc.GetString(L.tray_detect_reel_01, "料叉传感器感应到有料,请人工确认");
StoreMoveInfo.log($"开始无信息料盘出库");
ServerCM.storeStatus = StoreStatus.OutStoreExecute;
CloseFlipDoor(StoreMoveInfo);
}
else if ((RobotManage.HasReelInFixPos(out ReelParam reelParam))
&& boxTransport.IsComplateOrFree
&& ClampMoveInfo.MoveStep == MoveStep.Wait && ConfigHelper.Config.Get("Device_Use_Fixpos", false)
&& IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.LOW))
{
var pos = BoxStorePosition.GetFixPos(Config, reelParam);
if (pos != null)
{
LogUtil.info($"复位完成,校准库位出库:{pos.posid}");
RobotManage.mainMachine.AddSingleStoreTask(pos.posid, reelParam.PlateW, reelParam.PlateH);
RobotManage.ClearReelInFixPos();
CloseFlipDoor(StoreMoveInfo);
}
else
{
RobotManage.ClearReelInFixPos();
}
}
runStatus = RunStatus.Running;
ServerCM.storeStatus = StoreStatus.StoreOnline;
break;
}
}
//bool _IgnoreSafecheck = false;
public bool IgnoreSafecheck
{
get => IOValue(IO_Type.DoorSafe_Disable).Equals(IO_VALUE.HIGH); set
{
if (value)
{
IOMove(IO_Type.DoorSafe_Disable, IO_VALUE.HIGH);
}
else
{
IOMove(IO_Type.DoorSafe_Disable, IO_VALUE.LOW);
}
}
}
public bool IgnoreGratingSignal = false;
bool lastSafeCheckStatus = true;
bool lastStringSafetyStatus = true;
/// <summary>
/// 料串门光栅触发处理方式
/// </summary>
int stringdoorSafetyProcStrategy = ConfigAppSettings.GetValue("StringDoor_SafetyLightCurtainsProcStrategy", 1, "料串门光栅触发处理方式:0-设备急停;1-仅料串门停止");
bool SafeCheck()
{
bool ok = true;
var ignorestring = "[" + crc.GetString(L.ignored, "已忽略") + "]";
//if (IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.LOW))
//{
// if (!IgnoreSafecheck)// && IOValue(IO_Type.NGDoor_Open).Equals(IO_VALUE.HIGH))
// {
// ok = false;
// DeviceSuddenStop();
// }
// Msg.add(crc.GetString(L.SafetyLight_is_block, "安全光栅被遮挡") + (ok ? ignorestring : ""), MsgLevel.warning);
//}
if (ConfigHelper.Config.Get("Device_IO_X08IsStringDoor_SafetyLightCurtains", false))
{
//IOValue(IO_Type.StringFront_Check).Equals(IO_VALUE.LOW) &&
if (IOValue(IO_Type.AGV_OnPosition).Equals(IO_VALUE.LOW) && IOValue(IO_Type.StringDoor_Close).Equals(IO_VALUE.LOW))
{
Msg.add("料串门光栅被遮挡", MsgLevel.warning);
if (lastStringSafetyStatus)
{
lastStringSafetyStatus = false;
StringDoor.Pause();
}
if (stringdoorSafetyProcStrategy == 0)
{
ok = false;
DeviceSuddenStop();
}
}
else if (IOValue(IO_Type.AGV_OnPosition).Equals(IO_VALUE.HIGH))
{
if (stringdoorSafetyProcStrategy == 1)
{
if (!lastStringSafetyStatus)
{
StringDoor.ResumeSingle();
lastStringSafetyStatus = true;
}
}
}
}
if (!ConfigHelper.Config.Get("Device_Disable_DoorSafeCheck", false))
{
if (IOValue(IO_Type.LeftDoorClose_Check).Equals(IO_VALUE.LOW))
{
if (!IgnoreSafecheck)
{
ok = false;
DeviceSuddenStop();
}
Msg.add(crc.GetString(L.left_safedoor_not_close, "左侧防护门没有关闭") + (ok ? ignorestring : ""), MsgLevel.warning);
}
if (IOValue(IO_Type.RightDoorClose_Check).Equals(IO_VALUE.LOW))
{
if (!IgnoreSafecheck)
{
ok = false;
DeviceSuddenStop();
}
Msg.add(crc.GetString(L.right_safedoor_not_close, "右侧防护门没有关闭") + (ok ? ignorestring : ""), MsgLevel.warning);
}
if (IOValue(IO_Type.BackDoorClose_Check).Equals(IO_VALUE.LOW))
{
if (!IgnoreSafecheck)
{
ok = false;
DeviceSuddenStop();
}
Msg.add(crc.GetString(L.back_safedoor_not_close, "后侧防护门没有关闭") + (ok ? ignorestring : ""), MsgLevel.warning);
}
}
if (!lastSafeCheckStatus && ok)
{
if (!AxisBean.RunMultiAxis(true, out string msg, AxisBean.List))
{
ok = false;
Msg.add(msg, MsgLevel.warning);
}
SafetyDevice.ResumeAll();
//StringDoor.ResumeSingle();
}
lastSafeCheckStatus = ok;
return ok;
}
void DeviceSuddenStop()
{
if (lastSafeCheckStatus)
{
AxisBean.StopMultiAxis(AxisBean.List);
MoveInfo.List.ForEach((m) => { m.CanWhileCount = 5; });
SafetyDevice.PauseAll();
StringDoor.Pause();
if (runStatus == RunStatus.HomeReset)
{
ResetMoveInfo.NewMove(MoveStep.H01_HomeReset);
}
}
}
//bool lastStringDoorSafetyStatus = true;
//void StringDoorSuddenStop()
//{
// if (lastStringDoorSafetyStatus)
// {
// AxisBean axis = StringDoor.axisBean;
// AxisBean.StopMultiAxis(new List<AxisBean> { axis });
// StringDoor.Pause();
// if (runStatus == RunStatus.HomeReset)
// {
// ResetMoveInfo.NewMove(MoveStep.H01_HomeReset);
// }
// lastStringDoorSafetyStatus = false;
// }
//}
/// <summary>
/// 最后一次气压检测变为0的时间
/// </summary>
DateTime lastAirCloseTime = DateTime.MinValue;
internal DateTime checkAlarmTime = DateTime.Now;
bool SafetyLightStop
{
get
{
if (RobotManage.Config.DOList.ContainsKey(IO_Type.DoorSafe_Disable))
return IOValue(IO_Type.DoorSafe_Disable).Equals(IO_VALUE.LOW) && IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.LOW);
else
return IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.LOW);
}
}
public bool DeviceCheck()
{
bool ok = true;
isInSuddenDown = IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW);
if (SafetyLightStop)
{
DeviceSuddenStop();
lastSafeCheckStatus = false;
Msg.add(crc.GetString(L.SafetyLight_is_block, "安全光栅被遮挡"), MsgLevel.warning);
return false;
}
if (UserPause)
{
Msg.add(crc.GetString(L.system_pause, "系统暂停"), MsgLevel.warning);
DeviceSuddenStop();
lastSafeCheckStatus = false;
ok = false;
return ok;
}
else if (isInSuddenDown)
{
Alarm(AlarmType.SuddenStop);
Msg.add(crc.GetString(L.in_suddenstop, "急停中"), MsgLevel.alarm);
DeviceSuddenStop();
lastSafeCheckStatus = false;
ok = false;
}
else if (alarmType != AlarmType.None)
{
//if (IOValue(IO_Type.Right_BTN).Equals(IO_VALUE.HIGH) || IOValue(IO_Type.Left_BTN).Equals(IO_VALUE.HIGH))
//{
// Alarm(AlarmType.None);
//}
//else
{
Msg.add(crc.GetString(L.system_need_reset, "系统需要重置"), MsgLevel.alarm, ErrInfo.SuddenStop);
ok = false;
}
}
if (RobotManage.InoutDebugMode)
{
Msg.add(crc.GetString(L.store_inout_debug_mode, "进出库调试模式"), MsgLevel.info);
//ok = false;
}
if (IOValue(IO_Type.Airpressure_Check).Equals(IO_VALUE.LOW))
{
if (lastAirCloseTime == DateTime.MinValue)
lastAirCloseTime = DateTime.Now;
TimeSpan span = DateTime.Now - lastAirCloseTime;
if (span.TotalSeconds > RobotManage.Config.AirCheckSeconds)
{
ok = false;
Msg.add(crc.GetString(L.airpressure_not_enough, "气压不足"), MsgLevel.warning);
}
}
else
{
lastAirCloseTime = DateTime.MinValue;
}
if (alarmType != AlarmType.SuddenStop)
{
TimeSpan span = DateTime.Now - checkAlarmTime;
if (span.TotalSeconds > 2)
{
checkAlarmTime = DateTime.Now;
foreach (ConfigMoveAxis configMoveAxis in Config.moveAxisList)
{
if (AxisManager.GetAlarmStatus(configMoveAxis.DeviceName, configMoveAxis.GetAxisValue()) == 1)
{
Task.Delay(100).Wait();
if (!SafetyLightStop && lastSafeCheckStatus)
{
Msg.add(crc.GetString(configMoveAxis.ProName, configMoveAxis.Explain) + $"[{configMoveAxis.GetAxisValue()}]:"
+ crc.GetString(L.motion_alarm, "运动报警"), MsgLevel.alarm, ErrInfo.SuddenStop);
ok = false;
}
LogUtil.error(string.Join(",", HuichuanLibrary.HCBoardManager.GetAxisErrorDetail(configMoveAxis.GetAxisValue())));
}
}
}
}
return ok;
}
public void IgnoreX09()
{
boxTransport.IgnoreX09 = true;
LogUtil.info("按下X09忽略");
}
}
}