SchedulerEfemRobot.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Diagnostics;
  7. using Aitex.Core.RT.Fsm;
  8. using Aitex.Core.RT.Log;
  9. using Aitex.Core.Util;
  10. using Aitex.Sorter.Common;
  11. using VirgoRT.Modules;
  12. using MECF.Framework.Common.Equipment;
  13. using MECF.Framework.Common.SubstrateTrackings;
  14. namespace VirgoRT.Scheduler
  15. {
  16. public class SchedulerEfemRobot : SchedulerModule
  17. {
  18. public override bool IsAvailable
  19. {
  20. get { return _entity.IsIdle && /*_entity.IsOnline && */CheckTaskDone(); }
  21. }
  22. public override bool IsOnline
  23. {
  24. get { return _entity.IsOnline; }
  25. }
  26. public override bool IsError
  27. {
  28. get { return _entity.IsError; }
  29. }
  30. private EfemEntity _entity = null;
  31. private Hand _hand;
  32. private int _entityTaskToken = (int)FSM_MSG.NONE;
  33. private Hand _taskSwapPickHand;
  34. private Hand _taskSwapPlaceHand;
  35. private int _taskSwapPickSlot;
  36. private int _taskSwapPlaceSlot;
  37. private ModuleName _alignModule;
  38. private float _paramCoolingTime = 0;
  39. private Stopwatch _timerDelay = new Stopwatch();
  40. public ModuleName PreviousTarget { get; set; }
  41. public SchedulerEfemRobot() : base(ModuleName.EfemRobot.ToString())
  42. {
  43. _entity = Singleton<RouteManager>.Instance.EFEM;
  44. PreviousTarget = ModuleName.System;
  45. }
  46. public bool IsReadyForPick(Hand blade)
  47. {
  48. return WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)blade);
  49. }
  50. public bool IsReadyForPlace(Hand blade)
  51. {
  52. return WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)blade);
  53. }
  54. public bool Pick(ModuleName source, int slot, Hand hand)
  55. {
  56. _task = TaskType.Pick;
  57. _hand = hand;
  58. _entityTaskToken = _entity.InvokePick(source, slot, hand, WaferManager.Instance.GetWafer(source, slot).Size);
  59. PreviousTarget = source;
  60. LogTaskStart(_task, $"{source}.{slot + 1}=>{Module}.{hand}");
  61. return true;
  62. }
  63. public bool Place(ModuleName destination, int slot, Hand hand)
  64. {
  65. _task = TaskType.Place;
  66. _hand = hand;
  67. _entityTaskToken = _entity.InvokePlace(destination, slot, hand,
  68. WaferManager.Instance.GetWafer(ModuleName.EfemRobot, hand==Hand.Blade1 ? 0:1).Size);
  69. PreviousTarget = destination;
  70. LogTaskStart(_task, $"{Module}.{hand}=>{destination}.{slot + 1}");
  71. return true;
  72. }
  73. public bool PickAndPlace(ModuleName target, int pickSlot, int placeSlot, Hand pickHand, Hand placeHand)
  74. {
  75. PreviousTarget = target;
  76. _task = TaskType.PickAndPlace;
  77. _taskSwapPickHand = pickHand;
  78. _taskSwapPlaceHand = placeHand;
  79. _taskSwapPickSlot = pickSlot;
  80. _taskSwapPlaceSlot = placeSlot;
  81. _entityTaskToken = _entity.InvokePickAndPlace(target, pickHand, pickSlot, placeHand, placeSlot, WaferManager.Instance.GetWafer(target, pickSlot).Size);
  82. LogTaskStart(_task, $" {target}.{pickSlot + 1}=>{Module}.{pickHand} && {Module}.{placeHand}=>{target}.{placeSlot + 1}");
  83. return true;
  84. }
  85. public bool Goto(ModuleName target, int slot )
  86. {
  87. _task = TaskType.Goto;
  88. _entityTaskToken = _entity.InvokeGoto(target, slot );
  89. PreviousTarget = target;
  90. LogTaskStart(_task, $"Robot goto {target}.{slot + 1}");
  91. return true;
  92. }
  93. public bool Map(ModuleName destination )
  94. {
  95. _task = TaskType.Map;
  96. _entityTaskToken = _entity.InvokeMap(destination.ToString());
  97. LogTaskStart(_task, $"{Module} mapping");
  98. PreviousTarget = destination;
  99. return true;
  100. }
  101. public override bool Align(ModuleName aligner, float time)
  102. {
  103. _alignModule = aligner;
  104. _task = TaskType.Align;
  105. LogTaskStart(_task, $"Aligning");
  106. _paramCoolingTime = time;
  107. _timerDelay.Restart();
  108. if (_entity.EFEMType == EfemEntity.EfemType.BrooksEFEM || _entity.EFEMType == EfemEntity.EfemType.BeamSUNWAY)
  109. {
  110. _entityTaskToken = _entity.InvokeAlign(aligner.ToString(), time);
  111. }
  112. else
  113. {
  114. Singleton<RouteManager>.Instance.EFEM.EfemDevice.SetPinDown(_alignModule);
  115. }
  116. return true;// _token != (int)FSM_MSG.NONE;
  117. }
  118. public bool IsAligned()
  119. {
  120. if (_entity.EFEMType == EfemEntity.EfemType.BrooksEFEM)
  121. {
  122. if (_timerDelay.IsRunning && _timerDelay.ElapsedMilliseconds > _paramCoolingTime * 1000)
  123. {
  124. _timerDelay.Stop();
  125. }
  126. return _entity.CheckAcked(_entityTaskToken) && _entity.IsIdle && (!_timerDelay.IsRunning);
  127. }
  128. else
  129. {
  130. return !_entity.EfemDevice.IsBufferPinUp[_alignModule];
  131. }
  132. }
  133. public bool Monitor()
  134. {
  135. return true;
  136. }
  137. public bool CheckTaskDone()
  138. {
  139. bool ret = false;
  140. switch (_task)
  141. {
  142. case TaskType.None:
  143. ret = true;
  144. break;
  145. case TaskType.Pick:
  146. ret = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_hand);
  147. if (ret)
  148. {
  149. WaferArriveTicks[(int) _hand] = DateTime.Now.Ticks;
  150. }
  151. break;
  152. case TaskType.Place:
  153. ret = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_hand);
  154. break;
  155. case TaskType.Map:
  156. ret = _entity.CheckAcked(_entityTaskToken) && _entity.IsIdle;
  157. break;
  158. case TaskType.Goto:
  159. ret = _entity.CheckAcked(_entityTaskToken) && _entity.IsIdle;
  160. break;
  161. case TaskType.Align:
  162. ret = IsAligned();
  163. break;
  164. case TaskType.PickAndPlace:
  165. ret = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_taskSwapPickHand)
  166. && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_taskSwapPlaceHand);
  167. if (ret)
  168. {
  169. WaferArriveTicks[(int)_taskSwapPickHand] = DateTime.Now.Ticks;
  170. }
  171. break;
  172. }
  173. if (ret && _task != TaskType.None)
  174. {
  175. LogTaskDone(_task, "");
  176. _task = TaskType.None;
  177. }
  178. return ret;
  179. }
  180. }
  181. }