Pārlūkot izejas kodu

修复相机拍照死锁及移动相机校准过程中的错误

徐孝锋 8 mēneši atpakaļ
vecāks
revīzija
602a2b687f

+ 17 - 17
TeamAAS-VM/Core/Cameras/OptCamera.cs

@@ -25,7 +25,7 @@ namespace TeamAAS_VP.Core.Cameras
         #region 字段
         private Thread m_hReceiveThread;
         // 用于序列化对同一相机实例的操作,防止同一实例被并发操作
-        private readonly SemaphoreSlim _operationSemaphore = new SemaphoreSlim(1, 1);
+        //private readonly SemaphoreSlim _operationSemaphore = new SemaphoreSlim(1, 1);
         // 用于保护状态变量(例如 IsGrabbing)的并发访问
         private readonly object _stateLock = new object();
         #endregion
@@ -275,7 +275,7 @@ namespace TeamAAS_VP.Core.Cameras
         /// <exception cref="Exception"></exception>
         public bool OpenDevice()
         {
-            _operationSemaphore.Wait();
+            //_operationSemaphore.Wait();
             uint nReVal = SciCam.SCI_CAMERA_OK;
             try
             {
@@ -357,7 +357,7 @@ namespace TeamAAS_VP.Core.Cameras
             }
             finally
             {
-                _operationSemaphore.Release();
+                //_operationSemaphore.Release();
             }
         }
 
@@ -379,14 +379,14 @@ namespace TeamAAS_VP.Core.Cameras
         public void CloseDevice()
         {
             // ch:关闭设备 | en:Close Device
-            _operationSemaphore.Wait();
+            //_operationSemaphore.Wait();
             try
             {
                 mvCameraAcq.CloseDevice();
             }
             finally
             {
-                _operationSemaphore.Release();
+                //_operationSemaphore.Release();
             }
         }
 
@@ -396,7 +396,7 @@ namespace TeamAAS_VP.Core.Cameras
         /// <returns></returns>
         public ICogImage Grab()
         {
-            _operationSemaphore.Wait();
+            //_operationSemaphore.Wait();
             uint nReVal = SciCam.SCI_CAMERA_OK;
             IntPtr payload = IntPtr.Zero;
             try
@@ -424,7 +424,7 @@ namespace TeamAAS_VP.Core.Cameras
                         {
                             nReVal = mvCameraAcq.FreePayload(payload);
                             nReVal = mvCameraAcq.StopGrabbing();
-                            _operationSemaphore.Release();
+                            //_operationSemaphore.Release();
                             CloseDevice();
                             OpenDevice();
                             ErrorMessage = "图像采集失败!";
@@ -432,7 +432,7 @@ namespace TeamAAS_VP.Core.Cameras
                     }
                     catch (Exception ex)
                     {
-                        _operationSemaphore.Release();
+                        //_operationSemaphore.Release();
                         CloseDevice();
                         OpenDevice();
                         ErrorMessage = ex.Message;
@@ -447,7 +447,7 @@ namespace TeamAAS_VP.Core.Cameras
             }
             finally
             {
-                _operationSemaphore.Release();
+                //_operationSemaphore.Release();
             }
         }
 
@@ -497,7 +497,7 @@ namespace TeamAAS_VP.Core.Cameras
         /// <returns></returns>
         public bool SetExposureTime(float ExposureTime)
         {
-            _operationSemaphore.Wait();
+            //_operationSemaphore.Wait();
             try
             {
                 if (!mvCameraAcq.IsDeviceOpen())
@@ -512,7 +512,7 @@ namespace TeamAAS_VP.Core.Cameras
             }
             finally
             {
-                _operationSemaphore.Release();
+                //_operationSemaphore.Release();
             }
         }
 
@@ -522,7 +522,7 @@ namespace TeamAAS_VP.Core.Cameras
         /// <returns></returns>
         public float GetExposureTime()
         {
-            _operationSemaphore.Wait();
+            //_operationSemaphore.Wait();
             try
             {
                 if (!mvCameraAcq.IsDeviceOpen())
@@ -551,7 +551,7 @@ namespace TeamAAS_VP.Core.Cameras
             }
             finally
             {
-                _operationSemaphore.Release();
+                //_operationSemaphore.Release();
             }
         }
 
