using XP.Hardware.MotionControl.Abstractions.Enums;
namespace XP.Hardware.MotionControl.Abstractions
{
///
/// 旋转轴抽象基类 | Rotary Axis Abstract Base Class
/// 提供角度边界检查、启用状态管理等通用逻辑 | Provides angle boundary check, enabled status management
///
public abstract class RotaryAxisBase : IRotaryAxis
{
/// 轴标识 | Axis identifier
protected readonly RotaryAxisId _axisId;
/// 最小角度(度)| Minimum angle (degrees)
protected readonly double _minAngle;
/// 最大角度(度)| Maximum angle (degrees)
protected readonly double _maxAngle;
/// 是否启用 | Is enabled
protected readonly bool _enabled;
/// 轴标识 | Axis identifier
public RotaryAxisId Id => _axisId;
/// 实际角度(度)| Actual angle (degrees)
public double ActualAngle { get; protected set; }
/// 轴状态 | Axis status
public AxisStatus Status { get; protected set; } = AxisStatus.Idle;
/// 是否启用 | Is enabled
public bool Enabled => _enabled;
///
/// 构造函数 | Constructor
///
/// 轴标识 | Axis identifier
/// 最小角度(度)| Minimum angle (degrees)
/// 最大角度(度)| Maximum angle (degrees)
/// 是否启用 | Is enabled
protected RotaryAxisBase(RotaryAxisId axisId, double minAngle, double maxAngle, bool enabled)
{
_axisId = axisId;
_minAngle = minAngle;
_maxAngle = maxAngle;
_enabled = enabled;
}
/// 验证目标角度是否在范围内 | Validate target angle within range
/// 目标角度(度)| Target angle (degrees)
/// true=在范围内,false=越界 | true=within range, false=out of range
public bool ValidateTarget(double targetAngle) => targetAngle >= _minAngle && targetAngle <= _maxAngle;
///
public abstract MotionResult MoveToTarget(double targetAngle, double? speed = null);
///
public abstract MotionResult JogStart(bool positive);
///
public abstract MotionResult JogStop();
///
public abstract MotionResult Home();
///
public abstract MotionResult Stop();
///
public abstract void UpdateStatus();
}
}