183 lines
6.6 KiB
C#
183 lines
6.6 KiB
C#
|
|
using MainShell.Common;
|
|||
|
|
using MainShell.Log;
|
|||
|
|
using MainShell.Motion;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Threading;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
|
|||
|
|
namespace MainShell.PageCalib.OriginCalib.Service
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// ʾ<><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڱ궨<DAB1><EAB6A8><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public class VisionCapturePostProcessor : ICalibrationPostProcessor
|
|||
|
|
{
|
|||
|
|
public string Name => "VisionCapture";
|
|||
|
|
|
|||
|
|
public async Task ExecuteAsync(OriginCalibrationExecutionResult calibrationResult, CancellationToken cancellationToken,object pars= null)
|
|||
|
|
{
|
|||
|
|
"ִ<><D6B4><EFBFBD><EFBFBD><EFBFBD>պ<EFBFBD><D5BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...".LogInfo();
|
|||
|
|
|
|||
|
|
// <20>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// <20><><EFBFBD>磺await _visionService.CaptureAsync(cancellationToken);
|
|||
|
|
|
|||
|
|
await Task.Delay(100, cancellationToken);
|
|||
|
|
|
|||
|
|
"<22><><EFBFBD>պ<EFBFBD><D5BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɡ<EFBFBD>".LogInfo();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڱ궨<DAB1><EAB6A8><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>λ<EFBFBD><CEBB>ִ<EFBFBD>бƽ<D0B1><C6BD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public class ApproachAlignmentPostProcessor : ICalibrationPostProcessor
|
|||
|
|
{
|
|||
|
|
private readonly ApproachAlignmentService _approachAlignmentService;
|
|||
|
|
private readonly IReadOnlyList<ApproachAlignmentAxis> _alignmentAxes;
|
|||
|
|
private readonly CameraType _camera;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>캯<EFBFBD><ECBAAF>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="approachAlignmentService"><3E>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
|||
|
|
/// <param name="alignmentAxes"><3E><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD></param>
|
|||
|
|
/// <param name="camera"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>Ĭ<EFBFBD><C4AC>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
|||
|
|
public ApproachAlignmentPostProcessor(
|
|||
|
|
ApproachAlignmentService approachAlignmentService,
|
|||
|
|
IEnumerable<ApproachAlignmentAxis> alignmentAxes,
|
|||
|
|
CameraType camera = CameraType.TopPositionCamera)
|
|||
|
|
{
|
|||
|
|
_approachAlignmentService = approachAlignmentService ?? throw new ArgumentNullException(nameof(approachAlignmentService));
|
|||
|
|
|
|||
|
|
if (alignmentAxes == null)
|
|||
|
|
{
|
|||
|
|
throw new ArgumentNullException(nameof(alignmentAxes));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
_alignmentAxes = alignmentAxes.ToList().AsReadOnly();
|
|||
|
|
|
|||
|
|
if (_alignmentAxes.Count == 0)
|
|||
|
|
{
|
|||
|
|
throw new ArgumentException("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫһ<D2AA><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ᡣ", nameof(alignmentAxes));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
_camera = camera;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public string Name => "ApproachAlignment";
|
|||
|
|
|
|||
|
|
public async Task ExecuteAsync(OriginCalibrationExecutionResult calibrationResult, CancellationToken cancellationToken,object pars= null)
|
|||
|
|
{
|
|||
|
|
"ִ<>бƽ<D0B1><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...".LogInfo();
|
|||
|
|
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
ApproachAlignmentRequest alignmentRequest = new ApproachAlignmentRequest(_alignmentAxes, _camera);
|
|||
|
|
if(pars is CenterRecognitionParameters centerRecognitionParameters)
|
|||
|
|
{
|
|||
|
|
alignmentRequest.RecognitionParameters = centerRecognitionParameters;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ApproachAlignmentResult alignmentResult = await _approachAlignmentService.ApproachAlignmentAsync(
|
|||
|
|
alignmentRequest,
|
|||
|
|
cancellationToken).ConfigureAwait(false);
|
|||
|
|
|
|||
|
|
if (alignmentResult.Succeeded)
|
|||
|
|
{
|
|||
|
|
string.Format("<22>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{0}", alignmentResult.CompletedIterations).LogInfo();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
string.Format("<22>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>{0}", alignmentResult.Message).LogInfo();
|
|||
|
|
throw alignmentResult.Exception ?? new InvalidOperationException(alignmentResult.Message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (OperationCanceledException)
|
|||
|
|
{
|
|||
|
|
"<22>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>".LogInfo();
|
|||
|
|
throw;
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
string.Format("<22>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣<EFBFBD><ECB3A3>{0}", ex.Message).LogInfo();
|
|||
|
|
throw;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>ζ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڱ궨<DAB1><EAB6A8><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>λ<EFBFBD><CEBB>ִ<EFBFBD><D6B4>һ<EFBFBD><D2BB>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public class SingleAlignmentPostProcessor : ICalibrationPostProcessor
|
|||
|
|
{
|
|||
|
|
private readonly ApproachAlignmentService _approachAlignmentService;
|
|||
|
|
private readonly IReadOnlyList<ApproachAlignmentAxis> _alignmentAxes;
|
|||
|
|
private readonly CameraType _camera;
|
|||
|
|
|
|||
|
|
public SingleAlignmentPostProcessor(
|
|||
|
|
ApproachAlignmentService approachAlignmentService,
|
|||
|
|
IEnumerable<ApproachAlignmentAxis> alignmentAxes,
|
|||
|
|
CameraType camera = CameraType.TopPositionCamera)
|
|||
|
|
{
|
|||
|
|
_approachAlignmentService = approachAlignmentService ?? throw new ArgumentNullException(nameof(approachAlignmentService));
|
|||
|
|
|
|||
|
|
if (alignmentAxes == null)
|
|||
|
|
{
|
|||
|
|
throw new ArgumentNullException(nameof(alignmentAxes));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
_alignmentAxes = alignmentAxes.ToList().AsReadOnly();
|
|||
|
|
|
|||
|
|
if (_alignmentAxes.Count == 0)
|
|||
|
|
{
|
|||
|
|
throw new ArgumentException("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫһ<D2AA><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ᡣ", nameof(alignmentAxes));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
_camera = camera;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public string Name => "SingleAlignment";
|
|||
|
|
|
|||
|
|
public async Task ExecuteAsync(OriginCalibrationExecutionResult calibrationResult, CancellationToken cancellationToken, object pars = null)
|
|||
|
|
{
|
|||
|
|
"ִ<>е<EFBFBD><D0B5>ζ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...".LogInfo();
|
|||
|
|
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
ApproachAlignmentRequest alignmentRequest = new ApproachAlignmentRequest(_alignmentAxes, _camera);
|
|||
|
|
if (pars is CenterRecognitionParameters centerRecognitionParameters)
|
|||
|
|
{
|
|||
|
|
alignmentRequest.RecognitionParameters = centerRecognitionParameters;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ApproachAlignmentResult alignmentResult = await _approachAlignmentService.SingleAlignmentAsync(
|
|||
|
|
alignmentRequest,
|
|||
|
|
cancellationToken).ConfigureAwait(false);
|
|||
|
|
|
|||
|
|
if (alignmentResult.Succeeded)
|
|||
|
|
{
|
|||
|
|
string.Format("<22><><EFBFBD>ζ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD>ɣ<EFBFBD>ִ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>{0}", alignmentResult.CompletedIterations).LogInfo();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
string.Format("<22><><EFBFBD>ζ<EFBFBD>λʧ<CEBB>ܣ<EFBFBD>{0}", alignmentResult.Message).LogInfo();
|
|||
|
|
throw alignmentResult.Exception ?? new InvalidOperationException(alignmentResult.Message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (OperationCanceledException)
|
|||
|
|
{
|
|||
|
|
"<22><><EFBFBD>ζ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>".LogInfo();
|
|||
|
|
throw;
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
string.Format("<22><><EFBFBD>ζ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣<EFBFBD><ECB3A3>{0}", ex.Message).LogInfo();
|
|||
|
|
throw;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|