@@ -562,7 +562,7 @@ namespace TeamAAS_VP.Core.Cameras
         /// <returns></returns>
         public bool SetGain(float Gain)
         {
-            _operationSemaphore.Wait();
+            //_operationSemaphore.Wait();
             try
             {
                 if (!mvCameraAcq.IsDeviceOpen())
@@ -577,7 +577,7 @@ namespace TeamAAS_VP.Core.Cameras
             }
             finally
             {
-                _operationSemaphore.Release();
+                //_operationSemaphore.Release();
             }
         }
 
@@ -587,7 +587,7 @@ namespace TeamAAS_VP.Core.Cameras
         /// <returns></returns>
         public float GetGain()
         {
-            _operationSemaphore.Wait();
+            //_operationSemaphore.Wait();
             try
             {
                 if (!mvCameraAcq.IsDeviceOpen())
@@ -615,7 +615,7 @@ namespace TeamAAS_VP.Core.Cameras
             }
             finally
             {
-                _operationSemaphore.Release();
+                //_operationSemaphore.Release();
             }
         }
 

+ 35 - 1
TeamAAS-VM/Services/CameraCalibrationService.cs

@@ -804,7 +804,11 @@ namespace TeamAAS_VP.Services
                 }
                 calibrationInfo.CenterPoint.X = (float)autoMoveResult.X;
                 calibrationInfo.CenterPoint.Y = (float)autoMoveResult.Y;
-                calibrationInfo.MarkPoint = calibrationInfo.CenterPoint.Clone();
+                if (calibrationInfo.CameraMount != Enums.CameraMount.MobileDown_XYPlatform)
+                {
+                    calibrationInfo.MarkPoint = calibrationInfo.CenterPoint.Clone();
+                }
+                
                 calibrationInfo.RobotCameraRotationMatrix = robotCameraRotationMatrix.RotationMatrix.ToArray();
             }
 
@@ -1375,6 +1379,36 @@ namespace TeamAAS_VP.Services
                     differenceX.Add(cc[0] - calibrationInfo.MarkPoint.X);
                     differenceY.Add(cc[1] - calibrationInfo.MarkPoint.Y);
                 }
+                else if (calibrationInfo.CameraMount == Enums.CameraMount.MobileDown_XYPlatform)
+                {
+                    //像素直接转换成mm时的点位
+                    double Robot_X, Robot_Y;
+                    Robot_X = TestPos[i][0];
+                    Robot_Y = TestPos[i][1];
+
+                    //机器人当前TOOL 0下的坐标
+                    double curpos_x = 0, curpos_y = 0, curpos_u = 0;
+                    curpos_x = rPoints[i].X;
+                    curpos_y = rPoints[i].Y;
+                    curpos_u = rPoints[i].U;
+
+                    //得到旋转矩阵
+                    double angle = Math.PI * (curpos_u - calibrationInfo.MarkPoint.U) / 180;
+                    // 创建T矩阵
+                    Matrix<double> rotationMatrix = Matrix<double>.Build.DenseOfArray(new double[,]
+                    {
+                                { Math.Cos(angle), -Math.Sin(angle) },
+                                { Math.Sin(angle), Math.Cos(angle) }
+                    });
+
+                    Vector<double> p3 = Vector<double>.Build.Dense(new double[] { Robot_X - calibrationInfo.CalibPoints[0].Robot.X, Robot_Y - calibrationInfo.CalibPoints[0].Robot.Y });
+                    Vector<double> phere = Vector<double>.Build.Dense(new double[] { curpos_x, curpos_y });
+
+                    var cc = rotationMatrix * p3 + phere;
+
+                    differenceX.Add(cc[0] - calibrationInfo.MarkPoint.X);
+                    differenceY.Add(cc[1] - calibrationInfo.MarkPoint.Y);
+                }
                 else
                 {
                     //将tool 0下的坐标转换成Tool n下的坐标

+ 1 - 1
TeamAAS-VM/Services/RemoteCommandService.cs

@@ -1594,7 +1594,7 @@ namespace TeamAAS_VP.Services
                 LogHelper.WriteLogInfo("开始获取视觉输出结果");
                 //获取相机校准
                 var calib = _calibrationService.GetCalibration(procedure.CalibrationId);
-                string points = (string)(outputCollection["Points"].Value);
+                string points = (string)(outputCollection["Point"].Value);
                 string[] strpoints = points.Split(';');
                 //先将pos按照逗号进行分隔,拿到数组
                 var posParts = strpoints[0].Split(',');

+ 1 - 1
TeamAAS-VM/ViewModels/Calibration/CalibrationCameraParamsViewModel.cs

@@ -360,7 +360,7 @@ namespace TeamAAS_VP.ViewModels.Calibration
         /// <param name="navigationContext"></param>
         public void OnNavigatedFrom(NavigationContext navigationContext)
         {
-            
+            ExecuteStopGrabbingCommand();
         }
         #endregion
 

+ 1 - 0
TeamAAS-VM/ViewModels/Product/CameraParamsViewModel.cs

@@ -594,6 +594,7 @@ namespace TeamAAS_VP.ViewModels.Product
             {
                 Robot.EnterDebugMode = false;
             }
+            ExecuteStopGrabbingCommand();
         }
         #endregion
 

