孝锋 徐 před 8 měsíci
rodič
revize
9d388b371f

+ 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();

+ 66 - 53
TeamAAS-VM/Core/Management.cs

@@ -1,4 +1,5 @@
-using Cognex.VisionPro;
+using Basler.Pylon;
+using Cognex.VisionPro;
 using Cognex.VisionPro.ToolBlock;
 using CSScripting;
 using MathNet.Numerics.Distributions;
@@ -1008,14 +1009,14 @@ namespace TeamAAS_VP.Core
                     await item.WriteToPlcAddress(addressConfig.Out_ScrewCamera, plc);
                 }
             }
-            if (current.ScrewPoints != null && current.ScrewPoints.Count > 0)
-            {
-                foreach (var item in current.ScrewPoints)
-                {
-                    await item.WriteToPlcAddress(addressConfig.Out_Screw, plc);
-                }
-                await plc.WriteNodeAsync(addressConfig.Out_WorkNum.Address, (Int16)current.ScrewPoints.Count);
-            }
+            //if (current.ScrewPoints != null && current.ScrewPoints.Count > 0)
+            //{
+            //    foreach (var item in current.ScrewPoints)
+            //    {
+            //        await item.WriteToPlcAddress(addressConfig.Out_Screw, plc);
+            //    }
+            //    await plc.WriteNodeAsync(addressConfig.Out_WorkNum.Address, (Int16)current.ScrewPoints.Count);
+            //}
             if (current.CheckCameraPoints != null && current.CheckCameraPoints.Count > 0)
             {
                 foreach (var item in current.CheckCameraPoints)
@@ -1046,6 +1047,10 @@ namespace TeamAAS_VP.Core
                 if (plc == null || !plc.IsConnected) return;
                 // 获取当前产品
                 var currentProduct = _productService.GetCurrentProduct();
+                if (currentProduct==null)
+                {
+                    return;
+                }
 
                 // 触发下相机拍照
                 if (addressConfig.In_DowmCameraExe.Address.Contains(tuple.nodeId))
@@ -1057,6 +1062,7 @@ namespace TeamAAS_VP.Core
                             SendTaskMessage($"触发下相机拍照...", MessageLevel.Debug);
                             //相机的编号
                             Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.In_DowmCameraNum.Address);
+                            SendTaskMessage($"编号:{cameraIndex}", MessageLevel.Info);
 
                             // 获取流程
                             var process = _productService.GetCurrentProductProcedureModelById(currentProduct.FixedUpCamera1ProcedureId);
@@ -1135,6 +1141,7 @@ namespace TeamAAS_VP.Core
                             SendTaskMessage($"触发上相机锁附/组装拍照...", MessageLevel.Debug);
                             //相机的编号
                             Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.In_UpCameraPutNum.Address);
+                            SendTaskMessage($"编号:{cameraIndex}", MessageLevel.Info);
 
                             // 获取流程
                             var process = _productService.GetCurrentProductProcedureModelById(currentProduct.MoveDownCameraLockPhotoProcedureId);
