choieigun 5b4a856a2e AutoRun Simulation 추가
- AutoRun은 수정 안함(들여쓰기 변경)
- Timer 기반 시뮬레이션
2026-02-21 02:34:10 +09:00

116 lines
4.1 KiB
C#

using Aurora;
using Aurora.Api;
using Aurora.Util.HislogPlus;
using AuroraLaserScanner;
using AuroraPLC;
using ILSOS_CCW_H52A.Device;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static ILSOS_CCW_H52A.Device.PLCControllerCCWH52A;
namespace ILSOS_CCW_H52A.Sequences
{
public class ProcessManager
{
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; }
private readonly IAuroraEnvironment _env;
private readonly PLCControllerCCWH52A _plc;
private readonly Scanner _scanner;
public ProcessManager()
{
_plc = _env.DeviceManager[DeviceIds.PLCDevice] as PLCControllerCCWH52A;
_scanner = _env.DeviceManager[DeviceIds.Scanner] as Scanner;
}
public IEnumerable<bool> CheckRotaryState()
{
List<bool> rotaryStates = new List<bool>();
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)
{
//var RotaryStates = CheckRotaryState();
if (jigNo == 0)
jigNo = 1;
if (jigNo <= RotaryJigCount)
return _plc.ReadBit(eBitInput.PLC_USE_WELD_JIG_1 + (jigNo - 1)).data;
else
return false;
}
/// <summary>
/// Rotary의 현재 위치정보를 0~360로 전달함
/// </summary>
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;
}
}
/// <summary>
/// 중심 기준 가장 가까운 지그 번호(내림 연산)
/// <param name="HalfDegreePerJig">내림 카운팅을 중심 기준 값</param>
/// </summary>
/// <returns></returns>
public int getCurrentJigNo() => (int)((GetRotaryCurrentPosition(isView360:true) + HalfDegreePerJig) / DegreePerJig) + 1;
/// <summary>
/// 360도 이상으로 준다고하면 Welding Count를 가져올 수 있음 2word = 2147483.647 / 3600 = 596 >> 596*16 = 9_536까지 카운팅 가능함
/// <param name="HalfDegreePerJig">내림 카운팅을 중심 기준 값</param>
/// </summary>
/// <returns></returns>
public int getWeldingCount() => (int)((GetRotaryCurrentPosition(isView360:false) + HalfDegreePerJig) / DegreePerJig);
}
}