SEManualTransfer.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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)
  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. _moveQueue.Add(new MoveItem(ModuleName.VPA, 0, destination_station, destination_slot, 0));
  129. break;
  130. //goto slot need to go
  131. case MovingStatus.Waiting:
  132. _moveQueue.Add(new MoveItem(source_station, source_slot, destination_station, destination_slot, 0));
  133. break;
  134. }
  135. }
  136. private void TMRobotTask()
  137. {
  138. if (_tmrobot.IsAvailable)
  139. {
  140. if (_moveQueue.Count > 0 && _tmrobot.PostMoveItems(_moveQueue.ToArray()))
  141. {
  142. foreach (var item in _moveQueue)
  143. {
  144. var wafer = WaferManager.Instance.GetWafer(item.SourceModule, item.SourceSlot);
  145. if (wafer.IsEmpty && _tmrobot.IsAvailable)
  146. {
  147. // post alarm
  148. _transferstate = RState.Failed;
  149. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Cannot run TM moving task as Get {item.SourceModule}{item.SourceSlot} Wafer Info failed");
  150. return;
  151. }
  152. }
  153. _moveQueue.Clear();
  154. }
  155. }
  156. }
  157. public void Abort()
  158. {
  159. _transferstate = RState.End;
  160. _tmrobot._entityTaskToken = (int)FSM_MSG.NONE;
  161. _moveQueue.Clear();
  162. _moving_status = MovingStatus.Idle;
  163. }
  164. }
  165. public class SEReturnWafer : IRoutine
  166. {
  167. //target:
  168. //1. 1 wafer return as a Queue
  169. //2. all wafers return as a Queue
  170. private SEManualTransfer _transfer = null;
  171. private Queue<MoveItem> _ReturnQueue = new Queue<MoveItem> ();//all wafer enqueue
  172. private List<ModuleName> modulelist = new List<ModuleName>();
  173. private bool _alignflag;
  174. private float _alignangle;
  175. public SEReturnWafer(SEManualTransfer transfer)
  176. {
  177. _transfer = transfer;
  178. string[] InstalledModules = SC.GetStringValue("System.InstalledModules").ToString().Split(',');
  179. foreach (string module in InstalledModules)
  180. {
  181. //module without vce
  182. if(Enum.TryParse(module,out ModuleName mod) && !ModuleHelper.IsVCE(mod) && mod!=ModuleName.SETM)
  183. modulelist.Add(mod);
  184. }
  185. }
  186. public RState Start(params object[] objs)
  187. {
  188. _ReturnQueue.Clear();
  189. //单个wafer
  190. if (objs.Length >= 4)
  191. {
  192. if (bool.TryParse(objs[2].ToString(), out bool alignflag) && float.TryParse(objs[3].ToString(), out float alignangle))
  193. {
  194. _alignflag = alignflag;
  195. _alignangle = alignangle;
  196. }
  197. }
  198. //all wafer return
  199. AllWaferBack();
  200. return RState.Running;
  201. }
  202. public RState Monitor()
  203. {
  204. while (_ReturnQueue.Count > 0 || _transfer.Monitor() == RState.Running)
  205. {
  206. switch (_transfer.Monitor())
  207. {
  208. case RState.Init:
  209. case RState.End:
  210. MoveItem moveItem = _ReturnQueue.Dequeue();
  211. return _transfer.Start(moveItem.SourceModule,moveItem.SourceSlot,moveItem.DestinationModule,moveItem.DestinationSlot, _alignflag, _alignangle, false,1,"");
  212. case RState.Running:
  213. return RState.Running;
  214. case RState.Timeout:
  215. case RState.Failed:
  216. return RState.Failed;
  217. }
  218. }
  219. return RState.End;
  220. }
  221. private void AllWaferBack()
  222. {
  223. //Firstly,robot wafer back
  224. //Then,chamber wafer back
  225. CheckWaferEnqueue(ModuleName.TMRobot, 0);
  226. CheckWaferEnqueue(ModuleName.TMRobot, 1);
  227. foreach (ModuleName mod in modulelist)
  228. {
  229. if (mod == ModuleName.TMRobot)
  230. continue;
  231. else
  232. CheckWaferEnqueue(mod,0);
  233. }
  234. }
  235. //wafer back vce
  236. //1. has wafer
  237. //2. vce isinstalled and slot no wafer
  238. //3. robot check hand && chamber check 0
  239. private void CheckWaferEnqueue(ModuleName source_module,int source_slot)
  240. {
  241. if (WaferManager.Instance.CheckHasWafer(source_module, source_slot))
  242. {
  243. WaferInfo waferInfo = WaferManager.Instance.GetWafer(source_module, source_slot);
  244. if (ModuleHelper.IsVCE((ModuleName)waferInfo.OriginStation)
  245. && ModuleHelper.IsInstalled((ModuleName)waferInfo.OriginStation)
  246. && WaferManager.Instance.CheckNoWafer((ModuleName)waferInfo.OriginStation, waferInfo.OriginSlot))
  247. {
  248. if(source_module == ModuleName.TMRobot)
  249. _ReturnQueue.Enqueue(new MoveItem(source_module, source_slot, (ModuleName)waferInfo.OriginStation, waferInfo.OriginSlot, (Hand)source_slot));
  250. else
  251. _ReturnQueue.Enqueue(new MoveItem(source_module, source_slot, (ModuleName)waferInfo.OriginStation, waferInfo.OriginSlot, 0));
  252. }
  253. }
  254. }
  255. public void Abort()
  256. {
  257. _transfer.Abort();
  258. _ReturnQueue.Clear();
  259. }
  260. }
  261. }