using Aurora; using Aurora.Api; using Aurora.Util.HislogPlus; using AuroraLaserScanner; using AuroraPLC; using ILSOS_CCW_H52A.Device; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Reactive.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using WeldingCommon; using WeldingCommon.Data; using static ILSOS_CCW_H52A.Device.PLCControllerCCWH52A; namespace ILSOS_CCW_H52A.Sequences.ProcessObjects { public class ProcessManager { private static ProcessManager _Instance; public static ProcessManager Instance { get { if (_Instance is null) { _Instance = new ProcessManager(); } return _Instance; } } private IAuroraEnvironment _env; private PLCControllerCCWH52A _plc; private ScannerCCWH52A _scanner; private bool usedAnalyzerLog = false; private readonly Logger _log = new Logger("ProcessManager"); public const double compensateEncoderReset = 0.015; // 엔코더 리셋 보상 각도 설정(70도/sec 기준 약 0.015도) public const int RotaryJigCount = 16; public const int RotaryMaxAngle = 360; public double DegreePerJig { get => RotaryMaxAngle / RotaryJigCount; } public double HalfDegreePerJig { get => DegreePerJig / 2; } //public ConcurrentQueue public void Init(IAuroraEnvironment env) { _env = env; _plc = _env.DeviceManager[DeviceIds.PLCDevice] as PLCControllerCCWH52A; _scanner = _env.DeviceManager[DeviceIds.Scanner] as ScannerCCWH52A; } public IEnumerable CheckRotaryState() { List rotaryStates = new List(); for (int i = 0; i < RotaryJigCount; i++) { var rotaryProcessState = _plc.ReadBit(eBitInput.PLC_USE_WELD_JIG_1 + i).data; rotaryStates.Add(rotaryProcessState); //if (rotaryProcessState == false) // _plc.ToggleBit(eBitInput.PLC_USE_WELD_JIG_1 + i, eBitOutput.PC_WELD_COMPLETE_1 + i); } if (usedAnalyzerLog) { StringBuilder sb = new StringBuilder(); rotaryStates.ForEach(x => sb.Append($"{x} ")); _log.D($"Check Rotary State : {sb.ToString()}"); } return rotaryStates; } public bool GetRotaryCanExist(int jigNo) { if (jigNo == 0) jigNo = 1; if (jigNo <= RotaryJigCount) return _plc.ReadBit(eBitInput.PLC_USE_WELD_JIG_1 + (jigNo - 1)).data; else return false; } /// /// Rotary의 현재 위치정보를 0~360로 전달함 /// public double GetRotaryCurrentPosition(bool isView360 = true) { try { double finalValue = Convert.ToDouble(_plc.ReadDWord(eWordInput.PLC_CURRENT_POS_1).data / 100_000f); finalValue += _scanner.Config.RotaryEncoderOffset; if (isView360) { if (RotaryMaxAngle <= finalValue) { while (RotaryMaxAngle <= finalValue) { finalValue -= RotaryMaxAngle; } } else if (finalValue < 0) { while (finalValue < 0) { finalValue += RotaryMaxAngle; } } } return finalValue; } catch { return -9999.9999; } } /// /// 중심 기준 가장 가까운 지그 번호(내림 연산) /// 내림 카운팅을 중심 기준 값 /// /// public int getCurrentJigNo() => (int)((GetRotaryCurrentPosition(isView360:true) + HalfDegreePerJig) / DegreePerJig) + 1; /// /// 360도 이상으로 준다고하면 Welding Count를 가져올 수 있음 2word = 2147483.647 / 3600 = 596 >> 596*16 = 9_536까지 카운팅 가능함 /// 내림 카운팅을 중심 기준 값 /// /// public int getWeldingCount() => (int)((GetRotaryCurrentPosition(isView360:false) + HalfDegreePerJig) / DegreePerJig); } }