MFPMPickRoutine.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 System;
  15. using MECF.Framework.Common.DBCore;
  16. namespace Venus_RT.Modules.TM
  17. {
  18. class MFPMPickRoutine : ModuleRoutineBase, IRoutine
  19. {
  20. private enum PickStep
  21. {
  22. WaitPMReady,
  23. PMPrepare,
  24. ArmExtend,
  25. QueryAWC,
  26. DropDownWafer,
  27. PickDelay,
  28. ArmRetract,
  29. SavePickeData,
  30. NotifyDone,
  31. }
  32. private readonly JetTM _JetTM;
  33. private readonly ITransferRobot _robot;
  34. private int _pickingTimeout = 120 * 1000;
  35. private int _pickDelayTime = 0;
  36. private ModuleName _targetModule;
  37. private PMEntity _pmModule;
  38. private int _targetSlot;
  39. private Hand _hand;
  40. private DateTime _starttime;
  41. private bool _queryAwc;
  42. public MFPMPickRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  43. {
  44. _JetTM = tm;
  45. _robot = robot;
  46. Name = "Pick from PM";
  47. if (SC.GetValue<int>($"TM.QueryAWCOption") == 1 || SC.GetValue<int>($"TM.QueryAWCOption") == 3)
  48. _queryAwc = true;
  49. else
  50. _queryAwc = false;
  51. }
  52. public RState Start(params object[] objs)
  53. {
  54. _starttime = DateTime.Now;
  55. if (!_robot.IsHomed)
  56. {
  57. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  58. return RState.Failed;
  59. }
  60. var pickItem = (Queue<MoveItem>)objs[0];
  61. _targetModule = pickItem.Peek().SourceModule;
  62. _targetSlot = pickItem.Peek().SourceSlot;
  63. _hand = pickItem.Peek().RobotHand;
  64. if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  65. {
  66. _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
  67. }
  68. else
  69. {
  70. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for picking action");
  71. return RState.Failed;
  72. }
  73. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_hand))
  74. {
  75. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as TM Robot Arm: {_hand} already has a wafer");
  76. return RState.Failed;
  77. }
  78. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  79. {
  80. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as {_targetModule} Slot {_targetSlot + 1} has no wafer");
  81. return RState.Failed;
  82. }
  83. var wafer = WaferManager.Instance.GetWafer(_targetModule, _targetSlot);
  84. LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"{wafer.WaferOrigin} will be move from {_targetModule} {_targetSlot + 1} to TM Robot {_hand}");
  85. Reset();
  86. _pickingTimeout = SC.GetValue<int>("TM.PickTimeout") * 1000;
  87. _pickDelayTime = SC.GetValue<int>($"{_targetModule}.PickDelayTime");
  88. return Runner.Start(Module, $"Pick from {_targetModule}");
  89. }
  90. public RState Monitor()
  91. {
  92. Runner.Wait(PickStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  93. .Run(PickStep.PMPrepare, ModulePrepare, IsModulePrepareReady)
  94. .Run(PickStep.ArmExtend, ArmExtend, WaitRobotExtendDone)
  95. .Run(PickStep.QueryAWC, QueryAWC, WaitRobotQueryDone, _delay_1s)
  96. .Run(PickStep.DropDownWafer, NotifyPMPickWafer, WaitPMWaferDropDown)
  97. .Delay(PickStep.PickDelay, _pickDelayTime)
  98. .Run(PickStep.ArmRetract, ArmRetract, WaitRobotRetractDone)
  99. .Run(PickStep.SavePickeData, RecordAWCData, NullFun)
  100. .End(PickStep.NotifyDone, NotifyPMDone, _delay_50ms);
  101. return Runner.Status;
  102. }
  103. private bool ModulePrepare()
  104. {
  105. _pmModule.PostMsg(PMEntity.MSG.PreparePick);
  106. return true;
  107. }
  108. private bool IsModulePrepareReady()
  109. {
  110. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick && _pmModule.IsSlitDoorOpen;
  111. }
  112. private bool ArmExtend()
  113. {
  114. return _robot.PickExtend(_targetModule, _targetSlot, _hand);
  115. }
  116. private bool ArmRetract()
  117. {
  118. return _robot.PickRetract(_targetModule, _targetSlot, _hand);
  119. }
  120. private bool WaitRobotExtendDone()
  121. {
  122. if (_robot.Status == RState.Running)
  123. {
  124. return false;
  125. }
  126. else if (_robot.Status == RState.End)
  127. {
  128. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  129. return true;
  130. }
  131. else
  132. {
  133. Runner.Stop($"TM Robot Pick Extend failed, {_robot.Status}");
  134. return true;
  135. }
  136. }
  137. private bool QueryAWC()
  138. {
  139. if (!_queryAwc)
  140. return true;
  141. else
  142. return _robot.QueryAwc(); ;
  143. }
  144. private bool WaitRobotQueryDone()
  145. {
  146. if (!_queryAwc)
  147. return true;
  148. if (_robot.Status == RState.Running)
  149. {
  150. return false;
  151. }
  152. else if (_robot.Status == RState.End)
  153. {
  154. return true;
  155. }
  156. else
  157. {
  158. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  159. return true;
  160. }
  161. }
  162. private bool RecordAWCData()
  163. {
  164. if (!_queryAwc)
  165. return true;
  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. private bool NotifyPMPickWafer()
  181. {
  182. _pmModule.PostMsg(PMEntity.MSG.DropDownWafer);
  183. return true;
  184. }
  185. private bool WaitPMWaferDropDown()
  186. {
  187. return _pmModule.Status == PMEntity.PMStatus.Exchange_Ready;
  188. }
  189. private bool WaitRobotRetractDone()
  190. {
  191. if (_robot.Status == RState.Running)
  192. {
  193. return false;
  194. }
  195. else if (_robot.Status == RState.End)
  196. {
  197. return true;
  198. }
  199. else
  200. {
  201. Runner.Stop($"TM Robot Pick Retract failed, {_robot.Status}");
  202. return true;
  203. }
  204. }
  205. private bool NotifyPMDone()
  206. {
  207. _pmModule.PostMsg(PMEntity.MSG.PickReady);
  208. return true;
  209. }
  210. public void Abort()
  211. {
  212. _robot.Halt();
  213. }
  214. }
  215. }