|
|
@@ -3,6 +3,8 @@ using MaterialDesignThemes.Wpf;
|
|
|
using Prism.Commands;
|
|
|
using Prism.Events;
|
|
|
using Prism.Mvvm;
|
|
|
+using Prism.Regions;
|
|
|
+using Prism.Services.Dialogs;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
|
@@ -15,11 +17,12 @@ using TeamAAS_VP.Core.PLCs;
|
|
|
using TeamAAS_VP.Events;
|
|
|
using TeamAAS_VP.Interfaces;
|
|
|
using TeamAAS_VP.Models;
|
|
|
+using TeamAAS_VP.Models.Calibration;
|
|
|
using TeamAAS_VP.Models.PLC;
|
|
|
|
|
|
namespace TeamAAS_VP.ViewModels.Product
|
|
|
{
|
|
|
- public class AutoCorrectLockPointViewModel : BindableBase
|
|
|
+ public class AutoCorrectLockPointViewModel : BindableBase, IDialogAware
|
|
|
{
|
|
|
private readonly IRobotService _robotService;
|
|
|
private readonly IProductService _productService;
|
|
|
@@ -30,6 +33,8 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
|
|
|
private CancellationTokenSource _cts;
|
|
|
#region 属性
|
|
|
+ public string Title => "校准锁付点位";
|
|
|
+
|
|
|
private ICogImage _Image;
|
|
|
|
|
|
public ICogImage Image
|
|
|
@@ -101,7 +106,17 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
public DelegateCommand CancelAutoCorrectCommand =>
|
|
|
_CancelAutoCorrectCommand ?? (_CancelAutoCorrectCommand = new DelegateCommand(ExecuteCancelAutoCorrectCommand, CanExecuteCancelAutoCorrectCommand).ObservesProperty(() => IsExecuting));
|
|
|
|
|
|
-
|
|
|
+ private DelegateCommand _ConfirmCommand;
|
|
|
+ public DelegateCommand ConfirmCommand =>
|
|
|
+ _ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand));
|
|
|
+
|
|
|
+ private DelegateCommand _CancelCommand;
|
|
|
+ public DelegateCommand CancelCommand =>
|
|
|
+ _CancelCommand ?? (_CancelCommand = new DelegateCommand(ExecuteCancelCommand));
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 事件
|
|
|
+ public event Action<IDialogResult> RequestClose;
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
@@ -117,7 +132,30 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
}
|
|
|
|
|
|
#region 方法
|
|
|
+ /// <summary>
|
|
|
+ /// 确定
|
|
|
+ /// </summary>
|
|
|
+ void ExecuteConfirmCommand()
|
|
|
+ {
|
|
|
+ if (CorrectPoints == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ IDialogParameters parameters = new DialogParameters();
|
|
|
+ parameters.Add("CorrectPoints", CorrectPoints);
|
|
|
+ RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parameters));
|
|
|
+ }
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 取消
|
|
|
+ /// </summary>
|
|
|
+ void ExecuteCancelCommand()
|
|
|
+ {
|
|
|
+ IDialogParameters parameters = new DialogParameters();
|
|
|
+ parameters.Add("CorrectPoints", CorrectPoints);
|
|
|
+ RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel, parameters));
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 开始校准
|
|
|
@@ -127,6 +165,7 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
IsExecuting= true;
|
|
|
try
|
|
|
{
|
|
|
+
|
|
|
if (Robot == null || !Robot.IsConnected)
|
|
|
{
|
|
|
_eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
@@ -180,7 +219,7 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ _cts = new CancellationTokenSource();
|
|
|
//移动机器人至拍照点位,拍照
|
|
|
var rpoint = new RPoint()
|
|
|
{
|
|
|
@@ -195,7 +234,8 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
// 执行拍照并获取识别结果
|
|
|
var recognitionResult = await _remoteCommandService.ExecutePhotoGetSinglePointWithImage(procedure, null, new double[] { rpoint.X, rpoint.Y, 0 }, _cts.Token);
|
|
|
Image= recognitionResult.Image;
|
|
|
- Graphic= recognitionResult.Graphic;
|
|
|
+ Graphic = null;
|
|
|
+ Graphic = recognitionResult.Graphic;
|
|
|
if (!recognitionResult.IsSucceed)
|
|
|
{
|
|
|
_eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "拍照获取识别结果失败,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
@@ -206,11 +246,11 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
//移动机器人至拍照点位,拍照
|
|
|
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,
|
|
|
+ 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)
|
|
|
@@ -219,6 +259,7 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
// 执行拍照并获取识别结果
|
|
|
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)
|
|
|
{
|
|
|
@@ -248,17 +289,17 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
|
|
|
for (int i = 0; i < product.ScrewPoints.Count; i++)
|
|
|
{
|
|
|
- var localPoint = new PointF(product.ScrewCameraPoints[i].X_Position, product.ScrewCameraPoints[i].Y_Position);
|
|
|
+ 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[i].Clone();
|
|
|
+ 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 - screwCameraPoint[0].Z_Position_Start;
|
|
|
+ var deltaZ = product.ScrewPoints[i].Z_Position_Start - screwCameraLocalPoint1.Z_Position_Start;
|
|
|
|
|
|
//计算相机去拍照点位
|
|
|
- point.X_Position+= cameraOffsetX;
|
|
|
- point.Y_Position+= cameraOffsetY;
|
|
|
+ point.X_Position-= cameraOffsetX;
|
|
|
+ point.Y_Position-= cameraOffsetY;
|
|
|
point.Z_Position_Start= screwCameraPoint[0].Z_Position_Start + deltaZ;
|
|
|
|
|
|
//移动机器人至拍照点位,拍照
|
|
|
@@ -277,6 +318,7 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
// 执行拍照并获取识别结果
|
|
|
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)
|
|
|
{
|
|
|
@@ -292,10 +334,10 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- catch (Exception)
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
-
|
|
|
- throw;
|
|
|
+ LogHelper.WriteLogError("通过移动相机自动校准锁付点位是出错!",ex);
|
|
|
+ _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
@@ -319,6 +361,35 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
+ #region 继承
|
|
|
+
|
|
|
+ public bool CanCloseDialog()
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void OnDialogClosed()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void OnDialogOpened(IDialogParameters parameters)
|
|
|
+ {
|
|
|
+ Robot = parameters.GetValue<IRobot>("Robot");
|
|
|
+ AllScrewPoint = parameters.GetValue<List<PlcPoint>>("Points");
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="navigationContext"></param>
|
|
|
+ /// <param name="continuationCallback"></param>
|
|
|
+ public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
|
|
|
+ {
|
|
|
+ continuationCallback(true);
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
public class PointEx : BindableBase
|
|
|
{
|
|
|
private int _Number;
|
|
|
@@ -336,6 +407,9 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
}
|
|
|
|
|
|
private float _PreX;
|
|
|
+ /// <summary>
|
|
|
+ /// 校准前的坐标
|
|
|
+ /// </summary>
|
|
|
public float PreX
|
|
|
{
|
|
|
get { return _PreX; }
|
|
|
@@ -343,6 +417,9 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
}
|
|
|
|
|
|
private float _PreY;
|
|
|
+ /// <summary>
|
|
|
+ /// 校准前的坐标
|
|
|
+ /// </summary>
|
|
|
public float PreY
|
|
|
{
|
|
|
get { return _PreY; }
|
|
|
@@ -350,6 +427,9 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
}
|
|
|
|
|
|
private float _PostX;
|
|
|
+ /// <summary>
|
|
|
+ /// 校准后的坐标
|
|
|
+ /// </summary>
|
|
|
public float PostX
|
|
|
{
|
|
|
get { return _PostX; }
|
|
|
@@ -357,6 +437,9 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
}
|
|
|
|
|
|
private float _PostY;
|
|
|
+ /// <summary>
|
|
|
+ /// 校准后的坐标
|
|
|
+ /// </summary>
|
|
|
public float PostY
|
|
|
{
|
|
|
get { return _PostY; }
|