SchedulerEFEM.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.RT.SCCore;
  3. using Aitex.Core.Util;
  4. using Aitex.Sorter.Common;
  5. using MECF.Framework.Common.Equipment;
  6. using MECF.Framework.Common.SubstrateTrackings;
  7. using MECF.Framework.RT.ModuleLibrary.EfemModules;
  8. using MECF.Framework.RT.ModuleLibrary.SystemModules;
  9. using MECF.Framework.RT.ModuleLibrary.TMModules;
  10. namespace EfemDualSchedulerLib.Schedulers
  11. {
  12. public class SchedulerEFEM : SchedulerModule
  13. {
  14. public override bool IsAvailable
  15. {
  16. get { return _efem.IsReady && _efem.IsOnline && CheckTaskDone(); }
  17. }
  18. public override bool IsOnline
  19. {
  20. get { return _efem.IsOnline; }
  21. }
  22. public override bool IsError
  23. {
  24. get { return _efem.IsError; }
  25. }
  26. public bool Blade1Enable
  27. {
  28. get => SC.GetValueOrDefault<bool>($"Efem.EfemRobot.LowerBladeEnable");
  29. }
  30. public bool Blade2Enable
  31. {
  32. get => SC.GetValueOrDefault<bool>($"Efem.EfemRobot.UpperBladeEnable");
  33. }
  34. private EfemModuleBase _efem = null;
  35. private Hand _hand;
  36. private Hand _taskSwapPickHand;
  37. private Hand _taskSwapPlaceHand;
  38. private int _taskSwapPickSlot;
  39. private int _taskSwapPlaceSlot;
  40. public ModuleName PreviousTarget { get; set; }
  41. public SchedulerEFEM(EfemModuleBase moduleDevice) : base(ModuleName.EFEM.ToString())
  42. {
  43. _efem = moduleDevice;
  44. PreviousTarget = ModuleName.System;
  45. }
  46. public override void ResetTask()
  47. {
  48. base.ResetTask();
  49. PreviousTarget = ModuleName.System;
  50. }
  51. public override bool HasWafer(int slot)
  52. {
  53. return WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, slot);
  54. }
  55. public override bool NoWafer(int slot)
  56. {
  57. return WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, slot);
  58. }
  59. public bool IsReadyForPick(Hand blade)
  60. {
  61. return WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)blade);
  62. }
  63. public bool IsReadyForPlace(Hand blade)
  64. {
  65. return WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)blade);
  66. }
  67. public bool Pick(ModuleName source, int slot, Hand hand)
  68. {
  69. _task = TaskType.Pick;
  70. _hand = hand;
  71. if (!_efem.Pick(source, hand, slot, out string reason))
  72. {
  73. LOG.Write(reason);
  74. }
  75. PreviousTarget = source;
  76. LogTaskStart(_task, $"{source}.{slot + 1}=>{Module}.{hand}");
  77. return true;
  78. }
  79. public bool Place(ModuleName destination, int slot, Hand hand)
  80. {
  81. _task = TaskType.Place;
  82. _hand = hand;
  83. if (!_efem.Place(destination, hand, slot, out string reason))
  84. {
  85. LOG.Write(reason);
  86. }
  87. PreviousTarget = destination;
  88. LogTaskStart(_task, $"{Module}.{hand}=>{destination}.{slot + 1}");
  89. return true;
  90. }
  91. public bool Map(ModuleName destination)
  92. {
  93. _task = TaskType.Map;
  94. if (!_efem.Map(destination, out string reason))
  95. {
  96. LOG.Write(reason);
  97. }
  98. PreviousTarget = destination;
  99. LogTaskStart(_task, $"mapping {Module}");
  100. return true;
  101. }
  102. public bool PickAndPlace(ModuleName target, int pickSlot, int placeSlot, Hand pickHand, Hand placeHand)
  103. {
  104. PreviousTarget = target;
  105. _task = TaskType.PickAndPlace;
  106. _taskSwapPickHand = pickHand;
  107. _taskSwapPlaceHand = placeHand;
  108. _taskSwapPickSlot = pickSlot;
  109. _taskSwapPlaceSlot = placeSlot;
  110. LogTaskStart(_task, $" {target}.{pickSlot + 1}=>{Module}.{pickHand} && {Module}.{placeHand}=>{target}.{placeSlot + 1}");
  111. return _efem.PickAndPlace(target, pickHand, pickSlot, target, placeHand, placeSlot, out _);
  112. }
  113. public bool Goto(ModuleName target, int slot, Hand hand)
  114. {
  115. PreviousTarget = target;
  116. _task = TaskType.Goto;
  117. if (!_efem.Goto(target, hand, slot, out string reason))
  118. {
  119. LOG.Write(reason);
  120. }
  121. LogTaskStart(_task, $"robot {hand} goto {target}, slot {slot + 1}");
  122. return true;
  123. }
  124. public bool CheckTaskDone()
  125. {
  126. bool ret = false;
  127. switch (_task)
  128. {
  129. case TaskType.None:
  130. ret = true;
  131. break;
  132. case TaskType.Pick:
  133. if (_hand == Hand.Both)
  134. {
  135. ret = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)Hand.Blade1)
  136. && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)Hand.Blade2);
  137. }
  138. else
  139. {
  140. ret = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_hand);
  141. }
  142. break;
  143. case TaskType.Place:
  144. if (_hand == Hand.Both)
  145. {
  146. ret = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)Hand.Blade1)
  147. && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)Hand.Blade2);
  148. }
  149. else
  150. {
  151. ret = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_hand);
  152. }
  153. break;
  154. case TaskType.Map:
  155. ret = _efem.IsReady;
  156. break;
  157. case TaskType.Goto:
  158. ret = _efem.IsReady;
  159. break;
  160. case TaskType.PickAndPlace:
  161. ret = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_taskSwapPickHand)
  162. && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_taskSwapPlaceHand);
  163. break;
  164. }
  165. if (ret && _task != TaskType.None)
  166. {
  167. LogTaskDone(_task, "");
  168. _task = TaskType.None;
  169. }
  170. return ret;
  171. }
  172. }
  173. }