InOutDevice.cs
9.6 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
245
246
247
248
249
250
251
252
253
254
255
using CodeLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public partial class InOutDevice
{
public static Dictionary<InOutSideE,InOutDevice> InOutDeviceList = new Dictionary<InOutSideE, InOutDevice>();
#region io定义
string DO_Agv_Rsp = IO_Type.Right_Agv_Rsp;
string DO_Lift_Break = IO_Type.Right_Lift_Break;
string DO_Moto_Run = IO_Type.Right_Moto_Run;
string DO_Moto_Rev = IO_Type.Right_Moto_Rev;
string DO_F_Stop_Up = IO_Type.Right_F_Stop_Up;
string DO_F_Stop_Down = IO_Type.Right_F_Stop_Down;
string DO_M_Stop_Up = IO_Type.Right_M_Stop_Up;
string DO_M_Stop_Down = IO_Type.Right_M_Stop_Down;
string DO_Door_Up = IO_Type.Right_Door_Up;
string DO_Door_Down = IO_Type.Right_Door_Down;
string IO_Entry_SafetyGrating = IO_Type.Right_Entry_SafetyGrating;
string IO_Side_SafetyGrating = IO_Type.Right_Side_SafetyGrating;
string IO_OverHead_Check = IO_Type.Right_OverHead_Check;
string IO_AgvIn_Req = IO_Type.Right_AgvIn_Req;
string IO_AgvOut_Req = IO_Type.Right_AgvOut_Req;
string IO_F_Stop_In = IO_Type.Right_F_Stop_In;
string IO_F_Stop_Out = IO_Type.Right_F_Stop_Out;
string IO_F_Stop_Up = IO_Type.Right_F_Stop_Up;
string IO_F_Stop_Down = IO_Type.Right_F_Stop_Down;
string IO_M_Stop_In = IO_Type.Right_M_Stop_In;
string IO_M_Stop_Out = IO_Type.Right_M_Stop_Out;
string IO_M_Stop_Up = IO_Type.Right_M_Stop_Up;
string IO_M_Stop_Down = IO_Type.Right_M_Stop_Down;
string IO_EndMaterialTop_Check = IO_Type.Right_EndMaterialTop_Check;
string IO_EndMaterialBottom_Check = IO_Type.Right_EndMaterialBottom_Check;
string IO_Lift_Up = IO_Type.Right_Lift_Up;
string IO_Lift_Down = IO_Type.Right_Lift_Down;
string IO_Door_Up = IO_Type.Right_Door_Up;
string IO_Door_Down = IO_Type.Right_Door_Down;
#endregion
public InOutSideE InOutSide;
public InOutModeE InOutMode;
public InOutDirectionE CurrnetDirection = InOutDirectionE.NONE;
public MoveInfo MoveInfo;
public LiftMonitor Lift;
public LineRunMonitor Line;
Robot_Config Config;
MainMachine mainMachine;
public string Name;
public InOutDevice(InOutSideE inOutSide, InOutModeE inOutMode, Robot_Config _Config, MainMachine _mainMachine)
{
AxisBean Lift_Moto;
Name = "右侧出入口";
if (InOutSide == InOutSideE.Left)
{
Lift_Moto = new AxisBean(Config.Left_Lift_Moto, Name);
Name = "左侧出入口";
#region io定义
DO_Agv_Rsp = IO_Type.Left_Agv_Rsp;
DO_Lift_Break = IO_Type.Left_Lift_Break;
DO_Moto_Run = IO_Type.Left_Moto_Run;
DO_Moto_Rev = IO_Type.Left_Moto_Rev;
DO_F_Stop_Up = IO_Type.Left_F_Stop_Up;
DO_F_Stop_Down = IO_Type.Left_F_Stop_Down;
DO_M_Stop_Up = IO_Type.Left_M_Stop_Up;
DO_M_Stop_Down = IO_Type.Left_M_Stop_Down;
DO_Door_Up = IO_Type.Left_Door_Up;
DO_Door_Down = IO_Type.Left_Door_Down;
IO_Entry_SafetyGrating = IO_Type.Left_Entry_SafetyGrating;
IO_Side_SafetyGrating = IO_Type.Left_Side_SafetyGrating;
IO_OverHead_Check = IO_Type.Left_OverHead_Check;
IO_AgvIn_Req = IO_Type.Left_AgvIn_Req;
IO_AgvOut_Req = IO_Type.Left_AgvOut_Req;
IO_F_Stop_In = IO_Type.Left_F_Stop_In;
IO_F_Stop_Out = IO_Type.Left_F_Stop_Out;
IO_F_Stop_Up = IO_Type.Left_F_Stop_Up;
IO_F_Stop_Down = IO_Type.Left_F_Stop_Down;
IO_M_Stop_In = IO_Type.Left_M_Stop_In;
IO_M_Stop_Out = IO_Type.Left_M_Stop_Out;
IO_M_Stop_Up = IO_Type.Left_M_Stop_Up;
IO_M_Stop_Down = IO_Type.Left_M_Stop_Down;
IO_EndMaterialTop_Check = IO_Type.Left_EndMaterialTop_Check;
IO_EndMaterialBottom_Check = IO_Type.Left_EndMaterialBottom_Check;
IO_Lift_Up = IO_Type.Left_Lift_Up;
IO_Lift_Down = IO_Type.Left_Lift_Down;
IO_Door_Up = IO_Type.Left_Door_Up;
IO_Door_Down = IO_Type.Left_Door_Down;
#endregion
}
else
{
Lift_Moto = new AxisBean(Config.Right_Lift_Moto, Name);
}
MoveInfo.SetStateDelegate(State);
InOutSide = inOutSide;
InOutMode = inOutMode;
Config = _Config;
mainMachine = _mainMachine;
Lift = new LiftMonitor(IO_Lift_Up, IO_Lift_Down, DO_Lift_Break, Lift_Moto, Config.InLift_Moto_Speed, Config.InLift_Moto_DownSpeed);
Line = new LineRunMonitor(Name, Config.DOList[DO_Moto_Run].GetIOAddr(), Config.DOList[DO_Moto_Rev].GetIOAddr());
MoveInfo = new MoveInfo(Name);
InOutDeviceList.Add(inOutSide,this);
}
bool SafeCheck()
{
bool ok = true;
if (IOValue(IO_Entry_SafetyGrating).Equals(IO_VALUE.LOW))
{
if (!mainMachine.IgnoreSafecheck && !mainMachine.IgnoreGratingSignal
&& IOValue(IO_AgvIn_Req).Equals(IO_VALUE.LOW) && IOValue(IO_AgvOut_Req).Equals(IO_VALUE.LOW))
{
ok = false;
Line.Pause();
//Lift.Pause();
}
Msg.add(Name + "正面安全光栅被遮挡" + (ok ? "[已忽略]" : ""), MsgLevel.warning);
}
if (IOValue(IO_Side_SafetyGrating).Equals(IO_VALUE.LOW))
{
if (!mainMachine.IgnoreSafecheck && !mainMachine.IgnoreGratingSignal)
{
ok = false;
Line.Pause();
}
Msg.add(Name + "侧面光栅被遮挡" + (ok ? "[已忽略]" : ""), MsgLevel.warning);
}
if (ok)
{
Line.Resume();
//Lift.Resume();
}
return ok;
}
public void Progress()
{
if (!SafeCheck())
return;
if (MoveInfo.MoveStep == MoveStep.Wait)
{
if (CanIn(out string msg))
{
if (IOValue(IO_AgvIn_Req).Equals(IO_VALUE.HIGH) || (IOValue(IO_F_Stop_In).Equals(IO_VALUE.HIGH) && IOValue(IO_Entry_SafetyGrating).Equals(IO_VALUE.LOW)))
{
MoveInfo.NewMove(MoveStep.AgvIn01);
MoveInfo.log("检测到入口周转箱信号,开始入库流程");
CurrnetDirection = InOutDirectionE.IN;
return;
}
}
else if (IOValue(IO_AgvIn_Req).Equals(IO_VALUE.HIGH)){
Msg.add(Name + msg, MsgLevel.warning);
}
CurrnetDirection = InOutDirectionE.NONE;
return;
}
if (CurrnetDirection == InOutDirectionE.IN)
InProcess();
else if (CurrnetDirection == InOutDirectionE.OUT)
OutProcess();
}
public bool CanIn(out string msg)
{
//if (CurrnetDirection == InOutDirectionE.IN && MoveInfo.MoveStep>= MoveStep.In09) {
// return true;
//}
msg = "";
if (MoveInfo.MoveStep != MoveStep.Wait)
{
msg = Name+"忙碌中";
return false;
}
if (InOutMode == InOutModeE.OnlyIN || InOutMode == InOutModeE.Both)
{
return true;
}
msg = Name+"设定不允许入库";
return false;
}
public bool CanOut()
{
if (MoveInfo.MoveStep != MoveStep.Wait)
return false;
if (InOutMode == InOutModeE.OnlyOUT || InOutMode == InOutModeE.Both)
{
//CurrnetDirection = InOutDirectionE.OUT;
//MoveInfo.NewMove(MoveStep.Out01);
return true;
}
return false;
}
string State()
{
string state = "";
if (MoveInfo.MoveStep >= MoveStep.In02)
{
return MoveInfo.MoveParam.ToStr();
}
else if (MoveInfo.MoveStep >= MoveStep.Wait)
{
state = "空闲中";
}
else if (MoveInfo.MoveStep < MoveStep.In02)
{
state = "入库扫描";
}
return state;
}
public void FrontStop(MoveInfo moveInfo, IO_VALUE iO_VALUE)
{
MainMachine.CylinderMove(moveInfo, DO_F_Stop_Down, DO_F_Stop_Up, iO_VALUE);
}
public void MiddleStop(MoveInfo moveInfo, IO_VALUE iO_VALUE)
{
MainMachine.CylinderMove(moveInfo, DO_M_Stop_Down, DO_M_Stop_Up, iO_VALUE);
}
public IO_VALUE IOValue(string ioType)
{
return MainMachine.IOValue(ioType);
}
public void IOMove(string IoType, IO_VALUE value, bool isCheck = false, int msTime = 0)
{
MainMachine.IOMove(IoType, value, isCheck, msTime);
}
}
public enum InOutSideE {Left,Right}
public enum InOutDirectionE { NONE,IN, OUT}
public enum InOutModeE {OnlyIN, OnlyOUT,Both }
}