MFPMPickRoutine.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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 = 120 * 1000;
  52. private int _liftPinTimeout = 20 * 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. return false;
  201. }
  202. else if (_robot.Status == RState.End)
  203. {
  204. //WaferManager.Instance.WaferMoved(ModuleName.TM, (int)_hand, _targetModule, _targetSlot);
  205. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  206. return true;
  207. }
  208. else
  209. {
  210. WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  211. Runner.Stop($"TM Robot Picking failed, {_robot.Status}");
  212. return true;
  213. }
  214. }
  215. private bool ArmExtend()
  216. {
  217. return _robot.PickExtend(_targetModule, _targetSlot, _hand);
  218. }
  219. private bool ArmRetract()
  220. {
  221. return _robot.PickRetract(_targetModule, _targetSlot, _hand);
  222. }
  223. private bool WaitRobotExtendDone()
  224. {
  225. if (_robot.Status == RState.Running)
  226. {
  227. return false;
  228. }
  229. else if (_robot.Status == RState.End)
  230. {
  231. return true;
  232. }
  233. else
  234. {
  235. Runner.Stop($"TM Robot Pick Extend failed, {_robot.Status}");
  236. return true;
  237. }
  238. }
  239. private bool QueryAWC()
  240. {
  241. if (!_queryAwc)
  242. return true;
  243. else
  244. return _robot.QueryAwc(); ;
  245. }
  246. private bool WaitRobotQueryDone()
  247. {
  248. if (!_queryAwc)
  249. return true;
  250. if (_robot.Status == RState.Running)
  251. {
  252. return false;
  253. }
  254. else if (_robot.Status == RState.End)
  255. {
  256. return true;
  257. }
  258. else
  259. {
  260. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  261. return true;
  262. }
  263. }
  264. private bool RecordAWCData()
  265. {
  266. if (!_queryAwc)
  267. return true;
  268. //已经move后的数据
  269. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  270. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  271. //查询完毕 插入数据
  272. OffsetDataRecorder.RecordOffsetData(
  273. Guid.NewGuid().ToString(),
  274. _targetModule, _targetSlot,
  275. ModuleName.TMRobot, 0,
  276. _origin_module, _origin_slot,
  277. _hand, RobotArmPan.None,
  278. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  279. _starttime, DateTime.Now);
  280. return true;
  281. }
  282. //private bool CheckAwc()
  283. //{
  284. // if (Math.Abs(_robot.Offset_D) > awcAlarmRange * 1000)
  285. // {
  286. // Stop($"Check AWC 失败, 当前 AWC [{_robot.Offset_D}um], 高于Alarm最大值: [{awcAlarmRange}mm]");
  287. // return false;
  288. // }
  289. // if (Math.Abs(_robot.Offset_D) > awcWarningRange * 1000)
  290. // {
  291. // Stop($"Check AWC 报警, 当前 AWC [{_robot.Offset_D}um], 高于Warning最大值: [{awcWarningRange}mm]");
  292. // }
  293. // return true;
  294. //}
  295. private bool NotifyPMPickWafer()
  296. {
  297. _pmModule.PostMsg(PMEntity.MSG.DropDownWafer);
  298. return true;
  299. }
  300. private bool WaitPMWaferDropDown()
  301. {
  302. if (_pmModule.Status == PMEntity.PMStatus.Exchange_Ready)
  303. {
  304. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  305. return true;
  306. }
  307. else if (Runner.StepElapsedMS > _liftPinTimeout)
  308. {
  309. WaferManager.Instance.CreateDuplicatedWafer(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  310. Runner.Stop($"Wait {_targetModule} Lift Pin down timeout, {Runner.StepElapsedMS}");
  311. }
  312. return false;
  313. }
  314. private bool WaitRobotRetractDone()
  315. {
  316. if (_robot.Status == RState.Running)
  317. {
  318. return false;
  319. }
  320. else if (_robot.Status == RState.End)
  321. {
  322. return true;
  323. }
  324. else
  325. {
  326. Runner.Stop($"TM Robot Pick Retract failed, {_robot.Status}");
  327. return true;
  328. }
  329. }
  330. private bool NotifyPMDone()
  331. {
  332. _pmModule.PostMsg(PMEntity.MSG.PickReady);
  333. return true;
  334. }
  335. public void Abort()
  336. {
  337. _robot.Halt();
  338. }
  339. }
  340. }