MainMachine _LeftProcess.cs
22.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
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
using OnlineStore;
using CodeLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
namespace DeviceLibrary
{
partial class MainMachine
{
public bool LeftShelfNoTray = false;
int LeftCount = 0;
public bool SafeReleaseLeftShelf = false;
//int Uppre = -1000;
//int Uplast = -1000;
//int step = 0;
public int LastBatchAxisPosition = 0;
public int PlwHight = 0;
/// <summary>
/// 料盘高度单位脉冲
/// </summary>
//public int PlwHight
//{
// get
// {
// int hight = 0;
// //if (Uppre != -1000 && Uplast != -1000&&step==3)
// if (Uppre != -1000 && Uplast != -1000 && step == 2)
// {
// hight = Math.Abs(Uplast - Uppre) + 2000;
// RightMoveInfo.log($"料盘高度计算:hight:{hight},Uppre:{Uppre},Uplast:{Uplast}");
// }
// return hight;
// }
//}
int _leftBatchAxisPositionWhileTrayCheck = 0;
/// <summary>
/// 出库上一次料盘定位信号亮时批量轴的位置
/// </summary>
int LeftBatchAxisPositionWhileTrayCheck
{
get => _leftBatchAxisPositionWhileTrayCheck;
set
{
if (_leftBatchAxisPositionWhileTrayCheck != value)
{
_leftBatchAxisPositionWhileTrayCheck = value;
LeftMoveInfo.log($"左侧批量轴定位信号亮时位置:{_leftBatchAxisPositionWhileTrayCheck}");
}
}
}
bool checkReelIsPutOk(int curPos)
{
bool enableCheck = ConfigHelper.Config.Get("左侧料盘放料串检查是否启用", true);
if (enableCheck)
{
var aixH = 1f * Math.Abs(_leftBatchAxisPositionWhileTrayCheck - curPos) / Config.Left_Batch_ChangeValue;
int plateH = LeftMoveInfo.MoveParam.PlateH == 0 ? PlwHight / Config.Right_Batch_ChangeValue:LeftMoveInfo.MoveParam.PlateH;
var canErrorMM = ConfigHelper.Config.Get("左侧料盘放料串检查厚度最大偏差值", 5);
if (Math.Abs(aixH - plateH) <= canErrorMM)
{
LeftMoveInfo.log($"料盘定位信号{IOValue(IO_Type.LeftTop_Check)},批量轴当前位置:{curPos}," +
$"上次位置{_leftBatchAxisPositionWhileTrayCheck},批量轴厚度{aixH},料盘厚度{plateH},允许的最大差值{canErrorMM}," + $"{Math.Abs(aixH - plateH)}<={canErrorMM},认为放料串成功");
return true;
}
else
{
LeftMoveInfo.log($"料盘定位信号{IOValue(IO_Type.LeftTop_Check)},批量轴当前位置:{curPos}," +
$"上次位置{_leftBatchAxisPositionWhileTrayCheck},批量轴厚度{aixH},料盘厚度{plateH},允许的最大差值{canErrorMM}," + $"{Math.Abs(aixH - plateH)}>{canErrorMM},认为放料串失败");
return false;
}
}
else
{
return true;
}
}
void LeftProcess()
{
if (CheckWait(LeftMoveInfo))
return;
switch (LeftMoveInfo.MoveStep)
{
//阻挡上升,轴到p2
case MoveStep.L01:
LeftCount = 0;
LeftShelfNoTray = false;
LeftMoveInfo.CurShelfType = "";
LeftMoveInfo.NextMoveStep(MoveStep.L02);
CylinderMove(null, IO_Type.LeftStopDown, IO_Type.LeftStopUP);
LeftBatchAxisToP2(Config.Left_Batch_P2, Config.Left_Batch_P1_speed, IO_VALUE.HIGH);
LeftMoveInfo.log($"批量轴上升到P2位置,第一次提升,LeftStartMovePosition={LeftStartMovePosition}");
break;
case MoveStep.L02:
LeftMoveInfo.NextMoveStep(MoveStep.L03);
LeftBatchAxisPositionWhileTrayCheck = Left_Batch_Axis.GetAclPosition();
break;
//轴下降一点
case MoveStep.L03:
LeftMoveInfo.NextMoveStep(MoveStep.L04);
int targetP1 = Left_Batch_Axis.GetAclPosition() - ConfigHelper.Config.Get("LeftAxisDownValue", 50) * Config.Left_Batch_ChangeValue;
if (PlwHight > 5000)
{
int currpoint = Left_Batch_Axis.GetAclPosition();
int countPleHight = PlwHight / Config.Right_Batch_ChangeValue * Config.Left_Batch_ChangeValue;
targetP1 = currpoint - countPleHight + 5000;
LeftMoveInfo.MoveParam.PlateH = countPleHight / Config.Left_Batch_ChangeValue;
LeftMoveInfo.log($"出料提升机构,获取到料盘高度脉冲{PlwHight},当前位置{currpoint},计算盘高{LeftMoveInfo.MoveParam.PlateH}");
}
int targetSpeed = Config.Left_Batch_P1_speed;
if (targetP1 <= 0)
{
LeftMoveInfo.log("出料提升机构,下降固定值小于0,设置回到0原点。");
targetP1 = 0;
LeftMoveInfo.NextMoveStep(MoveStep.L40_ShelfFull);
LeftMoveInfo.log($"批量轴已下降到底,料串已满,Left_Batch_P1={Config.Left_Batch_P1}");
}
LeftMoveInfo.log($"出料提升机构,下降固定值为{targetP1}脉冲!");
Left_Batch_Axis.AbsMove(LeftMoveInfo, targetP1, targetSpeed);
LeftMoveInfo.log($"批量轴下降固定值");
break;
//根据轴位置判断去料串满步骤还是不满步骤
case MoveStep.L04:
var currpos = Left_Batch_Axis.GetAclPosition();
if (currpos <= Config.Left_Batch_P1 + 2000)
{
LeftMoveInfo.NextMoveStep(MoveStep.L40_ShelfFull);
LeftMoveInfo.log($"批量轴已下降到底,料串已满,Left_Batch_P1={Config.Left_Batch_P1},needpos={currpos}");
}
else
{
LeftMoveInfo.NextMoveStep(MoveStep.L10_WaitReelPut);
}
break;
//等中间步骤抓盘
case MoveStep.L10_WaitReelPut:
Msg.add(crc.GetString("Res0095", "左侧空闲中"), MsgLevel.info);
break;
//中间步骤给盘,下降一点,获取盘信息
case MoveStep.L11_ReelPutted:
//if (RightMoveInfo.MoveStep== MoveStep.Wait)
{
LeftCount++;
LeftMoveInfo.NextMoveStep(MoveStep.L12);
LeftBatchAxisToP2(Config.Left_Batch_P1, Config.Left_Batch_P1_speed, IO_VALUE.LOW);
//LeftBatchAxisDown();
LabelMoveInfo.MoveParam = LeftMoveInfo.MoveParam.clone();
LeftMoveInfo.log($"左侧料盘已放入,批量轴下降固定值");
}
if (LeftMoveInfo.MoveParam.PlateW == 7)
{
LeftMoveInfo.CurShelfType = ShelfType.smallReel.ToString();
}
else if (LeftMoveInfo.MoveParam.PlateW == 13)
{
LeftMoveInfo.CurShelfType = ShelfType.bigReel.ToString();
}
else if (LeftMoveInfo.MoveParam.PlateW == 15)
{
LeftMoveInfo.CurShelfType = ShelfType.bigReel.ToString();
}
//else
//{
// LeftMoveInfo.NextMoveStep(MoveStep.L11_ReelPutted);
//}
break;
//防意外
case MoveStep.L12:
LeftMoveInfo.NextMoveStep(MoveStep.L13);
//LeftBatchAxisToP2(false);
LeftAxisRiseMax();
LeftMoveInfo.log($"批量轴上升到P2位置,LeftStartMovePosition={LeftStartMovePosition}");
break;
case MoveStep.L13:
var curPos = Left_Batch_Axis.GetAclPosition();
//判断当前料盘是否放到料串上
if (checkReelIsPutOk(curPos))
{
LeftMoveInfo.NextMoveStep(MoveStep.L16);
LeftMoveInfo.log("放置料盘检查正常");
}
else
{
//LeftMoveInfo.log("检查到放置料盘检查异常");
Msg.add(crc.GetString("Res0225", "放料失败请手动处理,请将料盘放入: 左侧料串,按左侧按钮继续"), MsgLevel.alarm);
if (IOValue(IO_Type.Left_BTN).Equals(IO_VALUE.HIGH))
{
LeftMoveInfo.NextMoveStep(MoveStep.L14);
LeftMoveInfo.log("放置料盘检查异常,复位继续");
}
return;
}
break;
case MoveStep.L14:
LeftMoveInfo.NextMoveStep(MoveStep.L15);
LeftBatchAxisToP2(Config.Left_Batch_P1, Config.Left_Batch_P1_speed, IO_VALUE.LOW);
LeftMoveInfo.log($"左侧料盘已手动放入,批量轴下降固定值");
break;
case MoveStep.L15:
LeftMoveInfo.NextMoveStep(MoveStep.L16);
LeftAxisRiseMax();
LeftMoveInfo.log($"批量轴重新上升到P2位置,LeftStartMovePosition={LeftStartMovePosition}");
break;
case MoveStep.L16:
LeftBatchAxisPositionWhileTrayCheck = Left_Batch_Axis.GetAclPosition();
LeftMoveInfo.NextMoveStep(MoveStep.L20_WaitLabel);
break;
//等贴标,由贴标流程跳出
case MoveStep.L20_WaitLabel:
break;
//贴标完成,没有释放料串时进入判断料串满/不满流程
case MoveStep.L30_LabelFinish:
if (SafeReleaseLeftShelf)
{
//LeftShelfNoTray = true;
SafeReleaseLeftShelf = false;
LeftMoveInfo.NextMoveStep(MoveStep.L40_ShelfFull);
LeftMoveInfo.log($"用户请求释放料架");
}
else
{
if (PlwHight > 0)
{
LeftMoveInfo.NextMoveStep(MoveStep.L03);
LeftBatchAxisToP2(Config.Left_Batch_P1, Config.Left_Batch_P1_speed, IO_VALUE.LOW);
LeftMoveInfo.log($"贴标完成,批量轴下降固定值");
}
else
{
LeftMoveInfo.NextMoveStep(MoveStep.L30_LabelFinish);
}
}
break;
//满了下降到p1点,没有agv运输时挡停下降
case MoveStep.L40_ShelfFull:
LeftShelfNoTray = true;
LeftMoveInfo.NextMoveStep(MoveStep.LEND);
Left_Batch_Axis.AbsMove(LeftMoveInfo, Config.Left_Batch_P1, Config.Left_Batch_P1_speed);
if (ConfigHelper.Config.Get("UseAGVTransferShelf", false))//是否用AGV运输料串
{
LeftMoveInfo.log($"料串已满,批量轴下降到P1位置");
}
else
{
CylinderMove(LeftMoveInfo, IO_Type.LeftStopUP, IO_Type.LeftStopDown);
LeftMoveInfo.log($"料串已满,批量轴下降到P1位置,阻挡下降");
}
break;
case MoveStep.LEND:
LeftMoveInfo.EndMove();
LeftMoveInfo.log($"结束运动");
break;
//}
//料串出料流程,下降到p1,挡停下降,滚筒反转到后端检测低电平再转10秒,到前端检测低电平再转10秒,再等3秒,再等0.5秒后反转停止
//switch (LeftMoveInfo.MoveStep)
//{
case MoveStep.L50_OutShelf:
LeftMoveInfo.NextMoveStep(MoveStep.L51);
Left_Batch_Axis.AbsMove(LeftMoveInfo, Config.Left_Batch_P1, Config.Left_Batch_P1_speed);
LeftMoveInfo.log($"批量轴下降到P1位置");
break;
case MoveStep.L51:
LeftMoveInfo.NextMoveStep(MoveStep.L52);
CylinderMove(null, IO_Type.LeftStopUP, IO_Type.LeftStopDown);
LeftMoveInfo.log($"阻挡下降");
break;
case MoveStep.L52:
LeftMoveInfo.NextMoveStep(MoveStep.L53);
IOMove(IO_Type.LeftMoto_Run, IO_VALUE.LOW);
IOMove(IO_Type.LeftMoto_Reverse, IO_VALUE.HIGH);
LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LeftEnd_Check, IO_VALUE.LOW));
LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(10000));
LeftMoveInfo.log($"电滚筒向外滚动");
break;
case MoveStep.L53:
LeftMoveInfo.NextMoveStep(MoveStep.L54);
LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LeftFornt_Check, IO_VALUE.LOW));
LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(10000));
LeftMoveInfo.OneWaitCanEndStep = true;
LeftMoveInfo.log($"等待前置检测拉低");
break;
case MoveStep.L54:
LeftMoveInfo.NextMoveStep(MoveStep.L55);
LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(3000));
break;
case MoveStep.L55:
LeftMoveInfo.NextMoveStep(MoveStep.LEND);
IOMove(IO_Type.LeftMoto_Reverse, IO_VALUE.HIGH, false, 500);
LeftMoveInfo.log($"电滚停止");
break;
//}
//料串入料流程,轴下降到p1,挡停下降,滚筒正转到后端检测高电平后再转60秒,再转1秒,再转0.5秒停止,进入上料流程
//switch (LeftMoveInfo.MoveStep)
//{
case MoveStep.L60_InShelf:
LeftMoveInfo.NextMoveStep(MoveStep.L61);
Left_Batch_Axis.AbsMove(LeftMoveInfo, Config.Left_Batch_P1, Config.Left_Batch_P1_speed);
LeftMoveInfo.log($"批量轴下降到P1位置");
break;
case MoveStep.L61:
LeftMoveInfo.NextMoveStep(MoveStep.L62);
CylinderMove(null, IO_Type.LeftStopUP, IO_Type.LeftStopDown);
LeftMoveInfo.log($"阻挡下降");
break;
case MoveStep.L62:
LeftMoveInfo.NextMoveStep(MoveStep.L63);
IOMove(IO_Type.LeftMoto_Reverse, IO_VALUE.LOW);
IOMove(IO_Type.LeftMoto_Run, IO_VALUE.HIGH);
LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LeftEnd_Check, IO_VALUE.HIGH));
LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(60000));
LeftMoveInfo.TimeOutSeconds = 60;
LeftMoveInfo.OneWaitCanEndStep = true;
LeftMoveInfo.log($"等待料串到位");
break;
case MoveStep.L63:
LeftMoveInfo.NextMoveStep(MoveStep.L64);
LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
break;
case MoveStep.L64:
LeftMoveInfo.NextMoveStep(MoveStep.L65);
IOMove(IO_Type.LeftMoto_Run, IO_VALUE.HIGH, false, 500);
CylinderMove(null, IO_Type.LeftStopDown, IO_Type.LeftStopUP);
LeftMoveInfo.log($"电滚筒停止,阻挡上升");
break;
case MoveStep.L65:
if (IOValue(IO_Type.LeftEnd_Check).Equals(IO_VALUE.HIGH))
{
LeftMoveInfo.NewMove(MoveStep.L01);
LeftMoveInfo.log($"料串进入开始上料");
}
else
{
LeftMoveInfo.NextMoveStep(MoveStep.LEND);
LeftMoveInfo.log($"料串进入失败");
}
break;
default:
LeftMoveInfo.log($"未找到对应步骤:{LeftMoveInfo.MoveStep}");
break;
}
}
string LeftState()
{
string state = "";
if (IOValue(IO_Type.LeftEnd_Check).Equals(IO_VALUE.HIGH))
{
state += string.Format(crc.GetString("Res0069", "有料串,已放置{0}张料盘"), LeftCount);
if (LeftShelfNoTray)
{
state += "," + crc.GetString("Res0043", "料串已满");
}
else
state += ".";
state += crc.GetString("Res0045", "当前ReelID:") + LeftMoveInfo.MoveParam.WareCode;
}
else
{
return crc.GetString("Res0046", "无料串");
}
return state;
}
int LeftStartMovePosition = 0;
void LeftBatchAxisToP2(int target, int Speed, IO_VALUE ioValue)
{
int targetP2 = target;
int targetSpeed = Speed;
int currPosition = Left_Batch_Axis.GetAclPosition();
LeftMoveInfo.log("BatchAxisToP2 目标P2: " + targetP2 + "(" + currPosition + ")");
LeftMoveInfo.TimeOutSeconds = 200;
LeftMoveInfo.CanWhileCount = 0;
// 需要增加定时器,获取验证信号并停止伺服
LeftStartMovePosition = Left_Batch_Axis.GetAclPosition();
LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitBatchAxisMove(Config.Left_Batch_Axis, targetP2, targetSpeed));
Config.Left_Batch_Axis.TargetPosition = targetP2;
Left_Batch_Axis.AbsMove(null, targetP2, targetSpeed);
//开始检测信号
Left_Batch_Axis.BatchAxisStartCheck(IO_Type.LeftTop_Check, ioValue);
}
/// <summary>
/// 左批量轴下降到X23对射信号灭
/// </summary>
void LeftBatchAxisToP1()
{
int targetP1 = Config.Left_Batch_P1;
int targetSpeed = Config.Left_Batch_P2_speed;
LeftMoveInfo.TimeOutSeconds = 200;
LeftMoveInfo.CanWhileCount = 0;
// 需要增加定时器,获取验证信号并停止伺服
LeftStartMovePosition = Left_Batch_Axis.GetAclPosition();
LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitBatchAxisMove(Config.Left_Batch_Axis, targetP1, targetSpeed));
Config.Left_Batch_Axis.TargetPosition = targetP1;
Left_Batch_Axis.AbsMove(null, targetP1, targetSpeed);
//开始检测信号
Left_Batch_Axis.BatchAxisStartCheck(IO_Type.LeftTop_Check, IO_VALUE.LOW);
}
/// <summary>
/// 下降固定值
/// </summary>
void LeftBatchAxisDown()
{
int targetP1 = Left_Batch_Axis.GetAclPosition() - ConfigHelper.Config.Get("LeftAxisDownValue", 50) * Config.Left_Batch_ChangeValue;
if (PlwHight > 5000)
{
int currpoint = Left_Batch_Axis.GetAclPosition();
int countPleHight = PlwHight / Config.Right_Batch_ChangeValue * Config.Left_Batch_ChangeValue;
targetP1 = currpoint - countPleHight + 5000;
LeftMoveInfo.log($"出料提升机构,获取到料盘高度脉冲{PlwHight},当前位置{currpoint},计算盘高{countPleHight}");
}
int targetSpeed = Config.Left_Batch_P1_speed;
if (targetP1 <= 0)
{
LeftMoveInfo.log("出料提升机构,下降固定值小于0,设置回到0原点。");
targetP1 = 0;
}
LeftMoveInfo.log($"出料提升机构,下降固定值为{targetP1}脉冲!");
Left_Batch_Axis.AbsMove(LeftMoveInfo, targetP1, targetSpeed);
}
/// <summary>
/// 下降在上升以后,上升指定阈值,防止感应器失效
/// </summary>
void LeftAxisRiseMax()
{
//1.获取当前私服下降后的脉冲
LeftStartMovePosition = Left_Batch_Axis.GetAclPosition();
//2.获取下降的高度、冗余高度、一毫米的脉冲值
int downvalue = ConfigHelper.Config.Get("LeftAxisDownValue", 50);
int redundancy = ConfigHelper.Config.Get("LeftAxisRiseRedundancyValue", 10);
int change = Config.Left_Batch_ChangeValue;
int totalpulse = (downvalue + redundancy) * change;
int targetP2 = LeftStartMovePosition + totalpulse;
LeftMoveInfo.log($"下降固定值后提升,感应器亮或提升固定值:当前私服高度={LeftStartMovePosition},下降的固定高度={downvalue}," +
$"上升最大高度={redundancy},每毫米脉冲={change},上升脉冲为{targetP2},P2={Config.Left_Batch_P2}");
int targetSpeed = Config.Left_Batch_P2_speed;
LeftMoveInfo.TimeOutSeconds = 200;
LeftMoveInfo.CanWhileCount = 0;
// 需要增加定时器,获取验证信号并停止伺服
LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitBatchAxisMove(Config.Left_Batch_Axis, targetP2, targetSpeed));
Config.Left_Batch_Axis.TargetPosition = targetP2;
Left_Batch_Axis.AbsMove(null, targetP2, targetSpeed);
//开始检测信号
Left_Batch_Axis.BatchAxisStartCheck(IO_Type.LeftTop_Check, IO_VALUE.HIGH);
}
}
}