SafetyResetRoutine.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. Res12StoEstopRestart,
  36. Res12StoEstopDelay,
  37. Res34StoEstopRestart,
  38. Res34StoEstopDelay,
  39. VpwStoEstopRestart,
  40. VpwStoEstopDelay,
  41. SrdStoEstopRestart,
  42. SrdStoEstopDelay,
  43. SlsRestart,
  44. End
  45. }
  46. #region 常量
  47. private const string RUNSTOP = "RunStop";
  48. #endregion
  49. #region 内部变量
  50. private SafetyToggleRoutine _errAckToggleRoutine;
  51. private SafetyToggleRoutine _facilityStoEstopRestart;
  52. private SafetyToggleRoutine _platingCell12Sto1EstopRestart;
  53. private SafetyToggleRoutine _platingCell12Sto2EstopRestart;
  54. private SafetyToggleRoutine _platingCell34Sto1EstopRestart;
  55. private SafetyToggleRoutine _platingCell34Sto2EstopRestart;
  56. private SafetyToggleRoutine _res12StoEstopRestart;
  57. private SafetyToggleRoutine _res34StoEstopRestart;
  58. private SafetyToggleRoutine _vpwStoEstopRestart;
  59. private SafetyToggleRoutine _srdStoEstopRestart;
  60. private SafetyDevice _device;
  61. #endregion
  62. /// <summary>
  63. /// 构造函数
  64. /// </summary>
  65. /// <param name="module"></param>
  66. public SafetyResetRoutine(string module) : base(module)
  67. {
  68. _errAckToggleRoutine = new SafetyToggleRoutine(module);
  69. _facilityStoEstopRestart = new SafetyToggleRoutine(module);
  70. _platingCell12Sto1EstopRestart=new SafetyToggleRoutine(module);
  71. _platingCell12Sto2EstopRestart=new SafetyToggleRoutine(module);
  72. _platingCell34Sto1EstopRestart= new SafetyToggleRoutine(module);
  73. _platingCell34Sto2EstopRestart = new SafetyToggleRoutine(module);
  74. _res12StoEstopRestart=new SafetyToggleRoutine(module);
  75. _res34StoEstopRestart=new SafetyToggleRoutine(module);
  76. _vpwStoEstopRestart = new SafetyToggleRoutine(module);
  77. _srdStoEstopRestart=new SafetyToggleRoutine (module);
  78. }
  79. /// <summary>
  80. /// 中止
  81. /// </summary>
  82. public void Abort()
  83. {
  84. Runner.Stop("Manaul abort safety reset");
  85. }
  86. /// <summary>
  87. /// 监控
  88. /// </summary>
  89. /// <returns></returns>
  90. public RState Monitor()
  91. {
  92. Runner.Run(SafetyResetStep.RunStop, RunStop, _delay_1ms)
  93. .Run(SafetyResetStep.ErrAck, () => { return _errAckToggleRoutine.Start("ErrAck") == RState.Running; },
  94. () => { return CheckRoutineStatus(_errAckToggleRoutine); }, _delay_1s)
  95. .Run(SafetyResetStep.LockCasseteDoors, () => { return _device.LockCasseteDoor(); },CheckCasseteLocked, _delay_5s)
  96. .Run(SafetyResetStep.LockCellDoors, LockCellDoors,CheckCellLocked, _delay_1ms)
  97. .Run(SafetyResetStep.LockAlignerDoors, () => { return _device.LockAlignerDoor(); },CheckAlignerLocked, _delay_1ms)
  98. .Run(SafetyResetStep.FacilityStoEstopRestart, () => { return _facilityStoEstopRestart.Start("FacilityStoEstopRestart") == RState.Running; },
  99. () => { return CheckRoutineStatus(_facilityStoEstopRestart); }, _delay_1s)
  100. .Delay(SafetyResetStep.FacilityEstopDelay,100)//100 delay
  101. .Run(SafetyResetStep.PlatingCell12Sto1EstopDelay, () => { return _platingCell12Sto1EstopRestart.Start("PlatingCell12Sto1EstopRestart") == RState.Running; },
  102. () => { return CheckRoutineStatus(_platingCell12Sto1EstopRestart); }, _delay_1s)
  103. .Delay(SafetyResetStep.PlatingCell12Sto1EstopDelay, 100)//100 delay
  104. .Run(SafetyResetStep.PlatingCell12Sto2EstopDelay, () => { return _platingCell12Sto2EstopRestart.Start("PlatingCell12Sto2EstopRestart") == RState.Running; },
  105. () => { return CheckRoutineStatus(_platingCell12Sto2EstopRestart); }, _delay_1s)
  106. .Delay(SafetyResetStep.PlatingCell12Sto1EstopDelay, 100)//100 delay
  107. .Run(SafetyResetStep.PlatingCell34Sto1EstopDelay, () => { return _platingCell34Sto1EstopRestart.Start("PlatingCell34Sto1EstopRestart") == RState.Running; },
  108. () => { return CheckRoutineStatus(_platingCell34Sto1EstopRestart); }, _delay_1s)
  109. .Delay(SafetyResetStep.PlatingCell34Sto1EstopDelay, 100)//100 delay
  110. .Run(SafetyResetStep.PlatingCell34Sto2EstopDelay, () => { return _platingCell34Sto1EstopRestart.Start("PlatingCell34Sto2EstopRestart") == RState.Running; },
  111. () => { return CheckRoutineStatus(_platingCell34Sto2EstopRestart); }, _delay_1s)
  112. .Delay(SafetyResetStep.PlatingCell34Sto1EstopDelay, 100)//100 delay
  113. .Run(SafetyResetStep.Res12StoEstopDelay, () => { return _res12StoEstopRestart.Start("Res12StoEstopRestart") == RState.Running; },
  114. () => { return CheckRoutineStatus(_res12StoEstopRestart); }, _delay_1s)
  115. .Delay(SafetyResetStep.Res12StoEstopDelay, 100)//100 delay
  116. .Run(SafetyResetStep.Res34StoEstopDelay, () => { return _res34StoEstopRestart.Start("Res34StoEstopRestart") == RState.Running; },
  117. () => { return CheckRoutineStatus(_res34StoEstopRestart); }, _delay_1s)
  118. .Delay(SafetyResetStep.Res34StoEstopDelay, 100)//100 delay
  119. .Run(SafetyResetStep.VpwStoEstopRestart, () => { return _vpwStoEstopRestart.Start("VpwStoEstopRestart") == RState.Running; },
  120. () => { return CheckRoutineStatus(_vpwStoEstopRestart); }, _delay_1s)
  121. .Delay(SafetyResetStep.VpwStoEstopDelay, 100)//100 delay
  122. .Run(SafetyResetStep.SrdStoEstopRestart, () => { return _srdStoEstopRestart.Start("SrdStoEstopRestart") == RState.Running; },
  123. () => { return CheckRoutineStatus(_srdStoEstopRestart); }, _delay_1s)
  124. .Delay(SafetyResetStep.SrdStoEstopRestart, 100)//100 delay
  125. .End(SafetyResetStep.End, NullFun, _delay_1ms);
  126. return Runner.Status;
  127. }
  128. /// <summary>
  129. ///
  130. /// </summary>
  131. /// <returns></returns>
  132. private bool RunStop()
  133. {
  134. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{RUNSTOP}");
  135. return IOModuleManager.Instance.WriteIoValue(ioName, true);
  136. }
  137. /// <summary>
  138. /// 检验是否完成
  139. /// </summary>
  140. /// <param name="routine"></param>
  141. /// <returns></returns>
  142. private bool CheckRoutineStatus (IRoutine routine)
  143. {
  144. RState rsState = routine.Monitor();
  145. return rsState == RState.End;
  146. }
  147. /// <summary>
  148. /// 检验Process door locked状态
  149. /// </summary>
  150. /// <returns></returns>
  151. private bool CheckCasseteLocked()
  152. {
  153. return _device.SafetyData.CassetteDoorsLeftLocked&& _device.SafetyData.CassetteDoorsRightLocked;
  154. }
  155. /// <summary>
  156. /// lock cell doors
  157. /// </summary>
  158. /// <returns></returns>
  159. private bool LockCellDoors()
  160. {
  161. return _device.LockCell12Door() && _device.LockCell34Door();
  162. }
  163. /// <summary>
  164. /// 检验Cell locked状态
  165. /// </summary>
  166. /// <returns></returns>
  167. private bool CheckCellLocked()
  168. {
  169. return _device.SafetyData.Cell12DoorsLeftLocked && _device.SafetyData.Cell12DoorsRightLocked && _device.SafetyData.Cell34DoorsLeftLocked &&
  170. _device.SafetyData.Cell34DoorsRightLocked;
  171. }
  172. /// <summary>
  173. /// 检验Aligner door locked
  174. /// </summary>
  175. /// <returns></returns>
  176. private bool CheckAlignerLocked()
  177. {
  178. return _device.SafetyData.AlignerDoorClosed;
  179. }
  180. /// <summary>
  181. /// 启动
  182. /// </summary>
  183. /// <param name="objs"></param>
  184. /// <returns></returns>
  185. public RState Start(params object[] objs)
  186. {
  187. _device = DEVICE.GetDevice<SafetyDevice>("Safety");
  188. return Runner.Start(Module, "Start Reset safety");
  189. }
  190. }
  191. }