123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using Aitex.Sorter.Common;
- using Venus_RT.Devices;
- using MECF.Framework.Common.Routine;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.SubstrateTrackings;
- using Venus_Core;
- using Aitex.Core.RT.Log;
- using Aitex.Core.Util;
- using Venus_RT.Modules.PMs;
- using MECF.Framework.Common.Schedulers;
- using System.Collections.Generic;
- namespace Venus_RT.Modules.TM
- {
- class MFPMPickRoutine : ModuleRoutineBase, IRoutine
- {
- private enum PickStep
- {
- WaitPMReady,
- PMPrepare,
- ArmExtend,
- DropDownWafer,
- ArmRetract,
- NotifyDone,
- }
- private readonly JetTM _JetTM;
- private readonly ITransferRobot _robot;
- private int _pickingTimeout = 120 * 1000;
- private ModuleName _targetModule;
- private PMEntity _pmModule;
- int _targetSlot;
- Hand _hand;
- public MFPMPickRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TM)
- {
- _JetTM = tm;
- _robot = robot;
- Name = "Pick from PM";
- }
- public RState Start(params object[] objs)
- {
- if (!_robot.IsHomed)
- {
- LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
- return RState.Failed;
- }
- var pickItem = (Queue<MoveItem>)objs[0];
- _targetModule = pickItem.Peek().SourceModule;
- _targetSlot = pickItem.Peek().SourceSlot;
- _hand = pickItem.Peek().RobotHand;
- if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
- {
- _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
- }
- else
- {
- LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for picking action");
- return RState.Failed;
- }
- if (WaferManager.Instance.CheckHasWafer(ModuleName.TM, (int)_hand))
- {
- LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as TM Robot Arm: {_hand} already has a wafer");
- return RState.Failed;
- }
- if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
- {
- LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as {_targetModule} Slot {_targetSlot} has no wafer");
- return RState.Failed;
- }
- var wafer = WaferManager.Instance.GetWafer(_targetModule, _targetSlot);
- LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TM, $"{wafer.WaferOrigin} will be move from {_targetModule} {_targetSlot + 1} to TM Robot {_hand}");
- Reset();
- _pickingTimeout = SC.GetValue<int>($"{Module}.PickTimeout") * 1000;
- return Runner.Start(Module, $"Pick from {_targetModule}");
- }
- public RState Monitor()
- {
- Runner.Wait((int)PickStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
- .Run((int)PickStep.PMPrepare, ModulePrepare, IsModulePrepareReady)
- .Run((int)PickStep.ArmExtend, ArmExtend, WaitRobotExtendDone)
- .Run((int)PickStep.DropDownWafer, NotifyPMPickWafer, WaitPMWaferDropDown)
- .Run((int)PickStep.ArmRetract, ArmRetract, WaitRobotRetractDone)
- .End((int)PickStep.NotifyDone, NotifyPMDone, _delay_50ms);
- return Runner.Status;
- }
- private bool ModulePrepare()
- {
- _pmModule.PostMsg(PMEntity.MSG.PreparePick);
- return true;
- }
- private bool IsModulePrepareReady()
- {
- return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick && _pmModule.IsSlitDoorOpen;
- }
- private bool ArmExtend()
- {
- return _robot.PickExtend(_targetModule, _targetSlot, _hand);
- }
- private bool ArmRetract()
- {
- return _robot.PickRetract(_targetModule, _targetSlot, _hand);
- }
- private bool WaitRobotExtendDone()
- {
- if (_robot.Status == RState.Running)
- {
- return false;
- }
- else if (_robot.Status == RState.End)
- {
- WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TM, (int)_hand);
- return true;
- }
- else
- {
- Runner.Stop($"TM Robot Pick Extend failed, {_robot.Status}");
- return true;
- }
- }
- private bool NotifyPMPickWafer()
- {
- _pmModule.PostMsg(PMEntity.MSG.DropDownWafer);
- return true;
- }
- private bool WaitPMWaferDropDown()
- {
- return _pmModule.Status == PMEntity.PMStatus.Exchange_Ready;
- }
- private bool WaitRobotRetractDone()
- {
- if (_robot.Status == RState.Running)
- {
- return false;
- }
- else if (_robot.Status == RState.End)
- {
- return true;
- }
- else
- {
- Runner.Stop($"TM Robot Pick Retract failed, {_robot.Status}");
- return true;
- }
- }
- private bool NotifyPMDone()
- {
- _pmModule.PostMsg(PMEntity.MSG.PickReady);
- return true;
- }
- public void Abort()
- {
- _robot.Halt();
- }
- }
- }
|