SEMFPMPlaceRoutine.cs 9.8 KB

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