CommLineJob.cs
7.3 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
using AGVLib;
using DeviceLib.Model.AGV;
using System;
using System.Reflection;
using static System.Collections.Specialized.BitVector32;
namespace DeviceLib.BLL
{
internal class CommLineJob : ImpJob
{
public CommLineJob(JobParam jobParam) : base(jobParam)
{
JobName = $"与【{jobParam.CurDstNode.Name}】通讯";
}
public override Job Run(Robot robot)
{
Job job = this;
switch (JobRunStep.CurStep)
{
case RunStep.None:
ToNextStep(RunStep.CommLine_01_ReadyToCommLine, "准备与目标线体交互");
break;
case RunStep.CommLine_01_ReadyToCommLine:
ToNextStep(RunStep.CommLine_02_Request, "请求线体");
request();
break;
case RunStep.CommLine_02_Request:
ToNextStep(RunStep.CommLine_03_ResponseWait, $"等待线体响应{getAction()}");
break;
case RunStep.CommLine_03_ResponseWait:
getResponse();
break;
case RunStep.CommLine_04_ResponseAllow:
ToNextStep(RunStep.CommLine_06_ShelfMoving, "料架转移中");
transferShelf(robot);
break;
case RunStep.CommLine_05_ResponseDeny:
job = (Job)Activator.CreateInstance(JobParam.CallbackJob.Type);
job.JobParam = JobParam;
job.ToNextStep(JobParam.CallbackJob.RunStep, "与线体交互完成,因线体拒绝");
break;
case RunStep.CommLine_06_ShelfMoving:
if (JobRunStep.IsTimeOut(30))
{
ToNextStep(RunStep.CommLine_07_ShelfMovingTimeOut, "转移料架超时");
}
else if (ShelfMovingOk())
{
ToNextStep(RunStep.CommLine_08_ShelfMovingSuccess, "转移料架完成");
Turn(robot);
}
break;
case RunStep.CommLine_07_ShelfMovingTimeOut:
if (ShelfMovingOk())
{
ToNextStep(RunStep.CommLine_08_ShelfMovingSuccess, "转移料架完成");
Turn(robot);
}
break;
case RunStep.CommLine_08_ShelfMovingSuccess:
if (MissionIsOk())
{
NodeManager.Complete(JobParam.CurDstNode.Id);
//改变负载状态
setLodInfo(robot);
job = GetCallBackJob();
job.ToNextStep(GetCallBackStep(), "与线体交互完成");
}
break;
}
return job;
}
bool ShelfMovingOk()
{
finish();
return MissionIsOk()
&& (NodeManager.GetNodeStatus(JobParam.CurDstNode.Id).Equals(NodeStatus.FinishLeave)
|| NodeManager.GetNodeStatus(JobParam.CurDstNode.Id).Equals(NodeStatus.FinishEnter));
}
void request()
{
switch (JobParam.JobGoal)
{
case JobGoal.Send:
case JobGoal.Return:
NodeManager.RequestEnter(JobParam.CurDstNode.Id);
break;
case JobGoal.Get:
NodeManager.RequestLeave(JobParam.CurDstNode.Id);
break;
}
}
void finish()
{
if (MissionIsOk())
{
switch (JobParam.JobGoal)
{
case JobGoal.Send:
case JobGoal.Return:
if (NodeManager.GetNodeStatus(JobParam.CurDstNode.Id).Equals(NodeStatus.MayEnter))
NodeManager.Complete(JobParam.CurDstNode.Id);
break;
case JobGoal.Get:
if (NodeManager.GetNodeStatus(JobParam.CurDstNode.Id).Equals(NodeStatus.MayLeave))
NodeManager.Complete(JobParam.CurDstNode.Id);
break;
}
}
}
void setLodInfo(Robot robot)
{
switch (JobParam.JobGoal)
{
case JobGoal.Send:
case JobGoal.Return:
//NodeManager.RequestEnter(JobParam.CurDstNode.Id);
RobotManager.SetLoadInfo(robot.id, GetEmptySide(robot), ShelfType.None);
break;
case JobGoal.Get:
//NodeManager.RequestLeave(JobParam.CurDstNode.Id);
RobotManager.SetLoadInfo(robot.id, GetNoneSide(robot), ShelfType.Full, JobParam.FullBoxId);
HttpManager.BoxToAgv(JobParam.FullBoxId, robot.name);
break;
}
}
string getAction()
{
string action = "";
switch (JobParam.JobGoal)
{
case JobGoal.Send:
case JobGoal.Return:
action = NodeStatus.RequestEnter.ToString();
break;
case JobGoal.Get:
action = NodeStatus.RequestLeave.ToString();
break;
}
return action;
}
void getResponse()
{
if (JobRunStep.IsTimeOut(30))
{
ReTime();
SetWarnMsg($"线体响应{getAction()}超时,再次请求");
request();
}
else
{
if (JobParam.JobGoal.Equals(JobGoal.Send) || JobParam.JobGoal.Equals(JobGoal.Return))
{
switch (NodeManager.GetNodeStatus(JobParam.CurDstNode.Id))
{
case NodeStatus.MayEnter:
ToNextStep(RunStep.CommLine_04_ResponseAllow, "线体允许入料");
break;
case NodeStatus.RejectEnter:
ToNextStep(RunStep.CommLine_05_ResponseDeny, "线体拒绝入料");
break;
}
}
else if (JobParam.JobGoal.Equals(JobGoal.Get))
{
switch (NodeManager.GetNodeStatus(JobParam.CurDstNode.Id))
{
case NodeStatus.MayLeave:
ToNextStep(RunStep.CommLine_04_ResponseAllow, "线体允许出料");
break;
case NodeStatus.RejectLeave:
ToNextStep(RunStep.CommLine_05_ResponseDeny, "线体拒绝出料");
break;
}
}
}
}
void transferShelf(Robot robot)
{
switch (JobParam.JobGoal)
{
case JobGoal.Send:
PutDown(robot, GetEmptySide(robot));
break;
case JobGoal.Get:
case JobGoal.Return:
PickUp(robot, GetNoneSide(robot));
break;
}
}
}
}