@@ -1267,14 +1274,14 @@ namespace TeamAAS_VP.Core
                 // 开始锁付
                 else if (addressConfig.In_WorkStart.Address.Contains(tuple.nodeId))
                 {
-                    if (tuple.value is bool state)
+                    if (tuple.value is Int16 state)
                     {
-                        if (state)
+                        if (state==1)
                         {
                             SendTaskMessage($"收到开始锁付信号...", MessageLevel.Debug);
                             //位置编号
-                            //Int16 positionIndex = plc.ReadNode<Int16>(addressConfig.In_ProductNum.Address);
-
+                            Int16 positionIndex = plc.ReadNode<Int16>(addressConfig.In_ProductNum.Address);
+                            SendTaskMessage($"编号:{positionIndex}", MessageLevel.Info);
                         }
                         else
                         {
@@ -1286,48 +1293,53 @@ namespace TeamAAS_VP.Core
                 // 停止锁付
                 else if (addressConfig.In_WorkDone.Address.Contains(tuple.nodeId))
                 {
-                    if (tuple.value is bool state)
+                    if (tuple.value is Int16 state)
                     {
-                        if (state)
+                        if (state==1 || state == 2)
                         {
                             SendTaskMessage($"收到停止锁付信号...", MessageLevel.Debug);
                             //位置编号
                             Int16 positionIndex = plc.ReadNode<Int16>(addressConfig.In_ProductNum.Address);
-                            //获取当前锁付点
-                            var screwPoint = currentProduct.ScrewPoints.FirstOrDefault(p=>p.Number== positionIndex);
-                            //获取当前的机器人点位
-                            var robot = _robotService.GetAllRobots().FirstOrDefault();
-                            var currentPosition = robot.GetRobotPos();
-
-
-                            await Task.Delay(60);
-                            //获取电批结果
-                            ScrewDriver.GetData();
-                            LockResult lockResult=new LockResult();
-                            lockResult.Number = positionIndex;
-                            lockResult.LockPassed = ScrewDriver.Success;
-                            lockResult.ProductNumber = "";
-                            lockResult.LockTurns= (float)ScrewDriver.Truns;
-                            lockResult.LockTorque= (float)ScrewDriver.TorqueValue;
-                            lockResult.LockDuration= (float)ScrewDriver.FinalTime;
-                            lockResult.ScrewdriverProgramNumber= ScrewDriver.ProgramNumber;
-                            lockResult.ResultDetails = ScrewDriver.ErrorInfo;
-                            lockResult.Pressure= 0;
-                            lockResult.TargetTorque= 0;
-                            lockResult.TargetTurnsUpperLimit= 0;
-                            lockResult.TargetTurnsLowerLimit= 0;
-                            lockResult.TargetLockSpeed= 0;
-                            lockResult.StartPositionX= currentPosition.X;
-                            lockResult.StartPositionY= currentPosition.Y;
-                            lockResult.StartPositionZ= screwPoint.Z_Position_Start;
-                            lockResult.EndPositionZ= currentPosition.Z;
-                            lockResult.LockDescentSpeed= screwPoint.Z_Velocity_Stop;
-                            lockResult.FeederNumber= screwPoint!=null?screwPoint.Feeder:0;
-                            lockResult.NozzleNumber = "";
-                            lockResult.OperatorName = "";
-                            lockResult.WaveDatas= ScrewDriver.WaveDatas;
-                            _eventAggregator.GetEvent<LockFinishNotification>().Publish(lockResult);
-                            await _systemDatabaseService.RecordLockResultAsync(lockResult);
+                            SendTaskMessage($"编号:{positionIndex}", MessageLevel.Info);
+                            ////获取当前锁付点
+                            //var screwPoint = currentProduct.ScrewPoints.FirstOrDefault(p=>p.Number== positionIndex);
+                            ////获取当前的机器人点位
+                            //var robot = _robotService.GetAllRobots().FirstOrDefault();
+                            //var currentPosition = robot.GetRobotPos();
+
+
+                            //await Task.Delay(60);
+                            ////获取电批结果
+                            //ScrewDriver.GetData();
+                            //LockResult lockResult=new LockResult();
+                            //lockResult.Number = positionIndex;
+                            //lockResult.LockPassed = ScrewDriver.Success;
+                            //lockResult.ProductNumber = "";
+                            //lockResult.LockTurns= (float)ScrewDriver.Truns;
+                            //lockResult.LockTorque= (float)ScrewDriver.TorqueValue;
+                            //lockResult.LockDuration= (float)ScrewDriver.FinalTime;
+                            //lockResult.ScrewdriverProgramNumber= ScrewDriver.ProgramNumber;
+                            //lockResult.ResultDetails = ScrewDriver.ErrorInfo;
+                            //lockResult.Pressure= 0;
+                            //lockResult.TargetTorque= 0;
+                            //lockResult.TargetTurnsUpperLimit= 0;
+                            //lockResult.TargetTurnsLowerLimit= 0;
+                            //lockResult.TargetLockSpeed= 0;
+                            //lockResult.StartPositionX= currentPosition.X;
+                            //lockResult.StartPositionY= currentPosition.Y;
+                            //lockResult.StartPositionZ= screwPoint.Z_Position_Start;
+                            //lockResult.EndPositionZ= currentPosition.Z;
+                            //lockResult.LockDescentSpeed= screwPoint.Z_Velocity_Stop;
+                            //lockResult.FeederNumber= screwPoint!=null?screwPoint.Feeder:0;
+                            //lockResult.NozzleNumber = "";
+                            //lockResult.OperatorName = "";
+                            //lockResult.WaveDatas= ScrewDriver.WaveDatas;
+                            //App.Current.Dispatcher.Invoke(() =>
+                            //{
+                            //    _eventAggregator.GetEvent<LockFinishNotification>().Publish(lockResult);
+                            //});
+                            //await _systemDatabaseService.RecordLockResultAsync(lockResult);
+                            await plc.WriteNodeAsync(addressConfig.In_WorkDone.Address, (Int16)0);
                         }
                         else
                         {
@@ -1364,12 +1376,13 @@ namespace TeamAAS_VP.Core
 
                                 for (int i = 0; i < currentProduct.ScrewPoints.Count; i++)
                                 {
-                                    var localPoint = new PointF(currentProduct.ScrewCameraPoints[i].X_Position, currentProduct.ScrewCameraPoints[i].Y_Position);
+                                    var localPoint = new PointF(currentProduct.ScrewPoints[i].X_Position, currentProduct.ScrewPoints[i].Y_Position);
                                     var worldPoint= local.ToOldCoord(localPoint.X, localPoint.Y);
-                                    var point = currentProduct.ScrewCameraPoints[i].Clone();
+                                    var point = currentProduct.ScrewPoints[i].Clone();
                                     point.X_Position = (float)worldPoint[0];
                                     point.Y_Position = (float)worldPoint[1];
-                                    await point.WriteToPlcAddress(addressConfig.Out_ScrewCamera, plc);
+                                    SendTaskMessage($"点:{i},{point.X_Position:F3},{point.Y_Position:F4}", MessageLevel.Info);
+                                    await point.WriteToPlcAddress(addressConfig.Out_Screw, plc);
                                 }
                                 await plc.WriteNodeAsync(addressConfig.Out_WorkNum.Address, (Int16)currentProduct.ScrewPoints.Count);
                             }

+ 4 - 4
TeamAAS-VM/Core/PLCs/OPCuaClientPLC.cs

@@ -216,7 +216,7 @@ namespace TeamAAS_VP.Core.PLCs
             {
                 readNodeId = NodeHeader + nodeId;
             }
-            return OpcUaClient.ReadNode<T>(NodeHeader + nodeId);
+            return OpcUaClient.ReadNode<T>(readNodeId);
         }
 
         /// <summary>
@@ -232,7 +232,7 @@ namespace TeamAAS_VP.Core.PLCs
             {
                 readNodeId = NodeHeader + nodeId;
             }
-            return await OpcUaClient.ReadNodeAsync<T>(NodeHeader + nodeId);
+            return await OpcUaClient.ReadNodeAsync<T>(readNodeId);
         }
 
         /// <summary>
@@ -310,7 +310,7 @@ namespace TeamAAS_VP.Core.PLCs
         /// <param name="dataChangeHandler"></param>
         public void SubscribeNodes(string key, List<string> nodeIds, Action<(string key,string nodeId,object value)> dataChangeHandler)
         {
-            OpcUaClient.AddSubscription("InputOutput", nodeIds.Select(s =>
+            OpcUaClient.AddSubscription(key, nodeIds.Select(s =>
             {
                 if (s.StartsWith(NodeHeader))
                 {
@@ -333,7 +333,7 @@ namespace TeamAAS_VP.Core.PLCs
                     nodeId= nodeId.Substring(NodeHeader.Length);
                 }
                 // 触发数据变化事件
-                dataChangeHandler?.Invoke((key, nodeId, notification.Value.WrappedValue.Value));
+                dataChangeHandler?.Invoke((key1, nodeId, notification.Value.WrappedValue.Value));
             });
         }
         #region OPC事件

+ 16 - 0
TeamAAS-VM/Core/Robots/XYZU_Robot.cs

@@ -214,6 +214,7 @@ namespace TeamAAS_VP.Core.Robots
         {
             if (Plc.IsConnected)
             {
+                StopMove();
                 ConnectedEvent?.Invoke(Id, this, null);
             }
         }
@@ -222,6 +223,7 @@ namespace TeamAAS_VP.Core.Robots
         {
             if (Plc.IsConnected)
             {
+                StopMove();
                 ConnectedEvent?.Invoke(Id, this, null);
             }
             return Task.CompletedTask;
@@ -481,6 +483,7 @@ namespace TeamAAS_VP.Core.Robots
             try
             {
                 CanExecute = false;
+                Motor(true);
                 Dictionary<string, object> keyValues = new Dictionary<string, object>();
 
                 // 1. 写入目标位置到各轴的 ManuPositionNode
@@ -708,6 +711,10 @@ namespace TeamAAS_VP.Core.Robots
                 {
                     nodeIds.Add(axis.State.ErrorNode);
                 }
+                if (!string.IsNullOrWhiteSpace(axis.State.PausedNode))
+                {
+                    nodeIds.Add(axis.State.PausedNode);
+                }
             }
             var res = Plc.ReadNodes(nodeIds.ToArray());
             bool allOk = true;
@@ -730,6 +737,15 @@ namespace TeamAAS_VP.Core.Robots
                 {
                     isError = (bool)res[axis.State.ErrorNode];
                 }
+                if (res.ContainsKey(axis.State.PausedNode))
+                {
+                    isError = (bool)res[axis.State.PausedNode];
+                }
+                if (isError)
+                {
+                    isAnyError = true;
+                    break;
+                }
                 //检查是否到位和位置一致
                 float targetPos = 0;
                 switch (axis.Name)

+ 10 - 3
TeamAAS-VM/Data/SystemDatabaseService.cs

@@ -610,9 +610,16 @@ namespace TeamAAS_VP.Data
         /// <param name="result"></param>
         public async Task RecordLockResultAsync(LockResult result)
         {
-            if (result == null) throw new ArgumentNullException(nameof(result));
-            if (result.Timestamp == default(DateTime)) result.Timestamp = DateTime.UtcNow;
-            await _db.Insertable(result).ExecuteCommandAsync();
+            try
+            {
+                if (result == null) throw new ArgumentNullException(nameof(result));
+                if (result.Timestamp == default(DateTime)) result.Timestamp = DateTime.UtcNow;
+                await _db.Insertable(result).ExecuteCommandAsync();
+            }
+            catch (Exception)
+            {
+
+            }
         }
 
         /// <summary>

+ 8 - 6
TeamAAS-VM/Services/ConfigService.cs

@@ -40,6 +40,8 @@ namespace TeamAAS_VP.Services
             // Feeder清料任务配置路径
             public static readonly string FeederClearanceTasksConfigurationPath = "..//Config//FeederClearanceTasksConfiguration.cfg";
             // 光源控制器配置路径
+            public static readonly string LightControllersConfigurationPath = "..//Config//LightControllersConfiguration.cfg";
+            // 电批配置路径(单设备)
             public static readonly string ScrewDriverConfigurationPath = "..//Config//ScrewDriverConfiguration.cfg";
             // 螺丝供料器(物料)配置路径
             public static readonly string ScrewFeedersConfigurationPath = "..//Config//ScrewFeedersConfiguration.cfg";
@@ -179,14 +181,14 @@ namespace TeamAAS_VP.Services
                 }
 
                 // 读取光源控制器配置
-                if (!File.Exists(ConfigPaths.ScrewDriverConfigurationPath))
+                if (!File.Exists(ConfigPaths.LightControllersConfigurationPath))
                 {
                     LightControllers = new ObservableCollection<LightControllerConfig>();
-                    FileHelper.WriteJsonFile(LightControllers, ConfigPaths.ScrewDriverConfigurationPath);
+                    FileHelper.WriteJsonFile(LightControllers, ConfigPaths.LightControllersConfigurationPath);
                 }
                 else
                 {
-                    LightControllers = FileHelper.ReadJsonFile<ObservableCollection<LightControllerConfig>>(ConfigPaths.ScrewDriverConfigurationPath);
+                    LightControllers = FileHelper.ReadJsonFile<ObservableCollection<LightControllerConfig>>(ConfigPaths.LightControllersConfigurationPath);
                 }
                 // load plc addresses
                 var plcAddressPath = "..//Config//PlcAddressConfiguration.cfg";
@@ -894,7 +896,7 @@ namespace TeamAAS_VP.Services
                 }
             }
             // 持久化更新后的光源控制器配置
-            FileHelper.WriteJsonFile(LightControllers, ConfigPaths.ScrewDriverConfigurationPath);
+            FileHelper.WriteJsonFile(LightControllers, ConfigPaths.LightControllersConfigurationPath);
             return controller;
         }
 
@@ -927,7 +929,7 @@ namespace TeamAAS_VP.Services
                     LightControllers.Add(c);
                 }
             }
-            FileHelper.WriteJsonFile(LightControllers, ConfigPaths.ScrewDriverConfigurationPath);
+            FileHelper.WriteJsonFile(LightControllers, ConfigPaths.LightControllersConfigurationPath);
             return result;
         }
 
