LinMotStopMotorRoutine.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using Aitex.Core.RT.Routine;
  2. using MECF.Framework.Common.Device.LinMot;
  3. using MECF.Framework.Common.Routine;
  4. using Mono.Security.X509;
  5. using CyberX8_Core;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace CyberX8_RT.Devices.LinMot
  12. {
  13. public class LinMotStopMotorRoutine : RoutineBase, IRoutine
  14. {
  15. private enum LinMotStopMotorStep
  16. {
  17. Freeze,
  18. GoToInitialPosition,
  19. ReDelay,
  20. ReWait,
  21. LastSwitchOn,
  22. LastSwitchOff,
  23. End
  24. }
  25. #region 内部变量
  26. private LinMotAxis _axis;
  27. private bool _lastSwitchOff = false;
  28. #endregion
  29. public LinMotStopMotorRoutine(string module,LinMotAxis axis) : base(module)
  30. {
  31. _axis = axis;
  32. }
  33. public void Abort()
  34. {
  35. Runner.Stop("Manual Abort");
  36. }
  37. public RState Monitor()
  38. {
  39. Runner.Run(LinMotStopMotorStep.Freeze, () => { return _axis.SendOperation(LinMotOperation.Freeze); }, CheckMotorStop, _delay_5s)
  40. .Run(LinMotStopMotorStep.GoToInitialPosition, () => { return _axis.SendOperation(LinMotOperation.GoToInitialPosition); }, NullFun, 100)
  41. .Delay(LinMotStopMotorStep.ReDelay, 200)
  42. .WaitWithStopCondition(LinMotStopMotorStep.ReWait, CheckInTargetPosition,CheckAxisIsStop )
  43. .Run(LinMotStopMotorStep.LastSwitchOn, () => { return _axis.SendOperation(LinMotOperation.SwitchOn); }, CheckSwitchOn, _delay_5s)
  44. .RunIf(LinMotStopMotorStep.LastSwitchOff, _lastSwitchOff, () => { return _axis.SendOperation(LinMotOperation.SwitchOff); }, _delay_1ms)
  45. .End(LinMotStopMotorStep.End, NullFun);
  46. return Runner.Status;
  47. }
  48. public RState Start(params object[] objs)
  49. {
  50. _lastSwitchOff = objs == null || objs.Length == 0 ? false : (bool)objs[0];
  51. return Runner.Start(Module, "StopMotion");
  52. }
  53. private bool CheckInTargetPosition()
  54. {
  55. return _axis.InTargetPosition;
  56. }
  57. private bool CheckAxisIsStop()
  58. {
  59. return !_axis.IsMotorOn;
  60. }
  61. private bool CheckSwitchOn()
  62. {
  63. return _axis.IsSwitchOn;
  64. }
  65. private bool CheckMotorStop()
  66. {
  67. return !_axis.IsMotorOn ;
  68. }
  69. }
  70. }