# XP.Hardware.MotionControl 工业运动控制模块 | Industrial Motion Control Module --- ## 项目概述 | Project Overview XP.Hardware.MotionControl 是 XplorePlane 平面CT工业检测系统的核心运动控制模块,负责管理4个直线轴(SourceZ、DetectorZ、StageX、StageY)、3个旋转轴(DetectorSwing、StageRotation、FixtureRotation)及1个安全防护门的全部运动控制逻辑,并提供 FOD/FDD/放大倍率的几何正算与反算能力。 ### 主要特性 | Key Features - 4个直线轴 + 3个旋转轴统一管理(策略模式) - 安全防护门控制(联锁检查、状态机) - FOD/FDD/放大倍率几何正算与反算 - 多轴联动移动(原子性边界检查) - Jog 点动调试(虚拟摇杆控制) - 100ms 周期 PLC 状态轮询 - 基于 Prism EventAggregator 的跨模块事件通讯 - 可配置的轴启用/禁用(FixtureRotation 等可选轴) - Telerik Crystal 主题 UI 控件 - 中/英/繁体中文多语言支持 --- ## 界面组件 | UI Components ### AxisControlView(核心界面控件) `AxisControlView.xaml` 是运动控制模块的核心用户控件,提供完整的轴控制和调试功能: ``` XP.Hardware.MotionControl/Views/ ├── AxisControlView.xaml # 核心轴控制面板(350px+ UserControl) └── AxisControlView.xaml.cs ``` **功能组成 | Features** | 区域 | 组件 | 功能说明 | |------|------|----------| | **标题栏** | TextBlock | 显示"运动控制"标题 | | **左侧** | RadNumericUpDown | 7个轴位置输入框(StageX/Y/SourceZ/DetectorZ/DetectorSwing/StageRotation/FixtureRotation) | | **右侧** | VirtualJoystick | 单轴摇杆(Z轴)+ 双轴摇杆(XY+旋转) | | **底部** | RadButton | 使能开关、摇杆模式切换、SZDZ锁定、保存/恢复位置 | **ViewModel 绑定 | ViewModel Bindings** | 属性 | 类型 | 说明 | |------|------|------| | `StageXPosition` / `StageYPosition` | double | 载物台 X/Y 轴位置(mm) | | `SourceZPosition` / `DetectorZPosition` | double | 射线源/探测器 Z 轴位置(mm) | | `DetectorSwingAngle` | double | 探测器摆动角度(度) | | `StageRotationAngle` | double | 载物台旋转角度(度) | | `FixtureRotationAngle` | double | 夹具旋转角度(度) | | `IsJoystickEnabled` | bool | 摇杆使能开关 | | `SwapMouseButtons` | bool | 摇杆左右键功能切换 | | `SZDZLock` | bool | 射线源/探测器Z轴锁定移动 | | `SavedPositions` | SavedPositions | 已保存的位置快照 | **交互方式 | Interaction Modes** 1. **手动输入**:直接编辑 RadNumericUpDown,Enter 确认,Escape 取消 2. **单轴摇杆**:拖拽单轴摇杆控制 SourceZ/DetectorZ 轴 Jog 3. **双轴摇杆**: - 左键拖拽:控制 StageX/Y 轴(X轴=左右,Y轴=上下) - 右键拖拽:控制 StageRotation/DetectorSwing 轴(X轴=旋转,Y轴=摆动) 4. **快捷按钮**: - 使能开关:启用/禁用摇杆控制 - 摇杆模式:切换左右键功能(左键XY/右键旋转 vs 左键旋转/右键摆动) - SZDZ锁定:锁定 SourceZ/DetectorZ 同步移动 - 保存/恢复:保存当前所有轴位置或恢复到上次保存位置 --- ## 框架架构 | Architecture ``` XP.Hardware.MotionControl/ ├── Abstractions/ # 抽象层 | Abstraction Layer │ ├── ILinearAxis.cs # 直线轴策略接口 │ ├── IRotaryAxis.cs # 旋转轴策略接口 │ ├── ISafetyDoor.cs # 安全门策略接口 │ ├── IJoystick.cs # 实体摇杆接口 │ ├── IAxisReset.cs # 轴复位接口 │ ├── IMotionSystem.cs # 顶层系统管理接口 │ ├── LinearAxisBase.cs # 直线轴抽象基类(含边界检查) │ ├── RotaryAxisBase.cs # 旋转轴抽象基类 │ ├── SafetyDoorBase.cs # 安全门抽象基类 │ ├── MotionResult.cs # 统一操作结果类型 │ ├── Enums/ # 枚举定义 │ │ ├── AxisId.cs # 直线轴标识 │ │ ├── RotaryAxisId.cs # 旋转轴标识 │ │ ├── AxisStatus.cs # 轴状态 │ │ └── DoorStatus.cs # 门状态 │ └── Events/ # Prism 事件定义 │ ├── AxisStatusChangedEvent.cs │ ├── DoorStatusChangedEvent.cs │ ├── DoorInterlockChangedEvent.cs │ ├── GeometryUpdatedEvent.cs │ ├── GeometryApplyRequestEvent.cs │ ├── JoystickActiveEvent.cs │ └── MotionErrorEvent.cs ├── Implementations/ # PLC 实现层 │ ├── PlcLinearAxis.cs # 基于 PLC 的直线轴实现 │ ├── PlcRotaryAxis.cs # 基于 PLC 的旋转轴实现 │ ├── PlcSafetyDoor.cs # 基于 PLC 的安全门实现 │ ├── PlcJoystick.cs # 基于 PLC 的实体摇杆实现 │ ├── PlcAxisReset.cs # 基于 PLC 的轴复位实现 │ └── PlcMotionSystem.cs # 运动系统管理器 ├── Services/ # 业务服务层 │ ├── IMotionControlService.cs # 业务服务接口 │ ├── MotionControlService.cs # 服务实现(轮询、事件、日志) │ └── GeometryCalculator.cs # 几何计算器 ├── ViewModels/ # 视图模型 │ ├── AxisControlViewModel.cs # AxisControlView ViewModel │ ├── MotionControlViewModel.cs # MotionControlView ViewModel │ └── MotionDebugWindowViewModel.cs # MotionDebugWindow ViewModel ├── Config/ # 配置层 │ ├── MotionControlConfig.cs # 配置实体 │ ├── ConfigLoader.cs # 配置加载器 │ └── MotionSignalNames.cs # PLC 信号名称常量 ├── Views/ # WPF 视图 │ ├── AxisControlView.xaml # 核心轴控制面板(350px+) │ ├── AxisControlView.xaml.cs │ ├── MotionControlView.xaml # 简化版操作面板 │ └── MotionDebugWindow.xaml # Jog 调试窗口 ├── Module/ │ └── MotionControlModule.cs # Prism 模块注册 ├── Resources/ # 多语言资源 │ ├── Resources.resx # 默认(英文) │ ├── Resources.zh-CN.resx # 简体中文 │ ├── Resources.zh-TW.resx # 繁体中文 │ └── Resources.en-US.resx # 英文 └── Documents/ # 文档 ├── README.md # 本文档 └── GUIDENCE.md # 外部集成指南 ``` ### 对外接口 | Public Interfaces | 接口 | 用途 | 注册方式 | |------|------|----------| | `IMotionControlService` | 业务控制(移动、停止、回零、Jog、开关门、几何计算) | 单例 | | `IMotionSystem` | 底层状态读取(轴位置、状态、门状态、摇杆状态、轴复位) | 单例 | | `MotionControlConfig` | 配置参数(轴范围、几何原点、轮询周期) | 实例 | | `GeometryCalculator` | 几何正算/反算工具 | 单例 | ### 事件 | Events | 事件 | 载荷 | 触发时机 | |------|------|----------| | `AxisStatusChangedEvent` | `AxisStatusChangedData(AxisId, AxisStatus)` | 轴状态变化 | | `DoorStatusChangedEvent` | `DoorStatus` | 门状态变化 | | `DoorInterlockChangedEvent` | `bool` | 门联锁状态变化(true=已联锁, false=未联锁) | | `GeometryUpdatedEvent` | `GeometryData(FOD, FDD, Magnification)` | 几何参数更新(每轮询周期) | | `GeometryApplyRequestEvent` | `GeometryApplyRequestData(SourceZTarget, DetectorZTarget, ...)` | 几何反算结果填入请求(DebugWindow → MotionControlViewModel) | | `JoystickActiveEvent` | `bool` | 实体摇杆激活状态变化(true=激活, false=未激活) | | `MotionErrorEvent` | `MotionErrorData(AxisId, ErrorMessage)` | 轴进入 Error/Alarm 状态 | --- ## 技术要求 | Technical Requirements | 依赖 | 版本 | 用途 | |------|------|------| | .NET 8.0 | net8.0-windows7.0 | 运行时 | | Prism.Wpf | 9.0.537 | MVVM + DI + EventAggregator | | Telerik UI for WPF | 2024.1.408 | UI 控件(Crystal 主题) | | XP.Common | - | 日志、多语言 | | XP.Hardware.PLC | - | IPlcService(PLC 连接状态)、ISignalDataService(PLC 信号读写) | --- ## 配置参数 | Configuration 在 `App.config` 的 `` 中配置: | 参数 | 默认值 | 说明 | |------|--------|------| | `MotionControl:SourceZ:Min/Max/Origin` | 0/500/0 | 射线源Z轴范围和原点(mm) | | `MotionControl:DetectorZ:Min/Max/Origin` | 0/600/0 | 探测器Z轴范围和原点(mm) | | `MotionControl:StageX:Min/Max/Origin` | -150/150/0 | 载物台X轴范围和原点(mm) | | `MotionControl:StageY:Min/Max/Origin` | -150/150/0 | 载物台Y轴范围和原点(mm) | | `MotionControl:DetectorSwing:Min/Max/Origin/Enabled` | -45/45/0/true | 探测器摆动范围、原点和启用 | | `MotionControl:StageRotation:Min/Max/Origin/Enabled` | -360/360/0/true | 载物台旋转范围、原点和启用 | | `MotionControl:FixtureRotation:Min/Max/Origin/Enabled` | -90/90/0/false | 夹具旋转范围、原点和启用 | | `MotionControl:Geometry:SourceZOrigin` | 0 | 射线源Z原点偏移(mm) | | `MotionControl:Geometry:DetectorZOrigin` | 600 | 探测器Z原点偏移(mm) | | `MotionControl:Geometry:StageRotationCenterZ` | 0 | 旋转中心Z坐标(mm,固定值) | | `MotionControl:Geometry:SwingPivotOffset` | 0 | 探测器摆动旋转中心Z偏移(mm) | | `MotionControl:Geometry:SwingRadius` | 0 | 探测器摆动半径(mm) | | `MotionControl:PollingInterval` | 100 | 轮询周期(ms) | | `MotionControl:DefaultVelocity` | 100 | 默认速度 | | `MotionControl:SourceDetectorZLinkage:Enabled` | false | 射线源与探测器Z轴联动使能 | | `MotionControl:SourceDetectorZLinkage:TriggerThreshold` | 1.0 | 联动触发的位置变化阈值(mm) | | `MotionControl:SourceDetectorZLinkage:SpeedPercent` | 100 | 联动移动速度百分比(0-100) | PLC 信号名称硬编码在 `MotionSignalNames.cs` 中,信号定义在 `PlcAddrDfn.xml` 的 ReadCommon/WriteCommon 组。 --- **最后更新 | Last Updated**: 2026-05-11