using XP.Hardware.MotionControl.Abstractions.Enums;
namespace XP.Hardware.MotionControl.Abstractions
{
///
/// 直线轴抽象基类 | Linear Axis Abstract Base Class
/// 提供边界检查、状态管理等通用逻辑 | Provides boundary check, status management
///
public abstract class LinearAxisBase : ILinearAxis
{
/// 轴标识 | Axis identifier
protected readonly AxisId _axisId;
/// 最小位置(mm)| Minimum position (mm)
protected readonly double _min;
/// 最大位置(mm)| Maximum position (mm)
protected readonly double _max;
/// 原点偏移(mm)| Origin offset (mm)
protected readonly double _origin;
/// 轴标识 | Axis identifier
public AxisId Id => _axisId;
/// 实际位置(mm)| Actual position (mm)
public double ActualPosition { get; protected set; }
/// 轴状态 | Axis status
public AxisStatus Status { get; protected set; } = AxisStatus.Idle;
/// 正限位触发 | Positive limit triggered
public bool PositiveLimitHit { get; protected set; }
/// 负限位触发 | Negative limit triggered
public bool NegativeLimitHit { get; protected set; }
///
/// 构造函数 | Constructor
///
/// 轴标识 | Axis identifier
/// 最小位置(mm)| Minimum position (mm)
/// 最大位置(mm)| Maximum position (mm)
/// 原点偏移(mm)| Origin offset (mm)
protected LinearAxisBase(AxisId axisId, double min, double max, double origin)
{
_axisId = axisId;
_min = min;
_max = max;
_origin = origin;
}
/// 验证目标位置是否在范围内 | Validate target within range
/// 目标位置(mm)| Target position (mm)
/// true=在范围内,false=越界 | true=within range, false=out of range
public bool ValidateTarget(double target) => target >= _min && target <= _max;
///
public abstract MotionResult MoveToTarget(double target, 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();
}
}