SEManualTransfer.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.Device.Unit;
  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.Equipment;
  9. using MECF.Framework.Common.Schedulers;
  10. using MECF.Framework.Common.SubstrateTrackings;
  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.Modules.Schedulers;
  18. namespace Venus_RT.Modules
  19. {
  20. public class SEManualTransfer : IRoutine
  21. {
  22. SchedulerSETMRobot _tmrobot = (SchedulerSETMRobot)Singleton<TransferModule>.Instance.GetScheduler(ModuleName.SETM);
  23. private List<MoveItem> _moveQueue = new List<MoveItem>();
  24. private MovingStatus _moving_status = MovingStatus.Idle;
  25. private RState _transferstate = RState.Init;
  26. private ModuleName source_station;
  27. private int source_slot;
  28. private ModuleName destination_station;
  29. private int destination_slot;
  30. private ModuleName original_station;
  31. private int original_slot;
  32. private float align_angle;
  33. public SEManualTransfer()
  34. {
  35. }
  36. public RState Start(params object[] objs)
  37. {
  38. _moveQueue.Clear();
  39. // obj is enable && robot is usable
  40. if (objs.Length > 6)
  41. {
  42. _transferstate = RState.Running;
  43. //get where we from and where we go
  44. source_station = (ModuleName)Enum.Parse(typeof(ModuleName),objs[0].ToString());
  45. source_slot = Convert.ToInt32(objs[1]);
  46. destination_station = (ModuleName)Enum.Parse(typeof(ModuleName), objs[2].ToString());
  47. destination_slot = Convert.ToInt32(objs[3]);
  48. WaferInfo waferInfo = WaferManager.Instance.GetWafer(source_station,source_slot);
  49. original_station = (ModuleName)waferInfo.OriginStation;
  50. original_slot = waferInfo.OriginSlot;
  51. if ((bool)objs[4])
  52. {
  53. align_angle = float.Parse(objs[5].ToString());
  54. _moving_status = MovingStatus.WaitAlign;
  55. }
  56. else
  57. _moving_status = MovingStatus.Waiting;
  58. if (ModuleHelper.IsVCE(source_station) && _tmrobot.IsVCESlitDoorClosed)
  59. {
  60. LOG.Write(eEvent.ERR_TM, ModuleName.TMRobot, $"cannot transfer from {source_station} as VCE InnerDoor is close.");
  61. _transferstate = RState.Failed;
  62. }
  63. if (ModuleHelper.IsVCE(destination_station) && _tmrobot.IsVCESlitDoorClosed)
  64. {
  65. LOG.Write(eEvent.ERR_TM, ModuleName.TMRobot, $"cannot transfer to {destination_station} as VCE InnerDoor is close.");
  66. _transferstate = RState.Failed;
  67. }
  68. //from tm to tm
  69. if (source_station == destination_station && ModuleHelper.IsTMRobot(source_station))
  70. {
  71. LOG.Write(eEvent.ERR_TM,ModuleName.TMRobot,"cannot transfer from TMRobot to TMRobot.");
  72. _transferstate = RState.Failed;
  73. }
  74. if(WaferManager.Instance.CheckNoWafer(source_station,source_slot))
  75. {
  76. LOG.Write(eEvent.ERR_TM, ModuleName.TMRobot, "cannot transfer cause wafer has no wafer.");
  77. _transferstate = RState.Failed;
  78. }
  79. if (WaferManager.Instance.CheckHasWafer(destination_station, destination_slot))
  80. {
  81. LOG.Write(eEvent.ERR_TM, ModuleName.TMRobot, "cannot transfer cause wafer has wafer.");
  82. _transferstate = RState.Failed;
  83. }
  84. }
  85. else
  86. {
  87. _transferstate = RState.Failed;
  88. }
  89. return _transferstate;
  90. }
  91. public RState Monitor()
  92. {
  93. //if tm is free
  94. if (_tmrobot.IsAvailable)
  95. {
  96. CheckTransferOver();
  97. WaferNextGoto();
  98. TMRobotTask();
  99. }
  100. return _transferstate;
  101. }
  102. private void CheckTransferOver()
  103. {
  104. //when the transfer is over?
  105. //the wafer has arrived the targetModule and targetSlot
  106. if (WaferManager.Instance.CheckHasWafer(destination_station,destination_slot)
  107. && (ModuleName)WaferManager.Instance.GetWafer(destination_station, destination_slot).OriginStation == original_station
  108. && WaferManager.Instance.GetWafer(destination_station, destination_slot).OriginSlot == original_slot)
  109. {
  110. _moving_status = MovingStatus.Idle;
  111. _transferstate = RState.End;
  112. }
  113. }
  114. private void WaferNextGoto()
  115. {
  116. switch(_moving_status)
  117. {
  118. case MovingStatus.WaitAlign:
  119. _moveQueue.Add(new MoveItem(source_station, source_slot, ModuleName.VPA, 0, 0));
  120. _moving_status = MovingStatus.StartAlign;
  121. break;
  122. case MovingStatus.StartAlign:
  123. _tmrobot.Align(align_angle);
  124. _moving_status = MovingStatus.Aligning;
  125. break;
  126. case MovingStatus.Aligning:
  127. _moveQueue.Add(new MoveItem(ModuleName.VPA, 0, destination_station, destination_slot, 0));
  128. break;
  129. //goto slot need to go
  130. case MovingStatus.Waiting:
  131. _moveQueue.Add(new MoveItem(source_station, source_slot, destination_station, destination_slot, 0));
  132. break;
  133. }
  134. }
  135. private void TMRobotTask()
  136. {
  137. if (_tmrobot.IsAvailable)
  138. {
  139. if (_moveQueue.Count > 0 && _tmrobot.PostMoveItems(_moveQueue.ToArray()))
  140. {
  141. foreach (var item in _moveQueue)
  142. {
  143. var wafer = WaferManager.Instance.GetWafer(item.SourceModule, item.SourceSlot);
  144. if (wafer.IsEmpty && _tmrobot.IsAvailable)
  145. {
  146. // post alarm
  147. _transferstate = RState.Failed;
  148. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Cannot run TM moving task as Get {item.SourceModule}{item.SourceSlot} Wafer Info failed");
  149. return;
  150. }
  151. }
  152. _moveQueue.Clear();
  153. }
  154. }
  155. }
  156. public void Abort()
  157. {
  158. }
  159. }
  160. public class SEReturnWafer : IRoutine
  161. {
  162. //target:
  163. //1. 1 wafer return as a Queue
  164. //2. all wafers return as a Queue
  165. private SEManualTransfer _transfer = null;
  166. private Queue<MoveItem> _ReturnQueue = new Queue<MoveItem> ();//all wafer enqueue
  167. private List<ModuleName> modulelist = new List<ModuleName>();
  168. private bool _alignflag;
  169. private float _alignangle;
  170. public SEReturnWafer(SEManualTransfer transfer)
  171. {
  172. _transfer = transfer;
  173. string[] InstalledModules = SC.GetStringValue("System.InstalledModules").ToString().Split(',');
  174. foreach (string module in InstalledModules)
  175. {
  176. //module without vce
  177. if(Enum.TryParse(module,out ModuleName mod) && !ModuleHelper.IsVCE(mod) && mod!=ModuleName.SETM)
  178. modulelist.Add(mod);
  179. }
  180. }
  181. public RState Start(params object[] objs)
  182. {
  183. _ReturnQueue.Clear();
  184. //单个wafer
  185. if (objs.Length >= 4)
  186. {
  187. if (bool.TryParse(objs[2].ToString(), out bool alignflag) && float.TryParse(objs[3].ToString(), out float alignangle))
  188. {
  189. _alignflag = alignflag;
  190. _alignangle = alignangle;
  191. }
  192. }
  193. //all wafer return
  194. AllWaferBack();
  195. return RState.Running;
  196. }
  197. public RState Monitor()
  198. {
  199. while (_ReturnQueue.Count > 0 || _transfer.Monitor() == RState.Running)
  200. {
  201. switch (_transfer.Monitor())
  202. {
  203. case RState.Init:
  204. case RState.End:
  205. MoveItem moveItem = _ReturnQueue.Dequeue();
  206. return _transfer.Start(moveItem.SourceModule,moveItem.SourceSlot,moveItem.DestinationModule,moveItem.DestinationSlot, _alignflag, _alignangle, false,1,"");
  207. case RState.Running:
  208. return RState.Running;
  209. case RState.Timeout:
  210. case RState.Failed:
  211. return RState.Failed;
  212. }
  213. }
  214. return RState.End;
  215. }
  216. private void AllWaferBack()
  217. {
  218. //Firstly,robot wafer back
  219. //Then,chamber wafer back
  220. CheckWaferEnqueue(ModuleName.TMRobot, 0);
  221. CheckWaferEnqueue(ModuleName.TMRobot, 1);
  222. foreach (ModuleName mod in modulelist)
  223. {
  224. if (mod == ModuleName.TMRobot)
  225. continue;
  226. else
  227. CheckWaferEnqueue(mod,0);
  228. }
  229. }
  230. //wafer back vce
  231. //1. has wafer
  232. //2. vce isinstalled and slot no wafer
  233. //3. robot check hand && chamber check 0
  234. private void CheckWaferEnqueue(ModuleName source_module,int source_slot)
  235. {
  236. if (WaferManager.Instance.CheckHasWafer(source_module, source_slot))
  237. {
  238. WaferInfo waferInfo = WaferManager.Instance.GetWafer(source_module, source_slot);
  239. if (ModuleHelper.IsVCE((ModuleName)waferInfo.OriginStation)
  240. && ModuleHelper.IsInstalled((ModuleName)waferInfo.OriginStation)
  241. && WaferManager.Instance.CheckNoWafer((ModuleName)waferInfo.OriginStation, waferInfo.OriginSlot))
  242. {
  243. if(source_module == ModuleName.TMRobot)
  244. _ReturnQueue.Enqueue(new MoveItem(source_module, source_slot, (ModuleName)waferInfo.OriginStation, waferInfo.OriginSlot, (Hand)source_slot));
  245. else
  246. _ReturnQueue.Enqueue(new MoveItem(source_module, source_slot, (ModuleName)waferInfo.OriginStation, waferInfo.OriginSlot, 0));
  247. }
  248. }
  249. }
  250. public void Abort()
  251. {
  252. }
  253. }
  254. }