MFPMPickRoutine.cs 15 KB

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