Pārlūkot izejas kodu

增加螺丝锁付上下限设置

KWD 4 mēneši atpakaļ
vecāks
revīzija
feb579e9b9
2 mainītis faili ar 72 papildinājumiem un 29 dzēšanām
  1. 4 4
      TeamAAS-VM/Controls/ParameterEdit.xaml
  2. 68 25
      TeamAAS-VM/Core/Management.cs

+ 4 - 4
TeamAAS-VM/Controls/ParameterEdit.xaml

@@ -55,16 +55,16 @@
                 <DataGridTextColumn Header="Name"
                                     MinWidth="80"
                                     Binding="{Binding Name, Mode=TwoWay}" />
-                <DataGridTextColumn Header="Param1"
+                <DataGridTextColumn Header="X下限"
                                     MinWidth="80"
                                     Binding="{Binding Param1, Mode=TwoWay}" />
-                <DataGridTextColumn Header="Param2"
+                <DataGridTextColumn Header="X上限"
                                     MinWidth="80"
                                     Binding="{Binding Param2, Mode=TwoWay}" />
-                <DataGridTextColumn Header="Param3"
+                <DataGridTextColumn Header="Y下限"
                                     MinWidth="80"
                                     Binding="{Binding Param3, Mode=TwoWay}" />
-                <DataGridTextColumn Header="Param4"
+                <DataGridTextColumn Header="Y上限"
                                     MinWidth="80"
                                     Binding="{Binding Param4, Mode=TwoWay}" />
             </DataGrid.Columns>

+ 68 - 25
TeamAAS-VM/Core/Management.cs

@@ -1,4 +1,5 @@
 using Cognex.VisionPro.ToolBlock;
+using MahApps.Metro.Controls;
 using NPOI.OpenXmlFormats.Vml;
 using Org.BouncyCastle.Crypto;
 using Prism.Events;
@@ -1214,7 +1215,7 @@ namespace TeamAAS_VP.Core
                 monitorNodeIds.Add(string.Format(addressConfig.In_MesCheck.Address, i));
             }
             //订阅PLC地址变化
-            plc.SubscribeNodes("AutoSensor", monitorNodeIds, PlcCommandTrigger,OpcUaSubscriptionMode.CustomPolling);
+            plc.SubscribeNodes("AutoSensor", monitorNodeIds, PlcCommandTrigger, OpcUaSubscriptionMode.CustomPolling);
         }
 
         /// <summary>
@@ -1776,11 +1777,6 @@ namespace TeamAAS_VP.Core
                             var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(process, null, new double[] { currentPosition.X, currentPosition.Y, currentPosition.U }, _cts.Token, cameraIndex, num, null, null);
                             if (visionResult.IsSucceed)
                             {
-
-                                //if ()
-                                //{
-
-                                //}
                                 await plc.WriteNodeAsync(addressConfig.Out_UPCameracheckStatus.Address, (Int16)1);
                                 SendTaskMessage($"点位{cameraIndex}检测OK", MessageLevel.Debug);
                             }
@@ -2110,20 +2106,48 @@ namespace TeamAAS_VP.Core
                                         plcPoints.Add(item);
                                     }
                                 }
-                                var point = plcPoints[positionIndex - 1];
-                                if (point == null)
+                                var TempPoint = plcPoints[positionIndex - 1];
+                                if (TempPoint == null)
                                 {
                                     SendTaskMessage($"点:{positionIndex}不存在", MessageLevel.Info);
                                     await plc.WriteNodeAsync(addressConfig.Out_CameraDone.Address, (Int16)2);
                                     return;
                                 }
