MFPMPlaceRoutine.cs 13 KB

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