Przeglądaj źródła

修复相机标定

徐孝锋 8 miesięcy temu
rodzic
commit
4b6b1239cd

+ 19 - 19
TeamAAS-VM/Core/Robots/XYZU_Robot.cs

@@ -937,7 +937,7 @@ namespace TeamAAS_VP.Core.Robots
                     }
 
                     // 判断是否至少有一个轴在最近 Timeout 时间内发生过变化(即认为还在运动)
-                    bool anyAxisMovedRecently = actNodes.Any(node => (now - lastChange[node]).TotalMilliseconds <= 500);
+                    bool anyAxisMovedRecently = actNodes.Any(node => (now - lastChange[node]).TotalMilliseconds <= 1000);
 
                     // 如果没有任何轴在最近 Timeout 时间内发生变化,则认为出现停滞异常
                     if (!anyAxisMovedRecently && actNodes.Length > 0)
@@ -1112,7 +1112,7 @@ namespace TeamAAS_VP.Core.Robots
                     default: targetPos = 0; break;
                 }
                 //如果定位完成且位置一致,则此轴完成,如果有错误则失败
-                if (!(posOk && Math.Abs(actualPos - targetPos) < 0.02))
+                if (!(Math.Abs(actualPos - targetPos) < 0.02))
                 {
                     //if (isError)
                     //{
@@ -1158,11 +1158,11 @@ namespace TeamAAS_VP.Core.Robots
                 isError = (bool)res[axis.State.PausedNode];
             }
             //检查是否到位和位置一致
-            if (isError)
-            {
-                return (true, true);
-            }
-            if (posOk && Math.Abs(actualPos - targetPos) < 0.02)
+            //if (isError)
+            //{
+            //    return (true, true);
+            //}
+            if (Math.Abs(actualPos - targetPos) < 0.02)
             {
                 return (true, false);
             }
@@ -1860,16 +1860,16 @@ namespace TeamAAS_VP.Core.Robots
                 }
 
                 // 更新状态
-                if (isError)
-                {
-                    isAnyError = true;
-                    break;
-                }
-                if (isPaused)
-                {
-                    isAnyError = true;
-                    break;
-                }
+                //if (isError)
+                //{
+                //    isAnyError = true;
+                //    break;
+                //}
+                //if (isPaused)
+                //{
+                //    isAnyError = true;
+                //    break;
+                //}
                 //检查是否到位和位置一致
                 float targetPos = 0;
                 switch (axis.Name)
@@ -1881,7 +1881,7 @@ namespace TeamAAS_VP.Core.Robots
                     default: targetPos = 0; break;
                 }
                 //如果定位完成且位置一致,则此轴完成,如果有错误则失败
-                if (!(posOk && Math.Abs(actualPos - targetPos) < 0.02))
+                if (!(Math.Abs(actualPos - targetPos) < 0.02))
                 {
                     allOk = false;
                     break;
@@ -2014,7 +2014,7 @@ namespace TeamAAS_VP.Core.Robots
                     }
 
                     // 判断是否至少有一个轴在最近 Timeout 时间内发生过变化(即认为还在运动)
-                    bool anyAxisMovedRecently = actNodes.Any(node => (now - lastChange[node]).TotalMilliseconds <= 500);
+                    bool anyAxisMovedRecently = actNodes.Any(node => (now - lastChange[node]).TotalMilliseconds <= 1000);
 
                     // 如果没有任何轴在最近 Timeout 时间内发生变化,则认为出现停滞异常
                     if (!anyAxisMovedRecently && actNodes.Length > 0)

+ 150 - 107
TeamAAS-VM/Services/CameraCalibrationService.cs

@@ -488,29 +488,21 @@ namespace TeamAAS_VP.Services
             pixelScaleX = robotCameraRotationMatrix.PixelScaleX;
             pixelScaleY = robotCameraRotationMatrix.PixelScaleY;
             RobotCameraRotationMatrix = robotCameraRotationMatrix.Item2;
-            //相机拍照并处理图像
-            var photoResult = await CaptureAndProcessCallback();
-            if (!photoResult.IsSuccess)
+
+            //自动移动机器人至图像中心点位置
+            var autoMoveResult = await AutoMoveRobotToImageCenter(robot, RobotCameraRotationMatrix, pixelScaleX, pixelScaleY, cancellationToken);
+            if (!autoMoveResult.IsSuccess)
             {
                 return (false, null, 0, 0, 0, 0);
             }
