MFPlaceRoutine.cs 7.0 KB

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