MFPlaceRoutine.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 MECF.Framework.Common.Schedulers;
  12. using System.Collections.Generic;
  13. using System;
  14. using MECF.Framework.Common.DBCore;
  15. namespace Venus_RT.Modules.TM
  16. {
  17. class MFPlaceRoutine : ModuleRoutineBase, IRoutine
  18. {
  19. private enum PlaceStep
  20. {
  21. WaitModuleReady,
  22. ModulePrepare,
  23. OpenSlitDoor,
  24. Placing,
  25. QueryAwc,
  26. CloseSlitDoor,
  27. NotifyDone,
  28. }
  29. private readonly JetTM _JetTM;
  30. private readonly ITransferRobot _robot;
  31. private int _placingTimeout = 120 * 1000;
  32. private ModuleName _targetModule;
  33. private LLEntity _llModule;
  34. int _targetSlot;
  35. Hand _hand;
  36. private DateTime _starttime;
  37. public MFPlaceRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  38. {
  39. _JetTM = tm;
  40. _robot = robot;
  41. Name = "Place";
  42. }
  43. public RState Start(params object[] objs)
  44. {
  45. _starttime = DateTime.Now;
  46. if (!_robot.IsHomed)
  47. {
  48. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  49. return RState.Failed;
  50. }
  51. var placeItem = (Queue<MoveItem>)objs[0];
  52. _targetModule = placeItem.Peek().DestinationModule;
  53. _targetSlot = placeItem.Peek().DestinationSlot;
  54. _hand = placeItem.Peek().RobotHand;
  55. if (ModuleHelper.IsLoadLock(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  56. {
  57. _llModule = Singleton<RouteManager>.Instance.GetLL(_targetModule);
  58. }
  59. else
  60. {
  61. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for place action");
  62. return RState.Failed;
  63. }
  64. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_hand))
  65. {
  66. LOG.Write(eEvent.ERR_TM, Module, $"Cannot place as TM Robot Arm: {_hand} has no wafer");
  67. return RState.Failed;
  68. }
  69. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  70. {
  71. LOG.Write(eEvent.ERR_TM, Module, $"Cannot place as {_targetModule} Slot {_targetSlot + 1} already has a wafer");
  72. return RState.Failed;
  73. }
  74. Reset();
  75. _placingTimeout = SC.GetValue<int>($"TM.PlaceTimeout") * 1000;
  76. return Runner.Start(Module, $"Place to {_targetModule}");
  77. }
  78. public RState Monitor()
  79. {
  80. Runner.Wait((int)PlaceStep.WaitModuleReady, () => _llModule.IsIdle, _delay_60s)
  81. .Run((int)PlaceStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  82. .Run((int)PlaceStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen)
  83. .Run((int)PlaceStep.Placing, Placing, WaitPlaceDone)
  84. .Run((int)PlaceStep.QueryAwc, QueryAwc, WaitQueryDoneAndRecord)
  85. .Run((int)PlaceStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed)
  86. .End((int)PlaceStep.NotifyDone, NotifyLLDone, _delay_50ms);
  87. return Runner.Status;
  88. }
  89. private bool ModulePrepare()
  90. {
  91. _llModule.PostMsg(LLEntity.MSG.Prepare_TM);
  92. return true;
  93. }
  94. private bool IsModulePrepareReady()
  95. {
  96. return _llModule.Status == LLEntity.LLStatus.Ready_For_TM;
  97. }
  98. private bool OpenSlitDoor()
  99. {
  100. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  101. }
  102. private bool CloseSlitDoor()
  103. {
  104. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  105. }
  106. private bool IsSlitDoorOpen()
  107. {
  108. if (_targetModule == ModuleName.LLA)
  109. return _JetTM.IsLLASlitDoorOpen;
  110. else
  111. return _JetTM.IsLLBSlitDoorOpen;
  112. }
  113. private bool IsSlitDoorClosed()
  114. {
  115. if (_targetModule == ModuleName.LLA)
  116. return _JetTM.IsLLASlitDoorClosed;
  117. else
  118. return _JetTM.IsLLBSlitDoorClosed;
  119. }
  120. private bool Placing()
  121. {
  122. return _robot.Place(_targetModule, _targetSlot, _hand);
  123. }
  124. private bool WaitPlaceDone()
  125. {
  126. if (_robot.Status == RState.Running)
  127. {
  128. return false;
  129. }
  130. else if (_robot.Status == RState.End)
  131. {
  132. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  133. return true;
  134. }
  135. else
  136. {
  137. Runner.Stop($"TM Robot Place failed, {_robot.Status}");
  138. return true;
  139. }
  140. }
  141. private bool QueryAwc()
  142. {
  143. if (_robot.QueryAwc())
  144. return true;
  145. else
  146. return false;
  147. }
  148. private bool WaitQueryDoneAndRecord()
  149. {
  150. if (_robot.Status == RState.Running)
  151. {
  152. return false;
  153. }
  154. else if (_robot.Status == RState.End)
  155. {
  156. //已经move后的数据
  157. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  158. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  159. //查询完毕 插入数据
  160. OffsetDataRecorder.RecordOffsetData(
  161. Guid.NewGuid().ToString(),
  162. ModuleName.TMRobot, 0,
  163. _targetModule, _targetSlot,
  164. _origin_module, _origin_slot,
  165. _hand, RobotArmPan.None,
  166. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  167. _starttime, DateTime.Now);
  168. return true;
  169. }
  170. else
  171. {
  172. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  173. return true;
  174. }
  175. }
  176. private bool NotifyLLDone()
  177. {
  178. _llModule.PostMsg(LLEntity.MSG.TM_Exchange_Ready);
  179. return true;
  180. }
  181. public void Abort()
  182. {
  183. _robot.Halt();
  184. }
  185. }
  186. }