SEManualTransfer.cs 12 KB

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