|
|
@@ -1031,6 +1031,7 @@ namespace TeamAAS_VP.Core
|
|
|
|
|
|
PointF[] DowmCameraResults= new PointF[10];
|
|
|
PointF[] UpCameraPutResults = new PointF[10];
|
|
|
+ PointF DownTool = new PointF();
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -1076,15 +1077,6 @@ namespace TeamAAS_VP.Core
|
|
|
Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.In_DowmCameraNum.Address);
|
|
|
SendTaskMessage($"编号:{cameraIndex}", MessageLevel.Info);
|
|
|
|
|
|
- // 获取流程
|
|
|
- var process = _productService.GetCurrentProductProcedureModelById(currentProduct.FixedUpCamera1ProcedureId);
|
|
|
- if (process == null)
|
|
|
- {
|
|
|
- SendTaskMessage($"固定向上相机1视觉流程,流程ID:{currentProduct.FixedUpCamera1ProcedureId}", MessageLevel.Alarm);
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)2);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
// 获取机器人当前坐标
|
|
|
var robot = _robotService.GetAllRobots().FirstOrDefault();
|
|
|
if (robot == null)
|
|
|
@@ -1096,21 +1088,177 @@ namespace TeamAAS_VP.Core
|
|
|
}
|
|
|
var currentPosition = robot.GetRobotPos();
|
|
|
|
|
|
- // 执行视觉任务
|
|
|
- var _cts = new CancellationTokenSource();
|
|
|
- var visionResult =await _remoteCommandService.ExecutePhotoGetSinglePoint(process, null,null, _cts.Token);
|
|
|
- if (visionResult.IsSucceed)
|
|
|
+ //如果下相机拍照的次数是1,则判断用时拍照的相机是几个
|
|
|
+ int downCameraNum = _configService.GetSystemConfiguration().DowmCameraNum;
|
|
|
+ if (downCameraNum==1)
|
|
|
{
|
|
|
- //披头偏差
|
|
|
- float offsetX = (float)(visionResult.X - currentPosition.X);
|
|
|
- float offsetY = (float)(visionResult.Y - currentPosition.Y);
|
|
|
+ //如果下相机2的流程id为空,则表示只有一个下相机
|
|
|
+ if (currentProduct.FixedUpCamera2ProcedureId==Guid.Empty)
|
|
|
+ {
|
|
|
+ //获取固定向上相机1的流程
|
|
|
+ var process = _productService.GetCurrentProductProcedureModelById(currentProduct.FixedUpCamera1ProcedureId);
|
|
|
+ if (process == null)
|
|
|
+ {
|
|
|
+ SendTaskMessage($"固定向上相机1视觉流程,流程ID:{currentProduct.FixedUpCamera1ProcedureId}", MessageLevel.Alarm);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 执行视觉任务
|
|
|
+ var _cts = new CancellationTokenSource();
|
|
|
+ var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(process, null, new double[] { currentPosition .X, currentPosition .Y, currentPosition .U}, _cts.Token);
|
|
|
+ if (visionResult.IsSucceed)
|
|
|
+ {
|
|
|
+ float toolX = (float)(visionResult.X - currentPosition.X);
|
|
|
+ float toolY = (float)(visionResult.Y - currentPosition.Y);
|
|
|
|
|
|
- DowmCameraResults[cameraIndex] = new PointF(offsetX, offsetY);
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)1);
|
|
|
- return;
|
|
|
+ DowmCameraResults[cameraIndex] = new PointF(toolX, toolX);
|
|
|
+ DownTool= new PointF(toolX, toolX);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //获取固定向上相机1的流程
|
|
|
+ var process1 = _productService.GetCurrentProductProcedureModelById(currentProduct.FixedUpCamera1ProcedureId);
|
|
|
+ if (process1 == null)
|
|
|
+ {
|
|
|
+ SendTaskMessage($"固定向上相机1视觉流程,流程ID:{currentProduct.FixedUpCamera1ProcedureId}", MessageLevel.Alarm);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //获取固定向上相机2的流程
|
|
|
+ var process2 = _productService.GetCurrentProductProcedureModelById(currentProduct.FixedUpCamera2ProcedureId);
|
|
|
+ if (process2 == null)
|
|
|
+ {
|
|
|
+ SendTaskMessage($"固定向上相机1视觉流程,流程ID:{currentProduct.FixedUpCamera2ProcedureId}", MessageLevel.Alarm);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 执行视觉任务
|
|
|
+ var _cts = new CancellationTokenSource();
|
|
|
+ var task1= _remoteCommandService.ExecutePhotoGetSinglePoint(process1, null, new double[] { currentPosition.X, currentPosition.Y, currentPosition.U }, _cts.Token);
|
|
|
+ var task2= _remoteCommandService.ExecutePhotoGetSinglePoint(process2, null, new double[] { currentPosition.X, currentPosition.Y, currentPosition.U }, _cts.Token);
|
|
|
+ var visionResults= await Task.WhenAll(task1, task2);
|
|
|
+ if (visionResults[0].IsSucceed && visionResults[1].IsSucceed)
|
|
|
+ {
|
|
|
+ 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 tool2Y = (float)(visionResults[1].Y - visionResults[1].Y);
|
|
|
+ float toolX = (tool1X + tool2X) / 2;
|
|
|
+ float toolY = (tool1Y + tool2Y) / 2;
|
|
|
+
|
|
|
+ DowmCameraResults[cameraIndex] = new PointF(toolX, toolX);
|
|
|
+ DownTool = new PointF(toolX, toolX);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (downCameraNum == 2)
|
|
|
+ {
|
|
|
+ //如果下相机2的流程id为空,则表示只有一个下相机
|
|
|
+ if (currentProduct.FixedUpCamera2ProcedureId == Guid.Empty)
|
|
|
+ {
|
|
|
+ //获取固定向上相机1的流程
|
|
|
+ //var process = _productService.GetCurrentProductProcedureModelById(currentProduct.FixedUpCamera1ProcedureId);
|
|
|
+ //if (process == null)
|
|
|
+ //{
|
|
|
+ // SendTaskMessage($"固定向上相机1视觉流程,流程ID:{currentProduct.FixedUpCamera1ProcedureId}", MessageLevel.Alarm);
|
|
|
+ // await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)2);
|
|
|
+ // return;
|
|
|
+ //}
|
|
|
+ //// 执行视觉任务
|
|
|
+ //var _cts = new CancellationTokenSource();
|
|
|
+ //var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(process, null, new double[] { currentPosition.X, currentPosition.Y, currentPosition.U }, _cts.Token);
|
|
|
+ //if (visionResult.IsSucceed)
|
|
|
+ //{
|
|
|
+ // float toolX = (float)(visionResult.X - currentPosition.X);
|
|
|
+ // float toolY = (float)(visionResult.Y - currentPosition.Y);
|
|
|
+
|
|
|
+ // DowmCameraResults[cameraIndex] = new PointF(toolX, toolX);
|
|
|
+
|
|
|
+ // if (cameraIndex == downCameraNum)
|
|
|
+ // {
|
|
|
+ // //求取多个DowmCameraResults的中心点
|
|
|
+
|
|
|
+
|
|
|
+ // DownTool = new PointF(toolX, toolX);
|
|
|
+ // }
|
|
|
+
|
|
|
+ // await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)1);
|
|
|
+ // return;
|
|
|
+ //}
|
|
|
+ //else
|
|
|
+ //{
|
|
|
+ // await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)2);
|
|
|
+ // return;
|
|
|
+ //}
|
|
|
+
|
|
|
+ //暂时没有应用场景,不支持
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //获取固定向上相机1的流程
|
|
|
+ var process1 = _productService.GetCurrentProductProcedureModelById(currentProduct.FixedUpCamera1ProcedureId);
|
|
|
+ if (process1 == null)
|
|
|
+ {
|
|
|
+ SendTaskMessage($"固定向上相机1视觉流程,流程ID:{currentProduct.FixedUpCamera1ProcedureId}", MessageLevel.Alarm);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //获取固定向上相机2的流程
|
|
|
+ var process2 = _productService.GetCurrentProductProcedureModelById(currentProduct.FixedUpCamera2ProcedureId);
|
|
|
+ if (process2 == null)
|
|
|
+ {
|
|
|
+ SendTaskMessage($"固定向上相机1视觉流程,流程ID:{currentProduct.FixedUpCamera2ProcedureId}", MessageLevel.Alarm);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 执行视觉任务
|
|
|
+ var _cts = new CancellationTokenSource();
|
|
|
+ var task1 = _remoteCommandService.ExecutePhotoGetSinglePoint(process1, null, new double[] { currentPosition.X, currentPosition.Y, currentPosition.U }, _cts.Token);
|
|
|
+ var task2 = _remoteCommandService.ExecutePhotoGetSinglePoint(process2, null, new double[] { currentPosition.X, currentPosition.Y, currentPosition.U }, _cts.Token);
|
|
|
+ var visionResults = await Task.WhenAll(task1, task2);
|
|
|
+ if (visionResults[0].IsSucceed && visionResults[1].IsSucceed)
|
|
|
+ {
|
|
|
+ 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 tool2Y = (float)(visionResults[1].Y - visionResults[1].Y);
|
|
|
+ float toolX = (tool1X + tool2X) / 2;
|
|
|
+ float toolY = (tool1X + tool2X) / 2;
|
|
|
+
|
|
|
+ DowmCameraResults[cameraIndex] = new PointF(toolX, toolX);
|
|
|
+ DownTool = new PointF((DowmCameraResults[1].X + DowmCameraResults[2].X) / 2, (DowmCameraResults[1].Y + DowmCameraResults[2].Y) / 2);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ //暂时没有应用场景,不支持
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)2);
|
|
|
return;
|
|
|
}
|
|
|
@@ -1135,43 +1283,43 @@ namespace TeamAAS_VP.Core
|
|
|
SendTaskMessage($"编号:{cameraIndex}", MessageLevel.Info);
|
|
|
|
|
|
// 获取流程
|
|
|
- var process = _productService.GetCurrentProductProcedureModelById(currentProduct.FixedUpCamera1ProcedureId);
|
|
|
- if (process == null)
|
|
|
- {
|
|
|
- SendTaskMessage($"固定向上相机1视觉流程,流程ID:{currentProduct.FixedUpCamera1ProcedureId}", MessageLevel.Alarm);
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_ScrewTeachOk.Address, (Int16)2);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 获取机器人当前坐标
|
|
|
- var robot = _robotService.GetAllRobots().FirstOrDefault();
|
|
|
- if (robot == null)
|
|
|
- {
|
|
|
- SendTaskMessage($"未找到机器人,无法执行上相机锁附/组装拍照视觉任务", MessageLevel.Alarm);
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_ScrewTeachOk.Address, (Int16)2);
|
|
|
- return;
|
|
|
-
|
|
|
- }
|
|
|
- var currentPosition = robot.GetRobotPos();
|
|
|
-
|
|
|
- // 执行视觉任务
|
|
|
- var _cts = new CancellationTokenSource();
|
|
|
- var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(process, null, null, _cts.Token);
|
|
|
- if (visionResult.IsSucceed)
|
|
|
- {
|
|
|
- //披头偏差
|
|
|
- float offsetX = (float)(visionResult.X - currentPosition.X);
|
|
|
- float offsetY = (float)(visionResult.Y - currentPosition.Y);
|
|
|
-
|
|
|
- DowmCameraResults[cameraIndex] = new PointF(offsetX, offsetY);
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_ScrewTeachOk.Address, (Int16)1);
|
|
|
- return;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_ScrewTeachOk.Address, (Int16)2);
|
|
|
- return;
|
|
|
- }
|
|
|
+ //var process = _productService.GetCurrentProductProcedureModelById(currentProduct.FixedUpCamera1ProcedureId);
|
|
|
+ //if (process == null)
|
|
|
+ //{
|
|
|
+ // SendTaskMessage($"固定向上相机1视觉流程,流程ID:{currentProduct.FixedUpCamera1ProcedureId}", MessageLevel.Alarm);
|
|
|
+ // await plc.WriteNodeAsync(addressConfig.Out_ScrewTeachOk.Address, (Int16)2);
|
|
|
+ // return;
|
|
|
+ //}
|
|
|
+
|
|
|
+ //// 获取机器人当前坐标
|
|
|
+ //var robot = _robotService.GetAllRobots().FirstOrDefault();
|
|
|
+ //if (robot == null)
|
|
|
+ //{
|
|
|
+ // SendTaskMessage($"未找到机器人,无法执行上相机锁附/组装拍照视觉任务", MessageLevel.Alarm);
|
|
|
+ // await plc.WriteNodeAsync(addressConfig.Out_ScrewTeachOk.Address, (Int16)2);
|
|
|
+ // return;
|
|
|
+
|
|
|
+ //}
|
|
|
+ //var currentPosition = robot.GetRobotPos();
|
|
|
+
|
|
|
+ //// 执行视觉任务
|
|
|
+ //var _cts = new CancellationTokenSource();
|
|
|
+ //var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(process, null, null, _cts.Token);
|
|
|
+ //if (visionResult.IsSucceed)
|
|
|
+ //{
|
|
|
+ // //披头偏差
|
|
|
+ // float offsetX = (float)(visionResult.X - currentPosition.X);
|
|
|
+ // float offsetY = (float)(visionResult.Y - currentPosition.Y);
|
|
|
+
|
|
|
+ // DowmCameraResults[cameraIndex] = new PointF(offsetX, offsetY);
|
|
|
+ // await plc.WriteNodeAsync(addressConfig.Out_ScrewTeachOk.Address, (Int16)1);
|
|
|
+ // return;
|
|
|
+ //}
|
|
|
+ //else
|
|
|
+ //{
|
|
|
+ // await plc.WriteNodeAsync(addressConfig.Out_ScrewTeachOk.Address, (Int16)2);
|
|
|
+ // return;
|
|
|
+ //}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -1189,10 +1337,96 @@ namespace TeamAAS_VP.Core
|
|
|
{
|
|
|
SendTaskMessage($"触发上相机取料拍照...", MessageLevel.Debug);
|
|
|
//相机的编号
|
|
|
- //Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.In_UpCameraPickNum.Address);
|
|
|
+ Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.In_UpCameraPickNum.Address);
|
|
|
+ SendTaskMessage($"编号:{cameraIndex}", MessageLevel.Info);
|
|
|
|
|
|
+ // 获取机器人当前坐标
|
|
|
+ var robot = _robotService.GetAllRobots().FirstOrDefault();
|
|
|
+ if (robot == null)
|
|
|
+ {
|
|
|
+ SendTaskMessage($"未找到机器人,无法执行上相机锁附/组装拍照视觉任务", MessageLevel.Alarm);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_UpCameraPickStatus.Address, (Int16)1);
|
|
|
+ }
|
|
|
+ var currentPosition = robot.GetRobotPos();
|
|
|
+
|
|
|
+ //如果上相机2的流程id为空,则表示只有一个下相机
|
|
|
+ if (currentProduct.MoveDownCamer2PickPhotoProcedureId == Guid.Empty)
|
|
|
+ {
|
|
|
+ //获取移动向下相机1的流程
|
|
|
+ var process = _productService.GetCurrentProductProcedureModelById(currentProduct.MoveDownCamer1PickPhotoProcedureId);
|
|
|
+ if (process == null)
|
|
|
+ {
|
|
|
+ SendTaskMessage($"移动向下相机1视觉流程,流程ID:{currentProduct.MoveDownCamer1PickPhotoProcedureId}", MessageLevel.Alarm);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_UpCameraPickStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 执行视觉任务
|
|
|
+ var _cts = new CancellationTokenSource();
|
|
|
+ var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(process, null, new double[] { currentPosition.X, currentPosition.Y, currentPosition.U }, _cts.Token);
|
|
|
+ if (visionResult.IsSucceed)
|
|
|
+ {
|
|
|
+ currentProduct.PickPoints[0].X_Position = (float)visionResult.X;
|
|
|
+ currentProduct.PickPoints[0].Y_Position = (float)visionResult.Y;
|
|
|
+ //currentProduct.PickPoints[0].U_Position += (float)visionResult.U;
|
|
|
+ await currentProduct.ScrewPoints[0].WriteToPlcAddress(addressConfig.Out_Pick, plc);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_UpCameraPickStatus.Address, (Int16)1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_UpCameraPickStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //获取固定向上相机1的流程
|
|
|
+ var process1 = _productService.GetCurrentProductProcedureModelById(currentProduct.MoveDownCamer1PickPhotoProcedureId);
|
|
|
+ if (process1 == null)
|
|
|
+ {
|
|
|
+ SendTaskMessage($"固定向上相机1视觉流程,流程ID:{currentProduct.MoveDownCamer1PickPhotoProcedureId}", MessageLevel.Alarm);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_UpCameraPickStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //获取固定向上相机2的流程
|
|
|
+ var process2 = _productService.GetCurrentProductProcedureModelById(currentProduct.MoveDownCamer2PickPhotoProcedureId);
|
|
|
+ if (process2 == null)
|
|
|
+ {
|
|
|
+ SendTaskMessage($"固定向上相机1视觉流程,流程ID:{currentProduct.MoveDownCamer2PickPhotoProcedureId}", MessageLevel.Alarm);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_UpCameraPickStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 执行视觉任务
|
|
|
+ var _cts = new CancellationTokenSource();
|
|
|
+ var task1 = _remoteCommandService.ExecutePhotoGetSinglePoint(process1, null, new double[] { currentPosition.X, currentPosition.Y, currentPosition.U }, _cts.Token);
|
|
|
+ var task2 = _remoteCommandService.ExecutePhotoGetSinglePoint(process2, null, new double[] { currentPosition.X, currentPosition.Y, currentPosition.U }, _cts.Token);
|
|
|
+ var visionResults = await Task.WhenAll(task1, task2);
|
|
|
+ if (visionResults[0].IsSucceed && visionResults[1].IsSucceed)
|
|
|
+ {
|
|
|
+ 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 tool2Y = (float)(visionResults[1].Y - visionResults[1].Y);
|
|
|
+ float toolX = (tool1X + tool2X) / 2;
|
|
|
+ float toolY = (tool1Y + tool2Y) / 2;
|
|
|
+
|
|
|
+ //计算两个点的线角度
|
|
|
+
|
|
|
+ currentProduct.PickPoints[0].X_Position = (float)toolX;
|
|
|
+ currentProduct.PickPoints[0].Y_Position = (float)toolY;
|
|
|
+ //currentProduct.PickPoints[0].U_Position += (float)visionResult.U;
|
|
|
+ await currentProduct.ScrewPoints[0].WriteToPlcAddress(addressConfig.Out_Pick, plc);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_UpCameraPickStatus.Address, (Int16)1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_UpCameraPickStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -1213,15 +1447,6 @@ namespace TeamAAS_VP.Core
|
|
|
Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.In_UpCameraPutNum.Address);
|
|
|
SendTaskMessage($"编号:{cameraIndex}", MessageLevel.Info);
|
|
|
|
|
|
- // 获取流程
|
|
|
- var process = _productService.GetCurrentProductProcedureModelById(currentProduct.MoveDownCameraLockPhotoProcedureId);
|
|
|
- if (process == null)
|
|
|
- {
|
|
|
- SendTaskMessage($"未找到上相机锁附/组装拍照对应的视觉流程,流程ID:{currentProduct.MoveDownCameraLockPhotoProcedureId}", MessageLevel.Alarm);
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_UpCameraPutStatus.Address, (Int16)2);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
// 获取机器人当前坐标
|
|
|
var robot = _robotService.GetAllRobots().FirstOrDefault();
|
|
|
if (robot == null)
|
|
|
@@ -1233,19 +1458,73 @@ namespace TeamAAS_VP.Core
|
|
|
}
|
|
|
var currentPosition = robot.GetRobotPos();
|
|
|
|
|
|
- // 执行视觉任务
|
|
|
- var _cts = new CancellationTokenSource();
|
|
|
- var visionResult =await _remoteCommandService.ExecutePhotoGetSinglePoint(process, null, new double[] { currentPosition.X , currentPosition.Y, currentPosition.U}, _cts.Token);
|
|
|
- if (visionResult.IsSucceed)
|
|
|
+ //如果上相机2的流程id为空,则表示只有一个下相机
|
|
|
+ if (currentProduct.MoveDownCamera2LockPhotoProcedureId == Guid.Empty)
|
|
|
{
|
|
|
- UpCameraPutResults[cameraIndex]=new PointF((float)visionResult.X, (float)visionResult.Y);
|
|
|
-
|
|
|
-
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_UpCameraPutStatus.Address, (Int16)1);
|
|
|
+ //获取移动向下相机1的流程
|
|
|
+ var process = _productService.GetCurrentProductProcedureModelById(currentProduct.MoveDownCamera1LockPhotoProcedureId);
|
|
|
+ if (process == null)
|
|
|
+ {
|
|
|
+ SendTaskMessage($"移动向下相机1视觉流程,流程ID:{currentProduct.MoveDownCamera1LockPhotoProcedureId}", MessageLevel.Alarm);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_UpCameraPutStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 执行视觉任务
|
|
|
+ var _cts = new CancellationTokenSource();
|
|
|
+ var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(process, null, new double[] { currentPosition.X, currentPosition.Y, currentPosition.U }, _cts.Token);
|
|
|
+ if (visionResult.IsSucceed)
|
|
|
+ {
|
|
|
+ UpCameraPutResults[cameraIndex] = new PointF((float)visionResult.X, (float)visionResult.Y);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_UpCameraPutStatus.Address, (Int16)1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_UpCameraPutStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_UpCameraPutStatus.Address, (Int16)2);
|
|
|
+ //获取固定向上相机1的流程
|
|
|
+ var process1 = _productService.GetCurrentProductProcedureModelById(currentProduct.MoveDownCamera1LockPhotoProcedureId);
|
|
|
+ if (process1 == null)
|
|
|
+ {
|
|
|
+ SendTaskMessage($"固定向上相机1视觉流程,流程ID:{currentProduct.MoveDownCamera1LockPhotoProcedureId}", MessageLevel.Alarm);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_UpCameraPutStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //获取固定向上相机2的流程
|
|
|
+ var process2 = _productService.GetCurrentProductProcedureModelById(currentProduct.MoveDownCamera2LockPhotoProcedureId);
|
|
|
+ if (process2 == null)
|
|
|
+ {
|
|
|
+ SendTaskMessage($"固定向上相机1视觉流程,流程ID:{currentProduct.MoveDownCamera2LockPhotoProcedureId}", MessageLevel.Alarm);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_UpCameraPutStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 执行视觉任务
|
|
|
+ var _cts = new CancellationTokenSource();
|
|
|
+ var task1 = _remoteCommandService.ExecutePhotoGetSinglePoint(process1, null, new double[] { currentPosition.X, currentPosition.Y, currentPosition.U }, _cts.Token);
|
|
|
+ var task2 = _remoteCommandService.ExecutePhotoGetSinglePoint(process2, null, new double[] { currentPosition.X, currentPosition.Y, currentPosition.U }, _cts.Token);
|
|
|
+ var visionResults = await Task.WhenAll(task1, task2);
|
|
|
+ if (visionResults[0].IsSucceed && visionResults[1].IsSucceed)
|
|
|
+ {
|
|
|
+ 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 tool2Y = (float)(visionResults[1].Y - visionResults[1].Y);
|
|
|
+ float toolX = (tool1X + tool2X) / 2;
|
|
|
+ float toolY = (tool1Y + tool2Y) / 2;
|
|
|
+
|
|
|
+ UpCameraPutResults[cameraIndex] = new PointF(toolX, toolY);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_UpCameraPutStatus.Address, (Int16)1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_UpCameraPutStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
else
|