徐孝锋 8 ay önce
ebeveyn
işleme
c28761f785

+ 15 - 0
TeamAAS-VM/Core/Common.cs

@@ -106,5 +106,20 @@ namespace TeamAAS_VP.Core
             double angleRad = CalculateAngleBetweenPoints(p1, p2);
             return angleRad * (180.0 / Math.PI);
         }
+
+        /// <summary>
+        /// 使用 Math 类计算两点距离
+        /// </summary>
+        /// <param name="x1"></param>
+        /// <param name="y1"></param>
+        /// <param name="x2"></param>
+        /// <param name="y2"></param>
+        /// <returns></returns>
+        public static double CalculateDistance2D(double x1, double y1, double x2, double y2)
+        {
+            double dx = x2 - x1;
+            double dy = y2 - y1;
+            return Math.Sqrt(dx * dx + dy * dy);
+        }
     }
 }

+ 31 - 19
TeamAAS-VM/Services/CameraCalibrationService.cs

@@ -1654,10 +1654,10 @@ namespace TeamAAS_VP.Services
                 //计算偏差
                 double dx = finalrpos[0] - trans[0];
                 double dy = finalrpos[1] - trans[1];
-                if (Math.Abs(dx) > 0.05 || Math.Abs(dy) > 0.05)
+                if (Math.Abs(dx) > 0.15 || Math.Abs(dy) > 0.15)
                 {
                     MessageBox.Show($"验证失败:独立模组相机标定偏差过大!X方向偏差:{dx:F2} mm,Y方向偏差:{dy:F2} mm");
-                    return (false, null);
+                    //return (false, null);
                 }
                 else
                 {
@@ -1853,23 +1853,35 @@ namespace TeamAAS_VP.Services
             Console.WriteLine(local.Angle);
             Console.WriteLine($"{local.P1[0]:F3},{local.P1[1]:F3}");
 
-            // 9.计算刚体变换矩阵
-            ////得到旋转矩阵
-            //var rigidMatrix = local.InvR;
-            ////平移矩阵
-            //var translation = local.T;
-            //double[,] TransformationMatrix = new double[3, 3];
-            //TransformationMatrix[0, 0] = rigidMatrix[0, 0];
-            //TransformationMatrix[0, 1] = rigidMatrix[0, 1];
-            //TransformationMatrix[0, 2] = translation[0, 0];
-            //TransformationMatrix[1, 0] = rigidMatrix[1, 0];
-            //TransformationMatrix[1, 1] = rigidMatrix[1, 1];
-            //TransformationMatrix[1, 2] = translation[1, 0];
-            //TransformationMatrix[2, 0] = 0;
-            //TransformationMatrix[2, 1] = 0;
-            //TransformationMatrix[2, 2] = 1;
-
-            return (true, local.R.ToArray(), local.T.ToArray());
+            //计算;两点的间距
+            double wordLength = Common.CalculateDistance2D(P1.X, P1.Y, P2.X, P2.Y);
+            double localLength = Common.CalculateDistance2D(P11.X, P11.Y, P12.X, P12.Y);
+            if (Math.Abs(wordLength- localLength)>0.1)
+            {
+                MessageBox.Show("检测下来绝对坐标系移动距离和独立步进坐标系的移动距离差大于0.1mm,请检查哥轴的实际移动距离是否正确!"+ Math.Abs(wordLength - localLength).ToString()+"mm");
+            }
+            else
+            {
+                MessageBox.Show($"检测下来两个坐标系的移动距离正确,实际距离差:{Math.Abs(wordLength - localLength)}mm");
+            }
+
+                // 9.计算刚体变换矩阵
+                ////得到旋转矩阵
+                //var rigidMatrix = local.InvR;
+                ////平移矩阵
+                //var translation = local.T;
+                //double[,] TransformationMatrix = new double[3, 3];
+                //TransformationMatrix[0, 0] = rigidMatrix[0, 0];
+                //TransformationMatrix[0, 1] = rigidMatrix[0, 1];
+                //TransformationMatrix[0, 2] = translation[0, 0];
+                //TransformationMatrix[1, 0] = rigidMatrix[1, 0];
+                //TransformationMatrix[1, 1] = rigidMatrix[1, 1];
+                //TransformationMatrix[1, 2] = translation[1, 0];
+                //TransformationMatrix[2, 0] = 0;
+                //TransformationMatrix[2, 1] = 0;
+                //TransformationMatrix[2, 2] = 1;
+
+                return (true, local.R.ToArray(), local.T.ToArray());
         }
 
         public void Dispose()

+ 7 - 0
TeamAAS-VM/ViewModels/Calibration/CalibrationEditVisionViewModel.cs

@@ -139,6 +139,13 @@ namespace TeamAAS_VP.ViewModels.Calibration
             try
             {
                 SelectCalibration.ToolBlock = ToolBlockEdit.Subject;
+                string toolBlockPath = FilePath.CalibrationPath + "//" + SelectCalibration.Name + "//" + SelectCalibration.Name+".vpp";
+                if (!Directory.Exists(Path.GetDirectoryName(toolBlockPath)))
+                {
+                    Directory.CreateDirectory(Path.GetDirectoryName(toolBlockPath));
+                }
+                //保存校准工具
+                CogSerializer.SaveObjectToFile(ToolBlockEdit.Subject, toolBlockPath);
                 NavigationParameters param = new NavigationParameters();
                 param.Add("SelectCalibration", SelectCalibration);
                 _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationTeachCenterPoint", param);