|
|
@@ -1470,7 +1470,7 @@ namespace TeamAAS_VP.Services
|
|
|
}
|
|
|
DateTime nowtime = DateTime.Now;
|
|
|
LogHelper.WriteLogInfo("开始采集图像");
|
|
|
- Thread.Sleep(250);
|
|
|
+ //Thread.Sleep(250);
|
|
|
var image = camera.Grab();
|
|
|
if (image == null)
|
|
|
{
|
|
|
@@ -1893,93 +1893,103 @@ namespace TeamAAS_VP.Services
|
|
|
/// <param name="positionIndex"></param>
|
|
|
/// <param name="remark"></param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<(bool IsSucceed, double X, double Y, double U)> ExecutePhotoGetSinglePoint(ProcedureModel procedure, Dictionary<string, string> InputTerminal, double[] robotCoord, CancellationToken cancellationToken, int positionIndex, string remark)
|
|
|
+ public async Task<(bool IsSucceed, double X, double Y, double U, string dis)> ExecutePhotoGetSinglePoint(ProcedureModel procedure, Dictionary<string, string> InputTerminal, double[] robotCoord, CancellationToken cancellationToken, int positionIndex, string remark)
|
|
|
{
|
|
|
- DateTime nowtime = DateTime.Now;
|
|
|
+ DateTime nowtime = DateTime.Now;
|
|
|
await SetLightBeforePhoto(procedure);
|
|
|
- try
|
|
|
+ return await Task.Run(async () =>
|
|
|
{
|
|
|
- //拍照失败时,需要多次拍照
|
|
|
- for (int i = 0; i < procedure.FeederFailLimit; i++)
|
|
|
+ try
|
|
|
{
|
|
|
- SendTaskMessage(Lang.开始执行视觉流程.Replace("{0}", $"{i + 1}").Replace("{1}", procedure.Name), MessageLevel.Info);
|
|
|
-
|
|
|
- // 1. 执行相机拍照并运行视觉工具
|
|
|
- bool visionSucceed = ExecutePhoto(i + 1, procedure, InputTerminal, out CogToolBlockTerminalCollection outputCollection);
|
|
|
- if (!visionSucceed)
|
|
|
+ string dist = "";
|
|
|
+ //拍照失败时,需要多次拍照
|
|
|
+ for (int i = 0; i < procedure.FeederFailLimit; i++)
|
|
|
{
|
|
|
- SendTaskMessage(Lang.视觉任务执行失败, MessageLevel.Error);
|
|
|
- continue;
|
|
|
- }
|
|
|
+ SendTaskMessage(Lang.开始执行视觉流程.Replace("{0}", $"{i + 1}").Replace("{1}", procedure.Name), MessageLevel.Info);
|
|
|
|
|
|
- if (!outputCollection.Contains("Found"))
|
|
|
- {
|
|
|
- SendTaskMessage(Lang.未找到视觉输出结果, MessageLevel.Error);
|
|
|
- await RecordPhotoCaptureAsync(procedure, robotCoord, false, new double[] { 0, 0, 0 }, new double[] { 0, 0, 0 }, string.Empty, positionIndex, remark);
|
|
|
- return (false, 0, 0, 0);
|
|
|
- }
|
|
|
- // 2. 获取视觉输出结果
|
|
|
- bool Found = (bool)(outputCollection["Found"].Value);
|
|
|
- if (!Found)
|
|
|
- {
|
|
|
- SendTaskMessage(Lang.拍照NG, MessageLevel.Debug);
|
|
|
- continue;
|
|
|
- }
|
|
|
- SendTaskMessage(Lang.拍照OK, MessageLevel.Debug);
|
|
|
- if (procedure.CalibrationId == Guid.Empty)
|
|
|
- {
|
|
|
- //没有关联校准时,则执行检测任务
|
|
|
- await RecordPhotoCaptureAsync(procedure, robotCoord, true, new double[] { 0, 0, 0 }, new double[] { 0, 0, 0 }, string.Empty, positionIndex, remark);
|
|
|
- return (true, 0, 0, 0);
|
|
|
- }
|
|
|
+ // 1. 执行相机拍照并运行视觉工具
|
|
|
+ bool visionSucceed = ExecutePhoto(i + 1, procedure, InputTerminal, out CogToolBlockTerminalCollection outputCollection);
|
|
|
+ if (!visionSucceed)
|
|
|
+ {
|
|
|
+ SendTaskMessage(Lang.视觉任务执行失败, MessageLevel.Error);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- // 3. 获取视觉输出结果
|
|
|
- LogHelper.WriteLogInfo("开始获取视觉输出结果");
|
|
|
- //获取相机校准
|
|
|
- var calib = _calibrationService.GetCalibration(procedure.CalibrationId);
|
|
|
- string points = (string)(outputCollection["Point"].Value);
|
|
|
- string[] strpoints = points.Split(';');
|
|
|
- //先将pos按照逗号进行分隔,拿到数组
|
|
|
- var posParts = strpoints[0].Split(',');
|
|
|
- double _pixel_x = double.Parse(posParts[0]);
|
|
|
- double _pixel_y = double.Parse(posParts[1]);
|
|
|
- double _pixel_u = double.Parse(posParts[2]);
|
|
|
- if (calib != null)
|
|
|
- {
|
|
|
- //转换点位-像素转换成机器人绝对坐标
|
|
|
- var calibResult = _calibrationService.ConvertPixelToPosition((_pixel_x, _pixel_y, _pixel_u), robotCoord, calib, RobotBrand.XYZ_Platform);
|
|
|
- if (!calibResult.IsSucceed)
|
|
|
+ if (!outputCollection.Contains("Found"))
|
|
|
{
|
|
|
- await RecordPhotoCaptureAsync(procedure, robotCoord, false, new double[] { _pixel_x, _pixel_y, _pixel_u }, new double[] { 0, 0, 0 }, string.Empty, positionIndex, remark);
|
|
|
- return (false, 0, 0, 0);
|
|
|
+ SendTaskMessage(Lang.未找到视觉输出结果, MessageLevel.Error);
|
|
|
+ await RecordPhotoCaptureAsync(procedure, robotCoord, false, new double[] { 0, 0, 0 }, new double[] { 0, 0, 0 }, string.Empty, positionIndex, remark);
|
|
|
+ return (false, 0, 0, 0, "NA");
|
|
|
}
|
|
|
- await RecordPhotoCaptureAsync(procedure, robotCoord, true, new double[] { _pixel_x, _pixel_y, _pixel_u }, new double[] { calibResult.X, calibResult.Y, calibResult.U }, string.Empty, positionIndex, remark);
|
|
|
- return (true, calibResult.X, calibResult.Y, calibResult.U);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- await RecordPhotoCaptureAsync(procedure, robotCoord, true, new double[] { _pixel_x, _pixel_y, _pixel_u }, new double[] { 0, 0, 0 }, string.Empty, positionIndex, remark);
|
|
|
- return (true, _pixel_x, _pixel_y, _pixel_u);
|
|
|
+ // 2. 获取视觉输出结果
|
|
|
+ bool Found = (bool)(outputCollection["Found"].Value);
|
|
|
+ if (!Found)
|
|
|
+ {
|
|
|
+ SendTaskMessage(Lang.拍照NG, MessageLevel.Debug);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (outputCollection.Contains("dis"))
|
|
|
+ {
|
|
|
+ dist = (string)outputCollection["dis"].Value;
|
|
|
+ }
|
|
|
+ SendTaskMessage(Lang.拍照OK, MessageLevel.Debug);
|
|
|
+ if (procedure.CalibrationId == Guid.Empty)
|
|
|
+ {
|
|
|
+ //没有关联校准时,则执行检测任务
|
|
|
+ await RecordPhotoCaptureAsync(procedure, robotCoord, true, new double[] { 0, 0, 0 }, new double[] { 0, 0, 0 }, string.Empty, positionIndex, remark);
|
|
|
+ return (true, 0, 0, 0, dist);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 获取视觉输出结果
|
|
|
+ LogHelper.WriteLogInfo("开始获取视觉输出结果");
|
|
|
+ //获取相机校准
|
|
|
+ var calib = _calibrationService.GetCalibration(procedure.CalibrationId);
|
|
|
+ string points = (string)(outputCollection["Point"].Value);
|
|
|
+ string[] strpoints = points.Split(';');
|
|
|
+ //先将pos按照逗号进行分隔,拿到数组
|
|
|
+ var posParts = strpoints[0].Split(',');
|
|
|
+ double _pixel_x = double.Parse(posParts[0]);
|
|
|
+ double _pixel_y = double.Parse(posParts[1]);
|
|
|
+ double _pixel_u = double.Parse(posParts[2]);
|
|
|
+ if (calib != null)
|
|
|
+ {
|
|
|
+ //转换点位-像素转换成机器人绝对坐标
|
|
|
+ var calibResult = _calibrationService.ConvertPixelToPosition((_pixel_x, _pixel_y, _pixel_u), robotCoord, calib, RobotBrand.XYZ_Platform);
|
|
|
+ if (!calibResult.IsSucceed)
|
|
|
+ {
|
|
|
+ await RecordPhotoCaptureAsync(procedure, robotCoord, false, new double[] { _pixel_x, _pixel_y, _pixel_u }, new double[] { 0, 0, 0 }, string.Empty, positionIndex, remark);
|
|
|
+ return (false, 0, 0, 0, dist);
|
|
|
+ }
|
|
|
+ await RecordPhotoCaptureAsync(procedure, robotCoord, true, new double[] { _pixel_x, _pixel_y, _pixel_u }, new double[] { calibResult.X, calibResult.Y, calibResult.U }, string.Empty, positionIndex, remark);
|
|
|
+ return (true, calibResult.X, calibResult.Y, calibResult.U, dist);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await RecordPhotoCaptureAsync(procedure, robotCoord, true, new double[] { _pixel_x, _pixel_y, _pixel_u }, new double[] { 0, 0, 0 }, string.Empty, positionIndex, remark);
|
|
|
+ return (true, _pixel_x, _pixel_y, _pixel_u, dist);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+ SendTaskMessage(Lang.多次拍照失败, MessageLevel.Alarm);
|
|
|
+ await RecordPhotoCaptureAsync(procedure, robotCoord, false, new double[] { 0, 0, 0 }, new double[] { 0, 0, 0 }, string.Empty, positionIndex, remark);
|
|
|
+ return (false, 0, 0, 0, "NA");
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogHelper.WriteLogError("执行相机取图并获取单点位时出错!", ex);
|
|
|
+ await RecordPhotoCaptureAsync(procedure, robotCoord, false, new double[] { 0, 0, 0 }, new double[] { 0, 0, 0 }, string.Empty, positionIndex, remark);
|
|
|
+ return (false, 0, 0, 0, "NA");
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ await TurnOffLightAfterPhoto(procedure);
|
|
|
|
|
|
}
|
|
|
- SendTaskMessage(Lang.多次拍照失败, MessageLevel.Alarm);
|
|
|
- await RecordPhotoCaptureAsync(procedure, robotCoord, false, new double[] { 0, 0, 0 }, new double[] { 0, 0, 0 }, string.Empty, positionIndex, remark);
|
|
|
- return (false, 0, 0, 0);
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- LogHelper.WriteLogError("执行相机取图并获取单点位时出错!", ex);
|
|
|
- await RecordPhotoCaptureAsync(procedure, robotCoord, false, new double[] { 0, 0, 0 }, new double[] { 0, 0, 0 }, string.Empty, positionIndex, remark);
|
|
|
- return (false, 0, 0, 0);
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
- await TurnOffLightAfterPhoto(procedure);
|
|
|
+ });
|
|
|
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 获取复检结果
|
|
|
/// </summary>
|
|
|
@@ -1992,60 +2002,64 @@ namespace TeamAAS_VP.Services
|
|
|
/// <returns></returns>
|
|
|
public async Task<(bool IsSucceed, string distance)> ExecutePhotoGetDistance(ProcedureModel procedure, Dictionary<string, string> InputTerminal, double[] robotCoord, CancellationToken cancellationToken, int positionIndex, string remark)
|
|
|
{
|
|
|
- DateTime nowtime = DateTime.Now;
|
|
|
- await SetLightBeforePhoto(procedure);
|
|
|
- try
|
|
|
+ return await Task.Run(async () =>
|
|
|
{
|
|
|
- var dis = "0,0";
|
|
|
- //拍照失败时,需要多次拍照
|
|
|
- for (int i = 0; i < procedure.FeederFailLimit; i++)
|
|
|
+ DateTime nowtime = DateTime.Now;
|
|
|
+ await SetLightBeforePhoto(procedure);
|
|
|
+ try
|
|
|
{
|
|
|
- SendTaskMessage(Lang.开始执行视觉流程.Replace("{0}", $"{i + 1}").Replace("{1}", procedure.Name), MessageLevel.Info);
|
|
|
-
|
|
|
- // 1. 执行相机拍照并运行视觉工具
|
|
|
- bool visionSucceed = ExecutePhoto(i + 1, procedure, InputTerminal, out CogToolBlockTerminalCollection outputCollection);
|
|
|
- if (!visionSucceed)
|
|
|
+ var dis = "0,0";
|
|
|
+ //拍照失败时,需要多次拍照
|
|
|
+ for (int i = 0; i < procedure.FeederFailLimit; i++)
|
|
|
{
|
|
|
- SendTaskMessage(Lang.视觉任务执行失败, MessageLevel.Error);
|
|
|
- dis = (string)(outputCollection["Gap"].Value);
|
|
|
- continue;
|
|
|
- }
|
|
|
+ SendTaskMessage(Lang.开始执行视觉流程.Replace("{0}", $"{i + 1}").Replace("{1}", procedure.Name), MessageLevel.Info);
|
|
|
|
|
|
- if (!outputCollection.Contains("Found"))
|
|
|
- {
|
|
|
- SendTaskMessage(Lang.未找到视觉输出结果, MessageLevel.Error);
|
|
|
- return (false, "NA");
|
|
|
- }
|
|
|
+ // 1. 执行相机拍照并运行视觉工具
|
|
|
+ bool visionSucceed = ExecutePhoto(i + 1, procedure, InputTerminal, out CogToolBlockTerminalCollection outputCollection);
|
|
|
+ if (!visionSucceed)
|
|
|
+ {
|
|
|
+ SendTaskMessage(Lang.视觉任务执行失败, MessageLevel.Error);
|
|
|
+ dis = (string)(outputCollection["Gap"].Value);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- // 2. 获取视觉输出结果
|
|
|
- bool Found = (bool)(outputCollection["Found"].Value);
|
|
|
- if (!Found)
|
|
|
- {
|
|
|
- SendTaskMessage(Lang.拍照NG, MessageLevel.Debug);
|
|
|
+ if (!outputCollection.Contains("Found"))
|
|
|
+ {
|
|
|
+ SendTaskMessage(Lang.未找到视觉输出结果, MessageLevel.Error);
|
|
|
+ return (false, "NA");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 获取视觉输出结果
|
|
|
+ bool Found = (bool)(outputCollection["Found"].Value);
|
|
|
+ if (!Found)
|
|
|
+ {
|
|
|
+ SendTaskMessage(Lang.拍照NG, MessageLevel.Debug);
|
|
|
+ dis = (string)(outputCollection["Gap"].Value);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ SendTaskMessage(Lang.拍照OK, MessageLevel.Debug);
|
|
|
+
|
|
|
+ LogHelper.WriteLogInfo("开始获取视觉输出结果");
|
|
|
dis = (string)(outputCollection["Gap"].Value);
|
|
|
- continue;
|
|
|
+ return (true, dis);
|
|
|
}
|
|
|
+ //dis = (string)(outputCollection["Gap"].Value);
|
|
|
+ SendTaskMessage(Lang.多次拍照失败, MessageLevel.Alarm);
|
|
|
+ return (false, dis);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogHelper.WriteLogError("执行相机取图并获取单点位时出错!", ex);
|
|
|
+ return (false, "NA");
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ await TurnOffLightAfterPhoto(procedure);
|
|
|
|
|
|
- SendTaskMessage(Lang.拍照OK, MessageLevel.Debug);
|
|
|
-
|
|
|
- LogHelper.WriteLogInfo("开始获取视觉输出结果");
|
|
|
- dis = (string)(outputCollection["Gap"].Value);
|
|
|
- return (true, dis);
|
|
|
}
|
|
|
- //dis = (string)(outputCollection["Gap"].Value);
|
|
|
- SendTaskMessage(Lang.多次拍照失败, MessageLevel.Alarm);
|
|
|
- return (false, dis);
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- LogHelper.WriteLogError("执行相机取图并获取单点位时出错!", ex);
|
|
|
- return (false, "NA");
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
- await TurnOffLightAfterPhoto(procedure);
|
|
|
+ });
|
|
|
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -2627,12 +2641,12 @@ namespace TeamAAS_VP.Services
|
|
|
foreach (var lightChannel in procedure.LightChannels)
|
|
|
{
|
|
|
bool isSucceed = false;
|
|
|
- isSucceed = await _lightManagerService.TurnOnGlobalChannelAsync(lightChannel.GlobalIndex);
|
|
|
- if (!isSucceed)
|
|
|
- {
|
|
|
- LogHelper.WriteLogInfo($"设置光源通道{lightChannel.GlobalIndex}打开失败!");
|
|
|
- }
|
|
|
- await Task.Delay(200);
|
|
|
+ //isSucceed = await _lightManagerService.TurnOnGlobalChannelAsync(lightChannel.GlobalIndex);
|
|
|
+ //if (!isSucceed)
|
|
|
+ //{
|
|
|
+ // LogHelper.WriteLogInfo($"设置光源通道{lightChannel.GlobalIndex}打开失败!");
|
|
|
+ //}
|
|
|
+ // await Task.Delay(200);
|
|
|
isSucceed = await _lightManagerService.SetGlobalChannelBrightnessAsync(lightChannel.GlobalIndex, lightChannel.DefaultBrightness);
|
|
|
if (!isSucceed)
|
|
|
{
|
|
|
@@ -2641,7 +2655,7 @@ namespace TeamAAS_VP.Services
|
|
|
}
|
|
|
if (procedure.LightChannels.Count > 0)
|
|
|
{
|
|
|
- await Task.Delay(50);
|
|
|
+ // await Task.Delay(50);
|
|
|
}
|
|
|
}
|
|
|
}
|