MFPMPlaceRoutine.cs 14 KB

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