SchedulerEfemRobot.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Aitex.Core.RT.Fsm;
  7. using Aitex.Core.RT.Log;
  8. using Aitex.Core.RT.SCCore;
  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 bool LiftDone
  27. {
  28. get
  29. {
  30. return _entity.LiftDone;
  31. }
  32. }
  33. public override bool IsError
  34. {
  35. get { return _entity.IsError; }
  36. }
  37. public bool Blade1Enable
  38. {
  39. get
  40. {
  41. if (SC.ContainsItem($"EFEM.EfemRobot.LowerBladeEnable"))
  42. {
  43. return SC.GetValue<bool>($"EFEM.EfemRobot.LowerBladeEnable");
  44. }
  45. return true;
  46. }
  47. set
  48. {
  49. if (SC.ContainsItem($"EFEM.EfemRobot.LowerBladeEnable"))
  50. {
  51. SC.SetItemValue($"EFEM.EfemRobot.LowerBladeEnable", value);
  52. }
  53. }
  54. }
  55. public bool Blade2Enable
  56. {
  57. get
  58. {
  59. if (SC.ContainsItem($"EFEM.EfemRobot.UpperBladeEnable"))
  60. {
  61. return SC.GetValue<bool>($"EFEM.EfemRobot.UpperBladeEnable");
  62. }
  63. return true;
  64. }
  65. set
  66. {
  67. if (SC.ContainsItem($"EFEM.EfemRobot.UpperBladeEnable"))
  68. {
  69. SC.SetItemValue($"EFEM.EfemRobot.UpperBladeEnable", value);
  70. }
  71. }
  72. }
  73. private EfemEntity _entity = null;
  74. private Hand _hand;
  75. private int _entityTaskToken = (int)FSM_MSG.NONE;
  76. private Hand _taskSwapPickHand;
  77. private Hand _taskSwapPlaceHand;
  78. private int _taskSwapPickSlot;
  79. private int _taskSwapPlaceSlot;
  80. public ModuleName PreviousTarget { get; set; }
  81. public SchedulerEfemRobot() : base(ModuleName.EfemRobot.ToString())
  82. {
  83. _entity = Singleton<RouteManager>.Instance.EFEM;
  84. PreviousTarget = ModuleName.System;
  85. }
  86. public bool IsReadyForPick(Hand blade)
  87. {
  88. return WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)blade);
  89. }
  90. public bool IsReadyForPlace(Hand blade)
  91. {
  92. return WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)blade);
  93. }
  94. public bool Pick(ModuleName source, int slot, Hand hand)
  95. {
  96. _task = TaskType.Pick;
  97. _hand = hand;
  98. _entityTaskToken = _entity.InvokePick(source, slot, hand, WaferManager.Instance.GetWafer(source, slot).Size);
  99. PreviousTarget = source;
  100. LogTaskStart(_task, $"{source}.{slot + 1}=>{Module}.{hand}");
  101. return true;
  102. }
  103. public bool Place(ModuleName destination, int slot, Hand hand)
  104. {
  105. _task = TaskType.Place;
  106. _hand = hand;
  107. _entityTaskToken = _entity.InvokePlace(destination, slot, hand,
  108. WaferManager.Instance.GetWafer(ModuleName.EfemRobot, hand==Hand.Blade1 ? 0:1).Size);
  109. PreviousTarget = destination;
  110. LogTaskStart(_task, $"{Module}.{hand}=>{destination}.{slot + 1}");
  111. return true;
  112. }
  113. public bool PickAndPlace(ModuleName target, int pickSlot, int placeSlot, Hand pickHand, Hand placeHand)
  114. {
  115. PreviousTarget = target;
  116. _task = TaskType.PickAndPlace;
  117. _taskSwapPickHand = pickHand;
  118. _taskSwapPlaceHand = placeHand;
  119. _taskSwapPickSlot = pickSlot;
  120. _taskSwapPlaceSlot = placeSlot;
  121. _entityTaskToken = _entity.InvokePickAndPlace(target, pickHand, pickSlot, placeHand, placeSlot, WaferManager.Instance.GetWafer(target, pickSlot).Size);
  122. LogTaskStart(_task, $" {target}.{pickSlot + 1}=>{Module}.{pickHand} && {Module}.{placeHand}=>{target}.{placeSlot + 1}");
  123. return true;
  124. }
  125. public bool Goto(ModuleName target, int slot )
  126. {
  127. _task = TaskType.Goto;
  128. _entityTaskToken = _entity.InvokeGoto(target, slot );
  129. PreviousTarget = target;
  130. LogTaskStart(_task, $"Robot goto {target}.{slot + 1}");
  131. return true;
  132. }
  133. public bool Map(ModuleName destination )
  134. {
  135. _task = TaskType.Map;
  136. _entityTaskToken = _entity.InvokeMap(destination.ToString());
  137. LogTaskStart(_task, $"{Module} mapping");
  138. PreviousTarget = destination;
  139. return true;
  140. }
  141. public bool Monitor()
  142. {
  143. return true;
  144. }
  145. public bool CheckTaskDone()
  146. {
  147. bool ret = false;
  148. switch (_task)
  149. {
  150. case TaskType.None:
  151. ret = true;
  152. break;
  153. case TaskType.Pick:
  154. ret = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_hand);
  155. if (ret)
  156. {
  157. WaferArriveTicks[(int) _hand] = DateTime.Now.Ticks;
  158. }
  159. break;
  160. case TaskType.Place:
  161. ret = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_hand);
  162. break;
  163. case TaskType.Map:
  164. ret = _entity.CheckAcked(_entityTaskToken) && _entity.IsIdle;
  165. break;
  166. case TaskType.Goto:
  167. ret = _entity.CheckAcked(_entityTaskToken) && _entity.IsIdle;
  168. break;
  169. case TaskType.PickAndPlace:
  170. ret = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_taskSwapPickHand)
  171. && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_taskSwapPlaceHand);
  172. if (ret)
  173. {
  174. WaferArriveTicks[(int)_taskSwapPickHand] = DateTime.Now.Ticks;
  175. }
  176. break;
  177. }
  178. if (ret && _task != TaskType.None)
  179. {
  180. LogTaskDone(_task, "");
  181. _task = TaskType.None;
  182. }
  183. return ret;
  184. }
  185. }
  186. }