MFPMPlaceRoutine.cs 12 KB

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