AutomaticBaiting.cs
43.3 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
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace OnlineStore.DeviceLibrary
{
public partial class AutomaticBaiting
{
public static string TimeOut = "超时";
/// <summary>
/// 操作人员是否拿走料盘
/// </summary>
public static bool IsGetTrayGo = false;
public static bool IsWaitTragGo = false;
public static IO_VALUE WaitIoValue = IO_VALUE.LOW;
/// <summary>
/// 0=未知。1=门打开,2=门关闭
/// </summary>
public static int DoorStatus = 2;
private static int LastHeight = 0;
private static int LastWidth = 0;
private static List<string> LastCodeList = new List<string>();
public static string LastCode = "";
private static string LastPosId = "";
public static int AxisChangeValue = ConfigAppSettings.GetIntValue(Setting_Init.AxisChangeValue);
// public static string WarnMsg = "";
public static string CodeMsg = "";
public static string Name = "批量上下料 ";
public static StoreMoveInfo StoreMove = null;
public static StoreRunStatus AutoBaitingStatus = StoreRunStatus.Wait;
public static bool IsNeedStartInout = false;
public static bool IsNeedAxisHome = true;
/// <summary>
/// 记录没开门状态下,已经出库的数量
/// </summary>
public static int BatchOutStoreCount = 0;
/// <summary>
/// 累计出库的高度
/// </summary>
public static int BatchOutStoreHeight = 0;
public static int BatchInStoreCount = 0;
public static int BatchInStoreHeight = 0;
public static WarnInfo WarnObj = new WarnInfo();
public static void SetWarnMsg(string code, params string[] param)
{
if (code.Equals(""))
{
// WarnMsg =msg;
WarnObj.WarnMsg = "";
WarnObj.MsgCode = "";
WarnObj.MsgParam = null;
}
else
{
// WarnMsg = String.Format(msg, param);
WarnObj.WarnMsg = ResourceControl.GetString(code, param);
WarnObj.MsgCode = code;
WarnObj.MsgParam = param;
}
}
public static void SetWarnMsgAndLog(string type, params string[] param)
{
SetWarnMsg(type, param);
LogUtil.error("AutomaticBaiting WarnObj: Type[" + WarnObj.MsgCode + "]Msg[" + WarnObj.WarnMsg + "]");
}
public static void SetWaitWarnMsg(string myType, string type, params string[] param)
{
WarnObj.WarnMsg = myType;
WarnObj.MsgCode = type;
WarnObj.MsgParam = param;
}
/// <summary>
/// 初始化数据
/// </summary>
public static void Init()
{
StoreMove = new StoreMoveInfo(Name);
}
/// <summary>
/// 定时处理
/// </summary>
public static void TimerProcess()
{
try
{
if (AutoBaitingStatus >= StoreRunStatus.Wait)
{
if (StoreMove.MoveType.Equals(StoreMoveType.StoreReset))
{
ResetProcess();
}
else if (StoreMove.MoveType.Equals(StoreMoveType.InStore))
{
InStoreProcess();
}
else if (StoreMove.MoveType.Equals(StoreMoveType.OutStore))
{
OutStoreProcess();
}
}
}
catch (Exception ex)
{
LogUtil.error(Name + "出错:" + ex.StackTrace);
}
}
/// <summary>
/// 判断是否可以启动
/// </summary>
/// <returns></returns>
public static string CanStart()
{
string msg = "";
//需要判断门关闭
if (!DoorIsClose())
{
// msg = (ResourceControl.GetString(ResourceControl.CloseError, "锁门失败:请先关闭上料机构")); ;
return ResourceControl.CloseError;
}
return msg;
}
public static void ClearOutStoreInfo()
{
BatchOutStoreCount = 0;
BatchOutStoreHeight = 0;
BatchInStoreCount = 0;
BatchInStoreHeight = 0;
}
public static void ClearInStoreInfo()
{
LastCode = "";
LastCodeList = new List<string>();
LastPosId = "";
LastHeight = 0;
LastWidth = 0;
}
public static void StopRun()
{
// IOManager.IOMove(IO_Type.SuckingDisc_Work, IO_VALUE.LOW);
AutomaticBaiting.CylinderMove(IO_Type.Clamping_Work, IO_Type.Clamping_Relax, null);
ClearInStoreInfo();
ClearOutStoreInfo();
}
public static void StopMove()
{
BatchAxisController.StopCheck();
StoreMove.EndMove();
ClearInStoreInfo();
// IOManager.IOMove(IO_Type.SuckingDisc_Work, IO_VALUE.LOW);
AutomaticBaiting.CylinderMove(IO_Type.Clamping_Work, IO_Type.Clamping_Relax, null);
CylinderMove(IO_Type.ClampingDisc_Up, IO_Type.ClampingDisc_Down, false);
BatchDoorClose(false);
}
/// <summary>
/// 复位过程调用此方法
/// </summary>
/// <returns></returns>
public static bool StartReset()
{
return Reset(true, false);
}
public static bool Reset(bool isNeedHome, bool isNeedInout)
{
string msg = CanStart();
if (!String.IsNullOrEmpty(msg))
{
LogUtil.info(Name + "复位失败:" + msg);
return false;
}
if (StoreManager.Store.alarmType.Equals(StoreAlarmType.BatchAlarm) ||
StoreManager.Store.alarmType.Equals(StoreAlarmType.BatchAxisAlarm) || StoreManager.Store.alarmType.Equals(StoreAlarmType.BatchIoTimeOut))
{
LogUtil.info(Name + " 复位前,清理报警【" + StoreManager.Store.alarmType + "】");
StoreManager.Store.alarmType = StoreAlarmType.None;
IOManager.IOMove(IO_Type.Buzzer_Sign, IO_VALUE.LOW);
// WarnMsg = "";
SetWarnMsg("");
}
AutomaticBaiting.IsNeedStartInout = isNeedInout;
AutomaticBaiting.IsNeedAxisHome = isNeedHome;
if (!StoreMove.MoveType.Equals(StoreMoveType.None))
{
StopMove();
}
ClearInStoreInfo();
DoorStatus = 2;
AutoBaitingStatus = StoreRunStatus.Reset;
StoreMove.NewMove(StoreMoveType.StoreReset);
StoreMove.NextMoveStep(StoreMoveStep.AUTO_R00_Start);
LogUtil.info(Name + "开始复位,是否入库【" + AutomaticBaiting.IsNeedStartInout + "】,上料轴回原点【" + AutomaticBaiting.IsNeedAxisHome + "】");
return true;
}
private static void ResetProcess()
{
if (StoreMove.IsInWait)
{
CheckWait();
}
if (StoreMove.IsInWait)
{
return;
}
switch (StoreMove.MoveStep)
{
case StoreMoveStep.AUTO_R00_Start:
StoreMove.NextMoveStep(StoreMoveStep.AUTO_R01_CloseDoor);
//关闭门,轴回原点,检测
BatchDoorClose(true);
// IOManager.IOMove(IO_Type.SuckingDisc_Work, IO_VALUE.LOW);
AutomaticBaiting.CylinderMove(IO_Type.Clamping_Work, IO_Type.Clamping_Relax, StoreMove);
CylinderMove(IO_Type.ClampingDisc_Up, IO_Type.ClampingDisc_Down, true);
LogUtil.info(Name + "复位中:关闭门锁");
break;
case StoreMoveStep.AUTO_R01_CloseDoor:
StoreMove.NextMoveStep(StoreMoveStep.AUTO_R02_AutoAxisHome);
StoreMove.TimeOutSeconds = 120;
bool isClearAlarm = false;
if (ACServerManager.GetAlarmStatus(StoreManager.Config.Batch_Axis.DeviceName, StoreManager.Config.Batch_Axis.GetAxisValue()).Equals(1))
{
isClearAlarm = true;
LogUtil.debug(Name + "复位中:批量上下料轴清理报警");
ACServerManager.AlarmClear(StoreManager.Config.Batch_Axis.DeviceName, StoreManager.Config.Batch_Axis.GetAxisValue());
Thread.Sleep(100);
}
if (isClearAlarm || IsNeedAxisHome)
{
LogUtil.info(Name + "复位中:批量上下料轴原点返回");
ACAxisHomeMove(StoreManager.Config.Batch_Axis);
}
else
{
IsNeedInstore();
}
break;
case StoreMoveStep.AUTO_R02_AutoAxisHome:
IsNeedInstore();
break;
case StoreMoveStep.AUTO_R03_AutoAxisHome:
if (IOManager.IOValue(IO_Type.TrayCheck_LoadMaterial).Equals(IO_VALUE.LOW))
//if (ACServerManager.GetLimitPositiveSingle(StoreManager.Config.Batch_Axis).Equals(1))
{
LogUtil.info(Name + "复位中: 没有料盘,不需要上料,上料轴回原点");
StoreMove.NextMoveStep(StoreMoveStep.AUTO_R04_AutoBack);
StoreMove.TimeOutSeconds = 120;
ACAxisHomeMove(StoreManager.Config.Batch_Axis);
}
else
{
LogUtil.info(Name + "复位完成,有料盘,需要开始自动入料");
StoreMove.EndMove();
AutoBaitingStatus = StoreRunStatus.Runing;
//TODO
StartInOut();
}
break;
case StoreMoveStep.AUTO_R04_AutoBack:
Thread.Sleep(200);
StoreMove.NextMoveStep(StoreMoveStep.AUTO_R05_ToP2);
LogUtil.info(Name + "复位中:上料轴移动到p1点【" + StoreManager.Config.BatchAxis_P2 + "】");
ACAxisAbsMove(StoreManager.Config.Batch_Axis, StoreManager.Config.BatchAxis_P2, StoreManager.Config.BatchAxis_P2_Speed);
break;
case StoreMoveStep.AUTO_R05_ToP2:
LogUtil.info(Name + "复位完成");
StoreMove.EndMove();
AutoBaitingStatus = StoreRunStatus.Runing;
// WarnMsg = "";
SetWarnMsg("");
IsNeedStartInout = false;
break;
default: break;
}
}
#region 入库流程
private static void IsNeedInstore()
{
if (IsNeedStartInout)
{
StoreMove.NextMoveStep(StoreMoveStep.AUTO_R03_AutoAxisHome);
int speed = StoreManager.Config.BatchAxis_TargetSpeed;
LogUtil.info(Name + "复位中:检测是否有料盘,批量轴匀速上升【" + speed + "】");
ACAxisSpeedMove(StoreManager.Config.Batch_Axis, StoreManager.Config.BatchAxis_P3, speed, IO_Type.TrayCheck_LoadMaterial);
}
else
{
StoreMove.NextMoveStep(StoreMoveStep.AUTO_R05_ToP2);
LogUtil.info(Name + "复位中:上料轴移动到p2点【" + StoreManager.Config.BatchAxis_P2 + "】");
ACAxisAbsMove(StoreManager.Config.Batch_Axis, StoreManager.Config.BatchAxis_P2, StoreManager.Config.BatchAxis_P2_Speed);
}
}
public static bool StartInOut()
{
if ((!StoreManager.Store.storeRunStatus.Equals(StoreRunStatus.Runing)) ||
(!StoreManager.Store.StoreMove.MoveType.Equals(StoreMoveType.None)))
{
LogUtil.error(Name + " 启动入料失败,料仓不在待机状态" + StoreManager.Store.storeRunStatus + ",MoveType" + StoreManager.Store.StoreMove.MoveType);
return false;
}
if (AutoBaitingStatus == StoreRunStatus.Runing && StoreMove.MoveType.Equals(StoreMoveType.None))
{
AutoBaitingStatus = StoreRunStatus.Busy;
StoreMove.NewMove(StoreMoveType.InStore);
StoreMove.NextMoveStep(StoreMoveStep.AUTO_I01_Wait);
LogUtil.info(Name + "启动入料");
return true;
}
else
{
LogUtil.error(Name + " 启动入料失败, Status=" + AutoBaitingStatus + ",MoveType=" + StoreMove.MoveType);
return false;
}
}
private static int SuckingDisc_WorkCount = 0;
private static void InStoreProcess()
{
if (StoreMove.IsInWait)
{
CheckWait();
}
if (StoreMove.IsInWait)
{
return;
}
if (StoreMove.MoveStep.Equals(StoreMoveStep.AUTO_I01_Wait))
{
StoreMove.NextMoveStep(StoreMoveStep.AUTO_I02_MoveToUp);
if (IOManager.IOValue(IO_Type.TrayCheck_LoadMaterial).Equals(IO_VALUE.HIGH))
{
InStoreLog(" 已检测到料盘,轴不需要上升");
}
else
{
InStoreLog(" 轴上升到检测到料盘,速度【" + StoreManager.Config.Batch_Axis.TargetSpeed + "】");
ACAxisSpeedMove(StoreManager.Config.Batch_Axis, StoreManager.Config.BatchAxis_P3, StoreManager.Config.Batch_Axis.TargetSpeed, IO_Type.TrayCheck_LoadMaterial);
}
}
else if (StoreMove.MoveStep.Equals(StoreMoveStep.AUTO_I02_MoveToUp))
{
IsNeedScanCode();
}
else if (StoreMove.MoveStep.Equals(StoreMoveStep.AUTO_I03_ScanCode))
{
StoreMove.NextMoveStep(StoreMoveStep.AUTO_I04_SuckingDisc_Down);
InStoreLog(" 扫码结束,二维码【" + LastCode + "】 吸盘开始下降");
CylinderMove(IO_Type.ClampingDisc_Down, IO_Type.ClampingDisc_Up, true);
}
else if (StoreMove.MoveStep.Equals(StoreMoveStep.AUTO_I04_SuckingDisc_Down))
{
SuckingDiscWork();
}
else if (StoreMove.MoveStep.Equals(StoreMoveStep.AUTO_I05_SuckingDisc_Work))
{
// if (IOManager.IOValue(IO_Type.SuckingDisc_Air).Equals(IO_VALUE.HIGH))
if (IOManager.IOValue(IO_Type.Clamping_Work).Equals(IO_VALUE.HIGH) && IOManager.IOValue(IO_Type.Clamping_Relax).Equals(IO_VALUE.LOW))
{
StoreMove.NextMoveStep(StoreMoveStep.AUTO_I06_SuckingDisc_Up);
InStoreLog(" 吸盘上升");
//CylinderMove(IO_Type.ClampingDisc_Up, IO_Type.ClampingDisc_Down, false);
//StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.ClampingDisc_Down, IO_VALUE.LOW));
CylinderMove(IO_Type.ClampingDisc_Up, IO_Type.ClampingDisc_Down, true);
StoreMove.WaitList.Add(WaitResultInfo.WaitTime(1500));
}
else if (SuckingDisc_WorkCount < 3)
{
SuckingDiscWork();
}
else
{
//TODO 报警
//WarnMsg = ResourceControl.GetString(ResourceControl.XiLiaoError, "吸盘吸料失败");
SetWarnMsg(ResourceControl.XiLiaoError);
StoreManager.Store.Alarm(StoreAlarmType.BatchAlarm, WarnObj.WarnMsg, WarnObj.WarnMsg, StoreMoveType.InStore);
LogUtil.error(WarnObj.WarnMsg, 103);
}
}
else if (StoreMove.MoveStep.Equals(StoreMoveStep.AUTO_I06_SuckingDisc_Up))
{
bool needCheck = StoreManager.Config.DILIst.ContainsKey(IO_Type.Clamping_Check);
if (IOManager.IOValue(IO_Type.Clamping_Work).Equals(IO_VALUE.HIGH) && IOManager.IOValue(IO_Type.Clamping_Relax).Equals(IO_VALUE.LOW))
// if (IOManager.IOValue(IO_Type.SuckingDisc_Air).Equals(IO_VALUE.HIGH))
{
if ((!needCheck) || IOManager.IOValue(IO_Type.Clamping_Check).Equals(IO_VALUE.HIGH))
{
StoreMove.NextMoveStep(StoreMoveStep.AUTO_I07_BatchAxisUp);
InStoreLog(" 批量轴匀速上升【" + StoreManager.Config.BatchAxis_SlowSpeed + "】");
ACAxisSpeedMove(StoreManager.Config.Batch_Axis, StoreManager.Config.BatchAxis_P3, StoreManager.Config.BatchAxis_SlowSpeed, IO_Type.TrayCheck_LoadMaterial);
CylinderMove(IO_Type.ClampingDisc_Up, IO_Type.ClampingDisc_Down, true);
if (StoreManager.Store.Config.IsUse_Tray_Check.Equals(1))
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Fixture, IO_VALUE.LOW));
if (StoreManager.Config.Default_TrayWidth.Equals(7))
{
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.WidthCheck1, IO_VALUE.HIGH));
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.WidthCheck2, IO_VALUE.LOW));
}
else if (StoreManager.Config.Default_TrayWidth.Equals(13))
{
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.WidthCheck1, IO_VALUE.HIGH));
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.WidthCheck2, IO_VALUE.HIGH));
}
else if (StoreManager.Config.Default_TrayWidth.Equals(0))
{
}
}
else
{
SetWarnMsg(ResourceControl.NO_Clamping_Check);
StoreManager.Store.Alarm(StoreAlarmType.BatchAlarm, WarnObj.WarnMsg, WarnObj.WarnMsg, StoreMoveType.InStore);
LogUtil.error(Name + StoreMove.MoveStep + "入料: 吸盘上升后未检测到夹爪气缸料盘信号,吸取料盘失败", 106);
}
}
else
{
SetWarnMsg(ResourceControl.XiLiaoError);
StoreManager.Store.Alarm(StoreAlarmType.BatchAlarm, WarnObj.WarnMsg, WarnObj.WarnMsg, StoreMoveType.InStore);
LogUtil.error(Name + StoreMove.MoveStep + "入料: 吸盘上升后未检测到吸盘压力信号,吸取料盘失败", 105);
}
}
else if (StoreMove.MoveStep.Equals(StoreMoveStep.AUTO_I07_BatchAxisUp))
{
// if (IOManager.IOValue(IO_Type.SuckingDisc_Air).Equals(IO_VALUE.HIGH))
if (IOManager.IOValue(IO_Type.Clamping_Work).Equals(IO_VALUE.HIGH) && IOManager.IOValue(IO_Type.Clamping_Relax).Equals(IO_VALUE.LOW))
{
TimeSpan span = DateTime.Now - StoreMove.LastSetpTime;
//需要判断入库超时
if (StoreManager.Store.CanStarInOut())
{
LastWidth = StoreManager.Config.Default_TrayWidth;
if (LastWidth.Equals(0))
{
//料盘检测2亮为13寸盘,其他都认为是7寸盘
if (IOManager.IOValue(IO_Type.WidthCheck2).Equals(IO_VALUE.HIGH))
{
LastWidth = 13;
}
else if (IOManager.IOValue(IO_Type.WidthCheck1).Equals(IO_VALUE.HIGH))
{
LastWidth = 7;
}
else
{
LastWidth = 13;
}
}
LastHeight = GetHeight();
BatchInStoreCount++;
BatchInStoreHeight += LastHeight;
if (LastCode.Equals(""))
{
InStoreLog(" 未扫到二维码尺寸:【" + LastWidth + "*" + LastHeight + "】,将料盘送出,等待料盘拿走");
SendTrayOut();
}
else
{
StoreMove.NextMoveStep(StoreMoveStep.AUTO_I08_GetPosId);
LogUtil.debug(Name + StoreMove.MoveStep + "入料: 从服务器获取入库PosId,尺寸:【" + LastWidth + "*" + LastHeight + "】二维码【" + LastCode + "】");
GetInStorePosId(ProcessMsg());
StoreMove.WaitList.Add(WaitResultInfo.WaitTime(5000));
}
}
else if (span.TotalSeconds > 60)
{
StoreManager.Store.LoguStatus();
//一分钟还未开始,报警超时
// WarnMsg = "[" + StoreMove.MoveStep + "]" + ResourceControl.GetString(ResourceControl.TimeOut, "超时") + "[等待可以入库][" + Math.Round(span.TotalSeconds, 0) + "秒]";
SetWarnMsg(ResourceControl.WaitInstoreTimeOut, StoreMove.MoveStep + "", Math.Round(span.TotalSeconds, 0) + "");
LogUtil.error(WarnObj.WarnMsg, 105);
StoreManager.Store.Alarm(StoreAlarmType.BatchIoTimeOut, "", WarnObj.WarnMsg, StoreMove.MoveType);
}
}
else
{
//WarnMsg = ResourceControl.GetString(ResourceControl.XiLiaoError, "吸盘吸料失败");
SetWarnMsg(ResourceControl.XiLiaoError);
StoreManager.Store.Alarm(StoreAlarmType.BatchAlarm, ResourceControl.GetString(ResourceControl.XiLiaoError, "吸盘吸料失败"), WarnObj.WarnMsg, StoreMoveType.InStore);
LogUtil.error(Name + StoreMove.MoveStep + "入料: 吸盘上升后未检测到吸盘压力信号,吸取料盘失败", 105);
}
}
else if (StoreMove.MoveStep.Equals(StoreMoveStep.AUTO_I08_GetPosId))
{
//判断是否开始入库
if (StoreManager.Store.StoreMove.MoveType.Equals(StoreMoveType.InStore) || (!LastPosId.Equals("")))
{
StoreMove.NextMoveStep(StoreMoveStep.AUTO_I09_WaitTrayLeave);
InStoreLog(" 开始入库【" + LastPosId + "】,等待料盘拿走");
//StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SuckingDisc_Air, IO_VALUE.LOW));
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Clamping_Relax, IO_VALUE.HIGH));
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Clamping_Work, IO_VALUE.LOW));
}
else
{
InStoreLog(" 入库失败,尺寸:【" + LastWidth + "*" + LastHeight + "】将料盘送出,等待料盘拿走");
StoreManager.cancelPutInTask(LastSendCode);
SendTrayOut();
}
}
else if (StoreMove.MoveStep.Equals(StoreMoveStep.AUTO_I09_WaitTrayLeave))
{
if (StoreManager.Store.StoreMove.MoveType.Equals(StoreMoveType.None) ||
(StoreManager.Store.StoreMove.IsNeedInStore && StoreManager.Store.StoreMove.MoveStep >= StoreMoveStep.SI_09_MoveToBag))
{
IsNeedScanCode();
}
}
else if (StoreMove.MoveStep.Equals(StoreMoveStep.AUTO_I10_WaitTrayGo))
{
if (StoreManager.Store.CanStarInOut())
{
IsNeedScanCode();
}
}
else if (StoreMove.MoveStep.Equals(StoreMoveStep.AUTO_I11_BatchAxisHome))
{
//TODO
InStoreLog(" 已经没有料盘,批量上料结束");
StoreMove.EndMove();
AutoBaitingStatus = StoreRunStatus.Runing;
}
else
{
LogUtil.error(Name + StoreMove.MoveStep + "未找到步骤:" + StoreMove.MoveType);
}
}
private static int GetHeight()
{
//计算高度
EndMovePosition = ACServerManager.GetActualtPosition(StoreManager.Config.Batch_Axis);
if (EndMovePosition.Equals(-1))
{
EndMovePosition = ACServerManager.GetActualtPosition(StoreManager.Config.Batch_Axis);
}
int cha = EndMovePosition - StartMovePosition;
LastHeight = (int)Math.Ceiling(1F * (cha) / AxisChangeValue);
int addHeight = 0;
//如果检测信号未亮,极限亮了,需要补充高
if (IOManager.IOValue(IO_Type.TrayCheck_LoadMaterial).Equals(IO_VALUE.LOW)&& BatchAxisInP3())
{
addHeight = StoreManager.Config.LastTrayAddHeight;
}
LastHeight += addHeight;
string msg = Name + StoreMove.MoveStep + " 计算盘高:脉冲值 [" + EndMovePosition + "-" + StartMovePosition + "]=[" + cha + "] ,补充[" + addHeight + "]";
if (LastHeight < 0)
{
LastHeight = StoreManager.Config.GetDefaultHeight();
msg += "使用默认值[" + LastHeight + "]";
}
if (LastHeight <= 8) { LastHeight = 8;
msg += "小于8[" + LastHeight + "]";
}
else
{
msg += "计算后[" + LastHeight + "]";
//LastHeight = (int)Math.Floor(1F * (LastHeight-1) / 4) * 4;
LastHeight = LastHeight - LastHeight % 4;
}
LogUtil.info(msg + ",归类为" + LastHeight + "【" + LastCode + "】");
return LastHeight;
}
private static List<AutoStorePosition> AllPosList = null;
private static void SendTrayOut()
{
StoreMove.NextMoveStep(StoreMoveStep.AUTO_I10_WaitTrayGo);
StoreMove.TimeOutSeconds = 120;
string posId = StoreManager.Store.PositionNumList[0];
//盘先根据高低排序
if (AllPosList == null)
{
AllPosList = CSVPositionReader<AutoStorePosition>.getPositionList();
AllPosList = (from m in AllPosList orderby m.BagHeight ascending select m).ToList<AutoStorePosition>();
}
List<AutoStorePosition> okList = (from m in AllPosList where m.BagHeight >= LastHeight select m).ToList<AutoStorePosition>();
if (okList.Count > 0)
{
posId = okList[0].PositionNum;
}
else
{
LogUtil.info("未找到盘高>=" + LastHeight + "的库位");
}
bool result = StoreManager.Store.StartInStoreMove(new InOutStoreParam(LastCode, posId, LastHeight, LastWidth), true, false);
StoreMove.WaitList.Add(WaitResultInfo.WaitStoreRuning());
}
private static void SuckingDiscWork()
{
// IOManager.IOMove(IO_Type.SuckingDisc_Work, IO_VALUE.LOW);
StoreMove.NextMoveStep(StoreMoveStep.AUTO_I05_SuckingDisc_Work);
SuckingDisc_WorkCount++;
InStoreLog(" 吸盘开始第" + SuckingDisc_WorkCount + "次工作");
// IOManager.IOMove(IO_Type.SuckingDisc_Work, IO_VALUE.HIGH);
// StoreMove.WaitList.Add(WaitResultInfo.WaitTime(500));
// StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SuckingDisc_Air, IO_VALUE.HIGH));
CylinderMove(IO_Type.Clamping_Relax, IO_Type.Clamping_Work, StoreMove);
StoreMove.OneWaitCanEndStep = true;
}
private static void ClearTimeOut()
{
if (WarnObj.WarnMsg.Contains(TimeOut))
{
SetWarnMsg("");
}
}
private static void IsNeedScanCode()
{
ClearInStoreInfo();
SuckingDisc_WorkCount = 0;
//如果有超时异常,需要清理
if (StoreManager.Store.alarmType.Equals(StoreAlarmType.BatchIoTimeOut))
{
LogUtil.info(Name + StoreMove.MoveStep + " 扫码前清理超时报警【" + StoreManager.Store.alarmType + "】");
StoreManager.Store.alarmType = StoreAlarmType.None;
IOManager.IOMove(IO_Type.Buzzer_Sign, IO_VALUE.LOW);
ClearTimeOut();
}
// if (ACServerManager.GetLimitPositiveSingle(StoreManager.Config.Batch_Axis).Equals(0))
if (IOManager.IOValue(IO_Type.TrayCheck_LoadMaterial).Equals(IO_VALUE.HIGH))
{
StoreMove.NextMoveStep(StoreMoveStep.AUTO_I03_ScanCode);
InStoreLog(" 开始扫码,最多等待9000 ");
StoreMove.WaitList.Add(WaitResultInfo.WaitTime(9000));
StoreMove.WaitList.Add(WaitResultInfo.WaitCodeOK());
StoreMove.OneWaitCanEndStep = true;
GetCameraCode();
}
else
{
//判断是否到达目标位置
//int targetP = ACServerManager.GetActualtPosition(StoreManager.Config.Batch_Axis);
//int cha = Math.Abs(targetP - StoreManager.Config.BatchAxis_P3);
//if (cha < StoreManager.Config.Batch_Axis.CanErrorCountMax)
if(BatchAxisInP3())
{
StoreMove.NextMoveStep(StoreMoveStep.AUTO_I11_BatchAxisHome);
InStoreLog(" 批量轴到达P3,已经没有料盘,直接回待机点P2【" + StoreManager.Config.BatchAxis_P2 + "】");
ACAxisAbsMove(StoreManager.Config.Batch_Axis, StoreManager.Config.BatchAxis_P2, StoreManager.Config.BatchAxis_P2_Speed);
}
else
{
StoreMove.NextMoveStep(StoreMoveStep.AUTO_I02_MoveToUp);
InStoreLog(" 轴上升到检测到料盘,速度【" + StoreManager.Config.Batch_Axis.TargetSpeed + "】");
ACAxisSpeedMove(StoreManager.Config.Batch_Axis, StoreManager.Config.BatchAxis_P3, StoreManager.Config.Batch_Axis.TargetSpeed, IO_Type.TrayCheck_LoadMaterial);
}
}
}
private static bool BatchAxisInP3()
{
int targetP = ACServerManager.GetActualtPosition(StoreManager.Config.Batch_Axis);
int cha = Math.Abs(targetP - StoreManager.Config.BatchAxis_P3);
if (cha < StoreManager.Config.Batch_Axis.CanErrorCountMax)
{
return true;
}
return false;
}
#endregion
#region 出库流程
public static string StartOut()
{
if ((!StoreManager.Store.storeRunStatus.Equals(StoreRunStatus.Runing)) ||
(!StoreManager.Store.StoreMove.MoveType.Equals(StoreMoveType.None)))
{
LogUtil.error(Name + " 启动出料流程失败,料仓不在待机状态" + StoreManager.Store.storeRunStatus + ",MoveType" + StoreManager.Store.StoreMove.MoveType);
return "料仓不在待机状态" + StoreManager.Store.storeRunStatus + ",MoveType" + StoreManager.Store.StoreMove.MoveType;
}
if (AutoBaitingStatus == StoreRunStatus.Runing && StoreMove.MoveType.Equals(StoreMoveType.None))
{
AutoBaitingStatus = StoreRunStatus.Busy;
StoreMove.NewMove(StoreMoveType.OutStore);
StoreMove.NextMoveStep(StoreMoveStep.AUTO_O00_Wait);
LogUtil.info(Name + "启动出料");
return "";
}
else
{
LogUtil.error(Name + " 启动出料失败, Status=" + AutoBaitingStatus + ",MoveType=" + StoreMove.MoveType);
return "启动出料失败, Status = " + AutoBaitingStatus + ",MoveType = " + StoreMove.MoveType;
}
}
private static void OutStoreProcess()
{
if (StoreMove.IsInWait)
{
CheckWait();
}
if (StoreMove.IsInWait)
{
return;
}
//取料盘时,先检测X12,若X12不亮,直接打开门。
//若X12亮,先匀速下降到X12不亮,再开门。
if (StoreMove.MoveStep.Equals(StoreMoveStep.AUTO_O00_Wait))
{
if (IOManager.IOValue(IO_Type.OutCheck).Equals(IO_VALUE.LOW) && IOManager.IOValue(IO_Type.TrayCheck_LoadMaterial).Equals(IO_VALUE.LOW))
{
OutStoreLog("OutCheck=LOW ,直接打开门锁 ");
StoreMove.NextMoveStep(StoreMoveStep.AUTO_O02_WaitDoorOpen);
BatchDoorOpen(true);
StoreMove.WaitList.Add(WaitResultInfo.WaitTime(2000));
}
else
{
StoreMove.NextMoveStep(StoreMoveStep.AUTO_O01_BatchAxisDown);
OutStoreLog(": OutCheck=HIGH或TrayCheck_LoadMaterial=High,批量轴先匀速下降到P2 ");
ACAxisAbsMove(StoreManager.Config.Batch_Axis, StoreManager.Config.BatchAxis_P2, StoreManager.Config.BatchAxis_P2_Speed);
return;
//批量轴直接走到P2
AUTO_SA_Config Config = StoreManager.Config;
StoreMove.WaitList.Add(WaitResultInfo.WaitBatchAxisStop(Config.Batch_Axis, Config.BatchAxis_P2, IO_Type.OutCheck, IO_VALUE.LOW));
BatchAxisController.StartCheck(IO_Type.OutCheck, IO_VALUE.LOW);
StoreManager.Config.Batch_Axis.TargetPosition = Config.BatchAxis_P2;
ACServerManager.AbsMove(Config.Batch_Axis.DeviceName, Config.Batch_Axis.GetAxisValue(), Config.BatchAxis_OutMaxValue, Config.BatchAxis_P2_Speed, Config.Batch_Axis.AddSpeed, Config.Batch_Axis.DelSpeed);
}
}
else if (StoreMove.MoveStep.Equals(StoreMoveStep.AUTO_O01_BatchAxisDown))
{
OutStoreLog("批量轴已下降到P2 ,打开门锁 ");
StoreMove.NextMoveStep(StoreMoveStep.AUTO_O02_WaitDoorOpen);
BatchDoorOpen(true);
StoreMove.WaitList.Add(WaitResultInfo.WaitTime(2000));
}
else if (StoreMove.MoveStep.Equals(StoreMoveStep.AUTO_O02_WaitDoorOpen))
{
OutStoreLog("回到待机点完成,出料结束");
StoreMove.EndMove();
AutoBaitingStatus = StoreRunStatus.Runing;
return;
if (IOManager.IOValue(IO_Type.OutCheck).Equals(IO_VALUE.HIGH))
{
StoreMove.NextMoveStep(StoreMoveStep.AUTO_O03_WaitOutSingleLow);
OutStoreLog("等待出料检测信号关闭");
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.OutCheck, IO_VALUE.LOW));
}
else
{
StartSpeedOut();
}
}
else if (StoreMove.MoveStep.Equals(StoreMoveStep.AUTO_O03_WaitOutSingleLow))
{
StartSpeedOut();
}
else if (StoreMove.MoveStep.Equals(StoreMoveStep.AUTO_O04_SpeedMove))
{
//先判断极限是否亮
//int value = ACServerManager.GetLimitPositiveSingle(StoreManager.Config.Batch_Axis);
int currValue = ACServerManager.GetActualtPosition(StoreManager.Config.Batch_Axis);
int count = Math.Abs(currValue - StoreManager.Config.BatchAxis_OutMaxValue);
//if (IOManager.IOValue(IO_Type.BatchAxis_Limit).Equals(IO_VALUE.HIGH) || count < StoreManager.Config.Batch_Axis.CanErrorCountMax)
if ( count < StoreManager.Config.Batch_Axis.CanErrorCountMax)
{
StoreMove.NextMoveStep(StoreMoveStep.AUTO_O06_WaitDI12Low);
OutStoreLog("当前坐标【" + currValue + "】已到达高点 ,等待出料检测信号关闭(最多等待10秒)");
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.OutCheck, IO_VALUE.LOW));
StoreMove.WaitList.Add(WaitResultInfo.WaitTime(10000));
StoreMove.OneWaitCanEndStep = true;
}
else
{
//等待出料信号亮
StoreMove.NextMoveStep(StoreMoveStep.AUTO_O03_WaitOutSingleLow);
OutStoreLog("等待出料检测信号关闭");
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.OutCheck, IO_VALUE.LOW));
}
}
else if (StoreMove.MoveStep.Equals(StoreMoveStep.AUTO_O06_WaitDI12Low))
{
StoreMove.NextMoveStep(StoreMoveStep.AUTO_O07_WaitDown);
OutStoreLog("等待1秒后批量轴回P2点");
StoreMove.WaitList.Add(WaitResultInfo.WaitTime(1000));
}
else if (StoreMove.MoveStep.Equals(StoreMoveStep.AUTO_O07_WaitDown))
{
StoreMove.NextMoveStep(StoreMoveStep.AUTO_O08_BackToP2);
OutStoreLog("上料轴移动到p2点【" + StoreManager.Config.BatchAxis_P2 + "】");
ACAxisAbsMove(StoreManager.Config.Batch_Axis, StoreManager.Config.BatchAxis_P2, StoreManager.Config.BatchAxis_P2_Speed);
}
else if (StoreMove.MoveStep.Equals(StoreMoveStep.AUTO_O08_BackToP2))
{
//TODO
OutStoreLog("回到待机点完成,出料结束");
StoreMove.EndMove();
AutoBaitingStatus = StoreRunStatus.Runing;
}
else
{
LogUtil.error(Name + "未找到步骤:" + StoreMove.MoveType);
}
}
private static void StartSpeedOut()
{
StoreMove.NextMoveStep(StoreMoveStep.AUTO_O04_SpeedMove);
AUTO_SA_Config Config = StoreManager.Config;
OutStoreLog("轴上升到检测到出料信号,速度【" + Config.BatchAxis_SlowSpeed + "】,最大上升高度【" + Config.BatchAxis_OutMaxValue + "】");
//ACAxisSpeedMove(StoreManager.Config.Batch_Axis, StoreManager.Config.BatchAxis_SlowSpeed, IO_Type.OutCheck);
StoreMove.WaitList.Add(WaitResultInfo.WaitBatchAxisStop(Config.Batch_Axis, Config.BatchAxis_OutMaxValue, IO_Type.OutCheck));
BatchAxisController.StartCheck(IO_Type.OutCheck);
StoreManager.Config.Batch_Axis.TargetPosition = Config.BatchAxis_OutMaxValue;
int speed = Config.BatchAxis_SlowSpeed;
ACServerManager.AbsMove(Config.Batch_Axis.DeviceName, Config.Batch_Axis.GetAxisValue(), Config.BatchAxis_OutMaxValue, speed, Config.Batch_Axis.AddSpeed, Config.Batch_Axis.DelSpeed);
}
private static void StopOutProcess()
{
if (StoreMove.MoveType.Equals(StoreMoveType.OutStore))
{
LogUtil.error(Name + "正在出料中,停止出料流程");
ACServerManager.SuddenStop(StoreManager.Config.Batch_Axis);
StoreMove.EndMove();
AutoBaitingStatus = StoreRunStatus.Runing;
}
}
#endregion
public static bool DoorIsClose()
{
if (IOManager.IOValue(IO_Type.DoorClose_LoadMaterial).Equals(IO_VALUE.HIGH))
{
return true;
}
return false;
}
public static bool DoorCloseOK()
{
if (DoorIsClose())
{
if (IOManager.IOValue(IO_Type.BatchDoor_Close).Equals(IO_VALUE.HIGH) && IOManager.IOValue(IO_Type.BatchDoor_Open).Equals(IO_VALUE.LOW) &&
IOManager.IOValue(IO_Type.BatchDoor_Close2).Equals(IO_VALUE.HIGH) && IOManager.IOValue(IO_Type.BatchDoor_Open2).Equals(IO_VALUE.LOW))
{
return true;
}
}
return false;
}
/// <summary>
/// 是否可以打开门锁
/// </summary>
public static bool CanOpenBatchDoor()
{
if (!StoreMove.MoveType.Equals(StoreMoveType.None))
{
return false;
}
if (!StoreManager.Store.StoreMove.MoveType.Equals(StoreMoveType.None))
{
return false;
}
if (StoreManager.Store.storeRunStatus.Equals(StoreRunStatus.Runing) && AutoBaitingStatus.Equals(StoreRunStatus.Runing))
{
return true;
}
return false;
}
public static void BatchDoorOpen(bool isWait)
{
ClearInStoreInfo();
ClearOutStoreInfo();
DoorStatus = 1;
IOManager.IOMove(IO_Type.BatchDoor_Close, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.BatchDoor_Open, IO_VALUE.HIGH);
if (isWait)
{
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.BatchDoor_Close, IO_VALUE.LOW));
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.BatchDoor_Open, IO_VALUE.HIGH));
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.BatchDoor_Close2, IO_VALUE.LOW));
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.BatchDoor_Open2, IO_VALUE.HIGH));
}
}
public static bool BatchDoorClose(bool isWait)
{
if (!IOManager.IOValue(IO_Type.DoorClose_LoadMaterial).Equals(IO_VALUE.HIGH))
{
return false;
}
ClearInStoreInfo();
ClearOutStoreInfo();
DoorStatus = 2;
if (isWait)
{
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.BatchDoor_Open, IO_VALUE.LOW));
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.BatchDoor_Close, IO_VALUE.HIGH));
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.BatchDoor_Open2, IO_VALUE.LOW));
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.BatchDoor_Close2, IO_VALUE.HIGH));
}
IOManager.IOMove(IO_Type.BatchDoor_Open, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.BatchDoor_Close, IO_VALUE.HIGH);
return true;
}
private static void InStoreLog(string msg)
{
LogUtil.info(Name + " " + StoreMove.MoveStep + " " + "入料:" + msg);
}
private static void OutStoreLog(string msg)
{
LogUtil.info(Name + " " + StoreMove.MoveStep + " " + "出料:" + msg);
}
}
}