|
@@ -18,6 +18,7 @@ using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
using System.Collections.ObjectModel;
|
|
|
using System.ComponentModel;
|
|
using System.ComponentModel;
|
|
|
|
|
+using System.Drawing;
|
|
|
using System.IO;
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
using System.Net.Sockets;
|
|
using System.Net.Sockets;
|
|
@@ -299,7 +300,7 @@ namespace TeamAAS_VP.Core
|
|
|
}
|
|
}
|
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
|
{
|
|
{
|
|
|
- LogHelper.WriteLogError("为PLC写入系统参数和订阅变量时出错",ex);
|
|
|
|
|
|
|
+ LogHelper.WriteLogError("为PLC写入系统参数和订阅变量时出错", ex);
|
|
|
}
|
|
}
|
|
|
if (sb.Length == 0)
|
|
if (sb.Length == 0)
|
|
|
{
|
|
{
|
|
@@ -905,16 +906,16 @@ namespace TeamAAS_VP.Core
|
|
|
var addressConfig = _configService.GetPlcAddresses();
|
|
var addressConfig = _configService.GetPlcAddresses();
|
|
|
var plc = _plcService.GetPlcByNumber(addressConfig.PlcNo) as OpcUaClientPLC;
|
|
var plc = _plcService.GetPlcByNumber(addressConfig.PlcNo) as OpcUaClientPLC;
|
|
|
if (plc == null || !plc.IsConnected) return;
|
|
if (plc == null || !plc.IsConnected) return;
|
|
|
- var current= _productService.GetCurrentProduct();
|
|
|
|
|
|
|
+ var current = _productService.GetCurrentProduct();
|
|
|
if (current == null) return;
|
|
if (current == null) return;
|
|
|
- if (current.PickCameraPoints!=null && current.PickCameraPoints.Count>0)
|
|
|
|
|
|
|
+ if (current.PickCameraPoints != null && current.PickCameraPoints.Count > 0)
|
|
|
{
|
|
{
|
|
|
foreach (var item in current.PickCameraPoints)
|
|
foreach (var item in current.PickCameraPoints)
|
|
|
{
|
|
{
|
|
|
- await item.WriteToPlcAddress(addressConfig.Out_PickCamera,plc);
|
|
|
|
|
|
|
+ await item.WriteToPlcAddress(addressConfig.Out_PickCamera, plc);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (current.PickPoints != null && current.PickPoints.Count > 0)
|
|
if (current.PickPoints != null && current.PickPoints.Count > 0)
|
|
|
{
|
|
{
|
|
|
foreach (var item in current.PickPoints)
|
|
foreach (var item in current.PickPoints)
|
|
@@ -953,6 +954,9 @@ namespace TeamAAS_VP.Core
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ PointF[] DowmCameraResults= new PointF[10];
|
|
|
|
|
+ PointF[] UpCameraPutResults = new PointF[10];
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// PLC命令触发时
|
|
/// PLC命令触发时
|
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -964,6 +968,8 @@ namespace TeamAAS_VP.Core
|
|
|
var addressConfig = _configService.GetPlcAddresses();
|
|
var addressConfig = _configService.GetPlcAddresses();
|
|
|
var plc = _plcService.GetPlcByNumber(addressConfig.PlcNo) as OpcUaClientPLC;
|
|
var plc = _plcService.GetPlcByNumber(addressConfig.PlcNo) as OpcUaClientPLC;
|
|
|
if (plc == null || !plc.IsConnected) return;
|
|
if (plc == null || !plc.IsConnected) return;
|
|
|
|
|
+ // 获取当前产品
|
|
|
|
|
+ var currentProduct = _productService.GetCurrentProduct();
|
|
|
|
|
|
|
|
// 触发下相机拍照
|
|
// 触发下相机拍照
|
|
|
if (addressConfig.In_DowmCameraExe.Address.Contains(tuple.nodeId))
|
|
if (addressConfig.In_DowmCameraExe.Address.Contains(tuple.nodeId))
|
|
@@ -973,6 +979,33 @@ namespace TeamAAS_VP.Core
|
|
|
if (state)
|
|
if (state)
|
|
|
{
|
|
{
|
|
|
SendTaskMessage($"触发下相机拍照...", MessageLevel.Debug);
|
|
SendTaskMessage($"触发下相机拍照...", MessageLevel.Debug);
|
|
|
|
|
+ //相机的编号
|
|
|
|
|
+ Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.In_DowmCameraNum.Address);
|
|
|
|
|
+
|
|
|
|
|
+ // 获取流程
|
|
|
|
|
+ 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 = _remoteCommandService.ExecutePhotoGetSinglePoint(process, null,null, _cts.Token);
|
|
|
|
|
+ if (visionResult.IsSucceed)
|
|
|
|
|
+ {
|
|
|
|
|
+ DowmCameraResults[cameraIndex] = new PointF((float)visionResult.X, (float)visionResult.Y);
|
|
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)1);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)2);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //_remoteCommandService.ExecuteNormalVisionTaskAsync()
|
|
|
|
|
+
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)1);
|
|
await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)1);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -990,6 +1023,10 @@ namespace TeamAAS_VP.Core
|
|
|
if (state)
|
|
if (state)
|
|
|
{
|
|
{
|
|
|
SendTaskMessage($"触发上相机取料拍照...", MessageLevel.Debug);
|
|
SendTaskMessage($"触发上相机取料拍照...", MessageLevel.Debug);
|
|
|
|
|
+ //相机的编号
|
|
|
|
|
+ //Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.In_UpCameraPickNum.Address);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_UpCameraPickStatus.Address, (Int16)1);
|
|
await plc.WriteNodeAsync(addressConfig.Out_UpCameraPickStatus.Address, (Int16)1);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -1007,7 +1044,43 @@ namespace TeamAAS_VP.Core
|
|
|
if (state)
|
|
if (state)
|
|
|
{
|
|
{
|
|
|
SendTaskMessage($"触发上相机锁附/组装拍照...", MessageLevel.Debug);
|
|
SendTaskMessage($"触发上相机锁附/组装拍照...", MessageLevel.Debug);
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_UpCameraPutStatus.Address, (Int16)1);
|
|
|
|
|
|
|
+ //相机的编号
|
|
|
|
|
+ Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.In_UpCameraPutNum.Address);
|
|
|
|
|
+
|
|
|
|
|
+ // 获取流程
|
|
|
|
|
+ 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)
|
|
|
|
|
+ {
|
|
|
|
|
+ SendTaskMessage($"未找到机器人,无法执行上相机锁附/组装拍照视觉任务", MessageLevel.Alarm);
|
|
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_UpCameraPutStatus.Address, (Int16)2);
|
|
|
|
|
+ return;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ var currentPosition = robot.GetRobotPos();
|
|
|
|
|
+
|
|
|
|
|
+ // 执行视觉任务
|
|
|
|
|
+ var _cts = new CancellationTokenSource();
|
|
|
|
|
+ var visionResult = _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);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_UpCameraPutStatus.Address, (Int16)2);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
@@ -1024,6 +1097,11 @@ namespace TeamAAS_VP.Core
|
|
|
if (state)
|
|
if (state)
|
|
|
{
|
|
{
|
|
|
SendTaskMessage($"触发上相机检测拍照...", MessageLevel.Debug);
|
|
SendTaskMessage($"触发上相机检测拍照...", MessageLevel.Debug);
|
|
|
|
|
+ //相机的编号
|
|
|
|
|
+ //Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.Out_UPCameracheckNum.Address);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_UPCameracheckStatus.Address, (Int16)1);
|
|
await plc.WriteNodeAsync(addressConfig.Out_UPCameracheckStatus.Address, (Int16)1);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -1041,6 +1119,11 @@ namespace TeamAAS_VP.Core
|
|
|
if (state)
|
|
if (state)
|
|
|
{
|
|
{
|
|
|
SendTaskMessage($"触发固定相机取料拍照...", MessageLevel.Debug);
|
|
SendTaskMessage($"触发固定相机取料拍照...", MessageLevel.Debug);
|
|
|
|
|
+ //相机的编号
|
|
|
|
|
+ //Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.In_FixedCameraPickNum.Address);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)1);
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)1);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -1058,6 +1141,10 @@ namespace TeamAAS_VP.Core
|
|
|
if (state)
|
|
if (state)
|
|
|
{
|
|
{
|
|
|
SendTaskMessage($"触发固定相机锁附/组装拍照...", MessageLevel.Debug);
|
|
SendTaskMessage($"触发固定相机锁附/组装拍照...", MessageLevel.Debug);
|
|
|
|
|
+ //相机的编号
|
|
|
|
|
+ //Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.In_FixedCameraPutNum.Address);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPutStatus.Address, (Int16)1);
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPutStatus.Address, (Int16)1);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -1075,6 +1162,10 @@ namespace TeamAAS_VP.Core
|
|
|
if (state)
|
|
if (state)
|
|
|
{
|
|
{
|
|
|
SendTaskMessage($"触发固定相机检测拍照...", MessageLevel.Debug);
|
|
SendTaskMessage($"触发固定相机检测拍照...", MessageLevel.Debug);
|
|
|
|
|
+ //相机的编号
|
|
|
|
|
+ //Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.In_FixedCameracheckNum.Address);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameracheckStatus.Address, (Int16)1);
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameracheckStatus.Address, (Int16)1);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -1092,7 +1183,9 @@ namespace TeamAAS_VP.Core
|
|
|
if (state)
|
|
if (state)
|
|
|
{
|
|
{
|
|
|
SendTaskMessage($"收到开始锁付信号...", MessageLevel.Debug);
|
|
SendTaskMessage($"收到开始锁付信号...", MessageLevel.Debug);
|
|
|
- // 这里保留扩展点:可在此添加写 PLC 或启动工作流程的代码
|
|
|
|
|
|
|
+ //位置编号
|
|
|
|
|
+ //Int16 positionIndex = plc.ReadNode<Int16>(addressConfig.In_ProductNum.Address);
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
@@ -1109,7 +1202,9 @@ namespace TeamAAS_VP.Core
|
|
|
if (state)
|
|
if (state)
|
|
|
{
|
|
{
|
|
|
SendTaskMessage($"收到停止锁付信号...", MessageLevel.Debug);
|
|
SendTaskMessage($"收到停止锁付信号...", MessageLevel.Debug);
|
|
|
- // 停止动作的处理点
|
|
|
|
|
|
|
+ //位置编号
|
|
|
|
|
+ //Int16 positionIndex = plc.ReadNode<Int16>(addressConfig.In_ProductNum.Address);
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
@@ -1125,6 +1220,20 @@ namespace TeamAAS_VP.Core
|
|
|
if (state == 1)
|
|
if (state == 1)
|
|
|
{
|
|
{
|
|
|
SendTaskMessage($"收到多相机坐标合并请求,开始合并...", MessageLevel.Debug);
|
|
SendTaskMessage($"收到多相机坐标合并请求,开始合并...", MessageLevel.Debug);
|
|
|
|
|
+ //是拍一个锁一个还是拍两个点锁所有
|
|
|
|
|
+ var systemConfig = _configService.GetSystemConfiguration();
|
|
|
|
|
+ //拍1打1
|
|
|
|
|
+ if (systemConfig.WorkMode == 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ currentProduct.ScrewPoints[0].X_Position = UpCameraPutResults[1].X;
|
|
|
|
|
+ currentProduct.ScrewPoints[0].Y_Position = UpCameraPutResults[1].Y;
|
|
|
|
|
+ await currentProduct.ScrewPoints[0].WriteToPlcAddress(addressConfig.Out_Screw, plc);
|
|
|
|
|
+ }
|
|
|
|
|
+ //拍1打所有
|
|
|
|
|
+ else if (systemConfig.WorkMode == 2)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_CameraDone.Address, (Int16)1);
|
|
await plc.WriteNodeAsync(addressConfig.Out_CameraDone.Address, (Int16)1);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|