LinMotResetRoutine.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using Aitex.Core.RT.Routine;
  2. using MECF.Framework.Common.Device.LinMot;
  3. using MECF.Framework.Common.Routine;
  4. using CyberX8_Core;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using Aitex.Core.RT.Log;
  11. namespace CyberX8_RT.Devices.LinMot
  12. {
  13. public class LinMotResetRoutine : RoutineBase, IRoutine
  14. {
  15. private enum LinMotResetStep
  16. {
  17. ClearError,
  18. ClearErrorDelay,
  19. SwitchOff,
  20. SwitchOn,
  21. Home,
  22. HomeDelay,
  23. HomeWait,
  24. GoToInitialPosition,
  25. ReDelay,
  26. ReWait,
  27. LastSwitchOn,
  28. LastSwitchOff,
  29. End
  30. }
  31. #region 内部变量
  32. private LinMotAxis _axis;
  33. private bool _lastNeedSwitchOff = false;
  34. #endregion
  35. public LinMotResetRoutine(string module,LinMotAxis axis) : base(module)
  36. {
  37. _axis = axis;
  38. }
  39. public void Abort()
  40. {
  41. Runner.Stop("Manual Abort");
  42. }
  43. public RState Monitor()
  44. {
  45. Runner .Run(LinMotResetStep.ClearError, () => { return _axis.SendOperation(LinMotOperation.ClearError); }, NullFun, 100)
  46. .Delay(LinMotResetStep.ClearErrorDelay, 100)
  47. .Run(LinMotResetStep.SwitchOff, () => { return _axis.SendOperation(LinMotOperation.SwitchOff); }, CheckSwitchOff, _delay_5s)
  48. .Run(LinMotResetStep.SwitchOn, () => { return _axis.SendOperation(LinMotOperation.SwitchOn); }, CheckSwitchOn, _delay_5s)
  49. .RunIf(LinMotResetStep.Home,CheckNotHome(), () => { return _axis.SendOperation(LinMotOperation.Home); }, NullFun, 100)
  50. .Delay(LinMotResetStep.HomeDelay, 500)
  51. .WaitWithStopCondition(LinMotResetStep.HomeWait,CheckHomed,CheckAxisHomeIsStop)
  52. .Run(LinMotResetStep.GoToInitialPosition, () => { return _axis.SendOperation(LinMotOperation.GoToInitialPosition); },NullFun,_delay_1ms)
  53. .Delay(LinMotResetStep.ReDelay,_delay_1s)
  54. .Wait(LinMotResetStep.ReWait,CheckInTarget,_delay_5s)
  55. .Run(LinMotResetStep.LastSwitchOn, () => { return _axis.SendOperation(LinMotOperation.SwitchOn); }, CheckSwitchOn, _delay_5s)
  56. .RunIf(LinMotResetStep.LastSwitchOff, _lastNeedSwitchOff, () => { return _axis.SendOperation(LinMotOperation.SwitchOff); },_delay_1ms)
  57. .End(LinMotResetStep.End, NullFun);
  58. return Runner.Status;
  59. }
  60. public RState Start(params object[] objs)
  61. {
  62. _lastNeedSwitchOff = objs.Length != 0 ? (bool)objs[0] : false;
  63. return Runner.Start(Module, "Reset");
  64. }
  65. private bool CheckSwitchOff()
  66. {
  67. return !_axis.IsSwitchOn;
  68. }
  69. private bool CheckSwitchOn()
  70. {
  71. return _axis.IsSwitchOn;
  72. }
  73. private bool CheckNotHome()
  74. {
  75. return !_axis.IsHomed;
  76. }
  77. private bool CheckHomed()
  78. {
  79. return _axis.IsHomed;
  80. }
  81. private bool CheckInTarget()
  82. {
  83. return _axis.InTargetPosition;
  84. }
  85. private bool CheckAxisTargetIsStop()
  86. {
  87. if(_axis.InTargetPosition)
  88. {
  89. return false;
  90. }
  91. bool result= !_axis.IsMotorOn;
  92. if(result)
  93. {
  94. LOG.WriteLog(eEvent.ERR_PREWET, Module, "Axis is Stop");
  95. return true;
  96. }
  97. return false;
  98. }
  99. private bool CheckAxisHomeIsStop()
  100. {
  101. if (_axis.IsHomed)
  102. {
  103. return false;
  104. }
  105. bool result = !_axis.IsMotorOn;
  106. if (result)
  107. {
  108. LOG.WriteLog(eEvent.ERR_PREWET, Module, "Axis is Stop");
  109. return true;
  110. }
  111. return false;
  112. }
  113. }
  114. }