SEMFPMPlaceRoutine.cs 8.1 KB

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