ChargeJob.cs
5.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
using System;
using Model;
namespace BLL
{
public class ChargeJob : IJob
{
private AgvInfo _info;
private MoveJob move;
private string mission;
private JobStep<ChargeStep> chargeStep;
private IJob job;
private const int CHARGE_PLC = 20;
public ChargeJob()
{
chargeStep = new JobStep<ChargeStep>(ChargeStep.None);
Common.log.Debug("加载ChargeJob");
}
public bool IsEnd { get; private set; }
public string Msg
{
get
{
return chargeStep.Msg;
}
}
public IJob Execute(AgvInfo info)
{
_info = info;
if (chargeStep.Equals(ChargeStep.None))
{
_info.From = "";
_info.Place = "";
_info.LogJson.SetMissionStart("充电任务", "充电桩");
_info.LogJson.SetMissionStep("开始执行任务", ChargeStep.None.ToString());
if (_info.IsWorkspace())
MoveWash();
else
PassDoor();
}
else if (chargeStep.Equals(ChargeStep.PassDoor))
{
move.Execute(_info);
if (move.IsEnd)
{
MoveWash();
_info.LogJson.SetMissionStep("已过门", ChargeStep.PassDoor.ToString());
}
}
else if (chargeStep.Equals(ChargeStep.WaitWashPoint))
{
move.Execute(_info);
if (move.IsEnd)
{
_info.LogJson.SetMissionStep("到达" + _info.Workshop + "清洗房", ChargeStep.WaitWashPoint.ToString());
MoveCharge();
}
}
else if (chargeStep.Equals(ChargeStep.MoveStation))
{
move.Execute(_info);
MoveStation();
}
else if (chargeStep.Equals(ChargeStep.Charging))
{
Common.log.Debug(string.Format("{0} 充电中 当前{1} 最小{2} 最大{3}", _info.Name, _info.Battery, _info.BatteryMin, _info.BatteryMax));
move.Execute(_info);
if (_info.Battery == _info.BatteryMax)
{
chargeStep.Msg = _info.Name + " 电量达到" + _info.BatteryMax;
chargeStep.NextStep(ChargeStep.End);
_info.LogJson.SetMissionStep("结束充电", ChargeStep.Charging.ToString());
}
else if (_info.Battery > _info.BatteryMin)
{
job = SteelManage.GetSteelJob(_info);
if (job != null)
{
_info.LogJson.SetMissionStep("结束充电", ChargeStep.Charging.ToString());
Common.log.Info(_info.Name + " 结束充电,接收到任务" + job.ToString());
move.DeleteTask(_info);
chargeStep.NextStep(ChargeStep.DeleteTask);
}
}
}
else if (chargeStep.Equals(ChargeStep.DeleteTask))
{
move.Execute(_info);
if (move.IsEnd)
return job;
else
move.DeleteTask(_info); //没有成功删除时继续发删除
}
else if (chargeStep.Equals(ChargeStep.End))
{
_info.Place = "充电结束";
//_info.LogJson.SetMissionStep("充电任务结束", ChargeStep.End.ToString());
Common.mir.Del_Mission(_info.IP, _info.Authorization);
chargeStep.Msg = _info.Name + " 充电工作结束,回待机位";
return new StandbyJob();
}
return this;
}
private void MoveWash()
{
mission = Common.MISSION_MOVE_WASH + _info.Workshop;
_info.Place = string.Format("去{0}清洗点", _info.Workshop);
move = new MoveJob(mission);
move.Execute(_info);
chargeStep.NextStep(ChargeStep.WaitWashPoint);
chargeStep.Msg = _info.Name + " 发送回清洗点任务 " + mission;
}
private void MoveCharge()
{
mission = Common.MISSION_CHARGE + _info.Workshop;
_info.Place = "去充电位";
move = new MoveJob(mission);
move.Execute(_info);
chargeStep.NextStep(ChargeStep.MoveStation);
chargeStep.Msg = _info.Name + " 发送充电任务 " + mission;
}
private void PassDoor()
{
mission = Common.MISSION_PASS_DOOR_INTO + _info.Workshop;
_info.Place = string.Format("去{0}车间", _info.Workshop);
move = new MoveJob(mission);
move.Execute(_info);
chargeStep.NextStep(ChargeStep.PassDoor);
chargeStep.Msg = _info.Name + " 发送过车间门任务 " + mission;
}
private void MoveStation()
{
bool rtn = Common.mir.Get_Register(_info.IP, _info.Authorization, CHARGE_PLC, out int value);
if (rtn)
{
if (value == 1)
{
_info.Place = "充电中";
chargeStep.Msg = _info.Name + " 到达充电位,准备充电";
chargeStep.NextStep(ChargeStep.Charging);
_info.LogJson.SetMissionStep("到达充电位", ChargeStep.MoveStation.ToString());
}
}
}
private enum ChargeStep
{
None,
End,
PassDoor,
MoveStation,
GoWashPoint,
WaitWashPoint,
Charging,
DeleteTask
}
}
}