SEMFPMPlaceRoutine.cs 9.4 KB

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