190 lines
7.4 KiB
C#
190 lines
7.4 KiB
C#
using Aurora.Api;
|
|
using Aurora.Api.Devices;
|
|
using Aurora.Util.HislogPlus;
|
|
using Aurora.View;
|
|
using AuroraLaser;
|
|
using AuroraLaser.Trumpf;
|
|
using AuroraMassFlowMeter;
|
|
using Hermes;
|
|
using Hermes.Collections;
|
|
using ILSOS_PrismaticGun.Alarm;
|
|
using ILSOS_PrismaticGun.Device.ACS;
|
|
using ILSOS_PrismaticGun.Process;
|
|
using ILSOS_PrismaticGun.Recipes;
|
|
using ILSOS_PrismaticGun.Settings;
|
|
using ILSOS_PrismaticGun.Tools;
|
|
using ILSOS_PrismaticGun.Views.Recipe;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using WeldingCommon;
|
|
using WeldingCommon.Sequences;
|
|
|
|
namespace ILSOS_PrismaticGun.Sequences
|
|
{
|
|
class SeqOneShot
|
|
{
|
|
static readonly Logger Log = new Logger("OneShotSequence");
|
|
const string SEQ_ENTER = "SEQ_ENTER";
|
|
const string SEQ_CHECK_INIT_CONDITION = "Check Init Condition";
|
|
const string SEQ_ONE_SHOT = "OneShot";
|
|
const string SEQ_ONE_SHOT_COMPLETE = "OneShot Sequence Complete";
|
|
private static IPrismaticGunACS _motion;
|
|
private static Laser _laser;
|
|
private static LaserTruFiber _laserCore;
|
|
private static OneShotItem _Item;
|
|
private static eStage _stage;
|
|
|
|
const int MOTION_TIMEOUT = 10 * 1000;
|
|
const int WELDING_TIMEOUT = 100 * 1000;
|
|
const int MOTION_INTERVAL = 20;
|
|
|
|
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_ONE_SHOT, OneShot);
|
|
sb.AddAction(SEQ_ONE_SHOT_COMPLETE, ProcessComplete);
|
|
|
|
sb.OnStopped(OnStopped);
|
|
sb.OnForceError(OnForceError);
|
|
|
|
sb.Flows(sb.Init > sb[SEQ_ENTER] > sb[SEQ_CHECK_INIT_CONDITION] > sb[SEQ_ONE_SHOT] > sb[SEQ_ONE_SHOT_COMPLETE] > sb.Final);
|
|
|
|
//sb.Draw("SeqOneShot.pdf");
|
|
|
|
return sb;
|
|
}
|
|
|
|
public static SequenceActionResult Sequence_Enter(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
Log.I("SeqOneShot Start");
|
|
if (_motion is null)
|
|
_motion = context.Devices[DeviceIds.ACS] as IPrismaticGunACS;
|
|
if (_laser is null)
|
|
_laser = context.Devices[CommonDeviceIds.Laser] as Laser;
|
|
_laserCore = _laser.getCore() as LaserTruFiber;
|
|
|
|
(_stage, _Item) = ((eStage, OneShotItem))param.Param;
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private static SequenceActionResult CheckInitCondition(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
Log.I("SeqOneShot CheckInitCondition");
|
|
if (!((_motion as PrismaticGunACS).IsActivated)) {
|
|
Log.E($"[ACS activated({(_motion as PrismaticGunACS).IsActivated})]");
|
|
return null;
|
|
}
|
|
|
|
if (!(_laser.IsActivated && _laser.GetConnected())) {
|
|
Log.E($"[Laser activated({_laser.IsActivated}) / connected({_laser.GetConnected()})]");
|
|
context.PutValue<int>("AlarmCode", AlarmCode_PrismaticGun.DEVICE_LASER_DEACTIVATED_DISCONNECTED);
|
|
return null;
|
|
}
|
|
|
|
if (!_laser.GetLaserReady()) {
|
|
_laser.LaserOn();
|
|
|
|
Log.V($"Laser On");
|
|
var res = context.RetryUntilSuccess(() => _laser.GetLaserReady(), WELDING_TIMEOUT, MOTION_INTERVAL);
|
|
if (res == E2.TIMEOUT) {
|
|
Log.FuncE("Laser Ready Check Timeout!");
|
|
context.PutValue<int>("AlarmCode", AlarmCode_PrismaticGun.GET_LASER_READY);
|
|
return null;
|
|
} else if (res == E2.CANCELLED) {
|
|
Log.FuncE("Laser Ready Check Cancel!");
|
|
context.PutValue<int>("AlarmCode", 0);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
List<(int wordNo, int input, bool isWriteValue)> datas = new List<(int wordNo, int input, bool isWriteValue)>();
|
|
// OCT 미사용 >> A(1) / B(2)
|
|
// OCT 사용 >> A(3) B(4)
|
|
var programNo = (int)_stage + 1;
|
|
datas.Add((csWriteNodeNo.PROGRAM_NO, programNo, true));
|
|
datas.Add((csWriteNodeNo.IW05, _Item.CoreRatio, true));
|
|
|
|
if (_laserCore.UpdatesDatasIfChanged(datas)) {
|
|
var res = context.RetryUntilSuccess(() => _laserCore.GetProgramCompleted(), MOTION_TIMEOUT, MOTION_INTERVAL);
|
|
if (res == E2.TIMEOUT) {
|
|
context.PutValue<int>("AlarmCode", AlarmCode_PrismaticGun.LASER_READY);
|
|
return null;
|
|
} else if (res == E2.CANCELLED) {
|
|
context.PutValue<int>("AlarmCode", AlarmCode_PrismaticGun.LASER_READY);
|
|
return null;
|
|
}
|
|
}
|
|
Log.V($"Laser Program Update Complete [Ratio : {_Item.CoreRatio}] [Program No : {(int)_stage + 1}]");
|
|
|
|
var res1 = context.RetryUntilSuccess(() => _laserCore.GetLaserReady() && _laserCore.GetProgramNo() == (int)_stage + 1, MOTION_TIMEOUT, MOTION_INTERVAL);
|
|
if (res1 == E2.TIMEOUT) {
|
|
context.PutValue<int>("AlarmCode", AlarmCode_PrismaticGun.LASER_READY_PROGRAM_ACTIVATED_TIMEOUT);
|
|
return null;
|
|
} else if (res1 == E2.CANCELLED) {
|
|
context.PutValue<int>("AlarmCode", 0);
|
|
return null;
|
|
}
|
|
|
|
Log.V($"Laser Setting Complete {_stage}");
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private static SequenceActionResult OneShot(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
var _shotTime = _Item.ShotTime;
|
|
var _shotPower = _Item.ShotPower;
|
|
|
|
_motion.SetLCILserOn(_stage, true);
|
|
_motion.SetOneShot(_stage, _shotTime, _shotPower);
|
|
_motion.OneShotStart(_stage);
|
|
Thread.Sleep(500);
|
|
Log.E(">> OneShot Start");
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private static SequenceActionResult ProcessComplete(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
var ret = context.RetryUntilSuccess(() => _motion.CheckOneShotComp(_stage), MOTION_TIMEOUT, MOTION_INTERVAL);
|
|
if(ret == E2.TIMEOUT) {
|
|
Log.E("OneShot Timeout");
|
|
context.PutValue<int>("AlarmCode", AlarmCode_PrismaticGun.ACS_ONESHOT_COMP);
|
|
return null;
|
|
} else if(ret == E2.CANCELLED) {
|
|
Log.E("OneShot Cancel");
|
|
context.PutValue<int>("AlarmCode", AlarmCode_PrismaticGun.ACS_ONESHOT_COMP);
|
|
return null;
|
|
}
|
|
|
|
Log.FuncV(">> OneShot Complete");
|
|
_motion.SetLCILserOn(_stage, false);
|
|
_laser.LaserOff();
|
|
Thread.Sleep(500);
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private static void OnStopped(SequenceContext context)
|
|
{
|
|
_motion.SetLCILserOn(_stage, false);
|
|
_laser.LaserOff();
|
|
MessageUtil.ShowErrorToast(">> Sequence Stop");
|
|
return;
|
|
}
|
|
|
|
private static void OnForceError(SequenceContext context, string arg2)
|
|
{
|
|
_motion.SetLCILserOn(_stage, false);
|
|
_laser.LaserOff();
|
|
MessageUtil.ShowErrorToast(">> Sequence Fail");
|
|
return;
|
|
}
|
|
}
|
|
}
|