Просмотр исходного кода

修复自动校准锁付点位校准

徐孝锋 8 месяцев назад
Родитель
Сommit
b1ece88c41

+ 1 - 0
TeamAAS-VM/App.xaml.cs

@@ -177,6 +177,7 @@ namespace TeamAAS_VP
             containerRegistry.RegisterDialog<SelectCameraBrand>();
             containerRegistry.RegisterDialog<AddLightController>();
             containerRegistry.RegisterDialog<LightChannelList>();
+            containerRegistry.RegisterDialog<AutoCorrectLockPoint>();
             //**************************************************************************************
 
             // 注册 SQLSugar 客户端(单例模式)

+ 0 - 1
TeamAAS-VM/Core/Cameras/OptCamera.cs

@@ -477,7 +477,6 @@ namespace TeamAAS_VP.Core.Cameras
                 {
                     IsGrabbing = false;
                 }
-                Thread.Sleep(1000);
                 if (m_hReceiveThread != null)
                 {
                     m_hReceiveThread.Abort();

+ 76 - 6
TeamAAS-VM/ViewModels/Product/AutoCorrectLockPointViewModel.cs

@@ -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>
         /// 开始校准
@@ -196,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 });
@@ -220,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)
                 {
@@ -251,15 +291,15 @@ namespace TeamAAS_VP.ViewModels.Product
                 {
                     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 - 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;
 
                     //移动机器人至拍照点位,拍照
@@ -278,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)
                     {
@@ -320,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;

+ 16 - 9
TeamAAS-VM/ViewModels/Product/PlcPointParamsViewModel.cs

@@ -1,4 +1,5 @@
 using MaterialDesignThemes.Wpf;
+using MathNet.Numerics.LinearAlgebra;
 using Prism.Commands;
 using Prism.Events;
 using Prism.Ioc;
@@ -25,6 +26,7 @@ using TeamAAS_VP.Models.Robot;
 using TeamAAS_VP.Resources.Languages;
 using TeamAAS_VP.Services;
 using TeamAAS_VP.Views.Product;
+using static TeamAAS_VP.ViewModels.Product.AutoCorrectLockPointViewModel;
 
 namespace TeamAAS_VP.ViewModels.Product
 {
@@ -978,16 +980,21 @@ namespace TeamAAS_VP.ViewModels.Product
         {
             try
             {
-                var view = new AutoCorrectLockPoint();
-                var vm = view.DataContext as AutoCorrectLockPointViewModel;
-                vm.Robot = Robot;
-                vm.AllScrewPoint = new List<PlcPoint>(Points.ToArray());
-                //show the dialog
-                var result = await DialogHost.Show(view, "RootDialog", null, null, null);
-                if (result != null)
+                IDialogParameters parameters = new DialogParameters();
+                parameters.Add("Robot", Robot);
+                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");
+                        _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "完成!", Duration = 1 });
+                    }
+
+                });
             }
             catch (Exception ex)
             {

+ 35 - 14
TeamAAS-VM/Views/Product/AutoCorrectLockPoint.xaml

@@ -20,10 +20,31 @@
              prism:ViewModelLocator.AutoWireViewModel="True"
              mc:Ignorable="d"
              d:DataContext="{d:DesignInstance Type=vm:AutoCorrectLockPointViewModel}"
-             Height="768"
-             Width="1024"
+             d:Height="768"
+             d:Width="1024"
              d:Background="White"
              FontFamily="{DynamicResource DefaultFont}">
+
+    <prism:Dialog.WindowStyle>
+        <Style TargetType="Window">
+            <Setter Property="prism:Dialog.WindowStartupLocation"
+                    Value="CenterScreen" />
+            <Setter Property="AllowDrop"
+                    Value="True" />
+            <Setter Property="ShowInTaskbar"
+                    Value="True" />
+            <Setter Property="Width"
+                    Value="1024" />
+            <Setter Property="Height"
+                    Value="768" />
+            <!--<Setter Property="SizeToContent"
+                Value="WidthAndHeight" />-->
+            <!--<Setter Property="WindowState"
+                Value="Maximized" />-->
+            <Setter Property="Topmost"
+                    Value="True" />
+        </Style>
+    </prism:Dialog.WindowStyle>
     <Grid>
         <Grid.RowDefinitions>
             <RowDefinition Height="*" />
@@ -95,19 +116,19 @@
                     HorizontalAlignment="Right"
                     Margin="5"
                     IsEnabled="{Binding IsExecuting,Converter={StaticResource InvertBooleanConverter}}">
-            <Button Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}"
-                    CommandParameter="{Binding}"
-                    IsDefault="True"
+            <Button Height="30"
                     Content="{lex:Loc 确定}"
-                    Margin="0,0,12,0" />
-
-            <Button Margin="0"
-                    Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}"
-                    IsCancel="True"
-                    Content="{lex:Loc 取消}">
-                <Button.CommandParameter>
-                    <x:Null />
-                </Button.CommandParameter>
+                    materialDesign:ButtonAssist.CornerRadius="10"
+                    ToolTip="{lex:Loc 确定}"
+                    Command="{Binding ConfirmCommand}">
+            </Button>
+            <Button Height="30"
+                    Margin="20,0"
+                    materialDesign:ButtonAssist.CornerRadius="10"
+                    Style="{StaticResource MaterialDesignRaisedButton}"
+                    ToolTip="{lex:Loc 取消}"
+                    Command="{Binding CancelCommand}">
+                <TextBlock Text="{lex:Loc 取消}" />
             </Button>
         </StackPanel>
     </Grid>