-            PointF P0 = new PointF((float)(photoResult.X), (float)(photoResult.Y));
+            calibrationInfo.CenterPoint.X = (float)autoMoveResult.X;
+            calibrationInfo.CenterPoint.Y = (float)autoMoveResult.Y;
 
             RPoint RobotU = calibrationInfo.CenterPoint.Clone();
             RobotU.U += (float)calibrationInfo.Angle;
-            //移动机器人中心点
-            isFinished=await robot.CalibMotionAsync(calibrationInfo.CenterPoint, calibrationInfo.CenterPoint.Z);
-            if (!isFinished)
-            {
-                return (false, null, 0, 0, 0, 0);
-            }
-            if (cancellationToken.IsCancellationRequested)
-            {
-                return (false, null, 0, 0, 0, 0);
-            }
 
             //机器人U轴旋转
-            isFinished = await robot.CalibMotionAsync(RobotU, RobotU.Z); 
+            isFinished = await robot.CalibMotionAsync(RobotU, RobotU.Z);
             if (!isFinished)
             {
                 return (false, null, 0, 0, 0, 0);
@@ -521,85 +513,45 @@ namespace TeamAAS_VP.Services
             }
 
             //相机拍照并处理图像
-            photoResult = await CaptureAndProcessCallback();
+            var photoResult = await CaptureAndProcessCallback();
             if (!photoResult.IsSuccess)
             {
                 return (false, null, 0, 0, 0, 0);
             }
             PointF curPixel = new PointF((float)(photoResult.X), (float)(photoResult.Y));
 
-            bool IsFinish = false;
-            for (int i = 0; i < 10; i++)
+            autoMoveResult = await AutoMoveRobotToImageCenter(robot, RobotCameraRotationMatrix, pixelScaleX, pixelScaleY, cancellationToken);
+            if (!autoMoveResult.IsSuccess)
             {
-                //计算需要移动的偏移量,目的是逼近中心点
-                double offsetx = (P0.X - curPixel.X) * pixelScaleX;
-                double offsety = (P0.Y - curPixel.Y) * pixelScaleY;
-                var pos = RobotCameraRotationMatrix.Inverse() * Vector<double>.Build.Dense(new double[] { offsetx, offsety });
-
-                RobotU.X += (float)pos[0];
-                RobotU.Y += (float)pos[1];
-                //机器人移动
-                isFinished = await robot.CalibMotionAsync(RobotU, RobotU.Z);
-                if (!isFinished)
-                {
-                    return (false, null, 0, 0, 0, 0);
-                }
-                if (cancellationToken.IsCancellationRequested)
-                {
-                    return (false, null, 0, 0, 0, 0);
-                }
+                return (false, null, 0, 0, 0, 0);
+            }
+            RobotU.X = (float)autoMoveResult.X;
+            RobotU.Y = (float)autoMoveResult.Y;
 
-                photoResult = await CaptureAndProcessCallback();
-                if (!photoResult.IsSuccess)
-                {
-                    return (false, null, 0, 0, 0, 0);
-                }
-                curPixel = new PointF((float)(photoResult.X), (float)(photoResult.Y));
-                offsetx = P0.X - curPixel.X;
-                offsety = P0.Y - curPixel.Y;
-                //await Console.Out.WriteLineAsync($"移动后的差异:{offsetx},{offsety}");
-                if (Math.Abs(offsetx) < 1 && Math.Abs(offsetx) < 1)
-                {
-                    //移动机器人至待机位置
-                    isFinished=await robot.CalibMotionAsync(calibrationInfo.CenterPoint, calibrationInfo.CenterPoint.Z);
-                    if (!isFinished)
-                    {
-                        return (false, null, 0, 0, 0, 0);
-                    }
-                    IsFinish = true;
-                    break;
-                }
-                if (cancellationToken.IsCancellationRequested)
-                {
-                    return (false, null, 0, 0, 0, 0);
-                }
+            isFinished = await robot.CalibMotionAsync(calibrationInfo.CenterPoint, null);
+            if (!isFinished)
+            {
+                return (false, null, 0, 0, 0, 0);
             }
 