@@ -980,7 +982,7 @@ namespace TeamAAS_VP.Services
                 var ch = LightControllers.SelectMany(c => c.ChannelConfigs).FirstOrDefault(x => x.GlobalIndex == globalIndex);
                 if (ch == null) return false;
                 ch.DefaultBrightness = brightness;
-                FileHelper.WriteJsonFile(LightControllers, ConfigPaths.ScrewDriverConfigurationPath);
+                FileHelper.WriteJsonFile(LightControllers, ConfigPaths.LightControllersConfigurationPath);
                 return true;
             }
         }

+ 9 - 1
TeamAAS-VM/ViewModels/DebugMod/FocusAnalyzerViewModel.cs

@@ -215,6 +215,10 @@ namespace TeamAAS_VP.ViewModels.DebugMod
                     try
                     {
                         var image = Camera.Grab();
+                        if (image==null)
+                        {
+                            return;
+                        }
                         _currentMat = ImageHelper.ICogImageConvertMat(image);
                         // 转换为 WPF 可显示的位图并更新 UI 绑定
                         CurrentImage = _currentMat.ToBitmapSource();
@@ -514,7 +518,11 @@ namespace TeamAAS_VP.ViewModels.DebugMod
             {
                 return;
             }
-            Camera.StopGrabbing();
+            if (Camera.IsGrabbing)
+            {
+                Camera.StopGrabbing();
+            }
+            
             //_analysisTimer.Stop();
             IsAnalyzing = false;
             StatusText = "已停止";

+ 100 - 17
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>
         /// 开始校准
@@ -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; }

