SchedulerTM.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.SCCore;
  4. using Aitex.Core.Util;
  5. using Aitex.Sorter.Common;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.SubstrateTrackings;
  8. using MECF.Framework.RT.ModuleLibrary.EfemModules;
  9. using MECF.Framework.RT.ModuleLibrary.SystemModules;
  10. using MECF.Framework.RT.ModuleLibrary.TMModules;
  11. using System;
  12. using System.Linq;
  13. namespace EfemDualSchedulerLib.Schedulers
  14. {
  15. public class SchedulerTM : SchedulerModule
  16. {
  17. public override bool IsAvailable
  18. {
  19. get { return _tm.IsReady && _tm.IsOnline && CheckTaskDone(); }
  20. }
  21. public override bool IsOnline
  22. {
  23. get { return _tm.IsOnline; }
  24. }
  25. public override bool IsError
  26. {
  27. get { return _tm.IsError; }
  28. }
  29. public bool Blade1Enable
  30. {
  31. get => SC.GetValueOrDefault<bool>($"TM.TMRobot.LowerBladeEnable");
  32. }
  33. public bool Blade2Enable
  34. {
  35. get => SC.GetValueOrDefault<bool>($"TM.TMRobot.UpperBladeEnable");
  36. }
  37. private TMModuleBase _tm = null;
  38. private Hand _hand;
  39. private Hand _taskSwapPickHand;
  40. private Hand _taskSwapPlaceHand;
  41. private int[] _taskSwapPickSlot;
  42. private int[] _taskSwapPlaceSlot;
  43. private int[] _slots;
  44. private Pan _pan;
  45. private Pan _placePan;
  46. public ModuleName PreviousTarget { get; set; }
  47. public SchedulerTM(TMModuleBase moduleDevice) : base(ModuleName.TM.ToString())
  48. {
  49. _tm = moduleDevice;
  50. PreviousTarget = ModuleName.System;
  51. }
  52. public override void ResetTask()
  53. {
  54. base.ResetTask();
  55. PreviousTarget = ModuleName.System;
  56. }
  57. public override WaferInfo GetWaferInfo(int slot)
  58. {
  59. return WaferManager.Instance.GetWafer(ModuleName.TMRobot, slot);
  60. }
  61. public override bool HasWafer(int slot)
  62. {
  63. return WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, slot);
  64. }
  65. public override bool NoWafer(int slot)
  66. {
  67. return Converter.MapBladeToSlots(Converter.MapSlotToHand(slot)).All(p=> WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p));
  68. }
  69. public override bool CheckWaferNextStepIsThisModule(ModuleName module, int slot)
  70. {
  71. if (!WaferManager.Instance.CheckHasWafer(module, slot))
  72. return false;
  73. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  74. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  75. return false;
  76. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  77. return false;
  78. if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.TMRobot))
  79. return false;
  80. return true;
  81. }
  82. public override bool CheckWaferNextStepIsThisModuleSlot(ModuleName module, int slot, int thisSlot)
  83. {
  84. if (!WaferManager.Instance.CheckHasWafer(module, slot))
  85. return false;
  86. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  87. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  88. return false;
  89. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  90. return false;
  91. if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.TMRobot))
  92. return false;
  93. if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepParameter["SlotSelection"].ToString().Contains(thisSlot.ToString()))
  94. return false;
  95. return true;
  96. }
  97. public bool IsReadyForPick(Hand blade)
  98. {
  99. return Converter.MapBladeToSlots(blade).All(p=> WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p));
  100. }
  101. public bool IsReadyForPlace(Hand blade)
  102. {
  103. return Converter.MapBladeToSlots(blade).Any(p=> WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, p));
  104. }
  105. public bool Pick(ModuleName source, int[] slot, Hand hand, Pan pan, double temp1, double temp2, bool enableCheckTemp)
  106. {
  107. _task = TaskType.Pick;
  108. _hand = hand;
  109. _slots = slot;
  110. _pan = pan;
  111. if (!_tm.Pick(source, hand, pan, slot, temp1, temp2, enableCheckTemp, out string reason))
  112. {
  113. LOG.Write(reason);
  114. }
  115. PreviousTarget = source;
  116. Array.ForEach(slot, p => LogTaskStart(_task, $"{source}.{p + 1}=>{Module}.{hand}"));
  117. return true;
  118. }
  119. public bool Place(ModuleName destination, int[] slot, Hand hand, Pan pan, double temp1, double temp2, bool enableCheckTemp)
  120. {
  121. _task = TaskType.Place;
  122. _hand = hand;
  123. _slots = slot;
  124. _pan = pan;
  125. if (!_tm.Place(destination, hand, pan, slot, temp1, temp2, enableCheckTemp, out string reason))
  126. {
  127. LOG.Write(reason);
  128. }
  129. PreviousTarget = destination;
  130. Array.ForEach(slot,p=> LogTaskStart(_task, $"{Module}.{hand}=>{destination}.{p + 1}"));
  131. return true;
  132. }
  133. public bool Map(ModuleName destination)
  134. {
  135. _task = TaskType.Map;
  136. if (!_tm.Map(destination, out string reason))
  137. {
  138. LOG.Write(reason);
  139. }
  140. PreviousTarget = destination;
  141. LogTaskStart(_task, $"mapping {Module}");
  142. return true;
  143. }
  144. public bool PickAndPlace(ModuleName target, Hand pickHand, Pan pickPan, int[] pickSlot, Hand placeHand, Pan placePan, int[] placeSlot,double targetTemp1, double targetTemp2)
  145. {
  146. PreviousTarget = target;
  147. _task = TaskType.PickAndPlace;
  148. _taskSwapPickHand = pickHand;
  149. _pan = pickPan;
  150. _taskSwapPickSlot = pickSlot;
  151. _taskSwapPlaceHand = placeHand;
  152. _placePan = placePan;
  153. _taskSwapPlaceSlot = placeSlot;
  154. LogTaskStart(_task, $" {target}.[{string.Join(",", pickSlot.Select(p => p + 1).ToArray())}]=>{Module}.{pickHand}.{pickPan} && {Module}.{placeHand}.{placePan}=>{target}.[{string.Join(",", placeSlot.Select(p => p + 1).ToArray())}]");
  155. return _tm.PickAndPlace(target, pickHand, pickPan, pickSlot, target, placeHand, placePan, placeSlot, targetTemp1, targetTemp2, out _);
  156. }
  157. public bool Goto(ModuleName target, int[] slot, Hand pickHand, Pan pickPan)
  158. {
  159. PreviousTarget = target;
  160. _task = TaskType.Goto;
  161. _hand = pickHand;
  162. _slots = slot;
  163. _pan = pickPan;
  164. if (!_tm.Goto(target, pickHand, slot, out string reason,_pan))
  165. {
  166. LOG.Write(reason);
  167. }
  168. Array.ForEach(slot, p => LogTaskStart(_task, $"robot {pickHand} goto {target}"));
  169. return true;
  170. }
  171. private bool CheckPickDone(Hand hand, Pan pan)
  172. {
  173. var res = Converter.MapBladeAndPanToSlot(hand, pan)?.All(p => WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, p));
  174. return res == null ? false : res.Value;
  175. }
  176. private bool CheckPlaceDone(Hand hand,Pan pan)
  177. {
  178. var res = Converter.MapBladeAndPanToSlot(hand, pan)?.All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p));
  179. return res == null ? false : res.Value;
  180. }
  181. public bool CheckTaskDone()
  182. {
  183. bool ret = false;
  184. switch (_task)
  185. {
  186. case TaskType.None:
  187. ret = true;
  188. break;
  189. case TaskType.Pick:
  190. ret = CheckPickDone(_hand, _pan);
  191. break;
  192. case TaskType.Place:
  193. ret = CheckPlaceDone(_hand, _pan);
  194. break;
  195. case TaskType.Map:
  196. ret = _tm.IsReady;
  197. break;
  198. case TaskType.Goto:
  199. ret = _tm.IsReady;
  200. break;
  201. case TaskType.PickAndPlace:
  202. ret = CheckPickDone(_taskSwapPickHand, _pan) && CheckPlaceDone(_taskSwapPlaceHand, _placePan);
  203. break;
  204. }
  205. if (ret && _task != TaskType.None)
  206. {
  207. LogTaskDone(_task, "");
  208. _task = TaskType.None;
  209. }
  210. return ret;
  211. }
  212. }
  213. }