-            if (IsFinish)
+            Vector<double> p0 = Vector<double>.Build.Dense(new double[] { calibrationInfo.CenterPoint.X, calibrationInfo.CenterPoint.Y });
+            Vector<double> p1 = Vector<double>.Build.Dense(new double[] { RobotU.X, RobotU.Y });
+            ToolCoord toolCoord = new ToolCoord();
+            double u1 = calibrationInfo.CenterPoint.U;
+            double u2 = RobotU.U;
+            if (robot.Brand == Enums.RobotBrand.Schneider)
             {
-                Vector<double> p0 = Vector<double>.Build.Dense(new double[] { calibrationInfo.CenterPoint.X, calibrationInfo.CenterPoint.Y });
-                Vector<double> p1 = Vector<double>.Build.Dense(new double[] { RobotU.X, RobotU.Y });
-                ToolCoord toolCoord = new ToolCoord();
-                double u1 = calibrationInfo.CenterPoint.U;
-                double u2 = RobotU.U;
-                if (robot.Brand == Enums.RobotBrand.Schneider)
-                {
-                    u1 *= -1;
-                    u2 *= -1;
-                }
-                toolCoord.ComputeTool(p0, p1, u1, u2);
-                if (calibrationInfo.Tool == null)
-                {
-                    calibrationInfo.Tool = new RobotTool();
-                }
-                calibrationInfo.Tool.X = toolCoord.X;
-                calibrationInfo.Tool.Y = toolCoord.Y;
-                return (true, RobotCameraRotationMatrix, calibrationInfo.Tool.X, calibrationInfo.Tool.Y, pixelScaleX, pixelScaleY);
+                u1 *= -1;
+                u2 *= -1;
             }
-            else
+            toolCoord.ComputeTool(p0, p1, u1, u2);
+            if (calibrationInfo.Tool == null)
             {
-                return (false, null, 0, 0, 0, 0);
+                calibrationInfo.Tool = new RobotTool();
             }
+            calibrationInfo.Tool.X = toolCoord.X;
+            calibrationInfo.Tool.Y = toolCoord.Y;
+            return (true, RobotCameraRotationMatrix, calibrationInfo.Tool.X, calibrationInfo.Tool.Y, pixelScaleX, pixelScaleY);
         }
 
         /// <summary>
@@ -672,18 +624,26 @@ namespace TeamAAS_VP.Services
         {
             //移动距离,单位mm
             float distance = ((float)calibrationInfo.Height) / 3;
-
+            bool isFinished = false;
             //-------------------------------------------P0-----------------------------------
             //移动机器人至中心点
             if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown && !calibrationInfo.FixedDownCameraNoReturnToHome)
             {
-                await robot.CalibMotionAsync(calibrationInfo.CenterPoint, null);
+                isFinished = await robot.CalibMotionAsync(calibrationInfo.CenterPoint, null);
+                if (!isFinished)
+                {
+                    return (false, null, 0, 0);
+                }
                 //关闭吸气
                 await robot.CalibOutIOAsync(false);
             }
             else
             {
-                await robot.CalibMotionAsync(calibrationInfo.CenterPoint, calibrationInfo.CenterPoint.Z);
+                isFinished = await robot.CalibMotionAsync(calibrationInfo.CenterPoint, calibrationInfo.CenterPoint.Z);
+                if (!isFinished)
+                {
+                    return (false, null, 0, 0);
+                }
             }
 
 
@@ -696,7 +656,11 @@ namespace TeamAAS_VP.Services
             if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown && !calibrationInfo.FixedDownCameraNoReturnToHome)
             {
                 //移动机器人至待机位置
-                await robot.CalibMotionAsync(calibrationInfo.HomePoint, null);
+                isFinished = await robot.CalibMotionAsync(calibrationInfo.HomePoint, null);
+                if (!isFinished)
+                {
+                    return (false, null, 0, 0);
+                }
             }
 
             //相机拍照并处理图像
