MFPMPlaceRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. case JetChamber.Kepler2200B:
  120. Runner.Wait(PlaceWithHeaterStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  121. .RunIf(PlaceWithHeaterStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  122. .Run(PlaceWithHeaterStep.PMPrepare, ModulePrepare, IsModulePrepareReady, _delay_60s)
  123. .Run(PlaceWithHeaterStep.Placing, Placing, WaitPlaceDone)
  124. .Run(PlaceWithHeaterStep.QueryAWC, QueryAWC, WaitRobotQueryDone, _delay_1s)
  125. .Run(PlaceWithHeaterStep.SavePlaceData, RecordAWCData, NullFun)
  126. .End(PlaceWithHeaterStep.NotifyDone, NotifyPMDone, _delay_50ms);
  127. break;
  128. }
  129. return Runner.Status;
  130. }
  131. private bool ModulePrepare()
  132. {
  133. _pmModule.PostMsg(PMEntity.MSG.PreparePlace);
  134. return true;
  135. }
  136. private bool IsModulePrepareReady()
  137. {
  138. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place && _pmModule.IsSlitDoorOpen;
  139. }
  140. private bool RotateArm()
  141. {
  142. _pmModule.PostMsg(PMEntity.MSG.PreparePlace); // Notify PM to Serv pressure in advance for throughput enhancement
  143. return _robot.Goto(_JetTM.PreRotateModules[_targetModule], 0, _hand);
  144. }
  145. private bool WaitRotateDone()
  146. {
  147. if (_robot.Status == RState.Running)
  148. {
  149. return false;
  150. }
  151. else if (_robot.Status == RState.End)
  152. {
  153. return true;
  154. }
  155. else
  156. {
  157. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  158. return true;
  159. }
  160. }
  161. private bool Placing()
  162. {
  163. return _robot.Place(_targetModule, _targetSlot, _hand);
  164. }
  165. private bool WaitPlaceDone()
  166. {
  167. if (_robot.Status == RState.Running)
  168. {
  169. return false;
  170. }
  171. else if (_robot.Status == RState.End)
  172. {
  173. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  174. return true;
  175. }
  176. else
  177. {
  178. Runner.Stop($"TM Robot Place failed, {_robot.Status}");
  179. return true;
  180. }
  181. }
  182. private bool ArmExtend()
  183. {
  184. return _robot.PlaceExtend(_targetModule, _targetSlot, _hand);
  185. }
  186. private bool ArmRetract()
  187. {
  188. return _robot.PlaceRetract(_targetModule, _targetSlot, _hand);
  189. }
  190. private bool QueryAWC()
  191. {
  192. if (!_queryAwc)
  193. return true;
  194. else
  195. return _robot.QueryAwc();
  196. }
  197. private bool WaitRobotExtendDone()
  198. {
  199. if (_robot.Status == RState.Running)
  200. {
  201. return false;
  202. }
  203. else if (_robot.Status == RState.End)
  204. {
  205. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  206. return true;
  207. }
  208. else
  209. {
  210. Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}");
  211. return true;
  212. }
  213. }
  214. private bool RecordAWCData()
  215. {
  216. if(!_queryAwc)
  217. return true;
  218. //已经move后的数据
  219. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  220. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  221. //查询完毕 插入数据
  222. OffsetDataRecorder.RecordOffsetData(
  223. Guid.NewGuid().ToString(),
  224. ModuleName.TMRobot, 0,
  225. _targetModule, _targetSlot,
  226. _origin_module, _origin_slot,
  227. _hand, RobotArmPan.None,
  228. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  229. _starttime, DateTime.Now);
  230. return true;
  231. }
  232. private bool WaitRobotQueryDone()
  233. {
  234. if (!_queryAwc)
  235. return true;
  236. if (_robot.Status == RState.Running)
  237. {
  238. return false;
  239. }
  240. else if (_robot.Status == RState.End)
  241. {
  242. return true;
  243. }
  244. else
  245. {
  246. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  247. return true;
  248. }
  249. }
  250. private bool NotifyPMPlaceWafer()
  251. {
  252. _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
  253. return true;
  254. }
  255. private bool WaitPMWaferLiftUp()
  256. {
  257. return _pmModule.Status == PMEntity.PMStatus.Exchange_Ready;
  258. }
  259. private bool WaitRobotRetractDone()
  260. {
  261. if (_robot.Status == RState.Running)
  262. {
  263. return false;
  264. }
  265. else if (_robot.Status == RState.End)
  266. {
  267. return true;
  268. }
  269. else
  270. {
  271. Runner.Stop($"TM Robot Place Retract failed, {_robot.Status}");
  272. return true;
  273. }
  274. }
  275. private bool NotifyPMDone()
  276. {
  277. _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
  278. return true;
  279. }
  280. public void Abort()
  281. {
  282. _robot.Halt();
  283. }
  284. }
  285. }