StandbyJob.cs
4.2 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
using AGVControl_Steel;
namespace Model
{
public class StandbyJob : Job
{
private string id;
private JobStep<StandbyStep> standbyStep;
public StandbyJob()
{
standbyStep = new JobStep<StandbyStep>(StandbyStep.None);
}
public override Job Execute(AgvInfo info)
{
if (standbyStep.IsEqual(StandbyStep.None))
{
if (info.IsSelfWorkshop())
MoveStandby(info);
else
MoveDoor(info);
}
else if (standbyStep.IsEqual(StandbyStep.WaitWorkshopDoor))
{
rtn = Common.mir.Get_MissionState_Fleet(info.Authorization, id, out string state);
if (rtn)
{
if (state == MissionState.Done.ToString())
MoveStandby(info);
else if (state == MissionState.Aborted.ToString())
standbyStep.Msg = info.FullName + "任务状态" + MissionState.Aborted.ToString();
}
else
{
standbyStep.Msg = info.FullName + "获取任务状态id[" + id + "]失败";
}
}
else if (standbyStep.IsEqual(StandbyStep.WaitStandby))
{
rtn = Common.mir.Get_MissionState_Fleet(info.Authorization, id, out string state);
if (rtn)
{
if (state == MissionState.Done.ToString())
{
standbyStep.Msg = info.FullName + "已在待机位";
standbyStep.NextStep(StandbyStep.End);
}
else if (state == MissionState.Aborted.ToString())
{
standbyStep.Msg = info.FullName + "任务状态" + MissionState.Aborted.ToString();
}
}
else
{
standbyStep.Msg = info.FullName + "获取任务状态id[" + id + "]失败";
}
}
else if (standbyStep.IsEqual(StandbyStep.End))
{
if (info.Battery <= info.BatteryMin)
{
Common.log.Info(info.FullName + "电量小于" + info.BatteryMin + ",执行充电任务");
return new ChargeJob();
}
else
{
Job job = Common.steelManage.GetSteelJob(info);
if (job != null) return job;
}
}
return this;
}
private void MoveDoor(AgvInfo info)
{
if (info.Workshop == Common.WORKSHOP_4D)
mission = Common.MISSION_MOVE_4C_4D;
else if (info.Workshop == Common.WORKSHOP_4C)
mission = Common.MISSION_MOVE_4D_4C;
rtn = Common.mir.Add_Mission_Fleet(info.FleetID, info.Authorization, mission, out id);
if (rtn)
{
standbyStep.Msg = info.FullName + "在" + info.Workshop + "车间,先过车间门";
standbyStep.NextStep(StandbyStep.WaitWorkshopDoor);
}
else
{
standbyStep.Msg = info.FullName + "发送" + mission + "任务失败";
}
}
private void MoveStandby(AgvInfo info)
{
if (info.Workshop == Common.WORKSHOP_4D)
mission = Common.MISSION_STANDBY_4D;
else if (info.Workshop == Common.WORKSHOP_4C)
mission = Common.MISSION_STANDBY_4C;
rtn = Common.mir.Add_Mission_Fleet(info.FleetID, info.Authorization, mission, out id);
if (rtn)
{
info.Place = "待机位";
standbyStep.Msg = info.FullName + "回待机位" + mission;
standbyStep.NextStep(StandbyStep.WaitStandby);
}
else
{
standbyStep.Msg = info.FullName + "发送" + mission + "任务失败";
}
}
private enum StandbyStep
{
None,
WaitWorkshopDoor,
WaitStandby,
End
}
}
}