SEMFPMPlaceRoutine.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. Singleton<RouteManager>.Instance.GetPM(_targetModule).PostMsg(PMEntity.MSG.Error);
  156. return true;
  157. }
  158. }
  159. private bool RecordAWCData()
  160. {
  161. if (!_queryAwc)
  162. return true;
  163. //已经move后的数据
  164. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  165. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  166. //查询完毕 插入数据
  167. OffsetDataRecorder.RecordOffsetData(
  168. Guid.NewGuid().ToString(),
  169. ModuleName.TMRobot, 0,
  170. _targetModule, _targetSlot,
  171. _origin_module, _origin_slot,
  172. _hand, RobotArmPan.None,
  173. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  174. _starttime, DateTime.Now);
  175. return true;
  176. }
  177. private bool WaitRobotQueryDone()
  178. {
  179. if (!_queryAwc)
  180. return true;
  181. if (_robot.Status == RState.Running)
  182. {
  183. return false;
  184. }
  185. else if (_robot.Status == RState.End)
  186. {
  187. return true;
  188. }
  189. else
  190. {
  191. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  192. Singleton<RouteManager>.Instance.GetPM(_targetModule).PostMsg(PMEntity.MSG.Error);
  193. return true;
  194. }
  195. }
  196. private bool NotifyPMPlaceWafer()
  197. {
  198. _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
  199. return true;
  200. }
  201. private bool WaitPMWaferLiftUp()
  202. {
  203. return _pmModule.Status == PMEntity.PMStatus.Exchange_Ready;
  204. }
  205. private bool WaitRobotRetractDone()
  206. {
  207. if (_robot.Status == RState.Running)
  208. {
  209. return false;
  210. }
  211. else if (_robot.Status == RState.End)
  212. {
  213. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  214. return true;
  215. }
  216. else
  217. {
  218. Runner.Stop($"TM Robot Place Retract failed, {_robot.Status}");
  219. Singleton<RouteManager>.Instance.GetPM(_targetModule).PostMsg(PMEntity.MSG.Error);
  220. return true;
  221. }
  222. }
  223. private bool NotifyPMDone()
  224. {
  225. _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
  226. //_TM.TurnSlitDoor(_targetModule, false);
  227. return true;
  228. }
  229. private bool PMDoorClose()
  230. {
  231. LOG.Write(eEvent.WARN_TM, Module, $"PMPlace Close Door Again");
  232. return _TM.TurnSlitDoor(_targetModule, false);
  233. }
  234. private bool WaitPMDoorClose()
  235. {
  236. if (_TM.CheckSlitValveClose(_targetModule))
  237. {
  238. LOG.Write(eEvent.WARN_TM, Module, $"PMPlace Check Door Close");
  239. return true;
  240. }
  241. else
  242. {
  243. LOG.Write(eEvent.WARN_TM, Module, $"PMPlace Check not Close Door");
  244. return false;
  245. }
  246. }
  247. public void Abort()
  248. {
  249. _robot.Halt();
  250. }
  251. }
  252. }