+ 12 - 1
TeamAAS-VM/ViewModels/Product/PlcPointParamsViewModel.cs

@@ -370,8 +370,19 @@ namespace TeamAAS_VP.ViewModels.Product
             {
                 return;
             }
+            if (SelectedPoint==null)
+            {
+                return;
+            }
             var values = (object[])parameter;
-            var point = values[0] as RPoint;
+            var point = new RPoint()
+            {
+                X= SelectedPoint.X_Position,
+                Y= SelectedPoint.Y_Position,
+                Z= SelectedPoint.Z_Position_Start,
+                U=SelectedPoint.U_Position,
+                V= SelectedPoint.R_Position,
+            };
             MotionCommand motionCmd = (MotionCommand)values[1];
             if (Robot == null || !Robot.IsConnected) return;
             try

+ 22 - 3
TeamAAS-VM/Views/Product/PlcPointParams.xaml

@@ -251,7 +251,6 @@
                                 <!--取料拍照点位面板-->
                                 <StackPanel x:Name="AutoCorrectPickPointPanel"
                                             Orientation="Vertical"
-                                            Visibility="Collapsed"
                                             d:Visibility="Visible">
                                     <StackPanel.Style>
                                         <Style TargetType="StackPanel">
@@ -295,7 +294,17 @@
                                             <ComboBox MinWidth="50"
                                                       Margin="5,0,0,0"
                                                       ItemsSource="{Binding Points}"
-                                                      SelectedItem="{Binding SelectedCameraForPickPoint}" />
+                                                      SelectedItem="{Binding SelectedCameraForPickPoint}">
+                                                <ComboBox.ItemTemplate>
+                                                    <DataTemplate>
+                                                        <StackPanel HorizontalAlignment="Left"
+                                                                    Orientation="Horizontal">
+                                                            <TextBlock Text="{Binding Number,StringFormat={}{0}:}" />
+                                                            <TextBlock Text="{Binding Label}" />
+                                                        </StackPanel>
+                                                    </DataTemplate>
+                                                </ComboBox.ItemTemplate>
+                                            </ComboBox>
                                             <TextBlock Margin="5,0,0,0"
                                                        VerticalAlignment="Center"
                                                        Text="选择移动视觉流程:" />
@@ -322,7 +331,17 @@
                                             <ComboBox MinWidth="50"
                                                       Margin="5,0,0,0"
                                                       ItemsSource="{Binding PickPoints}"
-                                                      SelectedItem="{Binding SelectedPickPoint}" />
+                                                      SelectedItem="{Binding SelectedPickPoint}">
+                                                <ComboBox.ItemTemplate>
+                                                    <DataTemplate>
+                                                        <StackPanel HorizontalAlignment="Left"
+                                                                    Orientation="Horizontal">
+                                                            <TextBlock Text="{Binding Number,StringFormat={}{0}:}" />
+                                                            <TextBlock Text="{Binding Label}" />
+                                                        </StackPanel>
+                                                    </DataTemplate>
+                                                </ComboBox.ItemTemplate>
+                                            </ComboBox>
                                             <Button Content="执行校准"
                                                     Margin="10,0,0,0"
                                                     Command="{Binding AutoCorrectPickPointCommand}" />