-                                point = point.Clone();
-                                point.X_Position = UpCameraPutResults[1].X + DowmCameraResults[1].X;
-                                point.Y_Position = UpCameraPutResults[1].Y + DowmCameraResults[1].Y;
-                                SendTaskMessage($"点:{positionIndex},{point.X_Position:F3},{point.Y_Position:F4}", MessageLevel.Info);
-                                await point.WriteToPlcAddress(addressConfig.Out_Screw, plc, positionIndex);
+                                var PositionPoint = TempPoint.Clone();
+                                PositionPoint.X_Position = UpCameraPutResults[1].X + DowmCameraResults[1].X;
+                                PositionPoint.Y_Position = UpCameraPutResults[1].Y + DowmCameraResults[1].Y;
+                                SendTaskMessage($"点:{positionIndex},{PositionPoint.X_Position:F3},{PositionPoint.Y_Position:F4}", MessageLevel.Info);
+                                if (PositionPoint.X_Position == 0 || PositionPoint.Y_Position == 0)
+                                {
+                                    SendTaskMessage("拟合位置为0,请检查", MessageLevel.Error);
+                                    await plc.WriteNodeAsync(addressConfig.Out_CameraDone.Address, (Int16)2);
+                                    return;
+                                }
+                                //验证当前锁附点位与设置锁附点位的差值是否超限,超限则报警并停止流程
+                                //目前验证已OK 缺少切换按钮
+                                //try
+                                //{
+                                //    var ScrewLimit = currentProduct.GlobalParamListCollection.FirstOrDefault((p) => p.Number == positionIndex - 1);
+                                //    //判断实际偏差与设置的点位差数是否偏差过大
+                                //    float XOffsetPoint = Math.Abs(PositionPoint.X_Position - (TempPoint.X_Position + TempPoint.X_Offset));
+                                //    float YOffsetPoint = Math.Abs(PositionPoint.Y_Position - (TempPoint.Y_Position + TempPoint.Y_Offset));
+                                //    if (!(XOffsetPoint >= float.Parse(ScrewLimit.Param1) && XOffsetPoint <= float.Parse(ScrewLimit.Param2)) ||
+                                //        !(YOffsetPoint >= float.Parse(ScrewLimit.Param3) && YOffsetPoint <= float.Parse(ScrewLimit.Param4)))
+                                //    {
+                                //        SendTaskMessage($"当前锁附点位{positionIndex}与设置锁附点位差值超限,X偏差:{XOffsetPoint},Y偏差{YOffsetPoint}", MessageLevel.Error);
+                                //        await plc.WriteNodeAsync(addressConfig.Out_CameraDone.Address, (Int16)2);
+                                //        return;
+                                //    }
+                                //}
+                                //catch (Exception ex)
+                                //{
+                                //    SendTaskMessage($"当前锁附点位与设置锁附点位差值未设置:" + ex.Message, MessageLevel.Error);
+                                //    await plc.WriteNodeAsync(addressConfig.Out_CameraDone.Address, (Int16)2);
+                                //    return;
+                                //}
+                                await PositionPoint.WriteToPlcAddress(addressConfig.Out_Screw, plc, positionIndex);
                             }
-                            //拍1打所有
+                            //拍2打所有
                             else if (systemConfig.WorkMode == 2)
                             {
                                 //根据UpCameraPutResults[]中的索引1、2,和拍照点对应的Local下的坐标,从创建Local坐标系
@@ -2146,6 +2170,25 @@ namespace TeamAAS_VP.Core
                                     point.X_Position = (float)worldPoint[0];
                                     point.Y_Position = (float)worldPoint[1];
                                     SendTaskMessage($"点:{i},{point.X_Position:F3},{point.Y_Position:F4}", MessageLevel.Info);
+                                    try
+                                    {
+                                        var ScrewLimit = currentProduct.GlobalParamListCollection.FirstOrDefault((p) => p.Number == positionIndex - 1);
+                                        //判断实际偏差与设置的点位差数是否偏差过大
+                                        float XOffsetPoint = Math.Abs(localPoint.X - (float)worldPoint[0]);
+                                        float YOffsetPoint = Math.Abs(localPoint.Y - (float)worldPoint[1]);
+                                        if ((XOffsetPoint >= float.Parse(ScrewLimit.Param1) && XOffsetPoint <= float.Parse(ScrewLimit.Param2)) ||
+                                            (YOffsetPoint >= float.Parse(ScrewLimit.Param3) && YOffsetPoint <= float.Parse(ScrewLimit.Param4)))
+                                        {
+                                            SendTaskMessage($"当前锁附点位{i}与设置锁附点位差值超限,X偏差:{XOffsetPoint},Y偏差{YOffsetPoint}", MessageLevel.Error);
+                                            await plc.WriteNodeAsync(addressConfig.Out_CameraDone.Address, (Int16)2);
+                                            return;
+                                        }
+                                    }
+                                    catch (Exception ex)
+                                    {
+                                        SendTaskMessage($"当前锁附点位与设置锁附点位差值超限:" + ex.Message, MessageLevel.Error);
+                                        await plc.WriteNodeAsync(addressConfig.Out_CameraDone.Address, (Int16)2);
+                                    }
                                     await point.WriteToPlcAddress(addressConfig.Out_Screw, plc);
                                 }
                                 await plc.WriteNodeAsync(addressConfig.Out_WorkNum.Address, (Int16)currentProduct.ScrewPoints.Count);
