SEManualTransfer.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 int _tmRobotSingleArmOption = 0;//usable wafer
  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. }
  160. }
  161. }