MFPMPickRoutine.cs 11 KB

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