173 lines
6.2 KiB
C#
173 lines
6.2 KiB
C#
using ACS.SPiiPlusNET;
|
|
using Aurora;
|
|
using Aurora.Api;
|
|
using Aurora.Api.Devices;
|
|
using Aurora.View;
|
|
using AuroraACS;
|
|
using AuroraHeightSensor; //26.04.13 잠시 주석
|
|
using AuroraLaser;
|
|
using AuroraLaser.Trumpf;
|
|
using AuroraMassFlowMeter;
|
|
using AuroraMotionBoard.Ajin;
|
|
using AuroraOCT.Trumpf;
|
|
using Hermes;
|
|
using WeldingCommon.Alarm;
|
|
using WeldingCommon.Device;
|
|
using WeldingCommon.Device.ACS;
|
|
using WeldingCommon.Process;
|
|
using WeldingCommon.Recipes;
|
|
using WeldingCommon.Sequences.SubSequence.StageA;
|
|
using WeldingCommon.Settings;
|
|
using WeldingCommon.Tools;
|
|
using WeldingCommon.Views.Recipes;
|
|
using OpenCvSharp.Dnn;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Threading;
|
|
using System.Windows;
|
|
using VisionCommon;
|
|
using WeldingCommon;
|
|
using WeldingCommon.Alarm;
|
|
using WeldingCommon.Data;
|
|
using WeldingCommon.Sequences;
|
|
using WeldingCommon.Settings;
|
|
using static AuroraOCT.Trumpf.OCT;
|
|
using static WeldingCommon.Devices.PLCController;
|
|
using WeldingCommon.Devices.ACS;
|
|
|
|
|
|
namespace WeldingCommon.Sequences
|
|
{
|
|
class SeqMotorInit
|
|
{
|
|
static readonly Logger Log = new Logger("MotorInitSequence");
|
|
const int SEQ_TIMEOUT = 120 * 1000;
|
|
const int RESET_TIMEOUT = 10 * 1000;
|
|
|
|
const int MOTION_TIMEOUT = 10 * 1000;
|
|
const int MOTION_INTERVAL = 20;
|
|
|
|
const string SEQ_ENTER = "SEQ_ENTER";
|
|
const string SEQ_CHECK_INIT_CONDITION = "Check Init Condition";
|
|
const string SEQ_ACS_ALARM_RESET = "ACS Alarm Reset";
|
|
const string SEQ_INIT_ACS_AXIS = "Init ACS X,Y Axis";
|
|
const string SEQ_INIT_COMPLETE = "Init Complete";
|
|
|
|
private static ScannerACS _acs;
|
|
private static IScannerACS _motion;
|
|
|
|
public static SequenceBuilder Builder()
|
|
{
|
|
SequenceBuilder sb = new SequenceBuilder(1000, true);
|
|
|
|
sb.AddAction(SEQ_ENTER, Sequence_Enter);
|
|
sb.AddAction(SEQ_CHECK_INIT_CONDITION, CheckInitCondition);
|
|
sb.AddAction(SEQ_ACS_ALARM_RESET, ACSAlarmReset);
|
|
sb.AddAction(SEQ_INIT_ACS_AXIS, ACSAxisInit);
|
|
sb.AddAction(SEQ_INIT_COMPLETE, InitComplete);
|
|
|
|
sb.OnStopped(OnStopped);
|
|
sb.OnForceError(OnForceError);
|
|
|
|
sb.Flows(sb.Init > sb[SEQ_ENTER] > sb[SEQ_CHECK_INIT_CONDITION] > sb[SEQ_ACS_ALARM_RESET] > sb[SEQ_INIT_ACS_AXIS] > sb[SEQ_INIT_COMPLETE] > sb.Final);
|
|
return sb;
|
|
}
|
|
|
|
private static SequenceActionResult Sequence_Enter(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
if (_motion is null)
|
|
_motion = _acs = context.Devices[CommonDeviceIds.ACS] as ScannerACS;
|
|
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private static SequenceActionResult CheckInitCondition(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
if (!((_motion as ScannerACS).IsActivated)) {
|
|
//26.04.13 잠시 주석
|
|
context.PutValue<int>("AlarmCode", AlarmCode_PrismaticGun.STAGE_A_DEACTIVATED_DISCONNECTED);
|
|
context.PutValue<string>("AlarmMessage",
|
|
$"[ACS activated({(_motion as ScannerACS).IsActivated})]");
|
|
return null;
|
|
}
|
|
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private static SequenceActionResult ACSAlarmReset(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
Log.V("ACS Alarm Reset Start");
|
|
_motion.ResetAlarm();
|
|
Thread.Sleep(1000);
|
|
|
|
var res = context.RetryUntilSuccess(() => !_acs.HasHeavyAlarm & !_acs.HasLightAlarm, RESET_TIMEOUT, MOTION_INTERVAL);
|
|
if (res == E2.TIMEOUT) {
|
|
context.PutValue<int>("AlarmCode", AlarmCode_PrismaticGun.ACS_AXIS_INITIALIZE_FAIL); //26.04.13 잠시 주석
|
|
context.PutValue<string>("AlarmMessage", "ACS Alarm Reset Fail");
|
|
return null;
|
|
} else if (res == E2.CANCELLED) {
|
|
context.PutValue<int>("AlarmCode", 0);
|
|
context.PutValue<string>("AlarmMessage", "ACS Alarm Reset Cancel");
|
|
return null;
|
|
}
|
|
Log.V("ACS Alarm Reset End");
|
|
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private static SequenceActionResult ACSAxisInit(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
Log.V($"ACS Init Start");
|
|
_motion.AllAxisHomeStart();
|
|
Thread.Sleep(1000);
|
|
|
|
var res = context.RetryUntilSuccess(() => _motion.CheckAllAxisHome(), SEQ_TIMEOUT, MOTION_INTERVAL);
|
|
if (res == E2.TIMEOUT) {
|
|
context.PutValue<int>("AlarmCode", AlarmCode_PrismaticGun.ACS_AXIS_INITIALIZE_FAIL); // 26.04.13 잠시 주석
|
|
context.PutValue<string>("AlarmMessage", "ACS Axis Home Timeout");
|
|
return null;
|
|
} else if (res == E2.CANCELLED) {
|
|
context.PutValue<int>("AlarmCode", 0);
|
|
context.PutValue<string>("AlarmMessage", "ACS Axis Home Cancel");
|
|
return null;
|
|
}
|
|
|
|
Log.V($"ACS Init End");
|
|
return SequenceAction.Ok(eTeachingPosition.SafetyPosition);
|
|
}
|
|
|
|
private static SequenceActionResult InitComplete(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
MessageBox.Show("전체 초기화 완료");
|
|
MessageUtil.ShowSuccessToast("Initialize Complete", Log);
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private static void OnStopped(SequenceContext context)
|
|
{
|
|
var AlarmCode = context.GetValue<int>("AlarmCode");
|
|
if (AlarmCode > 0)
|
|
Log.E(context.AlarmAccured(AlarmCode));
|
|
|
|
_motion.AllAxisHomeStop();
|
|
|
|
return;
|
|
}
|
|
|
|
private static void OnForceError(SequenceContext context, string arg2)
|
|
{
|
|
var AlarmCode = context.GetValue<int>("AlarmCode");
|
|
if (AlarmCode > 0)
|
|
Log.E(context.AlarmAccured(AlarmCode));
|
|
|
|
var message = context.GetValue<string>("AlarmMessage");
|
|
Application.Current.Dispatcher.Invoke(() => { MessageUtil.CreateAndShowMessageDialog("Initialize", message); });
|
|
|
|
_motion.AllAxisHomeStop();
|
|
|
|
return;
|
|
}
|
|
}
|
|
}
|