Files

77 lines
2.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using XP.Hardware.MotionControl.Abstractions.Enums;
namespace XP.Hardware.MotionControl.Abstractions
{
/// <summary>
/// 直线轴抽象基类 | Linear Axis Abstract Base Class
/// 提供边界检查、状态管理等通用逻辑 | Provides boundary check, status management
/// </summary>
public abstract class LinearAxisBase : ILinearAxis
{
/// <summary>轴标识 | Axis identifier</summary>
protected readonly AxisId _axisId;
/// <summary>最小位置(mm| Minimum position (mm)</summary>
protected readonly double _min;
/// <summary>最大位置(mm| Maximum position (mm)</summary>
protected readonly double _max;
/// <summary>原点偏移(mm| Origin offset (mm)</summary>
protected readonly double _origin;
/// <summary>轴标识 | Axis identifier</summary>
public AxisId Id => _axisId;
/// <summary>实际位置(mm| Actual position (mm)</summary>
public double ActualPosition { get; protected set; }
/// <summary>轴状态 | Axis status</summary>
public AxisStatus Status { get; protected set; } = AxisStatus.Idle;
/// <summary>正限位触发 | Positive limit triggered</summary>
public bool PositiveLimitHit { get; protected set; }
/// <summary>负限位触发 | Negative limit triggered</summary>
public bool NegativeLimitHit { get; protected set; }
/// <summary>
/// 构造函数 | Constructor
/// </summary>
/// <param name="axisId">轴标识 | Axis identifier</param>
/// <param name="min">最小位置(mm| Minimum position (mm)</param>
/// <param name="max">最大位置(mm| Maximum position (mm)</param>
/// <param name="origin">原点偏移(mm| Origin offset (mm)</param>
protected LinearAxisBase(AxisId axisId, double min, double max, double origin)
{
_axisId = axisId;
_min = min;
_max = max;
_origin = origin;
}
/// <summary>验证目标位置是否在范围内 | Validate target within range</summary>
/// <param name="target">目标位置(mm| Target position (mm)</param>
/// <returns>true=在范围内,false=越界 | true=within range, false=out of range</returns>
public bool ValidateTarget(double target) => target >= _min && target <= _max;
/// <inheritdoc/>
public abstract MotionResult MoveToTarget(double target, double? speed = null);
/// <inheritdoc/>
public abstract MotionResult JogStart(bool positive);
/// <inheritdoc/>
public abstract MotionResult JogStop();
/// <inheritdoc/>
public abstract MotionResult Home();
/// <inheritdoc/>
public abstract MotionResult Stop();
/// <inheritdoc/>
public abstract void UpdateStatus();
}
}