BoxEquip_AutoFindPos.cs
7.8 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
using CodeLibrary;
using HuichuanLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms.VisualStyles;
using static eyemLib_Sharp.EyemLibDemo;
namespace OnlineStore.DeviceLibrary
{
public partial class BoxEquip
{
//public Dictionary<string, List<DrawerInfo>> DrawerNums = new Dictionary<string, List<DrawerInfo>>();
AutoFindPos autoFindPos;
private bool autoFindPosMode = false;
private void InitDrawInfos()
{
autoFindPos = new AutoFindPos(Config);
//DrawerNums.Add("A", new List<DrawerInfo>());
//DrawerNums.Add("B", new List<DrawerInfo>());
//List<DrawerPosition> drawerPositions = CSVPositionReader<DrawerPosition>.getPositionList();
//foreach (DrawerPosition position in drawerPositions)
//{
// if (position.StoreId.Equals(DeviceID))
// {
// DrawerNums[PosSide(position.PositionNum)].Add(new DrawerInfo(position.PositionNum,PositionNumList));
// }
//}
}
/// <summary>
/// 获取抽屉/仓位所在面
/// </summary>
/// <param name="pos">位置</param>
/// <returns></returns>
private string PosSide(string pos)
{
if (pos.Substring(2, 2).Equals("AA")) return "A";
else if (pos.Substring(2, 2).Equals("BB")) return "B";
return "";
}
/// <summary>
/// 获取轴的负限位
/// </summary>
/// <param name="axisNo"></param>
/// <returns></returns>
public bool GetAxisNelSts(short axisNo)
{
AxisSts sts = HCBoardManager.GetAxisSts(axisNo);
return sts.NEL == 1;
}
/// <summary>
/// 获取轴的正限位
/// </summary>
/// <param name="axisNo"></param>
/// <returns></returns>
public bool GetAxisPelSts(short axisNo)
{
AxisSts sts = HCBoardManager.GetAxisSts(axisNo);
return sts.PEL == 1;
}
public void AutoFindPosProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait(MoveInfo);
}
if (MoveInfo.IsInWait)
{
return;
}
switch(MoveInfo.MoveStep)
{
case StepEnum.SA_Drawer_Start_Find_Pos:
MoveInfo.NextMoveStep(StepEnum.SA_01_To_Drawer_StartPoint);
LogInfo($"存储机构-视觉对位 {MoveInfo.SLog}:到抽屉起始点," +
$"行走机构到进出料机构取放点P2,移栽升降轴到上暂存区取料低点P3/P9,移栽压紧轴到压紧前点P2,移栽旋转轴到进出料暂存区取放料水平点P2[{MoveInfo.MoveParam.PosInfo.PosSide}面]");
MoveAxis.AbsMove(MoveInfo, Config.MoveAxis_P2, Config.MoveAxis_P2_Speed);
break;
case StepEnum.SA_01_To_Drawer_StartPoint:
break;
case StepEnum.SA_02_Pos_AcqImg:
break;
case StepEnum.SA_03_Pos_AdjPos:
break;
case StepEnum.SA_04_Pos_NextDrawer:
break;
case StepEnum.SA_05_Neg_AcqImg:
break;
case StepEnum.SA_06_Neg_AdjPos:
break;
case StepEnum.SA_07_Neg_NextDrawer:
break;
//case StepEnum.:
// //如果行>抽屉行数,直接退出。否则获取图片、得到mark的坐标,并与模板坐标比较。根据误差范围外对行走机构和移栽升降轴移动
// //在误差范围内,保存该位置脉冲同时生成库位位置信息。列加1进行第二步
// break;
//case StepEnum.:
// //如果列>抽屉列数,判断行是否大于抽屉的行数?大于则结束;否则行加1,移栽升降轴运动,到第三步
// //否则行走机构移动一个行间距的距离,到第一步
// break;
//case StepEnum.:
// //如果行>抽屉行数,直接退出。否则获取图片、得到mark的坐标,并与模板坐标比较。根据误差范围外对行走机构和移栽升降轴移动
// //在误差范围内,保存该位置脉冲同时生成库位位置信息。列减1进行第四步
// break;
//case StepEnum.:
// //如果列《1,判断行是否大于抽屉的行数?大于则结束;否则行加1,移栽升降轴运动,到第一步
// //否则行走机构移动一个行间距的距离,到第三步
// break;
//case StepEnum.:
// break;
}
}
}
public class AutoFindPos
{
/// <summary>
/// 当前行
/// </summary>
public int CurRow { get; set; } = 1;
/// <summary>
/// 当前行脉冲
/// </summary>
public int CurRowPulse { get; set; } = 0;
/// <summary>
/// 当前列脉冲
/// </summary>
public int CurColumnPulse { get; set; } = 0;
/// <summary>
/// 坐标到脉冲的转换系数
/// </summary>
public float CoeffOfCoorToPulse { get; set; } = 1;
/// <summary>
/// 当前列
/// </summary>
public int CurColumn { get; set; } = 1;
/// <summary>
/// 抽屉行数
/// </summary>
public int Rows { get; private set; }
/// <summary>
/// 抽屉列数
/// </summary>
public int Columns { get; private set; }
/// <summary>
/// 抽屉间行间距
/// </summary>
public int Row_Spacing { get; private set; }
/// <summary>
/// 抽屉间列间距
/// </summary>
public int Column_Spacing { get; private set; }
public AutoFindPos(BoxEquip_Config boxEquip_Config)
{
Row_Spacing = boxEquip_Config.Row_Spacing;
Column_Spacing = boxEquip_Config.Column_Spacing;
Rows = boxEquip_Config.Drawer_Rows;
Columns = boxEquip_Config.Drawer_Columns;
}
/// <summary>
/// Mark点坐标信息
/// </summary>
/// <param name="bitmap">输入图片</param>
/// <param name="markCoor">mark点坐标信息</param>
/// <returns>0 正常 -4未定位到 </returns>
public static int GetMarkInfo(Bitmap bitmap,out EyemOcsFXYR markCoor)
{
int flag;
markCoor = new EyemOcsFXYR();
EyemImage image = eyemCvtToEyemImage(bitmap);
flag = eyemMarkerTracing(image, 130, ref markCoor);
Marshal.FreeHGlobal(image.vpImage);
return flag;
}
}
public class DrawerInfo
{
/// <summary>
/// 抽屉信息
/// </summary>
/// <param name="pos">抽屉位置</param>
/// <param name="posNums">仓位列表</param>
public DrawerInfo(string pos, List<string> posNums)
{
PositionNum = pos;
Positions = posNums.FindAll(s => s.StartsWith(pos));
}
/// <summary>
/// 抽屉位置
/// </summary>
public string PositionNum { get; private set; }
/// <summary>
/// 抽屉内的仓位位置
/// </summary>
public List<string> Positions { get; private set; }
}
}