SEMFPMSwapRoutine.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.Routine;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.Util;
  8. using Aitex.Sorter.Common;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.Schedulers;
  11. using MECF.Framework.Common.SubstrateTrackings;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Windows.Documents;
  18. using Venus_Core;
  19. using Venus_RT.Devices;
  20. using Venus_RT.Devices.TM;
  21. using Venus_RT.Modules.PMs;
  22. namespace Venus_RT.Modules.TM.VenusEntity
  23. {
  24. public class SEMFPMSwapRoutine : ModuleRoutineBase, IRoutine
  25. {
  26. private enum SwapStep
  27. {
  28. WaitPMReady,
  29. WaitforControlPressure,
  30. PreRotation,
  31. PickPrepare,
  32. PickExtend,
  33. DropDownWafer,
  34. PickDelay,
  35. PickRetract,
  36. PlacePrepare,
  37. PlaceExtend,
  38. LiftUpWafer,
  39. PlaceDelay,
  40. PlaceRetract,
  41. NotifyDone,
  42. EndDone,
  43. EndDelay
  44. }
  45. private readonly TMBase _TM;
  46. private readonly ITransferRobot _robot;
  47. private int _swapingTimeout = 120 * 1000;
  48. private int _placeDelayTime = 0;
  49. private int _pickDelayTime = 0;
  50. private ModuleName _targetModule;
  51. private PMEntity _pmModule;
  52. private int _targetSlot;
  53. private Hand _pickHand;
  54. private Hand _placeHand;
  55. private JetPMBase _chamber;
  56. private bool NeedControlPressure;
  57. private int _controlPressureSetPoint = 90;
  58. private int _controlFlowSetPoint = 90;
  59. public SEMFPMSwapRoutine(TMBase tm, ITransferRobot robot, ModuleName module) : base(module)
  60. {
  61. _TM = tm;
  62. _robot = robot;
  63. Name = "swap for pm";
  64. }
  65. public RState Start(params object[] objs)
  66. {
  67. if (!_robot.IsHomed)
  68. {
  69. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  70. return RState.Failed;
  71. }
  72. var swapItem = (Queue<MoveItem>)objs[0];
  73. _targetModule = swapItem.Peek().SourceModule;
  74. _targetSlot = swapItem.Peek().SourceSlot;
  75. _pickHand = swapItem.Peek().RobotHand;
  76. _placeHand = _pickHand == Hand.Blade2 ? Hand.Blade1 : Hand.Blade2;
  77. if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  78. {
  79. _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
  80. }
  81. else
  82. {
  83. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for swap action");
  84. return RState.Failed;
  85. }
  86. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_placeHand))
  87. {
  88. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as TM Robot Arm: {_placeHand} has no wafer");
  89. return RState.Failed;
  90. }
  91. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_pickHand))
  92. {
  93. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as TM Robot Arm: {_pickHand} has a wafer");
  94. return RState.Failed;
  95. }
  96. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  97. {
  98. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Swap Wafer as {_targetModule} Slot {_targetSlot + 1} has no wafer");
  99. return RState.Failed;
  100. }
  101. Reset();
  102. _swapingTimeout = SC.GetValue<int>($"{Module}.SwapTimeout") * 1000;
  103. _pickDelayTime = SC.GetValue<int>($"{_targetModule}.PickDelayTime");
  104. _placeDelayTime = SC.GetValue<int>($"{_targetModule}.PlaceDelayTime");
  105. if (Singleton<RouteManager>.Instance.GetPM(_targetModule).IsOnline)
  106. {
  107. NeedControlPressure = true;
  108. }
  109. else
  110. {
  111. NeedControlPressure = false;
  112. }
  113. return Runner.Start(Module, $"Swap with {_targetModule}");
  114. }
  115. public RState Monitor()
  116. {
  117. Runner.Wait(SwapStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  118. .RunIf(SwapStep.WaitforControlPressure, NeedControlPressure, StartControlPressure, IsPressureReady, _delay_60s)
  119. //.RunIf(SwapStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  120. .Run(SwapStep.PickPrepare, PickPrepare, IsModuleReadyForPick)
  121. .Run(SwapStep.PickExtend, PickExtend, WaitRobotExtendDone)
  122. .Run(SwapStep.DropDownWafer, NotifyPMPickWafer, WaitPMWaferDropDown)
  123. .Delay(SwapStep.PickDelay, _pickDelayTime)
  124. .Run(SwapStep.PickRetract, PickRetract, WaitRobotRetractDone)
  125. .Run(SwapStep.PlacePrepare, PlacePrepare, IsModuleReadyForPlace)
  126. .Run(SwapStep.PlaceExtend, PlaceExtend, WaitRobotExtendDone)
  127. .Run(SwapStep.LiftUpWafer, NotifyLiftUpWafer, WaitPMWaferLiftUp)
  128. .Delay(SwapStep.PlaceDelay, _placeDelayTime)
  129. .Run(SwapStep.PlaceRetract, PlaceRetract, WaitRobotRetractDone)
  130. .Run(SwapStep.NotifyDone, NotifyPMDone, _delay_50ms)
  131. .Delay(SwapStep.PlaceDelay, _delay_50ms)
  132. .Run(SwapStep.EndDone, CheckDoorClose, WaitPMDoorClose, 5000)
  133. .End(SwapStep.EndDelay, NullFun, _delay_50ms);
  134. return Runner.Status;
  135. }
  136. private bool StartControlPressure()
  137. {
  138. _chamber = DEVICE.GetDevice<JetPMBase>(_targetModule.ToString());
  139. _controlPressureSetPoint = SC.GetValue<int>($"{_targetModule}.ControlPressureSetPoint");
  140. _controlFlowSetPoint = SC.GetValue<int>($"{_targetModule}.ControlPressureN2FlowSetPoint");
  141. _chamber.StartControlPressure(_controlPressureSetPoint, _controlFlowSetPoint);
  142. return true;
  143. }
  144. private bool IsPressureReady()
  145. {
  146. double ControlPressure = SC.GetValue<int>($"{_targetModule}.ControlPressureSetPoint");
  147. //double PMPressure = Singleton<RouteManager>.Instance.GetPM(_targetModule).ChamberPressure;
  148. double PMPressure = (double)DATA.Poll($"{_targetModule}.ChamberPressure");
  149. double range = SC.GetValue<int>($"{_targetModule}.ControlPressureOffset");
  150. if ((PMPressure >= (ControlPressure - range)) && (PMPressure <= (ControlPressure + range)))
  151. {
  152. //LOG.Write(eEvent.WARN_DEFAULT_WARN, _targetModule, "current pmpressure" + PMPressure);
  153. //LOG.Write(eEvent.WARN_DEFAULT_WARN, _targetModule, "DATA current pmpressure" + DATA.Poll($"{_targetModule}.ChamberPressure"));
  154. //string reason = $"{Module} and TM pressure difference exceeds the max limit {maxPressureDifference}, TMPressure:{TMPressure}, {Module}Pressure:{PMPressure}";
  155. //LOG.Write(eEvent.ERR_DEVICE_INFO, Module, reason);
  156. return true;
  157. }
  158. else return false;
  159. }
  160. private bool PickPrepare()
  161. {
  162. _pmModule.PostMsg(PMEntity.MSG.PreparePick);
  163. //_TM.TurnSlitDoor(_targetModule, true);
  164. return true;
  165. }
  166. private bool PlacePrepare()
  167. {
  168. _pmModule.PostMsg(PMEntity.MSG.PreparePlace);
  169. //_TM.TurnSlitDoor(_targetModule, true);
  170. return true;
  171. }
  172. private bool IsModuleReadyForPick()
  173. {
  174. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick && _pmModule.IsSlitDoorOpen;
  175. }
  176. private bool PickExtend()
  177. {
  178. return _robot.PickExtend(_targetModule, _targetSlot, _pickHand);
  179. }
  180. private bool PickRetract()
  181. {
  182. return _robot.PickRetract(_targetModule, _targetSlot, _pickHand);
  183. }
  184. private bool IsModuleReadyForPlace()
  185. {
  186. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place && _pmModule.IsSlitDoorOpen;
  187. }
  188. private bool PlaceExtend()
  189. {
  190. return _robot.PlaceExtend(_targetModule, _targetSlot, _placeHand);
  191. }
  192. private bool PlaceRetract()
  193. {
  194. return _robot.PlaceRetract(_targetModule, _targetSlot, _placeHand);
  195. }
  196. private bool WaitRobotExtendDone()
  197. {
  198. if (_robot.Status == RState.Running)
  199. {
  200. return false;
  201. }
  202. else if (_robot.Status == RState.End)
  203. {
  204. return true;
  205. }
  206. else
  207. {
  208. Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}");
  209. Singleton<RouteManager>.Instance.GetPM(_targetModule).PostMsg(PMEntity.MSG.Error);
  210. return true;
  211. }
  212. }
  213. //private bool RotateArm()
  214. //{
  215. // _pmModule.PostMsg(PMEntity.MSG.PreparePick); // Notify PM to Serv pressure in advance for throughput enhancement
  216. // return _robot.Goto(_JetTM.PreRotateModules[_targetModule], 0, _placeHand);
  217. //}
  218. //private bool WaitRotateDone()
  219. //{
  220. // if (_robot.Status == RState.Running)
  221. // {
  222. // return false;
  223. // }
  224. // else if (_robot.Status == RState.End)
  225. // {
  226. // return true;
  227. // }
  228. // else
  229. // {
  230. // Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  231. // return true;
  232. // }
  233. //}
  234. private bool NotifyPMPickWafer()
  235. {
  236. _pmModule.PostMsg(PMEntity.MSG.DropDownWafer);
  237. return true;
  238. }
  239. private bool WaitPMWaferDropDown()
  240. {
  241. if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  242. {
  243. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_pickHand);
  244. return true;
  245. }
  246. return false;
  247. }
  248. private bool WaitRobotRetractDone()
  249. {
  250. if (_robot.Status == RState.Running)
  251. {
  252. return false;
  253. }
  254. else if (_robot.Status == RState.End)
  255. {
  256. return true;
  257. }
  258. else
  259. {
  260. Runner.Stop($"TM Robot Swap Retract failed, {_robot.Status}");
  261. Singleton<RouteManager>.Instance.GetPM(_targetModule).PostMsg(PMEntity.MSG.Error);
  262. return true;
  263. }
  264. }
  265. private bool NotifyLiftUpWafer()
  266. {
  267. _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
  268. return true;
  269. }
  270. private bool WaitPMWaferLiftUp()
  271. {
  272. if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  273. {
  274. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_placeHand, _targetModule, _targetSlot);
  275. return true;
  276. }
  277. return false;
  278. }
  279. private bool NotifyPMDone()
  280. {
  281. _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
  282. //_TM.TurnSlitDoor(_targetModule, false);
  283. return true;
  284. }
  285. private bool CheckDoorClose()
  286. {
  287. LOG.Write(eEvent.WARN_TM, Module, $"PMSwap Close Door Again");
  288. return _TM.TurnSlitDoor(_targetModule, false);
  289. }
  290. private bool WaitPMDoorClose()
  291. {
  292. if (_TM.CheckSlitValveClose(_targetModule))
  293. {
  294. LOG.Write(eEvent.WARN_TM, Module, $"PMSwap Check Door Close");
  295. return true;
  296. }
  297. else
  298. {
  299. if (DEVICE.GetDevice<IoCylinder>($"{Module}.{_targetModule}SlitDoor").SetPoint != (int)CylinderState.Close)
  300. {
  301. LOG.Write(eEvent.WARN_TM, Module, $"PMSwap {_targetModule}SlitDoor set close again");
  302. DEVICE.GetDevice<IoCylinder>($"{Module}.{_targetModule}SlitDoor").SetCylinder(false, out string reason);
  303. }
  304. //LOG.Write(eEvent.WARN_TM, Module, $"PMSwap Check not Close Door");
  305. return false;
  306. }
  307. }
  308. public void Abort()
  309. {
  310. _robot.Halt();
  311. }
  312. }
  313. }