SEMFPMPlaceRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.Util;
  6. using Aitex.Sorter.Common;
  7. using MECF.Framework.Common.DBCore;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.Common.Schedulers;
  10. using MECF.Framework.Common.SubstrateTrackings;
  11. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  12. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TMs;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Reflection;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. using Venus_Core;
  20. using Venus_RT.Devices;
  21. using Venus_RT.Devices.TM;
  22. using Venus_RT.Modules.PMs;
  23. namespace Venus_RT.Modules.TM.VenusEntity
  24. {
  25. public class SEMFPMPlaceRoutine : ModuleRoutineBase, IRoutine
  26. {
  27. private enum PlaceStep
  28. {
  29. WaitPMReady,
  30. OpenMFSlitDoor,
  31. PMPrepare,
  32. ArmExtend,
  33. QueryAWC,
  34. LiftUpWafer,
  35. PlaceDelay,
  36. PlaceDelay1,
  37. PlaceDelay2,
  38. ArmRetract,
  39. SavePlaceData,
  40. NotifyDone,
  41. CloseDoor,
  42. EndDelay
  43. }
  44. private readonly TMBase _TM;
  45. private readonly ITransferRobot _robot;
  46. private int _ExtendTimeout = 120 * 1000;
  47. private int _RetractTimeout = 120 * 1000;
  48. private int _placeDelayTime = 0;
  49. private ModuleName _targetModule;
  50. private PMEntity _pmModule;
  51. private int _targetSlot;
  52. private Hand _hand;
  53. private DateTime _starttime;
  54. private bool _queryAwc;
  55. public SEMFPMPlaceRoutine(TMBase honghutm, ITransferRobot robot, ModuleName module) : base(module)
  56. {
  57. _TM = honghutm;
  58. _robot = robot;
  59. Name = "Place to PM";
  60. _queryAwc = false;
  61. }
  62. public RState Start(params object[] objs)
  63. {
  64. _starttime = DateTime.Now;
  65. if (!_robot.IsHomed)
  66. {
  67. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  68. return RState.Failed;
  69. }
  70. var placeItem = (Queue<MoveItem>)objs[0];
  71. _targetModule = placeItem.Peek().DestinationModule;
  72. _targetSlot = placeItem.Peek().DestinationSlot;
  73. _hand = placeItem.Peek().RobotHand;
  74. if (ModuleHelper.IsPm(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  75. {
  76. _pmModule = Singleton<RouteManager>.Instance.GetPM(_targetModule);
  77. }
  78. else
  79. {
  80. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for placing action");
  81. return RState.Failed;
  82. }
  83. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, (int)_hand))
  84. {
  85. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Place as TM Robot Arm: {_hand} has no wafer");
  86. return RState.Failed;
  87. }
  88. if (WaferManager.Instance.CheckHasWafer(_targetModule, _targetSlot))
  89. {
  90. LOG.Write(eEvent.ERR_TM, Module, $"Cannot Place as {_targetModule} Slot {_targetSlot + 1} already has a wafer");
  91. return RState.Failed;
  92. }
  93. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)_hand);
  94. LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"{wafer.WaferOrigin} will be move from TM Robot {_hand} to {_targetModule} {_targetSlot + 1}");
  95. Reset();
  96. _ExtendTimeout = SC.GetValue<int>($"{Module}.ExtendTimeout") * 1000;
  97. _RetractTimeout = SC.GetValue<int>($"{Module}.RetractTimeout") * 1000;
  98. _placeDelayTime = SC.GetValue<int>($"{_targetModule}.PlaceDelayTime");
  99. return Runner.Start(Module, $"Place to {_targetModule}");
  100. }
  101. public RState Monitor()
  102. {
  103. Runner.Wait(PlaceStep.WaitPMReady, PMPrepare, _delay_60s)
  104. .Run(PlaceStep.OpenMFSlitDoor, OpenSlitDoor, CheckSlitDoorOpen)
  105. .Run(PlaceStep.PMPrepare, ModulePrepare, IsModulePrepareReady, _delay_60s)
  106. .Delay(PlaceStep.PlaceDelay, _placeDelayTime)
  107. .Run(PlaceStep.ArmExtend, ArmExtend, WaitRobotExtendDone, _ExtendTimeout)
  108. .Run(PlaceStep.QueryAWC, QueryAWC, WaitRobotQueryDone, _delay_1s)
  109. .Run(PlaceStep.LiftUpWafer, NotifyPMPlaceWafer, WaitPMWaferLiftUp, _delay_30s)
  110. .Delay(PlaceStep.PlaceDelay1, _placeDelayTime)
  111. .Run(PlaceStep.ArmRetract, ArmRetract, WaitRobotRetractDone, _RetractTimeout)
  112. .Run(PlaceStep.SavePlaceData, RecordAWCData, NullFun)
  113. .Run(PlaceStep.CloseDoor, PMDoorClose, WaitPMDoorClose)
  114. .Run(PlaceStep.NotifyDone, NotifyPMDone, _delay_50ms)
  115. .Delay(PlaceStep.PlaceDelay2, _delay_50ms)
  116. .End(PlaceStep.EndDelay, NullFun, _delay_50ms);
  117. return Runner.Status;
  118. }
  119. private bool PMPrepare()
  120. {
  121. return IsPressureReady(_targetModule) && _pmModule.IsIdle;
  122. }
  123. private bool IsPressureReady(ModuleName _targetModule)
  124. {
  125. if (RouteManager.IsATMMode)
  126. return true;
  127. if (_pmModule.IsOnline)
  128. {
  129. double PMPressure = _pmModule.ProcessPressure;
  130. double ControlPressure = SC.GetValue<int>($"{_targetModule}.ControlPressureSetPoint");
  131. double range = SC.GetValue<int>($"{_targetModule}.ControlPressureOffset");
  132. if ((PMPressure >= (ControlPressure - range)) && (PMPressure <= (ControlPressure + range)))
  133. {
  134. return true;
  135. }
  136. else return false;
  137. }else return true;
  138. }
  139. private bool OpenSlitDoor()
  140. {
  141. return _TM.TurnSlitDoor(_targetModule, true);
  142. }
  143. private bool CheckSlitDoorOpen()
  144. {
  145. return _TM.CheckSlitValveOpen(_targetModule);
  146. }
  147. private bool ModulePrepare()
  148. {
  149. _pmModule.PostMsg(PMEntity.MSG.PreparePlace);
  150. //_TM.TurnSlitDoor(_targetModule, true);
  151. return true;
  152. }
  153. private bool IsModulePrepareReady()
  154. {
  155. return _pmModule.Status == PMEntity.PMStatus.Ready_For_Place && _pmModule.IsSlitDoorOpen;
  156. }
  157. private bool ArmExtend()
  158. {
  159. if (!_pmModule.IsSlitDoorOpen)
  160. {
  161. LOG.Write(eEvent.ERR_TM, Module, $"Cannot place as {_targetModule} Door is not Open");
  162. return false;
  163. }
  164. return _robot.PlaceExtend(_targetModule, _targetSlot, _hand);
  165. }
  166. private bool ArmRetract()
  167. {
  168. return _robot.PlaceRetract(_targetModule, _targetSlot, _hand);
  169. }
  170. private bool QueryAWC()
  171. {
  172. if (!_queryAwc)
  173. return true;
  174. else
  175. return _robot.QueryAwc();
  176. }
  177. private bool WaitRobotExtendDone()
  178. {
  179. if (_robot.Status == RState.Running)
  180. {
  181. return false;
  182. }
  183. else if (_robot.Status == RState.End)
  184. {
  185. return true;
  186. }
  187. else
  188. {
  189. Runner.Stop($"TM Robot Place Extend failed, {_robot.Status}");
  190. Singleton<RouteManager>.Instance.GetPM(_targetModule).PostMsg(PMEntity.MSG.Error);
  191. return true;
  192. }
  193. }
  194. private bool RecordAWCData()
  195. {
  196. if (!_queryAwc)
  197. return true;
  198. //已经move后的数据
  199. string _origin_module = $"LP{WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginStation}";
  200. int _origin_slot = WaferManager.Instance.GetWafer(_targetModule, _targetSlot).OriginSlot;
  201. //查询完毕 插入数据
  202. OffsetDataRecorder.RecordOffsetData(
  203. Guid.NewGuid().ToString(),
  204. ModuleName.TMRobot, 0,
  205. _targetModule, _targetSlot,
  206. _origin_module, _origin_slot,
  207. _hand, RobotArmPan.None,
  208. _robot.Offset_X, _robot.Offset_Y, _robot.Offset_D,
  209. _starttime, DateTime.Now);
  210. return true;
  211. }
  212. private bool WaitRobotQueryDone()
  213. {
  214. if (!_queryAwc)
  215. return true;
  216. if (_robot.Status == RState.Running)
  217. {
  218. return false;
  219. }
  220. else if (_robot.Status == RState.End)
  221. {
  222. return true;
  223. }
  224. else
  225. {
  226. Runner.Stop($"TM Robot Query Awc failed, {_robot.Status}");
  227. Singleton<RouteManager>.Instance.GetPM(_targetModule).PostMsg(PMEntity.MSG.Error);
  228. return true;
  229. }
  230. }
  231. private bool NotifyPMPlaceWafer()
  232. {
  233. _pmModule.PostMsg(PMEntity.MSG.LiftUpWafer);
  234. return true;
  235. }
  236. private bool WaitPMWaferLiftUp()
  237. {
  238. return _pmModule.Status == PMEntity.PMStatus.Exchange_Ready;
  239. }
  240. private bool WaitRobotRetractDone()
  241. {
  242. if (_robot.Status == RState.Running)
  243. {
  244. return false;
  245. }
  246. else if (_robot.Status == RState.End)
  247. {
  248. WaferManager.Instance.WaferMoved(ModuleName.TMRobot, (int)_hand, _targetModule, _targetSlot);
  249. return true;
  250. }
  251. else
  252. {
  253. Runner.Stop($"TM Robot Place Retract failed, {_robot.Status}");
  254. Singleton<RouteManager>.Instance.GetPM(_targetModule).PostMsg(PMEntity.MSG.Error);
  255. return true;
  256. }
  257. }
  258. private bool NotifyPMDone()
  259. {
  260. _pmModule.PostMsg(PMEntity.MSG.PlaceReady);
  261. //_TM.TurnSlitDoor(_targetModule, false);
  262. return true;
  263. }
  264. private bool PMDoorClose()
  265. {
  266. //LOG.Write(eEvent.WARN_TM, Module, $"PMPlace Close Door Again");
  267. return _TM.TurnSlitDoor(_targetModule, false);
  268. }
  269. private bool WaitPMDoorClose()
  270. {
  271. if (_TM.CheckSlitValveClose(_targetModule))
  272. {
  273. //LOG.Write(eEvent.WARN_TM, Module, $"PMPlace Check Door Close");
  274. return true;
  275. }
  276. else
  277. {
  278. //LOG.Write(eEvent.WARN_TM, Module, $"PMPlace Check not Close Door");
  279. return false;
  280. }
  281. }
  282. public void Abort()
  283. {
  284. //_robot.Halt();
  285. }
  286. }
  287. }