CarrierRobotGoto.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.Util;
  6. using Aitex.Sorter.Common;
  7. using MECF.Framework.Common.Device.Bases;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.Common.Schedulers;
  10. using MECF.Framework.Common.SubstrateTrackings;
  11. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  12. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using FurnaceRT.Equipments.FIMSs;
  19. using FurnaceRT.Equipments.Stockers;
  20. using FurnaceRT.Equipments.Systems;
  21. using static FurnaceRT.Equipments.FIMSs.FIMSModule;
  22. using FurnaceRT.Equipments.LPs;
  23. namespace FurnaceRT.Equipments.CarrierRobots
  24. {
  25. public class CarrierRobotGoto : ModuleRoutine, IRoutine
  26. {
  27. enum RoutineStep
  28. {
  29. Goto,
  30. }
  31. private CarrierRobotModule _cassetteRobotModule;
  32. private ModuleName _destination;
  33. private int _destinationSlot;
  34. private Hand _blade;
  35. private int _timeout = 0;
  36. private RD_TRIG _holdTrig = new RD_TRIG();
  37. private R_TRIG _emergencyStopTrig = new R_TRIG();
  38. private R_TRIG _pauseTrig = new R_TRIG();
  39. private R_TRIG _resumeTrig = new R_TRIG();
  40. private RoutineStep _routineStep;
  41. private double _durationTime = 0;
  42. private bool _isHasAlarm = false;
  43. private bool _needStartCheck = true;
  44. private bool _isPickReady;
  45. public CarrierRobotGoto(CarrierRobotModule cassetteModule)
  46. {
  47. _cassetteRobotModule = cassetteModule;
  48. Module = cassetteModule.Module;
  49. Name = "Goto";
  50. }
  51. public void Init(ModuleName destination, int destinationSlot, Hand blade, bool isPickReady, bool isHasAlarm)
  52. {
  53. _destination = destination;
  54. _destinationSlot = destinationSlot;
  55. _blade = blade;
  56. _isPickReady = isPickReady;
  57. var para = new List<object> { _destination, _destinationSlot, _blade, _isPickReady, true };
  58. _cassetteRobotModule.GotoTimeoutAlarm.RetryMessage = (int)CarrierRobotModule.MSG.GotoRetry;
  59. _cassetteRobotModule.GotoTimeoutAlarm.RetryMessageParas = para.ToArray();
  60. _cassetteRobotModule.GotoFailAlarm.RetryMessage = (int)CarrierRobotModule.MSG.GotoRetry;
  61. _cassetteRobotModule.GotoFailAlarm.RetryMessageParas = para.ToArray();
  62. _isHasAlarm = isHasAlarm;
  63. if (!_isHasAlarm)
  64. _needStartCheck = true;
  65. }
  66. public Result Start(params object[] objs)
  67. {
  68. // 抛出过alarm就不reset
  69. if (!_isHasAlarm)
  70. {
  71. Reset();
  72. }
  73. else
  74. {
  75. _historySteps.Remove((int)_routineStep);
  76. _isHasAlarm = false;
  77. ResetState();
  78. }
  79. _holdTrig.RST = true;
  80. _emergencyStopTrig.RST = true;
  81. _pauseTrig.RST = true;
  82. _resumeTrig.RST = true;
  83. _timeout = SC.GetValue<int>($"{Module}.MotionTimeout");
  84. Notify($"Start");
  85. return Result.RUN;
  86. }
  87. public void Abort()
  88. {
  89. _cassetteRobotModule.Stop();
  90. }
  91. public override Result Monitor()
  92. {
  93. try
  94. {
  95. PauseRountine(_cassetteRobotModule.CarrierRobotDevice.IsPause);
  96. if (_cassetteRobotModule.CarrierRobotDevice.IsPause)
  97. return Result.RUN;
  98. Goto((int)RoutineStep.Goto, _destination, _destinationSlot, _blade, _isPickReady, _timeout);
  99. }
  100. catch (RoutineBreakException)
  101. {
  102. return Result.RUN;
  103. }
  104. catch (RoutineFaildException ex)
  105. {
  106. return Result.FAIL;
  107. }
  108. Notify("Finished");
  109. return Result.DONE;
  110. }
  111. private void Goto(int id, ModuleName target, int slot, Hand hand, bool isPickReady, int timeout)
  112. {
  113. _routineStep = (RoutineStep)Enum.Parse(typeof(RoutineStep), id.ToString());
  114. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  115. {
  116. Notify($"Send goto to {target} command to robot device");
  117. string reason;
  118. _cassetteRobotModule.RobotGoto(target, slot, hand, isPickReady, out reason);
  119. return true;
  120. }, () =>
  121. {
  122. if (_cassetteRobotModule.CarrierRobotDevice.IsError)
  123. return null;
  124. if (_cassetteRobotModule.CarrierRobotDevice.IsReady() && !_cassetteRobotModule.CarrierRobotDevice.IsError)
  125. {
  126. return true;
  127. }
  128. return false;
  129. }, timeout * 1000);
  130. if (ret.Item1)
  131. {
  132. if (ret.Item2 == Result.FAIL)
  133. {
  134. //_cassetteRobotModule.PlaceCassetteFailAlarm.Description = $"{_cassetteRobotModule.CassetteRobotDevice.ErrorCode}";
  135. _cassetteRobotModule.GotoFailAlarm.Set($"goto to {target} failed for robot error, error code={_cassetteRobotModule.CarrierRobotDevice.ErrorCode}");
  136. throw (new RoutineFaildException());
  137. }
  138. else if (ret.Item2 == Result.TIMEOUT) //timeout
  139. {
  140. //_cassetteRobotModule.PlaceCassetteTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  141. _cassetteRobotModule.GotoTimeoutAlarm.Set($"timeout over {timeout} seconds");
  142. throw (new RoutineFaildException());
  143. }
  144. else
  145. throw (new RoutineBreakException());
  146. }
  147. }
  148. }
  149. }