Răsfoiți Sursa

相机采集、PLC防抖与标定流程健壮性优化

本次提交主要包括以下改进:
- 相机采集流程优化,支持软触发与回调,提升实时性与容错性;
- PLC命令触发增加防抖处理,避免重复执行,提升系统稳定性;
- 机器人运动完成判断逻辑优化,减少误判与不必要的PLC操作;
- 相机标定流程增加运动结果判断,异常时及时中断,提升健壮性;
- 代码细节优化,提升可读性,移除冗余代码。
孝锋 徐 8 luni în urmă
părinte
comite
67ec41d992

+ 40 - 7
TeamAAS-VM/Core/Cameras/OptCamera.cs

@@ -1,5 +1,6 @@
 using Cognex.VisionPro;
 using Microsoft.Win32;
+using NPOI.POIFS.Crypt.Dsig;
 using NPOI.SS.Formula.Eval;
 using SciCamera.Net;
 using System;
@@ -121,7 +122,7 @@ namespace TeamAAS_VP.Core.Cameras
 
                 if (devTlType == SciCam.SciCamTLType.SciCam_TLType_Gige)
                 {
-                    
+
                     SciCam.SCI_DEVICE_GIGE_INFO gigeDevInfo = (SciCam.SCI_DEVICE_GIGE_INFO)SciCam.ByteToStruct(device.info.gigeInfo, typeof(SciCam.SCI_DEVICE_GIGE_INFO));
                     uint ip1 = gigeDevInfo.ip;
                     int nIp1 = (int)(ip1 & 0x000000ff);
@@ -337,7 +338,7 @@ namespace TeamAAS_VP.Core.Cameras
                         throw new Exception("没有发现相机");
                     }
                 }
-                SciCam.SCI_DEVICE_INFO sCI_DEVICE_INFO= CameraInfo;
+                SciCam.SCI_DEVICE_INFO sCI_DEVICE_INFO = CameraInfo;
                 nReVal = mvCameraAcq.CreateDevice(ref sCI_DEVICE_INFO);
                 if (nReVal != SciCam.SCI_CAMERA_OK)
                 {
@@ -348,13 +349,22 @@ namespace TeamAAS_VP.Core.Cameras
                 nReVal = mvCameraAcq.OpenDevice();
                 // ch:设置触发模式为off | en:Set trigger mode as off
                 nReVal = mvCameraAcq.SetEnumValueByStringEx(SciCam.SciCamDeviceXmlType.SciCam_DeviceXml_Camera, "TriggerMode", "Off");
+                nReVal = mvCameraAcq.SetEnumValueByString("TriggerSource", "Software");
+                // ch:注册事件回调 | en:Register event callback
+                //nReVal = mvCameraAcq.RegisterPayloadCallBack(new SciCam.fnOnPayloadDelegate(ImageCallBack), IntPtr.Zero, true);
+                // ch:设置采集策略 | en:Set Grab Strategy
+                nReVal = mvCameraAcq.SetGrabStrategy(SciCam.SciCamGrabStrategy.SciCam_GrabStrategy_Latest);
+                if (nReVal != SciCam.SCI_CAMERA_OK)
+                {
+                    Console.WriteLine("Register Event CallBack fail! nRet {0}", nReVal);
+                }
                 if (!IsConnected)
                 {
                     CameraConnectChangedEvent?.Invoke(ID, true);
                 }
-                mvCameraAcq.SetGrabTimeout(300);
+                mvCameraAcq.SetGrabTimeout(2000);
                 IsConnected = mvCameraAcq.IsDeviceOpen();
-                if (IsConnected) 
+                if (IsConnected)
                 {
                     mvCameraAcq.StartGrabbing();
                 }
@@ -421,7 +431,9 @@ namespace TeamAAS_VP.Core.Cameras
                         //    mvCameraAcq.StartGrabbing();
                         //}
                         //nReVal = mvCameraAcq.StartGrabbing();
-                        mvCameraAcq.ClearPayloadBuffer();
+                        //mvCameraAcq.ClearPayloadBuffer();
+                        // ch:发送软触发命令 | en:Send Trigger Software command
+                        //nReVal = mvCameraAcq.SetCommandValueEx(SciCam.SciCamDeviceXmlType.SciCam_DeviceXml_Camera, "TriggerSoftware");
                         nReVal = mvCameraAcq.Grab(ref payload);
                         if (nReVal == SciCam.SCI_CAMERA_OK)
                         {
@@ -429,12 +441,12 @@ namespace TeamAAS_VP.Core.Cameras
                             mvCameraAcq.FreePayload(payload);
                             //nReVal = mvCameraAcq.StopGrabbing();
                             TotalTime = sw.Elapsed;
-                            ErrorMessage= $"{i+1}";
+                            ErrorMessage = $"{i + 1}";
                             return Image;
                         }
                         else
                         {
-                            nReVal = mvCameraAcq.FreePayload(payload);
+                            //nReVal = mvCameraAcq.FreePayload(payload);
                             //nReVal = mvCameraAcq.StopGrabbing();
                             //_operationSemaphore.Release();
                             CloseDevice();
@@ -463,6 +475,27 @@ namespace TeamAAS_VP.Core.Cameras
             }
         }
 
