MFPMPickRoutine.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. using Aitex.Core.RT.Routine;
  2. using Aitex.Core.RT.SCCore;
  3. using Aitex.Sorter.Common;
  4. using Aitex.Core.Common;
  5. using Venus_RT.Devices;
  6. using MECF.Framework.Common.Routine;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.SubstrateTrackings;
  9. using Venus_Core;
  10. using Aitex.Core.RT.Log;
  11. using Aitex.Core.Util;
  12. using Venus_RT.Modules.PMs;
  13. using MECF.Framework.Common.Schedulers;
  14. using System.Collections.Generic;
  15. using System;
  16. using MECF.Framework.Common.DBCore;
  17. namespace Venus_RT.Modules.TM
  18. {
  19. class MFPMPickRoutine : ModuleRoutineBase, IRoutine
  20. {
  21. private enum PickStep
  22. {
  23. WaitPMReady,
  24. OpenPMSlitDoor,
  25. PMPrepare,
  26. ArmExtend,
  27. QueryAWC,
  28. DropDownWafer,
  29. PickDelay,
  30. ArmRetract,
  31. SavePickeData,
  32. ClosePMSlitDoor,
  33. CheckAWC,
  34. NotifyDone,
  35. }
  36. private enum PickStepWithHeater
  37. {
  38. WaitPMReady,
  39. PMPrepare,
  40. WaitPressreStable,
  41. OpenPMSlitDoor,
  42. Picking,
  43. QueryAWC,
  44. SavePickeData,
  45. ClosePMSlitDoor,
  46. CheckAWC,
  47. NotifyDone,
  48. }
  49. private readonly JetTM _JetTM;
  50. private readonly ITransferRobot _robot;
  51. private int _pickingTimeout = 20 * 1000;
  52. private int _liftPinTimeout = 10 * 1000;
  53. private int _pickDelayTime = 0;
  54. private ModuleName _targetModule;
  55. private PMEntity _pmModule;
  56. //private TMEntity _tmModule;
  57. private int _targetSlot;
  58. private Hand _hand;
  59. private DateTime _starttime;
  60. private bool _queryAwc;
  61. double maxPressureDifference ;
  62. private int _robotTransferAWCOffset;
  63. public MFPMPickRoutine(JetTM tm, ITransferRobot robot) : base(ModuleName.TMRobot)
  64. {
  65. _JetTM = tm;
  66. _robot = robot;
  67. Name = "Pick from PM";
  68. if (SC.GetValue<int>($"TM.QueryAWCOption") == 1 || SC.GetValue<int>($"TM.QueryAWCOption") == 3)
  69. _queryAwc = true;
  70. else
  71. _queryAwc = false;
  72. }
  73. public RState Start(params object[] objs)
  74. {
  75. _starttime = DateTime.Now;
  76. if (!_robot.IsHomed)
  77. {
  78. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  79. return RState.Failed;
  80. }
  81. var pickItem = (Queue<MoveItem>)objs[0];
  82. if (!WaferManager.Instance.CheckDuplicatedWafersBeforeMove(pickItem))
  83. return RState.Failed;
  84. _targetModule = pickItem.Peek().SourceModule;
  85. _targetSlot = pickItem.Peek().SourceSlot;
  86. _hand = pickItem.Peek().RobotHand;
  87. if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  88. {
  89. _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
  90. }
  91. else
  92. {
  93. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for picking action");
  94. return RState.Failed;
  95. }
  96. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_hand))
  97. {
  98. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as TM Robot Arm: {_hand} already has a wafer");
  99. return RState.Failed;
  100. }
  101. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  102. {
  103. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as {_targetModule} Slot {_targetSlot + 1} has no wafer");
  104. return RState.Failed;
  105. }
  106. var wafer = WaferManager.Instance.GetWafer(_targetModule, _targetSlot);
  107. if(wafer.ChuckState == EnumWaferChuckStatus.Chucked)
  108. {
  109. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick the wafer in {_targetModule }as the wafer is chucked");
  110. return RState.Failed;
  111. }
  112. LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"{wafer.WaferOrigin} will be move from {_targetModule} {_targetSlot + 1} to TM Robot {_hand}");
  113. Reset();
  114. _pickingTimeout = SC.GetValue<int>("TM.PickTimeout") * 1000;
  115. _pickDelayTime = SC.GetValue<int>($"{_targetModule}.PickDelayTime");
  116. _robotTransferAWCOffset= SC.GetValue<int>("TM.EnterPMAWCAlarmLimit");
  117. maxPressureDifference = SC.GetValue<double>("System.PMTMMaxPressureDifference");
  118. return Runner.Start(Module, $"Pick from {_targetModule}");
  119. }
  120. public RState Monitor()
  121. {
  122. switch (_pmModule.ChamberType)
  123. {
  124. //case JetChamber.Venus:
  125. case JetChamber.Kepler2300:
  126. Runner.Wait(PickStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  127. .Run(PickStep.OpenPMSlitDoor, OpenPMSlitDoor, OpenPMSlitDoorIsOK)
  128. .Run(PickStep.PMPrepare, PMPrepare, IsPMPrepareReady)
  129. .Run(PickStep.ArmExtend, ArmExtend, WaitRobotExtendDone)
  130. .Run(PickStep.QueryAWC, QueryAWC, WaitRobotQueryDone, _delay_1s)
  131. .Run(PickStep.DropDownWafer, NotifyPMPickWafer, WaitPMWaferDropDown)
  132. .Delay(PickStep.PickDelay, _pickDelayTime)
  133. .Run(PickStep.ArmRetract, ArmRetract, WaitRobotRetractDone)
  134. .Run(PickStep.ClosePMSlitDoor, ClosePMSlitDoor, ClosePMSlitDoorIsOK)
  135. //.Run(PickStep.CheckAWC, CheckAwc )
  136. .End(PickStep.NotifyDone, NotifyPMDone, _delay_50ms);
  137. break;
  138. case JetChamber.Kepler2200A:
  139. case JetChamber.Kepler2200B:
  140. Runner.Wait(PickStepWithHeater.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  141. .Run(PickStepWithHeater.PMPrepare, PMPrepare, IsPMPrepareReady)
  142. .Wait(PickStepWithHeater.WaitPressreStable, TMPMPressureIsOK, _delay_60s)
  143. .Run(PickStepWithHeater.OpenPMSlitDoor, OpenPMSlitDoor, OpenPMSlitDoorIsOK)
  144. .Run(PickStepWithHeater.Picking, Picking, WaitPickDone)
  145. .Run(PickStepWithHeater.QueryAWC, QueryAWC, WaitRobotQueryDone)
  146. .Run(PickStepWithHeater.SavePickeData, RecordAWCData, NullFun)
  147. .Run(PickStepWithHeater.ClosePMSlitDoor, ClosePMSlitDoor, ClosePMSlitDoorIsOK)
  148. //.Run(PickStepWithHeater.CheckAWC, CheckAwc )
  149. .End(PickStepWithHeater.NotifyDone, NotifyPMDone, _delay_1s);
  150. break;
  151. }
  152. return Runner.Status;
  153. }
  154. private bool TMPMPressureIsOK()
  155. {
  156. if (RouteManager.IsATMMode)
  157. {
  158. return _JetTM.IsTMATM && _JetTM.IsModuleATM(_targetModule);
  159. }
  160. else
  161. {
  162. if (Math.Abs((_pmModule.ChamberPressure - _JetTM.ChamberPressure)) < (maxPressureDifference-2))
  163. {
  164. return true;
  165. }
  166. else
  167. {
  168. return false;
  169. }
  170. }
  171. }
  172. private bool PMPrepare()
  173. {
  174. _pmModule.PostMsg(PMEntity.MSG.PreparePick);
  175. return true;
  176. }
  177. private bool OpenPMSlitDoor()
  178. {
  179. return _JetTM.TurnMFSlitDoor(_targetModule, true, out _);
  180. }
  181. private bool OpenPMSlitDoorIsOK()
  182. {
  183. return _JetTM.IsPMSlitdoorOpened(_targetModule);
  184. }
  185. private bool ClosePMSlitDoor()
  186. {
  187. return _JetTM.TurnMFSlitDoor(_targetModule, false, out _);
  188. }
  189. private bool ClosePMSlitDoorIsOK()
  190. {
  191. return _JetTM.IsPMSlitdoorClosed(_targetModule);
  192. }
  193. private bool IsPMPrepareReady()
  194. {
  195. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick;
  196. }
  197. private bool Picking()
  198. {
  199. return _robot.Pick(_targetModule, _targetSlot, _hand);
  200. }
  201. private bool WaitPickDone()
  202. {
  203. if (_robot.Status == RState.Running)
  204. {
  205. if(Runner.StepElapsedMS > _pickingTimeout)
  206. {
  207. WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  208. Runner.Stop($"TM Robot Picking {_targetModule} wafer timeout, {_pickingTimeout}");
  209. return true;
  210. }
  211. return false;
  212. }
  213. else if (_robot.Status == RState.End)
  214. {
  215. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  216. return true;
  217. }
  218. else
  219. {
  220. WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  221. Runner.Stop($"TM Robot Picking failed, {_robot.Status}");
  222. return true;
  223. }
  224. }
  225. private bool ArmExtend()
  226. {
  227. return _robot.PickExtend(_targetModule, _targetSlot, _hand);
  228. }
  229. private bool ArmRetract()
  230. {
  231. return _robot.PickRetract(_targetModule, _targetSlot, _hand);
  232. }
  233. private bool WaitRobotExtendDone()
  234. {
  235. if (_robot.Status == RState.Running)
  236. {
  237. return false;
  238. }
  239. else if (_robot.Status == RState.End)
  240. {
  241. return true;
  242. }
  243. else
  244. {
  245. Runner.Stop($"TM Robot Pick Extend failed, {_robot.Status}");
  246. return true;
  247. }
  248. }
  249. private bool QueryAWC()
  250. {
  251. if (!_queryAwc)
  252. return true;
  253. else
  254. return _robot.QueryAwc(); ;
  255. }
  256. private bool WaitRobotQueryDone()
  257. {
  258. if (!_queryAwc)
  259. return true;
  260. if (_robot.Status == RState.Running)
  261. {
  262. return false;
  263. }
  264. else if (_robot.Status == RState.End)
  265. {
  266. return true;
  267. }
  268. else
  269. {
  270. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  271. return true;
  272. }
  273. }
  274. private bool RecordAWCData()
  275. {
  276. if (!_queryAwc)
  277. return true;
  278. //已经move后的数据
  279. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  280. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  281. //查询完毕 插入数据
  282. OffsetDataRecorder.RecordOffsetData(
  283. Guid.NewGuid().ToString(),
  284. _targetModule, _targetSlot,
  285. ModuleName.TMRobot, 0,
  286. _origin_module, _origin_slot,
  287. _hand, RobotArmPan.None,
  288. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  289. _starttime, DateTime.Now);
  290. return true;
  291. }
  292. private bool CheckAwc()
  293. {
  294. //if (Math.Abs(_robot.Offset_D) > awcAlarmRange * 1000)
  295. //{
  296. // Stop($"Check AWC 失败, 当前 AWC [{_robot.Offset_D}um], 高于Alarm最大值: [{awcAlarmRange}mm]");
  297. // return false;
  298. //}
  299. return true;
  300. }
  301. private bool NotifyPMPickWafer()
  302. {
  303. _pmModule.PostMsg(PMEntity.MSG.DropDownWafer);
  304. return true;
  305. }
  306. private bool WaitPMWaferDropDown()
  307. {
  308. if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  309. {
  310. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  311. return true;
  312. }
  313. else if (Runner.StepElapsedMS > _liftPinTimeout)
  314. {
  315. WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  316. Runner.Stop($"Wait {_targetModule} Lift Pin down timeout, {Runner.StepElapsedMS}");
  317. }
  318. return false;
  319. }
  320. private bool WaitRobotRetractDone()
  321. {
  322. if (_robot.Status == RState.Running)
  323. {
  324. return false;
  325. }
  326. else if (_robot.Status == RState.End)
  327. {
  328. return true;
  329. }
  330. else
  331. {
  332. Runner.Stop($"TM Robot Pick Retract failed, {_robot.Status}");
  333. return true;
  334. }
  335. }
  336. private bool NotifyPMDone()
  337. {
  338. _pmModule.PostMsg(PMEntity.MSG.PickReady);
  339. return true;
  340. }
  341. public void Abort()
  342. {
  343. //_robot.Halt();
  344. }
  345. }
  346. }