MFPMPlaceRoutine.cs 7.6 KB

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