MFPMPlaceRoutine.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. PMPrepare,
  24. ArmExtend,
  25. QueryAWC,
  26. LiftUpWafer,
  27. PlaceDelay,
  28. ArmRetract,
  29. SavePlaceData,
  30. NotifyDone,
  31. }
  32. private readonly JetTM _JetTM;
  33. private readonly ITransferRobot _robot;
  34. private int _placingTimeout = 120 * 1000;
  35. private int _placeDelayTime = 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 MFPMPlaceRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  43. {
  44. _JetTM = tm;
  45. _robot = robot;
  46. Name = "Place to PM";
  47. if (SC.GetValue<int>($"TM.QueryAWCOption") == 2 || 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 placeItem = (Queue<MoveItem>)objs[0];
  61. _targetModule = placeItem.Peek().DestinationModule;
  62. _targetSlot = placeItem.Peek().DestinationSlot;
  63. _hand = placeItem.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 placing action");
  71. return RState.Failed;
  72. }
  73. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_hand))
  74. {
  75. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Place as TM Robot Arm: {_hand} has no wafer");
  76. return RState.Failed;
  77. }
  78. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  79. {
  80. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Place as {_targetModule} Slot {_targetSlot + 1} already has a wafer");
  81. return RState.Failed;
  82. }
  83. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)_hand);
  84. LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"{wafer.WaferOrigin} will be move from TM Robot {_hand} to {_targetModule} {_targetSlot + 1}");
  85. Reset();
  86. _placingTimeout = SC.GetValue<int>("TM.PlaceTimeout") * 1000;
  87. _placeDelayTime = SC.GetValue<int>($"{_targetModule}.PlaceDelayTime");
  88. return Runner.Start(Module, $"Place to {_targetModule}");
  89. }
  90. public RState Monitor()
  91. {
  92. Runner.Wait((int)PlaceStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  93. .Run((int)PlaceStep.PMPrepare, ModulePrepare, IsModulePrepareReady, _delay_60s)
  94. .Run((int)PlaceStep.ArmExtend, ArmExtend, WaitRobotExtendDone, _placingTimeout)
  95. .Run((int)PlaceStep.QueryAWC, QueryAWC, WaitRobotQueryDone, _delay_1s)
  96. .Run((int)PlaceStep.LiftUpWafer, NotifyPMPlaceWafer, WaitPMWaferLiftUp, _delay_30s)
  97. .Delay((int)PlaceStep.PlaceDelay, _placeDelayTime)
  98. .Run((int)PlaceStep.ArmRetract, ArmRetract, WaitRobotRetractDone, _delay_30s)
  99. .Run((int)PlaceStep.SavePlaceData, RecordAWCData, NullFun)
  100. .End((int)PlaceStep.NotifyDone, NotifyPMDone, _delay_50ms);
  101. return Runner.Status;
  102. }
  103. private bool ModulePrepare()
  104. {
  105. _pmModule.PostMsg(PMEntity.MSG.PreparePlace);
  106. return true;
  107. }
  108. private bool IsModulePrepareReady()
  109. {
  110. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place && _pmModule.IsSlitDoorOpen;
  111. }
  112. private bool ArmExtend()
  113. {
  114. return _robot.PlaceExtend(_targetModule, _targetSlot, _hand);
  115. }
  116. private bool ArmRetract()
  117. {
  118. return _robot.PlaceRetract(_targetModule, _targetSlot, _hand);
  119. }
  120. private bool QueryAWC()
  121. {
  122. if (!_queryAwc)
  123. return true;
  124. else
  125. return _robot.QueryAwc(); ;
  126. }
  127. private bool WaitRobotExtendDone()
  128. {
  129. if (_robot.Status == RState.Running)
  130. {
  131. return false;
  132. }
  133. else if (_robot.Status == RState.End)
  134. {
  135. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  136. return true;
  137. }
  138. else
  139. {
  140. Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}");
  141. return true;
  142. }
  143. }
  144. private bool RecordAWCData()
  145. {
  146. if(!_queryAwc)
  147. return true;
  148. //已经move后的数据
  149. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  150. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  151. //查询完毕 插入数据
  152. OffsetDataRecorder.RecordOffsetData(
  153. Guid.NewGuid().ToString(),
  154. ModuleName.TMRobot, 0,
  155. _targetModule, _targetSlot,
  156. _origin_module, _origin_slot,
  157. _hand, RobotArmPan.None,
  158. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  159. _starttime, DateTime.Now);
  160. return true;
  161. }
  162. private bool WaitRobotQueryDone()
  163. {
  164. if (!_queryAwc)
  165. return true;
  166. if (_robot.Status == RState.Running)
  167. {
  168. return false;
  169. }
  170. else if (_robot.Status == RState.End)
  171. {
  172. return true;
  173. }
  174. else
  175. {
  176. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  177. return true;
  178. }
  179. }
  180. private bool NotifyPMPlaceWafer()
  181. {
  182. _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
  183. return true;
  184. }
  185. private bool WaitPMWaferLiftUp()
  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 Place Retract failed, {_robot.Status}");
  202. return true;
  203. }
  204. }
  205. private bool NotifyPMDone()
  206. {
  207. _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
  208. return true;
  209. }
  210. public void Abort()
  211. {
  212. _robot.Halt();
  213. }
  214. }
  215. }