|
|
@@ -1,5 +1,6 @@
|
|
|
using Cognex.VisionPro;
|
|
|
using Cognex.VisionPro.ToolBlock;
|
|
|
+using MathNet.Numerics.LinearAlgebra;
|
|
|
using Prism.Commands;
|
|
|
using Prism.Events;
|
|
|
using Prism.Ioc;
|
|
|
@@ -164,7 +165,7 @@ namespace TeamAAS_VP.ViewModels.Calibration
|
|
|
set
|
|
|
{
|
|
|
SetProperty(ref _SelectedCalibration, value);
|
|
|
- if (value!=null)
|
|
|
+ if (value != null)
|
|
|
{
|
|
|
SelectCalibration.FixedUpCameraFindP0Info.CalibrationId = value.Id;
|
|
|
SelectCalibration.FixedUpCameraFindP0Info.CalibrationName = value.Name;
|
|
|
@@ -194,6 +195,25 @@ namespace TeamAAS_VP.ViewModels.Calibration
|
|
|
public DelegateCommand FindP0Command =>
|
|
|
_FindP0Command ?? (_FindP0Command = new DelegateCommand(ExecuteFindP0Command));
|
|
|
|
|
|
+ private DelegateCommand _TeachPutPosCommand;
|
|
|
+ public DelegateCommand TeachPutPosCommand =>
|
|
|
+ _TeachPutPosCommand ?? (_TeachPutPosCommand = new DelegateCommand(ExecuteTeachPutPosCommand));
|
|
|
+
|
|
|
+ private DelegateCommand _MovePutPosCommand;
|
|
|
+ public DelegateCommand MovePutPosCommand =>
|
|
|
+ _MovePutPosCommand ?? (_MovePutPosCommand = new DelegateCommand(ExecuteMovePutPosCommand));
|
|
|
+
|
|
|
+ private DelegateCommand _TeachDownCameraPosCommand;
|
|
|
+ public DelegateCommand TeachDownCameraPosCommand =>
|
|
|
+ _TeachDownCameraPosCommand ?? (_TeachDownCameraPosCommand = new DelegateCommand(ExecuteTeachDownCameraPosCommand));
|
|
|
+
|
|
|
+ private DelegateCommand _MoveDownCameraPosCommand;
|
|
|
+ public DelegateCommand MoveDownCameraPosCommand =>
|
|
|
+ _MoveDownCameraPosCommand ?? (_MoveDownCameraPosCommand = new DelegateCommand(ExecuteMoveDownCameraPosCommand));
|
|
|
+
|
|
|
+ private DelegateCommand _StartCalibP0Command;
|
|
|
+ public DelegateCommand StartCalibP0Command =>
|
|
|
+ _StartCalibP0Command ?? (_StartCalibP0Command = new DelegateCommand(ExecuteStartCalibP0Command));
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
@@ -317,14 +337,14 @@ namespace TeamAAS_VP.ViewModels.Calibration
|
|
|
MessageBox.Show("请先选择标定!");
|
|
|
return;
|
|
|
}
|
|
|
- var result = await CaptureAndProcess();
|
|
|
+ var result = await CaptureAndProcess(null);
|
|
|
if (result.IsSuccess)
|
|
|
{
|
|
|
if (SelectCalibration.MarkPoint == null)
|
|
|
{
|
|
|
SelectCalibration.MarkPoint = new RPoint();
|
|
|
}
|
|
|
- SelectCalibration.MarkPoint.X = (float) result.X;
|
|
|
+ SelectCalibration.MarkPoint.X = (float)result.X;
|
|
|
SelectCalibration.MarkPoint.Y = (float)result.Y;
|
|
|
MessageBox.Show($"P0点计算成功!X:{result.X},Y:{result.Y}");
|
|
|
}
|
|
|
@@ -334,11 +354,215 @@ namespace TeamAAS_VP.ViewModels.Calibration
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 通过下相机开始标定P0点
|
|
|
+ /// </summary>
|
|
|
+ async void ExecuteStartCalibP0Command()
|
|
|
+ {
|
|
|
+ //弹窗确认是否开始标定
|
|
|
+ var result = MessageBox.Show("确认通过下相机开始标定P0点?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
+ if (result != MessageBoxResult.Yes)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // 1.移动至标定块放置位置,取标定块
|
|
|
+
|
|
|
+ //移动机器人至下相机位置
|
|
|
+ bool isSuccess = await Robot.CalibMotionAsync(SelectCalibration.PutPoint, 0);
|
|
|
+ if (!isSuccess)
|
|
|
+ {
|
|
|
+ MessageBox.Show("移动至移动至标定块放置位置,取标定块失败!");
|
|
|
+ }
|
|
|
+ //打开吸气
|
|
|
+ Robot.CalibOutIO(true);
|
|
|
+ await Task.Delay(300);
|
|
|
+
|
|
|
+ // 2.移动至下相机位置,拍照,计算P0点
|
|
|
+ isSuccess = await Robot.CalibMotionAsync(SelectCalibration.DownCameraPoint, 0);
|
|
|
+ if (!isSuccess)
|
|
|
+ {
|
|
|
+ MessageBox.Show("移动至下相机位置失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ var calibResult = await CaptureAndProcess(new double[] { SelectCalibration.DownCameraPoint.X, SelectCalibration.DownCameraPoint.Y, SelectCalibration.DownCameraPoint.U });
|
|
|
+ if (calibResult.IsSuccess)
|
|
|
+ {
|
|
|
+ //工具坐标
|
|
|
+ double toolX = calibResult.X;
|
|
|
+ double toolY = calibResult.Y;
|
|
|
+
|
|
|
+ //创建工具坐标
|
|
|
+ ToolCoord toolCoord = new ToolCoord();
|
|
|
+ toolCoord.SetTool(toolX, toolY);
|
|
|
+
|
|
|
+ Vector<double> P10 = Vector<double>.Build.Dense(new double[] { SelectCalibration.PutPoint.X, SelectCalibration.PutPoint.Y });
|
|
|
+ var p0 = toolCoord.GetToolnCoord(P10, SelectCalibration.PutPoint.U);
|
|
|
+
|
|
|
+ //计算P0点
|
|
|
+ if (SelectCalibration.MarkPoint == null)
|
|
|
+ {
|
|
|
+ SelectCalibration.MarkPoint = new RPoint();
|
|
|
+ }
|
|
|
+ SelectCalibration.MarkPoint.X = (float)p0[0];
|
|
|
+ SelectCalibration.MarkPoint.Y = (float)p0[1];
|
|
|
+ MessageBox.Show($"P0点计算成功!X:{calibResult.X},Y:{calibResult.Y}");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MessageBox.Show("未找到P0点,请调整工件位置后重试!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3.移动至标定块放置位置,放下标定块
|
|
|
+ isSuccess = await Robot.CalibMotionAsync(SelectCalibration.PutPoint, 0);
|
|
|
+ if (isSuccess)
|
|
|
+ {
|
|
|
+ //关闭吸气
|
|
|
+ Robot.CalibOutIO(false);
|
|
|
+ await Task.Delay(300);
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MessageBox.Show("移动至标定块放置位置,放下标定块失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4.Z轴上升安全高度
|
|
|
+ RPoint safePoint = SelectCalibration.PutPoint.Clone();
|
|
|
+ safePoint.Z = 0;
|
|
|
+ isSuccess = await Robot.CalibMotionAsync(safePoint, 0);
|
|
|
+ if (!isSuccess)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Z轴上升至安全高度失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //完成提示
|
|
|
+ MessageBox.Show("通过下相机标定P0点完成!");
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogHelper.WriteLogError("相机校准-通过下相机开始标定P0点时出错!", ex);
|
|
|
+ MessageBox.Show(ex.Message);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 移动至下相机位置
|
|
|
+ /// </summary>
|
|
|
+ async void ExecuteMoveDownCameraPosCommand()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ //弹窗确认是否移动
|
|
|
+ var result = MessageBox.Show("确认移动至下相机位置?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
+ if (result != MessageBoxResult.Yes)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //移动机器人至下相机位置
|
|
|
+ bool isSuccess = await Robot.CalibMotionAsync(SelectCalibration.DownCameraPoint, 0);
|
|
|
+ if (isSuccess)
|
|
|
+ {
|
|
|
+ MessageBox.Show("移动至下相机位置成功!");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MessageBox.Show("移动至下相机位置失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ MessageBox.Show(ex.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 示教下相机位置
|
|
|
+ /// </summary>
|
|
|
+ void ExecuteTeachDownCameraPosCommand()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ //弹窗确认是否示教
|
|
|
+ var result = MessageBox.Show("确认示教下相机位置?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
+ if (result != MessageBoxResult.Yes)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取机器人当前位置
|
|
|
+ SelectCalibration.DownCameraPoint = Robot.GetRobotPos();
|
|
|
+ MessageBox.Show("示教下相机位置成功!");
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ MessageBox.Show(ex.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 移动至标定块放位置
|
|
|
+ /// </summary>
|
|
|
+ async void ExecuteMovePutPosCommand()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ //弹窗确认是否移动
|
|
|
+ var result = MessageBox.Show("确认移动至标定块放位置?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
+ if (result != MessageBoxResult.Yes)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //移动机器人至标定块放位置
|
|
|
+ bool isSuccess = await Robot.CalibMotionAsync(SelectCalibration.PutPoint, 0);
|
|
|
+ if (isSuccess)
|
|
|
+ {
|
|
|
+ MessageBox.Show("移动至标定块放位置成功!");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MessageBox.Show("移动至标定块放位置失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ MessageBox.Show(ex.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 示教标定块放位置
|
|
|
+ /// </summary>
|
|
|
+ void ExecuteTeachPutPosCommand()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ //弹窗确认是否示教
|
|
|
+ var result = MessageBox.Show("确认示教标定块放位置?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
+ if (result != MessageBoxResult.Yes)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取机器人当前位置
|
|
|
+ SelectCalibration.PutPoint = Robot.GetRobotPos();
|
|
|
+ MessageBox.Show("示教标定块放位置成功!");
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ MessageBox.Show(ex.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 相机拍照
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
- private async Task<(bool IsSuccess, double X, double Y, double U, int ImageWidth, int ImageHeight)> CaptureAndProcess()
|
|
|
+ private async Task<(bool IsSuccess, double X, double Y, double U, int ImageWidth, int ImageHeight)> CaptureAndProcess(double[] robotCoord)
|
|
|
{
|
|
|
|
|
|
ICogImage image = null;
|
|
|
@@ -359,7 +583,7 @@ namespace TeamAAS_VP.ViewModels.Calibration
|
|
|
double y = double.Parse(items[1]);
|
|
|
|
|
|
//校准转换
|
|
|
- var calibResult = _calibrationServvice.ConvertPixelToPosition((x, y, 0), null, SelectedCalibration, Robot.Brand);
|
|
|
+ var calibResult = _calibrationServvice.ConvertPixelToPosition((x, y, 0), robotCoord, SelectedCalibration, Robot.Brand);
|
|
|
if (calibResult.IsSucceed)
|
|
|
{
|
|
|
x = calibResult.X;
|
|
|
@@ -399,7 +623,7 @@ namespace TeamAAS_VP.ViewModels.Calibration
|
|
|
{
|
|
|
SelectCalibration.FixedUpCameraFindP0Info = new FixedUpCameraFindP0Info();
|
|
|
}
|
|
|
- if (ToolBlockEdit.Subject==null)
|
|
|
+ if (ToolBlockEdit.Subject == null)
|
|
|
{
|
|
|
string prcPath = FilePath.CalibrationPath + "//" + SelectCalibration.Name + "//" + "FixedUpCameraTool.vpp";
|
|
|
if (File.Exists(prcPath))
|