SEMFPMPlaceRoutine.cs 9.0 KB

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