Переглянути джерело

锁付点位校准与示教流程优化与安全增强

优化了锁付点位的校准与示教流程,将坐标变换器local提升为类成员并在校准后传递,确保示教前已完成相机定位。禁止未校准时直接示教锁付点位,提升了操作安全性。调整了弹窗确认逻辑,增强了代码健壮性和可读性。
孝锋 徐 8 місяців тому
батько
коміт
bb0719af85

+ 3 - 2
TeamAAS-VM/ViewModels/Product/AutoCorrectLockPointViewModel.cs

@@ -30,7 +30,7 @@ namespace TeamAAS_VP.ViewModels.Product
         private readonly IPlcService _plcService;
         private readonly IEventAggregator _eventAggregator;
         private readonly ICalibrationService _calibrationService;
-
+        CoordinateTransformer local = null;
         private CancellationTokenSource _cts;
         #region 属性
         public string Title => "校准锁付点位";
@@ -144,6 +144,7 @@ namespace TeamAAS_VP.ViewModels.Product
 
             IDialogParameters parameters = new DialogParameters();
             parameters.Add("CorrectPoints", CorrectPoints);
+            parameters.Add("Local", local);
             RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parameters));
         }
 
@@ -285,7 +286,7 @@ namespace TeamAAS_VP.ViewModels.Product
                 //根据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);
-                CoordinateTransformer local = new CoordinateTransformer(worldP1, worldP2, localP1, localP2);
+                local = new CoordinateTransformer(worldP1, worldP2, localP1, localP2);
 
                 for (int i = 0; i < product.ScrewPoints.Count; i++)
                 {

+ 42 - 14
TeamAAS-VM/ViewModels/Product/PlcPointParamsViewModel.cs

@@ -43,7 +43,7 @@ namespace TeamAAS_VP.ViewModels.Product
         ISystemDatabaseService _systemDatabaseService;
         IRemoteCommandService _remoteCommandService;
         ICalibrationService _calibrationService;
-        CoordinateTransformer local;
+        CoordinateTransformer local=null;
 
         #region 属性
 
@@ -561,23 +561,46 @@ namespace TeamAAS_VP.ViewModels.Product
                 //如果当前的选项卡处于锁付点位,则提示用户当前模式不允许进行示教
                 if (SelectedIndex == 4)
                 {
-                    MessageBox.Show("当前处于锁付点位模式,不允许进行示教操作!", "示教点位", MessageBoxButton.OK, MessageBoxImage.Warning);
-                    return;
-                }
+                    //如果local为空,则必须先通过相机定位产品,否则无法示教锁付点位
+                    if (local == null)
+                    {
+                        _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "当前模式不允许直接示教锁付点位,请先通过相机定位产品!", Duration = 1 });
+                        return;
+                    }
 
-                //弹窗用户是否确认要示教该点位
-                if (MessageBox.Show($"确认要示教点位 {SelectedPoint.Number} 吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
-                {
+                    //弹窗用户是否确认要示教该点位
+                    if (MessageBox.Show($"确认要示教点位 {SelectedPoint.Number} 吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
+                    {
+                        return;
+                    }
+
+                    var curpos1 = await Robot.GetRobotPosAsync();
+                    //将当前点位转换为产品Local坐标系下的点位
+                    var localPoint = local.ToOldCoord(curpos1.X, curpos1.Y);
+                    SelectedPoint.X_Position = (float)localPoint[0];
+                    SelectedPoint.Y_Position = (float)localPoint[1];
+                    SelectedPoint.Z_Position_Start = curpos1.Z;
+                    SelectedPoint.U_Position = curpos1.U;
+                    SelectedPoint.R_Position = curpos1.V;
+                    _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
                     return;
                 }
+                else
+                {
+                    //弹窗用户是否确认要示教该点位
+                    if (MessageBox.Show($"确认要示教点位 {SelectedPoint.Number} 吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
+                    {
+                        return;
+                    }
 
-                var curpos = await Robot.GetRobotPosAsync();
-                SelectedPoint.X_Position = curpos.X;
-                SelectedPoint.Y_Position = curpos.Y;
-                SelectedPoint.Z_Position_Start = curpos.Z;
-                SelectedPoint.U_Position = curpos.U;
-                SelectedPoint.R_Position = curpos.V;
-                _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
+                    var curpos = await Robot.GetRobotPosAsync();
+                    SelectedPoint.X_Position = curpos.X;
+                    SelectedPoint.Y_Position = curpos.Y;
+                    SelectedPoint.Z_Position_Start = curpos.Z;
+                    SelectedPoint.U_Position = curpos.U;
+                    SelectedPoint.R_Position = curpos.V;
+                    _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
+                }
             }
             catch (Exception ex)
             {
@@ -1127,6 +1150,11 @@ namespace TeamAAS_VP.ViewModels.Product
                     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;