SEMFPMSwapRoutine.cs 9.9 KB

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