MFPMPickRoutine.cs 12 KB

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