ChargeManage.cs
15.8 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
using XingYe_ACS.BaseStruct;
using XingYe_ACS.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace XingYe_ACS.Business
{
public class ChargeManager
{
public static void AgvCharge(int taskNum)
{
try
{
foreach (Agv agv in App.AgvList)
{
//记录日志
App.ExFile.MessageLog("AgvCharge", "进入充电判断");
if (agv.agvTask != null || !agv.isEnable || !agv.isOnline || agv.heightState != EnumMsg.HeightState.低位 || agv.isCarry == true) continue;
//待关机车辆禁止车辆
if (App.offAgvNo.Contains(agv.strAgvNo)) continue;
//当前AGV所在群组能够执行的所有任务群组
List<TaskAgvGroup> taskGroupList = App.TaskAgvGroupList.FindAll(b => b.agvGroup == agv.agvGroup);
//判断当前agv所在AGV群组对应的任务的群组里是否有未提交的任务
List<FTask> noSubmitList = App.TaskList.Where(a => !a.isTaskSubmit && a.strTaskAgv == ""
&& taskGroupList.Exists(b => b.taskGroup == a.strTaskGroup)).ToList();
//当前点不在地图中,禁止充电
Point startPoint = App.PointList.Find(a => a.strBarcode == agv.strBarcode);
if (startPoint == null) continue;
if (agv.agvState == EnumMsg.State.自动空闲)
{
//判断提升机有货 不做回家任务
//Hoister hoister = App.HoisterList.First();
//if (hoister.read_isFull) continue;
// if (agv.currentCharge > App.DangerCharge) continue;
//空闲AGV是否为其他车辆子任务终点
var agvPoint = App.PointList.Find(a => a.strBarcode == agv.strBarcode);
var sonTasks = App.TaskList.SelectMany(a => a.sonTaskList).ToList();
if (sonTasks.Count != 0)
{
var result = sonTasks.Exists(a => a.endPoint == agvPoint && a.sonTaskState != EnumMsg.SonTaskState.初始化);
if (result)
{
Point endPoint = null;
if (agvPoint.pointType == EnumMsg.PointType.充电点)
{
endPoint = App.PointList.Find(a => a.pointType == EnumMsg.PointType.避让点);
}
else
{
endPoint = App.PointList.Find(a => a.pointType == EnumMsg.PointType.充电点);
}
TaskManage.TaskBuild("回家", "", "", 1, agv.strAgvNo, "", startPoint, endPoint, "");
continue;
}
}
#region 测试电量
//Point point = App.PointList.Find(a => a.strBarcode == agv.strBarcode);
//if (point.pointType != EnumMsg.PointType.充电点) continue;
//int intChargeTime = 0;
//if (agv.chargeTime != DateTime.MinValue)
//{
// TimeSpan ts1 = new TimeSpan(agv.chargeTime.Ticks);
// TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks);
// TimeSpan ts3 = ts2.Subtract(ts1).Duration();
// intChargeTime = ts3.Minutes * 60 + ts3.Seconds;
//}
////20181006 充电延时
//if (intChargeTime < 120) continue;
#endregion
int flag = 0;
if (agv.currentCharge < App.DangerCharge)
{
NeedCharge(agv, ref flag);
}
//else if (agv.currentCharge < App.FullCharge && agv.currentCharge > App.DangerCharge)
//{
// if (noSubmitList.Count > 0) { flag = 0; }
// //查找是否有比当前车辆更低电量的车
// else if (App.AgvList.Where(a => a.isEnable && a.isOnline && a.agvTask == null
// && a.agvState == EnumMsg.State.自动空闲 && a.currentCharge < agv.currentCharge && a.agvGroup == agv.agvGroup).ToList().Count == 0)
// {
// NeedCharge(agv, ref flag);
// }
//}
//未找到充电桩,回家待命等待充电桩
if (flag == 99 || flag == 0)
//if(agv.agvState==EnumMsg.State.自动空闲 && agv.currentCharge >App.DangerCharge)
{
Station endStation = null;
//工位优先补车
Point minHomePoint = null;
//minHomePoint = ComnMethod.GetMinHomePoint(agv, 0);
minHomePoint = App.PointList.Find(a => a.intX == 10 && a.intY == 988);
if (agv.strBarcode == minHomePoint.strBarcode) continue;
App.ExFile.MessageLog("AgvCharge", "进入回家判断");
if (minHomePoint != null)
{
//endStation = App.StationList.Find(a => a.strBarcode == minHomePoint.strBarcode);
bool isResult = false;
isResult = TaskManage.TaskBuild("回家", "", "", 1, agv.strAgvNo,"", startPoint, minHomePoint, "");
if (isResult)
{
//agv.strChooseStation = endStation.strStationNo;
//endStation.isLocked = true;
//bool updateAgvResult = UpdateManage.UpdateAgvMsg(agv);
//bool updateAtationResult = UpdateManage.UpdateStation(endStation);
}
}
}
continue;
}
else if (agv.agvState == EnumMsg.State.充电中)
{
//异常或者满电结束充电
if (agv.strAgvError != "" || agv.currentCharge == 100)
{
TaskManage.TaskBuild("取消充电", "", "", 1, agv.strAgvNo, "", startPoint, startPoint, "");
taskNum--;
continue;
}
var hoister1 = App.HoisterList.First();
if (agv.currentCharge > App.DangerCharge && hoister1.read_isFull)
{
TaskManage.TaskBuild("取消充电", "", "", 1, agv.strAgvNo, "", startPoint, startPoint, "");
taskNum--;
continue;
}
#region 充电延时注释
int intChargeTime = 0;
if (agv.chargeTime != DateTime.MinValue)
{
TimeSpan ts1 = new TimeSpan(agv.chargeTime.Ticks);
TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks);
TimeSpan ts3 = ts2.Subtract(ts1).Duration();
intChargeTime = ts3.Minutes * 60 + ts3.Seconds;
}
//20181006 充电延时
if (intChargeTime < 3600) continue;
#endregion
//当前电量小于安全电量,继续充电
if (agv.currentCharge < App.DangerCharge) continue;
//充电量小于最小充电量,继续充电
//if (agv.currentCharge - agv.startCharges <= App.MinCharges) continue;
//当前AGV所属任务群组有未提交的任务
if (noSubmitList.Count > 0)
{
//获取所有能执行当前任务群组的AGV组
List<TaskAgvGroup> agvGroups =
App.TaskAgvGroupList.Where(a => a.taskGroup == noSubmitList[0].strTaskGroup).ToList();
//判断当前任务群组小车是否有取消充电任务
if (App.AgvList.Where(a => ((a.agvTask != null && a.agvTask.strTaskID == "取消充电")
|| (a.isEnable && a.isOnline && a.agvTask == null && a.agvState != EnumMsg.State.充电中))
&& agvGroups.Exists(b => b.agvGroup == a.agvGroup)).ToList().Count > 0) continue;
TaskManage.TaskBuild("取消充电", "", "", 1, agv.strAgvNo, "", startPoint, startPoint, "");
}
// int tt = App.AgvList.Where(a => a.agvTask != null && a.agvTask.strTaskID == "取消充电").ToList().Count;
//int ss = App.AgvList.Where(a => a.isEnable && a.isOnline && a.agvTask == null && a.agvState == EnumMsg.State.自动空闲).ToList().Count;
//if (taskNum <= (tt + ss) && agv.currentCharge < App.FullCharge) continue;
taskNum--;
}
}
}
catch (Exception Ex)
{
App.ExFile.MessageError("AgvCharge", Ex.StackTrace);
}
}
public static void NeedCharge(Agv agv, ref int flag)
{
try
{
#region
//int intMin = 0;
//Station minCs = null;
////获取所有充电点
//List<Point> listPoint = App.PointList.Where(a => a.pointType == EnumMsg.PointType.充电点).ToList();
//foreach (Point point in listPoint)
//{
// Station Cs = App.StationList.FirstOrDefault(a => a.isEnable && !a.isLocked && a.strBarcode == point.strBarcode);
// if (Cs == null) { continue; }
// else
// {
// Point agvPoint = App.PointList.Find(a => a.strBarcode == agv.strBarcode);
// if (point == null) { continue; }
// int csMinNum = Common.ComnMethod.GetMinPoint(agvPoint.intX, agvPoint.intY, point.intX, point.intY);
// if (intMin == 0) intMin = csMinNum;
// if (csMinNum <= intMin)
// {
// minCs = Cs;
// intMin = csMinNum;
// }
// }
//}
#endregion
Station minCs = null;
Point startPoint = App.PointList.Find(a => a.strBarcode == agv.strBarcode);
//未安装充电桩
if (startPoint.pointType == EnumMsg.PointType.充电点)
{
minCs = App.StationList.Find(a => a.strBarcode == startPoint.strBarcode);
}
else
{
minCs = ComnMethod.GetMinChargeStation(agv);
if (minCs == null)
{
agv.strStopReason = ComnMethod.GetStopReason(agv.strStopReason, "未找到充电桩;");
//未找到充电桩,判断充电中的车是否有满足条件可取消充电的车
//当前AGV所在群组能够执行的所有任务群组
List<TaskAgvGroup> taskGroupList = App.TaskAgvGroupList.FindAll(b => b.agvGroup == agv.agvGroup);
//判断是否有取消充电任务
FTask cancleTask = App.TaskList.FirstOrDefault(a => a.strTaskID == EnumMsg.TaskType.取消充电.ToString());
if (cancleTask == null && agv.currentCharge <= App.SafeCharge)
{
List<Agv> safeAgv = new List<Agv>();
//执行相同任务群组的AGV是否有可以取消充电的任务
safeAgv = App.AgvList.Where(a => a.currentCharge > App.SafeCharge
&& agv.currentCharge - agv.startCharges < App.MinCharges
&& a.agvState == EnumMsg.State.充电中
&& agv.agvTask == null && a.isEnable && a.isOnline
&& taskGroupList.Exists(b => b.agvGroup == a.agvGroup)).OrderByDescending(a => a.currentCharge).ToList();
if (safeAgv.Count == 0)
{
//按照电量从高到底排序
safeAgv = App.AgvList.Where(a => a.currentCharge > App.SafeCharge
&& agv.currentCharge - agv.startCharges < App.MinCharges
&& a.agvState == EnumMsg.State.充电中
&& agv.agvTask == null && a.isEnable && a.isOnline).OrderByDescending(a => a.currentCharge).ToList();
}
if (safeAgv.Count != 0)
{
Agv sAgv = safeAgv[0];
Point point = App.PointList.Find(a => a.strBarcode == sAgv.strBarcode);
TaskManage.TaskBuild("取消充电", "", "", 1, sAgv.strAgvNo, "", point, point, "");
flag = 2;
return;
}
}
flag = 99;
}
}
if (minCs != null)
{
Point endPoint = App.PointList.Find(a => a.strBarcode == minCs.strBarcode);
bool result = false;
if (startPoint.AreaType != endPoint.AreaType && agv.agvAreaType == "2")
{
result = TaskManage.TaskBuild("充电-1", "", "", 1, agv.strAgvNo, minCs.strStationNo, startPoint, endPoint, "");
}
else
{
result = TaskManage.TaskBuild("充电", "", "", 1, agv.strAgvNo, minCs.strStationNo, startPoint, endPoint, "");
}
if (result)
{
Station endCs = App.StationList.Find(a => a.strBarcode == endPoint.strBarcode);
endCs.isLocked = true;
bool isResult = UpdateManage.UpdateStation(endCs);
agv.strChooseStation = endCs.strStationNo;
bool isResultCs = UpdateManage.UpdateAgvMsg(agv);
flag = 1;
}
}
}
catch (Exception Ex)
{
App.ExFile.MessageError("NeedCharge", Ex.Message.Replace(Environment.NewLine, ""));
}
}
}
}