CarrierRobotSwap.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using Aitex.Core.RT.Routine;
  2. using Aitex.Core.RT.SCCore;
  3. using Aitex.Sorter.Common;
  4. using MECF.Framework.Common.Equipment;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace FurnaceRT.Equipments.CarrierRobots
  11. {
  12. public class CarrierRobotSwap : ModuleRoutine, IRoutine
  13. {
  14. enum RoutineStep
  15. {
  16. Loop,
  17. Pick1,
  18. Pick2,
  19. PickInit1,
  20. PickInit2,
  21. Place1,
  22. Place2,
  23. PlaceInit1,
  24. PlaceInit2,
  25. EndLoop,
  26. IncreaseLoopCount,
  27. }
  28. private CarrierRobotModule _cassetteRobotModule;
  29. private ModuleName _source;
  30. private ModuleName _dest;
  31. private Hand _hand;
  32. private CarrierRobotPick _pick;
  33. private CarrierRobotPlace _place;
  34. private int _slot;
  35. private int _cycleNumber;
  36. public CarrierRobotSwap(CarrierRobotModule cassetteModule)
  37. {
  38. _pick = new CarrierRobotPick(cassetteModule);
  39. _place = new CarrierRobotPlace(cassetteModule);
  40. _cassetteRobotModule = cassetteModule;
  41. Module = cassetteModule.Name;
  42. Name = "Transfer";
  43. }
  44. public Result Start(params object[] objs)
  45. {
  46. Reset();
  47. _cycleNumber = SC.GetValue<int>($"{Module}.TransferModeNumber");
  48. Notify("Start");
  49. return Result.RUN;
  50. }
  51. public void Init(ModuleName source, ModuleName dest, int slot, Hand hand)
  52. {
  53. _source = source;
  54. _dest = dest;
  55. _slot = slot;
  56. _hand = hand;
  57. }
  58. public void Abort()
  59. {
  60. _cassetteRobotModule.Stop();
  61. }
  62. public override Result Monitor()
  63. {
  64. try
  65. {
  66. PauseRountine(_cassetteRobotModule.CarrierRobotDevice.IsPause);
  67. if (_cassetteRobotModule.CarrierRobotDevice.IsPause)
  68. return Result.RUN;
  69. Loop((int)RoutineStep.Loop, _cycleNumber);
  70. PickInit((int)RoutineStep.PickInit1, _source, _slot, _hand);
  71. ExecuteRoutine((int)RoutineStep.Pick1, _pick);
  72. PlaceInit((int)RoutineStep.PlaceInit1, _dest, _slot, _hand);
  73. ExecuteRoutine((int)RoutineStep.Place1, _place);
  74. IncreaseLoopCount((int)RoutineStep.IncreaseLoopCount);
  75. if(LoopCounter < LoopTotalTime)
  76. {
  77. PickInit((int)RoutineStep.PickInit2, _dest, _slot, _hand);
  78. ExecuteRoutine((int)RoutineStep.Pick2, _pick);
  79. PlaceInit((int)RoutineStep.PlaceInit2, _source, _slot, _hand);
  80. ExecuteRoutine((int)RoutineStep.Place2, _place);
  81. }
  82. EndLoop((int)RoutineStep.EndLoop);
  83. }
  84. catch (RoutineBreakException)
  85. {
  86. return Result.RUN;
  87. }
  88. catch (RoutineFaildException)
  89. {
  90. return Result.FAIL;
  91. }
  92. Notify("Finished");
  93. return Result.DONE;
  94. }
  95. private void PickInit(int id, ModuleName source, int slot, Hand blade)
  96. {
  97. Tuple<bool, Result> ret = Execute(id, () =>
  98. {
  99. Notify($"Pick from {source} {slot} init");
  100. string reason = string.Empty;
  101. _pick.Init(source, slot, blade, false);
  102. return true;
  103. });
  104. if (ret.Item1)
  105. {
  106. if (ret.Item2 == Result.FAIL)
  107. {
  108. throw (new RoutineFaildException());
  109. }
  110. }
  111. }
  112. private void PlaceInit(int id, ModuleName dest, int slot, Hand blade)
  113. {
  114. Tuple<bool, Result> ret = Execute(id, () =>
  115. {
  116. Notify($"Place to {dest} {slot} init");
  117. string reason = string.Empty;
  118. _place.Init(dest, slot, blade, false);
  119. return true;
  120. });
  121. if (ret.Item1)
  122. {
  123. if (ret.Item2 == Result.FAIL)
  124. {
  125. throw (new RoutineFaildException());
  126. }
  127. }
  128. }
  129. private void IncreaseLoopCount(int id)
  130. {
  131. Tuple<bool, Result> ret = Execute(id, () =>
  132. {
  133. LoopCounter++;
  134. return true;
  135. });
  136. if (ret.Item1)
  137. {
  138. if (ret.Item2 == Result.FAIL)
  139. {
  140. throw (new RoutineFaildException());
  141. }
  142. }
  143. }
  144. }
  145. }