@@ -711,7 +675,11 @@ namespace TeamAAS_VP.Services
             if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown && !calibrationInfo.FixedDownCameraNoReturnToHome)
             {
                 //移动机器人至P0
-                await robot.CalibMotionAsync(RobotP0, null);
+                isFinished = await robot.CalibMotionAsync(RobotP0, null);
+                if (!isFinished)
+                {
+                    return (false, null, 0, 0);
+                }
                 if (cancellationToken.IsCancellationRequested)
                 {
                     return (false, null, 0, 0);
@@ -719,7 +687,11 @@ namespace TeamAAS_VP.Services
                 //打开吸气
                 await robot.CalibOutIOAsync(true);
                 //移动机器人至P1
-                await robot.CalibMotionAsync(RobotP1, null);
+                isFinished = await robot.CalibMotionAsync(RobotP1, null);
+                if (!isFinished)
+                {
+                    return (false, null, 0, 0);
+                }
                 if (cancellationToken.IsCancellationRequested)
                 {
                     return (false, null, 0, 0);
@@ -727,12 +699,20 @@ namespace TeamAAS_VP.Services
                 //关闭吸气
                 await robot.CalibOutIOAsync(false);
                 //移动机器人至待机位置
-                await robot.CalibMotionAsync(calibrationInfo.HomePoint, null);
+                isFinished = await robot.CalibMotionAsync(calibrationInfo.HomePoint, null);
+                if (!isFinished)
+                {
+                    return (false, null, 0, 0);
+                }
             }
             else
             {
                 //移动机器人至P1
-                await robot.CalibMotionAsync(RobotP1, RobotP1.Z);
+                isFinished= await robot.CalibMotionAsync(RobotP1, RobotP1.Z);
+                if (!isFinished)
+                {
+                    return (false, null, 0, 0);
+                }
             }
 
             if (cancellationToken.IsCancellationRequested)
@@ -752,7 +732,11 @@ namespace TeamAAS_VP.Services
             if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown && !calibrationInfo.FixedDownCameraNoReturnToHome)
             {
                 //移动机器人至P1
-                await robot.CalibMotionAsync(RobotP1, null);
+                isFinished= await robot.CalibMotionAsync(RobotP1, null);
+                if (!isFinished)
+                {
+                    return (false, null, 0, 0);
+                }
                 if (cancellationToken.IsCancellationRequested)
                 {
                     return (false, null, 0, 0);
@@ -760,7 +744,11 @@ namespace TeamAAS_VP.Services
                 //打开吸气
                 await robot.CalibOutIOAsync(true);
                 //移动机器人至P2
-                await robot.CalibMotionAsync(RobotP2, null);
+                isFinished= await robot.CalibMotionAsync(RobotP2, null);
+                if (!isFinished)
+                {
+                    return (false, null, 0, 0);
+                }
                 if (cancellationToken.IsCancellationRequested)
                 {
                     return (false, null, 0, 0);
@@ -768,12 +756,20 @@ namespace TeamAAS_VP.Services
                 //关闭吸气
                 await robot.CalibOutIOAsync(false);
                 //移动机器人至待机位置
-                await robot.CalibMotionAsync(calibrationInfo.HomePoint, null);
+                isFinished= await robot.CalibMotionAsync(calibrationInfo.HomePoint, null);
+                if (!isFinished)
+                {
+                    return (false, null, 0, 0);
+                }
             }
             else
             {
                 //移动机器人至P2
-                await robot.CalibMotionAsync(RobotP2, RobotP2.Z);
+                isFinished= await robot.CalibMotionAsync(RobotP2, RobotP2.Z);
+                if (!isFinished)
+                {
+                    return (false, null, 0, 0);
+                }
             }
             if (cancellationToken.IsCancellationRequested)
             {
@@ -793,7 +789,11 @@ namespace TeamAAS_VP.Services
             if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown && !calibrationInfo.FixedDownCameraNoReturnToHome)
             {
                 //移动机器人至P2
-                await robot.CalibMotionAsync(RobotP2, null);
+                isFinished= await robot.CalibMotionAsync(RobotP2, null);
+                if (!isFinished)
+                {
+                    return (false, null, 0, 0);
+                }
                 if (cancellationToken.IsCancellationRequested)
                 {
                     return (false, null, 0, 0);
@@ -801,7 +801,11 @@ namespace TeamAAS_VP.Services
                 //打开吸气
                 await robot.CalibOutIOAsync(true);
                 //移动机器人至P0
-                await robot.CalibMotionAsync(RobotP0, null);
+                isFinished= await robot.CalibMotionAsync(RobotP0, null);
+                if (!isFinished)
+                {
+                    return (false, null, 0, 0);
+                }
                 if (cancellationToken.IsCancellationRequested)
                 {
                     return (false, null, 0, 0);
@@ -809,12 +813,20 @@ namespace TeamAAS_VP.Services
                 //关闭吸气
                 await robot.CalibOutIOAsync(false);
                 //移动机器人至待机位置
-                await robot.CalibMotionAsync(calibrationInfo.HomePoint, null);
+                isFinished= await robot.CalibMotionAsync(calibrationInfo.HomePoint, null);
+                if (!isFinished)
+                {
+                    return (false, null, 0, 0);
+                }
             }
             else
             {
                 //移动机器人至P0
-                await robot.CalibMotionAsync(RobotP0, RobotP0.Z);
+                isFinished= await robot.CalibMotionAsync(RobotP0, RobotP0.Z);
+                if (!isFinished)
+                {
+                    return (false, null, 0, 0);
+                }
             }
             if (cancellationToken.IsCancellationRequested)
             {
@@ -1509,7 +1521,7 @@ namespace TeamAAS_VP.Services
                 Local = calibrationInfo.CenterPoint.Local,
                 Tool = calibrationInfo.CenterPoint.Tool
             });
-
+            bool isSucceed = false;
             List<Vector<double>> TestPos = new List<Vector<double>>();
             for (int i = 0; i < rPoints.Count; i++)
             {
@@ -1524,12 +1536,20 @@ namespace TeamAAS_VP.Services
                     //关闭吸气
                     await robot.CalibOutIOAsync(false);
                     //移动机器人至待机位置
-                    await robot.CalibMotionAsync(calibrationInfo.HomePoint, null);
+                    isSucceed = await robot.CalibMotionAsync(calibrationInfo.HomePoint, null);
+                    if (!isSucceed)
+                    {
+                        return (false, null);
+                    }
                 }
                 else
                 {
                     //移动机器人至i
-                    await robot.CalibMotionAsync(rPoints[i], rPoints[i].Z);
+                    isSucceed = await robot.CalibMotionAsync(rPoints[i], rPoints[i].Z);
+                    if (!isSucceed)
+                    {
+                        return (false, null);
+                    }
                 }
                 if (cancellationToken.IsCancellationRequested)
                 {
@@ -1550,7 +1570,11 @@ namespace TeamAAS_VP.Services
                 if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown)
                 {
                     //移动机器人至i
-                    await robot.CalibMotionAsync(rPoints[i], null);
+                    isSucceed = await robot.CalibMotionAsync(rPoints[i], null);
+                    if (!isSucceed)
+                    {
+                        return (false, null);
+                    }
                     //打开吸气
                     await robot.CalibOutIOAsync(true);
                 }
@@ -1564,17 +1588,29 @@ namespace TeamAAS_VP.Services
             if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown)
             {
                 //移动机器人至待机位置
-                await robot.CalibMotionAsync(calibrationInfo.HomePoint, null);
+                isSucceed = await robot.CalibMotionAsync(calibrationInfo.HomePoint, null);
+                if (!isSucceed)
+                {
+                    return (false, null);
+                }
             }
             else if (calibrationInfo.CameraMount == Enums.CameraMount.MobileDown_IndependentXYPlatform)
             {
                 //移动机器人至中心点
-                await robot.CalibMotionAsync(calibrationInfo.CenterPoint, null);
+                isSucceed = await robot.CalibMotionAsync(calibrationInfo.CenterPoint, null);
+                if (!isSucceed)
+                {
+                    return (false, null);
+                }
                 //移动独立模组偏移X距离
                 var movePos = calibrationInfo.IndependentDownCameraMotionModulePoint.Clone();
                 movePos.X += (float)calibrationInfo.IndependentDownCameraMotionModuleMoveX;
-                await ((XYZU_Robot)robot).WaitCameraMoveFinishedAsync(calibrationInfo.CameraMotionModuleIndex, movePos);
-                await Task.Delay(300);
+                isSucceed = await ((XYZU_Robot)robot).WaitCameraMoveFinishedAsync(calibrationInfo.CameraMotionModuleIndex, movePos);
+                if (!isSucceed)
+                {
+                    return (false, null);
+                }
+                await Task.Delay(500);
                 //相机拍照获取像素坐标
                 var photoResult = await CaptureAndProcessCallback();
                 if (!photoResult.IsSuccess)
@@ -1594,8 +1630,8 @@ namespace TeamAAS_VP.Services
                 //平移向量
                 Vector<double> PT = Vector<double>.Build.Dense(new double[] { T[0, 2], T[1, 2] });
 
-                Vector<double> p100 = Vector<double>.Build.Dense(new double[] { calibrationInfo.IndependentDownCameraMotionModulePoint.X, calibrationInfo.IndependentDownCameraMotionModulePoint.Y, 1 });
-                Vector<double> p101 = Vector<double>.Build.Dense(new double[] { movePos.X, movePos.Y, 1 });
+                Vector<double> p100 = Vector<double>.Build.Dense(new double[] { calibrationInfo.IndependentDownCameraMotionModulePoint.X, calibrationInfo.IndependentDownCameraMotionModulePoint.Y });
+                Vector<double> p101 = Vector<double>.Build.Dense(new double[] { movePos.X, movePos.Y });
                 //计算独立模组坐标系下的坐标
                 Vector<double> pl1 = R.Inverse() * (rpos - PT);
                 Vector<double> pl2 = pl1 + (p101 - p100);
@@ -1609,7 +1645,11 @@ namespace TeamAAS_VP.Services
                 var trans = toolCoord1.GetToolnCoord(Vector<double>.Build.Dense(new double[] { calibrationInfo.CenterPoint.X, calibrationInfo.CenterPoint.Y }), u1);
 
                 //独立移动模组回到初始位置
-                await ((XYZU_Robot)robot).WaitCameraMoveFinishedAsync(calibrationInfo.CameraMotionModuleIndex, calibrationInfo.IndependentDownCameraMotionModulePoint);
+                isSucceed = await ((XYZU_Robot)robot).WaitCameraMoveFinishedAsync(calibrationInfo.CameraMotionModuleIndex, calibrationInfo.IndependentDownCameraMotionModulePoint);
+                if (!isSucceed)
+                {
+                    return (false, null);
+                }
 
                 //计算偏差
                 double dx = finalrpos[0] - trans[0];
@@ -1748,6 +1788,7 @@ namespace TeamAAS_VP.Services
                 return (false, null, null);
             }
             PointF P11 = new PointF(calibrationInfo.IndependentDownCameraMotionModulePoint.X, calibrationInfo.IndependentDownCameraMotionModulePoint.Y);
+            await Task.Delay(300);
 
             double pixelScaleX = 0;
             double pixelScaleY = 0;
@@ -1809,6 +1850,8 @@ namespace TeamAAS_VP.Services
             var p2 = toolCoord1.GetToolnCoord(pf, currentRobotPos.U);
             PointF P2 = new PointF((float)p2[0], (float)p2[1]);
             CoordinateTransformer local = new CoordinateTransformer(P1, P2, P11, P12);
+            Console.WriteLine(local.Angle);
+            Console.WriteLine($"{local.P1[0]:F3},{local.P1[1]:F3}");
 
             // 9.计算刚体变换矩阵
             ////得到旋转矩阵

+ 3 - 3
TeamAAS-VM/ViewModels/Calibration/CalibIndependentCameraViewModel.cs

@@ -140,9 +140,9 @@ namespace TeamAAS_VP.ViewModels.Calibration
                 }
                 SelectCalibration.IndependentDownCameraMotionModuleRotationMatrix = RotationMatrix;
                 SelectCalibration.IndependentDownCameraMotionModuleTranslationMatrix = TranslationMatrix;
-                NavigationParameters param = new NavigationParameters();
-                param.Add("SelectCalibration", SelectCalibration);
-                _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationAuto", param);
+                //NavigationParameters param = new NavigationParameters();
+                //param.Add("SelectCalibration", SelectCalibration);
+                //_regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationAuto", param);
                 
             }
             catch (Exception ex)

+ 26 - 2
TeamAAS-VM/Views/Calibration/CalibTool.xaml.cs

@@ -1,4 +1,6 @@
-using System;
+using Cognex.VisionPro;
+using Cognex.VisionPro.Dimensioning;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -33,6 +35,8 @@ namespace TeamAAS_VP.Views.Calibration
             this.display.BackColor = System.Drawing.SystemColors.ActiveCaption;
         }
 