+ 24 - 18
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
 {
@@ -352,9 +354,9 @@ namespace TeamAAS_VP.ViewModels.Product
         public DelegateCommand ApplyLockPointFeederAndScrewProgramCommand =>
             _ApplyLockPointFeederAndScrewProgramCommand ?? (_ApplyLockPointFeederAndScrewProgramCommand = new DelegateCommand(ExecuteApplyLockPointFeederAndScrewProgramCommand));
 
-        private DelegateCommand _AutoCorrectLockPoint;
-        public DelegateCommand AutoCorrectLockPoint =>
-            _AutoCorrectLockPoint ?? (_AutoCorrectLockPoint = new DelegateCommand(ExecuteAutoCorrectLockPoint));
+        private DelegateCommand _AutoCorrectLockPointCommand;
+        public DelegateCommand AutoCorrectLockPointCommand =>
+            _AutoCorrectLockPointCommand ?? (_AutoCorrectLockPointCommand = new DelegateCommand(ExecuteAutoCorrectLockPoint));
 
         #endregion
 
@@ -1028,23 +1030,27 @@ namespace TeamAAS_VP.ViewModels.Product
         {
             try
             {
-                //弹窗提示用户是否确认要通过相机自动矫正锁附点位
-                var resultConfirm = MessageBox.Show("确认要通过相机自动矫正锁附点位吗?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
-                if (resultConfirm != MessageBoxResult.Yes)
+                IDialogParameters parameters = new DialogParameters();
+                parameters.Add("Robot", Robot);
+                parameters.Add("Points", new List<PlcPoint>(SelectProduct.ScrewPoints.ToArray()));
+                _dialogService.Show("AutoCorrectLockPoint", parameters, rst =>
                 {
-                    return;
-                }
+                    //对话框关闭之后的回调函数,可以在这解析结果。
+                    ButtonResult result1 = rst.Result;
 
-                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)
-                {
-                    
-                }
+                    if (result1 == ButtonResult.OK)
+                    {
+                        var param = rst.Parameters.GetValue<ObservableCollection<PointEx>>("CorrectPoints");
+                        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)
             {

+ 36 - 15
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="*" />
@@ -44,7 +65,7 @@
         <DataGrid Grid.Row="0"
                   Grid.Column="1"
                   Margin="5"
-                  Width="360"
+                  Width="400"
                   ItemsSource="{Binding CorrectPoints}"
                   AutoGenerateColumns="False"
                   IsReadOnly="True"
@@ -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>

+ 1 - 1
TeamAAS-VM/Views/Product/PlcPointParams.xaml

@@ -550,7 +550,7 @@
                                                         MinWidth="150"
                                                         HorizontalAlignment="Left"
                                                         materialDesign:ButtonAssist.CornerRadius="5"
-                                                        Command="{Binding AutoCorrectLockCameraPointCommand}" />
+                                                        Command="{Binding AutoCorrectLockPointCommand}" />
 
                                             </Grid>
                                         </StackPanel>