PMPrepareTransferRoutine.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. using System;
  2. using Aitex.Core.Common;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using MECF.Framework.Common.Equipment;
  6. using MECF.Framework.Common.Schedulers;
  7. using MECF.Framework.Common.SubstrateTrackings;
  8. using JetVirgoPM.Devices;
  9. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.PMs;
  10. using Aitex.Sorter.Common;
  11. using Aitex.Core.RT.Event;
  12. namespace JetVirgoPM.PMs.Routines
  13. {
  14. class PMPrepareTransferRoutine : PMRoutineBase, IStepRoutine
  15. {
  16. enum RoutineStep
  17. {
  18. LiftUpDown,
  19. Vent,
  20. VentDelay,
  21. SetGuidePin,
  22. CheckCoolantTemp1,
  23. CheckCoolantTemp2,
  24. CheckTemp1,
  25. CheckTemp2,
  26. CheckLETemp,
  27. SetSlitDoor,
  28. SlitDoorDelay,
  29. PrepareTransferPlace,
  30. PrepareTransferPick,
  31. kEnd
  32. }
  33. private EnumTransferType _TransferType;
  34. private EnumDualPM _pos;
  35. private int _timeout;
  36. private readonly VentRoutine _ventRoutine;
  37. private WaferSize _ws;
  38. private double _temp;
  39. private double _tolerance;
  40. private double _Chiller1OffsetTemp = 0.0f;
  41. private double _Chiller2OffsetTemp = 0.0f;
  42. private double _TargetTemp1 = 0.0f;
  43. private double _TargetTemp2 = 0.0f;
  44. private bool _enableCheckTemp = false;
  45. private int _checkChamberTempTimeout = 60;
  46. private bool _isATMMode;
  47. public bool _Chamber1Disabled;
  48. public bool _Chamber2Disabled;
  49. private bool _enableChiller1;
  50. private bool _enableChiller2;
  51. private bool _enableLE1;
  52. private bool _enableLE2;
  53. private bool _isVented = false;
  54. public bool GuidePinInstalled;
  55. public PMPrepareTransferRoutine(JetDualPM chamber, VentRoutine _vRoutine) : base(chamber)
  56. {
  57. Name = "PrepareTransfer";
  58. _ventRoutine = _vRoutine;
  59. }
  60. public RState Init(EnumTransferType type, EnumDualPM pos, WaferSize size, double temp1, double temp2, bool EnableCheckTemp)
  61. {
  62. if (type == EnumTransferType.Place)
  63. {
  64. Name = $"Prepare Place {_ws}";
  65. }
  66. else if (type == EnumTransferType.Pick)
  67. {
  68. size = WaferManager.Instance.GetWafer(_chamber.Module, pos == EnumDualPM.Left ? 0 : 1).Size;
  69. Name = $"Prepare Pick {_ws}";
  70. }
  71. _TargetTemp1 = temp1;
  72. _TargetTemp2 = temp2;
  73. _enableCheckTemp = EnableCheckTemp;
  74. _pos = pos;
  75. _TransferType = type;
  76. _ws = size;
  77. return RState.End;
  78. }
  79. public RState Init(EnumTransferType type, int[] slot, double temp1, double temp2, bool EnableCheckTemp, int handSlot = -1, EnumDualPM autoPos= EnumDualPM.None)
  80. {
  81. EnumDualPM pos = (slot.Length > 1) ? EnumDualPM.Both : (slot[0] == 0) ? EnumDualPM.Left : EnumDualPM.Right;
  82. if(autoPos != EnumDualPM.None)
  83. {
  84. pos = autoPos;
  85. }
  86. if (SC.IsDoubleFork) pos = EnumDualPM.Both;
  87. WaferSize ws = WaferSize.WS0;
  88. if(handSlot != -1 && type == EnumTransferType.Place)
  89. {
  90. Hand hand = (Hand)handSlot;
  91. if (hand == Hand.Both)
  92. {
  93. ws = WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)Hand.Blade1).Size;
  94. }
  95. else
  96. {
  97. ws = WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)hand).Size;
  98. }
  99. }
  100. else if (type == EnumTransferType.Pick)
  101. {
  102. if(pos == EnumDualPM.Left || pos == EnumDualPM.Both)
  103. {
  104. ws = WaferManager.Instance.GetWafer(_chamber.Module, (int)EnumDualPM.Left - 1).Size;
  105. }
  106. else if(pos == EnumDualPM.Right)
  107. {
  108. ws = WaferManager.Instance.GetWafer(_chamber.Module, (int)EnumDualPM.Right - 1).Size;
  109. }
  110. }
  111. _TargetTemp1 = temp1;
  112. _TargetTemp2 = temp2;
  113. _enableCheckTemp = EnableCheckTemp;
  114. return Init(type, pos, ws, temp1, temp2, EnableCheckTemp);
  115. }
  116. public RState Start(params object[] objs)
  117. {
  118. Reset();
  119. _timeout = SC.GetValue<int>($"{Module}.PrepareTransferTimeout");
  120. _Chamber1Disabled = SC.GetValue<bool>($"System.SetUp.{Module}Chamber1Disabled.IsInstalled");
  121. _Chamber2Disabled = SC.GetValue<bool>($"System.SetUp.{Module}Chamber2Disabled.IsInstalled");
  122. _enableChiller1 = SC.GetValue<bool>($"{Module}.Chiller1.EnableChiller");
  123. _enableChiller2 = SC.GetValue<bool>($"{Module}.Chiller2.EnableChiller");
  124. GuidePinInstalled = SC.GetValue<bool>($"{Module}.GuidePin.IsInstalled");
  125. if(GuidePinInstalled && _ws == WaferSize.WS0)
  126. {
  127. Stop($"GuidePin 开启后,检查到Wafer size is {_ws.ToString()}");
  128. return RState.Failed;
  129. }
  130. _checkChamberTempTimeout = SC.GetValue<int>($"{Module}.CheckChamberTempTimeout");
  131. _temp = SC.GetValue<double>($"{Module}.ChamberBaseTemperatureThreshold");
  132. _tolerance = SC.GetValue<double>($"System.MaxTemperatureToleranceToTarget");
  133. _Chiller1OffsetTemp = SC.GetValue<double>($"{Module}.Chiller1.ChillerTemperatureOffset");
  134. _Chiller2OffsetTemp = SC.GetValue<double>($"{Module}.Chiller2.ChillerTemperatureOffset");
  135. if (CheckAlreadyReadyForTransfer())
  136. {
  137. return RState.End;
  138. }
  139. _isATMMode = SC.IsATMMode;
  140. if (_isATMMode && !_chamber.CheckAtm())
  141. {
  142. Stop($"Running in ATMmode,{_chamber.DeviceID} not in atmos now!");
  143. return RState.Failed;
  144. }
  145. Notify($"开始, 准备 {(_TransferType == EnumTransferType.Place ? "放" : _TransferType == EnumTransferType.Pick ? "取" : "动作未知")}{_ws} 寸片, ");
  146. _enableLE1 = true;
  147. _enableLE2 = true;
  148. return Runner.Start(_chamber.Module.ToString(), Name);
  149. }
  150. public RState Monitor()
  151. {
  152. Runner
  153. .Run(RoutineStep.CheckCoolantTemp1, SetCoolant1Temp, CheckCoolant1Temp, _checkChamberTempTimeout * 1000)
  154. .Run(RoutineStep.CheckCoolantTemp2, SetCoolant2Temp, CheckCoolant2Temp, _checkChamberTempTimeout * 1000)
  155. .Run(RoutineStep.CheckLETemp, SetLETemp, CheckLETemp, _checkChamberTempTimeout * 1000)
  156. .Run(RoutineStep.CheckTemp1, SetLETemp1, CheckLETemp1, _checkChamberTempTimeout * 1000)
  157. .Run(RoutineStep.CheckTemp2, SetLETemp2, CheckLETemp2, _checkChamberTempTimeout * 1000)
  158. .Run(RoutineStep.PrepareTransferPlace, PMPreparePlace, CheckPMPreparePlace, _timeout * 1000)
  159. .Run(RoutineStep.PrepareTransferPick, PMPreparePick, CheckPMPreparePick, _timeout * 1000)
  160. .End(RoutineStep.kEnd, EndFunc, _delay_0s);
  161. return Runner.Status;
  162. }
  163. public override void Abort()
  164. {
  165. }
  166. bool Vent()
  167. {
  168. if(!SC.IsATMMode && _chamber.IsSlitDoor1Closed && _chamber.IsSlitDoor2Closed)
  169. {
  170. _isVented = _ventRoutine.Start() == RState.End;
  171. return _ventRoutine.Start() == RState.Running || _isVented;
  172. }
  173. return true;
  174. }
  175. bool CheckVent()
  176. {
  177. if (!SC.IsATMMode && _chamber.IsSlitDoor1Closed && _chamber.IsSlitDoor2Closed && !_isVented)
  178. {
  179. var status = _ventRoutine.Monitor();
  180. if (status == RState.End)
  181. {
  182. return true;
  183. }
  184. else if (status == RState.Failed || status == RState.Timeout)
  185. {
  186. Runner.Stop($"Vent failed.");
  187. return true;
  188. }
  189. return false;
  190. }
  191. return true;
  192. }
  193. bool SetCoolant1Temp()
  194. {
  195. if (_TransferType == EnumTransferType.Place && !SC.IsATMMode && _enableCheckTemp && !_Chamber1Disabled && _TargetTemp1 > 0 && _enableChiller1)
  196. {
  197. _enableLE1 = false;
  198. return SetCoolant1Temp(_TargetTemp1, _Chiller1OffsetTemp, _tolerance);
  199. }
  200. return true;
  201. }
  202. bool CheckCoolant1Temp()
  203. {
  204. if (_TransferType == EnumTransferType.Place && !SC.IsATMMode && _enableCheckTemp && !_Chamber1Disabled && _TargetTemp1 > 0 && _enableChiller1)
  205. {
  206. return CheckCoolant1Temp(_TargetTemp1, _Chiller1OffsetTemp, _tolerance);
  207. }
  208. return true;
  209. }
  210. bool SetCoolant2Temp()
  211. {
  212. if(_TransferType == EnumTransferType.Place && !SC.IsATMMode && _enableCheckTemp && !_Chamber2Disabled && _TargetTemp2 > 0 && _enableChiller2)
  213. {
  214. _enableLE2 = false;
  215. return SetCoolant2Temp(_TargetTemp2, _Chiller2OffsetTemp, _tolerance);
  216. }
  217. return true;
  218. }
  219. bool CheckCoolant2Temp()
  220. {
  221. if (_TransferType == EnumTransferType.Place && !SC.IsATMMode && _enableCheckTemp && !_Chamber2Disabled && _TargetTemp2 > 0 && _enableChiller2)
  222. {
  223. return CheckCoolant2Temp(_TargetTemp2, _Chiller2OffsetTemp, _tolerance);
  224. }
  225. return true;
  226. }
  227. bool SetLETemp()
  228. {
  229. if(_TransferType == EnumTransferType.Place && !SC.IsATMMode && (_enableLE1 && !_Chamber1Disabled && _TargetTemp1 > 0) && (_enableLE2 && !_Chamber2Disabled && _TargetTemp2 > 0))
  230. {
  231. return SetLETemp(_TargetTemp1, _TargetTemp2, _tolerance, _enableLE1, _enableLE2);
  232. }
  233. return true;
  234. }
  235. bool CheckLETemp()
  236. {
  237. if (_TransferType == EnumTransferType.Place && !SC.IsATMMode && (_enableLE1 && !_Chamber1Disabled && _TargetTemp1 > 0) && (_enableLE2 && !_Chamber2Disabled && _TargetTemp2 > 0))
  238. {
  239. return CheckLETemp(_TargetTemp1, _TargetTemp2, _tolerance, _enableLE1, _enableLE2);
  240. }
  241. return true;
  242. }
  243. bool SetLETemp1()
  244. {
  245. if (_TransferType == EnumTransferType.Place && !SC.IsATMMode && _enableLE1 && !_Chamber1Disabled && _TargetTemp1 > 0)
  246. {
  247. return SetLETemp(_TargetTemp1, 0, _tolerance, _enableLE1, false);
  248. }
  249. return true;
  250. }
  251. bool CheckLETemp1()
  252. {
  253. if (_TransferType == EnumTransferType.Place && !SC.IsATMMode && _enableLE1 && !_Chamber1Disabled && _TargetTemp1 > 0)
  254. {
  255. return CheckLETemp(_TargetTemp1, 0, _tolerance, _enableLE1, false);
  256. }
  257. return true;
  258. }
  259. bool SetLETemp2()
  260. {
  261. if (_TransferType == EnumTransferType.Place && !SC.IsATMMode && _enableLE2 && !_Chamber2Disabled && _TargetTemp2 > 0)
  262. {
  263. return SetLETemp(0, _TargetTemp2, _tolerance, false, _enableLE2);
  264. }
  265. return true;
  266. }
  267. bool CheckLETemp2()
  268. {
  269. if (_TransferType == EnumTransferType.Place && !SC.IsATMMode && _enableLE2 && !_Chamber2Disabled && _TargetTemp2 > 0)
  270. {
  271. return CheckLETemp(0, _TargetTemp2, _tolerance, false, _enableLE2);
  272. }
  273. return true;
  274. }
  275. bool CheckAlreadyReadyForTransfer()
  276. {
  277. if (_pos == EnumDualPM.Left)
  278. {
  279. if (_TransferType == EnumTransferType.Pick)
  280. {
  281. if (!_chamber.CheckSlitDoor1Open())
  282. {
  283. return false;
  284. }
  285. if (!_chamber.CheckLift1Up())
  286. {
  287. return false;
  288. }
  289. return _chamber.CheckSlitDoor1Open() && _chamber.CheckLift1Up();
  290. }
  291. else if (_TransferType == EnumTransferType.Place)
  292. {
  293. if (!_chamber.CheckSlitDoor1Open())
  294. {
  295. return false;
  296. }
  297. if (!_chamber.CheckLift1Down())
  298. {
  299. return false;
  300. }
  301. return _chamber.CheckSlitDoor1Open() && _chamber.CheckLift1Down();
  302. }
  303. }
  304. if (_pos == EnumDualPM.Right)
  305. {
  306. if (_TransferType == EnumTransferType.Pick)
  307. {
  308. if (!_chamber.CheckSlitDoor2Open())
  309. {
  310. return false;
  311. }
  312. if (!_chamber.CheckLift2Up())
  313. {
  314. return false;
  315. }
  316. return _chamber.CheckSlitDoor2Open() && _chamber.CheckLift2Up();
  317. }
  318. else if (_TransferType == EnumTransferType.Place)
  319. {
  320. if (!_chamber.CheckSlitDoor2Open())
  321. {
  322. return false;
  323. }
  324. if (!_chamber.CheckLift2Down())
  325. {
  326. return false;
  327. }
  328. return _chamber.CheckSlitDoor2Open() && _chamber.CheckLift2Down();
  329. }
  330. }
  331. if (_pos == EnumDualPM.Both)
  332. {
  333. bool checkSlitDoorBothResult = _chamber.CheckSlitDoor1Open() && _chamber.CheckSlitDoor2Open();
  334. if (!checkSlitDoorBothResult)
  335. {
  336. return checkSlitDoorBothResult;
  337. }
  338. if (_TransferType == EnumTransferType.Pick)
  339. {
  340. return _chamber.CheckLift1Up() && _chamber.CheckLift2Up();
  341. }
  342. else if (_TransferType == EnumTransferType.Place)
  343. {
  344. return _chamber.CheckLift1Down() && _chamber.CheckLift2Down();
  345. }
  346. }
  347. return false;
  348. }
  349. bool PMPreparePlace()
  350. {
  351. if(_TransferType == EnumTransferType.Place)
  352. {
  353. return SetLiftPinAndSlitDoorAndGuidePin(false, _ws, true, GuidePinInstalled);
  354. }
  355. return true;
  356. }
  357. bool CheckPMPreparePlace()
  358. {
  359. if (_TransferType == EnumTransferType.Place)
  360. {
  361. return CheckLiftPinAndSlitDoorAndGuidePin(false, _ws, true, GuidePinInstalled);
  362. }
  363. return true;
  364. }
  365. bool SetLiftPinAndSlitDoorAndGuidePin(bool isUp, WaferSize ws, bool isOpen, bool _guidePinInstalled)
  366. {
  367. Notify($"设置 {_chamber.Name}{_pos} liftPin {(isUp ? "升" : "降")}, 设置 {ws} Pin 升, 设置 {_chamber.Name}{_pos} SlitDoor {(isOpen ? "开" : "关")}");
  368. if (_pos == EnumDualPM.Left || _pos == EnumDualPM.Both)
  369. {
  370. EV.PostInfoLog(Module,$"设置Pin:{isUp}");
  371. if (!_chamber.SetLiftPin1(isUp ? MovementPosition.Up : MovementPosition.Down, out string reason))
  372. {
  373. EV.PostAlarmLog(Module, $"设置Pin:{isUp} 失败");
  374. Stop(reason);
  375. return false;
  376. }
  377. if (GuidePinInstalled)
  378. {
  379. _chamber.PrepareGuidePinForPlaceLeft(ws);
  380. }
  381. EV.PostInfoLog(Module, $"设置门开");
  382. _chamber.SetSlitDoor1(isOpen, out string reason1);
  383. }
  384. if (_pos == EnumDualPM.Right || _pos == EnumDualPM.Both)
  385. {
  386. EV.PostInfoLog(Module, $"设置Pin:{isUp}");
  387. if (!_chamber.SetLiftPin2(isUp ? MovementPosition.Up : MovementPosition.Down, out string reason))
  388. {
  389. EV.PostAlarmLog(Module, $"设置Pin:{isUp} 失败");
  390. Stop(reason);
  391. return false;
  392. }
  393. if (GuidePinInstalled)
  394. {
  395. _chamber.PrepareGuidePinForPlaceRight(ws);
  396. }
  397. _chamber.SetSlitDoor2(isOpen, out string reason2);
  398. }
  399. return true;
  400. }
  401. bool CheckLiftPinAndSlitDoorAndGuidePin(bool isUp, WaferSize ws, bool isOpen, bool _guidePinInstalled)
  402. {
  403. bool Check1()
  404. {
  405. bool res1 = isUp ? _chamber.CheckLift1Up() : _chamber.CheckLift1Down();
  406. bool res2 = isOpen ? _chamber.CheckSlitDoor1Open() : _chamber.CheckSlitDoor1Close();
  407. bool res3 = _guidePinInstalled ? _chamber.CheckGuidePinIsReadyForTransferLeft(ws) : true;
  408. return res1 && res2 && res3;
  409. }
  410. bool Check2()
  411. {
  412. bool res1 = isUp ? _chamber.CheckLift2Up() : _chamber.CheckLift2Down();
  413. bool res2 = isOpen ? _chamber.CheckSlitDoor2Open() : _chamber.CheckSlitDoor2Close();
  414. bool res3 = _guidePinInstalled ? _chamber.CheckGuidePinIsReadyForTransferRight(ws) : true;
  415. return res1 && res2 && res3;
  416. }
  417. return ((_pos != EnumDualPM.Left && _pos != EnumDualPM.Both) || Check1()) && ((_pos != EnumDualPM.Right && _pos != EnumDualPM.Both) || Check2());
  418. }
  419. bool PMPreparePick()
  420. {
  421. if (_TransferType == EnumTransferType.Pick)
  422. {
  423. return SetLiftPinAndSlitDoorAndGuidePin(true, _ws, true, false);
  424. }
  425. return true;
  426. }
  427. bool CheckPMPreparePick()
  428. {
  429. if (_TransferType == EnumTransferType.Pick)
  430. {
  431. return CheckLiftPinAndSlitDoorAndGuidePin(true, _ws, true, false);
  432. }
  433. return true;
  434. }
  435. }
  436. }