189 lines
7.0 KiB
C#
189 lines
7.0 KiB
C#
using Aurora.Api;
|
|
using VisionCommon;
|
|
using System.Collections.Generic;
|
|
|
|
namespace VisionSequence.Pattern {
|
|
/// <summary>
|
|
/// 카메라 그랩, 패턴 검출 공정 시퀀스 파라미터
|
|
/// </summary>
|
|
public class GrabFindProcSeqParams : SeqParamsBase {
|
|
/// <summary>FOV 키 정보</summary>
|
|
public FovInfo FovInfo { get; set; }
|
|
/// <summary>패턴 정보</summary>
|
|
public PatternInfo PatternInfo { get; set; }
|
|
/// <summary>메인 화면 타입</summary>
|
|
public eDisplayType DisplayType { get; set; }
|
|
|
|
/// <summary>
|
|
/// 생성자
|
|
/// </summary>
|
|
/// <param name="fovInfo">FOV 키 정보</param>
|
|
/// <param name="patternInfo">패턴 정보</param>
|
|
/// <param name="displayType">메인 화면 타입</param>
|
|
/// <param name="seqMode">시퀀스 모드</param>
|
|
public GrabFindProcSeqParams(
|
|
FovInfo fovInfo,
|
|
PatternInfo patternInfo,
|
|
eDisplayType displayType = eDisplayType.Main_1,
|
|
eSeqMode seqMode = eSeqMode.Auto) : base(seqMode) {
|
|
|
|
this.FovInfo = fovInfo;
|
|
this.PatternInfo = patternInfo;
|
|
this.DisplayType = displayType;
|
|
}
|
|
|
|
/// <summary>
|
|
/// GrabFindWithFixtureSeqParams로 변환한다.
|
|
/// </summary>
|
|
/// <returns>GrabFindWithFixtureSeqParams</returns>
|
|
internal GrabFindWithFixtureSeqParams ToGrabFindWithFixtureSeqParams() {
|
|
return new GrabFindWithFixtureSeqParams(FovInfo, PatternInfo, DisplayType, SeqMode);
|
|
}
|
|
|
|
/// <summary>
|
|
/// GrabFindSeqParams로 변환한다.
|
|
/// </summary>
|
|
/// <returns>GrabFindSeqParams</returns>
|
|
internal GrabFindSeqParams ToGrabFindSeqParams() {
|
|
return new GrabFindSeqParams(FovInfo, PatternInfo, DisplayType, SeqMode);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 카메라 그랩, 패턴 검출 공정 시퀀스
|
|
/// </summary>
|
|
public class GrabFindProcSeq : SubSeqBase {
|
|
private readonly Logger _Logger;
|
|
private TactTimeChecker _TactTimeChecker;
|
|
private GrabFindProcSeqParams _Params;
|
|
private FovRecipe _FovRecipe;
|
|
|
|
private string _SeqName;
|
|
|
|
#region Sequence Id
|
|
private const string SEQ_ID_INIT = "INIT";
|
|
private const string SEQ_ID_CHECK_FIXTURE_ENABLED = "CHECK_FIXTURE_ENABLED";
|
|
|
|
private const string SEQ_ID_SET_GRAB_FIND_SEQ_PARAMS = "SET_GRAB_FIND_SEQ_PARAMS";
|
|
private const string SEQ_ID_GRAB_FIND_SEQ = "GRAB_FIND_SEQ";
|
|
|
|
private const string SEQ_ID_SET_GRAB_FIND_WITH_FIXTURE_SEQ_PARAMS = "SET_GRAB_FIND_WITH_FIXTURE_SEQ_PARAMS";
|
|
private const string SEQ_ID_GRAB_FIND_WITH_FIXTURE_SEQ = "GRAB_FIND_WITH_FIXTURE_SEQ";
|
|
|
|
private const string SEQ_ID_SEQ_COMPLETE = "SEQ_COMPLETE";
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 생성자
|
|
/// </summary>
|
|
public GrabFindProcSeq() {
|
|
_Logger = new Logger($"{GetType().Name}");
|
|
}
|
|
|
|
private void SetActions(SequenceBuilder sb) {
|
|
var grabFindSeqBuilder = SubSeqManager.CreateSubSeqBuilder(new GrabFindSeq(), "GrabFindSeq");
|
|
var grabFindWithFixtureSeqBuilder = SubSeqManager.CreateSubSeqBuilder(new GrabFindWithFixtureSeq(), "GrabFindWithFixtureSeq");
|
|
|
|
sb.AddAction(SEQ_ID_INIT, Init);
|
|
sb.AddDecision(SEQ_ID_CHECK_FIXTURE_ENABLED, CheckFixtureEnabled);
|
|
|
|
sb.AddAction(SEQ_ID_SET_GRAB_FIND_WITH_FIXTURE_SEQ_PARAMS, SetGrabFindWithFixtureSeqParams);
|
|
sb.AddSubsequence(SEQ_ID_GRAB_FIND_WITH_FIXTURE_SEQ, grabFindWithFixtureSeqBuilder);
|
|
|
|
sb.AddAction(SEQ_ID_SET_GRAB_FIND_SEQ_PARAMS, SetGrabFindSeqParams);
|
|
sb.AddSubsequence(SEQ_ID_GRAB_FIND_SEQ, grabFindSeqBuilder);
|
|
|
|
sb.AddAction(SEQ_ID_SEQ_COMPLETE, SeqComplete);
|
|
}
|
|
|
|
public override SequenceBuilder Builder(string seqName) {
|
|
_SeqName = seqName;
|
|
_TactTimeChecker = new TactTimeChecker(_SeqName);
|
|
|
|
SequenceBuilder sb = new SequenceBuilder(1000);
|
|
SetActions(sb);
|
|
sb.OnStopped(OnStopped);
|
|
sb.OnForceError(OnForceError);
|
|
|
|
sb.Flows(
|
|
sb.Init
|
|
> sb[SEQ_ID_INIT]
|
|
> sb[SEQ_ID_CHECK_FIXTURE_ENABLED]
|
|
|
|
> sb[SEQ_ID_SET_GRAB_FIND_WITH_FIXTURE_SEQ_PARAMS]
|
|
> sb[SEQ_ID_GRAB_FIND_WITH_FIXTURE_SEQ]
|
|
> sb[SEQ_ID_SEQ_COMPLETE]
|
|
> sb.Final
|
|
);
|
|
|
|
sb.Flows(
|
|
sb[SEQ_ID_CHECK_FIXTURE_ENABLED] // Fixture Disabled
|
|
> sb[SEQ_ID_SET_GRAB_FIND_SEQ_PARAMS]
|
|
> sb[SEQ_ID_GRAB_FIND_SEQ]
|
|
> sb[SEQ_ID_SEQ_COMPLETE]
|
|
);
|
|
|
|
#if SEQ_DRAW
|
|
sb.Draw($"{GetType().Name}.pdf");
|
|
#endif
|
|
|
|
return sb;
|
|
}
|
|
|
|
private SequenceActionResult Init(SequenceContext context, string id, SequenceActionResult param) {
|
|
if (param.Param != null) {
|
|
_Params = param.Param as GrabFindProcSeqParams;
|
|
}
|
|
else {
|
|
_Logger.E($"_Params is null.");
|
|
return null;
|
|
}
|
|
|
|
_FovRecipe = VisionRecipeManager.GetFovRecipe(_Params.FovInfo);
|
|
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private string CheckFixtureEnabled(SequenceContext context, string id, ICollection<string> branches, SequenceActionResult param) {
|
|
if (_Params.PatternInfo.FixtureSetting.Enabled) {
|
|
return SEQ_ID_SET_GRAB_FIND_WITH_FIXTURE_SEQ_PARAMS;
|
|
}
|
|
else {
|
|
return SEQ_ID_SET_GRAB_FIND_SEQ_PARAMS;
|
|
}
|
|
}
|
|
|
|
private SequenceActionResult SetGrabFindWithFixtureSeqParams(SequenceContext context, string id, SequenceActionResult param) {
|
|
return SequenceAction.Ok(_Params.ToGrabFindWithFixtureSeqParams());
|
|
}
|
|
|
|
private SequenceActionResult SetGrabFindSeqParams(SequenceContext context, string id, SequenceActionResult param) {
|
|
return SequenceAction.Ok(_Params.ToGrabFindSeqParams());
|
|
}
|
|
|
|
private SequenceActionResult SeqComplete(SequenceContext context, string id, SequenceActionResult param) {
|
|
var mainPatternResult = context.GetValue<PatternResult>(string.Format(VisionContextKeys.CNTXT_KEY_PATTERN_RESULT, _Params.FovInfo.GetKey()));
|
|
_TactTimeChecker.Stop(TactTimeType.ProcSeq, "Light/Grab/Find");
|
|
|
|
return SequenceAction.Ok(mainPatternResult);
|
|
}
|
|
|
|
void OnStopped(
|
|
SequenceContext context) {
|
|
_Logger.I($"{context.SequenceId} - STOP Handler");
|
|
HandleAbnormalFinish(context);
|
|
}
|
|
|
|
void OnForceError(
|
|
SequenceContext context, string id) {
|
|
_Logger.E($"{context.SequenceId} - FORCE ERROR Handler");
|
|
HandleAbnormalFinish(context);
|
|
}
|
|
|
|
void HandleAbnormalFinish(
|
|
SequenceContext context) {
|
|
_TactTimeChecker.Stop(TactTimeType.ProcSeq, "Light/Grab/Find");
|
|
}
|
|
}
|
|
}
|