SafetyResetRoutine.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Routine;
  3. using MECF.Framework.Common.Routine;
  4. using PunkHPX8_Core;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using MECF.Framework.Common.Beckhoff.ModuleIO;
  11. using MECF.Framework.Common.TwinCat;
  12. using MECF.Framework.Common.IOCore;
  13. using Aitex.Core.RT.Log;
  14. namespace PunkHPX8_RT.Devices.Safety
  15. {
  16. public class SafetyResetRoutine : RoutineBase, IRoutine
  17. {
  18. private enum SafetyResetStep
  19. {
  20. RunStop,
  21. ErrAck,
  22. LockCasseteDoors,
  23. LockCellDoors,
  24. LockAlignerDoors,
  25. FacilityStoEstopRestart,
  26. FacilityEstopDelay,
  27. PlatingCell12Sto1EstopRestart,
  28. PlatingCell12Sto1EstopDelay,
  29. PlatingCell12Sto2EstopRestart,
  30. PlatingCell12Sto2EstopDelay,
  31. PlatingCell34Sto1EstopRestart,
  32. PlatingCell34Sto1EstopDelay,
  33. PlatingCell34Sto2EstopRestart,
  34. PlatingCell34Sto2EstopDelay,
  35. SlsRestart,
  36. End
  37. }
  38. #region 常量
  39. private const string RUNSTOP = "RunStop";
  40. #endregion
  41. #region 内部变量
  42. private SafetyToggleRoutine _errAckToggleRoutine;
  43. private SafetyToggleRoutine _facilityStoEstopRestart;
  44. private SafetyToggleRoutine _platingCell12Sto1EstopRestart;
  45. private SafetyToggleRoutine _platingCell12Sto2EstopRestart;
  46. private SafetyToggleRoutine _platingCell34Sto1EstopRestart;
  47. private SafetyToggleRoutine _platingCell34Sto2EstopRestart;
  48. private SafetyDevice _device;
  49. #endregion
  50. /// <summary>
  51. /// 构造函数
  52. /// </summary>
  53. /// <param name="module"></param>
  54. public SafetyResetRoutine(string module) : base(module)
  55. {
  56. _errAckToggleRoutine = new SafetyToggleRoutine(module);
  57. _facilityStoEstopRestart = new SafetyToggleRoutine(module);
  58. _platingCell12Sto1EstopRestart=new SafetyToggleRoutine(module);
  59. _platingCell12Sto2EstopRestart=new SafetyToggleRoutine(module);
  60. _platingCell34Sto1EstopRestart= new SafetyToggleRoutine(module);
  61. _platingCell34Sto2EstopRestart = new SafetyToggleRoutine(module);
  62. }
  63. /// <summary>
  64. /// 中止
  65. /// </summary>
  66. public void Abort()
  67. {
  68. Runner.Stop("Manaul abort safety reset");
  69. }
  70. /// <summary>
  71. /// 监控
  72. /// </summary>
  73. /// <returns></returns>
  74. public RState Monitor()
  75. {
  76. Runner.Run(SafetyResetStep.RunStop, RunStop, _delay_1ms)
  77. .Run(SafetyResetStep.ErrAck, () => { return _errAckToggleRoutine.Start("ErrAck") == RState.Running; },
  78. () => { return CheckRoutineStatus(_errAckToggleRoutine); }, _delay_1s)
  79. .Run(SafetyResetStep.LockCasseteDoors, () => { return _device.LockCasseteDoor(); },CheckCasseteLocked, _delay_5s)
  80. .Run(SafetyResetStep.LockCellDoors, LockCellDoors,CheckCellLocked, _delay_1ms)
  81. .Run(SafetyResetStep.LockAlignerDoors, () => { return _device.LockAlignerDoor(); },CheckAlignerLocked, _delay_1ms)
  82. .Run(SafetyResetStep.FacilityStoEstopRestart, () => { return _facilityStoEstopRestart.Start("FacilityStoEstopRestart") == RState.Running; },
  83. () => { return CheckRoutineStatus(_facilityStoEstopRestart); }, _delay_1s)
  84. .Delay(SafetyResetStep.FacilityEstopDelay,100)//100 delay
  85. .Run(SafetyResetStep.PlatingCell12Sto1EstopDelay, () => { return _platingCell12Sto1EstopRestart.Start("PlatingCell12Sto1EstopRestart") == RState.Running; },
  86. () => { return CheckRoutineStatus(_platingCell12Sto1EstopRestart); }, _delay_1s)
  87. .Delay(SafetyResetStep.PlatingCell12Sto1EstopDelay, 100)//100 delay
  88. .Run(SafetyResetStep.PlatingCell12Sto2EstopDelay, () => { return _platingCell12Sto2EstopRestart.Start("PlatingCell12Sto2EstopRestart") == RState.Running; },
  89. () => { return CheckRoutineStatus(_platingCell12Sto2EstopRestart); }, _delay_1s)
  90. .Delay(SafetyResetStep.PlatingCell12Sto1EstopDelay, 100)//100 delay
  91. .Run(SafetyResetStep.PlatingCell34Sto1EstopDelay, () => { return _platingCell34Sto1EstopRestart.Start("PlatingCell34Sto1EstopRestart") == RState.Running; },
  92. () => { return CheckRoutineStatus(_platingCell34Sto1EstopRestart); }, _delay_1s)
  93. .Delay(SafetyResetStep.PlatingCell34Sto1EstopDelay, 100)//100 delay
  94. .Run(SafetyResetStep.PlatingCell34Sto2EstopDelay, () => { return _platingCell34Sto1EstopRestart.Start("PlatingCell34Sto2EstopRestart") == RState.Running; },
  95. () => { return CheckRoutineStatus(_platingCell34Sto2EstopRestart); }, _delay_1s)
  96. .Delay(SafetyResetStep.PlatingCell34Sto1EstopDelay, 100)//100 delay
  97. .Run(SafetyResetStep.SlsRestart, () => { return _slsRestart.Start("SlsRestart") == RState.Running; },
  98. () => { return CheckRoutineStatus(_slsRestart); }, _delay_1s)
  99. .End(SafetyResetStep.End, NullFun, _delay_1ms);
  100. return Runner.Status;
  101. }
  102. /// <summary>
  103. ///
  104. /// </summary>
  105. /// <returns></returns>
  106. private bool RunStop()
  107. {
  108. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{RUNSTOP}");
  109. return IOModuleManager.Instance.WriteIoValue(ioName, true);
  110. }
  111. /// <summary>
  112. /// 检验是否完成
  113. /// </summary>
  114. /// <param name="routine"></param>
  115. /// <returns></returns>
  116. private bool CheckRoutineStatus (IRoutine routine)
  117. {
  118. RState rsState = routine.Monitor();
  119. return rsState == RState.End;
  120. }
  121. /// <summary>
  122. /// 检验Process door locked状态
  123. /// </summary>
  124. /// <returns></returns>
  125. private bool CheckCasseteLocked()
  126. {
  127. return _device.SafetyData.CassetteDoorsLeftLocked&& _device.SafetyData.CassetteDoorsRightLocked;
  128. }
  129. /// <summary>
  130. /// lock cell doors
  131. /// </summary>
  132. /// <returns></returns>
  133. private bool LockCellDoors()
  134. {
  135. return _device.LockCell12Door() && _device.LockCell34Door();
  136. }
  137. /// <summary>
  138. /// 检验Cell locked状态
  139. /// </summary>
  140. /// <returns></returns>
  141. private bool CheckCellLocked()
  142. {
  143. return _device.SafetyData.Cell12DoorsLeftLocked && _device.SafetyData.Cell12DoorsRightLocked && _device.SafetyData.Cell34DoorsLeftLocked &&
  144. _device.SafetyData.Cell34DoorsRightLocked;
  145. }
  146. /// <summary>
  147. /// 检验Aligner door locked
  148. /// </summary>
  149. /// <returns></returns>
  150. private bool CheckAlignerLocked()
  151. {
  152. return _device.SafetyData.AlignerDoorClosed;
  153. }
  154. /// <summary>
  155. /// 启动
  156. /// </summary>
  157. /// <param name="objs"></param>
  158. /// <returns></returns>
  159. public RState Start(params object[] objs)
  160. {
  161. _device = DEVICE.GetDevice<SafetyDevice>("Safety");
  162. return Runner.Start(Module, "Start Reset safety");
  163. }
  164. }
  165. }