SchedulerEfemRobot.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  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. public ModuleName PreviousTarget { get; set; }
  38. private Stopwatch _timer = new Stopwatch();
  39. public SchedulerEfemRobot() : base(ModuleName.EfemRobot.ToString())
  40. {
  41. _entity = Singleton<RouteManager>.Instance.EFEM;
  42. PreviousTarget = ModuleName.System;
  43. }
  44. public bool IsReadyForPick(Hand blade)
  45. {
  46. return WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)blade);
  47. }
  48. public bool IsReadyForPlace(Hand blade)
  49. {
  50. return WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)blade);
  51. }
  52. public bool Pick(ModuleName source, int slot, Hand hand)
  53. {
  54. _task = TaskType.Pick;
  55. _hand = hand;
  56. _entityTaskToken = _entity.InvokePick(source, slot, hand, WaferManager.Instance.GetWafer(source, slot).Size);
  57. PreviousTarget = source;
  58. LogTaskStart(_task, $"{source}.{slot + 1}=>{Module}.{hand}");
  59. return true;
  60. }
  61. public bool Place(ModuleName destination, int slot, Hand hand)
  62. {
  63. _task = TaskType.Place;
  64. _hand = hand;
  65. _entityTaskToken = _entity.InvokePlace(destination, slot, hand,
  66. WaferManager.Instance.GetWafer(ModuleName.EfemRobot, hand==Hand.Blade1 ? 0:1).Size);
  67. PreviousTarget = destination;
  68. LogTaskStart(_task, $"{Module}.{hand}=>{destination}.{slot + 1}");
  69. return true;
  70. }
  71. public bool PickAndPlace(ModuleName target, int pickSlot, int placeSlot, Hand pickHand, Hand placeHand)
  72. {
  73. PreviousTarget = target;
  74. _task = TaskType.PickAndPlace;
  75. _taskSwapPickHand = pickHand;
  76. _taskSwapPlaceHand = placeHand;
  77. _taskSwapPickSlot = pickSlot;
  78. _taskSwapPlaceSlot = placeSlot;
  79. _entityTaskToken = _entity.InvokePickAndPlace(target, pickHand, pickSlot, placeHand, placeSlot, WaferManager.Instance.GetWafer(target, pickSlot).Size);
  80. LogTaskStart(_task, $" {target}.{pickSlot + 1}=>{Module}.{pickHand} && {Module}.{placeHand}=>{target}.{placeSlot + 1}");
  81. return true;
  82. }
  83. public bool Goto(ModuleName target, int slot )
  84. {
  85. _task = TaskType.Goto;
  86. _entityTaskToken = _entity.InvokeGoto(target, slot );
  87. PreviousTarget = target;
  88. LogTaskStart(_task, $"Robot goto {target}.{slot + 1}");
  89. _timer.Restart();
  90. return true;
  91. }
  92. public bool Map(ModuleName destination )
  93. {
  94. _task = TaskType.Map;
  95. _entityTaskToken = _entity.InvokeMap(destination.ToString());
  96. LogTaskStart(_task, $"{Module} mapping");
  97. PreviousTarget = destination;
  98. _timer.Restart();
  99. return true;
  100. }
  101. public bool Monitor()
  102. {
  103. return true;
  104. }
  105. public bool CheckTaskDone()
  106. {
  107. bool ret = false;
  108. switch (_task)
  109. {
  110. case TaskType.None:
  111. ret = true;
  112. break;
  113. case TaskType.Pick:
  114. ret = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_hand);
  115. if (ret)
  116. {
  117. WaferArriveTicks[(int) _hand] = DateTime.Now.Ticks;
  118. }
  119. break;
  120. case TaskType.Place:
  121. ret = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_hand);
  122. break;
  123. case TaskType.Map:
  124. ret = _entity.IsIdle && _timer.ElapsedMilliseconds > 500;
  125. break;
  126. case TaskType.Goto:
  127. ret = _entity.IsIdle && _timer.ElapsedMilliseconds > 500;
  128. break;
  129. case TaskType.PickAndPlace:
  130. ret = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, (int)_taskSwapPickHand)
  131. && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_taskSwapPlaceHand);
  132. if (ret)
  133. {
  134. WaferArriveTicks[(int)_taskSwapPickHand] = DateTime.Now.Ticks;
  135. }
  136. break;
  137. }
  138. if (ret && _task != TaskType.None)
  139. {
  140. LogTaskDone(_task, "");
  141. _task = TaskType.None;
  142. _timer.Stop();
  143. }
  144. return ret;
  145. }
  146. }
  147. }