SEMFPMPickRoutine.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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, PMPrepare, _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 PMPrepare()
  124. {
  125. return IsPressureReady(_targetModule) && _pmModule.IsIdle;
  126. }
  127. private bool IsPressureReady(ModuleName _targetModule)
  128. {
  129. if (RouteManager.IsATMMode)
  130. return true;
  131. if (_pmModule.IsOnline)
  132. {
  133. double PMPressure = _pmModule.ProcessPressure;
  134. double ControlPressure = SC.GetValue<int>($"{_targetModule}.ControlPressureSetPoint");
  135. double range = SC.GetValue<int>($"{_targetModule}.ControlPressureOffset");
  136. if ((PMPressure >= (ControlPressure - range)) && (PMPressure <= (ControlPressure + range)))
  137. {
  138. return true;
  139. }
  140. else return false;
  141. }
  142. else return true;
  143. }
  144. private bool OpenSlitDoor()
  145. {
  146. return _tm.TurnSlitDoor(_targetModule,true);
  147. }
  148. private bool CheckSlitDoorOpen()
  149. {
  150. return _tm.CheckSlitValveOpen(_targetModule);
  151. }
  152. private bool ModulePrepare()
  153. {
  154. _pmModule.PostMsg(PMEntity.MSG.PreparePick);
  155. return true;
  156. }
  157. private bool IsModulePrepareReady()
  158. {
  159. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Pick;
  160. }
  161. private bool ArmExtend()
  162. {
  163. if (!_pmModule.IsSlitDoorOpen)
  164. {
  165. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as {_targetModule} Door is not Open");
  166. return false;
  167. }
  168. return _robot.PickExtend(_targetModule, _targetSlot, _hand);
  169. }
  170. private bool ArmRetract()
  171. {
  172. return _robot.PickRetract(_targetModule, _targetSlot, _hand);
  173. }
  174. private bool WaitRobotExtendDone()
  175. {
  176. if (_robot.Status == RState.Running)
  177. {
  178. return false;
  179. }
  180. else if (_robot.Status == RState.End)
  181. {
  182. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  183. return true;
  184. }
  185. else
  186. {
  187. Runner.Stop($"TM Robot Pick Extend failed, {_robot.Status}");
  188. Singleton<RouteManager>.Instance.GetPM(_targetModule).PostMsg(PMEntity.MSG.Error);
  189. return true;
  190. }
  191. }
  192. private bool QueryAWC()
  193. {
  194. if (!_queryAwc)
  195. return true;
  196. else
  197. return _robot.QueryAwc(); ;
  198. }
  199. private bool WaitRobotQueryDone()
  200. {
  201. if (!_queryAwc)
  202. return true;
  203. if (_robot.Status == RState.Running)
  204. {
  205. return false;
  206. }
  207. else if (_robot.Status == RState.End)
  208. {
  209. return true;
  210. }
  211. else
  212. {
  213. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  214. Singleton<RouteManager>.Instance.GetPM(_targetModule).PostMsg(PMEntity.MSG.Error);
  215. return true;
  216. }
  217. }
  218. private bool RecordAWCData()
  219. {
  220. if (!_queryAwc)
  221. return true;
  222. return true;
  223. }
  224. private bool NotifyPMPickWafer()
  225. {
  226. _pmModule.PostMsg(PMEntity.MSG.DropDownWafer);
  227. return true;
  228. }
  229. private bool WaitPMWaferDropDown()
  230. {
  231. return _pmModule.Status == PMEntity.PMStatus.Exchange_Ready;
  232. }
  233. private bool WaitRobotRetractDone()
  234. {
  235. if (_robot.Status == RState.Running)
  236. {
  237. return false;
  238. }
  239. else if (_robot.Status == RState.End)
  240. {
  241. return true;
  242. }
  243. else
  244. {
  245. Runner.Stop($"TM Robot Pick Retract failed, {_robot.Status}");
  246. Singleton<RouteManager>.Instance.GetPM(_targetModule).PostMsg(PMEntity.MSG.Error);
  247. return true;
  248. }
  249. }
  250. private bool NotifyPMDone()
  251. {
  252. _pmModule.PostMsg(PMEntity.MSG.PickReady);
  253. return true;
  254. }
  255. private bool PMDoorClose()
  256. {
  257. LOG.Write(eEvent.WARN_TM, Module, $"PMPick Close Door Again");
  258. return _tm.TurnSlitDoor(_targetModule, false);
  259. }
  260. private bool WaitPMDoorClose()
  261. {
  262. if (_tm.CheckSlitValveClose(_targetModule))
  263. {
  264. LOG.Write(eEvent.WARN_TM, Module, $"PMPick Check Door Close");
  265. return true;
  266. }
  267. else
  268. {
  269. LOG.Write(eEvent.WARN_TM, Module, $"PMPick Check not Close Door");
  270. return false;
  271. }
  272. }
  273. public void Abort()
  274. {
  275. //_robot.Halt();
  276. }
  277. }
  278. }