CarrierRobotCycleSwap.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. using Aitex.Core.RT.Routine;
  2. using Aitex.Core.Util;
  3. using Aitex.Sorter.Common;
  4. using DocumentFormat.OpenXml.Wordprocessing;
  5. using FurnaceRT.Equipments.Systems;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.Schedulers;
  8. using MECF.Framework.RT.EquipmentLibrary.LogicUnits;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Reflection;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. namespace FurnaceRT.Equipments.CarrierRobots
  16. {
  17. public class CarrierRobotCycleSwap : ModuleRoutine, IRoutine
  18. {
  19. enum RoutineStep
  20. {
  21. Loop,
  22. GetModule,
  23. Pick1,
  24. Pick2,
  25. PickInit1,
  26. PickInit2,
  27. Place1,
  28. Place2,
  29. PlaceInit1,
  30. PlaceInit2,
  31. EndLoop,
  32. }
  33. private CarrierRobotModule _CarrierRobotModule;
  34. private ModuleName _source;
  35. private ModuleName _dest;
  36. private Hand _hand;
  37. private CarrierRobotPick _pick;
  38. private CarrierRobotPlace _place;
  39. private int _slot;
  40. private int _cycleNumber;
  41. public bool IsAbortCycle = false;
  42. private int _currentIndex;
  43. public int _overAllLoopCount=0;
  44. private List<ModuleName> _lsModuleName;
  45. public CarrierRobotCycleSwap(CarrierRobotModule cassetteModule)
  46. {
  47. _pick = new CarrierRobotPick(cassetteModule);
  48. _place = new CarrierRobotPlace(cassetteModule);
  49. _CarrierRobotModule = cassetteModule;
  50. Module = cassetteModule.Name;
  51. Name = "CycleSwap";
  52. }
  53. public Result Start(params object[] objs)
  54. {
  55. Reset();
  56. _currentIndex = 0;
  57. _overAllLoopCount = 0;
  58. Notify("Start");
  59. return Result.RUN;
  60. }
  61. public void Init(ModuleName source, ModuleName dest, int slot, Hand hand, int cyclenum)
  62. {
  63. _source = source;
  64. _dest = dest;
  65. _slot = slot;
  66. _hand = hand;
  67. IsAbortCycle = false;
  68. int startIndex = int.Parse(source.ToString().Replace("Stocker", ""));
  69. int endIndex = int.Parse(dest.ToString().Replace("Stocker", ""));
  70. _lsModuleName = new List<ModuleName>();
  71. for (int i = 0; i < cyclenum; i++)
  72. {
  73. if (startIndex > endIndex)
  74. {
  75. for (int j = startIndex; j >= endIndex; j--)
  76. {
  77. _lsModuleName.Add((ModuleName)Enum.Parse(typeof(ModuleName), "Stocker" + j));
  78. }
  79. }
  80. else
  81. {
  82. for (int j = startIndex; j <= endIndex; j++)
  83. {
  84. _lsModuleName.Add((ModuleName)Enum.Parse(typeof(ModuleName), "Stocker" + j));
  85. }
  86. }
  87. }
  88. _cycleNumber = _lsModuleName.Count;
  89. }
  90. public void Abort()
  91. {
  92. IsAbortCycle = true;
  93. (Singleton<EquipmentManager>.Instance.Modules[_dest] as ITransferTarget)?.NoteTransferStop(ModuleHelper.Converter(_CarrierRobotModule.Module), new Hand(), 0, EnumTransferType.Pick);
  94. }
  95. public override Result Monitor()
  96. {
  97. try
  98. {
  99. if (IsAbortCycle) return Result.DONE;
  100. PauseRountine(_CarrierRobotModule.CarrierRobotDevice.IsPause);
  101. if (_CarrierRobotModule.CarrierRobotDevice.IsPause)
  102. return Result.RUN;
  103. Loop((int)RoutineStep.Loop, _cycleNumber);
  104. GetModule((int)RoutineStep.GetModule);
  105. PickInit((int)RoutineStep.PickInit1, _source, _slot, _hand);
  106. ExecuteRoutine((int)RoutineStep.Pick1, _pick);
  107. PlaceInit((int)RoutineStep.PlaceInit1, _dest, _slot, _hand);
  108. ExecuteRoutine((int)RoutineStep.Place1, _place);
  109. EndLoop((int)RoutineStep.EndLoop);
  110. }
  111. catch (RoutineBreakException)
  112. {
  113. return Result.RUN;
  114. }
  115. catch (RoutineFaildException)
  116. {
  117. return Result.FAIL;
  118. }
  119. Notify("Finished");
  120. return Result.DONE;
  121. }
  122. private void GetModule(int id)
  123. {
  124. Tuple<bool, Result> ret = Execute(id, () =>
  125. {
  126. Notify($"Get Module currentIndex = {_currentIndex}");
  127. _source = _lsModuleName[_currentIndex];
  128. if (_currentIndex == _lsModuleName.Count - 1)
  129. {
  130. _currentIndex = 0;
  131. }
  132. else
  133. {
  134. _currentIndex++;
  135. }
  136. _dest = _lsModuleName[_currentIndex];
  137. if ( _source.Equals(_lsModuleName.FirstOrDefault()))
  138. {
  139. _overAllLoopCount++;
  140. Notify($"_overAllLoopCount = {_overAllLoopCount}");
  141. }
  142. return true;
  143. });
  144. if (ret.Item1)
  145. {
  146. if (ret.Item2 == Result.FAIL)
  147. {
  148. throw (new RoutineFaildException());
  149. }
  150. }
  151. }
  152. private void PickInit(int id, ModuleName source, int slot, Hand blade)
  153. {
  154. Tuple<bool, Result> ret = Execute(id, () =>
  155. {
  156. Notify($"Pick from {source} {slot} init");
  157. string reason = string.Empty;
  158. _pick.Init(source, slot, blade, false);
  159. return true;
  160. });
  161. if (ret.Item1)
  162. {
  163. if (ret.Item2 == Result.FAIL)
  164. {
  165. throw (new RoutineFaildException());
  166. }
  167. }
  168. }
  169. private void PlaceInit(int id, ModuleName dest, int slot, Hand blade)
  170. {
  171. Tuple<bool, Result> ret = Execute(id, () =>
  172. {
  173. Notify($"Place to {dest} {slot} init");
  174. string reason = string.Empty;
  175. _place.Init(dest, slot, blade, false);
  176. return true;
  177. });
  178. if (ret.Item1)
  179. {
  180. if (ret.Item2 == Result.FAIL)
  181. {
  182. throw (new RoutineFaildException());
  183. }
  184. }
  185. }
  186. }
  187. }