MotionAxisContracts.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. using System.Collections.Generic;
  3. namespace TeamAAS.Global.Devices
  4. {
  5. /// <summary>轴的整体状态。</summary>
  6. public enum AxisState
  7. {
  8. Off,
  9. StandStill,
  10. DiscreteMotion,
  11. ContinuousMotion,
  12. Homing,
  13. Error
  14. }
  15. /// <summary>回零模式。</summary>
  16. public enum HomeMode
  17. {
  18. Default,
  19. LimitSwitch,
  20. HomeSwitch,
  21. ZPhase
  22. }
  23. /// <summary>运动参数。</summary>
  24. public class MotionParams
  25. {
  26. public double Velocity { get; set; }
  27. public double Acceleration { get; set; }
  28. public double Deceleration { get; set; }
  29. public double Jerk { get; set; }
  30. }
  31. public class AxisEventArgs : EventArgs
  32. {
  33. public int AxisNo { get; }
  34. public AxisEventArgs(int axisNo) => AxisNo = axisNo;
  35. }
  36. public class AxisMotionEventArgs : AxisEventArgs
  37. {
  38. public double TargetPosition { get; }
  39. public double ActualPosition { get; }
  40. public AxisMotionEventArgs(int axisNo, double target, double actual) : base(axisNo)
  41. {
  42. TargetPosition = target;
  43. ActualPosition = actual;
  44. }
  45. }
  46. public class AxisStateChangedEventArgs : AxisEventArgs
  47. {
  48. public AxisState OldState { get; }
  49. public AxisState NewState { get; }
  50. public AxisStateChangedEventArgs(int axisNo, AxisState oldState, AxisState newState) : base(axisNo)
  51. {
  52. OldState = oldState;
  53. NewState = newState;
  54. }
  55. }
  56. public class AxisErrorEventArgs : AxisEventArgs
  57. {
  58. public string ErrorMessage { get; }
  59. public AxisErrorEventArgs(int axisNo, string message) : base(axisNo) => ErrorMessage = message;
  60. }
  61. public class MotionConnectionStateChangedEventArgs : EventArgs
  62. {
  63. public bool Connected { get; }
  64. public MotionConnectionStateChangedEventArgs(bool connected) => Connected = connected;
  65. }
  66. public class MotionErrorEventArgs : EventArgs
  67. {
  68. public string ErrorMessage { get; }
  69. public MotionErrorEventArgs(string message) => ErrorMessage = message;
  70. }
  71. /// <summary>
  72. /// 单轴控制接口(调试/UI 门面;流程层优先使用 <see cref="IMotionCard"/> 索引 API)。
  73. /// </summary>
  74. public interface IAxis
  75. {
  76. int AxisNo { get; }
  77. string Name { get; set; }
  78. AxisState State { get; }
  79. bool IsEnabled { get; }
  80. bool IsMoving { get; }
  81. bool IsHomed { get; }
  82. double CommandPosition { get; }
  83. double ActualPosition { get; }
  84. double ActualVelocity { get; }
  85. double Velocity { get; set; }
  86. double Acceleration { get; set; }
  87. double Deceleration { get; set; }
  88. double Jerk { get; set; }
  89. void Enable();
  90. void Disable();
  91. void MoveTo(double position);
  92. void MoveBy(double distance);
  93. void Jog(double velocity);
  94. void Stop();
  95. void Home(HomeMode mode = HomeMode.Default);
  96. void SetPosition(double position);
  97. void SetMotionParams(MotionParams parameters);
  98. event EventHandler<AxisMotionEventArgs> MotionStarted;
  99. event EventHandler<AxisMotionEventArgs> MotionCompleted;
  100. event EventHandler<AxisStateChangedEventArgs> StateChanged;
  101. event EventHandler<AxisErrorEventArgs> ErrorOccurred;
  102. }
  103. }