using Aitex.Core.RT.Device; using Aitex.Core.RT.Event; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using athosRT.Devices; using athosRT.FSM; using athosRT.tool; using MECF.Framework.Common.Equipment; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase; using MECF.Framework.RT.EquipmentLibrary.LogicUnits; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace athosRT.Modules.LPs { public class HomeRoutine : ModuleRoutineBase, FSM.IRoutine { int _timeout = -1; protected readonly ModuleName _chamber; private RobotBaseDevice _robot; private LoadPortBaseDevice _device = null; private string _reason = string.Empty; public HomeRoutine(ModuleName chamber, RobotBaseDevice robot) : base(chamber) { _chamber = chamber; _robot = robot; _timeout = 3000; } public void Abort() { } public RState Monitor() { Runner.Run(HomeStep.LoadportReset, LoadportReset, WaitLoadportReset, _timeout) .End(HomeStep.LoadportInit, LoadportInit, LoadportMotion, _timeout); //.Wait((int)HomeStep.LoadportMotion, LoadportMotion, _timeout) //.End((int)HomeStep.WaitLoadportMotion, WaitLoadportMotion, _timeout); return Runner.Status; } //private bool test1() //{ // Trace.WriteLine("ceshi"); // return true; //} public RState Start(params object[] objs) { Trace.WriteLine("执行home start"); _device = DEVICE.GetDevice(this._chamber.ToString()); string reason = string.Empty; if (SC.GetValue("System.LPRobotActionIntervene") && !this.CheckLoadportMotionInterlock()) { //EV.PostMessage(this._chamber.ToString(), EventEnum.HomeFailed, (object)reason); return RState.Failed; } if (_chamber == ModuleName.LP1) { if (DeviceModel.SensorRBNotExtendSIMF1 != null && DeviceModel.SensorRBNotExtendSIMF1.Value) LogObject.Info(GetName.GetCurrentName(), "robot Extend to LP1."); //EV.PostMessage(this._chamber.ToString(), EventEnum.DefaultWarning, (object)"robot Extend to LP1."); } else if (DeviceModel.SensorRBNotExtendSIMF2 != null && DeviceModel.SensorRBNotExtendSIMF2.Value) LogObject.Info(GetName.GetCurrentName(), "robot Extend to LP2."); //EV.PostMessage(this._chamber.ToString(), EventEnum.DefaultWarning, (object)"robot Extend to LP2."); Trace.WriteLine("执行home start结束"); return Runner.Start(ModuleName.LP1, "LP1"); } public bool LoadportReset(){ LogObject.Info("LP Home", "LoadportReset"); LogObject.Info("LP",$"{_device.Name} clear error"); bool flag = _device.LoadportReset(out _); Trace.WriteLine($"执行Home{flag}"); return flag; } public bool LoadportInit() => _device.Home(out _reason); public bool LoadportMotion() { Trace.WriteLine("LoadportMotion"); if (_device.CurrentState == LoadPortStateEnum.Error || !_device.IsReady()) { Trace.WriteLine("1" + Runner.Status + " 2" + _device.CurrentState + " 3" + _device.IsReady()); return false; } return true; } public bool WaitLoadportMotion() { Trace.WriteLine("WaitLoadportMotion"); return true; } public bool WaitLoadportReset() => _device.IsReady(); public enum HomeStep { LoadportReset, WaitLoadportReset, LoadportInit, LoadportMotion, WaitLoadportMotion } public bool CheckLoadportMotionInterlock() { if (_robot.RobotState != RobotStateEnum.Idle) { LogObject.Info("LP and robot", "robot非空闲状态"); return false; } if (_robot.IsReady()) { LogObject.Info("LP and robot", "robot准备好"); return true; } return false; //return true; } } }