MFPMPlaceRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. using Aitex.Core.RT.Routine;
  2. using Aitex.Core.RT.SCCore;
  3. using Aitex.Sorter.Common;
  4. using Venus_RT.Devices;
  5. using MECF.Framework.Common.Routine;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.SubstrateTrackings;
  8. using Venus_Core;
  9. using Aitex.Core.RT.Log;
  10. using Aitex.Core.Util;
  11. using Venus_RT.Modules.PMs;
  12. using MECF.Framework.Common.Schedulers;
  13. using System.Collections.Generic;
  14. using MECF.Framework.Common.DBCore;
  15. using System;
  16. namespace Venus_RT.Modules.TM
  17. {
  18. class MFPMPlaceRoutine : ModuleRoutineBase, IRoutine
  19. {
  20. private enum PlaceStep
  21. {
  22. WaitPMReady,
  23. PreRotation,
  24. PMPrepare,
  25. ArmExtend,
  26. QueryAWC,
  27. LiftUpWafer,
  28. PlaceDelay,
  29. ArmRetract,
  30. SavePlaceData,
  31. NotifyDone,
  32. }
  33. private enum PlaceWithHeaterStep
  34. {
  35. WaitPMReady,
  36. PreRotation,
  37. PMPrepare,
  38. Placing,
  39. QueryAWC,
  40. SavePlaceData,
  41. NotifyDone,
  42. }
  43. private readonly JetTM _JetTM;
  44. private readonly ITransferRobot _robot;
  45. private int _placingTimeout = 120 * 1000;
  46. private int _placeDelayTime = 0;
  47. private ModuleName _targetModule;
  48. private PMEntity _pmModule;
  49. private int _targetSlot;
  50. private Hand _hand;
  51. private DateTime _starttime;
  52. private bool _queryAwc;
  53. public MFPMPlaceRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  54. {
  55. _JetTM = tm;
  56. _robot = robot;
  57. Name = "Place to PM";
  58. if (SC.GetValue<int>($"TM.QueryAWCOption") == 2 || SC.GetValue<int>($"TM.QueryAWCOption") == 3)
  59. _queryAwc = true;
  60. else
  61. _queryAwc = false;
  62. }
  63. public RState Start(params object[] objs)
  64. {
  65. _starttime = DateTime.Now;
  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 placeItem = (Queue<MoveItem>)objs[0];
  72. _targetModule = placeItem.Peek().DestinationModule;
  73. _targetSlot = placeItem.Peek().DestinationSlot;
  74. _hand = placeItem.Peek().RobotHand;
  75. if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  76. {
  77. _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
  78. }
  79. else
  80. {
  81. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for placing action");
  82. return RState.Failed;
  83. }
  84. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_hand))
  85. {
  86. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Place as TM Robot Arm: {_hand} has no wafer");
  87. return RState.Failed;
  88. }
  89. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  90. {
  91. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Place as {_targetModule} Slot {_targetSlot + 1} already has a wafer");
  92. return RState.Failed;
  93. }
  94. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)_hand);
  95. LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"{wafer.WaferOrigin} will be move from TM Robot {_hand} to {_targetModule} {_targetSlot + 1}");
  96. Reset();
  97. _placingTimeout = SC.GetValue<int>("TM.PlaceTimeout") * 1000;
  98. _placeDelayTime = SC.GetValue<int>($"{_targetModule}.PlaceDelayTime");
  99. return Runner.Start(Module, $"Place to {_targetModule}");
  100. }
  101. public RState Monitor()
  102. {
  103. switch (_pmModule.ChamberType)
  104. {
  105. case JetChamber.Venus:
  106. case JetChamber.Kepler2300:
  107. Runner.Wait(PlaceStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  108. .RunIf(PlaceStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  109. .Run(PlaceStep.PMPrepare, ModulePrepare, IsModulePrepareReady, _delay_60s)
  110. .Run(PlaceStep.ArmExtend, ArmExtend, WaitRobotExtendDone, _placingTimeout)
  111. .Run(PlaceStep.QueryAWC, QueryAWC, WaitRobotQueryDone, _delay_1s)
  112. .Run(PlaceStep.LiftUpWafer, NotifyPMPlaceWafer, WaitPMWaferLiftUp, _delay_30s)
  113. .Delay(PlaceStep.PlaceDelay, _placeDelayTime)
  114. .Run(PlaceStep.ArmRetract, ArmRetract, WaitRobotRetractDone, _delay_30s)
  115. .Run(PlaceStep.SavePlaceData, RecordAWCData, NullFun)
  116. .End(PlaceStep.NotifyDone, NotifyPMDone, _delay_50ms);
  117. break;
  118. case JetChamber.Kepler2200A:
  119. Runner.Wait(PlaceWithHeaterStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  120. .RunIf(PlaceWithHeaterStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  121. .Run(PlaceWithHeaterStep.PMPrepare, ModulePrepare, IsModulePrepareReady, _delay_60s)
  122. .Run(PlaceWithHeaterStep.Placing, Placing, WaitPlaceDone)
  123. .Run(PlaceWithHeaterStep.QueryAWC, QueryAWC, WaitRobotQueryDone, _delay_1s)
  124. .Run(PlaceWithHeaterStep.SavePlaceData, RecordAWCData, NullFun)
  125. .End(PlaceWithHeaterStep.NotifyDone, NotifyPMDone, _delay_50ms);
  126. break;
  127. }
  128. return Runner.Status;
  129. }
  130. private bool ModulePrepare()
  131. {
  132. _pmModule.PostMsg(PMEntity.MSG.PreparePlace);
  133. return true;
  134. }
  135. private bool IsModulePrepareReady()
  136. {
  137. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place && _pmModule.IsSlitDoorOpen;
  138. }
  139. private bool RotateArm()
  140. {
  141. _pmModule.PostMsg(PMEntity.MSG.PreparePlace); // Notify PM to Serv pressure in advance for throughput enhancement
  142. return _robot.Goto(_JetTM.PreRotateModules[_targetModule], 0, _hand);
  143. }
  144. private bool WaitRotateDone()
  145. {
  146. if (_robot.Status == RState.Running)
  147. {
  148. return false;
  149. }
  150. else if (_robot.Status == RState.End)
  151. {
  152. return true;
  153. }
  154. else
  155. {
  156. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  157. return true;
  158. }
  159. }
  160. private bool Placing()
  161. {
  162. return _robot.Place(_targetModule, _targetSlot, _hand);
  163. }
  164. private bool WaitPlaceDone()
  165. {
  166. if (_robot.Status == RState.Running)
  167. {
  168. return false;
  169. }
  170. else if (_robot.Status == RState.End)
  171. {
  172. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  173. return true;
  174. }
  175. else
  176. {
  177. Runner.Stop($"TM Robot Place failed, {_robot.Status}");
  178. return true;
  179. }
  180. }
  181. private bool ArmExtend()
  182. {
  183. return _robot.PlaceExtend(_targetModule, _targetSlot, _hand);
  184. }
  185. private bool ArmRetract()
  186. {
  187. return _robot.PlaceRetract(_targetModule, _targetSlot, _hand);
  188. }
  189. private bool QueryAWC()
  190. {
  191. if (!_queryAwc)
  192. return true;
  193. else
  194. return _robot.QueryAwc();
  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. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  205. return true;
  206. }
  207. else
  208. {
  209. Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}");
  210. return true;
  211. }
  212. }
  213. private bool RecordAWCData()
  214. {
  215. if(!_queryAwc)
  216. return true;
  217. //已经move后的数据
  218. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  219. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  220. //查询完毕 插入数据
  221. OffsetDataRecorder.RecordOffsetData(
  222. Guid.NewGuid().ToString(),
  223. ModuleName.TMRobot, 0,
  224. _targetModule, _targetSlot,
  225. _origin_module, _origin_slot,
  226. _hand, RobotArmPan.None,
  227. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  228. _starttime, DateTime.Now);
  229. return true;
  230. }
  231. private bool WaitRobotQueryDone()
  232. {
  233. if (!_queryAwc)
  234. return true;
  235. if (_robot.Status == RState.Running)
  236. {
  237. return false;
  238. }
  239. else if (_robot.Status == RState.End)
  240. {
  241. return true;
  242. }
  243. else
  244. {
  245. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  246. return true;
  247. }
  248. }
  249. private bool NotifyPMPlaceWafer()
  250. {
  251. _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
  252. return true;
  253. }
  254. private bool WaitPMWaferLiftUp()
  255. {
  256. return _pmModule.Status == PMEntity.PMStatus.Exchange_Ready;
  257. }
  258. private bool WaitRobotRetractDone()
  259. {
  260. if (_robot.Status == RState.Running)
  261. {
  262. return false;
  263. }
  264. else if (_robot.Status == RState.End)
  265. {
  266. return true;
  267. }
  268. else
  269. {
  270. Runner.Stop($"TM Robot Place Retract failed, {_robot.Status}");
  271. return true;
  272. }
  273. }
  274. private bool NotifyPMDone()
  275. {
  276. _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
  277. return true;
  278. }
  279. public void Abort()
  280. {
  281. _robot.Halt();
  282. }
  283. }
  284. }