BoxBean.cs
23.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
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
using Asa;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public partial class BoxBean : EquipBase
{
public AutoInoutInfo AutoInout = new AutoInoutInfo();
public string CID = "";
public override BOX_Config Config { get; set; } =null;
public string lastPosId = "";
public StoreStatus lastPosIdStatus = StoreStatus.StoreOnline;
public override List<ConfigMoveAxis> moveAxisList { get; set; } = new List<ConfigMoveAxis>();
public List<string> PositionNumList = new List<string>();
public HumitureBean humBean = null;
public AxisBean UpdownAxis = null;
public AxisBean MiddleAxis = null;
public AxisBean ComAxis = null;
public AxisBean InoutAxis = null;
public bool Disabled = false;
/// <summary>
/// 出料口最后一盘料信息,0=暂无,1=单盘出库料亮绿灯,2=入库NG料亮红灯
/// </summary>
public int OutDoorReelType = 0;
public BoxBean(BOX_Config config)
{
Init();
baseConfig = config;
CID = config.CID;
IoCheckTimer.Elapsed += IoCheckTimer_Elapsed;
serverConTimer.Elapsed += server_connect_timer_Tick;
logType = 1000 * config.Id;
//添加调试
IsDebug = config.IsInDebug.Equals(1);
Name = (" BOX_" + config.Id + " ").ToUpper();
MoveInfo = new StoreMoveInfo(ID, Name);
this.ID = config.Id; ;
this.Config = config;
//温湿度
humBean = new HumitureBean(config.Humiture_Port, Name);
MoveAxisConfig();
List<ACBoxPosition> positionList = CSVPositionReader<ACBoxPosition>.getPositionList();
PositionNumList = new List<string>();
foreach (ACBoxPosition position in positionList)
{
if (position.StoreId.Equals(ID) && ACBoxPosition.CheckPosition(position, Config))
{
PositionNumList.Add(position.PositionNum);
}
}
InoutAxis = new AxisBean(config.InOut_Axis, Name);
MiddleAxis = new AxisBean(config.Middle_Axis, Name);
MiddleAxis.Reverse_Offset = config.MiddleAxis_Reverse_Offset;
UpdownAxis = new AxisBean(config.UpDown_Axis, Name);
ComAxis = new AxisBean(config.Comp_Axis, Name);
mainTimer.Enabled = false;
try
{
LoadCameraConfig(config.Id.ToString());
}
catch { }
}
private void IoCheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//判断急停
if (runStatus >= StoreRunStatus.HomeMoving)
{
if (IOManager.IOValue(IO_Type.SuddenStop_BTN,0).Equals(IO_VALUE.LOW))
{
if (isInSuddenDown.Equals(false))
{
isInSuddenDown = true;
LogUtil.error(Name + "收到急停信号,报警急停");
WarnMsg = Name + "收到急停信号,报警急停";
//报警时会关闭所有轴
Alarm(AlarmType.SuddenStop, "1", WarnMsg, MoveType.None);
}
}
}
}
internal void MoveAxisConfig()
{
//Config.UpDown_Axis.BreakOnDO = IO_Type.UpdownAxis_Break;
moveAxisList = new List<ConfigMoveAxis>();
moveAxisList.Add(Config.Middle_Axis);
moveAxisList.Add(Config.UpDown_Axis);
moveAxisList.Add(Config.InOut_Axis);
moveAxisList.Add(Config.Comp_Axis);
}
public override bool StartRun(bool isDebug = false)
{
if (!StoreManager.Store.canStart)
{
WarnMsg = "启动失败:设备未初始化完成";
LogUtil.error(Name + "启动失败:设备未初始化完成");
return false;
}
if (Disabled)
{
WarnMsg = "启动失败:设备被禁用";
LogUtil.error(Name + "启动失败:设备被禁用");
return false;
}
LogInfo("开始启动,启动时间:" + StartTime.ToString());
WarnMsg = "";
AutoInout.StopAuto();
mainTimer.Enabled = false;
alarmType = AlarmType.None;
if (IOManager.IOValue(IO_Type.SuddenStop_BTN, 0).Equals(IO_VALUE.LOW))
{
WarnMsg = "启动失败:急停没开";
LogUtil.error(" (" + Name + ")启动失败:急停没开!");
return false;
}
else if (IOManager.IOValue(IO_Type.Airpressure_Check, 0).Equals(IO_VALUE.LOW))
{
WarnMsg = "启动失败:没有气压信号";
LogUtil.error(" (" + Name + ")启动失败:没有气压信号!");
return false;
}
else
//if (suddenBtn.Equals(IO_VALUE.HIGH) && (airCheck.Equals(IO_VALUE.HIGH)))
{
//lastAirValue = airCheck;
lastAirCloseTime = DateTime.Now;
if (!OpenAllAxis(true))
{
return false;
}
//TODO 启动时先所有轴远点返回,测试暂时关闭
runStatus = StoreRunStatus.HomeMoving;
storeStatus = StoreStatus.ResetMove;
//启动温湿度服务器
HumitureController.Init(Config.Humiture_Port);
ReturnHome();
StartTime = DateTime.Now;
mainTimer.Enabled = true;
IoCheckTimer.Enabled = true;
serverConTimer.Enabled = true;
return true;
}
}
#region 原点返回和复位处理
private void ReturnHome()
{
lastPosId = "";
lastPosIdStatus = StoreStatus.ResetMove;
AutoInout.ClearCount();
runStatus = StoreRunStatus.HomeMoving;
MoveInfo.NewMove(MoveType.ReturnHome);
InoutStartReset();
}
public override void Reset(bool isNeedClearAuto = true)
{
if (Disabled)
return;
AutoInout.ClearCount();
//复位之前先停止运行
if (isNeedClearAuto)
{
AutoInout.StopAuto();
}
runStatus = StoreRunStatus.Reset;
storeStatus = StoreStatus.ResetMove;
MoveInfo.NewMove(MoveType.Reset);
if (!OpenAllAxis(true))
{
LogInfo("复位时打开轴失败,需要再次复位,直接报警停止复位");
return;
}
InoutStartReset();
isInPro = false;
}
private void InoutStartReset()
{
//清理报警
WarnMsg = "";
isInSuddenDown = false;
isNoAirCheck = false;
alarmType = AlarmType.None;
//开始复位动作
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H01_InOutBack);
LogInfo(MoveInfo.MoveType + ": 进出轴回原点 ");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
InoutAxis.HomeMove(MoveInfo);
}
protected override void ResetProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait();
}
if (MoveInfo.IsInWait)
{
return;
}
switch (MoveInfo.MoveStep)
{
case StoreMoveStep.BOX_H01_InOutBack:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H02_InoutToP1);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
LogInfo(MoveInfo.MoveType + ": 进出轴到待机点P1,关闭仓门");
InoutAxis.AbsMove(MoveInfo, Config.InOutAxis_P1, Config.InOutAxis_P1_Speed);
CylinderMove(MoveInfo, IO_Type.OutDoor_Up, IO_Type.OutDoor_Down);
break;
case StoreMoveStep.BOX_H02_InoutToP1:
//如果此时轴三还在报警,需要提示错误并等待
if (AxisManager.instance.GetAlarmStatus(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue()) > 0)
{
LogUtil.error(Name + MoveInfo.MoveType + "复位失败: " + Config.InOut_Axis.Explain + "报警");
WarnMsg = Name + "复位失败: " + Config.InOut_Axis.Explain + "报警";
Alarm(AlarmType.AxisAlarm );
return;
}
//复位和回原点要等轴3进出轴ORG亮了以后才能返回其他轴
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H03_OtherAxisHome_wait);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
LogInfo(MoveInfo.MoveType + ": 压紧轴,旋转轴,上下轴开始 原点返回,关闭NG门");
CylinderMove(MoveInfo, IO_Type.OutDoor_Up, IO_Type.OutDoor_Down);
ComAxis.HomeMove(MoveInfo);
MiddleAxis.HomeMove(MoveInfo);
UpdownAxis.HomeMove(MoveInfo);
break;
case StoreMoveStep.BOX_H03_OtherAxisHome_wait:
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H03_SendOut_01);
if (IOValue(IO_Type.OutDoor_Check).Equals(IO_VALUE.HIGH))
{
CylinderMove(MoveInfo, IO_Type.OutDoor_Down, IO_Type.OutDoor_Up);
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.OutDoor_Check, IO_VALUE.LOW));
}
break;
case StoreMoveStep.BOX_H03_SendOut_01:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H03_SendOut_02);
InOutStoreLog("复位:" + "移动到出料口,旋转轴到P11[" + Config.MiddleAxis_P11 + "],升降轴到P12高点[" + Config.UpDownAxis_P12 + "] ");
MiddleAxis.AbsMove(MoveInfo, Config.MiddleAxis_P11, Config.MiddleAxis_P11_Speed);
UpdownAxis.AbsMove(MoveInfo, Config.UpDownAxis_P12, Config.UpDownAxis_P12_Speed);
break;
case StoreMoveStep.BOX_H03_SendOut_02:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H03_SendOut_03);
InOutStoreLog("复位:" + "进出轴到_P11-出料口取放料点 [" + Config.InOutAxis_P11 + "] ");
InoutAxis.AbsMove(MoveInfo, Config.InOutAxis_P11, Config.InOutAxis_P11_Speed);
break;
case StoreMoveStep.BOX_H03_SendOut_03:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H03_SendOut_04);
InOutStoreLog("复位:" + "升降轴到_P11-出料口-低点[" + Config.UpDownAxis_P11 + "]");
//ComAxis.AbsMove(MoveInfo, Config.CompAxis_P1, Config.CompAxis_P3_Speed);
UpdownAxis.AbsMove(MoveInfo, Config.UpDownAxis_P11, Config.UpDownAxis_P11_Speed);
break;
case StoreMoveStep.BOX_H03_SendOut_04:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H03_SendOut_05);
InOutStoreLog("复位:" + "进出轴返回P1 [" + Config.InOutAxis_P1 + "], 打开出料口门 ");
InOutBackToP1(Config.InOutAxis_P1);
OutDoorReelType = 2;
CylinderMove(MoveInfo, IO_Type.OutDoor_Down, IO_Type.OutDoor_Up);
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.OutDoor_Check, IO_VALUE.LOW));
break;
case StoreMoveStep.BOX_H03_SendOut_05:
if (IOValue(IO_Type.OutDoor_SafeSignal).Equals(IO_VALUE.HIGH))
{
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H03_OtherAxisHome);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
}
break;
case StoreMoveStep.BOX_H03_OtherAxisHome:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H04_OtherAxisBack);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
LogInfo(MoveInfo.MoveType + ": 旋转轴运动到P1,上下轴走到P1,压紧轴到P1, ");
MiddleAxis.AbsMove(MoveInfo, Config.MiddleAxis_P1, Config.MiddleAxis_P1_Speed);
UpdownAxis.AbsMove(MoveInfo, Config.UpDownAxis_P1, Config.UpDownAxis_P1_Speed);
ComAxis.AbsMove(MoveInfo, Config.CompAxis_P1, Config.CompAxis_P1_Speed);
CylinderMove(MoveInfo, IO_Type.OutDoor_Up, IO_Type.OutDoor_Down);
OutDoorReelType = 0;
break;
case StoreMoveStep.BOX_H04_OtherAxisBack:
HuichuanLibrary.HCBoardManager.SetAxBacklash(MiddleAxis.Config.GetAxisValue(),Config.MiddleAxis_Reverse_Offset, MiddleAxis.Config.HomeLowSpeed,-1);
LogInfo(MoveInfo.MoveType + ": 完成");
MoveEndP();
if (IOValue(IO_Type.InDoor_Check).Equals(IO_VALUE.HIGH) && IsDebug.Equals(false))
{
LogInfo("发现入口有无信息料");
InOutParam inOutParam = new InOutParam(MoveType.InStore);
inOutParam.InStoreNg = true;
inOutParam.TargetPosition = 1;
inOutParam.moveType = MoveType.InStore;
inOutParam.PlateH = 56;
StoreManager.LoadInoutParam(inOutParam, MoveType.InStore, true, this);
runStatus = StoreRunStatus.Busy;
storeStatus = StoreStatus.InStoreExecute;
MoveInfo.NewMove(MoveType.InStore, inOutParam);
MoveInfo.NextMoveStep(StoreMoveStep.SI_01_InoutToP1);
}
break;
default: break;
}
}
#endregion
public override void StopRun()
{
lastPosId = "";
lastPosIdStatus = StoreStatus.StoreOnline;
WarnMsg = "";
AutoInout.StopAuto();
IoCheckTimer.Enabled = false;
serverConTimer.Enabled = false;
StopMove();
runStatus = StoreRunStatus.Wait;
mainTimer.Enabled = false;
CameraClose();
TimeSpan span = DateTime.Now - StartTime;
LogInfo(",停止运行,总运行时间:" + span.ToString());
}
public override void Alarm(AlarmType alarmType, string alarmDetial = "", string alarmMsg = "", MoveType storeMoveType = MoveType.None)
{
base.Alarm(alarmType, alarmDetial, alarmMsg, storeMoveType);
AutoInout.StopAuto();
}
internal override void TimerProcess()
{
try
{
DateTime time = DateTime.Now;
if (MoveInfo.MoveType != MoveType.None)
{
BusyMoveProcess();
ShowTimeLog("BusyMoveProcess");
}
else if (runStatus.Equals(StoreRunStatus.Runing))
{
ShowTimeLog("判断是否需要出入库");
AutoResetProcess();
ShowTimeLog("AutoResetProcess");
IOTimeOutProcess();
ShowTimeLog("IOTimeOutProcess");
} //检查运动轴报警
if (runStatus > StoreRunStatus.Wait && (!isInSuddenDown) && (!isNoAirCheck))
{
ShowTimeLog("开始检测轴报警");
CheckAxisAlarm(new AxisBean[] { MiddleAxis, UpdownAxis, InoutAxis, ComAxis });
ShowTimeLog("轴报警检测完成");
}
if (runStatus >= StoreRunStatus.Runing)
{
IOMinoitor();
}
}
catch (Exception ex)
{
LogUtil.error(Name + "定时处理出错" + ex.ToString());
}
}
int OutDoorCloseCountDown = 5;
void IOMinoitor() {
if (IOValue(IO_Type.OutDoor_Up).Equals(IO_VALUE.HIGH)
&& IOValue(IO_Type.OutDoor_Check).Equals(IO_VALUE.LOW)
&& IOValue(IO_Type.OutDoor_SafeSignal).Equals(IO_VALUE.LOW))
{
OutDoorCloseCountDown--;
if (OutDoorCloseCountDown == 0)
{
CylinderMove(MoveInfo, IO_Type.OutDoor_Up, IO_Type.OutDoor_Down);
LogInfo("料已被取走,关门");
}
}
else {
OutDoorCloseCountDown = 5;
}
}
string lastOutPosID = "";
private void AutoResetProcess()
{
try
{
bool noInStore = MoveInfo.MoveType.Equals(MoveType.None) && alarmType.Equals(AlarmType.None);
bool middleinpos;
if (noInStore)
{
if (Config.Id == 1)
{
middleinpos = StoreManager.Store.T2_MiddleAxis.IsInPosition(StoreManager.Store.Config.MiddleAxis_P2);
}
else
{
middleinpos = StoreManager.Store.T2_MiddleAxis.IsInPosition(StoreManager.Store.Config.MiddleAxis_P3);
}
if (middleinpos)
noInStore = StoreManager.Store.T3_UpdownAxis.GetAclPosition() < (StoreManager.Store.Config.UpdownAxis_P3 - StoreManager.Store.Config.UpdownAxis_P4) / 2;
}
//LogInfo($"OutDoor_Check:{IOValue(IO_Type.OutDoor_Check)},InDoor_Check:{IOValue(IO_Type.InDoor_Check)},waitInStoreParam is null:{waitInStoreParam==null},waitOutStoreList.Count:{waitOutStoreList.Count},noInStore:{noInStore}");
if (AutoInout.CurrInOutACount >= StoreManager.Config.Box_ResetACount && noInStore)
{
if (runStatus < StoreRunStatus.Runing || MoveInfo.MoveType == MoveType.InStore || MoveInfo.MoveType == MoveType.OutStore)
{
// LogInfo("已经累计出入库" + AutoInout.CurrInOutACount + "次,当时当前正在忙碌中暂不复位");
}
else
{
LogInfo("已经累计出入库" + AutoInout.CurrInOutACount + "次,需要复位一下");
Reset();
}
return;
}
else if (IOValue(IO_Type.OutDoor_Check).Equals(IO_VALUE.HIGH) && noInStore && IsDebug.Equals(false))
{
LogInfo("发现紧急出口有料");
InOutParam inOutParam = new InOutParam(MoveType.InStore);
inOutParam.InStoreNg = true;
inOutParam.TargetPosition = 1;
inOutParam.moveType = MoveType.InStore;
StoreManager.LoadInoutParam(inOutParam, MoveType.InStore, true, this);
runStatus = StoreRunStatus.Busy;
storeStatus = StoreStatus.InStoreExecute;
MoveInfo.NewMove(MoveType.InStore, inOutParam);
MoveInfo.NextMoveStep(StoreMoveStep.SI_24_PurReel);
//InoutAxis.AbsMove(MoveInfo, Config.InOutAxis_P1, Config.InOutAxis_P1_Speed);
}
else if (waitInStoreParam != null && noInStore && IsDebug.Equals(false))
{
if (!StartInStoreMove(waitInStoreParam))
{
LogInfo("执行排队的入库【" + waitInStoreParam.ToStr() + "】失败");
}
else
{
LogInfo("执行排队的入库【" + waitInStoreParam.ToStr() + "】成功,清理缓存");
waitInStoreParam = null;
}
}
else if (waitOutStoreList.Count > 0 && noInStore && IsDebug.Equals(false))
{
lock (waitOutStoreList)
{
InOutParam param = null;
bool result = waitOutStoreList.TryDequeue(out param);
if (result && param != null)
{
if (lastOutPosID != param.PosID)
{
LogInfo("执行排队的出库【" + param.ToStr() + "】");
}
LogUtil.OutputDebugString(Name + "执行排队的出库【" + param.ToStr() + "】");
StartExecuctOut(param);
}
}
}
else if (false && IOValue(IO_Type.InDoor_Check).Equals(IO_VALUE.HIGH) && noInStore && IsDebug.Equals(false))
{
LogInfo("发现入口有无信息料");
InOutParam inOutParam = new InOutParam(MoveType.InStore);
inOutParam.InStoreNg = true;
inOutParam.TargetPosition = 1;
inOutParam.moveType = MoveType.InStore;
inOutParam.PlateH = 56;
StoreManager.LoadInoutParam(inOutParam, MoveType.InStore, true, this);
runStatus = StoreRunStatus.Busy;
storeStatus = StoreStatus.InStoreExecute;
MoveInfo.NewMove(MoveType.InStore, inOutParam);
MoveInfo.NextMoveStep(StoreMoveStep.SI_01_InoutToP1);
}
}
catch (Exception ex)
{
LogUtil.error(Name + "处理出入库排队列表出错:" + ex.ToString());
}
}
public override void StopMove()
{
MoveInfo.EndMove();
//IOMove(IO_Type.UpdownAxis_Break, IO_VALUE.LOW);
//运动版停止
MiddleAxis.SuddenStop();
UpdownAxis.SuddenStop();
InoutAxis.SuddenStop();
ComAxis.SuddenStop();
CloseAllAxis();
LogInfo("StopMove");
isInPro = false;
}
public bool OpenAllAxis(bool isCheck)
{
return RunMultiAxis(isCheck, new AxisBean[] { MiddleAxis, UpdownAxis, InoutAxis, ComAxis });
}
public void CloseAllAxis()
{
LogUtil.info(Name + "关闭伺服");
CloseMultiAxis(new AxisBean[] { MiddleAxis, UpdownAxis, InoutAxis, ComAxis });
}
}
}