SEManualTransfer.cs 11 KB

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