123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using Aitex.Sorter.Common;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.SubstrateTrackings;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Venus_Core;
- using Venus_RT.Devices;
- using Venus_RT.Devices.PreAligner;
- using Venus_RT.Modules.PMs;
- using Venus_RT.Modules.VCE;
- namespace Venus_RT.Modules.TM.VenusEntity
- {
- public class SEMFPMRetractRoutine : ModuleRoutineBase, IRoutine
- {
- //进入Retract的步骤
- private enum RetractStep
- {
- ArmRetract,
- End,
- }
- private readonly HongHuTM _TM;
- private readonly ITransferRobot _robot;
- private bool _queryAwc;
- private IPreAlign _vpa;
- private ModuleName _targetModule;
- private PMEntity _pmModule;
- private VceEntity _vceModule;
- private int _targetSlot;
- private Hand _hand;
- private int _retractingTimeout = 120 * 1000;
- public SEMFPMRetractRoutine(HongHuTM honghutm, ITransferRobot robot, IPreAlign vpa) : base(ModuleName.TMRobot)
- {
- _TM = honghutm;
- _robot = robot;
- Name = "Retract to PM VCE VPA";
- _vpa = vpa;
- _queryAwc = false;
- }
- //开始执行
- public RState Start(params object[] objs)
- {
- //检查robot home
- if (!_robot.IsHomed)
- {
- LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
- return RState.Failed;
- }
- _targetModule = (ModuleName)objs[0];
- _targetSlot = (int)objs[1];
- _hand = (Hand)objs[2];
- //检查targetModule是否合法
- if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
- {
- _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
- //检查开关门状态
- if (_pmModule.IsSlitDoorClose)
- {
- LOG.Write(eEvent.ERR_TM, Module, $"{_targetModule} slit door closed, can not retract robot arm");
- return RState.Failed;
- }
- }
- else if (ModuleHelper.IsVCE(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
- {
- _vceModule = Singleton<RouteManager>.Instance.GetVCE(_targetModule);
- if (_vceModule.IsError)
- {
- LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} is Error! Please solve Error first!");
- return RState.Failed;
- }
- if (_targetSlot < 0)
- {
- LOG.Write(eEvent.ERR_TM, Module, $"VCE target slot cannot be {_targetSlot}. Please check it first.");
- return RState.Failed;
- }
- //检查槽位置
- if (_targetSlot != _vceModule.CurrentSlot)
- {
- LOG.Write(eEvent.ERR_TM, Module, $"VCE current slot is {_vceModule.CurrentSlot} ,cannot be {_targetSlot}. Please check it first.");
- return RState.Failed;
- }
- //检查开关门状态
- if (_TM.VCESlitDoorClosed)
- {
- LOG.Write(eEvent.ERR_TM, Module, $"{_targetModule} slit door closed, can not retract robot arm");
- return RState.Failed;
- }
- }
- else if (ModuleHelper.IsVPA(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
- {
- //LOG.Write(eEvent.ERR_TM, Module, $"{_targetModule}");
- }
- else
- {
- LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for retracting action");
- return RState.Failed;
- }
- //检查Robot和targetModule的wafer状态
- if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
- {
- if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_hand))
- {
- LOG.Write(eEvent.ERR_TM, Module, $"Both {_targetModule} and robot arm {_hand} have wafers");
- return RState.Failed;
- }
- if (_pmModule.LiftPinIsDown && ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
- {
- LOG.Write(eEvent.ERR_TM, Module, $"{_targetModule} has a wafer and Lift Pin is down, can not retract robot arm");
- return RState.Failed;
- }
- }
- Reset();
- _retractingTimeout = SC.GetValue<int>("TM.RetractTimeout") * 1000;
- return Runner.Start(Module, $"Retract to {_targetModule}");
- }
- //状态监控
- public RState Monitor()
- {
- Runner.Run(RetractStep.ArmRetract, ArmRetract, WaitRobotRetractDone)
- .End(RetractStep.End, NullFun, _delay_50ms);
- return Runner.Status;
- }
- private bool ArmRetract()
- {
- return _robot.PickRetract(_targetModule, _targetSlot, _hand);
- }
- private bool WaitRobotRetractDone()
- {
- if (_robot.Status == RState.Running)
- {
- return false;
- }
- else if (_robot.Status == RState.End)
- {
- return true;
- }
- else
- {
- Runner.Stop($"TM Robot Arm Retract failed, {_robot.Status}");
- return true;
- }
- }
- public void Abort()
- {
- _robot.Halt();
- }
- }
- }
|