+        // ch:采集回调接口 | en:Grab Callback interface     
+        void ImageCallBack(IntPtr payload, IntPtr tag)
+        {
+            if (payload == IntPtr.Zero) return;
+            uint nReVal = SciCam.SCI_CAMERA_OK;
+
+            SciCam.SCI_CAM_PAYLOAD_ATTRIBUTE attribute = new SciCam.SCI_CAM_PAYLOAD_ATTRIBUTE();
+            nReVal = SciCam.PayloadGetAttribute(payload, ref attribute);
+            if (nReVal != SciCam.SCI_CAMERA_OK || !attribute.isComplete)
+            {
+                Console.WriteLine("Failed to get image attributes or frame is incomplete! nRet:{0}", nReVal);
+            }
+            else
+            {
+                Image = GetConvertedInfo(payload);
+                ImageCallbackEvent?.Invoke(Image, TotalTime, ErrorMessage);
+                //Console.WriteLine("Get One Frame: Width[{0}], Height[{1}], nFrameNum[{2}]",
+                //attribute.imgAttr.width, attribute.imgAttr.height, attribute.frameID);
+            }
+        }
+
         /// <summary>
         /// 开始采集图像
         /// </summary>

+ 130 - 0
TeamAAS-VM/Core/Management.cs

@@ -1048,6 +1048,20 @@ namespace TeamAAS_VP.Core
         double _FixedUpCameraAngle = 0;
         double _MoveCameraAngle = 0;
 
+        bool _LastDowmCameraExe = false;
+        bool _LastScrewTeachExe = false;
+        bool _LastUpCameraPickExe = false;
+        bool _LastUpCameraPutExe = false;
+        bool _LastUPCameracheckExe = false;
+        bool _LastFixedCameraPickExe = false;
+        bool _LastFixedCameraPutExe = false;
+        bool _LastFixedCameracheckExe = false;
+        Int16 _LastWorkStart = 0;
+        Int16 _LastWorkDone = 0;
+        Int16 _LastRequestPosition = 0;
+        Int16 _LastPickINC = 0;
+        Int16[] _LastMesCheck = new Int16[10];
+
         /// <summary>
         /// PLC命令触发时
         /// </summary>
