ChargeTask.cs
6.4 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
using CtuDeviceLib;
using Mushiny;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary.CtuService
{
/// <summary>
/// 充电任务
/// </summary>
public class ChargeTask : CtuTaskBase
{
public ChargeTask(CTU ctu, string dst) : base(ctu, dst)
{
Name = "充电任务";
}
public override void Excute()
{
if (string.IsNullOrEmpty(DstName))
{
Msg.add($"【{ctu.Name}】无充电位置,请检查充电位置是否配置", MsgLevel.warning);
return;
}
//当前位置不是目的地,就重新规划路线
if (MoveInfo.MoveStep != RunStep.Wait && MoveInfo.MoveStep != RunStep.Charge_01_MoveToDst)
{
if (ctu.CurLandMark != destination)
{
MoveInfo.NextMoveStep(RunStep.Wait);
MoveInfo.Info($"当前点位不在目标点【{DstName}】【{destination}】,重新进入充电流程");
}
}
switch (MoveInfo.MoveStep)
{
case RunStep.Wait:
if (!CalcDst())
{
Msg.add($"规划去【{DstName}】失败,请检查", MsgLevel.warning);
return;
}
MoveInfo.NextMoveStep(RunStep.Charge_01_MoveToDst);
MoveInfo.Info($"去充电点【{DstName}】【{destination}】");
break;
case RunStep.Charge_01_MoveToDst:
if (IsFinished)
{
MoveInfo.NextMoveStep(RunStep.Charge_02_AtDst);
MoveInfo.Info($"已到充电点【{DstName}】【{destination}】");
}
else
{
Move();
}
break;
case RunStep.Charge_02_AtDst:
if (StartChargeTask())
{
MoveInfo.NextMoveStep(RunStep.Charge_03_StartCharge);
MoveInfo.Info($"对接充电桩【{DstName}】【{destination}】");
}
else
{
MoveInfo.Info($"创建对接充电桩异常【{DstName}】【{destination}】");
Msg.add($"【{ctu.Name}】创建对接充电桩异常", MsgLevel.warning);
}
break;
case RunStep.Charge_03_StartCharge:
if (IsFinished)
{
MoveInfo.NextMoveStep(RunStep.Charge_04_Charging);
MoveInfo.Info($"对接充电桩成功【{DstName}】【{destination}】");
}
break;
case RunStep.Charge_04_Charging:
var task = findTasks();
if (task != null || RobotManager.IsReadyUpdate)
{
if (CreatesStopChargeTask())
{
MoveInfo.NextMoveStep(RunStep.Charge_05_ExitCharging);
MoveInfo.Info($"退出充电桩【{DstName}】【{destination}】");
}
else
{
MoveInfo.Info($"创建退出充电桩异常【{DstName}】【{destination}】");
Msg.add($"【{ctu.Name}】创建退出充电桩异常", MsgLevel.warning);
}
}
else
{
MoveInfo.Info($"充电中【{ctu.SOC}%】");
}
break;
case RunStep.Charge_05_ExitCharging:
if (IsFinished)
{
MoveInfo.NextMoveStep(RunStep.CtuTask_ProcessFinished);
MoveInfo.Info($"退出完成【{DstName}】【{destination}】【{ctu.SOC}%】,搜寻任务");
}
break;
case RunStep.CtuTask_ProcessFinished:
var nextTask = findTasks();
if (nextTask != null)
{
ctu.CtuTask = nextTask;
}
break;
}
}
bool StartChargeTask()
{
if (MushinyManager.GenStartChargePathPoints(ctu, dstPosInfo, out PathPoint pathPoint))
{
runInfo.Reset(CtuTaskRunInfo.StartCharge);
return createPathPoint(new List<PathPoint>() { pathPoint }, CtuTaskRunInfo.StartCharge);
}
else
{
return false;
}
}
bool CreatesStopChargeTask()
{
if (MushinyManager.GenStopChargePathPoints(ctu, dstPosInfo, out PathPoint pathPoint))
{
runInfo.Reset(CtuTaskRunInfo.StopCharge);
return createPathPoint(new List<PathPoint>() { pathPoint }, CtuTaskRunInfo.StopCharge);
}
else
{
return false;
}
}
CtuTaskBase findTasks()
{
var exitChargeSoc = ConfigAppSettings.GetValue(Setting_Init.Charge_ExitChargeSoc, 80);
if (ctu.SOC >= exitChargeSoc)
{
CtuTaskBase task = null;
{
task = new StandbyTask(ctu);
}
return task;
}
else
{
var forceChargeSoc = ConfigAppSettings.GetValue(Setting_Init.Charge_ForceChargeSoc, 80);
if (ctu.SOC <= forceChargeSoc + 5)
{
return null;
}
var othCtus = CTUManager.GetOhterEnabledCTUs(ctu);
if (othCtus != null && othCtus.Count > 0)
{
var find = othCtus.Find(s => (s.SOC < forceChargeSoc) || (s.SOC < ctu.SOC && s.CtuTask != null && s.CtuTask is StandbyTask));
if (find != null)
{
return new StandbyTask(ctu);
}
}
}
return null;
}
}
}