MainMachine_InCar.cs
17.1 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
using CodeLibrary;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace DeviceLibrary
{
partial class MainMachine
{
/// <summary>
/// 通知料盘已取走
/// </summary>
void ReelGetted(bool success = true)
{
if (InCarMoveInfo.MoveStep == MoveStep.InCarReadyGet)
if (success)
InCarMoveInfo.NextMoveStep(MoveStep.InCarReelGot);
else
InCarMoveInfo.NextMoveStep(MoveStep.InCarReelGetFail);
else
InCarMoveInfo.log($"无法执行ReelGetted,因为当前步骤为:{InCarMoveInfo.MoveStep}");
}
bool InHasCar { get => (IOValue(IO_Type.Loading_Car_Check).Equals(IO_VALUE.HIGH) || IOValue(IO_Type.Loading_Car1315_Check).Equals(IO_VALUE.HIGH)); }
public CarTypeE InCarType = CarTypeE.None;
public int InCurrentStringNum = 0;
bool innewreel = true;
int ReelGetFail = 0;
const bool oldtestheight = true;
void InCarProcess()
{
if (CheckWait(InCarMoveInfo))
return;
switch (InCarMoveInfo.MoveStep)
{
case MoveStep.Wait:
InCarType = CarTypeE.None;
var hascar = InHasCar;
if (hascar)
Loading_NOCar_Led.LedState = LedState.blink;
else
Loading_NOCar_Led.LedState = LedState.off;
if (hascar && IOValue(IO_Type.Loading_CarLock_Btn).Equals(IO_VALUE.HIGH))
{
InCarMoveInfo.NextMoveStep(MoveStep.InCar_01);
InCarMoveInfo.log("检测到小车到位");
}
else if (hascar && IOValue(IO_Type.Loading_Car_Location_Up).Equals(IO_VALUE.HIGH))
{
InCarMoveInfo.NextMoveStep(MoveStep.InCar_02);
InCarMoveInfo.log("小车已经到位");
}
break;
case MoveStep.InCar_01:
InCarMoveInfo.NextMoveStep(MoveStep.InCar_02);
InCarMoveInfo.log($"提升定位气缸");
CylinderMove(InCarMoveInfo, IO_Type.Loading_Car_Location_Down, IO_Type.Loading_Car_Location_Up, IO_VALUE.HIGH);
break;
case MoveStep.InCar_02:
var car7 = IOValue(IO_Type.Loading_Car_Check).Equals(IO_VALUE.HIGH);
var car13 = IOValue(IO_Type.Loading_Car1315_Check).Equals(IO_VALUE.HIGH);
if (car7 || car13)
{
if (car7)
InCarType = CarTypeE.Car7;
else
InCarType = CarTypeE.Car13;
InCarMoveInfo.log($"检测到料车尺寸:{InCarType}");
InCarMoveInfo.NextMoveStep(MoveStep.InCar_03);
Loading_NOCar_Led.LedState = LedState.on;
}
else {
InCarMoveInfo.log($"小车丢失,重新检测");
CylinderMove(InCarMoveInfo, IO_Type.Loading_Car_Location_Down, IO_Type.Loading_Car_Location_Up, IO_VALUE.LOW);
InCarMoveInfo.NextMoveStep(MoveStep.Wait);
}
break;
case MoveStep.InCar_03:
InCarMoveInfo.NextMoveStep(MoveStep.InCar_04);
innewreel = true;
InCarMoveInfo.log($"新料串");
break;
case MoveStep.InCar_04:
InCarMoveInfo.NextMoveStep(MoveStep.InCar_05);
InCarMoveInfo.log($"批量轴高速上升到顶部检测点");
BatchAxisToP2(InCarMoveInfo, Loading_Batch_Axis, INGetReelCheckIOList(),IO_VALUE.HIGH, Config.Loading_Batch_Axis_P2, Config.Loading_Batch_Axis_P1_speed);
break;
case MoveStep.InCar_05:
InCarMoveInfo.NextMoveStep(MoveStep.InCar_06);
InCurrentStringNum = GetTopStringNum(INGetReelCheckIOList());
if (Loading_Batch_Axis.IsInPosition(Config.Loading_Batch_Axis_P2) && InCurrentStringNum==0)
{
StartMovePosition = Setting_Init.Runtime_StartMovePosition;
SetReelHeight(GetHeight(InCarMoveInfo));
InCarMoveInfo.log($"料车料盘检测为空");
InCarMoveInfo.NextMoveStep(MoveStep.InCarOut_01);
return;
}
var tpos1 = Loading_Batch_Axis.GetAclPosition() - Config.Loading_Batch_Axis_MMtoPOS * 10;
if (tpos1 < Config.Loading_Batch_Axis_P1)
tpos1 = Config.Loading_Batch_Axis_P1;
Loading_Batch_Axis.AbsMove(InCarMoveInfo, tpos1, Config.Loading_Batch_Axis_P1_speed);
InCarMoveInfo.log($"批量轴下降1cm");
break;
case MoveStep.InCar_06:
InCarMoveInfo.NextMoveStep(MoveStep.InCar_07);
BatchAxisToP2(InCarMoveInfo, Loading_Batch_Axis, INGetReelCheckIOList(), IO_VALUE.HIGH, Config.Loading_Batch_Axis_P2, Config.Loading_Batch_Axis_P2_speed);
InCarMoveInfo.WaitList.Add(WaitResultInfo.WaitMsg("进料车料串正在上升",MsgLevel.warning));
break;
case MoveStep.InCar_07:
InCarMoveInfo.NextMoveStep(MoveStep.InCarReadyGet);
InCurrentStringNum = GetTopStringNum(INGetReelCheckIOList());
if (Loading_Batch_Axis.IsInPosition(Config.Loading_Batch_Axis_P2) && InCurrentStringNum == 0)
{
InCarMoveInfo.log($"料车料盘检测为空");
InCarMoveInfo.NextMoveStep(MoveStep.InCarOut_01);
return;
}
InCarMoveInfo.log($"料车料盘检测到新的当前串[{InCurrentStringNum}串]");
if (InCurrentStringNum == 0) {
InCarMoveInfo.NextMoveStep(MoveStep.InCar_06);
InCarMoveInfo.log($"再次上升");
return;
}
//if (!innewreel)
StartMovePosition = Setting_Init.Runtime_StartMovePosition;
SetReelHeight(GetHeight(InCarMoveInfo));
//innewreel = false;
break;
case MoveStep.InCarReadyGet:
Msg.add("入口料串取料准备就绪", MsgLevel.info);
break;
case MoveStep.InCarReelGot:
InCarMoveInfo.log($"料已取走,开始测高");
InCarMoveInfo.NextMoveStep(MoveStep.InCarReelGet_01);
break;
case MoveStep.InCarReelGet_01:
InCarMoveInfo.NextMoveStep(MoveStep.InCarReelGet_02);
BatchAxisToP2(InCarMoveInfo, Loading_Batch_Axis, INGetReelCheckIOList(InCurrentStringNum), IO_VALUE.HIGH, Config.Loading_Batch_Axis_P2, Config.Loading_Batch_Axis_P2_speed);
InCarMoveInfo.log($"批量轴[{InCurrentStringNum}串]上升检测信号:{INGetReelCheckIOList(InCurrentStringNum)[0]}");
break;
case MoveStep.InCarReelGet_02:
InCarMoveInfo.NextMoveStep(MoveStep.InCarReelGet_03);
SetReelHeight(GetHeight(InCarMoveInfo));
var topnum = GetTopStringNum(INGetReelCheckIOList());
if (InCurrentStringNum == topnum)
{
InCarMoveInfo.log($"最高侧等于当前侧:{InCurrentStringNum}");
}
else {
InCarMoveInfo.log($"最高侧不等于当前侧:{InCurrentStringNum}!={topnum}");
}
break;
case MoveStep.InCarReelGet_03:
InCarMoveInfo.NextMoveStep(MoveStep.InCarReelGet_04);
BatchAxisToP2(InCarMoveInfo, Loading_Batch_Axis, INGetReelCheckIOList(), IO_VALUE.LOW, Config.Loading_Batch_Axis_P1, Config.Loading_Batch_Axis_P1_speed);
InCarMoveInfo.log($"下降到所有传感器灭");
break;
case MoveStep.InCarReelGet_04:
if (GetTopStringNum(INGetReelCheckIOList()) != 0)
{
InCarMoveInfo.NextMoveStep(MoveStep.InCarReelGet_03);
InCarMoveInfo.log($"还未到底, 继续下降");
}
else
{
InCarMoveInfo.NextMoveStep(MoveStep.InCar_06);
InCarMoveInfo.log($"完成[{InCurrentStringNum}串]盘上料");
}
break;
case MoveStep.InCarReelGetFail:
InCarMoveInfo.log($"料盘取走失败,料盘下降");
ReelGetFail++;
InCarMoveInfo.NextMoveStep(MoveStep.InCarReelGetFail_02);
var tpos2 = Loading_Batch_Axis.GetAclPosition() - Config.Loading_Batch_Axis_MMtoPOS * 20;
if (tpos2 < 0)
tpos2 = 0;
Loading_Batch_Axis.AbsMove(InCarMoveInfo, tpos2, Config.Loading_Batch_Axis_P1_speed);
break;
case MoveStep.InCarReelGetFail_02:
InCarMoveInfo.NextMoveStep(MoveStep.InCar_06);
InCarMoveInfo.log($"[{InCurrentStringNum}串]料盘取走失败,重新上升");
break;
case MoveStep.InCarOut_01:
InCarMoveInfo.NextMoveStep(MoveStep.InCarOut_02);
incarProcessFinish = true;
InCarMoveInfo.log($"料串下降到P1点");
Loading_Batch_Axis.AbsMove(InCarMoveInfo, Config.Loading_Batch_Axis_P1, Config.Loading_Batch_Axis_P1_speed);
InCarMoveInfo.WaitList.Add(WaitResultInfo.WaitMsg("料串正在下降", MsgLevel.warning));
break;
case MoveStep.InCarOut_02:
InCarMoveInfo.NextMoveStep(MoveStep.InCarOut_Released);
InCarMoveInfo.log($"顶升下降");
CylinderMove(InCarMoveInfo, IO_Type.Loading_Car_Location_Down, IO_Type.Loading_Car_Location_Up, IO_VALUE.LOW);
break;
case MoveStep.InCarOut_Released:
InCarMoveInfo.log($"料串已回到待机点");
InCarMoveInfo.NewMove(MoveStep.Wait);
break;
default:
InCarMoveInfo.log($"未找到对应步骤:{InCarMoveInfo.MoveStep}");
break;
}
}
string InCarProcessState() {
string state = "";
if (InCarType == CarTypeE.Car13)
state = "13/15寸盘小车";
else if (InCarType == CarTypeE.Car7)
{
state = "7寸盘小车";
}
else if (InHasCar)
state = "检测到小车,尚未锁定";
if (InCarMoveInfo.MoveStep == MoveStep.Wait)
{
return "空闲中";
}
else if (InCarMoveInfo.MoveStep < MoveStep.InCarReadyGet)
{
return state + "," + "准备中";
}
else if (InCarMoveInfo.MoveStep >= MoveStep.InCarOut_01)
{
return state + "," + "释放中";
}
else if (InCarMoveInfo.MoveStep > MoveStep.InCar_06)
{
return state;
}
return state;
}
int StartMovePosition = 0;
void BatchAxisToP2(MoveInfo moveInfo, AxisBean axisBean, string[] CheckIoList, IO_VALUE iO_VALUE, int targetpos, int speed)
{
int targetP2 = targetpos;
int targetSpeed = speed;
moveInfo.log($"BatchAxis 目标P2: {targetP2},{speed},IO_VALUE={iO_VALUE},axisBean:{axisBean.Config.Explain},CheckIoList:{string.Join(",",CheckIoList)}");
moveInfo.TimeOutSeconds = 200;
moveInfo.CanWhileCount = 0;
// 需要增加定时器,获取验证信号并停止伺服
if (axisBean== Loading_Batch_Axis)
StartMovePosition = axisBean.GetAclPosition();
moveInfo.WaitList.Add(WaitResultInfo.WaitBatchAxisMove(axisBean.Config, targetP2, targetSpeed));
axisBean.Config.TargetPosition = targetP2;
axisBean.AbsMove(null, targetP2, targetSpeed);
//开始检测信号
axisBean.BatchAxisStartCheck(CheckIoList, iO_VALUE);
}
int CalcHeight(int mm)
{
LogUtil.info($"获取mm:{mm}");
List<int> heightList = new List<int> { 8, 12, 16, 24, 32, 44, 56 };
heightList.Reverse();
//heightList = (from m in heightList orderby m descending select m).ToList<int>();
//float minCha = height;
foreach (int h in heightList)
{
if (mm > h + 1)
{
return h;
}
}
return 8;
}
string LastCode = "";
private int GetHeight(MoveInfo moveInfo)
{
int LastHeight = 0;
int AxisChangeValue = Config.Loading_Batch_Axis_MMtoPOS;
//计算高度
int EndMovePosition = Loading_Batch_Axis.GetAclPosition();
float height = (float)Math.Ceiling(1F * Math.Abs(EndMovePosition - StartMovePosition) / AxisChangeValue);
string buchongStr = "";
if (Loading_Batch_Axis.IsInPosition(Config.Loading_Batch_Axis_P2))
{
buchongStr = $"(最后一盘料已补充{Config.LastTrayAddHeight})";
height += Config.LastTrayAddHeight;
}
LastHeight = (int)height;
if (LastHeight <= 8) { LastHeight = 8; }
string msg = Name + " 计算盘高:上升前 [" + StartMovePosition + "]实时[ " + EndMovePosition + "]差值[" + (EndMovePosition - StartMovePosition) + "]系数[" + AxisChangeValue + "] 计算后" + buchongStr + "[" + height + "]" + ",归类为【" + LastHeight + "mm】条码【" + LastCode + "】";
LogUtil.info(msg);
if (LastHeight > 80)
LastHeight = 80;
return LastHeight;
if (moveInfo.MoveParam.PlateW == 15)
{
height -= 2;
}
else if (moveInfo.MoveParam.PlateW == 13)
{
//height -= 3;
}
//如果检测出<=15,都按照8计算
if (height < 12)
{
LastHeight = 8;
}
else
{
List<int> heightList = new List<int> { 8, 12, 16, 24, 32, 44, 56 };
//heightList = (from m in heightList orderby m descending select m).ToList<int>();
//float minCha = height;
foreach (int h in heightList)
{
if (height > h)
{
LastHeight = h;
}
}
}
if (LastHeight <= 8) { LastHeight = 8; }
//string code = CodeManager.ProcessCode(LastCodeList);
msg = Name + " 计算盘高:上升前 [" + StartMovePosition + "]实时[ " + EndMovePosition + "]差值[" + (EndMovePosition - StartMovePosition) + "]系数[" + AxisChangeValue + "] 计算后" + buchongStr + "[" + height + "]" + ",归类为【" + LastHeight + "mm】条码【" + LastCode + "】";
LogUtil.info(msg);
return LastHeight;
}
string[] INGetReelCheckIOList(int currentnum = 0) {
if (currentnum > 0)
return new string[] { "Loading_Batch_ReelCheck_T" + currentnum.ToString() };
if (InCarType == CarTypeE.Car7)
{
return new string[] { IO_Type.Loading_Batch_ReelCheck_T1, IO_Type.Loading_Batch_ReelCheck_T2, IO_Type.Loading_Batch_ReelCheck_T4, IO_Type.Loading_Batch_ReelCheck_T5 };
}
else
{
return new string[] { IO_Type.Loading_Batch_ReelCheck_T3 };
}
}
int GetTopStringNum(string[] checkiolist) {
foreach (var io in checkiolist) {
if (IOValue(io).Equals(IO_VALUE.HIGH))
{
return int.Parse(io.Substring(io.Length - 1));
}
}
return 0;
}
}
}