361 lines
15 KiB
C#
361 lines
15 KiB
C#
using Aurora.Api;
|
|
using Aurora.Api.Devices;
|
|
using Aurora.Api.Manager;
|
|
using Aurora.View;
|
|
using AuroraACS;
|
|
using AuroraLaser;
|
|
using AuroraLaser.Trumpf;
|
|
using AuroraMassFlowMeter;
|
|
using AuroraMotionBoard.Ajin;
|
|
using AuroraOCT.Trumpf;
|
|
using Hermes;
|
|
using WeldingCommon.Alarm;
|
|
using WeldingCommon.Device.ACS;
|
|
using WeldingCommon.Process;
|
|
using WeldingCommon.Recipes;
|
|
using WeldingCommon.Sequences.SubSequence.StageA;
|
|
using WeldingCommon.Settings;
|
|
using WeldingCommon.Tools;
|
|
using OpenCvSharp;
|
|
using OpenCvSharp.Dnn;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using VisionCommon;
|
|
using WeldingCommon;
|
|
using WeldingCommon.Settings;
|
|
using static AuroraOCT.Trumpf.OCT;
|
|
using WeldingCommon.Devices.ACS;
|
|
|
|
namespace WeldingCommon.Sequences
|
|
{
|
|
class SeqSplitLine
|
|
{
|
|
static readonly Logger Log = new Logger("SplitLineSequence");
|
|
const int SLEEP_TIME_MS = 50;
|
|
const int SEQ_CHECK_TIMER = 100;
|
|
const int SEQ_TIMEOUT = 30 * 1000;
|
|
|
|
const int MOTION_TIMEOUT = 10 * 1000;
|
|
const int MOTION_INTERVAL = 20;
|
|
const int WELDING_TIMEOUT = 30 * 1000;
|
|
|
|
const string SEQ_ENTER = "SEQ_ENTER";
|
|
const string SEQ_CHECK_INIT_CONDITION = "Check Init Condition";
|
|
const string SEQ_CHECK_LINE_COUNT = "Check Line Counting";
|
|
const string SEQ_Z_AXIS_MOVE = "X Axis Moving";
|
|
const string SEQ_ACS_PARAMETER_SET = "ACS Parameter Setting";
|
|
const string SEQ_WELDING_MOTION = "Welding Motion";
|
|
const string SEQ_MOTION_INTERLOCK = "Motion Interlock";
|
|
const string SEQ_LINE_PROCESS_COMPLETE = "SplitSequence Complete";
|
|
|
|
private static ManualLaserSetting _manual;
|
|
private static ObservableCollection<LineShotItem> _data;
|
|
private static bool _LaserIOUse;
|
|
|
|
private static int LineInLinesCount;
|
|
private static int LineInLinesIndex = 0;
|
|
|
|
private static MainRecipe _mainRecipe;
|
|
|
|
private static ScannerACS _acs;
|
|
private static IScannerACS _acsMotion;
|
|
private static Laser _laser;
|
|
private static LaserTruFiber _laserCore;
|
|
private static LaserPowerCalParam _laserCal;
|
|
private static ACSMotor _AxisX, _AxisY, _AxisZ;
|
|
private static AuroraACS.Speed _spd = AuroraACS.Speed.M;
|
|
private static TeachingPositionSetting _setting;
|
|
|
|
public static SequenceBuilder Builder()
|
|
{
|
|
SequenceBuilder sb = new SequenceBuilder(1000, true);
|
|
|
|
sb.AddAction(SEQ_ENTER, Sequence_Enter);
|
|
sb.AddAction(SEQ_CHECK_INIT_CONDITION, CheckInitCondition);
|
|
sb.AddDecision(SEQ_CHECK_LINE_COUNT, CheckLineCount);
|
|
sb.AddAction(SEQ_Z_AXIS_MOVE, ZAxisMove);
|
|
sb.AddAction(SEQ_ACS_PARAMETER_SET, AcsParameterSetting);
|
|
sb.AddAction(SEQ_WELDING_MOTION, WeldingMotion);
|
|
|
|
sb.AddAction(SEQ_MOTION_INTERLOCK, MotionInterlock);
|
|
sb.AddAction(SEQ_LINE_PROCESS_COMPLETE, LineProcessComplete);
|
|
|
|
sb.OnStopped(OnStopped);
|
|
sb.OnForceError(OnForceError);
|
|
|
|
sb.Flows(sb.Init > sb[SEQ_ENTER] > sb[SEQ_CHECK_INIT_CONDITION] > sb[SEQ_CHECK_LINE_COUNT]);
|
|
|
|
sb.Flows(sb[SEQ_CHECK_LINE_COUNT] > sb[SEQ_Z_AXIS_MOVE] > sb[SEQ_ACS_PARAMETER_SET] > sb[SEQ_WELDING_MOTION] > sb[SEQ_CHECK_LINE_COUNT]);
|
|
|
|
sb.Flows(sb[SEQ_CHECK_LINE_COUNT] > sb[SEQ_MOTION_INTERLOCK] > sb[SEQ_LINE_PROCESS_COMPLETE] > sb.Final);
|
|
|
|
//sb.Draw("SplitLineSequence.pdf");
|
|
|
|
return sb;
|
|
}
|
|
|
|
private static SequenceActionResult Sequence_Enter(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
context.RetryUntilSuccess(() => true, 1000 * 100, 100);
|
|
//_data = (ObservableCollection<LineShotItem>)param.Param;
|
|
_manual = (ManualLaserSetting)param.Param;
|
|
_data = _manual.Lines;
|
|
_LaserIOUse = _manual.LaserIOUse;
|
|
|
|
if (_acsMotion is null)
|
|
_acsMotion = _acs = context.Devices[CommonDeviceIds.ACS] as ScannerACS;
|
|
|
|
//if (_laser is null)
|
|
// _laser = context.Devices[CommonDeviceIds.Laser] as Laser;
|
|
// _laserCore = _laser.getCore() as LaserTruFiber;
|
|
// _laserCal = context.Settings[CommonSettingIds.LaserPowerCalParam] as LaserPowerCalParam;
|
|
|
|
//if (_io is null)
|
|
// _io = context.Devices[DeviceIds.IODevice] as PrismaticGunACSIO;
|
|
|
|
if (_setting is null)
|
|
_setting = context.Settings[CommonSettingIds.TeachingPos] as TeachingPositionSetting;
|
|
|
|
//if (_stage == eStage.A)
|
|
// _AxisX = context.Devices[MotorIds.ALineX] as ACSMotor;
|
|
//else
|
|
// _AxisX = context.Devices[MotorIds.BLineX] as ACSMotor;
|
|
|
|
//if (_stage == eStage.A)
|
|
// _AxisY = context.Devices[MotorIds.ALineY] as ACSMotor;
|
|
//else
|
|
// _AxisY = context.Devices[MotorIds.BLineY] as ACSMotor;
|
|
|
|
LineInLinesCount = _data.Count;
|
|
LineInLinesIndex = 0;
|
|
_laserCal = context.Settings[CommonSettingIds.LaserPowerCalParam] as LaserPowerCalParam;
|
|
|
|
_AxisX = context.Devices[CommonMotorIds.AxisX2] as ACSMotor;
|
|
_AxisZ = context.Devices[CommonMotorIds.AxisZ] as ACSMotor;
|
|
if (_data[LineInLinesIndex].YAxisType == (int)eYAxisType.Y1) {
|
|
_AxisY = context.Devices[CommonMotorIds.AxisY1] as ACSMotor;
|
|
_acsMotion.SetWeldingAxes((int)CommonMotorIds.eMotorIdx.AxisX2, (int)CommonMotorIds.eMotorIdx.AxisY1);
|
|
}
|
|
else {
|
|
_AxisY = context.Devices[CommonMotorIds.AxisY2] as ACSMotor;
|
|
_acsMotion.SetWeldingAxes((int)CommonMotorIds.eMotorIdx.AxisX2, (int)CommonMotorIds.eMotorIdx.AxisY2);
|
|
}
|
|
|
|
|
|
if (Status.EquipmentStatus == eEqpStatus.Manual)
|
|
_spd = AuroraACS.Speed.M;
|
|
else
|
|
_spd = AuroraACS.Speed.H;
|
|
|
|
Thread.Sleep(SLEEP_TIME_MS);
|
|
Log.V(">> SeqSplitLIne - Start");
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private static SequenceActionResult CheckInitCondition(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
if (!_AxisX.IsActivated) {
|
|
//context.PutValue<int>("AlarmCode", AlarmCode_PrismaticGun.DEVICE_STAGE_A_AXISX_DEACTIVATED); //26.04.13 잠시 주석
|
|
return null;
|
|
}
|
|
|
|
if (!_AxisY.IsActivated) {
|
|
//context.PutValue<int>("AlarmCode", AlarmCode_PrismaticGun.DEVICE_STAGE_A_AXISY_DEACTIVATED); //26.04.13 잠시 주석
|
|
return null;
|
|
}
|
|
|
|
if (!((_acsMotion as ScannerACS).IsActivated)) {
|
|
Log.E($"[ACS activated({(_acsMotion as ScannerACS).IsActivated})]");
|
|
//context.PutValue<int>("AlarmCode", AlarmCode_PrismaticGun.STAGE_A_DEACTIVATED_DISCONNECTED); // 26.04.13 잠시 주석
|
|
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 (!(_io.IsActivated && _io.IsConnected())) {
|
|
// Log.E($"[IO activated({_io.IsActivated}) / connected({_io.IsConnected()})]");
|
|
// context.PutValue<int>("AlarmCode", AlarmCode_PrismaticGun.DEVICE_ACSIO_DEACTIVATED_DISCONNECTED);
|
|
// return null;
|
|
//}
|
|
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private static string CheckLineCount(SequenceContext context, string id, ICollection<string> branches, SequenceActionResult param)
|
|
{
|
|
if (LineInLinesCount > LineInLinesIndex){
|
|
Log.FuncV($">> LineShot Count ({LineInLinesIndex + 1} / {LineInLinesCount})");
|
|
return SEQ_Z_AXIS_MOVE;
|
|
}
|
|
|
|
Thread.Sleep(SLEEP_TIME_MS);
|
|
return SEQ_MOTION_INTERLOCK;
|
|
}
|
|
private static SequenceActionResult ZAxisMove(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
_acsMotion.SetLaserIOUse(_LaserIOUse);
|
|
var _zPos = _data[LineInLinesIndex].PositionZ;
|
|
|
|
if (_AxisZ.IsReachedTargetPosition(_zPos))
|
|
{
|
|
Log.V($"Already Z-Axis Process Position");
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
_AxisZ.SetTargetPos(_zPos, TargetPosType.ABS);
|
|
_AxisZ.SetMoveVelocityImm(_spd);
|
|
_AxisZ.AccelerationImm(_spd);
|
|
_AxisZ.DecelerationImm(_spd);
|
|
_AxisZ.JerkImm(_spd);
|
|
_AxisZ.Move();
|
|
Log.V($"Move Z Position : {_zPos}");
|
|
|
|
var res = context.RetryUntilSuccess(() => _AxisZ.IsReachedTargetPosition(_zPos), MOTION_TIMEOUT, MOTION_INTERVAL, true);
|
|
if (res == E2.TIMEOUT) {
|
|
Log.FuncE($"Z-Axis Move Timeout!");
|
|
//context.PutValue<int>("AlarmCode", AlarmCode_PrismaticGun.STAGE_A_Z_MOVE_TIMEOUT); // 26.04.13 잠시 주석
|
|
return null;
|
|
}
|
|
else if (res == E2.CANCELLED) {
|
|
Log.FuncE($"Z-Axis Move Cancel!");
|
|
context.PutValue<int>("AlarmCode", 0);
|
|
return null;
|
|
}
|
|
Log.V($"Move Z Position Complete :{_zPos}");
|
|
|
|
Log.V($"Z Move Complete");
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private static SequenceActionResult AcsParameterSetting(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
var LineData = _data;
|
|
LineData[LineInLinesIndex].State = "Working";
|
|
|
|
// 볼트 켈 정도를 가져오기 위해 10을 곱해서 검색한다
|
|
_laserCal.Initialize(_laserCal.PowerCalibrationCenterBeamCSVFile, _laserCal.PowerCalibrationRingBeamCSVFile);
|
|
var RealCoreVoltage = (_laserCal.CalibrateWattToMeasuredVoltage(_data[LineInLinesIndex].Core, (uint)LaserPowerCalibrationParam.beamMode.Center));
|
|
var RealRingVoltage = (_laserCal.CalibrateWattToMeasuredVoltage(_data[LineInLinesIndex].Ring, (uint)LaserPowerCalibrationParam.beamMode.Ring));
|
|
|
|
if (double.IsNaN(RealCoreVoltage) || RealCoreVoltage < 0.0)
|
|
RealCoreVoltage = 0.0;
|
|
if (double.IsNaN(RealRingVoltage) || RealRingVoltage < 0.0)
|
|
RealRingVoltage = 0.0;
|
|
|
|
var _startX = _data[LineInLinesIndex].StartX;
|
|
var _startY = _data[LineInLinesIndex].StartY;
|
|
var _endX = _data[LineInLinesIndex].EndX;
|
|
var _endY = _data[LineInLinesIndex].EndY;
|
|
|
|
if (_data[LineInLinesIndex].YAxisType == (int)eYAxisType.Y1) {
|
|
_startX += _manual.CamLaserPositionOffset.Y1UseOffsetX;
|
|
_startY -= _manual.CamLaserPositionOffset.Y1UseOffsetY;
|
|
_endX += _manual.CamLaserPositionOffset.Y1UseOffsetX;
|
|
_endY -= _manual.CamLaserPositionOffset.Y1UseOffsetY;
|
|
|
|
}
|
|
else {
|
|
_startX += _manual.CamLaserPositionOffset.Y2UseOffsetX;
|
|
_startY -= _manual.CamLaserPositionOffset.Y2UseOffsetY;
|
|
_endX += _manual.CamLaserPositionOffset.Y2UseOffsetX;
|
|
_endY -= _manual.CamLaserPositionOffset.Y2UseOffsetY;
|
|
}
|
|
|
|
var _velocity = _data[LineInLinesIndex].Velocity;
|
|
var _acc = _data[LineInLinesIndex].Acc;
|
|
|
|
//SetLineShot(double corePower, double ringPower, double startPosX, double endPosX, double startPosY, double endPosY, double velocity, double acc)
|
|
_acsMotion.SetLCILserOn(true);
|
|
_acsMotion.SetLineShot(RealCoreVoltage, RealRingVoltage, _startX, _endX, _startY, _endY, _velocity, _acc);
|
|
_acsMotion.SetLaserIOUse(_LaserIOUse);
|
|
|
|
//레이저 출력 셋팅 Jeongin
|
|
|
|
Log.V($"ACS Setting Complete");
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private static SequenceActionResult WeldingMotion(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
if (_acsMotion.LineShotStart())
|
|
Log.V($">> {LineInLinesIndex} LineShot Start");
|
|
|
|
Thread.Sleep(500);
|
|
var res = context.RetryUntilSuccess(() => _acsMotion.CheckLineShotComp(), SEQ_TIMEOUT, SEQ_CHECK_TIMER);
|
|
if (res == E2.TIMEOUT) {
|
|
Log.FuncV($">> {LineInLinesIndex} LineShot Fail");
|
|
return null;
|
|
} else if(res == E2.CANCELLED) {
|
|
Log.FuncV($">> {LineInLinesIndex} LineShot Cancel");
|
|
return null;
|
|
}
|
|
|
|
_data[LineInLinesIndex].State = "Done";
|
|
|
|
Log.V($"Laser Interlock Start");
|
|
_acsMotion.SetLCILserOn(false);
|
|
//ProcessManager.Instance.EnableLaserUse(true);
|
|
Log.FuncV($">> {LineInLinesIndex++} : LineShot Complete");
|
|
|
|
Thread.Sleep(SLEEP_TIME_MS);
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private static SequenceActionResult MotionInterlock(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
if (Status.EquipmentStatus == eEqpStatus.Manual) {
|
|
//_laserCore.LaserOff();
|
|
Log.I("Manual Laser Off");
|
|
}
|
|
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
|
|
private static SequenceActionResult LineProcessComplete(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
LineInLinesIndex = 0;
|
|
//ProcessManager.Instance.EnableLaserUse(true);
|
|
//_laser.LaserOff();
|
|
_acsMotion.SetLCILserOn(false);
|
|
Log.FuncV(">> All LineShot Complete");
|
|
MessageUtil.ShowSuccessToast(">> All LineShot Complete");
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private static void OnStopped(SequenceContext context)
|
|
{
|
|
LineInLinesIndex = 0;
|
|
//ProcessManager.Instance.EnableLaserUse(true);
|
|
//_laser.LaserOff();
|
|
_acsMotion.SetLCILserOn(false);
|
|
|
|
Log.FuncV(">> All LineShot Fail");
|
|
MessageUtil.ShowWarningToast(">> Sequence Stop");
|
|
return;
|
|
}
|
|
|
|
private static void OnForceError(SequenceContext context, string arg2)
|
|
{
|
|
LineInLinesIndex = 0;
|
|
//ProcessManager.Instance.EnableLaserUse(true);
|
|
//_laser.LaserOff();
|
|
_acsMotion.SetLCILserOn(false);
|
|
|
|
Log.FuncV(">> All LineShot Fail");
|
|
MessageUtil.ShowErrorToast(">> Sequence Fail");
|
|
return;
|
|
}
|
|
}
|
|
}
|