SEMFPMPlaceRoutine.cs 11 KB

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