MFPMPlaceRoutine.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. PreRotation,
  24. PMPrepare,
  25. ArmExtend,
  26. QueryAWC,
  27. LiftUpWafer,
  28. PlaceDelay,
  29. ArmRetract,
  30. SavePlaceData,
  31. NotifyDone,
  32. }
  33. private readonly JetTM _JetTM;
  34. private readonly ITransferRobot _robot;
  35. private int _placingTimeout = 120 * 1000;
  36. private int _placeDelayTime = 0;
  37. private ModuleName _targetModule;
  38. private PMEntity _pmModule;
  39. private int _targetSlot;
  40. private Hand _hand;
  41. private DateTime _starttime;
  42. private bool _queryAwc;
  43. public MFPMPlaceRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  44. {
  45. _JetTM = tm;
  46. _robot = robot;
  47. Name = "Place to PM";
  48. if (SC.GetValue<int>($"TM.QueryAWCOption") == 2 || SC.GetValue<int>($"TM.QueryAWCOption") == 3)
  49. _queryAwc = true;
  50. else
  51. _queryAwc = false;
  52. }
  53. public RState Start(params object[] objs)
  54. {
  55. _starttime = DateTime.Now;
  56. if (!_robot.IsHomed)
  57. {
  58. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  59. return RState.Failed;
  60. }
  61. var placeItem = (Queue<MoveItem>)objs[0];
  62. _targetModule = placeItem.Peek().DestinationModule;
  63. _targetSlot = placeItem.Peek().DestinationSlot;
  64. _hand = placeItem.Peek().RobotHand;
  65. if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  66. {
  67. _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
  68. }
  69. else
  70. {
  71. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for placing action");
  72. return RState.Failed;
  73. }
  74. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_hand))
  75. {
  76. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Place as TM Robot Arm: {_hand} has no wafer");
  77. return RState.Failed;
  78. }
  79. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  80. {
  81. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Place as {_targetModule} Slot {_targetSlot + 1} already has a wafer");
  82. return RState.Failed;
  83. }
  84. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)_hand);
  85. LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"{wafer.WaferOrigin} will be move from TM Robot {_hand} to {_targetModule} {_targetSlot + 1}");
  86. Reset();
  87. _placingTimeout = SC.GetValue<int>("TM.PlaceTimeout") * 1000;
  88. _placeDelayTime = SC.GetValue<int>($"{_targetModule}.PlaceDelayTime");
  89. return Runner.Start(Module, $"Place to {_targetModule}");
  90. }
  91. public RState Monitor()
  92. {
  93. Runner.Wait(PlaceStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  94. .RunIf(PlaceStep.PreRotation, _JetTM.PreRotateModules.ContainsKey(_targetModule), RotateArm, WaitRotateDone)
  95. .Run(PlaceStep.PMPrepare, ModulePrepare, IsModulePrepareReady, _delay_60s)
  96. .Run(PlaceStep.ArmExtend, ArmExtend, WaitRobotExtendDone, _placingTimeout)
  97. .Run(PlaceStep.QueryAWC, QueryAWC, WaitRobotQueryDone, _delay_1s)
  98. .Run(PlaceStep.LiftUpWafer, NotifyPMPlaceWafer, WaitPMWaferLiftUp, _delay_30s)
  99. .Delay(PlaceStep.PlaceDelay, _placeDelayTime)
  100. .Run(PlaceStep.ArmRetract, ArmRetract, WaitRobotRetractDone, _delay_30s)
  101. .Run(PlaceStep.SavePlaceData, RecordAWCData, NullFun)
  102. .End(PlaceStep.NotifyDone, NotifyPMDone, _delay_50ms);
  103. return Runner.Status;
  104. }
  105. private bool ModulePrepare()
  106. {
  107. _pmModule.PostMsg(PMEntity.MSG.PreparePlace);
  108. return true;
  109. }
  110. private bool IsModulePrepareReady()
  111. {
  112. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place && _pmModule.IsSlitDoorOpen;
  113. }
  114. private bool RotateArm()
  115. {
  116. _pmModule.PostMsg(PMEntity.MSG.PreparePlace); // Notify PM to Serv pressure in advance for throughput enhancement
  117. return _robot.Goto(_JetTM.PreRotateModules[_targetModule], 0, _hand);
  118. }
  119. private bool WaitRotateDone()
  120. {
  121. if (_robot.Status == RState.Running)
  122. {
  123. return false;
  124. }
  125. else if (_robot.Status == RState.End)
  126. {
  127. return true;
  128. }
  129. else
  130. {
  131. Runner.Stop($"TM Robot Rotate Arm failed, {_robot.Status}");
  132. return true;
  133. }
  134. }
  135. private bool ArmExtend()
  136. {
  137. return _robot.PlaceExtend(_targetModule, _targetSlot, _hand);
  138. }
  139. private bool ArmRetract()
  140. {
  141. return _robot.PlaceRetract(_targetModule, _targetSlot, _hand);
  142. }
  143. private bool QueryAWC()
  144. {
  145. if (!_queryAwc)
  146. return true;
  147. else
  148. return _robot.QueryAwc();
  149. }
  150. private bool WaitRobotExtendDone()
  151. {
  152. if (_robot.Status == RState.Running)
  153. {
  154. return false;
  155. }
  156. else if (_robot.Status == RState.End)
  157. {
  158. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  159. return true;
  160. }
  161. else
  162. {
  163. Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}");
  164. return true;
  165. }
  166. }
  167. private bool RecordAWCData()
  168. {
  169. if(!_queryAwc)
  170. return true;
  171. //已经move后的数据
  172. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  173. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  174. //查询完毕 插入数据
  175. OffsetDataRecorder.RecordOffsetData(
  176. Guid.NewGuid().ToString(),
  177. ModuleName.TMRobot, 0,
  178. _targetModule, _targetSlot,
  179. _origin_module, _origin_slot,
  180. _hand, RobotArmPan.None,
  181. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  182. _starttime, DateTime.Now);
  183. return true;
  184. }
  185. private bool WaitRobotQueryDone()
  186. {
  187. if (!_queryAwc)
  188. return true;
  189. if (_robot.Status == RState.Running)
  190. {
  191. return false;
  192. }
  193. else if (_robot.Status == RState.End)
  194. {
  195. return true;
  196. }
  197. else
  198. {
  199. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  200. return true;
  201. }
  202. }
  203. private bool NotifyPMPlaceWafer()
  204. {
  205. _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
  206. return true;
  207. }
  208. private bool WaitPMWaferLiftUp()
  209. {
  210. return _pmModule.Status == PMEntity.PMStatus.Exchange_Ready;
  211. }
  212. private bool WaitRobotRetractDone()
  213. {
  214. if (_robot.Status == RState.Running)
  215. {
  216. return false;
  217. }
  218. else if (_robot.Status == RState.End)
  219. {
  220. return true;
  221. }
  222. else
  223. {
  224. Runner.Stop($"TM Robot Place Retract failed, {_robot.Status}");
  225. return true;
  226. }
  227. }
  228. private bool NotifyPMDone()
  229. {
  230. _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
  231. return true;
  232. }
  233. public void Abort()
  234. {
  235. _robot.Halt();
  236. }
  237. }
  238. }