AGVExtensions.cs
5.01 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
using RCS.Model.Comm;
using RCS.Model.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static RCS.Model.Comm.EnumMsg;
namespace RCS.WinClient.Common;
public static class AGVExtensions
{
#region AGV通用
/// <summary>
/// 判断车是否能接任务
/// </summary>
/// <param name="agv"></param>
/// <returns></returns>
public static bool IsCanExecTask(this Base_Agv agv)
{
var agvPoint = App.PointList.FirstOrDefault(x => x.Barcode == agv.Barcode);
if (agvPoint == null)
{
return false;
}
//只有在 站台附属点、充电桩、出库区才能接任务
if (agv.AgvType == AgvType.叉车 && agvPoint.PointType == EnumMsg.PointType.站台点)
{
agv.StopReason = ComnMethod.GetStopReason(agv.StopReason, $"AGV在【站台点】不能接任务!");
return false;
}
if (IsFree(agv) && agv.Voltage > App.GetKeyValue("DangerCharge"))
{
return true;
}
return false;
}
/// <summary>
/// agv是否正常
/// </summary>
/// <param name="agv"></param>
/// <returns></returns>
public static bool IsNormal(this Base_Agv agv)
{
if (agv != null
&& agv.IsOnline
&& agv.IsEnable
&& string.IsNullOrWhiteSpace(agv.StopReason)
&& string.IsNullOrWhiteSpace(agv.Error))
return true;
return false;
}
/// <summary>
/// agv是否空闲
/// </summary>
/// <param name="agv"></param>
/// <returns></returns>
public static bool IsFree(this Base_Agv agv)
{
if (IsNormal(agv)
&& agv.AgvState == EnumMsg.AGVState.自动空闲
&& !App.OffAgvNos.Contains(agv.AgvNo)//待关机车辆不属于空闲
&& !App.TaskList.Any(t => t.TaskAgvNo == agv.AgvNo)//任务可能事先分配
&& agv.IsNotHaveGoods()
&& agv.AgvTask == null
//非叉车只能低位接任务
&& (agv.AgvType == AgvType.叉车 || agv.AgvType != AgvType.叉车 && agv.HeightState == HeightState.低位)
)
return true;
return false;
}
/// <summary>
/// 全部无货
/// 或者有货但是agv在站台且处于低位就判定为无货
/// </summary>
/// <returns></returns>
public static bool IsNotHaveGoods(this Base_Agv agv)
{
return !agv.SensorStatus.HasFlag(SensorStatus.车顶有货)
//顶升式agv在站台底下存在误检测可能
|| (agv.AgvType != AgvType.叉车 && agv.SensorStatus.HasFlag(SensorStatus.车顶有货)
&& App.StationList.Exists(station => station.Barcode == agv.Barcode)
&& agv.HeightState == HeightState.低位);
}
public static Base_SubTask? GetCurrSonTask(this Base_Agv agv)
{
var sonTask = agv
?.AgvTask
?.SubTaskList
?.Get(0);
return sonTask;
}
public static bool IsOnPoint(this Base_Agv agv, out Base_Point? point, int error = 25)
{
point = App.PointList.Find(x => ComnMethod.IsOnPoint(x, agv.XLength, agv.YLength, error));
return point != null;
}
public static bool IsInMap(this Base_Agv agv, double? tempX = null, double? tempY = null)
{
try
{
var agvPoint = new Base_Point()
{
XLength = (int)(tempX ?? agv.XLength),
YLength = (int)(tempY ?? agv.YLength)
};
var task = agv.AgvTask;
var sonTask = task?.SubTaskList?.FirstOrDefault();
if (
task == null
|| sonTask == null
|| sonTask.SubTaskState <= SubTaskState.建立路径失败
|| sonTask.PathPointList.Count == 0
)
return false;
var pathList = sonTask.PathPointList;
//任务中点位刷新不及时,当前点实际为上一个点
var lastPoint = App.PointList.Find(x => x.Barcode == agv.Barcode);
if (lastPoint == null)
return false;
var nextPathPoint = ComnMethod.GetNextPathPoint(agv, agv.Barcode);
if (nextPathPoint == null)
return false;
var res = agvPoint.IsOnLineSegment(lastPoint, nextPathPoint.Point);
if (!res)
return false;
App.ExFile.MessageLog("Motions", $"agv:{agv.AgvNo}在执行{agv.AgvTask?.TaskType}任务{agv.AgvTask?.TaskNo}:{sonTask.TaskNo}的子任务:{sonTask?.SubTaskNo}时agv不在点位上,但是在地图中{agv.Barcode},{agvPoint.IntX},{agvPoint.IntY}");
return true;
}
catch (Exception ex)
{
App.ExFile.MessageError("IsInMap", ex.Message + ex.StackTrace);
return false;
}
}
#endregion
}