GetNextPoint.cs
33.2 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
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XingYe_ACS.BaseStruct;
using XingYe_ACS.Common;
namespace XingYe_ACS.Business
{
public class GetNextPoint
{
/// <summary>
/// 为小车获取后续动作点
/// </summary>
/// <param name="sonTask">子任务信息</param>
/// <param name="agv">小车信息</param>
/// <returns></returns>
public static List<ClientMotion> Motions(SonTask sonTask, Agv agv)
{
try
{
//储存此过程中添加的lock点,除此之外的都解除lock;
List<Point> lockedPoint = new List<Point>();
List<ClientMotion> motionList = new List<ClientMotion>();
PathPoint currentPathPoint = sonTask.pathPointList.FirstOrDefault(a => a.point.strBarcode == agv.strBarcode);
//根据车身距离判断是否是否前一路径
PathPoint beforePathPoint = sonTask.pathPointList.FirstOrDefault(a => a.intSerialNo == currentPathPoint.intSerialNo - 1);
if (beforePathPoint != null)
{
int length = ComnMethod.GetDistance(beforePathPoint.point.strBarcode, agv.strBarcode, "");
if (length < App.AgvLength)
{
beforePathPoint.point.lockedAgv = agv;
lockedPoint.Add(beforePathPoint.point);
}
}
//移除当前点之前的路径点
sonTask.pathPointList.RemoveAll(a => a.intSerialNo < currentPathPoint.intSerialNo);
#region 注释的原地旋转
//if (sonTask.sonTaskType == EnumMsg.AgvTaskType.原地旋转)
//{
// string Region = currentPathPoint.point.strRegionName;
// List<Point> attachPointList = App.PointList.Where(a => a.strRegionName.Contains(Region)).ToList();
// int flag = 0;
// foreach (Point point in attachPointList)
// {
// if (point.lockedAgv != null && point.lockedAgv != agv)
// {
// flag = 99;
// continue;
// }
// point.lockedAgv = agv;
// lockedPoint.Add(point);
// }
// //判断旋转点周围有没有车
// if (flag == 0)
// {
// ClientMotion clientMotion = GetMotion(sonTask, currentPathPoint);
// motionList.Add(clientMotion);
// }
// return motionList;
//}
#endregion
//找到路径中此点以后的四个点
List<PathPoint> pathList = sonTask.pathPointList.Where(a => a.intSerialNo <= currentPathPoint.intSerialNo + 3).ToList();
pathList.Sort();
foreach (PathPoint pathPoint in pathList)
{
ClientMotion clientMotion = null;
Point point = pathPoint.point;
var oriPoint = motionList.FirstOrDefault(a => a.intOriDial != 0 && a.strBarcode != agv.strBarcode);
if (oriPoint != null)
{
break;
}
//获取路径下个点是否被占用
//如果是,判断距离是否满足车身长度,满足,申请,不满足直接不申请
PathPoint nextPath = sonTask.pathPointList.Find(a => a.intSerialNo == pathPoint.intSerialNo + 1);
if (nextPath != null && nextPath.point.lockedAgv != null && nextPath.point.lockedAgv != agv)
{
int length = ComnMethod.GetDistance(pathPoint.point.strBarcode, nextPath.point.strBarcode, "");
if (length < App.AgvLength) break;
}
#region 判断当前点占用小车是否位自己,否在重建路径
//AGV已申请的点直接加入Motion
if (point.lockedAgv == agv)
{
clientMotion = GetMotion(sonTask, pathPoint, agv);
lockedPoint.Add(point);
motionList.Add(clientMotion);
continue;
}
//不是当前小车申请的点
else if (point.lockedAgv != null)
{
//判断是不是小车当前点的下一个点
if (motionList.Count == 1)
{
Agv nextAgv = point.lockedAgv;
/*
* 若nextAgv没有任务,当前车需要重建路径
* 若nextAgv没有找到路径,当前车需要重建路径
*/
if (nextAgv.agvTask == null || nextAgv.agvTask.sonTaskList.Count == 0 || nextAgv.agvTask.sonTaskList[0].sonTaskState == EnumMsg.SonTaskState.建立路径失败)
{
UpdateManage.ResetPath(sonTask);
}
}
break;
}
#endregion
#region 互斥管控
if (point.strRegionName.Contains("Mutex"))
{
//if(point.strRegionName)
List<Point> mutexPointList = App.PointList.FindAll(a => a.strRegionName == point.strRegionName);
bool isMutexResult = MutexAreaContrl(mutexPointList, pathPoint, agv);
if (isMutexResult)
{
if (motionList.Count == 1)
agv.strStopReason = ComnMethod.GetStopReason(agv.strStopReason, "互斥区域的流量管控;");
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 提升机等待点
if (lockedPoint.Exists(a => a.pointType == EnumMsg.PointType.对接等待点) &&
currentPathPoint.point.pointType != EnumMsg.PointType.对接等待点) break;
#endregion
//判断申请点为站台附属点,并且当前任务终点为站台点,判断是否有车申请,有车申请不进
if ((pathPoint.point.pointType == EnumMsg.PointType.站台附属点|| pathPoint.point.pointType == EnumMsg.PointType.对接等待点)
&& sonTask.endPoint.strPreBarcode == point.strBarcode
&& sonTask.endPoint.lockedAgv != null && sonTask.endPoint.lockedAgv != agv) break;
#region 防止回环申请的管控
bool isLoop = false;
Loop(pathPoint, new List<Agv>() { agv }, ref isLoop);
if (isLoop)
{
//只有一个点的时候才报错
if (motionList.Count == 1)
agv.strStopReason = ComnMethod.GetStopReason(agv.strStopReason, "回环申请的管控;");
break;
}
#endregion
#region 特殊区域的流量管控
if (point.strRegionName.Contains("KeyArea"))
{
List<Point> keyPointList = App.PointList.Where(a => a.strRegionName == point.strRegionName).ToList();
bool isKeyResult = KeyAreaContrl(keyPointList, agv);
if (isKeyResult)
{
if (motionList.Count == 1)
agv.strStopReason = ComnMethod.GetStopReason(agv.strStopReason, "特殊区域的流量管控;");
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
#region 旋转区域的控制
if (point.strRegionName.Contains("Rotote"))
{
string strRegion = point.strRegionName;
if (point.strRegionName.Contains("&"))
{
string[] regionList = strRegion.Split('&');
Station station = App.StationList.Find(a => a.strBarcode == sonTask.endPoint.strBarcode);
if (station != null)
{
strRegion = regionList.FirstOrDefault(a => a.Contains(station.strStationNo));
}
else
{
station = App.StationList.Find(a => a.strBarcode == agv.strBarcode);
strRegion = regionList.FirstOrDefault(a => a.Contains(station.strStationNo));
}
}
if (strRegion != "")
{
//找到此旋转区域所有的点
List<Point> rototeList = App.PointList.Where(a => a.strRegionName.Contains(strRegion)).ToList();
bool isRototeResult = RototeContrl(rototeList, agv, sonTask);
if (isRototeResult)
{
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);
}
//检查最后的停止点距离下个路径点的距离
UpdateManage.relieveLocked(lockedPoint, agv);
return motionList;
}
catch (Exception Ex)
{
throw new Exception("Motions:" + Ex.StackTrace);
}
}
/// <summary>
/// 获取Motion
/// </summary>
/// <param name="sonTask">子任务</param>
/// <param name="currentPathPoint">待加入的路径点</param>
/// <returns></returns>
public static ClientMotion GetMotion(SonTask sonTask, PathPoint currentPathPoint, Agv agv)
{
try
{
ClientMotion clientMotion = new ClientMotion();
clientMotion.intTaskType = (int)sonTask.sonTaskType;
clientMotion.strBarcode = currentPathPoint.point.strBarcode;
clientMotion.intX = currentPathPoint.point.intX;
clientMotion.intY = currentPathPoint.point.intY;
clientMotion.intXLength = currentPathPoint.point.intXLength;
clientMotion.intYLength = currentPathPoint.point.intYLength;
clientMotion.intOriAgv = (int)currentPathPoint.point.oriAgv;
clientMotion.intPointType = (int)currentPathPoint.point.pointType;
clientMotion.intAntiCollision = (int)currentPathPoint.point.antiCollision;
if (currentPathPoint.pathPointType == 0)
{
clientMotion.intPathPointType = (int)currentPathPoint.point.pointType;
}
else
{
clientMotion.intPathPointType = (int)currentPathPoint.pathPointType;
}
if (clientMotion.intPathPointType != (int)EnumMsg.PointType.对接点)
{
clientMotion.intPathPointType = (int)EnumMsg.PointType.对接点;
}
if ((currentPathPoint.point.pointType == EnumMsg.PointType.站台附属点
|| currentPathPoint.point.pointType == EnumMsg.PointType.整体旋转点)
&& sonTask.endPoint.strPreBarcode == currentPathPoint.point.strBarcode)
{
clientMotion.intOriDial = currentPathPoint.point.oriDial.GetIndexInt();
}
if (currentPathPoint.point.pointType == EnumMsg.PointType.充电点)
{
clientMotion.intOriAgv = (int)App.StationList.Find(a => a.strBarcode == currentPathPoint.point.strBarcode).stationOri == 2 ? 4 : 2;
}
if (currentPathPoint.point.pointType == EnumMsg.PointType.对接点&& currentPathPoint.point.strBarcode=="750")
{
clientMotion.intOriAgv = 2;
clientMotion.intOriDial = 1;
}
if (currentPathPoint.point.pointType == EnumMsg.PointType.对接点 && currentPathPoint.point.strBarcode == "745")
{
clientMotion.intOriDial = 1;
}
#region 获取当前点的转盘方向
//ComnMethod.getAgvDial(currentPathPoint, agv);
#endregion
#region 充电车头方向及距离
if (sonTask.sonTaskType == EnumMsg.AgvTaskType.充电 || sonTask.sonTaskType == EnumMsg.AgvTaskType.取消充电)
{
//clientMotion.intOriAgv = (int)sonTask.agvDirection;
clientMotion.intXLength = sonTask.chargeLength;
clientMotion.intYLength = sonTask.chargeLength;
}
#endregion
return clientMotion;
}
catch (Exception Ex)
{
throw new Exception("GetMotion:" + Ex.Message.Replace(Environment.NewLine, ""));
}
}
/// <summary>
/// 检查是否有回旋死锁
/// </summary>
/// <param name="nowPoint"></param>
/// <param name="listAgv"></param>
/// <param name="isLoop"></param>
public static void Loop(PathPoint nowPoint, List<Agv> listAgv, ref bool isLoop)
{
try
{
//找最新的AGV
Agv lastAgv = listAgv.LastOrDefault();
PathPoint nextPoint = ComnMethod.GetNextPathPoint(lastAgv, nowPoint);
if (nextPoint != null)
{
//获取占用此点的AGV
Agv agv = nextPoint.point.lockedAgv;
//此点被另外的AGV占用了
if (agv != null && agv != lastAgv)
{
listAgv.Add(agv);
//如果还没找到第四个点,则继续找
if (listAgv.Count == 4)
{
if (listAgv[0].strAgvNo != listAgv[3].strAgvNo)
isLoop = true;
else
isLoop = false;
return;
}
Loop(nextPoint, listAgv, ref isLoop);
}
}
}
catch (Exception Ex)
{
throw new Exception("Loop:" + Ex.Message.Replace(Environment.NewLine, ""));
}
}
/// <summary>
/// 区域流量管控
/// </summary>
/// <param name="keyPointList"></param>
/// <param name="point"></param>
/// <returns></returns>
public static bool KeyAreaContrl(List<Point> keyPointList, Agv agv)
{
try
{
if (keyPointList.FirstOrDefault(a => a.strBarcode == agv.strBarcode) != null) return false;
//提取所有小车的当前点和关键区域所有的点,找相同则为区域内的小车数量
List<string> agvList = App.AgvList.Select(a => a.strBarcode).ToList();
List<string> keyList = keyPointList.Select(a => a.strBarcode).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.Replace(Environment.NewLine, ""));
}
}
/// <summary>
/// 旋转区域控制
/// </summary>
/// <param name="rototeList"></param>
/// <param name="agv"></param>
/// <param name="sonTask"></param>
/// <returns></returns>
public static bool RototeContrl(List<Point> rototeList, Agv agv, SonTask sonTask)
{
try
{
//找到此旋转区域的旋转点
Point rototePoint = rototeList.FirstOrDefault(a => a.pointType == EnumMsg.PointType.站台点);
//此区域没有被锁定
if (!rototePoint.isRegionApply)
{
//是不是要旋转,需要锁定旋转区域
if (sonTask.sonTaskType == EnumMsg.AgvTaskType.原地旋转 && sonTask.startPoint == rototePoint)
{
string sqlUpdate = string.Format(@"UPDATE T_Base_Point SET isRegionApply = '1', strRegionApplyAgvNo = '{1}' WHERE strBarcode = '{0}';"
, rototePoint.strBarcode, rototePoint.strRegionApplyAgvNo);
int isSqlResult = DbHelperSQL.ExecuteSql(sqlUpdate);
if (isSqlResult == 1)
{
rototePoint.isRegionApply = true;
rototePoint.strRegionApplyAgvNo = agv.strAgvNo;
}
}
}
else
{
//判断旋转区域有没有此车的占用
if (rototeList.FirstOrDefault(a => a.lockedAgv == agv) == null) return true;
//判断是否是此车占用
if (rototePoint.strRegionApplyAgvNo == agv.strAgvNo)
{
foreach (Point lockPoint in rototeList)
{
if (lockPoint.lockedAgv == null || lockPoint.lockedAgv == agv) continue;
if (lockPoint.lockedAgv.agvTask == null || lockPoint.lockedAgv.agvTask.sonTaskList.Count == 0) continue;
if (lockPoint.lockedAgv.agvTask.sonTaskList[0].pathPointList.Exists(a => a.point == rototePoint)) return true;
}
}
}
return false;
}
catch (Exception Ex)
{
throw new Exception("RototeContrl:" + Ex.Message.Replace(Environment.NewLine, ""));
}
}
/// <summary>
/// 互斥区域
/// </summary>
/// <param name="mutexPointList">当前点区域集合</param>
/// <param name="nowPoint">当前点</param>
/// <param name="agv">申请AGV</param>
/// <returns></returns>
public static bool MutexAreaContrl(List<Point> mutexPointList, PathPoint nowPoint, Agv agv)
{
try
{
if (mutexPointList.Count == 0) return false;
//当前子任务的终点
Point agvEndPoint = agv.agvTask.sonTaskList.First().endPoint;
//手动模式的任务的agv不进行管控
//if (agv.agvTask.strTaskID.Contains("手动")) return false;
//进入限制区域判定。
Point prePoint = App.PointList.Find(a => a.strBarcode == agvEndPoint.strPreBarcode);
if (prePoint != null && mutexPointList.Exists(a => a.strRegionName == prePoint.strRegionName)
&& agvEndPoint.lockedAgv != null && agvEndPoint.lockedAgv != agv) 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
//正常限制区域判定
if (mutexPointList.Exists(a => a.lockedAgv != null && a.lockedAgv != agv))
{
//|| nextPoint.point.pointType == EnumMsg.PointType.停靠点 || nowPoint.point.pointType == EnumMsg.PointType.站台附属点
if (mutexPointList.Find(a => a.strBarcode == agv.strBarcode) != null) return false;
PathPoint nextPoint = ComnMethod.GetNextPathPoint(agv, nowPoint);
if (nextPoint == null || mutexPointList.Exists(a => a.strBarcode == nextPoint.point.strBarcode)
|| nowPoint.point.pointType == EnumMsg.PointType.虚拟点) return true;
else
{
Agv lockAgv = mutexPointList.Find(a => a.lockedAgv != null).lockedAgv;
return false;
}
}
else
{
//可以找到该限制区域的所有站台附属点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.Replace(Environment.NewLine, ""));
}
}
public static int StopMutexAreaControl(List<Point> mutexPointList, PathPoint nowPoint, 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.sonTaskList.FirstOrDefault().pathPointList;
//申请AGV的路径 与 限制区域路径点的集合
var result8 = agvpath.FindAll(a => mutexPointList.Exists(b => b.strBarcode == a.point.strBarcode));
//获取所有限制区域内的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.sonTaskList.FirstOrDefault().endPoint.strRegionName == "area1");
if (sontaskAgv.Count > 1 && agv.agvTask.endPoint.strRegionName == "area1") return 1;
//20201112判断集合内的是否有任务起点是当前任务终点的AGV
bool taskAgv = result3.Exists(a => a.agvTask.startPoint == agv.agvTask.endPoint);
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.sonTaskList.SelectMany(b => b.pathPointList)).ToList();
if (result4.Count == 0) return 0;
//获取上述路径点集合和限制区域集合的交集
var result5 = result4.FindAll(a => mutexPointList.Exists(b => a.point.strBarcode == b.strBarcode));
if (result5.Count() == 0) return 0;
var result7 = result5.FindAll(a => agvpath.Exists(b => b.point.strBarcode == a.point.strBarcode));
//判断两个集合是否存在路径点方向差值等于2的
var result6 = result7.Exists(a => agvpath.Exists(b => Math.Abs((int)a.pathDirection - (int)b.pathDirection) == 2 && a.point.strBarcode == b.point.strBarcode));
if (result6)
{
return 1;
}
else
{
if (agvpath.Last().point.lockedAgv != null)
{
return 1;
}
else
{
return 0;
}
}
#region 注释
//手动模式的任务的agv不进行管控
//if (agv.agvTask.strTaskID.Contains("手动")) return 0;
//正常限制区域判定
//if (mutexPointList.Exists(a => a.lockedAgv != null && a.lockedAgv != agv))
//{
// //申请车在当前区域内,继续执行
// if (mutexPointList.Find(a => a.strBarcode == agv.strBarcode) != null) return 0;
// //判定当前区域内的agv是否同向行驶
// List<PathPoint> pathPointList = null;
// List<PathPoint> newPathPoints = new List<PathPoint>();
// List<Point> lockPoints = mutexPointList.FindAll(a => a.lockedAgv != null && a.lockedAgv != agv);
// if (lockPoints.Count == 0) return 0;
// List<Agv> agvs = new List<Agv>();
// foreach (Point lockPoint in lockPoints)
// {
// if (lockPoint.lockedAgv.agvTask != null)
// {
// //获取区域内lockAgv当前子任务的路径点
// if (lockPoint.lockedAgv.agvTask.sonTaskList.Count == 0) continue;
// agvs.Add(lockPoint.lockedAgv);
// }
// }
// //获取agv接下来的路径点
// foreach (Agv InAgv in agvs)
// {
// //当前任务的路径集合
// pathPointList = InAgv.agvTask.sonTaskList.FirstOrDefault().pathPointList;
// //当前点路径的序号
// int ss = pathPointList.Find(a => a.point.strBarcode == InAgv.strBarcode).intSerialNo;
// //接下来的路径点
// pathPointList = pathPointList.FindAll(a => a.intSerialNo > ss && a.point.strRegionName == nowPoint.point.strRegionName);
// foreach (PathPoint pa in pathPointList)
// {
// newPathPoints.Add(pa);
// }
// }
// foreach (PathPoint paths in agv.agvTask.sonTaskList.FirstOrDefault().pathPointList)
// {
// List<PathPoint> pathList = newPathPoints.FindAll(a => a.point.strBarcode == paths.point.strBarcode);
// if (pathList.Count == 0) { }
// else
// {
// //判断里面的路径方向是否与申请车的路径方向相反
// if (pathList.Exists(a => a.pathDirection == paths.pathDirection)) { }
// else
// {
// foreach (PathPoint patt in pathList)
// {
// int ss = Math.Abs((int)patt.pathDirection - (int)paths.pathDirection);
// if (ss == 2) return 1;
// }
// }
// }
// }
//}
#endregion
}
catch (Exception Ex)
{
throw new Exception("停靠点判定MutexAreaControl:" + Ex.StackTrace);
}
}
}
}