SEMFPMPlaceRoutine.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. _TM.TurnSlitDoor(_targetModule, true);
  109. return true;
  110. }
  111. private bool IsModulePrepareReady()
  112. {
  113. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place && _pmModule.IsSlitDoorOpen;
  114. }
  115. private bool ArmExtend()
  116. {
  117. return _robot.PlaceExtend(_targetModule, _targetSlot, _hand);
  118. }
  119. private bool ArmRetract()
  120. {
  121. return _robot.PlaceRetract(_targetModule, _targetSlot, _hand);
  122. }
  123. private bool QueryAWC()
  124. {
  125. if (!_queryAwc)
  126. return true;
  127. else
  128. return _robot.QueryAwc();
  129. }
  130. private bool WaitRobotExtendDone()
  131. {
  132. if (_robot.Status == RState.Running)
  133. {
  134. return false;
  135. }
  136. else if (_robot.Status == RState.End)
  137. {
  138. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  139. return true;
  140. }
  141. else
  142. {
  143. Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}");
  144. return true;
  145. }
  146. }
  147. private bool RecordAWCData()
  148. {
  149. if (!_queryAwc)
  150. return true;
  151. //已经move后的数据
  152. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  153. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  154. //查询完毕 插入数据
  155. OffsetDataRecorder.RecordOffsetData(
  156. Guid.NewGuid().ToString(),
  157. ModuleName.TMRobot, 0,
  158. _targetModule, _targetSlot,
  159. _origin_module, _origin_slot,
  160. _hand, RobotArmPan.None,
  161. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  162. _starttime, DateTime.Now);
  163. return true;
  164. }
  165. private bool WaitRobotQueryDone()
  166. {
  167. if (!_queryAwc)
  168. return true;
  169. if (_robot.Status == RState.Running)
  170. {
  171. return false;
  172. }
  173. else if (_robot.Status == RState.End)
  174. {
  175. return true;
  176. }
  177. else
  178. {
  179. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  180. return true;
  181. }
  182. }
  183. private bool NotifyPMPlaceWafer()
  184. {
  185. _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
  186. return true;
  187. }
  188. private bool WaitPMWaferLiftUp()
  189. {
  190. return _pmModule.Status == PMEntity.PMStatus.Exchange_Ready;
  191. }
  192. private bool WaitRobotRetractDone()
  193. {
  194. if (_robot.Status == RState.Running)
  195. {
  196. return false;
  197. }
  198. else if (_robot.Status == RState.End)
  199. {
  200. return true;
  201. }
  202. else
  203. {
  204. Runner.Stop($"TM Robot Place Retract failed, {_robot.Status}");
  205. return true;
  206. }
  207. }
  208. private bool NotifyPMDone()
  209. {
  210. _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
  211. _TM.TurnSlitDoor(_targetModule, false);
  212. return true;
  213. }
  214. public void Abort()
  215. {
  216. _robot.Halt();
  217. }
  218. }
  219. }