MFPMPickRoutine.cs 13 KB

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