+        private int _imageWidth;
+        private int _imageHeight;
         private void VM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
         {
             try
@@ -40,11 +44,31 @@ namespace TeamAAS_VP.Views.Calibration
                 if (e.PropertyName == "Image")
                 {
                     this.display.Image = VM.Image;
+                    //图像中心点坐标
+                    _imageWidth = this.display.Image.Width;
+                    _imageHeight = this.display.Image.Height;
                 }
                 else if (e.PropertyName == "Graphic")
                 {
                     this.display.StaticGraphics.Clear();
-                    if (VM.Graphic!=null)
+                    CogGraphicCollection graphic = new CogGraphicCollection();
+                    CogCreateLineTool line1 = new CogCreateLineTool();
+                    CogCreateLineTool line2 = new CogCreateLineTool();
+                    line1.InputImage = this.display.Image;
+                    line2.InputImage = this.display.Image;
+                    line1.Line.X = _imageWidth / 2;
+                    line1.Line.Y = _imageHeight / 2;
+                    line1.Line.Rotation = 0;
+                    line2.Line.X = _imageWidth / 2;
+                    line2.Line.Y = _imageHeight / 2;
+                    line2.Line.Rotation = Math.PI / 180 * 90;
+                    line1.Run();
+                    line2.Run();
+                    graphic.Add(line1.GetOutputLine());
+                    graphic.Add(line2.GetOutputLine());
+                    this.display.StaticGraphics.Clear();
+                    this.display.StaticGraphics.AddList(graphic, "");
+                    if (VM.Graphic != null)
                     {
                         this.display.StaticGraphics.AddList(VM.Graphic, "");
                     }

+ 27 - 2
TeamAAS-VM/Views/Calibration/CalibrationVerification.xaml.cs

@@ -1,4 +1,7 @@
-using System.Windows.Controls;
+using Cognex.VisionPro;
+using Cognex.VisionPro.Dimensioning;
+using System;
+using System.Windows.Controls;
 using TeamAAS_VP.ViewModels.Calibration;
 
 namespace TeamAAS_VP.Views.Calibration
@@ -20,6 +23,8 @@ namespace TeamAAS_VP.Views.Calibration
             this.display.BackColor = System.Drawing.SystemColors.ActiveCaption;
         }
 
+        private int _imageWidth;
+        private int _imageHeight;
         private void VM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
         {
             try
@@ -27,11 +32,31 @@ namespace TeamAAS_VP.Views.Calibration
                 if (e.PropertyName == "Image")
                 {
                     this.display.Image = VM.Image;
+                    //图像中心点坐标
+                    _imageWidth = this.display.Image.Width;
+                    _imageHeight = this.display.Image.Height;
                 }
                 else if (e.PropertyName == "Graphic")
                 {
                     this.display.StaticGraphics.Clear();
-                    if (VM.Graphic!=null)
+                    CogGraphicCollection graphic = new CogGraphicCollection();
+                    CogCreateLineTool line1 = new CogCreateLineTool();
+                    CogCreateLineTool line2 = new CogCreateLineTool();
+                    line1.InputImage = this.display.Image;
+                    line2.InputImage = this.display.Image;
+                    line1.Line.X = _imageWidth / 2;
+                    line1.Line.Y = _imageHeight / 2;
+                    line1.Line.Rotation = 0;
+                    line2.Line.X = _imageWidth / 2;
+                    line2.Line.Y = _imageHeight / 2;
+                    line2.Line.Rotation = Math.PI / 180 * 90;
+                    line1.Run();
+                    line2.Run();
+                    graphic.Add(line1.GetOutputLine());
+                    graphic.Add(line2.GetOutputLine());
+                    this.display.StaticGraphics.Clear();
+                    this.display.StaticGraphics.AddList(graphic, "");
+                    if (VM.Graphic != null)
                     {
                         this.display.StaticGraphics.AddList(VM.Graphic, "");
                     }