MainMachine _RightProcess.cs
9.7 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
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
{
partial class MainMachine
{
bool RightShelfNoTray = false;
void RightProcess()
{
if (CheckWait(RightMoveInfo))
return;
switch (RightMoveInfo.MoveStep)
{
case MoveStep.R01:
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);
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:
if (RightScanTask.IsCompleted)
{
RightMoveInfo.NextMoveStep(MoveStep.R10_WaitReelLeave);
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}");
}
}
else if (RightMoveInfo.IsTimeOut(10)) {
RightMoveInfo.log($"等待扫码超时");
}
break;
case MoveStep.R10_WaitReelLeave:
break;
case MoveStep.R11_NextReel:
RightMoveInfo.NextMoveStep(MoveStep.R02);
RightMoveInfo.log($"料盘已取走,开始准备下一盘料");
break;
case MoveStep.R12_ShelfNoTray:
RightMoveInfo.NextMoveStep(MoveStep.R20);
Right_Batch_Axis.AbsMove(RightMoveInfo, Config.Right_Batch_P1, Config.Right_Batch_P1_speed);
RightMoveInfo.log($"料窜已取完, 批量轴下降到P1");
break;
case MoveStep.R20:
RightMoveInfo.EndMove();
break;
case MoveStep.REND:
break;
}
}
/// <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;
}
}
}