|
|
@@ -169,187 +169,187 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
/// </summary>
|
|
|
async void ExecuteStartAutoCorrectCommand()
|
|
|
{
|
|
|
- IsExecuting= true;
|
|
|
- try
|
|
|
- {
|
|
|
+ //IsExecuting= true;
|
|
|
+ //try
|
|
|
+ //{
|
|
|
|
|
|
- if (Robot == null || !Robot.IsConnected)
|
|
|
- {
|
|
|
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
- return;
|
|
|
- }
|
|
|
- //获取当前产品
|
|
|
- var product = SelectProduct;
|
|
|
- if (product == null)
|
|
|
- {
|
|
|
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "未选择产品,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
- return;
|
|
|
- }
|
|
|
- //获取锁付相机拍照点位
|
|
|
- var screwCameraPoint = product.ScrewCameraPoints;
|
|
|
- if (screwCameraPoint == null || screwCameraPoint.Count < 2)
|
|
|
- {
|
|
|
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "未获取到锁付相机拍照点位,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
- return;
|
|
|
- }
|
|
|
- //获取相机拍照点位对应的锁付点
|
|
|
- var screwCameraLocalPoint1 = product.ScrewCameraLocalPos1;
|
|
|
- if (screwCameraLocalPoint1 == null)
|
|
|
- {
|
|
|
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "未获取到锁付相机拍照点位对应的锁付点,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
- return;
|
|
|
- }
|
|
|
- var screwCameraLocalPoint2= product.ScrewCameraLocalPos2;
|
|
|
- if (screwCameraLocalPoint2 == null)
|
|
|
- {
|
|
|
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "未获取到锁付相机拍照点位对应的锁付点,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
- return;
|
|
|
- }
|
|
|
- var ProcedureModels = new ObservableCollection<ProcedureModel>();
|
|
|
- foreach (var item in product.CameraProcedures)
|
|
|
- {
|
|
|
- foreach (var item1 in item.ProcedureModels)
|
|
|
- {
|
|
|
- ProcedureModels.Add(item1);
|
|
|
- }
|
|
|
- }
|
|
|
- //获取拍照流程
|
|
|
- if (product.MoveDownCameraLockPhotoProcedureId == Guid.Empty)
|
|
|
- {
|
|
|
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "未获取到锁付相机拍照流程,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
- return;
|
|
|
- }
|
|
|
- var procedure = ProcedureModels.FirstOrDefault(p => p.Id == product.MoveDownCameraLockPhotoProcedureId);
|
|
|
- if (procedure == null)
|
|
|
- {
|
|
|
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "未获取到锁付相机拍照流程,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- _cts = new CancellationTokenSource();
|
|
|
- //移动机器人至拍照点位,拍照
|
|
|
- var rpoint = new RPoint()
|
|
|
- {
|
|
|
- X = screwCameraPoint[0].X_Position,
|
|
|
- Y = screwCameraPoint[0].Y_Position,
|
|
|
- Z = screwCameraPoint[0].Z_Position_Start,
|
|
|
- U = screwCameraPoint[0].U_Position,
|
|
|
- V = screwCameraPoint[0].R_Position,
|
|
|
- };
|
|
|
- await Robot.CalibMotionAsync(rpoint, 0);
|
|
|
- await Task.Delay(200);
|
|
|
- // 执行拍照并获取识别结果
|
|
|
- var recognitionResult = await _remoteCommandService.ExecutePhotoGetSinglePointWithImage(procedure, null, new double[] { rpoint.X, rpoint.Y, 0 }, _cts.Token);
|
|
|
- Image= recognitionResult.Image;
|
|
|
- Graphic = null;
|
|
|
- Graphic = recognitionResult.Graphic;
|
|
|
- if (!recognitionResult.IsSucceed)
|
|
|
- {
|
|
|
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "拍照获取识别结果失败,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
- return;
|
|
|
- }
|
|
|
- //第一个点位的校正结果
|
|
|
- PointF worldP1 = new PointF((float)recognitionResult.X, (float)recognitionResult.Y);
|
|
|
- //移动机器人至拍照点位,拍照
|
|
|
- rpoint = new RPoint()
|
|
|
- {
|
|
|
- X = screwCameraPoint[1].X_Position,
|
|
|
- Y = screwCameraPoint[1].Y_Position,
|
|
|
- Z = screwCameraPoint[1].Z_Position_Start,
|
|
|
- U = screwCameraPoint[1].U_Position,
|
|
|
- V = screwCameraPoint[1].R_Position,
|
|
|
- };
|
|
|
- await Robot.CalibMotionAsync(rpoint, 0);
|
|
|
- if (_cts.IsCancellationRequested)
|
|
|
- return;
|
|
|
- await Task.Delay(200);
|
|
|
- // 执行拍照并获取识别结果
|
|
|
- recognitionResult = await _remoteCommandService.ExecutePhotoGetSinglePointWithImage(procedure, null, new double[] { rpoint.X, rpoint.Y, 0 }, _cts.Token);
|
|
|
- Image = recognitionResult.Image;
|
|
|
- Graphic = null;
|
|
|
- Graphic = recognitionResult.Graphic;
|
|
|
- if (!recognitionResult.IsSucceed)
|
|
|
- {
|
|
|
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "拍照获取识别结果失败,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
- return;
|
|
|
- }
|
|
|
- //第一个点位的校正结果
|
|
|
- PointF worldP2 = new PointF((float)recognitionResult.X, (float)recognitionResult.Y);
|
|
|
-
|
|
|
- //计算移动相机与拍照点之间的偏差
|
|
|
- //获取校准
|
|
|
- var calibration = _calibrationService.GetCalibration(procedure.CalibrationId);
|
|
|
-
|
|
|
- //获取mark点
|
|
|
- var mark = calibration.MarkPoint;
|
|
|
- //获取中心点
|
|
|
- var center = calibration.CenterPoint;
|
|
|
- //计算相机中心与披头之间的坐标偏差
|
|
|
- var cameraOffsetX = mark.X - center.X;
|
|
|
- var cameraOffsetY = mark.Y - center.Y;
|
|
|
-
|
|
|
-
|
|
|
- //根据UpCameraPutResults[]中的索引1、2,和拍照点对应的Local下的坐标,从创建Local坐标系
|
|
|
- PointF localP1 = new PointF(screwCameraLocalPoint1.X_Position, screwCameraLocalPoint1.Y_Position);
|
|
|
- PointF localP2 = new PointF(screwCameraLocalPoint2.X_Position, screwCameraLocalPoint2.Y_Position);
|
|
|
- local = new CoordinateTransformer(worldP1, worldP2, localP1, localP2);
|
|
|
-
|
|
|
- for (int i = 0; i < product.ScrewPoints.Count; i++)
|
|
|
- {
|
|
|
- var localPoint = new PointF(product.ScrewPoints[i].X_Position, product.ScrewPoints[i].Y_Position);
|
|
|
- var worldPoint = local.ToOldCoord(localPoint.X, localPoint.Y);
|
|
|
- var point = product.ScrewCameraPoints[0].Clone();
|
|
|
- point.X_Position = (float)worldPoint[0];
|
|
|
- point.Y_Position = (float)worldPoint[1];
|
|
|
- //计算当前点的高度与screwCameraLocalPoint1的Z轴之间的偏差
|
|
|
- var deltaZ = product.ScrewPoints[i].Z_Position_Start - screwCameraLocalPoint1.Z_Position_Start;
|
|
|
-
|
|
|
- //计算相机去拍照点位
|
|
|
- point.X_Position-= cameraOffsetX;
|
|
|
- point.Y_Position-= cameraOffsetY;
|
|
|
- point.Z_Position_Start= screwCameraPoint[0].Z_Position_Start + deltaZ;
|
|
|
-
|
|
|
- //移动机器人至拍照点位,拍照
|
|
|
- rpoint = new RPoint()
|
|
|
- {
|
|
|
- X = point.X_Position,
|
|
|
- Y = point.Y_Position,
|
|
|
- Z = point.Z_Position_Start,
|
|
|
- U = screwCameraPoint[0].U_Position,
|
|
|
- V = screwCameraPoint[0].R_Position,
|
|
|
- };
|
|
|
- await Robot.CalibMotionAsync(rpoint, 0);
|
|
|
- if (_cts.IsCancellationRequested)
|
|
|
- return;
|
|
|
- await Task.Delay(200);
|
|
|
- // 执行拍照并获取识别结果
|
|
|
- recognitionResult = await _remoteCommandService.ExecutePhotoGetSinglePointWithImage(procedure, null, new double[] { rpoint.X, rpoint.Y, 0 }, _cts.Token);
|
|
|
- Image = recognitionResult.Image;
|
|
|
- Graphic = null;
|
|
|
- Graphic = recognitionResult.Graphic;
|
|
|
- if (!recognitionResult.IsSucceed)
|
|
|
- {
|
|
|
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "拍照获取识别结果失败,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
- return;
|
|
|
- }
|
|
|
- //将获取到的点位转换至Local坐标系下
|
|
|
- var correctedPoint = local.ToNewCoord((float)recognitionResult.X, (float)recognitionResult.Y);
|
|
|
- CorrectPoints[i].PostX = (float)correctedPoint[0];
|
|
|
- CorrectPoints[i].PostY = (float)correctedPoint[1];
|
|
|
- if (_cts.IsCancellationRequested)
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- LogHelper.WriteLogError("通过移动相机自动校准锁付点位是出错!",ex);
|
|
|
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
- IsExecuting= false;
|
|
|
- }
|
|
|
+ // if (Robot == null || !Robot.IsConnected)
|
|
|
+ // {
|
|
|
+ // _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // //获取当前产品
|
|
|
+ // var product = SelectProduct;
|
|
|
+ // if (product == null)
|
|
|
+ // {
|
|
|
+ // _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "未选择产品,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // //获取锁付相机拍照点位
|
|
|
+ // var screwCameraPoint = product.ScrewCameraPoints;
|
|
|
+ // if (screwCameraPoint == null || screwCameraPoint.Count < 2)
|
|
|
+ // {
|
|
|
+ // _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "未获取到锁付相机拍照点位,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // //获取相机拍照点位对应的锁付点
|
|
|
+ // var screwCameraLocalPoint1 = product.ScrewCameraLocalPos1;
|
|
|
+ // if (screwCameraLocalPoint1 == null)
|
|
|
+ // {
|
|
|
+ // _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "未获取到锁付相机拍照点位对应的锁付点,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // var screwCameraLocalPoint2= product.ScrewCameraLocalPos2;
|
|
|
+ // if (screwCameraLocalPoint2 == null)
|
|
|
+ // {
|
|
|
+ // _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "未获取到锁付相机拍照点位对应的锁付点,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // var ProcedureModels = new ObservableCollection<ProcedureModel>();
|
|
|
+ // foreach (var item in product.CameraProcedures)
|
|
|
+ // {
|
|
|
+ // foreach (var item1 in item.ProcedureModels)
|
|
|
+ // {
|
|
|
+ // ProcedureModels.Add(item1);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // //获取拍照流程
|
|
|
+ // if (product.MoveDownCameraLockPhotoProcedureId == Guid.Empty)
|
|
|
+ // {
|
|
|
+ // _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "未获取到锁付相机拍照流程,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // var procedure = ProcedureModels.FirstOrDefault(p => p.Id == product.MoveDownCameraLockPhotoProcedureId);
|
|
|
+ // if (procedure == null)
|
|
|
+ // {
|
|
|
+ // _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "未获取到锁付相机拍照流程,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // _cts = new CancellationTokenSource();
|
|
|
+ // //移动机器人至拍照点位,拍照
|
|
|
+ // var rpoint = new RPoint()
|
|
|
+ // {
|
|
|
+ // X = screwCameraPoint[0].X_Position,
|
|
|
+ // Y = screwCameraPoint[0].Y_Position,
|
|
|
+ // Z = screwCameraPoint[0].Z_Position_Start,
|
|
|
+ // U = screwCameraPoint[0].U_Position,
|
|
|
+ // V = screwCameraPoint[0].R_Position,
|
|
|
+ // };
|
|
|
+ // await Robot.CalibMotionAsync(rpoint, 0);
|
|
|
+ // await Task.Delay(200);
|
|
|
+ // // 执行拍照并获取识别结果
|
|
|
+ // var recognitionResult = await _remoteCommandService.ExecutePhotoGetSinglePointWithImage(procedure, null, new double[] { rpoint.X, rpoint.Y, 0 }, _cts.Token);
|
|
|
+ // Image= recognitionResult.Image;
|
|
|
+ // Graphic = null;
|
|
|
+ // Graphic = recognitionResult.Graphic;
|
|
|
+ // if (!recognitionResult.IsSucceed)
|
|
|
+ // {
|
|
|
+ // _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "拍照获取识别结果失败,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // //第一个点位的校正结果
|
|
|
+ // PointF worldP1 = new PointF((float)recognitionResult.X, (float)recognitionResult.Y);
|
|
|
+ // //移动机器人至拍照点位,拍照
|
|
|
+ // rpoint = new RPoint()
|
|
|
+ // {
|
|
|
+ // X = screwCameraPoint[1].X_Position,
|
|
|
+ // Y = screwCameraPoint[1].Y_Position,
|
|
|
+ // Z = screwCameraPoint[1].Z_Position_Start,
|
|
|
+ // U = screwCameraPoint[1].U_Position,
|
|
|
+ // V = screwCameraPoint[1].R_Position,
|
|
|
+ // };
|
|
|
+ // await Robot.CalibMotionAsync(rpoint, 0);
|
|
|
+ // if (_cts.IsCancellationRequested)
|
|
|
+ // return;
|
|
|
+ // await Task.Delay(200);
|
|
|
+ // // 执行拍照并获取识别结果
|
|
|
+ // recognitionResult = await _remoteCommandService.ExecutePhotoGetSinglePointWithImage(procedure, null, new double[] { rpoint.X, rpoint.Y, 0 }, _cts.Token);
|
|
|
+ // Image = recognitionResult.Image;
|
|
|
+ // Graphic = null;
|
|
|
+ // Graphic = recognitionResult.Graphic;
|
|
|
+ // if (!recognitionResult.IsSucceed)
|
|
|
+ // {
|
|
|
+ // _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "拍照获取识别结果失败,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // //第一个点位的校正结果
|
|
|
+ // PointF worldP2 = new PointF((float)recognitionResult.X, (float)recognitionResult.Y);
|
|
|
+
|
|
|
+ // //计算移动相机与拍照点之间的偏差
|
|
|
+ // //获取校准
|
|
|
+ // var calibration = _calibrationService.GetCalibration(procedure.CalibrationId);
|
|
|
+
|
|
|
+ // //获取mark点
|
|
|
+ // var mark = calibration.MarkPoint;
|
|
|
+ // //获取中心点
|
|
|
+ // var center = calibration.CenterPoint;
|
|
|
+ // //计算相机中心与披头之间的坐标偏差
|
|
|
+ // var cameraOffsetX = mark.X - center.X;
|
|
|
+ // var cameraOffsetY = mark.Y - center.Y;
|
|
|
+
|
|
|
+
|
|
|
+ // //根据UpCameraPutResults[]中的索引1、2,和拍照点对应的Local下的坐标,从创建Local坐标系
|
|
|
+ // PointF localP1 = new PointF(screwCameraLocalPoint1.X_Position, screwCameraLocalPoint1.Y_Position);
|
|
|
+ // PointF localP2 = new PointF(screwCameraLocalPoint2.X_Position, screwCameraLocalPoint2.Y_Position);
|
|
|
+ // local = new CoordinateTransformer(worldP1, worldP2, localP1, localP2);
|
|
|
+
|
|
|
+ // for (int i = 0; i < product.ScrewPoints.Count; i++)
|
|
|
+ // {
|
|
|
+ // var localPoint = new PointF(product.ScrewPoints[i].X_Position, product.ScrewPoints[i].Y_Position);
|
|
|
+ // var worldPoint = local.ToOldCoord(localPoint.X, localPoint.Y);
|
|
|
+ // var point = product.ScrewCameraPoints[0].Clone();
|
|
|
+ // point.X_Position = (float)worldPoint[0];
|
|
|
+ // point.Y_Position = (float)worldPoint[1];
|
|
|
+ // //计算当前点的高度与screwCameraLocalPoint1的Z轴之间的偏差
|
|
|
+ // var deltaZ = product.ScrewPoints[i].Z_Position_Start - screwCameraLocalPoint1.Z_Position_Start;
|
|
|
+
|
|
|
+ // //计算相机去拍照点位
|
|
|
+ // point.X_Position-= cameraOffsetX;
|
|
|
+ // point.Y_Position-= cameraOffsetY;
|
|
|
+ // point.Z_Position_Start= screwCameraPoint[0].Z_Position_Start + deltaZ;
|
|
|
+
|
|
|
+ // //移动机器人至拍照点位,拍照
|
|
|
+ // rpoint = new RPoint()
|
|
|
+ // {
|
|
|
+ // X = point.X_Position,
|
|
|
+ // Y = point.Y_Position,
|
|
|
+ // Z = point.Z_Position_Start,
|
|
|
+ // U = screwCameraPoint[0].U_Position,
|
|
|
+ // V = screwCameraPoint[0].R_Position,
|
|
|
+ // };
|
|
|
+ // await Robot.CalibMotionAsync(rpoint, 0);
|
|
|
+ // if (_cts.IsCancellationRequested)
|
|
|
+ // return;
|
|
|
+ // await Task.Delay(200);
|
|
|
+ // // 执行拍照并获取识别结果
|
|
|
+ // recognitionResult = await _remoteCommandService.ExecutePhotoGetSinglePointWithImage(procedure, null, new double[] { rpoint.X, rpoint.Y, 0 }, _cts.Token);
|
|
|
+ // Image = recognitionResult.Image;
|
|
|
+ // Graphic = null;
|
|
|
+ // Graphic = recognitionResult.Graphic;
|
|
|
+ // if (!recognitionResult.IsSucceed)
|
|
|
+ // {
|
|
|
+ // _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "拍照获取识别结果失败,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // //将获取到的点位转换至Local坐标系下
|
|
|
+ // var correctedPoint = local.ToNewCoord((float)recognitionResult.X, (float)recognitionResult.Y);
|
|
|
+ // CorrectPoints[i].PostX = (float)correctedPoint[0];
|
|
|
+ // CorrectPoints[i].PostY = (float)correctedPoint[1];
|
|
|
+ // if (_cts.IsCancellationRequested)
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+
|
|
|
+ //}
|
|
|
+ //catch (Exception ex)
|
|
|
+ //{
|
|
|
+ // LogHelper.WriteLogError("通过移动相机自动校准锁付点位是出错!",ex);
|
|
|
+ // _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
|
|
|
+ //}
|
|
|
+ //finally
|
|
|
+ //{
|
|
|
+ // IsExecuting= false;
|
|
|
+ //}
|
|
|
}
|
|
|
|
|
|
bool CanExecuteStartAutoCorrectCommand()
|