95 lines
4.2 KiB
C#
95 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using XP.Hardware.MotionControl.Abstractions;
|
|
using XP.Hardware.MotionControl.Abstractions.Enums;
|
|
using XP.Hardware.MotionControl.Config;
|
|
|
|
namespace XP.Hardware.MotionControl.Implementations
|
|
{
|
|
/// <summary>
|
|
/// 虚拟运动系统实现 | Simulated Motion System Implementation
|
|
/// 根据 MotionControlConfig 创建虚拟轴实例,无需真实 PLC 硬件
|
|
/// Creates simulated axis instances from MotionControlConfig, no real PLC required
|
|
/// </summary>
|
|
public class SimulatedMotionSystem : IMotionSystem
|
|
{
|
|
private readonly Dictionary<AxisId, ILinearAxis> _linearAxes = new();
|
|
private readonly Dictionary<RotaryAxisId, IRotaryAxis> _rotaryAxes = new();
|
|
private readonly ISafetyDoor _safetyDoor;
|
|
private readonly IJoystick _joystick;
|
|
private readonly IAxisReset _axisReset;
|
|
|
|
/// <summary>
|
|
/// 构造函数 | Constructor
|
|
/// </summary>
|
|
/// <param name="config">运动控制配置 | Motion control configuration</param>
|
|
public SimulatedMotionSystem(MotionControlConfig config)
|
|
{
|
|
if (config == null) throw new ArgumentNullException(nameof(config));
|
|
|
|
// 创建直线轴 | Create linear axes
|
|
if (config.LinearAxes.TryGetValue(AxisId.SourceZ, out var sz))
|
|
_linearAxes[AxisId.SourceZ] = new SimulatedLinearAxis(AxisId.SourceZ, sz.Min, sz.Max, sz.Origin);
|
|
|
|
if (config.LinearAxes.TryGetValue(AxisId.DetectorZ, out var dz))
|
|
_linearAxes[AxisId.DetectorZ] = new SimulatedLinearAxis(AxisId.DetectorZ, dz.Min, dz.Max, dz.Origin);
|
|
|
|
if (config.LinearAxes.TryGetValue(AxisId.StageX, out var sx))
|
|
_linearAxes[AxisId.StageX] = new SimulatedLinearAxis(AxisId.StageX, sx.Min, sx.Max, sx.Origin);
|
|
|
|
if (config.LinearAxes.TryGetValue(AxisId.StageY, out var sy))
|
|
_linearAxes[AxisId.StageY] = new SimulatedLinearAxis(AxisId.StageY, sy.Min, sy.Max, sy.Origin);
|
|
|
|
// 创建旋转轴 | Create rotary axes
|
|
if (config.RotaryAxes.TryGetValue(RotaryAxisId.DetectorSwing, out var ds))
|
|
_rotaryAxes[RotaryAxisId.DetectorSwing] = new SimulatedRotaryAxis(RotaryAxisId.DetectorSwing, ds.Min, ds.Max, ds.Enabled);
|
|
|
|
if (config.RotaryAxes.TryGetValue(RotaryAxisId.StageRotation, out var sr))
|
|
_rotaryAxes[RotaryAxisId.StageRotation] = new SimulatedRotaryAxis(RotaryAxisId.StageRotation, sr.Min, sr.Max, sr.Enabled);
|
|
|
|
if (config.RotaryAxes.TryGetValue(RotaryAxisId.FixtureRotation, out var fr))
|
|
_rotaryAxes[RotaryAxisId.FixtureRotation] = new SimulatedRotaryAxis(RotaryAxisId.FixtureRotation, fr.Min, fr.Max, fr.Enabled);
|
|
|
|
// 创建辅助设备 | Create helper devices
|
|
_safetyDoor = new SimulatedSafetyDoor();
|
|
_joystick = new SimulatedJoystick();
|
|
_axisReset = new SimulatedAxisReset();
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public ISafetyDoor SafetyDoor => _safetyDoor;
|
|
|
|
/// <inheritdoc/>
|
|
public IJoystick Joystick => _joystick;
|
|
|
|
/// <inheritdoc/>
|
|
public IAxisReset AxisReset => _axisReset;
|
|
|
|
/// <inheritdoc/>
|
|
public IReadOnlyDictionary<AxisId, ILinearAxis> LinearAxes => _linearAxes;
|
|
|
|
/// <inheritdoc/>
|
|
public IReadOnlyDictionary<RotaryAxisId, IRotaryAxis> RotaryAxes => _rotaryAxes;
|
|
|
|
/// <inheritdoc/>
|
|
public ILinearAxis GetLinearAxis(AxisId axisId)
|
|
{
|
|
if (_linearAxes.TryGetValue(axisId, out var axis)) return axis;
|
|
throw new KeyNotFoundException($"[Simulated] 未找到直线轴 {axisId} | Linear axis {axisId} not found");
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public IRotaryAxis GetRotaryAxis(RotaryAxisId axisId)
|
|
{
|
|
if (_rotaryAxes.TryGetValue(axisId, out var axis)) return axis;
|
|
throw new KeyNotFoundException($"[Simulated] 未找到旋转轴 {axisId} | Rotary axis {axisId} not found");
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public void UpdateAllStatus()
|
|
{
|
|
// 虚拟运动系统无需从 PLC 轮询状态 | No PLC polling needed for simulated motion system
|
|
}
|
|
}
|
|
}
|