123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- using Aitex.Core.RT.DataCenter;
- 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.DBCore;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.Schedulers;
- using MECF.Framework.Common.SubstrateTrackings;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TMs;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using Venus_Core;
- using Venus_RT.Devices;
- using Venus_RT.Devices.TM;
- using Venus_RT.Modules.PMs;
- namespace Venus_RT.Modules.TM.VenusEntity
- {
- public class SEMFPMPlaceRoutine : ModuleRoutineBase, IRoutine
- {
- private enum PlaceStep
- {
- WaitPMReady,
- OpenMFSlitDoor,
- PMPrepare,
- ArmExtend,
- QueryAWC,
- LiftUpWafer,
- PlaceDelay,
- PlaceDelay1,
- PlaceDelay2,
- ArmRetract,
- SavePlaceData,
- NotifyDone,
- CloseDoor,
- EndDelay
- }
- private readonly TMBase _TM;
- private readonly ITransferRobot _robot;
- private int _ExtendTimeout = 120 * 1000;
- private int _RetractTimeout = 120 * 1000;
- private int _placeDelayTime = 0;
- private ModuleName _targetModule;
- private PMEntity _pmModule;
- private int _targetSlot;
- private Hand _hand;
- private DateTime _starttime;
- private bool _queryAwc;
- public SEMFPMPlaceRoutine(TMBase honghutm, ITransferRobot robot, ModuleName module) : base(module)
- {
- _TM = honghutm;
- _robot = robot;
- Name = "Place to PM";
- _queryAwc = false;
- }
- public RState Start(params object[] objs)
- {
- _starttime = DateTime.Now;
- if (!_robot.IsHomed)
- {
- LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
- return RState.Failed;
- }
- var placeItem = (Queue<MoveItem>)objs[0];
- _targetModule = placeItem.Peek().DestinationModule;
- _targetSlot = placeItem.Peek().DestinationSlot;
- _hand = placeItem.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 placing action");
- return RState.Failed;
- }
- if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_hand))
- {
- LOG.Write(eEvent.ERR_TM, Module, $"Cannot Place as TM Robot Arm: {_hand} has no wafer");
- return RState.Failed;
- }
- if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
- {
- LOG.Write(eEvent.ERR_TM, Module, $"Cannot Place as {_targetModule} Slot {_targetSlot + 1} already has a wafer");
- return RState.Failed;
- }
- var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)_hand);
- LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"{wafer.WaferOrigin} will be move from TM Robot {_hand} to {_targetModule} {_targetSlot + 1}");
- Reset();
- _ExtendTimeout = SC.GetValue<int>($"{Module}.ExtendTimeout") * 1000;
- _RetractTimeout = SC.GetValue<int>($"{Module}.RetractTimeout") * 1000;
- _placeDelayTime = SC.GetValue<int>($"{_targetModule}.PlaceDelayTime");
- return Runner.Start(Module, $"Place to {_targetModule}");
- }
- public RState Monitor()
- {
- Runner.Wait(PlaceStep.WaitPMReady, PMPrepare, _delay_60s)
- .Run(PlaceStep.OpenMFSlitDoor, OpenSlitDoor, CheckSlitDoorOpen)
- .Run(PlaceStep.PMPrepare, ModulePrepare, IsModulePrepareReady, _delay_60s)
- .Delay(PlaceStep.PlaceDelay, _placeDelayTime)
- .Run(PlaceStep.ArmExtend, ArmExtend, WaitRobotExtendDone, _ExtendTimeout)
- .Run(PlaceStep.QueryAWC, QueryAWC, WaitRobotQueryDone, _delay_1s)
- .Run(PlaceStep.LiftUpWafer, NotifyPMPlaceWafer, WaitPMWaferLiftUp, _delay_30s)
- .Delay(PlaceStep.PlaceDelay1, _placeDelayTime)
- .Run(PlaceStep.ArmRetract, ArmRetract, WaitRobotRetractDone, _RetractTimeout)
- .Run(PlaceStep.SavePlaceData, RecordAWCData, NullFun)
- .Run(PlaceStep.CloseDoor, PMDoorClose, WaitPMDoorClose)
- .Run(PlaceStep.NotifyDone, NotifyPMDone, _delay_50ms)
- .Delay(PlaceStep.PlaceDelay2, _delay_50ms)
- .End(PlaceStep.EndDelay, NullFun, _delay_50ms);
- return Runner.Status;
- }
- private bool PMPrepare()
- {
- return IsPressureReady(_targetModule) && _pmModule.IsIdle;
- }
- private bool IsPressureReady(ModuleName _targetModule)
- {
- if (RouteManager.IsATMMode)
- return true;
- if (_pmModule.IsOnline)
- {
- double PMPressure = _pmModule.ProcessPressure;
- double ControlPressure = SC.GetValue<int>($"{_targetModule}.ControlPressureSetPoint");
- double range = SC.GetValue<int>($"{_targetModule}.ControlPressureOffset");
- if ((PMPressure >= (ControlPressure - range)) && (PMPressure <= (ControlPressure + range)))
- {
- return true;
- }
- else return false;
- }else return true;
- }
- private bool OpenSlitDoor()
- {
- return _TM.TurnSlitDoor(_targetModule, true);
- }
- private bool CheckSlitDoorOpen()
- {
- return _TM.CheckSlitValveOpen(_targetModule);
- }
- private bool ModulePrepare()
- {
- _pmModule.PostMsg(PMEntity.MSG.PreparePlace);
- //_TM.TurnSlitDoor(_targetModule, true);
- return true;
- }
- private bool IsModulePrepareReady()
- {
- return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place && _pmModule.IsSlitDoorOpen;
- }
- private bool ArmExtend()
- {
- if (!_pmModule.IsSlitDoorOpen)
- {
- LOG.Write(eEvent.ERR_TM, Module, $"Cannot place as {_targetModule} Door is not Open");
- return false;
- }
- return _robot.PlaceExtend(_targetModule, _targetSlot, _hand);
- }
- private bool ArmRetract()
- {
- return _robot.PlaceRetract(_targetModule, _targetSlot, _hand);
- }
- private bool QueryAWC()
- {
- if (!_queryAwc)
- return true;
- else
- return _robot.QueryAwc();
- }
- private bool WaitRobotExtendDone()
- {
- if (_robot.Status == RState.Running)
- {
- return false;
- }
- else if (_robot.Status == RState.End)
- {
- return true;
- }
- else
- {
- Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}");
- Singleton<RouteManager>.Instance.GetPM(_targetModule).PostMsg(PMEntity.MSG.Error);
- return true;
- }
- }
- private bool RecordAWCData()
- {
- if (!_queryAwc)
- return true;
- //已经move后的数据
- string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
- int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
- //查询完毕 插入数据
- OffsetDataRecorder.RecordOffsetData(
- Guid.NewGuid().ToString(),
- ModuleName.TMRobot, 0,
- _targetModule, _targetSlot,
- _origin_module, _origin_slot,
- _hand, RobotArmPan.None,
- _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
- _starttime, DateTime.Now);
- return true;
- }
- private bool WaitRobotQueryDone()
- {
- if (!_queryAwc)
- return true;
- if (_robot.Status == RState.Running)
- {
- return false;
- }
- else if (_robot.Status == RState.End)
- {
- return true;
- }
- else
- {
- Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
- Singleton<RouteManager>.Instance.GetPM(_targetModule).PostMsg(PMEntity.MSG.Error);
- return true;
- }
- }
- private bool NotifyPMPlaceWafer()
- {
- _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
- return true;
- }
- private bool WaitPMWaferLiftUp()
- {
- return _pmModule.Status == PMEntity.PMStatus.Exchange_Ready;
- }
- private bool WaitRobotRetractDone()
- {
- if (_robot.Status == RState.Running)
- {
- return false;
- }
- else if (_robot.Status == RState.End)
- {
- WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
- return true;
- }
- else
- {
- Runner.Stop($"TM Robot Place Retract failed, {_robot.Status}");
- Singleton<RouteManager>.Instance.GetPM(_targetModule).PostMsg(PMEntity.MSG.Error);
- return true;
- }
- }
- private bool NotifyPMDone()
- {
- _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
- //_TM.TurnSlitDoor(_targetModule, false);
- return true;
- }
- private bool PMDoorClose()
- {
- //LOG.Write(eEvent.WARN_TM, Module, $"PMPlace Close Door Again");
- return _TM.TurnSlitDoor(_targetModule, false);
- }
- private bool WaitPMDoorClose()
- {
- if (_TM.CheckSlitValveClose(_targetModule))
- {
- //LOG.Write(eEvent.WARN_TM, Module, $"PMPlace Check Door Close");
- return true;
- }
- else
- {
- //LOG.Write(eEvent.WARN_TM, Module, $"PMPlace Check not Close Door");
- return false;
- }
- }
- public void Abort()
- {
- //_robot.Halt();
- }
- }
- }
|