MFPMPickRoutine.cs 11 KB

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