SEMFPMSwapRoutine.cs 12 KB

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