MFPMPickRoutine.cs 13 KB

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