125 lines
3.7 KiB
C#
125 lines
3.7 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora.Api;
|
|
using VisionCommon;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace VisionAligner {
|
|
/// <summary>
|
|
/// 얼라인 재시도 체크
|
|
/// </summary>
|
|
public class AlignRetryChecker {
|
|
private Logger _Logger;
|
|
private AlignRecipe _AlignRecipe;
|
|
|
|
private int _CurrentRetryCount;
|
|
|
|
/// <summary>
|
|
/// 생성자
|
|
/// </summary>
|
|
/// <param name="alignRecipe">얼라인 레시피</param>
|
|
public AlignRetryChecker(AlignRecipe alignRecipe) {
|
|
_Logger = new Logger("AlignRetryChecker");
|
|
_AlignRecipe = alignRecipe;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 얼라인 재시도 활성 유무
|
|
/// </summary>
|
|
/// <returns>얼라인 재시도 활성 유무</returns>
|
|
public bool IsEnabled() {
|
|
return _AlignRecipe.AlignRetry.Enabled;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 얼라인 재시도 상태를 Get한다
|
|
/// </summary>
|
|
/// <param name="alignDelta">얼라인 보정값</param>
|
|
/// <returns>얼라인 상태</returns>
|
|
public AlignStatus GetRetryStatus(AlignDelta alignDelta) {
|
|
AlignStatus status = GetRetrySpecStatus(alignDelta);
|
|
|
|
IncreaseRetryCount();
|
|
|
|
if (status == AlignStatus.RETRY) {
|
|
if (IsOverRetryCount()) {
|
|
status = AlignStatus.RETRY_COUNT_OVER;
|
|
}
|
|
}
|
|
|
|
if (IsResetRetryCountNeeded(status)) {
|
|
ResetRetryCount();
|
|
}
|
|
|
|
return status;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 얼라인 재시도 횟수를 초기화한다
|
|
/// </summary>
|
|
public void Reset() {
|
|
ResetRetryCount();
|
|
}
|
|
|
|
private AlignStatus GetRetrySpecStatus(AlignDelta alignDelta) {
|
|
bool isOver = IsOverRetrySpecX(alignDelta);
|
|
isOver |= IsOverRetrySpecY(alignDelta);
|
|
isOver |= IsOverRetrySpecT(alignDelta.T);
|
|
|
|
if (isOver) {
|
|
return AlignStatus.RETRY;
|
|
}
|
|
return AlignStatus.OK;
|
|
}
|
|
|
|
private bool IsOverRetrySpecX(AlignDelta alignDelta) {
|
|
if (Math.Abs(alignDelta.X) > _AlignRecipe.AlignRetry.RangeX) {
|
|
_Logger.I($"Over Retry-SpecX! [deltaX : {alignDelta.ToStringX()}, specX : {_AlignRecipe.AlignRetry.RangeX} mm]");
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private bool IsOverRetrySpecY(AlignDelta alignDelta) {
|
|
if (Math.Abs(alignDelta.Y) > _AlignRecipe.AlignRetry.RangeY) {
|
|
_Logger.I($"Over Retry-SpecY! [deltaY : {alignDelta.ToStringY()}, specY : {_AlignRecipe.AlignRetry.RangeY} mm]");
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private bool IsOverRetrySpecT(Angle deltaT) {
|
|
if (Math.Abs(deltaT.Degree) > _AlignRecipe.AlignRetry.RangeT) {
|
|
_Logger.I($"Over Retry-SpecT! [deltaT : {deltaT}, specT : {_AlignRecipe.AlignRetry.RangeT}]");
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private void IncreaseRetryCount() {
|
|
_CurrentRetryCount++;
|
|
}
|
|
|
|
private void ResetRetryCount() {
|
|
_CurrentRetryCount = 0;
|
|
}
|
|
|
|
private bool IsResetRetryCountNeeded(AlignStatus status) {
|
|
if (status == AlignStatus.RETRY) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private bool IsOverRetryCount() {
|
|
return _CurrentRetryCount > (int)_AlignRecipe.AlignRetry.RetryCnt;
|
|
}
|
|
}
|
|
}
|