|
|
@@ -46,6 +46,7 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
IRemoteCommandService _remoteCommandService;
|
|
|
ICalibrationService _calibrationService;
|
|
|
ICameraService _cameraService;
|
|
|
+ IProductService _productService;
|
|
|
CoordinateTransformer local=null;
|
|
|
|
|
|
#region 属性
|
|
|
@@ -354,6 +355,12 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private int _Inhal=1;
|
|
|
+ public int Inhal
|
|
|
+ {
|
|
|
+ get { return _Inhal; }
|
|
|
+ set { SetProperty(ref _Inhal, value); }
|
|
|
+ }
|
|
|
#endregion
|
|
|
|
|
|
#region 命令
|
|
|
@@ -420,30 +427,6 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
public DelegateCommand ImportCadPointCommand =>
|
|
|
_ImportCadPointCommand ?? (_ImportCadPointCommand = new DelegateCommand(ExecuteImportCadPointCommand));
|
|
|
|
|
|
- private DelegateCommand _ImportCadLockCameraPointCommand;
|
|
|
- public DelegateCommand ImportCadLockCameraPointCommand =>
|
|
|
- _ImportCadLockCameraPointCommand ?? (_ImportCadLockCameraPointCommand = new DelegateCommand(ExecuteImportCadLockCameraPointCommand));
|
|
|
-
|
|
|
- private DelegateCommand _ApplyLockPointStartZCommand;
|
|
|
- public DelegateCommand ApplyLockPointStartZCommand =>
|
|
|
- _ApplyLockPointStartZCommand ?? (_ApplyLockPointStartZCommand = new DelegateCommand(ExecuteApplyLockPointStartZCommand));
|
|
|
-
|
|
|
- private DelegateCommand _ApplyLockPointDepthCommand;
|
|
|
- public DelegateCommand ApplyLockPointDepthCommand =>
|
|
|
- _ApplyLockPointDepthCommand ?? (_ApplyLockPointDepthCommand = new DelegateCommand(ExecuteApplyLockPointDepthCommand));
|
|
|
-
|
|
|
- private DelegateCommand _ApplyLockPointSpeedCommand;
|
|
|
- public DelegateCommand ApplyLockPointSpeedCommand =>
|
|
|
- _ApplyLockPointSpeedCommand ?? (_ApplyLockPointSpeedCommand = new DelegateCommand(ExecuteApplyLockPointSpeedCommand));
|
|
|
-
|
|
|
- private DelegateCommand _ApplyLockPointFeederAndScrewProgramCommand;
|
|
|
- public DelegateCommand ApplyLockPointFeederAndScrewProgramCommand =>
|
|
|
- _ApplyLockPointFeederAndScrewProgramCommand ?? (_ApplyLockPointFeederAndScrewProgramCommand = new DelegateCommand(ExecuteApplyLockPointFeederAndScrewProgramCommand));
|
|
|
-
|
|
|
- private DelegateCommand _AutoCorrectLockPointCommand;
|
|
|
- public DelegateCommand AutoCorrectLockPointCommand =>
|
|
|
- _AutoCorrectLockPointCommand ?? (_AutoCorrectLockPointCommand = new DelegateCommand(ExecuteAutoCorrectLockPoint));
|
|
|
-
|
|
|
private DelegateCommand _StartGrabbingCommand;
|
|
|
public DelegateCommand StartGrabbingCommand =>
|
|
|
_StartGrabbingCommand ?? (_StartGrabbingCommand = new DelegateCommand(ExecuteStartGrabbingCommand, CanExecuteStartGrabbingCommand).ObservesProperty(() => IsGrap).ObservesProperty(()=> SelectedCamera));
|
|
|
@@ -470,6 +453,19 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
public DelegateCommand<object> AdditionalAxisMotorOffCommand =>
|
|
|
_AdditionalAxisMotorOffCommand ?? (_AdditionalAxisMotorOffCommand = new DelegateCommand<object>(ExecuteAdditionalAxisMotorOffCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
|
|
|
|
|
|
+ private DelegateCommand _GoPickCommand;
|
|
|
+ public DelegateCommand GoPickCommand =>
|
|
|
+ _GoPickCommand ?? (_GoPickCommand = new DelegateCommand(ExecuteGoPickCommand, CanExecuteCommandGoPickCommandName).ObservesProperty(()=>SelectedPoint));
|
|
|
+
|
|
|
+ private DelegateCommand _GoRepositionCommand;
|
|
|
+ public DelegateCommand GoRepositionCommand =>
|
|
|
+ _GoRepositionCommand ?? (_GoRepositionCommand = new DelegateCommand(ExecuteGoRepositionCommand, CanExecuteCommandGoPickCommandName).ObservesProperty(() => SelectedPoint));
|
|
|
+
|
|
|
+ private DelegateCommand _TakeProductPhotoCommand;
|
|
|
+ public DelegateCommand TakeProductPhotoCommand =>
|
|
|
+ _TakeProductPhotoCommand ?? (_TakeProductPhotoCommand = new DelegateCommand(ExecuteTakeProductPhotoCommand, CanExecuteCommandGoPickCommandName).ObservesProperty(() => SelectedPoint));
|
|
|
+
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
#region 事件
|
|
|
@@ -478,7 +474,7 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
|
|
|
public PlcPointParamsViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService,
|
|
|
IConfigService configService, IRobotService robotService, ISystemDatabaseService systemDatabaseService, IRemoteCommandService remoteCommandService,
|
|
|
- ICalibrationService calibrationService, ICameraService cameraService)
|
|
|
+ ICalibrationService calibrationService, ICameraService cameraService, IProductService productService)
|
|
|
{
|
|
|
_regionManager = regionManager;
|
|
|
_eventAggregator = ea;
|
|
|
@@ -493,6 +489,7 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
_remoteCommandService = remoteCommandService;
|
|
|
_calibrationService = calibrationService;
|
|
|
_cameraService = cameraService;
|
|
|
+ _productService = productService;
|
|
|
}
|
|
|
|
|
|
#region 方法
|
|
|
@@ -620,33 +617,25 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
if (Robot == null || !Robot.IsConnected) return;
|
|
|
try
|
|
|
{
|
|
|
- if (SelectedIndex == 4)
|
|
|
+ //确认要执行该点位的该运动指令吗
|
|
|
+ if (MessageBox.Show($"确认要执行点位 {SelectedPoint.Number} 的 {motionCmd} 指令吗?", "执行点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
|
|
|
{
|
|
|
- await ExecuteAutoCorrectLockPointAndExecuteCommand(SelectedPoint);
|
|
|
+ return;
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- //确认要执行该点位的该运动指令吗
|
|
|
- if (MessageBox.Show($"确认要执行点位 {SelectedPoint.Number} 的 {motionCmd} 指令吗?", "执行点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
- //Robot.Timeout = 6000000;
|
|
|
- switch (motionCmd)
|
|
|
- {
|
|
|
- case MotionCommand.Go:
|
|
|
- await Robot.GoAsync(point);
|
|
|
- break;
|
|
|
- case MotionCommand.Jump:
|
|
|
- await Robot.JumpAsync(point, 0);
|
|
|
- break;
|
|
|
- case MotionCommand.Move:
|
|
|
- await Robot.MoveAsync(point);
|
|
|
- break;
|
|
|
- }
|
|
|
- //Robot.Timeout = 5000;
|
|
|
- }
|
|
|
+ //Robot.Timeout = 6000000;
|
|
|
+ switch (motionCmd)
|
|
|
+ {
|
|
|
+ case MotionCommand.Go:
|
|
|
+ await Robot.GoAsync(point);
|
|
|
+ break;
|
|
|
+ case MotionCommand.Jump:
|
|
|
+ await Robot.JumpAsync(point, 0);
|
|
|
+ break;
|
|
|
+ case MotionCommand.Move:
|
|
|
+ await Robot.MoveAsync(point);
|
|
|
+ break;
|
|
|
+ }
|
|
|
_eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
@@ -837,9 +826,7 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
switch (SelectedIndex)
|
|
|
{
|
|
|
case 0:
|
|
|
-
|
|
|
Points = SelectProduct.PickCameraPoints;
|
|
|
- PickPoints = SelectProduct.PickPoints;
|
|
|
break;
|
|
|
case 1:
|
|
|
Points = SelectProduct.PickPoints;
|
|
|
@@ -1049,487 +1036,6 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 导入锁付拍照引导的产品坐标系中的点位
|
|
|
- /// </summary>
|
|
|
- async void ExecuteImportCadLockCameraPointCommand()
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- var view = new DxfView();
|
|
|
-
|
|
|
- //show the dialog
|
|
|
- var result = await DialogHost.Show(view, "RootDialog", null, null, null);
|
|
|
- if (result != null)
|
|
|
- {
|
|
|
- var cadPoints = view.Points;
|
|
|
- if (cadPoints != null && cadPoints.Count == 2)
|
|
|
- {
|
|
|
- //弹窗提示用户是否确认要导入锁付拍照引导的起始点和结束点
|
|
|
- if (MessageBox.Show($"确认要导入锁付拍照引导的起始点和结束点吗?", "导入点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- //导入点位
|
|
|
- //起始点
|
|
|
- var startPoint = cadPoints[0];
|
|
|
- SelectProduct.ScrewCameraLocalPos1.X_Position = startPoint.X;
|
|
|
- SelectProduct.ScrewCameraLocalPos1.Y_Position = startPoint.Y;
|
|
|
-
|
|
|
- //结束点
|
|
|
- var endPoint = cadPoints[1];
|
|
|
- SelectProduct.ScrewCameraLocalPos2.X_Position = endPoint.X;
|
|
|
- SelectProduct.ScrewCameraLocalPos2.Y_Position = endPoint.Y;
|
|
|
-
|
|
|
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "请导入两个点,分别为锁付拍照引导的起始点和结束点!", Duration = 1 });
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- LogHelper.WriteLogError("导入CAD点位时出错!", ex);
|
|
|
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 批量设置锁付点的供料器编号和螺丝程序编号
|
|
|
- /// </summary>
|
|
|
- void ExecuteApplyLockPointFeederAndScrewProgramCommand()
|
|
|
- {
|
|
|
- //检查供料器编号和螺丝程序编号是否大于0,如果小于等于0,则提示用户编号是否正确,是否继续写入
|
|
|
- if (LockFeederNumber <= 0 || LockScrewProgramNumber <= 0)
|
|
|
- {
|
|
|
- var result = MessageBox.Show("供料器编号或螺丝程序编号小于等于0,是否继续写入?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
- if (result != MessageBoxResult.Yes)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //遍历所有点位,设置供料器编号和螺丝程序编号
|
|
|
- foreach (var point in Points)
|
|
|
- {
|
|
|
- point.Feeder = LockFeederNumber;
|
|
|
- point.ScrewProNum = LockScrewProgramNumber;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 批量设置锁付点的速度
|
|
|
- /// </summary>
|
|
|
- void ExecuteApplyLockPointSpeedCommand()
|
|
|
- {
|
|
|
- //检查速度是否大于0,如果小于等于0,则提示用户速度是否正确,是否继续写入
|
|
|
- if (LockXSpeed <= 0 || LockYSpeed <= 0 || LockZSpeed <= 0 || LockZDescendSpeed <= 0)
|
|
|
- {
|
|
|
- var result = MessageBox.Show("速度小于等于0,是否继续写入?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
- if (result != MessageBoxResult.Yes)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //遍历所有点位,设置速度
|
|
|
- foreach (var point in Points)
|
|
|
- {
|
|
|
- point.X_Velocity = LockXSpeed;
|
|
|
- point.Y_Velocity = LockYSpeed;
|
|
|
- point.Z_Velocity_Start = LockZSpeed;
|
|
|
- point.Z_Velocity_Stop = LockZDescendSpeed;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 批量设置锁付点的Z深度
|
|
|
- /// </summary>
|
|
|
- void ExecuteApplyLockPointDepthCommand()
|
|
|
- {
|
|
|
- //检查深度是否大于0,如果小于等于0,则提示用户深度是否正确,是否继续写入
|
|
|
- if (LockZDepth <= 0)
|
|
|
- {
|
|
|
- var result = MessageBox.Show("深度小于等于0,是否继续写入?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
- if (result != MessageBoxResult.Yes)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //遍历所有点位,设置Z深度
|
|
|
- foreach (var point in Points)
|
|
|
- {
|
|
|
- point.Z_Position_Stop = point.Z_Position_Start - LockZDepth;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 批量设置锁付点的起始Z坐标
|
|
|
- /// </summary>
|
|
|
- void ExecuteApplyLockPointStartZCommand()
|
|
|
- {
|
|
|
- //检查起始Z坐标是否小于0,如果大于等于0,则提示用户坐标是否正确,是否继续写入
|
|
|
- if (LockPointStartZ >= 0)
|
|
|
- {
|
|
|
- var result = MessageBox.Show("起始Z坐标大于等于0,是否继续写入?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
- if (result != MessageBoxResult.Yes)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //遍历所有点位,设置起始Z坐标
|
|
|
- foreach (var point in Points)
|
|
|
- {
|
|
|
- point.Z_Position_Start = LockPointStartZ;
|
|
|
- }
|
|
|
-
|
|
|
- //检查终点坐标是否小于等于起始坐标,如果不是,则提示用户终点坐标大于等于起始坐标,用户需要去调整终点坐标
|
|
|
- foreach (var point in Points)
|
|
|
- {
|
|
|
- if (point.Z_Position_Stop >= point.Z_Position_Start)
|
|
|
- {
|
|
|
- MessageBox.Show($"点位编号 {point.Number} 的终点坐标大于等于起始坐标,请调整终点坐标!", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 通过相机自动矫正锁附点位
|
|
|
- /// </summary>
|
|
|
- async void ExecuteAutoCorrectLockPoint()
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (Camera != null)
|
|
|
- {
|
|
|
- if (Camera.IsGrabbing)
|
|
|
- {
|
|
|
- ExecuteStopGrabbingCommand();
|
|
|
- }
|
|
|
- }
|
|
|
- //弹窗提示用户是否确认要通过相机自动矫正锁附点位
|
|
|
- var resultConfirm = MessageBox.Show("确认要通过相机自动矫正锁附点位吗?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
- if (resultConfirm != MessageBoxResult.Yes)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- //获取螺丝相机拍照点位
|
|
|
- var screwCameraPoint = SelectProduct.ScrewCameraPoints;
|
|
|
- //获取相机拍照点对应的LocalPos
|
|
|
- var screwCameraLocalPos1 = SelectProduct.ScrewCameraLocalPos1;
|
|
|
- var screwCameraLocalPos2 = SelectProduct.ScrewCameraLocalPos2;
|
|
|
- //获取螺丝锁付点位
|
|
|
- var screwLockPoints = SelectProduct.ScrewPoints;
|
|
|
- //检查screwLockPoints中是否有和screwCameraLocalPos1的XY坐标相同的点位
|
|
|
- var matchingPoint = screwLockPoints.FirstOrDefault(p => p.X_Position == screwCameraLocalPos1.X_Position && p.Y_Position == screwCameraLocalPos1.Y_Position);
|
|
|
- if (matchingPoint != null)
|
|
|
- {
|
|
|
- //检查两个点位的Z是否一致?如果不一致,则提示用户锁付点位中有和锁付拍照引导起始点Local坐标相同的点位,且Z坐标不一致,是否将锁付拍照引导起始点Local坐标的Z轴坐标更新为锁付点位的Z坐标
|
|
|
- if (matchingPoint.Z_Position_Start != screwCameraLocalPos1.Z_Position_Start)
|
|
|
- {
|
|
|
- var resultUpdateZ = MessageBox.Show("锁付点位中有和锁付拍照引导起始点Local坐标相同的点位,且Z坐标不一致,是否将锁付拍照引导起始点Local坐标的Z轴坐标更新为锁付点位的Z坐标?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
- if (resultUpdateZ == MessageBoxResult.Yes)
|
|
|
- {
|
|
|
- screwCameraLocalPos1.Z_Position_Start = matchingPoint.Z_Position_Start;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //检查screwLockPoints中是否有和screwCameraLocalPos2的XY坐标相同的点位
|
|
|
- matchingPoint = screwLockPoints.FirstOrDefault(p => p.X_Position == screwCameraLocalPos2.X_Position && p.Y_Position == screwCameraLocalPos2.Y_Position);
|
|
|
- if (matchingPoint != null)
|
|
|
- {
|
|
|
- //检查两个点位的Z是否一致?如果不一致,则提示用户锁付点位中有和锁付拍照引导结束点Local坐标相同的点位,且Z坐标不一致,是否将锁付拍照引导结束点Local坐标的Z轴坐标更新为锁付点位的Z坐标
|
|
|
- if (matchingPoint.Z_Position_Start != screwCameraLocalPos2.Z_Position_Start)
|
|
|
- {
|
|
|
- var resultUpdateZ = MessageBox.Show("锁付点位中有和锁付拍照引导结束点Local坐标相同的点位,且Z坐标不一致,是否将锁付拍照引导结束点Local坐标的Z轴坐标更新为锁付点位的Z坐标?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
- if (resultUpdateZ == MessageBoxResult.Yes)
|
|
|
- {
|
|
|
- screwCameraLocalPos2.Z_Position_Start = matchingPoint.Z_Position_Start;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- IDialogParameters parameters = new DialogParameters();
|
|
|
- parameters.Add("Robot", Robot);
|
|
|
- parameters.Add("SelectProduct", SelectProduct);
|
|
|
- parameters.Add("Points", new List<PlcPoint>(SelectProduct.ScrewPoints.ToArray()));
|
|
|
- _dialogService.Show("AutoCorrectLockPoint", parameters, rst =>
|
|
|
- {
|
|
|
- //对话框关闭之后的回调函数,可以在这解析结果。
|
|
|
- ButtonResult result1 = rst.Result;
|
|
|
-
|
|
|
- if (result1 == ButtonResult.OK)
|
|
|
- {
|
|
|
- var param = rst.Parameters.GetValue<ObservableCollection<PointEx>>("CorrectPoints");
|
|
|
- var local1= rst.Parameters.GetValue<CoordinateTransformer>("Local");
|
|
|
- if (local1!=null)
|
|
|
- {
|
|
|
- local = local1;
|
|
|
- }
|
|
|
- for (int i = 0; i < SelectProduct.ScrewPoints.Count; i++)
|
|
|
- {
|
|
|
- SelectProduct.ScrewPoints[i].X_Position = param[i].PostX;
|
|
|
- SelectProduct.ScrewPoints[i].Y_Position = param[i].PostY;
|
|
|
- }
|
|
|
-
|
|
|
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "完成!", Duration = 1 });
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- LogHelper.WriteLogError("通过相机自动矫正锁附点位时出错!", ex);
|
|
|
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 通过相机先定位产品再执行锁付点位
|
|
|
- /// </summary>
|
|
|
- /// <param name="point"></param>
|
|
|
- private async Task ExecuteAutoCorrectLockPointAndExecuteCommand(PlcPoint point)
|
|
|
- {
|
|
|
- var waiting = new WaitingControl();
|
|
|
- Task<object> task;
|
|
|
- try
|
|
|
- {
|
|
|
- if (Camera != null)
|
|
|
- {
|
|
|
- if (Camera.IsGrabbing)
|
|
|
- {
|
|
|
- ExecuteStopGrabbingCommand();
|
|
|
- }
|
|
|
- }
|
|
|
- if (Robot == null || !Robot.IsConnected) return;
|
|
|
- //弹窗提示用户是否确认要通过相机自动矫正锁附点位并执行该点位
|
|
|
- var resultConfirm = MessageBox.Show($"确认要通过相机自动矫正锁附点位并执行点位 {point.Number} 吗?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
- if (resultConfirm != MessageBoxResult.Yes)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- 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;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- //如果当前Local为空,则自动进行锁付点位的Local计算
|
|
|
- if (local == null)
|
|
|
- {
|
|
|
- //show the dialog
|
|
|
- task = DialogHost.Show(waiting, "RootDialog", null, null, null);
|
|
|
- var isCalibSucceed = await AutoCalibLockPointLocal(product);
|
|
|
- if (!isCalibSucceed)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //提示用户,当前系统检测到进入此界面后已经进行过相机产品定位并计算过Local,是否继续使用该Local进行锁付点位的转换计算
|
|
|
- var resultUseExistingLocal = MessageBox.Show("系统检测到进入此界面后已经进行过相机产品定位并计算过Local,是否继续使用该Local进行锁付点位的转换计算?点击“是”继续使用,点击“否”则重新进行锁付点位的Local计算。", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
- if (resultUseExistingLocal == MessageBoxResult.No)
|
|
|
- {
|
|
|
- //show the dialog
|
|
|
- task = DialogHost.Show(waiting, "RootDialog", null, null, null);
|
|
|
- var isCalibSucceed = await AutoCalibLockPointLocal(product);
|
|
|
- if (!isCalibSucceed)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //show the dialog
|
|
|
- task = DialogHost.Show(waiting, "RootDialog", null, null, null);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //将锁付点位转换到世界坐标系
|
|
|
- var localPoint = new PointF(point.X_Position, point.Y_Position);
|
|
|
- var worldPoint = local.ToOldCoord(localPoint.X, localPoint.Y);
|
|
|
- var point1 = point.Clone();
|
|
|
- point1.X_Position = (float)worldPoint[0];
|
|
|
- point1.Y_Position = (float)worldPoint[1];
|
|
|
- //执行该点位
|
|
|
- //移动机器人至拍照点位,拍照
|
|
|
- var rpoint = new RPoint()
|
|
|
- {
|
|
|
- X = point1.X_Position,
|
|
|
- Y = point1.Y_Position,
|
|
|
- Z = point1.Z_Position_Start,
|
|
|
- };
|
|
|
- await Robot.CalibMotionAsync(rpoint, 0);
|
|
|
-
|
|
|
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "完成!", Duration = 1 });
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- LogHelper.WriteLogError("通过相机自动矫正锁附点位并执行时出错!", ex);
|
|
|
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (DialogHost.IsDialogOpen("RootDialog"))
|
|
|
- {
|
|
|
- DialogHost.Close("RootDialog");
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception)
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 移动相机拍产品两个Msrk点计算Local
|
|
|
- /// </summary>
|
|
|
- /// <param name="product"></param>
|
|
|
- /// <returns></returns>
|
|
|
- private async Task<bool> AutoCalibLockPointLocal(ProductModel product)
|
|
|
- {
|
|
|
- return true;
|
|
|
- //try
|
|
|
- //{
|
|
|
- // //获取锁付相机拍照点位
|
|
|
- // var screwCameraPoint = product.ScrewCameraPoints;
|
|
|
- // if (screwCameraPoint == null || screwCameraPoint.Count < 2)
|
|
|
- // {
|
|
|
- // _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "未获取到锁付相机拍照点位,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
- // return false;
|
|
|
- // }
|
|
|
- // //获取相机拍照点位对应的锁付点
|
|
|
- // var screwCameraLocalPoint1 = product.ScrewCameraLocalPos1;
|
|
|
- // if (screwCameraLocalPoint1 == null)
|
|
|
- // {
|
|
|
- // _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "未获取到锁付相机拍照点位对应的锁付点,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
- // return false;
|
|
|
- // }
|
|
|
- // var screwCameraLocalPoint2 = product.ScrewCameraLocalPos2;
|
|
|
- // if (screwCameraLocalPoint2 == null)
|
|
|
- // {
|
|
|
- // _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "未获取到锁付相机拍照点位对应的锁付点,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
- // return false;
|
|
|
- // }
|
|
|
- // 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 false;
|
|
|
- // }
|
|
|
- // var procedure = ProcedureModels.FirstOrDefault(p => p.Id == product.MoveDownCameraLockPhotoProcedureId);
|
|
|
- // if (procedure == null)
|
|
|
- // {
|
|
|
- // _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "未获取到锁付相机拍照流程,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
- // return false;
|
|
|
- // }
|
|
|
-
|
|
|
- // CancellationTokenSource _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);
|
|
|
- // //var Image = recognitionResult.Image;
|
|
|
- // //var Graphic = null;
|
|
|
- // //var Graphic = recognitionResult.Graphic;
|
|
|
- // if (!recognitionResult.IsSucceed)
|
|
|
- // {
|
|
|
- // _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "拍照获取识别结果失败,无法执行取料拍照点位矫正!", Duration = 1 });
|
|
|
- // return false;
|
|
|
- // }
|
|
|
- // //第一个点位的校正结果
|
|
|
- // 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 false;
|
|
|
- // 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 false;
|
|
|
- // }
|
|
|
- // //第一个点位的校正结果
|
|
|
- // 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);
|
|
|
- // return true;
|
|
|
- //}
|
|
|
- //catch (Exception ex)
|
|
|
- //{
|
|
|
- // LogHelper.WriteLogError("计算锁付点位产品坐标系坐标时出错!", ex);
|
|
|
- // _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
|
|
|
- // return false;
|
|
|
- //}
|
|
|
- }
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// 停止采集
|
|
|
/// </summary>
|
|
|
@@ -1680,6 +1186,291 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
_eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 0.4 });
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 去取料
|
|
|
+ /// </summary>
|
|
|
+ async void ExecuteGoPickCommand()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (SelectedPoint == 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ var waiting = new WaitingControl();
|
|
|
+ //show the dialog
|
|
|
+ var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
|
|
|
+
|
|
|
+ // 1. 控制机器人移动至拍照点位
|
|
|
+ var rpoint = new RPoint()
|
|
|
+ {
|
|
|
+ X = SelectedPoint.X_Position,
|
|
|
+ Y = SelectedPoint.Y_Position,
|
|
|
+ Z = SelectedPoint.Z_Position_Start,
|
|
|
+ U = SelectedPoint.U_Position,
|
|
|
+ V = SelectedPoint.R_Position,
|
|
|
+ };
|
|
|
+ await Robot.CalibMotionAsync(rpoint, 0);
|
|
|
+
|
|
|
+ await Robot.CalibParameAsync(new PickInfo() { Inhal= Inhal,Blow=1},20,20,true,200,200);
|
|
|
+ //打开吸真空
|
|
|
+ await Robot.CalibOutIOAsync(true);
|
|
|
+
|
|
|
+ await Task.Delay(500);
|
|
|
+
|
|
|
+ rpoint.Z = 0;
|
|
|
+ await Robot.CalibMotionAsync(rpoint, 0);
|
|
|
+
|
|
|
+ if (DialogHost.IsDialogOpen("RootDialog"))
|
|
|
+ {
|
|
|
+ DialogHost.Close("RootDialog");
|
|
|
+ }
|
|
|
+ await task;
|
|
|
+
|
|
|
+ _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 });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ bool CanExecuteCommandGoPickCommandName()
|
|
|
+ {
|
|
|
+ return SelectedPoint != null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ToolCoord toolCoord = null;
|
|
|
+ /// <summary>
|
|
|
+ /// 去二次定位
|
|
|
+ /// </summary>
|
|
|
+ async void ExecuteGoRepositionCommand()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (SelectedPoint == 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ var waiting = new WaitingControl();
|
|
|
+ //show the dialog
|
|
|
+ var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
|
|
|
+
|
|
|
+ // 1. 控制机器人移动至拍照点位
|
|
|
+ var rpoint = new RPoint()
|
|
|
+ {
|
|
|
+ X = SelectedPoint.X_Position,
|
|
|
+ Y = SelectedPoint.Y_Position,
|
|
|
+ Z = SelectedPoint.Z_Position_Start,
|
|
|
+ U = SelectedPoint.U_Position,
|
|
|
+ V = SelectedPoint.R_Position,
|
|
|
+ };
|
|
|
+ await Robot.CalibMotionAsync(rpoint, 0);
|
|
|
+ await Task.Delay(200);
|
|
|
+
|
|
|
+ //获取固定向上相机1的流程
|
|
|
+ var process1 = _productService.GetCurrentProductProcedureModelById(SelectProduct.FixedUpCamera1ProcedureId);
|
|
|
+ if (process1 == null)
|
|
|
+ {
|
|
|
+ _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"固定向上相机1视觉流程,流程ID:{SelectProduct.FixedUpCamera1ProcedureId} 未找到!", Duration = 1 });
|
|
|
+ if (DialogHost.IsDialogOpen("RootDialog"))
|
|
|
+ {
|
|
|
+ DialogHost.Close("RootDialog");
|
|
|
+ }
|
|
|
+ await task;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //获取固定向上相机2的流程
|
|
|
+ var process2 = _productService.GetCurrentProductProcedureModelById(SelectProduct.FixedUpCamera2ProcedureId);
|
|
|
+ if (process2 == null)
|
|
|
+ {
|
|
|
+ _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"固定向上相机2视觉流程,流程ID:{SelectProduct.FixedUpCamera2ProcedureId} 未找到!", Duration = 1 });
|
|
|
+ if (DialogHost.IsDialogOpen("RootDialog"))
|
|
|
+ {
|
|
|
+ DialogHost.Close("RootDialog");
|
|
|
+ }
|
|
|
+ await task;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 执行视觉任务
|
|
|
+ var _cts = new CancellationTokenSource();
|
|
|
+ var task1 = _remoteCommandService.ExecutePhotoGetSinglePoint(process1, null, new double[] { rpoint.X, rpoint.Y, rpoint.U }, _cts.Token);
|
|
|
+ var task2 = _remoteCommandService.ExecutePhotoGetSinglePoint(process2, null, new double[] { rpoint.X, rpoint.Y, rpoint.U }, _cts.Token);
|
|
|
+ var visionResults = await Task.WhenAll(task1, task2);
|
|
|
+ if (visionResults[0].IsSucceed && visionResults[1].IsSucceed)
|
|
|
+ {
|
|
|
+ float tool1X = (float)(visionResults[0].X - visionResults[0].X);
|
|
|
+ float tool1Y = (float)(visionResults[0].Y - visionResults[0].Y);
|
|
|
+ float tool2X = (float)(visionResults[1].Y - visionResults[1].Y);
|
|
|
+ float tool2Y = (float)(visionResults[1].Y - visionResults[1].Y);
|
|
|
+ float toolX = (tool1X + tool2X) / 2;
|
|
|
+ float toolY = (tool1Y + tool2Y) / 2;
|
|
|
+ toolCoord = new ToolCoord();
|
|
|
+ toolCoord.SetTool(toolX, toolY);
|
|
|
+ _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "视觉定位成功!", Duration = 0.4 });
|
|
|
+ if (DialogHost.IsDialogOpen("RootDialog"))
|
|
|
+ {
|
|
|
+ DialogHost.Close("RootDialog");
|
|
|
+ }
|
|
|
+ await task;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "视觉定位失败,无法进行二次定位!", Duration = 1 });
|
|
|
+ if (DialogHost.IsDialogOpen("RootDialog"))
|
|
|
+ {
|
|
|
+ DialogHost.Close("RootDialog");
|
|
|
+ }
|
|
|
+ await task;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogHelper.WriteLogError("二次定位时出错!", ex);
|
|
|
+ _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
|
|
|
+ if (DialogHost.IsDialogOpen("RootDialog"))
|
|
|
+ {
|
|
|
+ DialogHost.Close("RootDialog");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 执行产品拍照
|
|
|
+ /// </summary>
|
|
|
+ async void ExecuteTakeProductPhotoCommand()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (SelectedPoint == 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果二次定位的工具坐标为空,则提示用户先进行二次定位
|
|
|
+ if (toolCoord == null)
|
|
|
+ {
|
|
|
+ _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "二次定位的工具坐标为空,无法执行产品拍照!", Duration = 1 });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var waiting = new WaitingControl();
|
|
|
+ //show the dialog
|
|
|
+ var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
|
|
|
+
|
|
|
+ // 1. 控制机器人移动至拍照点位
|
|
|
+ var rpoint = new RPoint()
|
|
|
+ {
|
|
|
+ X = SelectedPoint.X_Position,
|
|
|
+ Y = SelectedPoint.Y_Position,
|
|
|
+ Z = SelectedPoint.Z_Position_Start,
|
|
|
+ U = SelectedPoint.U_Position,
|
|
|
+ V = SelectedPoint.R_Position,
|
|
|
+ };
|
|
|
+ await Robot.CalibMotionAsync(rpoint, 0);
|
|
|
+ await Task.Delay(200);
|
|
|
+
|
|
|
+ //获取移动向下相机1的流程
|
|
|
+ var process1 = _productService.GetCurrentProductProcedureModelById(SelectProduct.MoveDownCamera1LockPhotoProcedureId);
|
|
|
+ if (process1 == null)
|
|
|
+ {
|
|
|
+ _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"移动向下相机1视觉流程,流程ID:{SelectProduct.MoveDownCamera1LockPhotoProcedureId} 未找到!", Duration = 1 });
|
|
|
+ if (DialogHost.IsDialogOpen("RootDialog"))
|
|
|
+ {
|
|
|
+ DialogHost.Close("RootDialog");
|
|
|
+ }
|
|
|
+ await task;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //获取移动向下相机2的流程
|
|
|
+ var process2 = _productService.GetCurrentProductProcedureModelById(SelectProduct.MoveDownCamera2LockPhotoProcedureId);
|
|
|
+ if (process2 == null)
|
|
|
+ {
|
|
|
+ _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"移动向下相机2视觉流程,流程ID:{SelectProduct.MoveDownCamera2LockPhotoProcedureId} 未找到!", Duration = 1 });
|
|
|
+ if (DialogHost.IsDialogOpen("RootDialog"))
|
|
|
+ {
|
|
|
+ DialogHost.Close("RootDialog");
|
|
|
+ }
|
|
|
+ await task;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 执行视觉任务
|
|
|
+ var _cts = new CancellationTokenSource();
|
|
|
+ var task1 = _remoteCommandService.ExecutePhotoGetSinglePoint(process1, null, new double[] { rpoint.X, rpoint.Y, rpoint.U }, _cts.Token);
|
|
|
+ var task2 = _remoteCommandService.ExecutePhotoGetSinglePoint(process2, null, new double[] { rpoint.X, rpoint.Y, rpoint.U }, _cts.Token);
|
|
|
+ var visionResults = await Task.WhenAll(task1, task2);
|
|
|
+ if (visionResults[0].IsSucceed && visionResults[1].IsSucceed)
|
|
|
+ {
|
|
|
+ float tool1X = (float)(visionResults[0].X - visionResults[0].X);
|
|
|
+ float tool1Y = (float)(visionResults[0].Y - visionResults[0].Y);
|
|
|
+ float tool2X = (float)(visionResults[1].Y - visionResults[1].Y);
|
|
|
+ float tool2Y = (float)(visionResults[1].Y - visionResults[1].Y);
|
|
|
+ float toolX = (tool1X + tool2X) / 2;
|
|
|
+ float toolY = (tool1Y + tool2Y) / 2;
|
|
|
+
|
|
|
+ if (DialogHost.IsDialogOpen("RootDialog"))
|
|
|
+ {
|
|
|
+ DialogHost.Close("RootDialog");
|
|
|
+ }
|
|
|
+ await task;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "视觉定位失败,无法进行产品拍照!", Duration = 1 });
|
|
|
+ if (DialogHost.IsDialogOpen("RootDialog"))
|
|
|
+ {
|
|
|
+ DialogHost.Close("RootDialog");
|
|
|
+ }
|
|
|
+ await task;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogHelper.WriteLogError("执行产品拍照时出错!", ex);
|
|
|
+ _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
|
|
|
+ if (DialogHost.IsDialogOpen("RootDialog"))
|
|
|
+ {
|
|
|
+ DialogHost.Close("RootDialog");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
#endregion
|
|
|
|
|
|
#region 继承
|
|
|
@@ -1702,11 +1493,11 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
+ toolCoord = null;
|
|
|
local = null;
|
|
|
SelectProduct = navigationContext.Parameters.GetValue<ProductModel>("SelectProduct");
|
|
|
|
|
|
SelectedIndex = 0;
|
|
|
- PickPoints = SelectProduct.PickPoints;
|
|
|
Points = SelectProduct.PickCameraPoints;
|
|
|
|
|
|
if (Robot == null)
|
|
|
@@ -1794,129 +1585,6 @@ 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;
|
|
|
- }
|
|
|
-
|
|
|
- var waiting = new WaitingControl();
|
|
|
- //show the dialog
|
|
|
- var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
|
|
|
-
|
|
|
- // 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 = await _remoteCommandService.ExecutePhotoGetSinglePoint(SelectProcedure, null, new double[] { rpoint.X, rpoint.Y, 0 }, _cts.Token);
|
|
|
- if (!recognitionResult.IsSucceed)
|
|
|
- {
|
|
|
- if (DialogHost.IsDialogOpen("RootDialog"))
|
|
|
- {
|
|
|
- DialogHost.Close("RootDialog");
|
|
|
- }
|
|
|
- await task;
|
|
|
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "取料拍照点位矫正失败,识别未成功!", Duration = 1 });
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 3. 根据识别结果更新取料点位坐标
|
|
|
- SelectedPickPoint.X_Position = (float)recognitionResult.X;
|
|
|
- SelectedPickPoint.Y_Position = (float)recognitionResult.Y;
|
|
|
-
|
|
|
- if (DialogHost.IsDialogOpen("RootDialog"))
|
|
|
- {
|
|
|
- DialogHost.Close("RootDialog");
|
|
|
- }
|
|
|
- await task;
|
|
|
-
|
|
|
- _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;
|
|
|
|