|
|
@@ -9,6 +9,8 @@ using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
|
using System.Linq;
|
|
|
+using System.Threading;
|
|
|
+using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
using TeamAAS_VP.Core;
|
|
|
using TeamAAS_VP.Core.PLCs;
|
|
|
@@ -20,6 +22,7 @@ using TeamAAS_VP.Models;
|
|
|
using TeamAAS_VP.Models.PLC;
|
|
|
using TeamAAS_VP.Models.Robot;
|
|
|
using TeamAAS_VP.Resources.Languages;
|
|
|
+using TeamAAS_VP.Services;
|
|
|
using TeamAAS_VP.Views.Product;
|
|
|
|
|
|
namespace TeamAAS_VP.ViewModels.Product
|
|
|
@@ -33,6 +36,7 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
IConfigService _configService;
|
|
|
IRobotService _robotService;
|
|
|
ISystemDatabaseService _systemDatabaseService;
|
|
|
+ IRemoteCommandService _remoteCommandService;
|
|
|
|
|
|
#region 属性
|
|
|
|
|
|
@@ -155,6 +159,31 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private ObservableCollection<ProcedureModel> _ProcedureModels;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 流程集合
|
|
|
+ /// </summary>
|
|
|
+ public ObservableCollection<ProcedureModel> ProcedureModels
|
|
|
+ {
|
|
|
+ get { return _ProcedureModels; }
|
|
|
+ set { SetProperty(ref _ProcedureModels, value); }
|
|
|
+ }
|
|
|
+
|
|
|
+ private ProcedureModel _SelectProcedure;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 选中的流程
|
|
|
+ /// </summary>
|
|
|
+ public ProcedureModel SelectProcedure
|
|
|
+ {
|
|
|
+ get { return _SelectProcedure; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref _SelectProcedure, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
#endregion
|
|
|
|
|
|
#region 命令
|
|
|
@@ -229,7 +258,7 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
#endregion
|
|
|
|
|
|
public PlcPointParamsViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService,
|
|
|
- IConfigService configService, IRobotService robotService, ISystemDatabaseService systemDatabaseService)
|
|
|
+ IConfigService configService, IRobotService robotService, ISystemDatabaseService systemDatabaseService, IRemoteCommandService remoteCommandService)
|
|
|
{
|
|
|
_regionManager = regionManager;
|
|
|
_eventAggregator = ea;
|
|
|
@@ -241,6 +270,7 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
_eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
|
|
|
management = _container.Resolve<Management>();
|
|
|
_robotService = robotService;
|
|
|
+ _remoteCommandService = remoteCommandService;
|
|
|
}
|
|
|
|
|
|
#region 方法
|
|
|
@@ -501,7 +531,9 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
switch (SelectedIndex)
|
|
|
{
|
|
|
case 0:
|
|
|
+
|
|
|
Points = SelectProduct.PickCameraPoints;
|
|
|
+ PickPoints= SelectProduct.PickPoints;
|
|
|
break;
|
|
|
case 1:
|
|
|
Points = SelectProduct.PickPoints;
|
|
|
@@ -746,6 +778,14 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
{
|
|
|
Robot.EnterDebugMode = true;
|
|
|
}
|
|
|
+ ProcedureModels = new ObservableCollection<ProcedureModel>();
|
|
|
+ foreach (var item in SelectProduct.CameraProcedures)
|
|
|
+ {
|
|
|
+ foreach (var item1 in item.ProcedureModels)
|
|
|
+ {
|
|
|
+ ProcedureModels.Add(item1);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
@@ -776,6 +816,115 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
+ #region 取料拍照点位矫正
|
|
|
+ private PlcPoint _SelectedCameraForPickPoint;
|
|
|
+ public PlcPoint SelectedCameraForPickPoint
|
|
|
+ {
|
|
|
+ get { return _SelectedCameraForPickPoint; }
|
|
|
+ set { SetProperty(ref _SelectedCameraForPickPoint, value); }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private ObservableCollection<PlcPoint> _PickPoints = new ObservableCollection<PlcPoint>();
|
|
|
+ /// <summary>
|
|
|
+ /// 取料点位集合
|
|
|
+ /// </summary>
|
|
|
+ public ObservableCollection<PlcPoint> PickPoints
|
|
|
+ {
|
|
|
+ get { return _PickPoints; }
|
|
|
+ set { SetProperty(ref _PickPoints, value); }
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
+ private PlcPoint _SelectedPickPoint;
|
|
|
+ /// <summary>
|
|
|
+ /// 选中的取料点位
|
|
|
+ /// </summary>
|
|
|
+ public PlcPoint SelectedPickPoint
|
|
|
+ {
|
|
|
+ get { return _SelectedPickPoint; }
|
|
|
+ set { SetProperty(ref _SelectedPickPoint, value); }
|
|
|
+ }
|
|
|
+
|
|
|
+ private DelegateCommand _AutoCorrectPickPointCommand;
|
|
|
+ public DelegateCommand AutoCorrectPickPointCommand =>
|
|
|
+ _AutoCorrectPickPointCommand ?? (_AutoCorrectPickPointCommand = new DelegateCommand(ExecuteAutoCorrectPickPointCommand, CanExecuteAutoCorrectPickPointCommand)
|
|
|
+ .ObservesProperty(()=> SelectedCameraForPickPoint).ObservesProperty(() => SelectedPickPoint).ObservesProperty(() => SelectProcedure).ObservesProperty(() => IsExecutingAutoCorrectPickPoint));
|
|
|
+
|
|
|
+ //
|
|
|
+ private bool _IsExecutingAutoCorrectPickPoint = false;
|
|
|
+ /// <summary>
|
|
|
+ /// 正在执行取料拍照点位矫正
|
|
|
+ /// </summary>
|
|
|
+ public bool IsExecutingAutoCorrectPickPoint
|
|
|
+ {
|
|
|
+ get { return _IsExecutingAutoCorrectPickPoint; }
|
|
|
+ set { SetProperty(ref _IsExecutingAutoCorrectPickPoint, value); }
|
|
|
+ }
|
|
|
+
|
|
|
+ async void ExecuteAutoCorrectPickPointCommand()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ IsExecutingAutoCorrectPickPoint = true;
|
|
|
+ if (SelectedCameraForPickPoint == null || SelectedPickPoint == null || SelectProcedure == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (Robot == null || !Robot.IsConnected)
|
|
|
+ {
|
|
|
+ _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (MessageBox.Show("确认要执行取料拍照点位矫正吗?", "取料拍照点位矫正", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 控制机器人移动至拍照点位
|
|
|
+ var rpoint = new RPoint()
|
|
|
+ {
|
|
|
+ X = SelectedCameraForPickPoint.X_Position,
|
|
|
+ Y = SelectedCameraForPickPoint.Y_Position,
|
|
|
+ Z = SelectedCameraForPickPoint.Z_Position_Start,
|
|
|
+ U = SelectedCameraForPickPoint.U_Position,
|
|
|
+ V = SelectedCameraForPickPoint.R_Position,
|
|
|
+ };
|
|
|
+ await Robot.CalibMotionAsync(rpoint, 0);
|
|
|
+
|
|
|
+ var _cts = new CancellationTokenSource();
|
|
|
+ // 2. 执行拍照并获取识别结果
|
|
|
+ var recognitionResult = _remoteCommandService.ExecutePhotoGetSinglePoint(SelectProcedure, null, new double[] { rpoint.X, rpoint.Y, 0 }, _cts.Token);
|
|
|
+ if (!recognitionResult.IsSucceed)
|
|
|
+ {
|
|
|
+ _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "取料拍照点位矫正失败,识别未成功!", Duration = 1 });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 根据识别结果更新取料点位坐标
|
|
|
+ SelectedPickPoint.X_Position = (float)recognitionResult.X;
|
|
|
+ SelectedPickPoint.Y_Position = (float)recognitionResult.Y;
|
|
|
+
|
|
|
+ _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "取料拍照点位矫正完成!", Duration = 0.4 });
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogHelper.WriteLogError("取料拍照点位矫正时出错!", ex);
|
|
|
+ _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ IsExecutingAutoCorrectPickPoint = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ bool CanExecuteAutoCorrectPickPointCommand()
|
|
|
+ {
|
|
|
+ return SelectedCameraForPickPoint!=null && SelectedPickPoint!=null && SelectProcedure!=null && !IsExecutingAutoCorrectPickPoint;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
private bool _IsAllowEdit = false;
|
|
|
|
|
|
public bool IsAllowEdit
|