using Aurora.Api; using Aurora.View; using System.Threading; namespace VisionCommon { /// /// 서브 시퀀스 추상 베이스 클래스 /// public abstract class SubSeqBase { private const int DEFAULT_GRAB_DELAY = 50; // 50 ms protected Logger _VisionLog = new Logger(typeof(SubSeqBase).Name, VisionKeys.LogKey); /// /// 서브 시퀀스의 시퀀스빌더 생성 /// /// 서브 시퀀스 이름 /// 시퀀스빌더 public abstract SequenceBuilder Builder(string seqName); /// /// 무브 후, 그랩 전 딜레이 적용 /// /// 서브 시스템 정보 public void ApplyGrabDelay(SubSysInfo subSysInfo) { var subSysRecipe = VisionRecipeManager.GetSubSysRecipe(subSysInfo); if (subSysRecipe != null) { Thread.Sleep(subSysRecipe.ProcRecipe.GrabDelay); } else { Thread.Sleep(DEFAULT_GRAB_DELAY); } } /// /// 에러로그 출력 및 Toast 메시지 띄우기 /// /// 로거 /// 에러 메시지 public void PrintErrorLogAndShowErrorToast(Logger logger, string errMsg) { logger.E(errMsg); MessageUtil.ShowErrorToast(errMsg); } /// /// 에러로그 출력 및 Toast 메시지 띄우기 /// /// 로거 /// 메시지 public void PrintLogAndShowToast(Logger logger, string msg) { logger.I(msg); MessageUtil.ShowToast(msg); } /// /// C2_F4 or C4_F4 라인 교점 얼라인시, 이웃한 FOV들 간에 상관관계를 이용하여 라인 교점을 보상할지 체크 /// /// protected bool IsFixedLineIntersections(AlignInfo alignInfo) { var alignRecipe = VisionRecipeManager.GetAlignRecipe(alignInfo); if (alignRecipe.ProcParams.ProcFovType == eProcFovType.C2_F4_MV || alignRecipe.ProcParams.ProcFovType == eProcFovType.C4_F4) { if (alignRecipe.ProcParams.FixedLineIntersections) { return true; } } return false; } protected PatternInfo GetPatternInfo(AlignInfo alignInfo, FovInfo fovInfo, ProcPatternInfo procPatternInfo) { var fovRecipe = VisionRecipeManager.GetFovRecipe(fovInfo); var alignRecipe = VisionRecipeManager.GetAlignRecipe(alignInfo); PatternIndex patternIndex; PatternAgentBase patternAgent; if (procPatternInfo.IsFovPattern) { patternAgent = FovPatternAgentManager.GetAgent(fovInfo.ToSubSysInfo()); patternIndex = new FovPatternIndex(fovInfo, fovRecipe.FovName, procPatternInfo.PatternId); } else { patternAgent = CamPatternAgentManager.GetAgent(fovRecipe.CamRecipe.CamId); patternIndex = new CamPatternIndex(fovRecipe.CamRecipe.CamId, procPatternInfo.PatternId); } PatternInfo patternInfo = patternAgent.GetPatternInfo(patternIndex); patternInfo.PatternName = procPatternInfo.PatternName; return patternInfo; } protected void PrintVisionLog(AlignResult alignResult) { _VisionLog.I($"AlignCnt : {alignResult.AlignCnt}"); _VisionLog.I($"dX : {alignResult.Delta.X:F4}, dY : {alignResult.Delta.Y:F4}, dT : {alignResult.Delta.T.Degree:F4}"); _VisionLog.I($"Status : {alignResult.Status}"); _VisionLog.I($"Algorithm : {alignResult.AlignAlgorithm}"); } #region Light Retry protected LightInfo _OriginalLightInfo = null; // 원본 조명 백업용 protected int _CurLightRetryCnt = 0; //protected const int LIGHT_RETRY_MAX_CNT = 4; // -20%, -10%, +10%, +20% (총 4회) protected void SetLightRetry() { _CurLightRetryCnt = 0; _OriginalLightInfo = null; } protected bool IsLightRetryStepMode(eLightRetryMode mode) => mode == eLightRetryMode.Step_OneWay || mode == eLightRetryMode.Step_Swing; // LightRetry Step Mode 일때 Light Value 가져오는 Method protected double GetLightRetryValueStepMode(int curLightRetryCnt, double curLightValue, LightRetryParams lightRetryParams) { double result = 0; if (lightRetryParams.LightRetryMode == eLightRetryMode.Step_OneWay) { result = curLightValue + lightRetryParams.LightRetryStep; } else // if (lightRetryParams.LightRetryMode == eLightRetryMode.Step_Swing) { var sign = curLightRetryCnt % 2 == 0 ? 1 : -1; result = curLightValue + lightRetryParams.LightRetryStep * curLightRetryCnt * sign; } return result >=0 ? result : 0; } // LightRetry Ratio Mode 일때 Light Value 가져오는 Method protected double GetLightRetryValueRatioMode(int curLightRetryCnt, double curLightValue, double originLightValue, LightRetryParams lightRetryParams) { double result = 0; if (lightRetryParams.LightRetryMode == eLightRetryMode.Ratio_OneWay ) { result = curLightValue + (lightRetryParams.LightRetryRatio == 0? 0: originLightValue * (lightRetryParams.LightRetryRatio / 100.0)); } else // if(lightRetryParams.LightRetryMode == eLightRetryMode.Ratio_Swing) { var sign = curLightRetryCnt % 2 == 0 ? 1 : -1; result = curLightValue + (lightRetryParams.LightRetryRatio == 0 ? 0 : originLightValue * (lightRetryParams.LightRetryRatio / 100.0 * curLightRetryCnt * sign)); } return result >= 0 ? result : 0; } #endregion } }