T1Machine.partial.cs
27.4 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
using CodeLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static Asa.eyemLib;
using static DeviceLibrary.eyemlib;
namespace DeviceLibrary
{
partial class T1Machine
{
public IO_VALUE End_Line_Tray_Check { get => IOValue(IO_T1_Type.End_Line_Tray_Check); }
public bool TrayCanIN()
{
return IOValue(IO_T1_Type.End_Line_Tray_Check).Equals(IO_VALUE.LOW) && IOValue(IO_T1_Type.End_Lift_Cylinder_Down).Equals(IO_VALUE.HIGH);
}
public void LineRun(int sec = 0)
{
IOMove(IO_T1_Type.Line4_Run, IO_VALUE.HIGH, false, sec);
}
void WorkProcess()
{
if (CheckWait(MoveInfo))
return;
switch (MoveInfo.MoveStep)
{
case MoveStep.T1_01_WaitReel:
if (End_Line_Tray_Check.Equals(IO_VALUE.HIGH) && preReelParam != null)
{
MoveInfo.ReelParam = preReelParam;
preReelParam = null;
MoveInfo.log("检测到料盘 ReelParam:" + MoveInfo.ReelParam.ToStr());
MoveInfo.NextMoveStep(MoveStep.T1_02_WaitReelInpos);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
}
else
{
Msg.add("等待上料区进入料盘", MsgLevel.info);
}
break;
case MoveStep.T1_02_WaitReelInpos:
MoveInfo.NextMoveStep(MoveStep.T1_03_LocationUp);
//IOMove(IO_T1_Type.Line4_Run, IO_VALUE.LOW);
MoveInfo.log($"将料盘推到位 width:{MoveInfo.ReelParam.PlateW},POS:{Config.GetTrayPos(MoveInfo.ReelParam.PlateW)}位置");
T_TrayPos_Axis.AbsMove(MoveInfo, Config.GetTrayPos(MoveInfo.ReelParam.PlateW), Config.TrayPos_P1_speed);
T_Pan_Axis.AbsMove(MoveInfo, Config.Pan_P1, Config.Pan_P1_speed);
RobotManage.electricGripper.Release();
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
break;
case MoveStep.T1_03_LocationUp:
MoveInfo.NextMoveStep(MoveStep.T1_04_DownToReel);
MoveInfo.log($"料盘顶升");
IOMove(IO_T1_Type.Line4_Run, IO_VALUE.LOW);
CylinderMove(MoveInfo, IO_T1_Type.End_Lift_Cylinder_Down, IO_T1_Type.End_Lift_Cylinder_Up, IO_VALUE.HIGH);
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_T1_Type.End_Lift_Tray_Check, IO_VALUE.HIGH));
break;
case MoveStep.T1_04_DownToReel:
MoveInfo.NextMoveStep(MoveStep.T1_05_ClampReel);
int pos = Config.UpdownAxis_P2 - (MoveInfo.ReelParam.PlateH - 8) * Config.UpdownAxis_ChangeValue;
MoveInfo.log($"升降轴下降到取料位置,配置位置:{Config.UpdownAxis_P2},计算位置:{pos}");
T_Updown_Axis.AbsMove(MoveInfo, pos, Config.UpdownAxis_P2_speed);
T_TrayPos_Axis.AbsMove(null, Config.TrayPos_P1, Config.TrayPos_P1_speed);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
break;
case MoveStep.T1_05_ClampReel:
if (RobotManage.electricGripper.Clamp(null))
{
MoveInfo.NextMoveStep(MoveStep.T1_06_UpToTop);
MoveInfo.log($"夹爪张开");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1500));
}
else
{
Msg.add("夹爪忙碌中...", MsgLevel.warning);
}
break;
case MoveStep.T1_06_UpToTop:
MoveInfo.NextMoveStep(MoveStep.T1_07_PanToOut);
MoveInfo.log($"升降轴上升, 料盘提升下降");
T_Updown_Axis.AbsMove(MoveInfo, Config.UpdownAxis_P1, Config.UpdownAxis_P1_speed);
CylinderMove(MoveInfo, IO_T1_Type.End_Lift_Cylinder_Down, IO_T1_Type.End_Lift_Cylinder_Up, IO_VALUE.LOW);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
break;
case MoveStep.T1_07_PanToOut:
MoveInfo.NextMoveStep(MoveStep.T1_08_DownToShelf);
MoveInfo.log($"横移到料串");
T_Pan_Axis.AbsMove(MoveInfo, Config.Pan_P2, Config.Pan_P2_speed);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
break;
case MoveStep.T1_08_DownToShelf:
if (ShelfInMoveInfo.MoveStep == MoveStep.Shelf_20_EmptyIn_ShelfReady)
{
MoveInfo.NextMoveStep(MoveStep.T1_09_ReleaseReel);
MoveInfo.log($"下降到料串");
T_Updown_Axis.AbsMove(MoveInfo, Config.UpdownAxis_P3, Config.UpdownAxis_P3_speed);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
}
else if (MoveInfo.IsTimeOut(30))
{
Msg.add("等待料串准备完成", MsgLevel.warning);
}
break;
case MoveStep.T1_09_ReleaseReel:
if (RobotManage.electricGripper.Release())
{
MoveInfo.NextMoveStep(MoveStep.T1_10_PutReelFinish);
MoveInfo.log($"夹爪放松");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
}
else
{
Msg.add("夹爪忙碌中...", MsgLevel.warning);
}
break;
case MoveStep.T1_10_PutReelFinish:
ShelfInMoveInfo.ReelParam = MoveInfo.ReelParam;
MoveInfo.NewMove(MoveStep.T1_01_WaitReel);
MoveInfo.log($"放料完成");
T_Updown_Axis.AbsMove(MoveInfo, Config.UpdownAxis_P1, Config.UpdownAxis_P1_speed);
T_Pan_Axis.AbsMove(MoveInfo, Config.Pan_P1, Config.Pan_P1_speed);
T_TrayPos_Axis.AbsMove(MoveInfo, Config.TrayPos_P1, Config.TrayPos_P1_speed);
ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_21_EmptyIn_TrayDown);
break;
}
}
/// <summary>
/// 最后的料串中心点距离
/// </summary>
int Lastdistance = 0;
/// <summary>
/// 料串高度修正次数
/// </summary>
int TrayStringFixTimes = 0;
void ShelfInProcess()
{
if (CheckWait(ShelfInMoveInfo))
return;
switch (ShelfInMoveInfo.MoveStep)
{
case MoveStep.Shelf_EmptyIn_WaitWorkLeave:
Msg.add("等待空料串进入线体", MsgLevel.info);
if (IOValue(IO_T1_Type.T1_Lift_Tray_Check).Equals(IO_VALUE.HIGH))
{
ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_15_EmptyIn_LocationUp);
ShelfInMoveInfo.log("工位有料,提升准备");
}
else if (IOValue(IO_T1_Type.EmptyString_In_Check).Equals(IO_VALUE.HIGH))
{
ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_10_EmptyIn_StopDown);
ShelfInMoveInfo.log("工位无料,入口等待位有料,开始进入");
}
else if (IOValue(IO_T1_Type.Empty_LineIn_Check).Equals(IO_VALUE.HIGH))
{
ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_10_EmptyIn_Wait_StopDown);
ShelfInMoveInfo.log("工位无料,入口位有料,开始进入");
}
break;
case MoveStep.Shelf_10_EmptyIn_StopDown:
ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_10_EmptyIn_Wait_StopDown);
ShelfInMoveInfo.log("入料线体启动, 等待料串到等待位置");
IOMove(IO_T1_Type.EmptyString_In_Stop, IO_VALUE.HIGH, false, 2000);
ShelfInLine.LineRun("n", 999, "Shelf_10_EmptyIn_Wait_StopDown");
ShelfInMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_T1_Type.EmptyString_In_Check, IO_VALUE.HIGH));
break;
case MoveStep.Shelf_10_EmptyIn_Wait_StopDown:
if (IOValue(IO_T1_Type.T1_Lift_Tray_Check).Equals(IO_VALUE.LOW))
{
ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_11_EmptyIn_WaitTime);
ShelfInMoveInfo.log("入料线体启动, 等待料串到横移等待位置");
IOMove(IO_T1_Type.EmptyString_Wait_Stop, IO_VALUE.HIGH, false, 2000);
ShelfInLine.LineRun("n", 999, "Shelf_11_EmptyIn_WaitTime");
ShelfInMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_T1_Type.EmptyString_End_Check, IO_VALUE.HIGH));
}
break;
case MoveStep.Shelf_11_EmptyIn_WaitTime:
ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_11_EmptyIn_LiftUp);
ShelfInMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
break;
case MoveStep.Shelf_11_EmptyIn_LiftUp:
ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_13_EmptyIn_SidingRun);
ShelfInMoveInfo.log("入料线体停止, 横移顶升上升");
ShelfInLine.LineStop("n", "Shelf_13_EmptyIn_SidingRun");
CylinderMove(ShelfInMoveInfo, IO_T1_Type.EmptyString_Lift_Down, IO_T1_Type.EmptyString_Lift_Up, IO_VALUE.HIGH);
CylinderMove(ShelfInMoveInfo, IO_T1_Type.T1_Lift_Down, IO_T1_Type.T1_Lift_Up, IO_VALUE.HIGH);
break;
case MoveStep.Shelf_13_EmptyIn_SidingRun:
ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_14_EmptyIn_LiftDown);
ShelfInMoveInfo.log("横移到位, 停止横移");
IOMove(IO_T1_Type.T1_Sliding_Run, IO_VALUE.HIGH);
IOMove(IO_T1_Type.EmptyString_Sliding_Run, IO_VALUE.HIGH);
IOMove(IO_T1_Type.T1String_Sliding_Run, IO_VALUE.HIGH);
ShelfInMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_T1_Type.T1_Lift_Tray_Check, IO_VALUE.HIGH));
break;
case MoveStep.Shelf_14_EmptyIn_LiftDown:
ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_15_EmptyIn_LocationUp);
ShelfInMoveInfo.log("入横移顶升下降");
CylinderMove(ShelfInMoveInfo, IO_T1_Type.EmptyString_Lift_Down, IO_T1_Type.EmptyString_Lift_Up, IO_VALUE.LOW);
//CylinderMove(ShelfInMoveInfo, IO_T1_Type.T1_Lift_Down, IO_T1_Type.T1_Lift_Up, IO_VALUE.LOW);
break;
case MoveStep.Shelf_15_EmptyIn_LocationUp:
ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_16_EmptyIn_ForkFwd);
ShelfInMoveInfo.log("定位气缸上升");
LocationUp(ShelfInMoveInfo);
ShelfInMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
break;
case MoveStep.Shelf_16_EmptyIn_ForkFwd:
ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_19_EmptyIn_BatchUp);
ShelfOutMoveInfo.log("料架叉前进,横移皮带停止");
CylinderMove(ShelfOutMoveInfo, IO_T1_Type.Fork_Cylinder_Bck, IO_T1_Type.Fork_Cylinder_Fwd, IO_VALUE.HIGH);
IOMove(IO_T1_Type.T1_Sliding_Run, IO_VALUE.LOW);
IOMove(IO_T1_Type.EmptyString_Sliding_Run, IO_VALUE.LOW);
IOMove(IO_T1_Type.T1String_Sliding_Run, IO_VALUE.LOW);
break;
case MoveStep.Shelf_19_EmptyIn_BatchUp:
ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_17_EmptyIn_CheckLocation);
ShelfOutMoveInfo.log("T1 批量轴上升到P2");
TrayStringFixTimes = 0;
BatchAxisToP2(false);
break;
case MoveStep.Shelf_17_EmptyIn_CheckLocation:
ShelfOutMoveInfo.log("计算料串中心位置");
var (Bitmap, distance, debugstring) = GetStringCenter(true);
Lastdistance = distance;
TrayStringLocation?.Invoke(this, Bitmap);
if (Lastdistance > Config.String_Offset_Range_Px)
{
ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_18_EmptyIn_WaitManCheck);
}
else
{
ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_20_EmptyIn_ShelfReady);
}
break;
case MoveStep.Shelf_18_EmptyIn_WaitManCheck:
Msg.add("料串中心位置偏移, 请手动调整.", MsgLevel.warning);
if (IOValue(IO_T1_Type.Reset_BTN).Equals(IO_VALUE.HIGH))
{
ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_17_EmptyIn_CheckLocation);
}
break;
case MoveStep.Shelf_20_EmptyIn_ShelfReady: //等待料盘放入
Msg.add("料串准备完毕,等待放入料盘", MsgLevel.info);
break;
case MoveStep.Shelf_21_EmptyIn_TrayDown: //料盘放入后调用
var Height = ShelfInMoveInfo.ReelParam.PlateH + 3;
var currpos = T_Batch_Axis.GetAclPosition() - Config.BatchAxis_ChangeValue * Height;
if (currpos < Config.BatchAxis_P1 + Config.BatchAxis_ChangeValue * 20)
{
ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_Work_WaitShelfLeave);
ShelfOutMoveInfo.NewMove(MoveStep.Shelf_Out_Wait);
ShelfInMoveInfo.log($"批量轴已下降到底,料串已满,Left_Batch_P1={Config.BatchAxis_P1},needpos={currpos}");
}
//else if (TrayStringFixTimes < 3 && currpos < Config.BatchAxis_P1 + Config.BatchAxis_ChangeValue * 100)
//{
// ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_20_EmptyIn_ShelfReady);
// TrayStringFixTimes++;
// ShelfInMoveInfo.log($"批量轴已下降过半,重新提升料串 TrayStringFixTimes:{TrayStringFixTimes}");
// BatchAxisToP2(false);
//}
else
{
ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_20_EmptyIn_ShelfReady);
//T_Batch_Axis.AbsMove(ShelfInMoveInfo, currpos, Config.BatchAxis_P1_speed);
BatchAxisToP1();
ShelfInMoveInfo.log($"批量轴已下降一张料盘位置,等待料盘放入,needpos={currpos},{ShelfInMoveInfo.ReelParam.ToStr()}");
}
break;
case MoveStep.Shelf_Work_WaitShelfLeave:
if ((IOValue(IO_T1_Type.T1_Lift_Tray_Check).Equals(IO_VALUE.LOW)))
{
ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_EmptyIn_WaitWorkLeave);
}
Msg.add("料串已满等待空料串", MsgLevel.info);
break;
}
}
public bool ReleaseShelf()
{
if (MoveInfo.MoveStep != MoveStep.Shelf_20_EmptyIn_ShelfReady)
{
return false;
}
ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_Work_WaitShelfLeave);
ShelfOutMoveInfo.NewMove(MoveStep.Shelf_Out_Wait);
ShelfInMoveInfo.log($"用户强制释放料架");
return true;
}
void ShelfOutProcess()
{
if (CheckWait(ShelfOutMoveInfo))
return;
switch (ShelfOutMoveInfo.MoveStep)
{
case MoveStep.Shelf_Out_Wait:
if (IOValue(IO_T1_Type.T1_Lift_Tray_Check).Equals(IO_VALUE.LOW))
return;
if (IOValue(IO_T1_Type.T1_Out_Check).Equals(IO_VALUE.HIGH))
return;
ShelfOutMoveInfo.NextMoveStep(MoveStep.Shelf_30_Out_BatchDown);
ShelfOutMoveInfo.log("出口工位有料,出口等待位无料,开始送出");
break;
case MoveStep.Shelf_30_Out_BatchDown:
ShelfOutMoveInfo.NextMoveStep(MoveStep.Shelf_31_Out_ForkBck);
ShelfOutMoveInfo.log("批量轴下降到P1");
T_Batch_Axis.AbsMove(ShelfOutMoveInfo, Config.BatchAxis_P1, Config.BatchAxis_P1_speed);
break;
case MoveStep.Shelf_31_Out_ForkBck:
ShelfOutMoveInfo.NextMoveStep(MoveStep.Shelf_32_Out_LocationDown);
ShelfOutMoveInfo.log("料架叉后退");
CylinderMove(ShelfOutMoveInfo, IO_T1_Type.Fork_Cylinder_Bck, IO_T1_Type.Fork_Cylinder_Fwd, IO_VALUE.LOW);
break;
case MoveStep.Shelf_32_Out_LocationDown:
ShelfOutMoveInfo.NextMoveStep(MoveStep.Shelf_33_Out_OutStopDown);
ShelfOutMoveInfo.log("顶升工位下降");
CylinderMove(ShelfInMoveInfo, IO_T1_Type.T1_Lift_Down, IO_T1_Type.T1_Lift_Up, IO_VALUE.LOW);
break;
case MoveStep.Shelf_33_Out_OutStopDown:
ShelfOutMoveInfo.NextMoveStep(MoveStep.Shelf_34_Out_OutStopDown);
ShelfOutMoveInfo.log("顶升气缸下降");
LocationDown(ShelfOutMoveInfo);
break;
case MoveStep.Shelf_34_Out_OutStopDown:
ShelfOutMoveInfo.NextMoveStep(MoveStep.Shelf_35_Out_OutLineRun);
ShelfOutMoveInfo.log("阻挡气缸下降,链条运转");
//IOMove(IO_T1_Type.Line_Out_Run, IO_VALUE.HIGH);
ShelfOutLine.LineRun("n", 999, "Shelf_34_Out_OutLineRun");
ShelfOutMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_T1_Type.T1_Wait_Check, IO_VALUE.HIGH));
break;
case MoveStep.Shelf_35_Out_OutLineRun:
ShelfOutMoveInfo.NextMoveStep(MoveStep.Shelf_36_Out_OutLineRun);
IOMove(IO_T1_Type.T1_Wait_Stop, IO_VALUE.HIGH, false, 2000);
ShelfOutMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_T1_Type.T1_Out_Check, IO_VALUE.HIGH));
break;
case MoveStep.Shelf_36_Out_OutLineRun:
ShelfOutMoveInfo.EndMove();
ShelfOutLine.LineStop("n", "Shelf_35_Out_OutLineRun");
break;
}
}
void EmptyStringIN()
{
this.loginfo($"T1空料串入口感应到料串,EmptyString_In_Check:{IOValue(IO_T1_Type.EmptyString_In_Check)}");
//if (IOValue(IO_T1_Type.EmptyString_In_Check).Equals(IO_VALUE.HIGH))
// return;
//if (IOValue(IO_T1_Type.Empty_LineIn_Check).Equals(IO_VALUE.HIGH))
// return;
ShelfInLine.LineRun("EmptyStringIN", 30);
WaitIo(IO_T1_Type.Empty_LineIn_Check, IO_VALUE.HIGH, 10);
Thread.Sleep(2000);
ShelfInLine.LineStop("EmptyStringIN");
}
int StartMovePosition = 0;
void BatchAxisToP2(bool isFirstMove = true)
{
int targetP2 = Config.BatchAxis_P2;
int targetSpeed = Config.BatchAxis_P2_speed;
if (!isFirstMove)
{
int currPosition = T_Batch_Axis.GetAclPosition();
if (currPosition != -1)
{
//targetP2 = currPosition + Config.Right_Batch_ChangeValue * 80;
if (targetP2 > Config.BatchAxis_P2)
{
targetP2 = Config.BatchAxis_P2;
}
ShelfOutMoveInfo.log("BatchAxisToP2 目标P2: " + targetP2 + "(" + currPosition + ")");
}
//targetSpeed = Config.BatchAxis_P3Speed / 2;
}
ShelfOutMoveInfo.TimeOutSeconds = 200;
ShelfOutMoveInfo.CanWhileCount = 0;
// 需要增加定时器,获取验证信号并停止伺服
StartMovePosition = T_Batch_Axis.GetAclPosition();
ShelfOutMoveInfo.WaitList.Add(WaitResultInfo.WaitBatchAxisMove(Config.T_Batch_Axis, targetP2, targetSpeed));
Config.T_Batch_Axis.TargetPosition = targetP2;
T_Batch_Axis.AbsMove(null, targetP2, targetSpeed);
//开始检测信号
T_Batch_Axis.BatchAxisStartCheck(IO_T1_Type.T1_Tray_Check, Config, IO_VALUE.HIGH);
}
void BatchAxisToP1()
{
int targetP1 = Config.BatchAxis_P1;
int targetSpeed = Config.BatchAxis_P2_speed;
ShelfOutMoveInfo.TimeOutSeconds = 200;
ShelfOutMoveInfo.CanWhileCount = 0;
// 需要增加定时器,获取验证信号并停止伺服
StartMovePosition = T_Batch_Axis.GetAclPosition();
ShelfOutMoveInfo.WaitList.Add(WaitResultInfo.WaitBatchAxisMove(Config.T_Batch_Axis, targetP1, targetSpeed));
Config.T_Batch_Axis.TargetPosition = targetP1;
T_Batch_Axis.AbsMove(null, targetP1, targetSpeed);
//开始检测信号
T_Batch_Axis.BatchAxisStartCheck(IO_T1_Type.T1_Tray_Check, Config, IO_VALUE.LOW);
}
public (Bitmap, int, string) GetStringCenter(bool isFirst = false)
{
if (isFirst)
return GetStringCenterA();
else
return GetStringCenterB();
}
public (Bitmap, int, string) GetStringCenterA()
{
//return (null, 0, "调试屏蔽");
Bitmap bmap = Camera._cam.GrabOneImage(RobotManage.t1Machine.Config.String_Camera);
//Bitmap bmap = new Bitmap("D:\\853string\\Image_20210605142037637.bmp");
//pictureBox1.Image = (Bitmap)bmap.Clone();
Rectangle rect = new Rectangle(0, 0, bmap.Width, bmap.Height);
var bitmapData = bmap.LockBits(rect, ImageLockMode.ReadOnly, bmap.PixelFormat);
var eyemImage = new EyemImage();
eyemImage.ucpImage = bitmapData.Scan0;
eyemImage.iWidth = rect.Width;
eyemImage.iHeight = rect.Height;
eyemImage.iChannels = 1;
eyemImage.iDepth = 0;
//创建扫描区域
EyemRect eyemRect = new EyemRect();
eyemRect.iXs = Config.String_Center_X - 200;
eyemRect.iYs = Config.String_Center_Y - 200;
eyemRect.iWidth = 400;
eyemRect.iHeight = 400;
eyemlib.EyemOcsFXYR eyemOcsFXYR = new eyemlib.EyemOcsFXYR();
int result = eyemlib.eyemMulFuncTool(eyemImage, eyemRect, "__func1", 65, 75, ref eyemOcsFXYR, out _);
LogUtil.info($"eyemMulFuncTool:result:{result},fX:{eyemOcsFXYR.fX},fY:{eyemOcsFXYR.fY},fR:{eyemOcsFXYR.fR}");
var debugtxt = $"eyemMulFuncTool:\nresult:{result}\nfX:{eyemOcsFXYR.fX}\nfY:{eyemOcsFXYR.fY}\nfR:{eyemOcsFXYR.fR}";
bmap.UnlockBits(bitmapData);
var currpos = new Point((int)eyemOcsFXYR.fX, (int)eyemOcsFXYR.fY);
var centerpos = new Point(Config.String_Center_X, Config.String_Center_Y);
var distance = (int)Common.distance(centerpos, currpos);
Bitmap bitmap = new Bitmap(bmap.Width, bmap.Height);
Graphics graphics = Graphics.FromImage(bitmap);
graphics.DrawImage(bmap, new PointF(0, 0));
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
Pen greenpen = new Pen(Color.Green, 15);
int r = 102;
graphics.DrawEllipse(greenpen, Config.String_Center_X - r, Config.String_Center_Y - r, r * 2, r * 2);
graphics.DrawEllipse(greenpen, Config.String_Center_X - 8, Config.String_Center_Y - 8, 8 * 2, 8 * 2);
Pen redpen = new Pen(Color.FromArgb(255, Color.Red), 10);
graphics.DrawEllipse(redpen, eyemOcsFXYR.fX - eyemOcsFXYR.fR, eyemOcsFXYR.fY - eyemOcsFXYR.fR, eyemOcsFXYR.fR * 2, eyemOcsFXYR.fR * 2);
graphics.DrawEllipse(redpen, eyemOcsFXYR.fX - 5, eyemOcsFXYR.fY - 5, 5 * 2, 5 * 2);
var rectx = Config.String_Center_X - 500;
var recty = Config.String_Center_Y - 500;
SolidBrush blue = new SolidBrush(Color.BlueViolet);
Font font = new Font(FontFamily.GenericSansSerif, 30);
graphics.DrawString($"center:X:{Config.String_Center_X},Y:{Config.String_Center_Y}", font, blue, rectx, recty);
graphics.DrawString($"result:{result},fX:{eyemOcsFXYR.fX},fY:{eyemOcsFXYR.fY},fR:{eyemOcsFXYR.fR}", font, blue, rectx, font.Height + recty);
graphics.DrawString($"distance:{distance}", font, blue, rectx, font.Height * 2 + recty);
graphics.Save();
bmap.Dispose();
graphics.Dispose();
Bitmap newbitmap = bitmap.Clone(new Rectangle(rectx, recty, 1000, 1000), PixelFormat.Format24bppRgb);
bitmap.Dispose();
Directory.CreateDirectory("\\image\\TrayString\\");
newbitmap.Save("\\image\\TrayString\\" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".jpg", ImageFormat.Jpeg);
return (newbitmap, distance, debugtxt);
}
public (Bitmap, int, string) GetStringCenterB()
{
//return (null, 0, "调试屏蔽");
var centerpos = new Point(Config.String_Center_X, Config.String_Center_Y);
Bitmap bmap = Camera._cam.GrabOneImage(RobotManage.t1Machine.Config.String_Camera);
Bitmap newbitmap = new Bitmap(640, 640);
Graphics g = Graphics.FromImage(newbitmap);
Rectangle rectangle = new Rectangle(centerpos.X - newbitmap.Width / 2, centerpos.Y - newbitmap.Height / 2, newbitmap.Width, newbitmap.Height);
g.DrawImage(bmap, rectangle);
g.Save();g.Dispose();
string filename = "\\image\\TrayString\\" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".jpg";
newbitmap.Save(filename, ImageFormat.Jpeg);
//newbitmap.Dispose();
bmap.Dispose();
float fx = 0, fy = 0;
int r = centerDetector(filename, ref fx, ref fy);
LogUtil.info($"centerDetector r:{r},x:{fx},y:{fy}");
var debugtxt = $"centerDetector:\nresult:{r}\nfX:{fx}\nfY:{fy}";
var currpos = new Point((int)fx+ rectangle.X, (int)fy+ rectangle.Y);
var distance = (int)Common.distance(centerpos, currpos);
return (newbitmap, distance, debugtxt);
}
[DllImport("yolov5.dll", CharSet = CharSet.None)]
public static extern int centerDetector([MarshalAs(UnmanagedType.LPStr)] string filename, ref float x, ref float y);
}
}