InputEquip.cs
14.4 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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
using Asa;
using DeviceLib;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public partial class InputEquip : EquipBase
{
public InputEquip_Config Config;
public AxisBean MiddleAxis = null;
public AxisBean UpdownAxis = null;
public AxisBean InOutAxis = null;
private AxisBean[] moveAxisArray;
public BatchMoveBean LeftBatchMove = null;
public BatchMoveBean RightBatchMove = null;
public bool AutoInput = ConfigAppSettings.GetIntValue(Setting_Init.AutoInput).Equals(1);
public int DefautTargetP = 1;
public InputEquip(string cid, InputEquip_Config config)
{
this.DeviceID = config.Id;
baseConfig = config;
this.Config = config;
IsDebug = config.IsDebug.Equals(1);
Name = (" " + "入料模块" + " ").ToUpper();
Init();
ledProcessTimer.Elapsed += LedProcess;
IoCheckTimer.Elapsed += IoCheckTimerProcess;
Config.SetAxisParam();
MiddleAxis = new AxisBean(RobotManager.Config.Take_Middle_Axis, Name);
UpdownAxis = new AxisBean(RobotManager.Config.Take_UpDown_Axis, Name);
InOutAxis = new AxisBean(RobotManager.Config.Take_InOut_Axis, Name);
AxisBean LeftBatchAxis = new AxisBean(RobotManager.Config.Left_Batch_Axis, Name);
AxisBean RightBatchAxis = new AxisBean(RobotManager.Config.Right_Batch_Axis, Name);
moveAxisArray = new AxisBean[] { MiddleAxis, UpdownAxis, InOutAxis };
MoveInfo = new RobotMoveInfo(Name);
SecMoveInfo = new RobotMoveInfo( "[" + Name.Trim() + "-SMove]");
LeftBatchMove = new BatchMoveBean(Config, LeftBatchAxis, 1);
RightBatchMove = new BatchMoveBean(config, RightBatchAxis, 2);
}
public override bool StartRun()
{
if (CanStartRun().Equals(false))
{
return false;
}
if (!OpenAllAxis())
{
CloseAllAxis();
return false;
}
SetAllTimer(false);
MoveInfo.EndMove();
SecMoveInfo.EndMove();
LogInfo("StartRun : 开始启动 ");
runStatus = RobotRunStatus.HomeMoving;
MoveInfo.NewMove(RobotMoveType.RHome);
StartReset();
SetAllTimer(true);
return true;
}
public override bool Reset()
{
SetAllTimer(false);
StopMove();
if (!OpenAllAxis())
{
CloseAllAxis();
SetAllTimer(true);
return false;
}
LogInfo("Reset 开始重置 ");
runStatus = RobotRunStatus.Reset;
MoveInfo.NewMove(RobotMoveType.Reset);
StartReset();
SetAllTimer(true);
return true;
}
private void StartReset()
{
WorkLogLevel = 1;
//复位时设置状态为none
AgvClient.SetStatus(Config.LeftAgvName);
AgvClient.SetStatus(Config.RightAgvName);
// TimerMaxSeconds = 10;
SetWarnMsg("");
alarmType = AlarmType.None;
isInSuddenDown = false;
isNoAirCheck = false;
MoveInfo.NextMoveStep(StepEnum.IR01_Wait);
CylinderMove(MoveInfo, IO_Type.Clamping_Work, IO_Type.Clamping_Relax);
}
protected override void ResetProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait(MoveInfo);
}
if (MoveInfo.IsInWait)
{
return;
}
if (MoveInfo.IsStep(StepEnum.IR01_Wait))
{
MoveInfo.NextMoveStep(StepEnum.IR02_InoutHome);
WorkLog("复位:进出轴回原点");
InOutAxis.HomeMove(MoveInfo);
}
else if (MoveInfo.IsStep(StepEnum.IR02_InoutHome))
{
MoveInfo.NextMoveStep(StepEnum.IR03_InoutToP1);
WorkLog("复位:进出轴到待机点P1");
InOutAxis.AbsMove(MoveInfo, Config.InoutAxis_P1, Config.InoutAxis_P1Speed);
}
else if (MoveInfo.IsStep(StepEnum.IR03_InoutToP1))
{
MoveInfo.NextMoveStep(StepEnum.IR04_UpdownAxisHome);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
WorkLog("复位:升降轴原点返回,左右批量轴开始回原点");
UpdownAxis.HomeMove(MoveInfo);
LeftBatchMove.Reset();
RightBatchMove.Reset();
}
else if (MoveInfo.IsStep(StepEnum.IR04_UpdownAxisHome))
{
MoveInfo.NextMoveStep(StepEnum.IR05_UpdownToP1);
WorkLog("复位:升降轴运动到待机点P1");
UpdownAxis.AbsMove(MoveInfo, Config.UpdownAxis_P1, Config.UpdownAxis_P1Speed);
}
else if (MoveInfo.IsStep(StepEnum.IR05_UpdownToP1))
{
MoveInfo.NextMoveStep(StepEnum.IR06_MiddleAxisHome);
WorkLog("复位:旋转轴开始回原点");
MiddleAxis.HomeMove(MoveInfo);
}
else if (MoveInfo.IsStep(StepEnum.IR06_MiddleAxisHome))
{
MoveInfo.NextMoveStep(StepEnum.IR07_MiddleToP1);
WorkLog("复位:旋转轴到待机点P1");
MiddleAxis.AbsMove(MoveInfo, Config.MiddleAxis_P1, Config.MiddleAxis_P1Speed);
}
else if (MoveInfo.IsStep(StepEnum.IR07_MiddleToP1))
{
MoveInfo.NextMoveStep(StepEnum.IR08_Clamping_Relax);
WorkLog("复位:夹爪放松");
CylinderMove(MoveInfo, IO_Type.Clamping_Work, IO_Type.Clamping_Relax);
}
else if (MoveInfo.IsStep(StepEnum.IR08_Clamping_Relax))
{
MoveInfo.NextMoveStep(StepEnum.IR09_WaitBatchMove);
WorkLog("复位:等待左右批量轴模块复位完成");
}
else if (MoveInfo.IsStep(StepEnum.IR09_WaitBatchMove))
{
if ((LeftBatchMove.MoveInfo.MoveType.Equals(RobotMoveType.None) || LeftBatchMove.MoveInfo.MoveType.Equals(RobotMoveType.Working))
&& (RightBatchMove.MoveInfo.MoveType.Equals(RobotMoveType.None) || RightBatchMove.MoveInfo.MoveType.Equals(RobotMoveType.Working)))
{
WorkLog("复位完成");
runStatus = RobotRunStatus.Runing;
MoveInfo.EndMove();
WorkLogLevel = 0;
}
else if (MoveInfo.IsTimeOut(180))
{
if (!LeftBatchMove.MoveInfo.MoveType.Equals(RobotMoveType.None) && (!LeftBatchMove.MoveInfo.MoveType.Equals(RobotMoveType.Working)))
{
WarnMsg = Name + "等待" + LeftBatchMove.Name + "复位完成超时[" + MoveInfo.TimeOutSeconds + "]秒";
LogUtil.error(WarnMsg, MoveInfo.ErrorLogType,MoveInfo.logSeconds());
Alarm(AlarmType.IoSingleTimeOut);
}
else
{
WarnMsg = Name + "等待" + LeftBatchMove.Name + "复位完成超时[" + MoveInfo.TimeOutSeconds + "]秒";
LogUtil.error(WarnMsg);
Alarm(AlarmType.IoSingleTimeOut);
}
}
}
}
internal override void StopMove()
{
//StopMove时设置状态为none
AgvClient.SetStatus(Config.LeftAgvName);
AgvClient.SetStatus(Config.RightAgvName);
MoveInfo.EndMove();
SecMoveInfo.EndMove();
LeftBatchMove.StopMove();
RightBatchMove.StopMove();
UpdownAxis.SuddenStop();
MiddleAxis.SuddenStop();
InOutAxis.SuddenStop();
CloseAllAxis();
}
public override void StopRun()
{
SetAllTimer(false);
runStatus = RobotRunStatus.Wait;
StopMove();
}
protected override void BaseTimerProcess()
{
if (isInSuddenDown || isNoAirCheck)
{
return;
}
BusyMoveProcess();
IOTimeOutProcess();
//判断流水线打开了才可以运行
if (MoveInfo.MoveType.Equals(RobotMoveType.None) && NoErrorAlarm())
{
//若左侧或右侧在等待扫码结束的状态,需要开始去取料
if (LeftBatchMove.MoveInfo.MoveType.Equals(RobotMoveType.Working) && LeftBatchMove.MoveInfo.IsStep(StepEnum.IB10_ScanOK))
{
WorkLog("左侧开始取料");
string code = LeftBatchMove.MoveInfo.MoveParam.WareCode;
var p = new WorkParam(1, 0, code);
p.IsNgReel = LeftBatchMove.MoveInfo.MoveParam.IsNgReel;
p.TargetPosType = LeftBatchMove.MoveInfo.MoveParam.TargetPosType;
p.NgMsg = LeftBatchMove.MoveInfo.MoveParam.NgMsg;
StartWorking(p);
}
else if (RightBatchMove.MoveInfo.MoveType.Equals(RobotMoveType.Working) && RightBatchMove.MoveInfo.IsStep(StepEnum.IB10_ScanOK))
{
WorkLog("右侧开始取料");
string code = RightBatchMove.MoveInfo.MoveParam.WareCode;
var p = new WorkParam(2, 0, code);
p.IsNgReel = RightBatchMove.MoveInfo.MoveParam.IsNgReel;
p.TargetPosType = RightBatchMove.MoveInfo.MoveParam.TargetPosType;
p.NgMsg = RightBatchMove.MoveInfo.MoveParam.NgMsg;
StartWorking(p);
}
}
if (SecMoveInfo.MoveType.Equals(RobotMoveType.None) && NoErrorAlarm())
{
if (RobotManager.robot.runStatus <= RobotRunStatus.Wait)
{
// StartCheckFixture();
}
}
LeftBatchMove.TimerProcess();
RightBatchMove.TimerProcess();
if (NoErrorAlarm())
{
CheckAxisAlarm();
}
GratingSignalProcess();
}
internal bool CanStartWork()
{
//是否可以开始新的料串入料
if (LeftBatchMove.MoveInfo.MoveType.Equals(RobotMoveType.Working))
{
StepEnum step = LeftBatchMove.MoveInfo.MoveStep;
if (step < StepEnum.IB21_BatchToP1)
{
return false;
}
}
else if (RightBatchMove.MoveInfo.MoveType.Equals(RobotMoveType.Working))
{
StepEnum step = RightBatchMove.MoveInfo.MoveStep;
if (step < StepEnum.IB21_BatchToP1)
{
return false;
}
}
return true ;
}
private DateTime checkAlarmTime = DateTime.Now;
public void CheckAxisAlarm()
{
if (alarmType.Equals(AlarmType.AxisAlarm) || alarmType.Equals(AlarmType.AxisMoveError))
{
return;
}
TimeSpan span = DateTime.Now - checkAlarmTime;
//在回原点,复位,出入库时,检测报警间隔减小
if (MoveInfo.MoveType.Equals(RobotMoveType.None))
{
if (span.TotalSeconds < 5)
{
return;
}
}
else if (span.TotalSeconds < 1)
{
return;
}
checkAlarmTime = DateTime.Now;
foreach (AxisBean axisInfo in moveAxisArray)
{
if (AxisIsAlarm(axisInfo))
{
return;
}
}
if (AxisIsAlarm(LeftBatchMove.BatchAxis,false ))
{
LeftBatchMove.WarnMsg = WarnMsg;
LeftBatchMove.Alarm(AlarmType.AxisAlarm);
return;
}
if (AxisIsAlarm(RightBatchMove.BatchAxis,false ))
{
RightBatchMove.WarnMsg = WarnMsg;
RightBatchMove.Alarm(AlarmType.AxisAlarm);
return;
}
}
public bool OpenAllAxis(bool isCheck = true)
{
if (RunMultiAxis(isCheck, IO_Type.TakeAxis_ON, IO_Type.Take_Axis_Break, moveAxisArray))
{
if (RunAxis(isCheck, LeftBatchMove.BatchAxis) && RunAxis(isCheck, RightBatchMove.BatchAxis))
{
return true;
}
}
return false;
}
public void CloseAllAxis()
{
IOMove(IO_Type.Take_Axis_Break, IO_VALUE.LOW);
IOMove(IO_Type.LeftBatchAxis_Break, IO_VALUE.LOW);
IOMove(IO_Type.RightBatchAxis_Break, IO_VALUE.LOW);
CloseMultiAxis(IO_Type.TakeAxis_ON, IO_Type.Take_Axis_Break, moveAxisArray);
CloseAxis(LeftBatchMove.BatchAxis);
CloseAxis(RightBatchMove.BatchAxis);
}
public override string GetMoveStr()
{
string msg = "";
int tLength = 15;
msg += "左侧料串:" + LeftBatchMove.CurrShelfId + " 右侧料串:"+RightBatchMove.CurrShelfId+" \r\n";
msg += "runS: " + runStatus + "\n";
msg += "alarm: " + alarmType + " " + LeftBatchMove.alarmType +" " + RightBatchMove.alarmType +"\n";
msg += "Move:" + MoveInfo.MoveType + " "+MoveInfo.MoveStep + "\n";
if (MoveInfo.MoveType.Equals(RobotMoveType.Working))
{
msg += "料盘信息:" + MoveInfo.MoveParam.ToStr() + "\n";
}
else
{
msg+= "\n";
}
msg += "左侧上料 :" + LeftBatchMove.GetMoveStr()+"\n";
msg += "右侧上料:" + RightBatchMove.GetMoveStr() + "\n";
return msg;
}
}
}