SEMFPMPickRoutine.cs 8.4 KB

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