ChargeManage.cs
7.76 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
using RCS.Model.Comm;
using RCS.Model.Entity;
namespace RCS.WinClient.Service
{
public class ChargeManager
{
/// <summary>
/// 充电或是回家
/// </summary>
public static void AgvCharge()
{
try
{
foreach (Base_Agv agv in App.AgvList)
{
if (agv.AgvTask != null || !agv.IsEnable || !agv.IsOnline || agv.InStock != EnumMsg.InStock.全部无货) continue;
//待关机车辆禁止车辆
if (App.offAgvNo.Contains(agv.AgvNo)) continue;
//当前点不在地图中,禁止充电
Base_Point startPoint = App.PointList.Find(t => t.Barcode == agv.Barcode);
if (startPoint == null) continue;
if (agv.AgvState == EnumMsg.State.自动空闲)
{
// 充电
if ((DateTime.Now - agv.FreeTime).TotalSeconds > App.GetKeyValue("MinFreeTime"))
{
if (App.TaskList.Any(t => t.TaskAgvNo == agv.AgvNo && t.TaskID == EnumMsg.TaskType.充电.ToString())) continue;
if (agv.Voltage <= App.GetKeyValue("DangerCharge") || agv.power <= App.GetKeyValue("DangerVoltage"))
{
NeedCharge(agv);
continue;
}
if (agv.Voltage < App.GetKeyValue("SafeCharge") || agv.power < App.GetKeyValue("SafeVoltage") || agv.VirtuallyVoltage < App.GetKeyValue("DangerVirtuallyVoltage"))
{
if (!App.TaskList.Any(t => t.PredictAgvNo == agv.AgvNo))
{
NeedCharge(agv);
continue;
}
}
}
// 回家
if ((DateTime.Now - agv.FreeTime).TotalSeconds > App.GetKeyValue("GoHomeTime"))
{
if (App.TaskList.Any(t => t.TaskAgvNo == agv.AgvNo && t.TaskID == EnumMsg.TaskType.手动行走.ToString())) continue;
if (agv.AgvNo == "A33_9001")
{
var stopPoint = App.PointList.FirstOrDefault(t => t.Barcode == "1326");
TaskManage.TaskBuild(EnumMsg.TaskType.手动行走.ToString(), EnumMsg.TaskGroup.RCS单步任务.ToString(), "1", 1, agv.AgvNo, startPoint.Barcode, stopPoint.Barcode, "", "", "");
continue;
}
if (agv.AgvNo == "A33_9002")
{
var stopPoint = App.PointList.FirstOrDefault(t => t.Barcode == "805");
TaskManage.TaskBuild(EnumMsg.TaskType.手动行走.ToString(), EnumMsg.TaskGroup.RCS单步任务.ToString(), "1", 1, agv.AgvNo, startPoint.Barcode, stopPoint.Barcode, "", "", "");
continue;
}
}
}
else if (agv.AgvState == EnumMsg.State.充电中)
{
//异常或者满电结束充电
if (agv.Error != "" || agv.Voltage >= App.GetKeyValue("FullCharge") && agv.current < App.GetKeyValue("FullCurrent") || agv.batteryflag > 0)
{
var result = TaskManage.TaskBuild(EnumMsg.TaskType.取消充电.ToString(),
EnumMsg.TaskGroup.RCS单步任务.ToString(),
"", 1, agv.AgvNo, agv.Barcode, agv.Barcode, "", "", "");
if (result.Success)
App.ExFile.MessageLog("TaskBuild", $"因为车不满足充电条件,生成AGV【{agv.AgvNo}】的【取消充电】任务!当前车辆电量【{agv.Voltage}】电流【{agv.current}】充满标识【{agv.batteryflag}】错误【{agv.Error}】");
else
App.ExFile.MessageBusinessErr("TaskBuild", $"因为车不满足充电条件,生成AGV【{agv.AgvNo}】的【取消充电】任务失败,原因:{result.Msg}!");
continue;
}
//当前电量小于安全电量、电压小于安全电压,就继续充电
if (agv.Voltage <= App.GetKeyValue("DangerCharge") || agv.power <= App.GetKeyValue("DangerVoltage")) continue;
//如果充电时间小于最少充电时间,继续充电
if ((DateTime.Now - agv.ChargeTime).TotalSeconds < App.GetKeyValue("MinChargeTime")) continue;
//当前AGV所属任务群组有未提交的任务
if (App.TaskList.Any(t => t.PredictAgvNo == agv.AgvNo))
{
//判断是否有取消充电任务,已经有取消充电的任务,就不处理
if (App.TaskList.Any(t => t.TaskAgvNo == agv.AgvNo && t.TaskID == EnumMsg.TaskType.取消充电.ToString())) continue;
var result = TaskManage.TaskBuild(EnumMsg.TaskType.取消充电.ToString(),
EnumMsg.TaskGroup.RCS单步任务.ToString(),
"1", 1, agv.AgvNo, agv.Barcode, agv.Barcode, "", "", "");
if (result.Success)
App.ExFile.MessageLog("TaskBuild", $"因为有预分配给车的任务,生成AGV【{agv.AgvNo}】的【取消充电】任务!");
else
App.ExFile.MessageBusinessErr("TaskBuild", $"因为有预分配给车的任务,生成AGV【{agv.AgvNo}】的【取消充电】任务失败,原因:{result.Msg}!");
continue;
}
}
}
}
catch (Exception ex)
{
App.ExFile.MessageError("AgvCharge", $"充电和回家发生异常,原因:{ex.Message},堆栈:{ex.StackTrace}");
}
}
/// <summary>
/// 充电
/// </summary>
/// <param name="agv"></param>
/// <param name="flag"></param>
public static void NeedCharge(Base_Agv agv)
{
try
{
//一个车对应一个充电桩
var chargeName = agv.ChargeName;
Base_Station minCs = App.StationList.FirstOrDefault(t => t.Name == chargeName);
if (minCs != null)
{
var result = TaskManage.TaskBuild(EnumMsg.TaskType.充电.ToString(),
EnumMsg.TaskGroup.RCS单步任务.ToString(),
"1", 1, agv.AgvNo, agv.Barcode, minCs.Barcode, "", "", "");
if (result.Success)
App.ExFile.MessageLog("TaskBuild", $"生成AGV【{agv.AgvNo}】的【充电】任务!");
else
App.ExFile.MessageBusinessErr("TaskBuild", $"生成AGV【{agv.AgvNo}】的【充电】任务失败,原因:{result.Msg}!");
}
}
catch (Exception ex)
{
App.ExFile.MessageError("NeedCharge", ex.Message.Replace(Environment.NewLine, ""));
}
}
}
}