MFPMPlaceRoutine.cs 12 KB

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