ChargeJob.cs
5.5 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
using System;
using AGVControl_Steel;
namespace Model
{
/// <summary>
/// 充电工作
/// </summary>
public class ChargeJob : Job
{
private string id;
private JobStep<ChargeStep> chargeStep;
private const int CHARGE_PLACE_PLC = 20;
/// <summary>
/// 充电工作
/// </summary>
public ChargeJob()
{
chargeStep = new JobStep<ChargeStep>(ChargeStep.None);
Common.log.Debug("进入ChargeJob任务");
}
/// <summary>
/// 任务执行
/// </summary>
/// <param name="info"></param>
public override Job Execute(AgvInfo info)
{
if (chargeStep.IsEqual(ChargeStep.None))
{
if (info.IsSelfWorkshop())
MoveCharge(info);
else
MoveDoor(info);
}
else if (chargeStep.IsEqual(ChargeStep.WaitWorkshopDoor))
{
rtn = Common.mir.Get_MissionState_Fleet(info.Authorization, id, out string state);
if (rtn)
{
if (state == MissionState.Done.ToString())
MoveCharge(info);
else if (state == MissionState.Aborted.ToString())
chargeStep.Msg = info.FullName + "任务状态" + MissionState.Aborted.ToString();
}
else
{
chargeStep.Msg = info.FullName + "获取任务状态id[" + id + "]失败";
}
}
else if (chargeStep.IsEqual(ChargeStep.WaitChargeStation))
{
rtn = Common.mir.Get_Register(info.IP, info.Authorization, CHARGE_PLACE_PLC, out int value);
if (rtn)
{
if (value == 1)
{
chargeStep.Msg = info.FullName + "到达充电位,准备充电";
chargeStep.NextStep(ChargeStep.Charging);
}
}
else
{
chargeStep.Msg = info.FullName + "获取PLC" + CHARGE_PLACE_PLC + "失败";
}
}
else if (chargeStep.IsEqual(ChargeStep.Charging))
{
if (info.Battery == info.BatteryMax)
{
chargeStep.Msg = info.FullName + "电量达到" + info.BatteryMax + ",充电工作结束";
chargeStep.NextStep(ChargeStep.End);
}
else if (info.Battery > info.BatteryMin)
{
Job job = Common.steelManage.GetSteelJob(info);
if (job != null)
{
Common.mir.Del_Mission(info.IP, info.Authorization);
return job;
}
}
}
else if (chargeStep.IsEqual(ChargeStep.End))
{
Common.mir.Del_Mission(info.IP, info.Authorization);
Common.log.Info(info.FullName + "ChargeJob结束,切换StandbyJob");
return new StandbyJob();
}
return this;
}
private void MoveDoor(AgvInfo info)
{
mission = Common.MISSION_PASS_DOOR_INTO + info.Workshop;
if (Common.FLEET_SEND)
rtn = Common.mir.Add_Mission_Fleet(info.FleetID, info.Authorization, mission, out id);
else
rtn = Common.mir.Add_Mission(info.IP, info.Authorization, mission, out id);
if (rtn)
{
chargeStep.Msg = info.FullName + "在" + info.Workshop + "车间,先过车间门";
chargeStep.NextStep(ChargeStep.WaitWorkshopDoor);
}
else
{
chargeStep.Msg = info.FullName + "发送" + mission + "任务失败";
}
}
private void MoveCharge(AgvInfo info)
{
mission = Common.MISSION_CHARGE + info.Workshop;
if (Common.FLEET_SEND)
rtn = Common.mir.Add_Mission_Fleet(info.FleetID, info.Authorization, mission, out id);
else
rtn = Common.mir.Add_Mission(info.IP, info.Authorization, mission, out id);
if (rtn)
{
info.Place = "充电位";
chargeStep.Msg = info.FullName + "在" + info.Workshop + "车间去充电位," + mission;
chargeStep.NextStep(ChargeStep.WaitChargeStation);
}
else
{
chargeStep.Msg = info.FullName + "发送" + mission + "任务失败";
}
}
/// <summary>
/// 充电步骤
/// </summary>
private enum ChargeStep
{
/// <summary>
/// 无
/// </summary>
None,
/// <summary>
/// 充电结束
/// </summary>
End,
/// <summary>
/// 移动到车间门口
/// </summary>
WaitWorkshopDoor,
/// <summary>
/// 移动到充电位置
/// </summary>
WaitChargeStation,
/// <summary>
/// 移动到待机位
/// </summary>
WaitStandby,
/// <summary>
/// 充电中
/// </summary>
Charging,
/// <summary>
/// 发送任务
/// </summary>
SendMission
}
}
}