FullShelfJob.cs
8.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
using System;
using Model;
namespace BLL
{
public class FullShelfJob : IJob
{
private AgvInfo _info;
private MissionJob move;
private string mission;
private DateTime getTime;
private string key;
//private bool recycleFirst;
private JobStep<FullShelfStep> fullShelfStep;
public FullShelfJob()
{
IsEnd = false;
fullShelfStep = new JobStep<FullShelfStep>(FullShelfStep.None);
Common.log.Debug("加载FullShelfJob");
}
public bool IsEnd { get; private set; }
public IJob Execute(AgvInfo info)
{
_info = info;
if (fullShelfStep.Equals(FullShelfStep.None))
{
if (ManageWork.PauseFull)
EnterElevatorSideShelf();
else
FindLine();
}
else if (fullShelfStep.Equals(FullShelfStep.MoveLine))
{
MoveLine();
}
else if (fullShelfStep.Equals(FullShelfStep.MoveElevator))
{
MoveElevator();
}
else if (fullShelfStep.Equals(FullShelfStep.SendUseAsk))
{
ManageWork.SendElevatorUseAsk();
fullShelfStep.NextStep(FullShelfStep.UseAnswer);
fullShelfStep.Msg = string.Format("{0} 发送电梯使用请求", _info.Name);
}
else if (fullShelfStep.Equals(FullShelfStep.UseAnswer))
{
if (ManageWork.ElevatorUseAnswer())
{
ManageWork.PauseFull = false;
fullShelfStep.NextStep(FullShelfStep.CallElevator);
fullShelfStep.Msg = string.Format("{0} 电梯可以使用", _info.Name);
}
else if (ManageWork.FindElevatorWork())
{
//送满架子时,同时要回收空架子
ManageWork.PauseFull = true;
mission = Common.MISSION_LEAVE_SHELF;
move = new MissionJob(mission);
move.Execute(_info);
fullShelfStep.NextStep(FullShelfStep.LeaveShelf);
fullShelfStep.Msg = string.Format("{0} 暂停送满货架,优先拉空货架", _info.Name);
}
else
{
Common.log.Debug(string.Format("{0} 电梯还未应答使用请求", _info.Name));
}
}
else if (fullShelfStep.Equals(FullShelfStep.CallElevator))
{
ManageWork.ElevatorCall(true);
getTime = DateTime.Now;
fullShelfStep.NextStep(FullShelfStep.CancelCallElevator);
fullShelfStep.Msg = string.Format("{0} 发送电梯呼叫", _info.Name);
}
else if (fullShelfStep.Equals(FullShelfStep.CancelCallElevator))
{
TimeSpan ts = DateTime.Now - getTime;
if (ts.Seconds >= 3)
{
//呼叫信号不能长时间保持,3s-5s即可。
ManageWork.ElevatorCall(false);
fullShelfStep.Msg = string.Format("{0} 满3s以上取消呼叫保持", _info.Name);
fullShelfStep.NextStep(FullShelfStep.OpenDoorAnswer);
}
}
else if (fullShelfStep.Equals(FullShelfStep.OpenDoorAnswer))
{
if (ManageWork.ElevatorReady())
{
fullShelfStep.Msg = string.Format("{0} 电梯已开门", _info.Name);
fullShelfStep.NextStep(FullShelfStep.EnterInto);
}
else
{
Common.log.Debug(string.Format("{0} 电梯还未开门", _info.Name));
}
}
else if (fullShelfStep.Equals(FullShelfStep.EnterInto))
{
_info.Place = "送满架进电梯";
EnterInto();
}
else if (fullShelfStep.Equals(FullShelfStep.Leave))
{
move.Execute(_info);
if (move.IsEnd)
{
_info.Place = "电梯门外";
ManageWork.ElevatorFullShelf();
getTime = DateTime.Now;
fullShelfStep.Msg = string.Format("{0} 发送满料信号", _info.Name);
fullShelfStep.NextStep(FullShelfStep.EndTask);
}
}
else if (fullShelfStep.Equals(FullShelfStep.EndTask))
{
TimeSpan ts = DateTime.Now - getTime;
if (ts.Seconds >= 3)
{
//离开信号保持几秒后,取消所有信号
ManageWork.ElevatorEnd();
ManageWork.FirstFloorAdd();
fullShelfStep.Msg = string.Format("{0} 送满料任务结束,当前一楼货架数量{1}个", _info.Name, Common.FirstFloorCurr);
fullShelfStep.NextStep(FullShelfStep.End);
}
}
else if (fullShelfStep.Equals(FullShelfStep.LeaveShelf))
{
move.Execute(_info);
if (move.IsEnd)
{
fullShelfStep.NextStep(FullShelfStep.End);
fullShelfStep.Msg = string.Format("{0} 退出货架,[{1}]", _info.Name, mission);
}
}
else if (fullShelfStep.Equals(FullShelfStep.End))
{
IsEnd = true;
if (ManageWork.PauseFull)
{
return new RecycleJob();
}
else
{
IJob job = ManageWork.GetJob();
if (job == null)
return new StandbyJob();
else
return job;
}
}
return this;
}
private void FindLine()
{
bool rtn = ManageWork.FindLineWork(out string key, out string name);
if (rtn)
{
_info.Place = name;
this.key = key;
mission = Common.MISSION_CARRY_FULL + key;
move = new MissionJob(mission);
move.Execute(_info);
fullShelfStep.NextStep(FullShelfStep.MoveLine);
fullShelfStep.Msg = string.Format("{0} 送满货架任务,去{1},[{2}]", _info.Name, name, mission);
}
else
{
fullShelfStep.NextStep(FullShelfStep.End);
fullShelfStep.Msg = string.Format("{0} 没有找到产线呼叫,或产线没有货架", _info.Name);
}
}
private void MoveLine()
{
move.Execute(_info);
if (move.IsEnd)
{
ManageWork.LineTakeAway(key);
_info.Place = "去电梯";
mission = Common.MISSION_MOVE_ELEVATOR;
move = new MissionJob(mission);
move.Execute(_info);
fullShelfStep.NextStep(FullShelfStep.MoveElevator);
fullShelfStep.Msg = string.Format("{0} 送满货架任务,去电梯,[{1}]", _info.Name, mission);
}
}
private void EnterElevatorSideShelf()
{
_info.Place = "进入电梯旁货架";
mission = Common.MISSION_CARRY_ELEVATOR;
move = new MissionJob(mission);
move.Execute(_info);
fullShelfStep.NextStep(FullShelfStep.MoveElevator);
fullShelfStep.Msg = string.Format("{0} 送满货架任务,去电梯,[{1}]", _info.Name, mission);
}
private void MoveElevator()
{
move.Execute(_info);
if (move.IsEnd)
{
ManageWork.PauseFull = false;
_info.Place = "电梯等待位";
fullShelfStep.NextStep(FullShelfStep.SendUseAsk);
fullShelfStep.Msg = string.Format("{0} 到达电梯等待位", _info.Name);
}
}
private void EnterInto()
{
mission = Common.MISSION_ENTER_ELEVATOR_FULL;
move = new MissionJob(mission);
move.Execute(_info);
fullShelfStep.Msg = string.Format("{0} 送满货架进电梯,[{1}]", _info.Name, mission);
fullShelfStep.NextStep(FullShelfStep.Leave);
}
private enum FullShelfStep
{
None,
End,
MoveLine,
MoveElevator,
SendUseAsk,
UseAnswer,
CallElevator,
CancelCallElevator,
OpenDoorAnswer,
EnterInto,
Leave,
LeaveShelf,
EndTask
}
}
}