@@ -1086,6 +1100,14 @@ namespace TeamAAS_VP.Core
                 {
                     if (tuple.value is bool state)
                     {
+                        if (_LastDowmCameraExe != state)
+                        {
+                            _LastDowmCameraExe = state;
+                        }
+                        else
+                        {
+                            return;
+                        }
                         if (state)
                         {
                             SendTaskMessage($"触发下相机拍照...", MessageLevel.Debug);
@@ -1299,6 +1321,15 @@ namespace TeamAAS_VP.Core
                 {
                     if (tuple.value is bool state)
                     {
+                        if (_LastScrewTeachExe != state)
+                        {
+                            _LastScrewTeachExe = state;
+                        }
+                        else
+                        {
+                            return;
+                        }
+
                         if (state)
                         {
                             SendTaskMessage($"触发下相机拍照...", MessageLevel.Debug);
@@ -1357,6 +1388,15 @@ namespace TeamAAS_VP.Core
                 {
                     if (tuple.value is bool state)
                     {
+                        if (_LastUpCameraPickExe != state)
+                        {
+                            _LastUpCameraPickExe = state;
+                        }
+                        else
+                        {
+                            return;
+                        }
+
                         if (state)
                         {
                             SendTaskMessage($"触发上相机取料拍照...", MessageLevel.Debug);
@@ -1464,6 +1504,15 @@ namespace TeamAAS_VP.Core
                 {
                     if (tuple.value is bool state)
                     {
+                        if (_LastUpCameraPutExe != state)
+                        {
+                            _LastUpCameraPutExe = state;
+                        }
+                        else
+                        {
+                            return;
+                        }
+
                         if (state)
                         {
                             SendTaskMessage($"触发上相机锁附/组装拍照...", MessageLevel.Debug);
@@ -1571,6 +1620,15 @@ namespace TeamAAS_VP.Core
                 {
                     if (tuple.value is bool state)
                     {
+                        if (_LastUPCameracheckExe != state)
+                        {
+                            _LastUPCameracheckExe = state;
+                        }
+                        else
+                        {
+                            return;
+                        }
+
                         if (state)
                         {
                             SendTaskMessage($"触发上相机检测拍照...", MessageLevel.Debug);
@@ -1593,6 +1651,15 @@ namespace TeamAAS_VP.Core
                 {
                     if (tuple.value is bool state)
                     {
+                        if (_LastFixedCameraPickExe != state)
+                        {
+                            _LastFixedCameraPickExe = state;
+                        }
+                        else
+                        {
+                            return;
+                        }
+
                         if (state)
                         {
                             SendTaskMessage($"触发固定相机取料拍照...", MessageLevel.Debug);
@@ -1615,6 +1682,15 @@ namespace TeamAAS_VP.Core
                 {
                     if (tuple.value is bool state)
                     {
+                        if (_LastFixedCameraPutExe != state)
+                        {
+                            _LastFixedCameraPutExe = state;
+                        }
+                        else
+                        {
+                            return;
+                        }
+
                         if (state)
                         {
                             SendTaskMessage($"触发固定相机锁附/组装拍照...", MessageLevel.Debug);
@@ -1636,6 +1712,15 @@ namespace TeamAAS_VP.Core
                 {
                     if (tuple.value is bool state)
                     {
+                        if (_LastFixedCameracheckExe != state)
+                        {
+                            _LastFixedCameracheckExe = state;
+                        }
+                        else
+                        {
+                            return;
+                        }
+
                         if (state)
                         {
                             SendTaskMessage($"触发固定相机检测拍照...", MessageLevel.Debug);
@@ -1657,6 +1742,15 @@ namespace TeamAAS_VP.Core
                 {
                     if (tuple.value is Int16 state)
                     {
+                        if (_LastWorkStart != state)
+                        {
+                            _LastWorkStart = state;
+                        }
+                        else
+                        {
+                            return;
+                        }
+
                         if (state == 1)
                         {
                             SendTaskMessage($"收到开始锁付信号...", MessageLevel.Debug);
@@ -1676,6 +1770,15 @@ namespace TeamAAS_VP.Core
                 {
                     if (tuple.value is Int16 state)
                     {
+                        if (_LastWorkDone != state)
+                        {
+                            _LastWorkDone = state;
+                        }
+                        else
+                        {
+                            return;
+                        }
+
                         if (state == 1 || state == 2)
                         {
                             SendTaskMessage($"收到停止锁付信号...", MessageLevel.Debug);
@@ -1737,6 +1840,15 @@ namespace TeamAAS_VP.Core
                 {
                     if (tuple.value is Int16 state)
                     {
+                        if (_LastRequestPosition != state)
+                        {
+                            _LastRequestPosition = state;
+                        }
+                        else
+                        {
+                            return;
+                        }
+
                         if (state == 1)
                         {
                             SendTaskMessage($"收到多相机坐标合并请求,开始合并...", MessageLevel.Debug);
@@ -1793,6 +1905,15 @@ namespace TeamAAS_VP.Core
                 {
                     if (tuple.value is Int16 state)
                     {
+                        if (_LastPickINC != state)
+                        {
+                            _LastPickINC = state;
+                        }
+                        else
+                        {
+                            return;
+                        }
+
                         if (state != 0)
                         {
                             SendTaskMessage($"螺丝供料器...", MessageLevel.Info);
@@ -1810,6 +1931,15 @@ namespace TeamAAS_VP.Core
                         {
                             if (tuple.value is Int16 state)
                             {
+                                if (_LastMesCheck[i] != state)
+                                {
+                                    _LastMesCheck[i] = state;
+                                }
+                                else
+                                {
+                                    return;
+                                }
+
                                 if (state == 1)
                                 {
                                     if (i == 0)

+ 37 - 35
TeamAAS-VM/Core/Robots/XYZU_Robot.cs

@@ -694,13 +694,15 @@ namespace TeamAAS_VP.Core.Robots
                     if (isFinished)
                     {
                         StopMove();
-                        if (isError)
-                        {
-                            LogHelper.WriteLogInfo($"机器人执行移动时发生错误,位置:X={position.X},Y={position.Y},Z={position.Z},U={position.U}");
-                            return false;
-                        }
+                        
                         return true;
                     }
+                    if (isError)
+                    {
+                        StopMove();
+                        LogHelper.WriteLogInfo($"机器人执行移动时发生错误,位置:X={position.X},Y={position.Y},Z={position.Z},U={position.U}");
+                        return false;
+                    }
 
                     // 检查整体超时(防止一直有抖动导致 anyAxisMovedRecently 一直为 true)
                     if (sw.ElapsedMilliseconds > 60000) // 保守超时,一分钟,可根据需求调整
@@ -759,10 +761,10 @@ namespace TeamAAS_VP.Core.Robots
                 {
                     keyValues.Add(axis.Command.ManuPositionNode, false);
                 }
-                if (!string.IsNullOrWhiteSpace(axis.Command.StopNode))
-                {
-                    keyValues.Add(axis.Command.StopNode, true);
-                }
+                //if (!string.IsNullOrWhiteSpace(axis.Command.StopNode))
+                //{
+                //    keyValues.Add(axis.Command.StopNode, true);
+                //}
             }
             bool result = Plc.WriteNodes(keyValues);
 
@@ -770,16 +772,16 @@ namespace TeamAAS_VP.Core.Robots
             //Task.Run(async () =>
             //{
             //    await Task.Delay(100);
-            Thread.Sleep(50);
-            Dictionary<string, object> resetValues = new Dictionary<string, object>();
-            foreach (var axis in Axes)
-            {
-                if (!string.IsNullOrWhiteSpace(axis.Command.StopNode))
-                {
-                    resetValues.Add(axis.Command.StopNode, false);
-                }
-            }
-            Plc.WriteNodes(resetValues);
+            //Thread.Sleep(50);
+            //Dictionary<string, object> resetValues = new Dictionary<string, object>();
+            //foreach (var axis in Axes)
+            //{
+            //    if (!string.IsNullOrWhiteSpace(axis.Command.StopNode))
+            //    {
+            //        resetValues.Add(axis.Command.StopNode, false);
+            //    }
+            //}
+            //Plc.WriteNodes(resetValues);
             //});
             return result;
         }
@@ -838,11 +840,11 @@ namespace TeamAAS_VP.Core.Robots
                 {
                     isError = (bool)res[axis.State.PausedNode];
                 }
-                if (isError)
-                {
-                    isAnyError = true;
-                    break;
-                }
+                //if (isError)
+                //{
+                //    isAnyError = true;
+                //    break;
+                //}
                 //检查是否到位和位置一致
                 float targetPos = 0;
                 switch (axis.Name)
@@ -854,13 +856,13 @@ 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)
-                    {
-                        isAnyError = true;
-                        break;
-                    }
+                    //if (isError)
+                    //{
+                    //    isAnyError = true;
+                    //    break;
+                    //}
                     allOk = false;
                     break;
                 }
@@ -898,11 +900,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);
             }

+ 224 - 44
TeamAAS-VM/Services/CameraCalibrationService.cs

@@ -62,7 +62,11 @@ namespace TeamAAS_VP.Services
             Matrix<double> RobotCameraRotationMatrix = null;
 
             //移动机器人至待机位置
-            await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+            bool isSuccess = await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+            if (!isSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
             if (cancellationToken.IsCancellationRequested)
             {
                 return (false, null, 0, 0, 0, 0);
@@ -109,7 +113,11 @@ namespace TeamAAS_VP.Services
             RPoint RobotU = calibrationInfo.CenterPoint.Clone();
             RobotU.U += (float)calibrationInfo.Angle;
             //移动机器人中心点
-            await robot.CalibMotionAsync(calibrationInfo.CenterPoint, 0);
+            isSuccess = await robot.CalibMotionAsync(calibrationInfo.CenterPoint, 0);
+            if (!isSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
             if (cancellationToken.IsCancellationRequested)
             {
                 return (false, null, 0, 0, 0, 0);
@@ -118,7 +126,11 @@ namespace TeamAAS_VP.Services
             await robot.CalibOutIOAsync(true);
 
             //机器人U轴旋转
-            await robot.CalibMotionAsync(RobotU, 0);
+            isSuccess = await robot.CalibMotionAsync(RobotU, 0);
+            if (!isSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
             if (cancellationToken.IsCancellationRequested)
             {
                 return (false, null, 0, 0, 0, 0);
@@ -127,7 +139,11 @@ namespace TeamAAS_VP.Services
             //关闭吸气
             await robot.CalibOutIOAsync(false);
             //移动机器人至待机位置
-            await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+            isSuccess = await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+            if (!isSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
             if (cancellationToken.IsCancellationRequested)
             {
                 return (false, null, 0, 0, 0, 0);
@@ -149,7 +165,11 @@ namespace TeamAAS_VP.Services
                 double offsety = (P0.Y - curPixel.Y) * pixelScaleY;
                 var pos = RobotCameraRotationMatrix.Inverse() * Vector<double>.Build.Dense(new double[] { offsetx, offsety });
                 //移动机器人取标定块
-                await robot.CalibMotionAsync(RobotU, 0);
+                isSuccess = await robot.CalibMotionAsync(RobotU, 0);
+                if (!isSuccess)
+                {
+                    return (false, null, 0, 0, 0, 0);
+                }
                 if (cancellationToken.IsCancellationRequested)
                 {
                     return (false, null, 0, 0, 0, 0);
@@ -160,7 +180,11 @@ namespace TeamAAS_VP.Services
                 RobotU.X += (float)pos[0];
                 RobotU.Y += (float)pos[1];
                 //机器人移动
-                await robot.CalibMotionAsync(RobotU, 0);
+                isSuccess = await robot.CalibMotionAsync(RobotU, 0);
+                if (!isSuccess)
+                {
+                    return (false, null, 0, 0, 0, 0);
+                }
                 if (cancellationToken.IsCancellationRequested)
                 {
                     return (false, null, 0, 0, 0, 0);
@@ -169,7 +193,11 @@ namespace TeamAAS_VP.Services
                 //关闭吸气
                 await robot.CalibOutIOAsync(false);
                 //移动机器人至待机位置
-                await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                isSuccess = await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                if (!isSuccess)
+                {
+                    return (false, null, 0, 0, 0, 0);
+                }
                 if (cancellationToken.IsCancellationRequested)
                 {
                     return (false, null, 0, 0, 0, 0);
@@ -187,7 +215,11 @@ namespace TeamAAS_VP.Services
                 if (Math.Abs(offsetx) < 1 && Math.Abs(offsetx) < 1)
                 {
                     //移动机器人取标定块
-                    await robot.CalibMotionAsync(RobotU, 0);
+                    isSuccess = await robot.CalibMotionAsync(RobotU, 0);
+                    if (!isSuccess)
+                    {
+                        return (false, null, 0, 0, 0, 0);
+                    }
                     if (cancellationToken.IsCancellationRequested)
                     {
                         return (false, null, 0, 0, 0, 0);
@@ -195,7 +227,11 @@ namespace TeamAAS_VP.Services
                     //打开吸气
                     await robot.CalibOutIOAsync(true);
                     //移动机器人至待机位置
-                    await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                    isSuccess = await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                    if (!isSuccess)
+                    {
+                        return (false, null, 0, 0, 0, 0);
+                    }
                     IsFinish = true;
                     break;
                 }
@@ -247,7 +283,11 @@ namespace TeamAAS_VP.Services
             Matrix<double> RobotCameraRotationMatrix = null;
 
             //移动机器人至中心位置
-            await robot.CalibMotionAsync(calibrationInfo.CenterPoint, 0);
+            bool isSuccess = await robot.CalibMotionAsync(calibrationInfo.CenterPoint, 0);
+            if (!isSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
 
             //计算相机与机器人坐标系的旋转矩阵
             var robotCameraRotationMatrix = await AutoIdentifyRobotCameraRotationMatrix(calibrationInfo, robot, cancellationToken);
@@ -272,7 +312,11 @@ namespace TeamAAS_VP.Services
             RobotU.U += (float)calibrationInfo.Angle;
 
             //机器人U轴旋转
-            await robot.CalibMotionAsync(RobotU, RobotU.Z);
+            isSuccess = await robot.CalibMotionAsync(RobotU, RobotU.Z);
+            if (!isSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
             if (cancellationToken.IsCancellationRequested)
             {
                 return (false, null, 0, 0, 0, 0);
@@ -314,7 +358,11 @@ namespace TeamAAS_VP.Services
             calibrationInfo.Tool.Y = toolCoord.Y;
 
             //移动机器人至中心位置
-            await robot.CalibMotionAsync(calibrationInfo.CenterPoint, calibrationInfo.CenterPoint.Z);
+            isSuccess = await robot.CalibMotionAsync(calibrationInfo.CenterPoint, calibrationInfo.CenterPoint.Z);
+            if (!isSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
 
             return (true, RobotCameraRotationMatrix, calibrationInfo.Tool.X, calibrationInfo.Tool.Y, pixelScaleX, pixelScaleY);
         }
@@ -334,7 +382,11 @@ namespace TeamAAS_VP.Services
             Matrix<double> RobotCameraRotationMatrix = null;
 
             //移动机器人至中心位置
-            await robot.CalibMotionAsync(calibrationInfo.CenterPoint, 0);
+            bool isSuccess = await robot.CalibMotionAsync(calibrationInfo.CenterPoint, 0);
+            if (!isSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
 
             if (calibrationInfo.Pick.PickPlaceModel == Enums.PickPlaceModel.Inhal)
             {
@@ -380,7 +432,11 @@ namespace TeamAAS_VP.Services
             RobotU.U += (float)calibrationInfo.Angle;
 
             //机器人U轴旋转
-            await robot.CalibMotionAsync(RobotU, RobotU.Z);
+            isSuccess = await robot.CalibMotionAsync(RobotU, RobotU.Z);
+            if (!isSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
             if (cancellationToken.IsCancellationRequested)
             {
                 return (false, null, 0, 0, 0, 0);
@@ -422,7 +478,11 @@ namespace TeamAAS_VP.Services
             calibrationInfo.Tool.Y = toolCoord.Y;
 
             //移动机器人至中心位置
-            await robot.CalibMotionAsync(calibrationInfo.CenterPoint, calibrationInfo.CenterPoint.Z);
+            isSuccess = await robot.CalibMotionAsync(calibrationInfo.CenterPoint, calibrationInfo.CenterPoint.Z);
+            if (!isSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
 
             return (true, RobotCameraRotationMatrix, calibrationInfo.Tool.X, calibrationInfo.Tool.Y, pixelScaleX, pixelScaleY);
         }
@@ -493,18 +553,27 @@ namespace TeamAAS_VP.Services
         {
             //移动距离,单位mm
             float distance = ((float)calibrationInfo.Height) / 3;
+            bool isSuccess = false;
 
             //-------------------------------------------P0-----------------------------------
             //移动机器人至中心点
             if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown && !calibrationInfo.FixedDownCameraNoReturnToHome)
             {
-                await robot.CalibMotionAsync(calibrationInfo.CenterPoint, 0);
+                isSuccess = await robot.CalibMotionAsync(calibrationInfo.CenterPoint, 0);
+                if (!isSuccess)
+                {
+                    return (false, null, 0, 0);
+                }
                 //关闭吸气
                 await robot.CalibOutIOAsync(false);
             }
             else
             {
-                await robot.CalibMotionAsync(calibrationInfo.CenterPoint, calibrationInfo.CenterPoint.Z);
+                isSuccess = await robot.CalibMotionAsync(calibrationInfo.CenterPoint, calibrationInfo.CenterPoint.Z);
+                if (!isSuccess)
+                {
+                    return (false, null, 0, 0);
+                }
             }
 
 
@@ -517,7 +586,11 @@ namespace TeamAAS_VP.Services
             if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown && !calibrationInfo.FixedDownCameraNoReturnToHome)
             {
                 //移动机器人至待机位置
-                await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                isSuccess = await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                if (!isSuccess)
+                {
+                    return (false, null, 0, 0);
+                }
             }
 
             //相机拍照并处理图像
@@ -532,7 +605,11 @@ namespace TeamAAS_VP.Services
             if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown && !calibrationInfo.FixedDownCameraNoReturnToHome)
             {
                 //移动机器人至P0
-                await robot.CalibMotionAsync(RobotP0, 0);
+                isSuccess = await robot.CalibMotionAsync(RobotP0, 0);
+                if (!isSuccess)
+                {
+                    return (false, null, 0, 0);
+                }
                 if (cancellationToken.IsCancellationRequested)
                 {
                     return (false, null, 0, 0);
@@ -540,7 +617,11 @@ namespace TeamAAS_VP.Services
                 //打开吸气
                 await robot.CalibOutIOAsync(true);
                 //移动机器人至P1
-                await robot.CalibMotionAsync(RobotP1, 0);
+                isSuccess = await robot.CalibMotionAsync(RobotP1, 0);
+                if (!isSuccess)
+                {
+                    return (false, null, 0, 0);
+                }
                 if (cancellationToken.IsCancellationRequested)
                 {
                     return (false, null, 0, 0);
@@ -548,12 +629,20 @@ namespace TeamAAS_VP.Services
                 //关闭吸气
                 await robot.CalibOutIOAsync(false);
                 //移动机器人至待机位置
-                await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                isSuccess = await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                if (!isSuccess)
+                {
+                    return (false, null, 0, 0);
+                }
             }
             else
             {
                 //移动机器人至P1
-                await robot.CalibMotionAsync(RobotP1, RobotP1.Z);
+                isSuccess = await robot.CalibMotionAsync(RobotP1, RobotP1.Z);
+                if (!isSuccess)
+                {
+                    return (false, null, 0, 0);
+                }
             }
 
             if (cancellationToken.IsCancellationRequested)
@@ -573,7 +662,11 @@ namespace TeamAAS_VP.Services
             if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown && !calibrationInfo.FixedDownCameraNoReturnToHome)
             {
                 //移动机器人至P1
-                await robot.CalibMotionAsync(RobotP1, 0);
+                isSuccess = await robot.CalibMotionAsync(RobotP1, 0);
+                if (!isSuccess)
+                {
+                    return (false, null, 0, 0);
+                }
                 if (cancellationToken.IsCancellationRequested)
                 {
                     return (false, null, 0, 0);
@@ -581,7 +674,11 @@ namespace TeamAAS_VP.Services
                 //打开吸气
                 await robot.CalibOutIOAsync(true);
                 //移动机器人至P2
-                await robot.CalibMotionAsync(RobotP2, 0);
+                isSuccess = await robot.CalibMotionAsync(RobotP2, 0);
+                if (!isSuccess)
+                {
+                    return (false, null, 0, 0);
+                }
                 if (cancellationToken.IsCancellationRequested)
                 {
                     return (false, null, 0, 0);
@@ -589,12 +686,20 @@ namespace TeamAAS_VP.Services
                 //关闭吸气
                 await robot.CalibOutIOAsync(false);
                 //移动机器人至待机位置
-                await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                isSuccess = await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                if (!isSuccess)
+                {
+                    return (false, null, 0, 0);
+                }
             }
             else
             {
                 //移动机器人至P2
-                await robot.CalibMotionAsync(RobotP2, RobotP2.Z);
+                isSuccess = await robot.CalibMotionAsync(RobotP2, RobotP2.Z);
+                if (!isSuccess)
+                {
+                    return (false, null, 0, 0);
+                }
             }
             if (cancellationToken.IsCancellationRequested)
             {
@@ -614,7 +719,11 @@ namespace TeamAAS_VP.Services
             if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown && !calibrationInfo.FixedDownCameraNoReturnToHome)
             {
                 //移动机器人至P2
-                await robot.CalibMotionAsync(RobotP2, 0);
+                isSuccess = await robot.CalibMotionAsync(RobotP2, 0);
+                if (!isSuccess)
+                {
+                    return (false, null, 0, 0);
+                }
                 if (cancellationToken.IsCancellationRequested)
                 {
                     return (false, null, 0, 0);
@@ -622,7 +731,11 @@ namespace TeamAAS_VP.Services
                 //打开吸气
                 await robot.CalibOutIOAsync(true);
                 //移动机器人至P0
-                await robot.CalibMotionAsync(RobotP0, 0);
+                isSuccess = await robot.CalibMotionAsync(RobotP0, 0);
+                if (!isSuccess)
+                {
+                    return (false, null, 0, 0);
+                }
                 if (cancellationToken.IsCancellationRequested)
                 {
                     return (false, null, 0, 0);
@@ -630,12 +743,20 @@ namespace TeamAAS_VP.Services
                 //关闭吸气
                 await robot.CalibOutIOAsync(false);
                 //移动机器人至待机位置
-                await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                isSuccess = await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                if (!isSuccess)
+                {
+                    return (false, null, 0, 0);
+                }
             }
             else
             {
                 //移动机器人至P0
-                await robot.CalibMotionAsync(RobotP0, RobotP0.Z);
+                isSuccess = await robot.CalibMotionAsync(RobotP0, RobotP0.Z);
+                if (!isSuccess)
+                {
+                    return (false, null, 0, 0);
+                }
             }
             if (cancellationToken.IsCancellationRequested)
             {
@@ -709,6 +830,7 @@ namespace TeamAAS_VP.Services
             //中心点像素坐标
             PointF P0 = new PointF((float)(result.ImageWidth / 2), (float)(result.ImageHeight / 2));
 
+            bool isSuccess = false;
             var curpos = robot.GetRobotPos();
             for (int i = 0; i < 10; i++)
             {
@@ -719,7 +841,11 @@ namespace TeamAAS_VP.Services
                 curpos.X += (float)pos[0];
                 curpos.Y += (float)pos[1];
                 //机器人移动
-                await robot.CalibMotionAsync(curpos, curpos.Z);
+                isSuccess = await robot.CalibMotionAsync(curpos, curpos.Z);
+                if (!isSuccess)
+                {
+                    return (false, 0, 0, 0);
+                }
                 await Task.Delay(200);
 
                 result = await CaptureAndProcessCallback();
@@ -777,12 +903,17 @@ namespace TeamAAS_VP.Services
             //发送校准的参数
             await robot.CalibParameAsync(calibrationInfo.Pick, calibrationInfo.Speed, calibrationInfo.Accel, calibrationInfo.Power, calibrationInfo.WaitSuction, calibrationInfo.WaitBlow);
 
+            bool isSuccess = false;
             var P0 = Vector<double>.Build.Dense(new double[] { calibrationInfo.CenterPoint.X, calibrationInfo.CenterPoint.Y });
             if (robot.Brand == Enums.RobotBrand.XYZ_Platform)
             {
 
                 //移动机器人至中心位置
-                await robot.CalibMotionAsync(calibrationInfo.CenterPoint, 0);
+                isSuccess = await robot.CalibMotionAsync(calibrationInfo.CenterPoint, 0);
+                if (!isSuccess)
+                {
+                    return (false, null, null, null);
+                }
                 if (cancellationToken.IsCancellationRequested)
                 {
                     return (false, null, null, null);
@@ -811,7 +942,11 @@ namespace TeamAAS_VP.Services
             else if (calibrationInfo.CameraMount== Enums.CameraMount.MobileDown_XYPlatform)
             {
                 //移动机器人至中心位置
-                await robot.CalibMotionAsync(calibrationInfo.CenterPoint, 0);
+                isSuccess = await robot.CalibMotionAsync(calibrationInfo.CenterPoint, 0);
+                if (!isSuccess)
+                {
+                    return (false, null, null, null);
+                }
                 if (cancellationToken.IsCancellationRequested)
                 {
                     return (false, null, null, null);
@@ -1002,7 +1137,11 @@ namespace TeamAAS_VP.Services
             if (calibrationInfo.CameraMount == Enums.CameraMount.MobileJ4)
             {
                 //移动机器人至中心位置
-                await robot.CalibMotionAsync(calibrationInfo.CenterPoint, 0);
+                isSuccess = await robot.CalibMotionAsync(calibrationInfo.CenterPoint, 0);
+                if (!isSuccess)
+                {
+                    return (false, null, null, null);
+                }
                 if (cancellationToken.IsCancellationRequested)
                 {
                     return (false, null, null, null);
@@ -1028,7 +1167,11 @@ namespace TeamAAS_VP.Services
                 //移动机器人至i
                 if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown)
                 {
-                    await robot.CalibMotionAsync(rPoints[i], 0);
+                    isSuccess = await robot.CalibMotionAsync(rPoints[i], 0);
+                    if (!isSuccess)
+                    {
+                        return (false, null, null, null);
+                    }
                     if (cancellationToken.IsCancellationRequested)
                     {
                         return (false, null, null, null);
@@ -1036,11 +1179,19 @@ namespace TeamAAS_VP.Services
                     //关闭吸气
                     await robot.CalibOutIOAsync(false);
                     //移动机器人至待机位置
-                    await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                    isSuccess = await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                    if (!isSuccess)
+                    {
+                        return (false, null, null, null);
+                    }
                 }
                 else
                 {
-                    await robot.CalibMotionAsync(rPoints[i], rPoints[i].Z);
+                    isSuccess = await robot.CalibMotionAsync(rPoints[i], rPoints[i].Z);
+                    if (!isSuccess)
+                    {
+                        return (false, null, null, null);
+                    }
                 }
                 if (cancellationToken.IsCancellationRequested)
                 {
@@ -1059,7 +1210,11 @@ namespace TeamAAS_VP.Services
                 if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown)
                 {
                     //移动机器人至i
-                    await robot.CalibMotionAsync(rPoints[i], 0);
+                    isSuccess = await robot.CalibMotionAsync(rPoints[i], 0);
+                    if (!isSuccess)
+                    {
+                        return (false, null, null, null);
+                    }
                     if (cancellationToken.IsCancellationRequested)
                     {
                         return (false, null, null, null);
@@ -1082,7 +1237,11 @@ namespace TeamAAS_VP.Services
             if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown)
             {
                 //移动机器人至待机位置
-                await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                isSuccess = await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                if (!isSuccess)
+                {
+                    return (false, null, null, null);
+                }
             }
 
             if (cancellationToken.IsCancellationRequested)
@@ -1321,13 +1480,18 @@ namespace TeamAAS_VP.Services
                 Tool = calibrationInfo.CenterPoint.Tool
             });
 
+            bool isSuccess = false;
             List<Vector<double>> TestPos = new List<Vector<double>>();
             for (int i = 0; i < rPoints.Count; i++)
             {
                 if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown)
                 {
                     //移动机器人至i
-                    await robot.CalibMotionAsync(rPoints[i], 0);
+                    isSuccess = await robot.CalibMotionAsync(rPoints[i], 0);
+                    if (!isSuccess)
+                    {
+                        return (false, null);
+                    }
                     if (cancellationToken.IsCancellationRequested)
                     {
                         return (false, null);
@@ -1335,12 +1499,20 @@ namespace TeamAAS_VP.Services
                     //关闭吸气
                     await robot.CalibOutIOAsync(false);
                     //移动机器人至待机位置
-                    await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                    isSuccess = await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                    if (!isSuccess)
+                    {
+                        return (false, null);
+                    }
                 }
                 else
                 {
                     //移动机器人至i
-                    await robot.CalibMotionAsync(rPoints[i], rPoints[i].Z);
+                    isSuccess = await robot.CalibMotionAsync(rPoints[i], rPoints[i].Z);
+                    if (!isSuccess)
+                    {
+                        return (false, null);
+                    }
                 }
                 if (cancellationToken.IsCancellationRequested)
                 {
@@ -1361,7 +1533,11 @@ namespace TeamAAS_VP.Services
                 if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown)
                 {
                     //移动机器人至i
-                    await robot.CalibMotionAsync(rPoints[i], 0);
+                    isSuccess = await robot.CalibMotionAsync(rPoints[i], 0);
+                    if (!isSuccess)
+                    {
+                        return (false, null);
+                    }
                     //打开吸气
                     await robot.CalibOutIOAsync(true);
                 }
@@ -1375,7 +1551,11 @@ namespace TeamAAS_VP.Services
             if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown)
             {
                 //移动机器人至待机位置
-                await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                isSuccess = await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                if (!isSuccess)
+                {
+                    return (false, null);
+                }
             }
 
             //RMS(均方根值) 标定偏差