GetNextPoint.cs
63.7 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
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
using RCS.Model.ClientMoel;
using RCS.Model.Comm;
using RCS.Model.Entity;
using RCS.WinClient.Common;
using RCS.WinClient.PLC;
using System.Data;
namespace RCS.WinClient.Service
{
public class GetNextPoint
{
/// <summary>
/// 为小车获取后续动作点
/// </summary>
/// <param name="">子任务信息</param>
/// <param name="agv">小车信息</param>
/// <returns></returns>sonTask
public static List<ClientMotion> Motions(Base_SubTask sonTask, Base_Agv agv)
{
try
{
//储存此过程中添加的lock点,除此之外的都解除lock;
List<Base_Point> lockedPoint = new List<Base_Point>();
List<ClientMotion> motionList = new List<ClientMotion>();
Base_PathPoint currentPathPoint = sonTask.PathPointList.FirstOrDefault(a => a.Point.Barcode == agv.Barcode);
#region 提前避让
//if (agv.AgvNo == "A33_9002")
//{
// var lockPoint = App.PointList.FirstOrDefault(x => x.XLength < sonTask.EndPoint.YLength + agv.Length && x.LockedAgv != null && x.LockedAgv != agv);
// if (lockPoint != null && lockPoint.LockedAgv.AgvTask == null && lockPoint.LockedAgv.AgvState == EnumMsg.State.自动空闲)
// {
// //AGV高速行走的速度是每秒0.5米,车中心距离最后点位2米开始减速。那么如果辆车距离8米的话,要12秒后才开始减速,足够前面的车启动到高速了。
// if (lockPoint.LockedAgv.YLength < agv.YLength + 800)
// AvoidTask(agv, lockPoint.LockedAgv);
// }
//}
//if (agv.AgvNo == "A33_9001")
//{
// var lockPoint = App.PointList.FirstOrDefault(x => x.XLength > sonTask.EndPoint.YLength - agv.Length && x.LockedAgv != null && x.LockedAgv != agv);
// if (lockPoint != null && lockPoint.LockedAgv.AgvTask == null && lockPoint.LockedAgv.AgvState == EnumMsg.State.自动空闲)
// {
// //AGV高速行走的速度是每秒0.5米,车中心距离最后点位2米开始减速。那么如果辆车距离8米的话,要12秒后才开始减速,足够前面的车启动到高速了。
// if (lockPoint.LockedAgv.YLength > agv.YLength - 800)
// AvoidTask(agv, lockPoint.LockedAgv);
// }
//}
#endregion
#region 旧方式的处理,暂时注释
//if (currentPathPoint == null)
//{
////如果当前点位不在路径中,检查AGV是否在站台附属点,因为AGV取放货的时候,可能会被拖拽,导致从站台点偏移到站台附属点
//var currentPoint = App.PointList.FirstOrDefault(t => t.Barcode == agv.Barcode);
//if (currentPoint.PointType == EnumMsg.PointType.站台附属点)
//{
// // 根据站台附属点,找到站台点
// var stationPoint = App.PointList.FirstOrDefault(t => t.PreBarcode == agv.Barcode);
// if (stationPoint == null)
// return motionList;
// // 如果在路径中第一个点位是站台点,就把位置当成站台继续处理
// var firstPathPoint = sonTask.PathPointList.FirstOrDefault();
// if (firstPathPoint == null || firstPathPoint.Barcode != stationPoint.Barcode)
// return motionList;
// else
// currentPathPoint = firstPathPoint;
//}
////如果当前点位不在路径中,检查AGV是否在站台点,因为精度偏差从站台附属点偏移到站台点
//if (currentPoint.PointType == EnumMsg.PointType.站台点)
//{
// // 如果在路径中第一个点位是站台附属点,就先从当前点到站台附属点
// var firstPathPoint = sonTask.PathPointList.FirstOrDefault();
// if (firstPathPoint == null || firstPathPoint.Barcode != currentPoint.PreBarcode)
// return motionList;
// // 临时增加一个站台点路径
// var beginPathPoint = ComnMethod.GetPathPoint(currentPoint);
// beginPathPoint.AreaType = currentPoint.AreaType;
// beginPathPoint.SubTaskNo = firstPathPoint.SubTaskNo;
// beginPathPoint.SerialNo = 0;
// beginPathPoint.Barcode = currentPoint.Barcode;
// beginPathPoint.IsCorner = false;
// beginPathPoint.PathPointType = currentPoint.PointType;
// beginPathPoint.PathTim = 1;
// var clientMotion = GetMotion(sonTask, beginPathPoint, agv);
// motionList.Add(clientMotion);
// //增加站台附属点的路径,这样让AGV先走到站台附属点
// clientMotion = GetMotion(sonTask, firstPathPoint, agv);
// motionList.Add(clientMotion);
// return motionList;
//}
//}
#endregion
//当前车身一半的长度是否超过前一点的和当前点的间距
//Base_PathPoint beforePathPoint = agv.PathPointList.FirstOrDefault(a => a.SerialNo == currentPathPoint.SerialNo - 1);
//if (beforePathPoint != null && !beforePathPoint.IsCorner)
//{
// var barcodeLength = ComnMethod.GetDistance(beforePathPoint.Point.Barcode, agv.Barcode, beforePathPoint.PathDirection);
// if (barcodeLength < agv.Length / 2)
// {
// beforePathPoint.Point.LockedAgv = agv;
// lockedPoint.Add(beforePathPoint.Point);
// }
//}
//移除当前点之前的路径点
sonTask.PathPointList.RemoveAll(a => a.SerialNo < currentPathPoint.SerialNo);
//找到小车后面的路径点,每次包含当前点位在内,最多发4个点位
List<Base_PathPoint> pathList = sonTask.PathPointList.OrderBy(t => t.SerialNo).Take(4).ToList();
#region 判断后续点位距离是否满足条件可以申请
//可被申请的后续路径
//List<Base_PathPoint> newNextPathList = new List<Base_PathPoint>();
//获取后续路径点可被申请几个
//foreach (var pathPoint in pathList)
//{
// //当前点不做判断
// if (pathPoint.Barcode == agv.Barcode) { newNextPathList.Add(pathPoint); continue; }
// var nextPath = sonTask.PathPointList.Find(a => a.SerialNo == pathPoint.SerialNo + 1);
// //申请点
// var curPoint = pathPoint.Point;
// //直行判断
// //1、申请点被Lock,直接不申请
// //2、未被申请,判断当前点两侧方向是否被申请
// //判断当前点的方向
// if (pathPoint.PathDirection == EnumMsg.AgvOri.X正方向 ||
// pathPoint.PathDirection == EnumMsg.AgvOri.X负方向)
// {
// //获取当申请点两侧的点是否被AGV占用
// if (curPoint.YNegPoint != null)
// {
// //lock点的AGV
// var lockAgv = curPoint.YNegPoint.LockedAgv;
// //lock点
// var lockAgvPoint = curPoint.YNegPoint;
// if (lockAgv != null && lockAgv != agv)
// {
// //如果申请点是LockAGV的后续路径点,则不申请
// if (lockAgv.Barcode != lockAgvPoint.Barcode)
// {
// var isTrue = lockAgv.AgvTask.SubTaskList[0].PathPointList.Exists(a => a.Barcode == lockAgvPoint.Barcode);
// if (isTrue) break;
// }
// }
// }
// //获取当申请点两侧的点是否被AGV占用
// if (curPoint.YPosPoint != null)
// {
// //lock点的AGV
// var lockAgv = curPoint.YPosPoint.LockedAgv;
// //lock点
// var lockAgvPoint = curPoint.YPosPoint;
// if (lockAgv != null && lockAgv != agv)
// {
// //如果申请点是LockAGV的后续路径点,则不申请
// if (lockAgv.Barcode != lockAgvPoint.Barcode)
// {
// var isTrue = lockAgv.AgvTask.SubTaskList[0].PathPointList.Exists(a => a.Barcode == lockAgvPoint.Barcode);
// if (isTrue) break;
// }
// }
// }
// }
// else if (pathPoint.PathDirection == EnumMsg.AgvOri.Y正方向
// || pathPoint.PathDirection == EnumMsg.AgvOri.Y负方向)
// {
// //获取当申请点两侧的点是否被AGV占用
// if (curPoint.XNegPoint != null)
// {
// //lock点的AGV
// var lockAgv = curPoint.XNegPoint.LockedAgv;
// //lock点
// var lockAgvPoint = curPoint.XNegPoint;
// if (lockAgv != null && lockAgv != agv)
// {
// //如果申请点是LockAGV的后续路径点,则不申请
// if (lockAgv.Barcode != lockAgvPoint.Barcode)
// {
// var isTrue = lockAgv.AgvTask.SubTaskList[0].PathPointList.Exists(a => a.Barcode == lockAgvPoint.Barcode);
// if (isTrue) break;
// }
// }
// }
// //获取当申请点两侧的点是否被AGV占用
// if (curPoint.XPosPoint != null)
// {
// //lock点的AGV
// var lockAgv = curPoint.XPosPoint.LockedAgv;
// //lock点
// var lockAgvPoint = curPoint.XPosPoint;
// if (lockAgv != null && lockAgv != agv)
// {
// //如果申请点是LockAGV的后续路径点,则不申请
// if (lockAgv.Barcode != lockAgvPoint.Barcode)
// {
// var isTrue = lockAgv.AgvTask.SubTaskList[0].PathPointList.Exists(a => a.Barcode == lockAgvPoint.Barcode);
// if (isTrue) break;
// }
// }
// }
// }
// if (nextPath != null)
// {
// //申请点后续点
// var nextPoint = nextPath.Point;
// if (nextPath.Point.LockedAgv != null && nextPath.Point.LockedAgv != agv && nextPath.Point.Barcode == nextPath.Point.LockedAgv.Barcode) break;
// if (nextPath.PathDirection == EnumMsg.AgvOri.X正方向
// || nextPath.PathDirection == EnumMsg.AgvOri.X负方向)
// {
// //获取当申请点下个点两侧的点是否被AGV占用
// if (nextPoint.YNegPoint != null)
// {
// var lockAgv = nextPoint.YNegPoint.LockedAgv;
// //lock点
// var lockAgvPoint = nextPoint.YNegPoint;
// if (lockAgv != null && lockAgv != agv)
// {
// //如果申请点是LockAGV的后续路径点,则不申请
// if (lockAgv.Barcode != lockAgvPoint.Barcode)
// {
// var isTrue = lockAgv.AgvTask.SubTaskList[0].PathPointList.Exists(a => a.Barcode == lockAgvPoint.Barcode);
// if (isTrue) break;
// }
// }
// }
// if (nextPoint.YPosPoint != null)
// {
// var lockAgv = nextPoint.YPosPoint.LockedAgv;
// //lock点
// var lockAgvPoint = nextPoint.YPosPoint;
// if (lockAgv != null && lockAgv != agv)
// {
// //如果申请点是LockAGV的后续路径点,则不申请
// if (lockAgv.Barcode != lockAgvPoint.Barcode)
// {
// var isTrue = lockAgv.AgvTask.SubTaskList[0].PathPointList.Exists(a => a.Barcode == lockAgvPoint.Barcode);
// if (isTrue) break;
// }
// }
// }
// }
// else if (nextPath.PathDirection == EnumMsg.AgvOri.Y正方向
// || nextPath.PathDirection == EnumMsg.AgvOri.Y负方向)
// {
// //获取当申请点下个点两侧的点是否被AGV占用
// if (nextPoint.XNegPoint != null)
// {
// var lockAgv = nextPoint.XNegPoint.LockedAgv;
// //lock点
// var lockAgvPoint = nextPoint.XNegPoint;
// if (lockAgv != null && lockAgv != agv)
// {
// //如果申请点是LockAGV的后续路径点,则不申请
// if (lockAgv.Barcode != lockAgvPoint.Barcode)
// {
// var isTrue = lockAgv.AgvTask.SubTaskList[0].PathPointList.Exists(a => a.Barcode == lockAgvPoint.Barcode);
// if (isTrue) break;
// }
// }
// }
// if (nextPoint.XPosPoint != null)
// {
// var lockAgv = nextPoint.XPosPoint.LockedAgv;
// //lock点
// var lockAgvPoint = nextPoint.XPosPoint;
// if (lockAgv != null && lockAgv != agv)
// {
// //如果申请点是LockAGV的后续路径点,则不申请
// if (lockAgv.Barcode != lockAgvPoint.Barcode)
// {
// var isTrue = lockAgv.AgvTask.SubTaskList[0].PathPointList.Exists(a => a.Barcode == lockAgvPoint.Barcode);
// if (isTrue) break;
// }
// }
// }
// }
// }
// newNextPathList.Add(pathPoint);
//}
#endregion 判断后续点位距离是否满足条件可以申请
//判断后面的点位可以否能去,能去就加入motionList中。
foreach (Base_PathPoint pathPoint in pathList)
{
ClientMotion clientMotion = null;
Base_Point point = pathPoint.Point;
// pathPoint.PathDirection是当前点位往下个点位走的方向,上个点位往当前点位走的方向要取 lastPathPoint.PathDirection
var lastPathPoint = agv.PathPointList.Where(t => t.SerialNo < pathPoint.SerialNo).OrderByDescending(t => t.SerialNo).FirstOrDefault();
//如果没锁定的点位,就需要判断是否能去,锁定的路径就直接下发。
if (point.LockedAgv != agv)
{
#region 特殊点位的处理
//只能发送旋转点
if (lockedPoint.FindAll(a => a.PointType == EnumMsg.PointType.整体旋转点).Count == 2)
break;
if (lockedPoint.Exists(a => a.PointType == EnumMsg.PointType.整体旋转点) &&
agv.Barcode.Point().Data.PointType != EnumMsg.PointType.整体旋转点)
{
break;
}
//对接点只发到工位前一个点
if (pathPoint.Point.PointType == EnumMsg.PointType.对接点
&& App.StationList.Find(a => a.Barcode == point.Barcode).PreBarcode != "0"
&& agv.Barcode != App.StationList.Find(a => a.Barcode == point.Barcode).PreBarcode) continue;
//站台有车,附属点也不能去
if (pathPoint.Point.PointType == EnumMsg.PointType.站台附属点)
{
var stationPoint = App.PointList.Find(t => t.PreBarcode == pathPoint.Barcode);
if (stationPoint != null && stationPoint.LockedAgv != null && stationPoint.LockedAgv != agv)
{
break;
}
}
////判断申请点为站台附属点,并且当前任务终点为站台点,判断是否有车申请,有车申请不进
//if (pathPoint.Point.PointType == EnumMsg.PointType.站台附属点
// && sonTask.EndPoint.PreBarcode == point.Barcode
// && sonTask.EndPoint.LockedAgv != null && sonTask.EndPoint.LockedAgv != agv) break;
////如果车没到对接等待点,只能发送到第一个对接等待点(如果后面的点位,车就一直走,不会在等待点停了)
//if (pathPoint.Barcode == "104" || pathPoint.Barcode == "105")
//{
// if (agv.Barcode != pathPoint.Barcode)
// {
// if (lockedPoint.Exists(t => t.Barcode == "104" || t.Barcode == "105"))
// {
// break;
// }
// }
//}
#endregion
#region 路径的防撞检测
if (lastPathPoint != null)
{
//如果会撞击就不能下发后面的点位
if (CheckCrash(pathPoint, agv, lastPathPoint.PathDirection, out Base_Agv crashAGV))
{
AvoidTask(agv, crashAGV);
break;
}
//如果上个路径是Y方向的,那就要检测后面是否也会撞
if (lastPathPoint.PathDirection == EnumMsg.AgvOri.Y正方向 || lastPathPoint.PathDirection == EnumMsg.AgvOri.Y负方向)
{
//如果会撞击就不能下发后面的点位
if (CheckCrash(pathPoint, agv, EnumMsg.AgvOri.X正方向, out Base_Agv frontAGV))
{
AvoidTask(agv, crashAGV);
break;
}
//如果会撞击就不能下发后面的点位
if (CheckCrash(pathPoint, agv, EnumMsg.AgvOri.X负方向, out Base_Agv lastAGV))
{
AvoidTask(agv, crashAGV);
break;
}
}
}
#endregion
#region 互斥管控,当前区域只许一辆车出入
if (point.RegionName.Contains("Mutex"))
{
//if(point.strRegionName)
List<Base_Point> mutexPointList = App.PointList.FindAll(a => a.RegionName == point.RegionName);
bool isMutexResult = MutexAreaContrl(mutexPointList, pathPoint, agv);
if (isMutexResult)
{
if (motionList.Count == 1)
agv.StopReason = ComnMethod.GetStopReason(agv.StopReason, "互斥区域的流量管控;");
break;
}
}
//当前区域只许同向AGV通行
if (point.RegionName.Contains("Area"))
{
//if(point.strRegionName)
List<Base_Point> mutexPointList = App.PointList.FindAll(a => a.RegionName == point.RegionName);
var mutexResult = StopMutexAreaControl(mutexPointList, agv);
if (mutexResult != 0)
{
if (motionList.Count == 1)
agv.StopReason = ComnMethod.GetStopReason(agv.StopReason, "互斥区域的流量管控;");
break;
}
}
#endregion 互斥管控,当前区域只许一辆车出入
#region 注释 整体旋转点托盘旋转
//路径中有需要旋转的旋转点,停
//if (agv.heightState == EnumMsg.HeightState.高位)
//{
// if (lockedPoint.Exists(a => a.pointType == EnumMsg.PointType.整体旋转点) &&
// pathList.Find(b => b.point.strBarcode == lockedPoint.Last(a => a.pointType == EnumMsg.PointType.整体旋转点).strBarcode
// && b.pathPointType == EnumMsg.PointType.托盘旋转点) != null
// && currentPathPoint.pathPointType != EnumMsg.PointType.托盘旋转点) break;
// PathPoint nextPoint = ComnMethod.GetNextPathPoint(agv, currentPathPoint);
// if (currentPathPoint.pathPointType == EnumMsg.PointType.托盘旋转点 && nextPoint != null)
// {
// if (nextPoint.isCorner)
// {
// if (nextPoint.point.pointType == EnumMsg.PointType.虚拟点 || nextPoint.point.pointType == EnumMsg.PointType.整体旋转点)
// {
// if ((int)agv.dialOri != 1) break;
// }
// else
// {
// if ((int)agv.dialOri != 2) break;
// }
// //if (nextPoint.point.pointType == EnumMsg.PointType.虚拟点 && (int)agv.dialOri != 1) break;
// //if (nextPoint.point.pointType != EnumMsg.PointType.虚拟点 && (int)agv.dialOri != 2) break;
// }
// else
// {
// if ((int)agv.dialOri != 1) break;
// }
// }
//}
#endregion 注释 整体旋转点托盘旋转
#region 防止回环申请的管控
bool isLoop = false;
Loop(pathPoint, new List<Base_Agv>() { agv }, ref isLoop);
if (isLoop)
{
//只有一个点的时候才报错
if (motionList.Count == 1)
agv.StopReason = ComnMethod.GetStopReason(agv.StopReason, "回环申请的管控;");
break;
}
#endregion 防止回环申请的管控
#region 特殊区域的流量管控
if (point.RegionName.Contains("KeyArea"))
{
List<Base_Point> keyPointList = App.PointList.Where(a => a.RegionName == point.RegionName).ToList();
bool isKeyResult = KeyAreaContrl(keyPointList, agv);
if (isKeyResult)
{
if (motionList.Count == 1)
agv.StopReason = ComnMethod.GetStopReason(agv.StopReason, "特殊区域的流量管控;");
break;
}
}
#endregion 特殊区域的流量管控
#region 特殊点区域流量管控
//if (App.Config_PointList.Find(a => a.strBarcode == point.strBarcode) != null)
//{
// List<Config_Point> config_PointList = App.Config_PointList.FindAll(a => a.intNo == App.Config_PointList.Find(b => b.strBarcode == point.strBarcode).intNo && a.areaType == point.AreaType);
// int flag = 0;
// foreach (Config_Point config_Point in config_PointList)
// {
// Point conPoint = App.PointList.Find(a => a.strBarcode == config_Point.strBarcode);
// if (conPoint.lockedAgv != null && conPoint.lockedAgv != agv)// && conPoint.pointType == EnumMsg.PointType.整体旋转点
// {
// if (conPoint.lockedAgv.agvAreaType == "1" && conPoint.lockedAgv.heightState != EnumMsg.HeightState.低位
// && ((agv.agvAreaType == "1" && agv.heightState != EnumMsg.HeightState.低位) || agv.agvAreaType == "2")) { flag = 99; }
// else if (conPoint.lockedAgv.agvAreaType == "2" && agv.agvAreaType == "1" && agv.heightState != EnumMsg.HeightState.低位)
// flag = 99;
// }
// if (conPoint.lockedAgv != null && conPoint.lockedAgv != agv && conPoint.pointType == EnumMsg.PointType.托盘旋转点)
// { flag = 99; }
// }
// //旋转点是否有车,有车不进入
// if (flag == 99)
// {
// if (motionList.Count == 1)
// agv.strStopReason = ComnMethod.GetStopReason(agv.strStopReason, "特殊点区域的流量管控;");
// break;
// }
//}
#endregion 特殊点区域流量管控
}
point.LockedAgv = agv;
lockedPoint.Add(point);
clientMotion = GetMotion(sonTask, pathPoint, agv);
motionList.Add(clientMotion);
#region 对接等待点的处理
if (point.PointType == EnumMsg.PointType.对接等待点)
{
//如果还有下个路径,就进行处理
var nextPath = pathList.Where(x => x.SerialNo > pathPoint.SerialNo).OrderBy(x => x.SerialNo).FirstOrDefault();
if (nextPath != null)
{
BllResult bllResult = BllResult.Sucess();
//如果当前点位是对接等待点,下个点位也是对接等待点,说明要穿越等待点,就要和设备交互
if (point.PointType == EnumMsg.PointType.对接等待点 && nextPath.Point.PointType == EnumMsg.PointType.对接等待点)
{
//如果车没到第一个对接等待点,就不发后面的路径,等车到了再和设备通信。因为裴工说路不是直线,必须先停一下再走,否则会撞墙
if (currentPathPoint.Barcode != point.Barcode)
{
break;
}
var equipment = App.EquipmentList.FirstOrDefault(t => t.Code.Split('_').Contains(point.Barcode));
bllResult = EquipmentExecutor.Instance.RequestOperator(equipment?.Name, EnumMsg.TaskRequestType.开快卷门);
}
//如果当前点位是对接等待点,下个点位也是对接等待点,说明要穿越等待点,就要和设备交互
if (point.PointType == EnumMsg.PointType.对接等待点 && nextPath.Point.PointType != EnumMsg.PointType.对接等待点)
{
////如果车没到第二个对接等待点,就不发后面的路径,等车到了再和设备通信
//if (currentPathPoint.Barcode != point.Barcode)
//{
// break;
//}
//根据配置,如果配置需要关门,才关门
if (App.GetKeyValue("CloseDoor") == 1)
{
//必须等车到了第二个对接等待点,也就是门后,才能关门
if (currentPathPoint.Barcode == point.Barcode)
{
var equipment = App.EquipmentList.FirstOrDefault(t => t.Code.Split('_').Contains(point.Barcode));
EquipmentExecutor.Instance.RequestOperator(equipment?.Name, EnumMsg.TaskRequestType.关快卷门);
}
}
}
//如果AGV和设备交互,失败就之下发到对接等待点,然后返回。
if (!bllResult.Success)
{
agv.StopReason = ComnMethod.GetStopReason(agv.StopReason, bllResult.Msg);
break;
}
}
}
#endregion
}
//检查最后的停止点距离下个路径点的距离
UpdateManage.RelieveLocked(lockedPoint, agv);
return motionList;
}
catch (Exception ex)
{
throw new Exception($"Motions:原因:{ex.Message},\n 堆栈:{ex.StackTrace}");
}
}
/// <summary>
/// 获取Motion,重新封装给AGV
/// </summary>
/// <param name="sonTask">子任务</param>
/// <param name="currentPathPoint">待加入的路径点</param>
/// <returns></returns>
public static ClientMotion GetMotion(Base_SubTask sonTask, Base_PathPoint currentPathPoint, Base_Agv agv)
{
try
{
ClientMotion clientMotion = new ClientMotion();
clientMotion.TaskType = (int)sonTask.SubTaskType;
clientMotion.Barcode = currentPathPoint.Point.Barcode;
clientMotion.BarcodeValue = currentPathPoint.Point.BarcodeValue;
clientMotion.IntX = currentPathPoint.Point.IntX;
clientMotion.IntY = currentPathPoint.Point.IntY;
clientMotion.XLength = currentPathPoint.Point.GetXLength(agv.AgvNo);
clientMotion.YLength = currentPathPoint.Point.GetYLength(agv.AgvNo);
clientMotion.AgvOri = (int)currentPathPoint.Point.AgvOri;
clientMotion.PointTim = currentPathPoint.PathTim;
clientMotion.IsCorner = currentPathPoint.IsCorner;
var pickGood = new EnumMsg.AgvTaskType[] { EnumMsg.AgvTaskType.上层接料, EnumMsg.AgvTaskType.下层接料 };
var putGood = new EnumMsg.AgvTaskType[] { EnumMsg.AgvTaskType.上层下料, EnumMsg.AgvTaskType.下层下料 };
//如果是取货,输送方向就是起点站台
if (pickGood.Contains(sonTask.SubTaskType))
{
Base_Station station = App.StationList.Find(t => t.Name == agv.AgvTask.Initial);
clientMotion.TransportOri = (int)station.StationOri;
}
//如果是放货,输送方向就是终点站台
if (putGood.Contains(sonTask.SubTaskType))
{
Base_Station station = App.StationList.Find(t => t.Name == agv.AgvTask.Target);
clientMotion.TransportOri = (int)station.StationOri;
}
if (currentPathPoint.Point.PointType == EnumMsg.PointType.站台附属点 || currentPathPoint.Point.PointType == EnumMsg.PointType.充电点)
{
clientMotion.PathPointType = (int)EnumMsg.PointType.站台点;
}
else
{
clientMotion.PathPointType = (int)currentPathPoint.Point.PointType;
}
if (agv.AgvType == EnumMsg.AgvType.差速)
{
if (sonTask.SubTaskType == EnumMsg.AgvTaskType.下降到底)
{
var staiton = App.StationList.Find(a => a.Barcode == sonTask.EndBarcode);
if (staiton != null && !staiton.Name.Contains("精准"))
{
clientMotion.PathPointType = (int)EnumMsg.PointType.不精准定位;
}
}
if (agv.HeightState != EnumMsg.HeightState.低位 && currentPathPoint.IsCorner)
{
if (currentPathPoint.Point.IntX == 160 && currentPathPoint.Point.IntY == 950
|| currentPathPoint.Point.IntX == 160 && currentPathPoint.Point.IntY == 966)
{
clientMotion.PathPointType = 4;
}
}
#region 充电点车头方向旋转
if (currentPathPoint.Point.PointType == EnumMsg.PointType.充电点)
{
clientMotion.AgvOri = (int)App.StationList.Find(a => a.Barcode == currentPathPoint.Point.Barcode).StationOri;
}
#endregion 充电点车头方向旋转
#region 获取当前点的转盘方向
//ComnMethod.getAgvDial(currentPathPoint, agv);
#endregion 获取当前点的转盘方向
#region 充电取消充电车行驶距离
if (sonTask.SubTaskType == EnumMsg.AgvTaskType.充电 || sonTask.SubTaskType == EnumMsg.AgvTaskType.取消充电)
{
clientMotion.XLength = sonTask.ChargeLength;
clientMotion.YLength = sonTask.ChargeLength;
}
#endregion 充电取消充电车行驶距离
}
//如果当前车型为舵轮车
else if (agv.AgvType == EnumMsg.AgvType.舵轮)
{
clientMotion.DlAgvOri = currentPathPoint.Point.GetDlAgvOri(agv.AgvNo);
//子任务终点,如果是行走、且是站台点,就精确调整
if (currentPathPoint.Barcode == sonTask.EndBarcode && currentPathPoint.Point.PointType == EnumMsg.PointType.站台点)
{
clientMotion.Adjust = (int)EnumMsg.Adjust.CCD调整等级1;
}
////子任务终点,如果是行走、且是站台点,就精确调整
//if (currentPathPoint.Barcode == sonTask.EndBarcode && currentPathPoint.Point.PointType == EnumMsg.PointType.充电点)
//{
// clientMotion.Adjust = (int)EnumMsg.Adjust.SLAM调整等级3;
//}
//充电取消充电距离
if (sonTask.SubTaskType == EnumMsg.AgvTaskType.充电 || sonTask.SubTaskType == EnumMsg.AgvTaskType.取消充电)
{
clientMotion.HeightOrLength = sonTask.ChargeLength;
clientMotion.PathPointType = (int)EnumMsg.PointType.充电点;
}
//// 如果是 升降到指定高度,那么充电距离存放的就是顶升高度
//if (sonTask.SubTaskType == EnumMsg.AgvTaskType.升降到指定高度)
//{
// clientMotion.HeightOrLength = sonTask.ChargeLength;
// clientMotion.Adjust = (int)EnumMsg.Adjust.不调整;
//}
}
return clientMotion;
}
catch (Exception ex)
{
throw new Exception($"GetMotion:{ex.Message},\n 堆栈:{ex.StackTrace}");
}
}
/// <summary>
/// 检查是否有回旋死锁,防止三个车环形堵死
/// </summary>
/// <param name="nowPoint"></param>
/// <param name="listAgv"></param>
/// <param name="isLoop"></param>
public static void Loop(Base_PathPoint nowPoint, List<Base_Agv> listAgv, ref bool isLoop)
{
try
{
//找最新的AGV
Base_Agv lastAgv = listAgv.LastOrDefault();
Base_PathPoint nextPoint = ComnMethod.GetNextPathPoint(lastAgv, nowPoint);
if (nextPoint != null)
{
//获取占用此点的AGV
Base_Agv agv = nextPoint.Point.LockedAgv;
//此点被另外的AGV占用了
if (agv != null && agv != lastAgv)
{
listAgv.Add(agv);
//如果还没找到第四个点,则继续找
if (listAgv.Count == 4)
{
if (listAgv[0].AgvNo != listAgv[3].AgvNo)
isLoop = true;
else
isLoop = false;
return;
}
Loop(nextPoint, listAgv, ref isLoop);
}
}
}
catch (Exception ex)
{
throw new Exception($"Loop:{ex.Message},\n 堆栈:{ex.StackTrace}");
}
}
/// <summary>
/// 区域流量管控
/// </summary>
/// <param name="keyPointList"></param>
/// <param name="point"></param>
/// <returns></returns>
public static bool KeyAreaContrl(List<Base_Point> keyPointList, Base_Agv agv)
{
try
{
if (keyPointList.FirstOrDefault(a => a.Barcode == agv.Barcode) != null) return false;
//提取所有小车的当前点和关键区域所有的点,找相同则为区域内的小车数量
List<string> agvList = App.AgvList.Select(a => a.Barcode).ToList();
List<string> keyList = keyPointList.Select(a => a.Barcode).ToList();
int agvCount = agvList.Intersect(keyList).ToList().Count;
if (agvCount <= App.KeyAreaNum) return false;
return true;
}
catch (Exception ex)
{
throw new Exception($"KeyAreaContrl:{ex.Message},\n 堆栈:{ex.StackTrace}");
}
}
/// <summary>
/// 互斥区域是否限制进入
/// </summary>
/// <param name="mutexPointList">当前点区域集合</param>
/// <param name="nowPoint">当前点</param>
/// <param name="agv">申请AGV</param>
/// <returns></returns>
public static bool MutexAreaContrl(List<Base_Point> mutexPointList, Base_PathPoint nowPoint, Base_Agv agv)
{
try
{
if (mutexPointList.Count == 0) return false;
//如果点位在管控区,那么也把附属点位加入进来,如果附属点在管控区,那么也把点位加入进来,因为点位和附属点很近
var points = App.PointList.Where(x => mutexPointList.Exists(y => y.PreBarcode == x.Barcode || y.Barcode == x.PreBarcode));
mutexPointList.AddRange(points);
#region 如果子任务的终点有附属点,并附属点和当前点是同一个管控区,就限制进入
////当前子任务的终点
//Base_Point agvEndPoint = agv.AgvTask.SubTaskList.First().EndPoint;
////手动模式的任务的agv不进行管控
////if (agv.agvTask.strTaskID.Contains("手动")) return false;
////子任务终点的附属点
//Base_Point prePoint = App.PointList.Find(a => a.Barcode == agvEndPoint.PreBarcode);
////如果子任务的终点有附属点,并且附属点在管控区内,占用也不是当前AGV申请
//if (prePoint != null && agvEndPoint.LockedAgv != null && agvEndPoint.LockedAgv != agv &&
// mutexPointList.Exists(a => a.RegionName == prePoint.RegionName))
//{
// return true;
//}
#endregion
// 点位不在管控区,就允许进入
if (!mutexPointList.Exists(a => a.Barcode == nowPoint.Barcode))
return false;
//如果管控区有AGV锁定,且锁定的不是本车,那不许进入
if (mutexPointList.Exists(a => a.LockedAgv != null && a.LockedAgv != agv))
return true;
//找出管制区的所有小车,如果有车,那不许进入
var agvBarcodes = App.AgvList.Where(t => t.AgvNo != agv.AgvNo).Select(t => t.Barcode).ToList();
if (mutexPointList.Exists(x => agvBarcodes.Contains(x.Barcode)))
return true;
////找出管制区的所有小车,如果数量大于0就限制进入
//List<string> agvList = App.AgvList.Select(a => a.Barcode).ToList();
//List<string> keyList = mutexPointList.Select(a => a.Barcode).ToList();
//int agvCount = agvList.Intersect(keyList).Count();
//if (agvCount > 0)
// return true;
#region 注释当前点是停靠点区域判定
//if (nowPoint.point.pointType == EnumMsg.PointType.停靠附属点)
//{
// PathPoint nextPoint = ComnMethod.GetNextPathPoint(agv, nowPoint);
// if (nextPoint.point.pointType == EnumMsg.PointType.停靠点)
// {
// if (mutexPointList.Exists(a => a.lockedAgv != null && a.lockedAgv != agv)) return true;
// }
//}
#endregion 注释当前点是停靠点区域判定
//可以找到该限制区域的所有站台附属点perBarcode
//找到该限制区域内所有站台点
//List<string> listBarcode = mutexPointList.Select(a => a.strBarcode).ToList();
//List<Point> listPoint = App.PointList.FindAll(a => listBarcode.Contains(a.strPreBarcode));
////&& listPoint.Exists(a => a.strBarcode == agvEndPoint.strBarcode)
//PathPoint nextPoint = ComnMethod.GetNextPathPoint(agv, nowPoint);
//if (listPoint.Exists(a => a.lockedAgv != null && a.lockedAgv != agv
//&& a.lockedAgv.agvTask!=null && a.pointType != EnumMsg.PointType.停靠点)
// && (nextPoint == null || mutexPointList.Exists(a => a.strBarcode == nextPoint.point.strBarcode))) return true;
return false;
}
catch (Exception ex)
{
throw new Exception($"MutexAreaContrl:{ex.Message},\n 堆栈:{ex.StackTrace}");
}
}
/// <summary>
/// 判断当前区域内AGV是否和申请车同方向,如果是可进,不是不可进
/// </summary>
/// <param name="mutexPointList"></param>
/// <param name="agv"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static int StopMutexAreaControl(List<Base_Point> mutexPointList, Base_Agv agv)
{
try
{
if (mutexPointList.Count == 0) return 0;
//if (mutexPointList.Find(a => a.strRegionName.Contains("Mutex_004") && a.lockedAgv != null && a.lockedAgv != agv) != null) return 1;
//获取申请AGV的路径点集合
var agvpath = agv.AgvTask.SubTaskList.FirstOrDefault().PathPointList;
//申请AGV的路径 与 限制区域路径点的集合
var result8 = agvpath.FindAll(a => mutexPointList.Exists(b => b.Barcode == a.Point.Barcode));
//获取所有限制区域内有任务agv集合
var result3 = App.AgvList.ToList().FindAll(j => mutexPointList.Exists(point => point.LockedAgv == j && point.LockedAgv != agv && point.LockedAgv.AgvTask != null));
if (result3.Count() == 0) return 0;
//获取区域内AGV的任务终点和申请车终点在同一区域
var sontaskAgv = result3.FindAll(a => a.AgvTask.SubTaskList.FirstOrDefault().EndPoint.RegionName.Contains("Area"));
if (sontaskAgv.Count > 1 && agv.AgvTask.EndPoint.RegionName.Contains("Area")) return 1;
//20201112判断集合内的是否有任务起点是当前任务终点的AGV
bool taskAgv = result3.Exists(a =>
a.AgvTask.SubTaskList[0].StartPoint == agv.AgvTask.SubTaskList[0].EndPoint
&& a.Barcode == agv.AgvTask.SubTaskList[0].EndPoint.Barcode);
if (taskAgv)
{
return 1;
}
//bool freeresult = result3.Exists(a => agvpath.Exists(p => p.point.strBarcode == a.strBarcode));
//if (freeresult)
//{
// return 1;
//}
//申请车有且仅有一个路径点在限制区域内
if (result8.Count == 1 && result8.Exists(a => a.PathDirection == 0)) return 1;
//获取已经在限制区域内AGV的路径点
var result4 = result3.SelectMany(a => a.AgvTask.SubTaskList.SelectMany(b => b.PathPointList)).ToList();
if (result4.Count == 0) return 0;
//获取已经在限制区域内AGV的路径点和限制区域集合的交集
var result5 = result4.FindAll(a => mutexPointList.Exists(b => a.Point.Barcode == b.Barcode));
if (result5.Count() == 0) return 0;
//申请车在限制区域内的点和已在限制区域内AGV的路径点的交集
var result7 = result5.FindAll(a => agvpath.Exists(b => b.Point.Barcode == a.Point.Barcode));
//判断两个集合是否存在路径点方向差值等于2的
var result6 = result7.Exists(a => agvpath.Exists(b => Math.Abs((int)a.PathDirection - (int)b.PathDirection) == 2 && a.Point.Barcode == b.Point.Barcode));
if (result6)
{
return 1;
}
else
{
if (agvpath.Last().Point.LockedAgv != null)
{
return 1;
}
else
{
return 0;
}
}
}
catch (Exception ex)
{
throw new Exception($"停靠点判定MutexAreaControl:原因:{ex.Message},\n 堆栈:{ex.StackTrace}");
}
}
/// <summary>
/// 判断点位如果去了,是否会撞车
/// </summary>
/// <param name="pathPoint">要判断的路径点</param>
/// <param name="agv">路径点中的AGV</param>
/// <param name="pathDirection">需要判断的方向</param>
/// <param name="nextAGV">需要避让的AGV</param>
/// <returns></returns>
public static bool CheckCrash(Base_PathPoint pathPoint, Base_Agv agv, EnumMsg.AgvOri pathDirection, out Base_Agv nextAGV)
{
try
{
nextAGV = null;
var point = pathPoint.Point;
//点位有其它车,直接不能去
if (point.LockedAgv != null && point.LockedAgv != agv)
{
nextAGV = point.LockedAgv;
return true;
}
// 中间仓只要斜着跑,就会撞
if (pathDirection == EnumMsg.AgvOri.斜向)
{
return true;
}
bool crash = false;
Base_Point nextAGVPoint = null;
// 找出 当前点位X正方向、相同区域,存在其他车的点位。
// 具体计算方式:X正方向行走的时候,会IntX变大,IntY不变,XLength不变,YLength变小,也就是说小车把地图的Y坐标当X坐标来行走的,而且是反向。
if (pathDirection == EnumMsg.AgvOri.X正方向)
{
//X正方向的点位
var barcodes = App.PointList.Where(t => t.IntX >= point.IntX && t.IntY == point.IntY && t.AreaType == point.AreaType)
.Select(t => t.Barcode)
.ToList();
//X正方向的点位、站台点
nextAGVPoint = App.PointList.Where(t => (barcodes.Contains(t.Barcode) || barcodes.Contains(t.PreBarcode)) &&
t.LockedAgv != null && t.LockedAgv != agv)
.OrderBy(t => t.IntX)
.FirstOrDefault();
}
// 找出 当前点位X负方向、相同区域,存在其他车的点位。
// 具体计算方式:X负方向行走的时候,会IntX变小,IntY不变,XLength不变,YLength变大,也就是说小车把地图的Y坐标当X坐标来行走的,而且是反向。
if (pathDirection == EnumMsg.AgvOri.X负方向)
{
//X负方向的点位
var barcodes = App.PointList.Where(t => t.IntX <= point.IntX && t.IntY == point.IntY && t.AreaType == point.AreaType)
.Select(t => t.Barcode)
.ToList();
//X负方向的点位、站台点
nextAGVPoint = App.PointList.Where(t => (barcodes.Contains(t.Barcode) || barcodes.Contains(t.PreBarcode)) &&
t.LockedAgv != null && t.LockedAgv != agv)
.OrderByDescending(t => t.IntX)
.FirstOrDefault();
}
// 找出 当前点位Y正方向、相同区域,存在其他车的点位。
// 具体计算方式:Y正方向行走的时候,会IntX不变,IntY变大,XLength变大,YLength不变,也就是说小车把地图的X坐标当Y坐标来行走的,而且是同向。
if (pathDirection == EnumMsg.AgvOri.Y正方向)
{
//Y正方向的点位
var barcodes = App.PointList.Where(t => t.IntX == point.IntX && t.IntY >= point.IntY && t.AreaType == point.AreaType)
.Select(t => t.Barcode)
.ToList();
//Y正方向的点位、站台点
nextAGVPoint = App.PointList.Where(t => (barcodes.Contains(t.Barcode) || barcodes.Contains(t.PreBarcode)) &&
t.LockedAgv != null && t.LockedAgv != agv)
.OrderBy(t => t.IntY)
.FirstOrDefault();
}
// 找出 当前点位Y负方向、相同区域,存在其他车的点位。
// 具体计算方式:Y负方向行走的时候,会IntX不变,IntY变小,XLength变小,YLength不变,也就是说小车把地图的X坐标当Y坐标来行走的,而且是同向。
if (pathDirection == EnumMsg.AgvOri.Y负方向)
{
//Y负方向的点位
var barcodes = App.PointList.Where(t => t.IntX == point.IntX && t.IntY <= point.IntY && t.AreaType == point.AreaType)
.Select(t => t.Barcode)
.ToList();
//Y负方向的点位、站台点
nextAGVPoint = App.PointList.Where(t => (barcodes.Contains(t.Barcode) || barcodes.Contains(t.PreBarcode)) &&
t.LockedAgv != null && t.LockedAgv != agv)
.OrderByDescending(t => t.IntY)
.FirstOrDefault();
}
//如果路径点有车,就计算够不够远,两个车会不会撞
if (nextAGVPoint != null && nextAGVPoint.LockedAgv != null && nextAGVPoint.LockedAgv != agv)
{
// AGV不撞,需要的长度
var agvLenth = nextAGVPoint.LockedAgv.Length / 2 + agv.Length / 2;
int distance = ComnMethod.GetDistance(point, nextAGVPoint, pathDirection);
if (distance < agvLenth)
{
crash = true;
nextAGV = nextAGVPoint.LockedAgv;
}
}
return crash;
}
catch (Exception ex)
{
throw new Exception($"CheckCrash:: {ex.Message},\n 堆栈:{ex.StackTrace}");
}
}
/// <summary>
/// 生成避让任务
/// </summary>
/// <param name="agvTask">被阻挡的任务</param>
/// <param name="targetAGV">需要执行避让的AGV</param>
/// <exception cref="Exception"></exception>
public static void AvoidTask(Base_Agv currentAGV, Base_Agv targetAGV)
{
try
{
var msg = string.Empty;
if (targetAGV == null)
{
msg = $"需要避让的AGV【{targetAGV.AgvNo}】为空,无法避让!";
currentAGV.StopReason = ComnMethod.GetStopReason(currentAGV.StopReason, msg);
return;
}
if (string.IsNullOrEmpty(targetAGV.Barcode))
{
msg = $"需要避让的AGV【{targetAGV.AgvNo}】当前点位为空,无法避让!";
currentAGV.StopReason = ComnMethod.GetStopReason(currentAGV.StopReason, msg);
return;
}
if ((DateTime.Now - targetAGV.FreeTime).TotalSeconds < 3)
{
msg = $"需要避让的AGV【{targetAGV.AgvNo}】要空闲超过3秒,才会生成避让!";
currentAGV.StopReason = ComnMethod.GetStopReason(currentAGV.StopReason, msg);
return;
}
var task = App.TaskList.FirstOrDefault(t => t.TaskAgvNo == targetAGV.AgvNo);
if (task != null)
{
if (task.TaskID == EnumMsg.TaskType.手动行走.ToString())
{
msg = $"需要避让的AGV【{targetAGV.AgvNo}】已经【手动有行】走任务,等待前车执行!";
currentAGV.StopReason = ComnMethod.GetStopReason(currentAGV.StopReason, msg);
return;
}
if (task.TaskID == EnumMsg.TaskType.取消充电.ToString())
{
msg = $"需要避让的AGV【{targetAGV.AgvNo}】已经有【取消充电】任务,等待前车执行!";
currentAGV.StopReason = ComnMethod.GetStopReason(currentAGV.StopReason, msg);
return;
}
if (task.TaskID == EnumMsg.TaskType.充电.ToString())
{
var result = TaskManage.TaskDelete(targetAGV.AgvTask);
currentAGV.StopReason = ComnMethod.GetStopReason(currentAGV.StopReason, result.Msg);
return;
}
msg = $"需要避让的AGV【{targetAGV.AgvNo}】存在【{task.TaskID}】任务【{task.TaskNo}】,不能生成避让任务,请等待前车执行!";
currentAGV.StopReason = ComnMethod.GetStopReason(currentAGV.StopReason, msg);
return;
}
//如果车在充电中,且AGV没有取消充电的任务,就生成取消充电的任务
if (targetAGV.AgvState == EnumMsg.State.充电中)
{
if (App.TaskList.Any(t => t.TaskAgvNo == targetAGV.AgvNo && t.TaskID == EnumMsg.TaskType.取消充电.ToString()))
{
msg = $"需要避让的AGV【{targetAGV.AgvNo}】充电中,已生成取消充电任务,等待执行!";
currentAGV.StopReason = ComnMethod.GetStopReason(currentAGV.StopReason, msg);
return;
}
var result = TaskManage.TaskBuild(EnumMsg.TaskType.取消充电.ToString(),
EnumMsg.TaskGroup.RCS单步任务.ToString(),
"1", 1, targetAGV.AgvNo, targetAGV.Barcode, targetAGV.Barcode, "", "", "");
if (result.Success)
{
App.ExFile.MessageLog("TaskBuild", $"因为需要避让,生成AGV【{targetAGV.AgvNo}】的【取消充电】任务!");
}
else
{
msg = $"需要避让的AGV【{targetAGV.AgvNo}】生成【取消充电】任务失败,原因:{result.Msg}!";
App.ExFile.MessageBusinessErr("TaskBuild", msg);
currentAGV.StopReason = ComnMethod.GetStopReason(currentAGV.StopReason, msg);
return;
}
return;
}
// 如果车是自动空闲,且没有手动行走的任务,就生成行走任务来避让
if (targetAGV.AgvState == EnumMsg.State.自动空闲)
{
var homeBarcode = ComnMethod.GetHomeBarcode(currentAGV.AgvTask, targetAGV);
if (string.IsNullOrEmpty(homeBarcode))
{
msg = $"需要避让的AGV【{targetAGV.AgvNo}】获取不到避让位置,无法生成避让任务!";
currentAGV.StopReason = ComnMethod.GetStopReason(currentAGV.StopReason, msg);
return;
}
if (homeBarcode == targetAGV.Barcode)
{
msg = $"需要避让的AGV【{targetAGV.AgvNo}】就在避让点,请等待!";
currentAGV.StopReason = ComnMethod.GetStopReason(currentAGV.StopReason, msg);
return;
}
if (App.TaskList.Any(t => t.TaskAgvNo == targetAGV.AgvNo && t.TaskID == EnumMsg.TaskType.手动行走.ToString()))
{
msg = $"需要避让的AGV【{targetAGV.AgvNo}】已经生成【手动行走】任务,等待前面的车离开!";
currentAGV.StopReason = ComnMethod.GetStopReason(currentAGV.StopReason, msg);
return;
}
var result = TaskManage.TaskBuild(EnumMsg.TaskType.手动行走.ToString(),
EnumMsg.TaskGroup.RCS单步任务.ToString(),
"1", 1, targetAGV.AgvNo, targetAGV.Barcode, homeBarcode, "", "", "");
if (!result.Success)
{
App.ExFile.MessageLog("TaskBuild", $"因为需要避让,生成AGV【{targetAGV.AgvNo}】的【手动行走】任务!");
}
else
{
msg = $"需要避让的AGV【{targetAGV.AgvNo}】生成避让【手动行走】任务失败,原因:{result.Msg}!";
App.ExFile.MessageBusinessErr("TaskBuild", msg);
currentAGV.StopReason = ComnMethod.GetStopReason(currentAGV.StopReason, msg);
return;
}
return;
}
msg = $"需要避让的AGV【{targetAGV.AgvNo}】不是【自动空闲】或是【充电中】,不能生成避让任务!";
currentAGV.StopReason = ComnMethod.GetStopReason(currentAGV.StopReason, msg);
return;
}
catch (Exception ex)
{
throw new Exception($"AvoidTask:: {ex.Message},\n 堆栈:{ex.StackTrace}");
}
}
}
}