MFPickRoutine.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 MFPickRoutine : ModuleRoutineBase, IRoutine
  18. {
  19. private enum PickStep
  20. {
  21. WaitModuleReady,
  22. ModulePrepare,
  23. OpenSlitDoor,
  24. Picking,
  25. QueryAwc,
  26. CloseSlitDoor,
  27. NotifyDone,
  28. }
  29. private readonly JetTM _JetTM;
  30. private readonly ITransferRobot _robot;
  31. private int _pickingTimeout = 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 MFPickRoutine(JetTM tm, ITransferRobot robot) :base(ModuleName.TMRobot)
  39. {
  40. _JetTM = tm;
  41. _robot = robot;
  42. Name = "Pick";
  43. if (SC.GetValue<int>($"TM.QueryAWCOption") == 1 || 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 pickItem = (Queue<MoveItem>)objs[0];
  57. _targetModule = pickItem.Peek().SourceModule;
  58. _targetSlot = pickItem.Peek().SourceSlot;
  59. _hand = pickItem.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 picking action");
  67. return RState.Failed;
  68. }
  69. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_hand))
  70. {
  71. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as TM Robot Arm: {_hand} already has a wafer");
  72. return RState.Failed;
  73. }
  74. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  75. {
  76. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as {_targetModule} Slot {_targetSlot + 1} has no wafer");
  77. return RState.Failed;
  78. }
  79. Reset();
  80. _pickingTimeout = SC.GetValue<int>("TM.PickTimeout") * 1000;
  81. return Runner.Start(Module, $"Pick from {_targetModule}");
  82. }
  83. public RState Monitor()
  84. {
  85. Runner.Wait(PickStep.WaitModuleReady, () => _llModule.IsIdle, _delay_60s)
  86. .Run(PickStep.ModulePrepare, ModulePrepare, IsModulePrepareReady)
  87. .Run(PickStep.OpenSlitDoor, OpenSlitDoor, IsSlitDoorOpen)
  88. .Run(PickStep.Picking, Picking, WaitPickDone)
  89. .Run(PickStep.QueryAwc, QueryAwc, WaitQueryDoneAndRecord)
  90. .Run(PickStep.CloseSlitDoor, CloseSlitDoor, IsSlitDoorClosed)
  91. .End(PickStep.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 Picking()
  126. {
  127. return _robot.Pick(_targetModule, _targetSlot, _hand);
  128. }
  129. private bool WaitPickDone()
  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.TM, (int)_hand, _targetModule, _targetSlot);
  138. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  139. return true;
  140. }
  141. else
  142. {
  143. Runner.Stop($"TM Robot Picking failed, {_robot.Status}");
  144. return true;
  145. }
  146. }
  147. private bool QueryAwc()
  148. {
  149. if (!_queryAwc)
  150. return true;
  151. if (_robot.QueryAwc())
  152. return true;
  153. else
  154. return false;
  155. }
  156. private bool WaitQueryDoneAndRecord()
  157. {
  158. if (!_queryAwc)
  159. return true;
  160. if (_robot.Status == RState.Running)
  161. {
  162. return false;
  163. }
  164. else if (_robot.Status == RState.End)
  165. {
  166. //已经move后的数据
  167. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  168. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  169. //查询完毕 插入数据
  170. OffsetDataRecorder.RecordOffsetData(
  171. Guid.NewGuid().ToString(),
  172. _targetModule, _targetSlot,
  173. ModuleName.TMRobot, 0,
  174. _origin_module, _origin_slot,
  175. _hand, RobotArmPan.None,
  176. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  177. _starttime, DateTime.Now);
  178. return true;
  179. }
  180. else
  181. {
  182. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  183. return true;
  184. }
  185. }
  186. private bool NotifyLLDone()
  187. {
  188. _llModule.PostMsg(LLEntity.MSG.TM_Exchange_Ready);
  189. return true;
  190. }
  191. public void Abort()
  192. {
  193. _robot.Halt();
  194. }
  195. }
  196. }