SEMFPMPlaceRoutine.cs 9.4 KB

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