@@ -2418,7 +2461,7 @@ namespace TeamAAS_VP.Core
                                     {
                                         code = outputCollection["QR"].Value as string;
                                         code = code.ToUpper();
-                                        if (!string.IsNullOrEmpty(code)&&code.Length>5)
+                                        if (!string.IsNullOrEmpty(code) && code.Length > 5)
                                         {
                                             if (systemConfig.IsBasePartCodeChooseScrew)//是否基于零件码,判断是不是当站要打的螺丝
                                             {
@@ -2466,7 +2509,7 @@ namespace TeamAAS_VP.Core
                                     //获取过站时间
                                     _LastMesCheckTime[i] = (await _mesService.GetServerTimeAsync(i, code, 2)).Now;
                                     if (_configService.GetDeviceInfo().EnableMES)
-                                    {                                              
+                                    {
                                         LogHelper.WriteLogMes($"【mes开始QUERY】");
                                         SendTaskMessage($"mes开始QUERY", MessageLevel.Info);
                                         //dataToMes.Clear();
@@ -2626,7 +2669,7 @@ namespace TeamAAS_VP.Core
                                                         if (i == 0)
                                                         {
                                                             _productService.CurrentProductCode = ProductMainSN[i];
-                                                        }                                                       
+                                                        }
                                                         SendTaskMessage($"产品主sn:{ProductMainSN[i]}", MessageLevel.Info);
                                                     }
                                                     string woItem = item.FirstOrDefault(f => f.Contains("wo="));
@@ -2748,7 +2791,7 @@ namespace TeamAAS_VP.Core
                                 }
                                 // 上传本站数据
                                 else if (state == 2)
-                                {                                
+                                {
                                     DFC.Clear();//CTQ数据集合
 
                                     //获取当前工位的配置
@@ -2892,17 +2935,17 @@ namespace TeamAAS_VP.Core
                                                 PD_ATTR_03 = "NA",
                                                 PD_ATTR_04 = productSn,
                                                 PD_ATTR_05 = "NA",
-                                            });                                            
+                                            });
                                         }
                                         if (systemConfig.IsBasePartOpenLightKB)
                                         {
                                             string midValue = "999", saveppid = "NA";
                                             double upvlalue = 0, doenvlaue = 0;
                                             if (stationConfig.SaveCsvPPID) saveppid = ppid[i];
-                                            bool pressureRes=true;                                            
+                                            bool pressureRes = true;
                                             foreach (var item in mes_cc)
                                             {
-                                                switch(item.Key)
+                                                switch (item.Key)
                                                 {
                                                     case "1":
                                                         upvlalue = Convert.ToDouble(currentProduct.GlobalParamEx.CC1DownLimit.ToString("F3"));
@@ -2913,13 +2956,13 @@ namespace TeamAAS_VP.Core
                                                         upvlalue = Convert.ToDouble(currentProduct.GlobalParamEx.CC2DownLimit.ToString("F3"));
                                                         doenvlaue = Convert.ToDouble(currentProduct.GlobalParamEx.CC2UpLimit.ToString("F3"));
                                                         midValue = ((currentProduct.GlobalParamEx.CC2DownLimit + currentProduct.GlobalParamEx.CC2UpLimit) / 2).ToString("F3");
-                                                        break;                                                   
+                                                        break;
                                                 }
-                                                if (doenvlaue<= currentProduct.GlobalParamEx.CC1DownLimit|| doenvlaue >= currentProduct.GlobalParamEx.CC1UpLimit)
+                                                if (doenvlaue <= currentProduct.GlobalParamEx.CC1DownLimit || doenvlaue >= currentProduct.GlobalParamEx.CC1UpLimit)
                                                 {
                                                     pressureRes = false;
                                                 }
-                                                if (doenvlaue <= currentProduct.GlobalParamEx.CC2DownLimit|| doenvlaue >= currentProduct.GlobalParamEx.CC2UpLimit)
+                                                if (doenvlaue <= currentProduct.GlobalParamEx.CC2DownLimit || doenvlaue >= currentProduct.GlobalParamEx.CC2UpLimit)
                                                 {
                                                     pressureRes = false;
                                                 }
@@ -3093,7 +3136,7 @@ namespace TeamAAS_VP.Core
                                     WriteProductLog(lockResultsAll, ProductMainSN[i], CTtime);
                                     mes_cc.Clear();
                                     LogHelper.WriteLogMes($"【mes结束ADD】");
-                                    SendTaskMessage($"mes结束ADD", MessageLevel.Info);                                 
+                                    SendTaskMessage($"mes结束ADD", MessageLevel.Info);
                                 }
                                 else
                                 {