MotionContracts.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Collections.Generic;
  3. namespace TeamAAS.Global.Devices
  4. {
  5. /// <summary>轴状态快照(流程/状态栏批量读取用)。</summary>
  6. public sealed class AxisStatus
  7. {
  8. public int Index { get; set; }
  9. public string Name { get; set; }
  10. public double Position { get; set; }
  11. public double Velocity { get; set; }
  12. public bool IsMoving { get; set; }
  13. public bool IsHomed { get; set; }
  14. public bool IsEnabled { get; set; }
  15. public bool PositiveLimit { get; set; }
  16. public bool NegativeLimit { get; set; }
  17. public bool Alarm { get; set; }
  18. }
  19. /// <summary>
  20. /// 运动控制卡统一契约:索引式 API(流程层)+ 轴对象(调试层)+ 插补/IO。
  21. /// 品牌适配器(仿真/雷赛/汇川 IMC60G 等)实现本接口后注册进 MotionManager。
  22. /// </summary>
  23. public interface IMotionCard : IConnectableDevice
  24. {
  25. int AxisCount { get; }
  26. // --- 流程层:索引 API ---
  27. bool SetEnable(int axis, bool enable);
  28. bool Home(int axis, int mode = 0);
  29. bool IsHomed(int axis);
  30. bool MoveAbsolute(int axis, double position, double velocity);
  31. bool MoveRelative(int axis, double distance, double velocity);
  32. bool JogStart(int axis, int direction, double velocity);
  33. bool JogStop(int axis);
  34. /// <summary>平滑停止(axis=-1 表示全部轴)。</summary>
  35. bool Stop(int axis = -1);
  36. AxisStatus GetAxisStatus(int axis);
  37. List<AxisStatus> GetAllAxisStatus();
  38. // --- 调试层:轴对象 ---
  39. IAxis GetAxis(int axisNo);
  40. IList<IAxis> GetAxes();
  41. // --- 多轴协同 ---
  42. bool MoveLinear(double[] targetPositions, double velocity);
  43. bool MoveArc(double[] centerPoint, double[] targetPositions, double velocity);
  44. /// <summary>急停全部轴。</summary>
  45. bool EmergencyStop();
  46. // --- 板载 IO(无 bank 时按本地端子)---
  47. bool ReadDI(int portIndex);
  48. bool WriteDO(int portIndex, bool value);
  49. event EventHandler<MotionConnectionStateChangedEventArgs> ConnectionStateChanged;
  50. event EventHandler<MotionErrorEventArgs> ErrorOccurred;
  51. }
  52. /// <summary>运动卡 IO 分区:本地端子板与 EtherCAT 扩展点号相互独立。</summary>
  53. public enum MotionIoBank
  54. {
  55. Local = 0,
  56. EtherCat = 1
  57. }
  58. /// <summary>运动卡本地 / EtherCAT 数字量 IO。</summary>
  59. public interface IMotionIoHost
  60. {
  61. bool CanSimulateDi { get; }
  62. int GetDiCount(MotionIoBank bank);
  63. int GetDoCount(MotionIoBank bank);
  64. bool ReadDI(MotionIoBank bank, int index);
  65. bool ReadDO(MotionIoBank bank, int index);
  66. bool WriteDO(MotionIoBank bank, int index, bool value);
  67. bool WriteDI(MotionIoBank bank, int index, bool value);
  68. }
  69. /// <summary>
  70. /// 卡级安全互锁:急停下使能并禁止使能/运动;停止信号禁止运动。
  71. /// </summary>
  72. public interface IMotionSafetyHost
  73. {
  74. bool IsEstopActive { get; }
  75. bool IsStopActive { get; }
  76. bool AllowEnable(out string reason);
  77. bool AllowMotion(out string reason);
  78. event EventHandler SafetyChanged;
  79. }
  80. /// <summary>
  81. /// 仿真卡时钟。点到点应一次拨完剩余行程;超时只用于真实等待(点动/硬件),不要和仿真行程绑在同一循环。
  82. /// </summary>
  83. public interface IMotionSimulation
  84. {
  85. void Simulate(double deltaSeconds);
  86. /// <summary>把所有点到点运动按剩余路程/速度一次仿真到结束。点动保持运动中。</summary>
  87. void FinishDiscreteMoves();
  88. }
  89. /// <summary>
  90. /// IO 卡(如 GR20T-ECT-1616ETN)统一契约。
  91. /// </summary>
  92. public interface IIOCard : IConnectableDevice
  93. {
  94. int InputCount { get; }
  95. int OutputCount { get; }
  96. bool[] ReadAllInputs();
  97. bool[] ReadAllOutputs();
  98. bool WriteOutput(int index, bool value);
  99. bool WriteOutputs(bool[] values);
  100. }
  101. }