using System; using System.Collections.Generic; using System.Diagnostics; using Aitex.Core.Common; using Aitex.Core.RT.DataCenter; using Aitex.Core.RT.Device; using Aitex.Core.RT.Device.Unit; using Aitex.Core.RT.Event; using Aitex.Core.RT.Fsm; using Aitex.Core.RT.OperationCenter; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using Aitex.Core.Utilities; using Aitex.Sorter.Common; using MECF.Framework.Common.Alarms; using MECF.Framework.Common.Equipment; using MECF.Framework.Common.Event; using MECF.Framework.Common.Schedulers; using MECF.Framework.Common.SubstrateTrackings; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase; using FurnaceRT.Equipments.Systems; using FurnaceRT.Devices; using IoDoor = FurnaceRT.Devices.IoDoor; using Aitex.Core.Util; namespace FurnaceRT.Equipments.CarrierRobots { public partial class CarrierRobotModule { private List _triggeredAlarmList = new List(); private int _alarmNumber; public IoTrigger TrigActionCommand => _trigActionCommand; public RobotBaseDevice CarrierRobotDevice { get; set; } public IoBufferMotor BufferDevice { get; set; } private IoTrigger _trigAlarmReset; private IoTrigger _trigActionCommand; private IoAlarmSignal _alarmSignaRobotAlarm; private R_TRIG _alarmSignaRobotAlarmTrig = new R_TRIG(); public IoDoor DoorDevice { get; set; } public IoAlarmSignal AlarmSignaFOUPRobotTPStatusWarning { get; set; } private Dictionary _actionCommand; private Dictionary _actionCommandStocker; public void InitDevice() { CarrierRobotDevice = DEVICE.GetDevice($"{Module}"); BufferDevice = DEVICE.GetDevice($"PM1.BufferServo"); DoorDevice = DEVICE.GetDevice($"PM1.AGVDoor"); AlarmSignaFOUPRobotTPStatusWarning = DEVICE.GetDevice($"PM1.AlarmSignaFOUPRobotTPStatusWarning"); _alarmSignaRobotAlarm = DEVICE.GetDevice($"PM1.AlarmSignaFOUPRobotAlarm"); _trigAlarmReset = DEVICE.GetDevice($"PM1.TrigFOUPRobotAlarmReset"); _trigActionCommand = DEVICE.GetDevice($"PM1.TrigFOUPRobotActionCommand"); CarrierManager.Instance.SubscribeLocation(Module, 1, SC.GetValue("System.CassetteSlotCount")); WaferManager.Instance.SubscribeLocation(Module, SC.GetValue("System.CassetteSlotCount")); this.OnDeviceAlarmStateChanged += OnModuleDeviceAlarmStateChanged; CarrierRobotDevice.OnDeviceAlarmStateChanged += OnModuleDeviceAlarmStateChanged; _actionCommand = new Dictionary() { {"C01.Pick",1 }, {"C01.Place",2 }, {"C02.Pick",3 }, {"C02.Place",4 }, {"C03.Pick",5 }, {"C03.Place",6 }, {"C04.Pick",7 }, {"C04.Place",8 }, {"C05.Pick",9 }, {"C05.Place",10 }, {"C06.Pick",11 }, {"C06.Place",12 }, {"C07.Pick",13 }, {"C07.Place",14 }, {"C08.Pick",15 }, {"C08.Place",16 }, {"C09.Pick",17 }, {"C09.Place",18 }, {"C10.Pick",19 }, {"C10.Place",20 }, {"C11.Pick",21 }, {"C11.Place",22 }, {"C12.Pick",23 }, {"C12.Place",24 }, }; _actionCommandStocker = new Dictionary() { {"Stocker1.Pick",171 }, {"Stocker1.Place",181 }, {"Stocker2.Pick",172 }, {"Stocker2.Place",182 }, {"Stocker3.Pick",173 }, {"Stocker3.Place",183 }, {"Stocker4.Pick",174 }, {"Stocker4.Place",184 }, {"Stocker5.Pick",191 }, {"Stocker5.Place",201 }, {"Stocker6.Pick",192 }, {"Stocker6.Place",202 }, {"Stocker7.Pick",193 }, {"Stocker7.Place",203 }, {"Stocker8.Pick",194 }, {"Stocker8.Place",204 }, {"Stocker9.Pick",211 }, {"Stocker9.Place",221 }, {"Stocker10.Pick",212 }, {"Stocker10.Place",222 }, {"Stocker11.Pick",213 }, {"Stocker11.Place",223 }, {"Stocker12.Pick",214 }, {"Stocker12.Place",224 }, {"Stocker13.Pick",231 }, {"Stocker13.Place",241 }, {"Stocker14.Pick",232 }, {"Stocker14.Place",242 }, {"Stocker15.Pick",233 }, {"Stocker15.Place",243 }, {"Stocker16.Pick",234 }, {"Stocker16.Place",244 }, }; } public void OnModuleDeviceAlarmStateChanged(string deviceId, AlarmEventItem alarmItem) { if (alarmItem.IsTriggered) { EventLevel level = alarmItem.Level; _triggeredAlarmList.Add(alarmItem); if (level == EventLevel.Alarm) { try { EV.PostAlarmLog(Module, alarmItem); } catch (Exception ex) { EV.WriteEvent(ex.Message.ToString()); } } else { EV.PostWarningLog(Module, alarmItem); } } else { } } public void SetCassetteRobotReset() { CarrierRobotDevice.RobotReset(); } public bool SetCassetteRobotHome(out string reason) { reason = string.Empty; return CarrierRobotDevice.HomeModule(null); } public bool SetSpeed(int speed, out string reason) { reason = string.Empty; return CarrierRobotDevice.SetSpeed("SetSpeed", speed); } public bool RequestCassettePresent(Hand hand, out string reason) { reason = string.Empty; RobotArmEnum arm = hand == Hand.Blade1 ? RobotArmEnum.Blade1 : RobotArmEnum.Blade2; List paras = new List() { "CurrentStatus", arm }; return CarrierRobotDevice.ReadParameter(paras.ToArray()); } public bool RobotPick(ModuleName target, int targetSlot, Hand hand, out string reason) { reason = string.Empty; RobotArmEnum arm = hand == Hand.Blade1 ? RobotArmEnum.Blade1 : RobotArmEnum.Both; return CarrierRobotDevice.Pick(arm, target.ToString(), targetSlot); } public bool RobotPlace(ModuleName target, int targetSlot, Hand hand, out string reason) { reason = string.Empty; RobotArmEnum arm = hand == Hand.Blade1 ? RobotArmEnum.Blade1 : RobotArmEnum.Both; return CarrierRobotDevice.Place(arm, target.ToString(), targetSlot); } public bool RobotGoto(ModuleName target, int targetSlot, Hand hand, bool isPickReady, out string reason) { reason = string.Empty; RobotArmEnum arm = hand == Hand.Blade1 ? RobotArmEnum.Blade1 : RobotArmEnum.Blade2; List paras = new List() { arm, target, targetSlot, isPickReady ? "PickReady" : "PlaceReady" }; return CarrierRobotDevice.GoTo(paras.ToArray()); } public void Stop() { CarrierRobotDevice.Stop(); } public void SetBufferTargetPosition(string module) { int.TryParse(module.Replace("Stocker", ""), out int target); BufferDevice.SetServoTargetPosition(target); } public bool SetBufferMoveTo() { return BufferDevice.SetServoMoveTo(); } public bool CheckBufferTargetPosition(string module) { int.TryParse(module.Replace("Stocker", ""), out int target); return (int)(BufferDevice.ServoMovePositionSet + 0.00001) == target && BufferDevice.TargetPositionFb == target; } public void SetRobotActionCommand(ModuleName traget, EnumTransferType transferType) { if (!CarrierRobotDevice.ModuleAssociateStationDic.ContainsKey(traget.ToString())) return; if (_actionCommandStocker.ContainsKey($"{traget}.{transferType}")) { //Stocker相关工位 _trigActionCommand.SetAOTrigger(_actionCommandStocker[$"{traget}.{transferType}"], out _); return; } var station = CarrierRobotDevice.ModuleAssociateStationDic[traget.ToString()]; if (!_actionCommand.ContainsKey($"{station}.{transferType}")) return; _trigActionCommand.SetAOTrigger(_actionCommand[$"{station}.{transferType}"], out _); } public bool CheckRobotActionCommand(ModuleName traget, EnumTransferType transferType) { if (!CarrierRobotDevice.ModuleAssociateStationDic.ContainsKey(traget.ToString())) return false; if (_actionCommandStocker.ContainsKey($"{traget}.{transferType}")) { //Stocker相关工位 return Math.Abs(_trigActionCommand.AIValue - _actionCommandStocker[$"{traget}.{transferType}"]) < 0.001; } var station = CarrierRobotDevice.ModuleAssociateStationDic[traget.ToString()]; if (!_actionCommand.ContainsKey($"{station}.{transferType}")) return false; return Math.Abs(_trigActionCommand.AIValue - _actionCommand[$"{station}.{transferType}"]) < 0.001; } public void ResetRobotActionCommand() { _trigActionCommand?.SetAOTrigger(0, out _); } } }