SEManualTransfer.cs 11 KB

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