MFPMPickRoutine.cs 10 KB

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