MainMachine _RightProcess.cs
14.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
using CodeLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
partial class MainMachine
{
bool RightShelfNoTray = false;
int RightCount = 0;
void RightProcess()
{
if (CheckWait(RightMoveInfo))
return;
//常规上料扫码流程
switch (RightMoveInfo.MoveStep)
{
case MoveStep.R01:
RightCount = 0;
RightMoveInfo.NextMoveStep(MoveStep.R03);
RightBatchAxisToP2(true);
RightMoveInfo.log($"批量轴上升到P2位置,第一次提升,RightStartMovePosition={RightStartMovePosition}");
break;
case MoveStep.R02:
RightMoveInfo.NextMoveStep(MoveStep.R03);
RightBatchAxisToP2(false);
RightMoveInfo.log($"批量轴上升到P2位置,二次提升,RightStartMovePosition={RightStartMovePosition}");
break;
case MoveStep.R03:
if (IOValue(IO_Type.RightOverHead_Check).Equals(IO_VALUE.HIGH))
{
RightMoveInfo.NextMoveStep(MoveStep.R02);
Right_Batch_Axis.AbsMove(RightMoveInfo, RightStartMovePosition, Config.Right_Batch_P2_speed);
RightMoveInfo.log($"批量轴上升过头,下降到:RightStartMovePosition={RightStartMovePosition}");
}
else
{
RightMoveInfo.NextMoveStep(MoveStep.R04);
}
break;
case MoveStep.R04:
if (IOValue(IO_Type.RightTop_Check).Equals(IO_VALUE.LOW) && RightShelfNoTray.Equals(false))
{
RightMoveInfo.NextMoveStep(MoveStep.R06_GettedReelHigh);
GetHeight();
ScanCode();
RightMoveInfo.log($"开始扫码,并获取上一盘料高度,LastHeight={LastHeight}");
}
else
{
if (RightShelfNoTray.Equals(false))
{
//判断当前位置是否在指定的位置
int currP = Right_Batch_Axis.GetAclPosition();
int chaz = Math.Abs(currP - Config.Right_Batch_P2);
if (chaz > Right_Batch_Axis.Config.CanErrorCountMax)
{
//RightMoveInfo.NextMoveStep(MoveStep.R02);
RightMoveInfo.log("CheckHasTray:上料轴开始慢速上升到P2[" + Config.Right_Batch_P2 + "],等待检测到料盘");
RightShelfNoTray = false;
RightBatchAxisToP2(false);
return;
}
}
//无料盘
RightShelfNoTray = true;
RightMoveInfo.NextMoveStep(MoveStep.R12_ShelfNoTray);
RightMoveInfo.log($"批量轴已上升到顶,料串已满.");
}
break;
case MoveStep.R06_GettedReelHigh:
if (RightScanTask.IsCompleted)
{
var x = RightScanTask.Result;
if (x.Count == 0)
{
RightMoveInfo.log($"未识别到有效二维码,转入NG箱");
RightMoveInfo.MoveParam.IsNg = true;
}
else
{
RightMoveInfo.MoveParam.codeInfos = x;
//调用标签打印
DoPrint("123");
RightMoveInfo.log($"已完成扫码,等待料盘被取走 Count={x.Count}");
}
RightMoveInfo.NextMoveStep(MoveStep.R10_WaitReelLeave);
}
else if (RightMoveInfo.IsTimeOut(10))
{
RightMoveInfo.log($"等待扫码超时");
}
break;
case MoveStep.R10_WaitReelLeave:
break;
case MoveStep.R11_NextReel:
RightCount++;
RightMoveInfo.NextMoveStep(MoveStep.R02);
RightMoveInfo.log($"料盘已取走,开始准备下一盘料");
break;
case MoveStep.R12_ShelfNoTray:
RightMoveInfo.NextMoveStep(MoveStep.REND);
Right_Batch_Axis.AbsMove(RightMoveInfo, Config.Right_Batch_P1, Config.Right_Batch_P1_speed);
RightMoveInfo.log($"料窜已取完, 批量轴下降到P1");
break;
case MoveStep.REND:
RightMoveInfo.log($"结束运动");
RightMoveInfo.EndMove();
break;
//}
//料窜出料流程
//switch (RightMoveInfo.MoveStep)
//{
case MoveStep.R30_OutShelf:
RightMoveInfo.NextMoveStep(MoveStep.R31);
Right_Batch_Axis.AbsMove(RightMoveInfo, Config.Right_Batch_P1, Config.Right_Batch_P1_speed);
RightMoveInfo.log($"批量轴下降到P1位置");
break;
case MoveStep.R31:
RightMoveInfo.NextMoveStep(MoveStep.R32);
CylinderMove(null, IO_Type.RightStopUP, IO_Type.RightStopDown);
RightMoveInfo.log($"阻挡下降");
break;
case MoveStep.R32:
RightMoveInfo.NextMoveStep(MoveStep.R33);
IOMove(IO_Type.RightMoto_Reverse, IO_VALUE.HIGH);
IOMove(IO_Type.RightMoto_Run, IO_VALUE.HIGH, false);
MiddleMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.RightEnd_Check, IO_VALUE.LOW));
RightMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(3000));
RightMoveInfo.log($"电滚筒向外滚动");
break;
case MoveStep.R33:
RightMoveInfo.NextMoveStep(MoveStep.R34);
MiddleMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.RightFornt_Check, IO_VALUE.LOW));
RightMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(3000));
RightMoveInfo.OneWaitCanEndStep = true;
RightMoveInfo.log($"等待前置检测拉低");
break;
case MoveStep.R34:
RightMoveInfo.NextMoveStep(MoveStep.REND);
IOMove(IO_Type.RightMoto_Run, IO_VALUE.LOW, false, 500);
RightMoveInfo.log($"电滚停止");
break;
//}
//料窜入料流程
//switch (RightMoveInfo.MoveStep)
//{
case MoveStep.R40_InShelf:
RightMoveInfo.NextMoveStep(MoveStep.R41);
Right_Batch_Axis.AbsMove(RightMoveInfo, Config.Right_Batch_P1, Config.Right_Batch_P1_speed);
RightMoveInfo.log($"批量轴下降到P1位置");
break;
case MoveStep.R41:
RightMoveInfo.NextMoveStep(MoveStep.R42);
IOMove(IO_Type.RightStopUP, IO_VALUE.LOW);
RightMoveInfo.log($"阻挡下降");
break;
case MoveStep.R42:
RightMoveInfo.NextMoveStep(MoveStep.R43);
IOMove(IO_Type.RightMoto_Reverse, IO_VALUE.LOW);
IOMove(IO_Type.RightMoto_Run, IO_VALUE.HIGH, false);
MiddleMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.RightEnd_Check, IO_VALUE.HIGH));
RightMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(6000));
RightMoveInfo.OneWaitCanEndStep = true;
RightMoveInfo.log($"等待料窜到位");
break;
case MoveStep.R43:
RightMoveInfo.NextMoveStep(MoveStep.R44);
IOMove(IO_Type.RightMoto_Run, IO_VALUE.LOW, false,500);
IOMove(IO_Type.RightStopUP, IO_VALUE.HIGH);
RightMoveInfo.log($"电滚筒停止,阻挡上升");
break;
case MoveStep.R44:
if (IOValue(IO_Type.RightEnd_Check).Equals(IO_VALUE.HIGH))
{
RightMoveInfo.NewMove(MoveStep.R01);
RightMoveInfo.log($"料窜进入开始上料");
}
else
{
RightMoveInfo.NextMoveStep(MoveStep.REND);
RightMoveInfo.log($"料窜进入失败");
}
break;
default:
RightMoveInfo.log($"未找到对应步骤:{RightMoveInfo.MoveStep}");
break;
}
}
string RightState() {
string state = "";
if (IOValue(IO_Type.RightEnd_Check).Equals(IO_VALUE.HIGH))
{
state += $"有料窜,已提取{RightCount}张料盘";
if (RightShelfNoTray)
state += ",料串已清空";
else
state += ".";
state += "当前ReelID:"+ RightMoveInfo.MoveParam.WareCode;
}
else
{
return "无料窜";
}
return state;
}
/// <summary>
/// 扫码线程
/// </summary>
Task<List<CodeInfo>> RightScanTask;
void ScanCode() {
RightMoveInfo.log("开始扫码");
//RightMoveInfo.OneWaitCanEndStep = true;
//RightMoveInfo.WaitList.Add(WaitResultInfo.WaitScanCode());
//RightMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
try
{
RightScanTask = Task.Run(new Func<List<CodeInfo>>(()=>
{
IOMove(IO_Type.Camera_Led, IO_VALUE.HIGH);
Task.Delay(10).Wait();
List<CodeInfo> LastCodeList = CodeManager.CameraScan(new List<string> { Config.RightCameraName });
if (LastCodeList.Count <= 0)
{
Task.Delay(500).Wait();
LastCodeList = CodeManager.CameraScan(new List<string> { Config.RightCameraName });
}
IOMove(IO_Type.Camera_Led, IO_VALUE.LOW);
return LastCodeList;
}));
}
catch (Exception ex)
{
LogUtil.error("FI_13_ScanCode扫码出错:", ex);
}
}
int RightStartMovePosition = 0;
void RightBatchAxisToP2(bool isFirstMove = true)
{
int targetP2 = Config.Right_Batch_P2;
int targetSpeed = Config.Right_Batch_P2_speed;
if (!isFirstMove)
{
int currPosition = Right_Batch_Axis.GetAclPosition();
if (currPosition != -1)
{
//targetP2 = currPosition + Config.Right_Batch_ChangeValue * 80;
if (targetP2 > Config.Right_Batch_P2)
{
targetP2 = Config.Right_Batch_P2;
}
RightMoveInfo.log("BatchAxisToP2 目标P2: " + targetP2 + "(" + currPosition + ")");
}
//targetSpeed = Config.BatchAxis_P3Speed / 2;
}
RightMoveInfo.TimeOutSeconds = 200;
RightMoveInfo.CanWhileCount = 0;
// 需要增加定时器,获取验证信号并停止伺服
RightStartMovePosition = Right_Batch_Axis.GetAclPosition();
RightMoveInfo.WaitList.Add(WaitResultInfo.WaitBatchAxisMove(Config.Right_Batch_Axis, targetP2, targetSpeed));
Config.Right_Batch_Axis.TargetPosition = targetP2;
Right_Batch_Axis.AbsMove(null, targetP2, targetSpeed);
//开始检测信号
Right_Batch_Axis.BatchAxisStartCheck(IO_Type.RightTop_Check, IO_VALUE.LOW);
}
int RightEndMovePosition = 0;
int LastHeight = 0;
private int GetHeight()
{
LastHeight = 0;
int AxisChangeValue = Config.Right_Batch_ChangeValue;
//计算高度
RightEndMovePosition = Right_Batch_Axis.GetAclPosition();
bool isLast = false;
int chaz = Math.Abs(RightEndMovePosition - Config.Right_Batch_P2);
if (chaz < Right_Batch_Axis.Config.CanErrorCountMax)
{
isLast = true;
}
float height = (float)Math.Ceiling(1F * Math.Abs(RightEndMovePosition - RightStartMovePosition) / AxisChangeValue);
string buchongStr = "";
if (isLast)
{
buchongStr = "(最后一盘料已补充5)";
height += 5;
}
//如果检测出<=15,都按照8计算
if (height <= 15)
{
LastHeight = 8;
}
else
{
List<int> heightList = new List<int> { 8, 12, 16, 20 };
heightList = (from m in heightList orderby m descending select m).ToList<int>();
float minCha = height;
foreach (int h in heightList)
{
//取差值最小的接近值
float cha = Math.Abs(h - (height - 4));
if (cha < minCha)
{
LastHeight = h;
minCha = cha;
}
}
}
if (LastHeight <= 8) { LastHeight = 8; }
string msg = Name + " 计算盘高:上升前 [" + RightStartMovePosition + "]实时[ " + RightEndMovePosition + "]差值[" + (RightEndMovePosition - RightStartMovePosition) + "]系数[" + AxisChangeValue + "] 计算后" + buchongStr + "[" + height + "]" + ",归类为【" + LastHeight + "mm】";
LogUtil.info(msg);
return LastHeight;
}
}
}