MFPMPickRoutine.cs 9.6 KB

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