|
|
@@ -1279,8 +1279,8 @@ namespace TeamAAS_VP.Core
|
|
|
float toolX = (float)(visionResults[0].X + visionResults[1].X) / 2;
|
|
|
float toolY = (float)(visionResults[0].Y + visionResults[1].Y) / 2;
|
|
|
_FixedUpCameraAngle = Common.CalculateAngleBetweenPointsDegrees(new PointF((float)visionResults[0].X, (float)visionResults[0].Y), new PointF((float)visionResults[1].X, (float)visionResults[1].Y));
|
|
|
- DowmCameraResults[cameraIndex] = new OpenCvSharp.Point3f(toolX, toolX, (float)_FixedUpCameraAngle);
|
|
|
- DownTool = new PointF(toolX, toolX);
|
|
|
+ DowmCameraResults[cameraIndex] = new OpenCvSharp.Point3f(toolX, toolY, (float)_FixedUpCameraAngle);
|
|
|
+ DownTool = new PointF(toolX, toolY);
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)1);
|
|
|
return;
|
|
|
}
|
|
|
@@ -1375,8 +1375,8 @@ namespace TeamAAS_VP.Core
|
|
|
float toolX = (float)(visionResults[0].X + visionResults[1].X) / 2;
|
|
|
float toolY = (float)(visionResults[0].Y + visionResults[1].Y) / 2;
|
|
|
_FixedUpCameraAngle = Common.CalculateAngleBetweenPointsDegrees(new PointF((float)visionResults[0].X, (float)visionResults[0].Y), new PointF((float)visionResults[1].X, (float)visionResults[1].Y));
|
|
|
- DowmCameraResults[cameraIndex] = new OpenCvSharp.Point3f(toolX, toolX, (float)_FixedUpCameraAngle);
|
|
|
- DownTool = new PointF(toolX, toolX);
|
|
|
+ DowmCameraResults[cameraIndex] = new OpenCvSharp.Point3f(toolX, toolY, (float)_FixedUpCameraAngle);
|
|
|
+ DownTool = new PointF(toolX, toolY);
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)1);
|
|
|
return;
|
|
|
}
|
|
|
@@ -1495,7 +1495,7 @@ namespace TeamAAS_VP.Core
|
|
|
if (robot == null)
|
|
|
{
|
|
|
SendTaskMessage($"未找到机器人,无法执行上相机锁附/组装拍照视觉任务", MessageLevel.Alarm);
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)2);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_UpCameraPickStatus.Address, (Int16)2);
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
@@ -1567,7 +1567,7 @@ namespace TeamAAS_VP.Core
|
|
|
{
|
|
|
float tool1X = (float)(visionResults[0].X - visionResults[0].X);
|
|
|
float tool1Y = (float)(visionResults[0].Y - visionResults[0].Y);
|
|
|
- float tool2X = (float)(visionResults[1].Y - visionResults[1].Y);
|
|
|
+ float tool2X = (float)(visionResults[1].X - visionResults[1].X);
|
|
|
float tool2Y = (float)(visionResults[1].Y - visionResults[1].Y);
|
|
|
float toolX = (tool1X + tool2X) / 2;
|
|
|
float toolY = (tool1Y + tool2Y) / 2;
|
|
|
@@ -1730,7 +1730,7 @@ namespace TeamAAS_VP.Core
|
|
|
{
|
|
|
SendTaskMessage($"触发上相机检测拍照...", MessageLevel.Debug);
|
|
|
//相机的编号
|
|
|
- //Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.Out_UPCameracheckNum.Address);
|
|
|
+ Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.Out_UPCameracheckNum.Address);
|
|
|
|
|
|
if (isDryMode)
|
|
|
{
|
|
|
@@ -1738,6 +1738,37 @@ namespace TeamAAS_VP.Core
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ //视觉流程ID
|
|
|
+ Guid procedureId = Guid.Empty;
|
|
|
+ //获取锁付拍照的点位
|
|
|
+ var pos = currentProduct.CheckCameraPoints.FirstOrDefault(p => p.Number == cameraIndex);
|
|
|
+ if (pos != null)
|
|
|
+ {
|
|
|
+ procedureId = pos.VisionProcessID;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取流程
|
|
|
+ var process = _productService.GetCurrentProductProcedureModelById(procedureId);
|
|
|
+ if (process == null)
|
|
|
+ {
|
|
|
+ SendTaskMessage(string.Format("未找到点位:{0}的视觉流程:{1}", cameraIndex, procedureId), MessageLevel.Alarm);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_UPCameracheckStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 执行视觉任务
|
|
|
+ var _cts = new CancellationTokenSource();
|
|
|
+ var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(process, null, null, _cts.Token, cameraIndex, null);
|
|
|
+ if (visionResult.IsSucceed)
|
|
|
+ {
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_UPCameracheckStatus.Address, (Int16)1);
|
|
|
+ SendTaskMessage($"点位{cameraIndex}检测OK", MessageLevel.Debug);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_UPCameracheckStatus.Address, (Int16)2);
|
|
|
+ SendTaskMessage($"点位{cameraIndex}检测NG", MessageLevel.Error);
|
|
|
+ }
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_UPCameracheckStatus.Address, (Int16)1);
|
|
|
}
|
|
|
else
|
|
|
@@ -1767,11 +1798,66 @@ namespace TeamAAS_VP.Core
|
|
|
//相机的编号
|
|
|
//Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.In_FixedCameraPickNum.Address);
|
|
|
|
|
|
+ if (currentProduct.IndependentCamer1AuxProcedureId == Guid.Empty)
|
|
|
+ {
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (currentProduct.IndependentCamer2AuxProcedureId == Guid.Empty)
|
|
|
+ {
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (currentProduct.IndependentCamer3AuxProcedureId == Guid.Empty)
|
|
|
+ {
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (currentProduct.IndependentCamer4AuxProcedureId == Guid.Empty)
|
|
|
+ {
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取四个独立相机的流程id
|
|
|
+ var process1 = _productService.GetCurrentProductProcedureModelById(currentProduct.IndependentCamer1AuxProcedureId);
|
|
|
+ var process2 = _productService.GetCurrentProductProcedureModelById(currentProduct.IndependentCamer2AuxProcedureId);
|
|
|
+ var process3 = _productService.GetCurrentProductProcedureModelById(currentProduct.IndependentCamer3AuxProcedureId);
|
|
|
+ var process4 = _productService.GetCurrentProductProcedureModelById(currentProduct.IndependentCamer4AuxProcedureId);
|
|
|
+
|
|
|
+ // 执行视觉任务
|
|
|
+ var _cts = new CancellationTokenSource();
|
|
|
+ var task1 = _remoteCommandService.ExecutePhotoGetSinglePoint(process1, null, null, _cts.Token, 1, null);
|
|
|
+ var task2 = _remoteCommandService.ExecutePhotoGetSinglePoint(process2, null, null, _cts.Token, 2, null);
|
|
|
+ var task3 = _remoteCommandService.ExecutePhotoGetSinglePoint(process3, null, null, _cts.Token, 3, null);
|
|
|
+ var task4 = _remoteCommandService.ExecutePhotoGetSinglePoint(process4, null, null, _cts.Token, 4, null);
|
|
|
+
|
|
|
+ var visionResults = await Task.WhenAll(task1, task2, task3, task4);
|
|
|
if (isDryMode)
|
|
|
{
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)1);
|
|
|
return;
|
|
|
}
|
|
|
+ if (visionResults[0].IsSucceed && visionResults[1].IsSucceed && visionResults[2].IsSucceed && visionResults[3].IsSucceed)
|
|
|
+ {
|
|
|
+
|
|
|
+ Vector<double> p1 = Vector<double>.Build.Dense(new double[] { visionResults[1].X, visionResults[1].Y });
|
|
|
+ Vector<double> p2 = Vector<double>.Build.Dense(new double[] { visionResults[2].X, visionResults[2].Y });
|
|
|
+ Vector<double> p3 = Vector<double>.Build.Dense(new double[] { visionResults[3].X, visionResults[3].Y });
|
|
|
+ Vector<double> p4 = Vector<double>.Build.Dense(new double[] { visionResults[0].X, visionResults[0].Y });
|
|
|
+
|
|
|
+ var center = RectangleCenterCalculator.CalculateByPCAWithKnownOrder(new List<Vector<double>> { p1, p2, p3, p4 });
|
|
|
+ UpCameraPutResults[1].X = (float)center.Center[0];
|
|
|
+ UpCameraPutResults[1].Y = (float)center.Center[1];
|
|
|
+ UpCameraPutResults[1].Z = (float)center.MajorAxisAngle;
|
|
|
+ SendTaskMessage($"LCD拍照结果:X={UpCameraPutResults[1].X},Y={UpCameraPutResults[1].Y},Angle={UpCameraPutResults[1].Z}", MessageLevel.Info);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)1);
|
|
|
}
|
|
|
@@ -1890,32 +1976,32 @@ namespace TeamAAS_VP.Core
|
|
|
//相机的编号
|
|
|
//Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.In_FixedCameracheckNum.Address);
|
|
|
|
|
|
- if (currentProduct.IndependentCamer1AuxProcedureId == Guid.Empty)
|
|
|
+ if (currentProduct.IndependentCamer1CheckProcedureId == Guid.Empty)
|
|
|
{
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameracheckStatus.Address, (Int16)2);
|
|
|
return;
|
|
|
}
|
|
|
- if (currentProduct.IndependentCamer2AuxProcedureId == Guid.Empty)
|
|
|
+ if (currentProduct.IndependentCamer2CheckProcedureId == Guid.Empty)
|
|
|
{
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameracheckStatus.Address, (Int16)2);
|
|
|
return;
|
|
|
}
|
|
|
- if (currentProduct.IndependentCamer3AuxProcedureId == Guid.Empty)
|
|
|
+ if (currentProduct.IndependentCamer3CheckProcedureId == Guid.Empty)
|
|
|
{
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameracheckStatus.Address, (Int16)2);
|
|
|
return;
|
|
|
}
|
|
|
- if (currentProduct.IndependentCamer4AuxProcedureId == Guid.Empty)
|
|
|
+ if (currentProduct.IndependentCamer4CheckProcedureId == Guid.Empty)
|
|
|
{
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameracheckStatus.Address, (Int16)2);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
//获取四个独立相机的流程id
|
|
|
- var process1 = _productService.GetCurrentProductProcedureModelById(currentProduct.IndependentCamer1AuxProcedureId);
|
|
|
- var process2 = _productService.GetCurrentProductProcedureModelById(currentProduct.IndependentCamer2AuxProcedureId);
|
|
|
- var process3 = _productService.GetCurrentProductProcedureModelById(currentProduct.IndependentCamer3AuxProcedureId);
|
|
|
- var process4 = _productService.GetCurrentProductProcedureModelById(currentProduct.IndependentCamer4AuxProcedureId);
|
|
|
+ var process1 = _productService.GetCurrentProductProcedureModelById(currentProduct.IndependentCamer1CheckProcedureId);
|
|
|
+ var process2 = _productService.GetCurrentProductProcedureModelById(currentProduct.IndependentCamer2CheckProcedureId);
|
|
|
+ var process3 = _productService.GetCurrentProductProcedureModelById(currentProduct.IndependentCamer3CheckProcedureId);
|
|
|
+ var process4 = _productService.GetCurrentProductProcedureModelById(currentProduct.IndependentCamer4CheckProcedureId);
|
|
|
|
|
|
// 执行视觉任务
|
|
|
var _cts = new CancellationTokenSource();
|
|
|
@@ -1932,26 +2018,16 @@ namespace TeamAAS_VP.Core
|
|
|
}
|
|
|
if (visionResults[0].IsSucceed && visionResults[1].IsSucceed && visionResults[2].IsSucceed && visionResults[3].IsSucceed)
|
|
|
{
|
|
|
-
|
|
|
- Vector<double> p1 = Vector<double>.Build.Dense(new double[] { visionResults[1].X, visionResults[1].Y });
|
|
|
- Vector<double> p2 = Vector<double>.Build.Dense(new double[] { visionResults[2].X, visionResults[2].Y });
|
|
|
- Vector<double> p3 = Vector<double>.Build.Dense(new double[] { visionResults[3].X, visionResults[3].Y });
|
|
|
- Vector<double> p4 = Vector<double>.Build.Dense(new double[] { visionResults[0].X, visionResults[0].Y });
|
|
|
-
|
|
|
- var center = RectangleCenterCalculator.CalculateByPCAWithKnownOrder(new List<Vector<double>> { p1, p2, p3, p4 });
|
|
|
- UpCameraPutResults[1].X = (float)center.Center[0];
|
|
|
- UpCameraPutResults[1].Y = (float)center.Center[1];
|
|
|
- UpCameraPutResults[1].Z = (float)center.MajorAxisAngle;
|
|
|
- SendTaskMessage($"LCD拍照结果:X={UpCameraPutResults[1].X},Y={UpCameraPutResults[1].Y},Angle={UpCameraPutResults[1].Z}", MessageLevel.Info);
|
|
|
+ SendTaskMessage($"固定相机检测OK", MessageLevel.Debug);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_FixedCameracheckStatus.Address, (Int16)1);
|
|
|
+ return;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
-
|
|
|
+ SendTaskMessage($"固定相机检测NG", MessageLevel.Error);
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameracheckStatus.Address, (Int16)2);
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_FixedCameracheckStatus.Address, (Int16)1);
|
|
|
}
|
|
|
else
|
|
|
{
|