SEMFPMPickRoutine.cs 7.7 KB

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