SEMFPMPlaceRoutine.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.RT.Routine;
  3. using Aitex.Core.RT.SCCore;
  4. using Aitex.Core.Util;
  5. using Aitex.Sorter.Common;
  6. using MECF.Framework.Common.DBCore;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.Schedulers;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  11. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TMs;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Reflection;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using Venus_Core;
  19. using Venus_RT.Devices;
  20. using Venus_RT.Modules.PMs;
  21. namespace Venus_RT.Modules.TM.VenusEntity
  22. {
  23. public class SEMFPMPlaceRoutine : ModuleRoutineBase, IRoutine
  24. {
  25. private enum PlaceStep
  26. {
  27. WaitPMReady,
  28. PMPrepare,
  29. ArmExtend,
  30. QueryAWC,
  31. LiftUpWafer,
  32. PlaceDelay,
  33. ArmRetract,
  34. SavePlaceData,
  35. NotifyDone,
  36. }
  37. private readonly HongHuTM _TM;
  38. private readonly ITransferRobot _robot;
  39. private int _placingTimeout = 120 * 1000;
  40. private int _placeDelayTime = 0;
  41. private ModuleName _targetModule;
  42. private PMEntity _pmModule;
  43. private int _targetSlot;
  44. private Hand _hand;
  45. private DateTime _starttime;
  46. private bool _queryAwc;
  47. public SEMFPMPlaceRoutine(HongHuTM honghutm,ITransferRobot robot) : base(ModuleName.TMRobot)
  48. {
  49. _TM = honghutm;
  50. _robot = robot;
  51. Name = "Place to PM";
  52. _queryAwc = false;
  53. }
  54. public RState Start(params object[] objs)
  55. {
  56. _starttime = DateTime.Now;
  57. if (!_robot.IsHomed)
  58. {
  59. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  60. return RState.Failed;
  61. }
  62. var placeItem = (Queue<MoveItem>)objs[0];
  63. _targetModule = placeItem.Peek().DestinationModule;
  64. _targetSlot = placeItem.Peek().DestinationSlot;
  65. _hand = placeItem.Peek().RobotHand;
  66. if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  67. {
  68. _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
  69. }
  70. else
  71. {
  72. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for placing action");
  73. return RState.Failed;
  74. }
  75. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_hand))
  76. {
  77. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Place as TM Robot Arm: {_hand} has no wafer");
  78. return RState.Failed;
  79. }
  80. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  81. {
  82. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Place as {_targetModule} Slot {_targetSlot + 1} already has a wafer");
  83. return RState.Failed;
  84. }
  85. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)_hand);
  86. LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"{wafer.WaferOrigin} will be move from TM Robot {_hand} to {_targetModule} {_targetSlot + 1}");
  87. Reset();
  88. _placingTimeout = SC.GetValue<int>("SETM.PlaceTimeout") * 1000;
  89. _placeDelayTime = SC.GetValue<int>($"{_targetModule}.PlaceDelayTime");
  90. return Runner.Start(Module, $"Place to {_targetModule}");
  91. }
  92. public RState Monitor()
  93. {
  94. Runner.Wait(PlaceStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  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 ArmExtend()
  115. {
  116. return _robot.PlaceExtend(_targetModule, _targetSlot, _hand);
  117. }
  118. private bool ArmRetract()
  119. {
  120. return _robot.PlaceRetract(_targetModule, _targetSlot, _hand);
  121. }
  122. private bool QueryAWC()
  123. {
  124. if (!_queryAwc)
  125. return true;
  126. else
  127. return _robot.QueryAwc();
  128. }
  129. private bool WaitRobotExtendDone()
  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.TMRobot, (int)_hand, _targetModule, _targetSlot);
  138. return true;
  139. }
  140. else
  141. {
  142. Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}");
  143. return true;
  144. }
  145. }
  146. private bool RecordAWCData()
  147. {
  148. if (!_queryAwc)
  149. return true;
  150. //已经move后的数据
  151. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  152. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  153. //查询完毕 插入数据
  154. OffsetDataRecorder.RecordOffsetData(
  155. Guid.NewGuid().ToString(),
  156. ModuleName.TMRobot, 0,
  157. _targetModule, _targetSlot,
  158. _origin_module, _origin_slot,
  159. _hand, RobotArmPan.None,
  160. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  161. _starttime, DateTime.Now);
  162. return true;
  163. }
  164. private bool WaitRobotQueryDone()
  165. {
  166. if (!_queryAwc)
  167. return true;
  168. if (_robot.Status == RState.Running)
  169. {
  170. return false;
  171. }
  172. else if (_robot.Status == RState.End)
  173. {
  174. return true;
  175. }
  176. else
  177. {
  178. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  179. return true;
  180. }
  181. }
  182. private bool NotifyPMPlaceWafer()
  183. {
  184. _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
  185. return true;
  186. }
  187. private bool WaitPMWaferLiftUp()
  188. {
  189. return _pmModule.Status == PMEntity.PMStatus.Exchange_Ready;
  190. }
  191. private bool WaitRobotRetractDone()
  192. {
  193. if (_robot.Status == RState.Running)
  194. {
  195. return false;
  196. }
  197. else if (_robot.Status == RState.End)
  198. {
  199. return true;
  200. }
  201. else
  202. {
  203. Runner.Stop($"TM Robot Place Retract failed, {_robot.Status}");
  204. return true;
  205. }
  206. }
  207. private bool NotifyPMDone()
  208. {
  209. _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
  210. return true;
  211. }
  212. public void Abort()
  213. {
  214. _robot.Halt();
  215. }
  216. }
  217. }