SEMFPMPickRoutine.cs 9.2 KB

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