SEMFPMPickRoutine.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. }
  35. private readonly HongHuTM _tm;
  36. private readonly ITransferRobot _robot;
  37. private int _picktimeout = 60 * 1000;//1 min
  38. private int _pickdelay = 0;
  39. private ModuleName _targetModule;
  40. private Hand _hand;
  41. private int _targetSlot;
  42. private PMEntity _pmModule;
  43. private DateTime _starttime;
  44. private bool _queryAwc;
  45. public SEMFPMPickRoutine(HongHuTM honghutm,ITransferRobot robot) : base(ModuleName.TMRobot)
  46. {
  47. _tm = honghutm;
  48. _robot = robot;
  49. _queryAwc = false;
  50. }
  51. public RState Start(params object[] objs)
  52. {
  53. //_starttime = DateTime.Now;
  54. if (!_robot.IsHomed)
  55. {
  56. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  57. return RState.Failed;
  58. }
  59. var pickItem = (Queue<MoveItem>)objs[0];
  60. _targetModule = pickItem.Peek().SourceModule;
  61. _targetSlot = pickItem.Peek().SourceSlot;
  62. _hand = pickItem.Peek().RobotHand;
  63. if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  64. {
  65. _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
  66. }
  67. else
  68. {
  69. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for picking action");
  70. return RState.Failed;
  71. }
  72. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_hand))
  73. {
  74. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as TM Robot Arm: {_hand} already has a wafer");
  75. return RState.Failed;
  76. }
  77. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  78. {
  79. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as {_targetModule} Slot {_targetSlot + 1} has no wafer");
  80. return RState.Failed;
  81. }
  82. var wafer = WaferManager.Instance.GetWafer(_targetModule, _targetSlot);
  83. LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"{wafer.WaferOrigin} will be move from {_targetModule} {_targetSlot + 1} to TM Robot {_hand}");
  84. _picktimeout = SC.GetValue<int>("SETM.PickTimeout") * 1000;
  85. _pickdelay = SC.GetValue<int>($"{_targetModule}.PickDelayTime");
  86. Reset();
  87. return Runner.Start(Module, $"Pick from {_targetModule}");
  88. }
  89. public RState Monitor()
  90. {
  91. Runner.Wait(PickStep.WaitPMReady, () => _pmModule.IsIdle, _delay_60s)
  92. .Run(PickStep.PMPrepare, ModulePrepare, IsModulePrepareReady)
  93. .Run(PickStep.ArmExtend, ArmExtend, WaitRobotExtendDone)
  94. .Run(PickStep.QueryAWC, QueryAWC, WaitRobotQueryDone, _delay_1s)
  95. .Run(PickStep.DropDownWafer, NotifyPMPickWafer, WaitPMWaferDropDown)
  96. .Delay(PickStep.PickDelay, _pickdelay)
  97. .Run(PickStep.ArmRetract, ArmRetract, WaitRobotRetractDone)
  98. .Run(PickStep.SavePickeData, RecordAWCData, NullFun)
  99. .End(PickStep.NotifyDone, NotifyPMDone, _delay_50ms);
  100. return Runner.Status;
  101. }
  102. private bool ModulePrepare()
  103. {
  104. _pmModule.PostMsg(PMEntity.MSG.PreparePick);
  105. return true;
  106. }
  107. private bool IsModulePrepareReady()
  108. {
  109. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick && _pmModule.IsSlitDoorOpen;
  110. }
  111. private bool ArmExtend()
  112. {
  113. return _robot.PickExtend(_targetModule, _targetSlot, _hand);
  114. }
  115. private bool ArmRetract()
  116. {
  117. return _robot.PickRetract(_targetModule, _targetSlot, _hand);
  118. }
  119. private bool WaitRobotExtendDone()
  120. {
  121. if (_robot.Status == RState.Running)
  122. {
  123. return false;
  124. }
  125. else if (_robot.Status == RState.End)
  126. {
  127. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  128. return true;
  129. }
  130. else
  131. {
  132. Runner.Stop($"TM Robot Pick Extend failed, {_robot.Status}");
  133. return true;
  134. }
  135. }
  136. private bool QueryAWC()
  137. {
  138. if (!_queryAwc)
  139. return true;
  140. else
  141. return _robot.QueryAwc(); ;
  142. }
  143. private bool WaitRobotQueryDone()
  144. {
  145. if (!_queryAwc)
  146. return true;
  147. if (_robot.Status == RState.Running)
  148. {
  149. return false;
  150. }
  151. else if (_robot.Status == RState.End)
  152. {
  153. return true;
  154. }
  155. else
  156. {
  157. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  158. return true;
  159. }
  160. }
  161. private bool RecordAWCData()
  162. {
  163. if (!_queryAwc)
  164. return true;
  165. return true;
  166. }
  167. private bool NotifyPMPickWafer()
  168. {
  169. _pmModule.PostMsg(PMEntity.MSG.DropDownWafer);
  170. return true;
  171. }
  172. private bool WaitPMWaferDropDown()
  173. {
  174. return _pmModule.Status == PMEntity.PMStatus.Exchange_Ready;
  175. }
  176. private bool WaitRobotRetractDone()
  177. {
  178. if (_robot.Status == RState.Running)
  179. {
  180. return false;
  181. }
  182. else if (_robot.Status == RState.End)
  183. {
  184. return true;
  185. }
  186. else
  187. {
  188. Runner.Stop($"TM Robot Pick Retract failed, {_robot.Status}");
  189. return true;
  190. }
  191. }
  192. private bool NotifyPMDone()
  193. {
  194. _pmModule.PostMsg(PMEntity.MSG.PickReady);
  195. return true;
  196. }
  197. public void Abort()
  198. {
  199. _robot.Halt();
  200. }
  201. }
  202. }