Files
LinuxMotion/MotionLib/Inc/Types.h
T
chen 818041201b fix: 修复 Types.h 缺少头文件保护导致的重复定义错误
- Types.h: 添加 #pragma once 防止重复包含
- CMakeLists.txt: C++ 标准 17 → 20
- App/CMakeLists.txt: 移除重复的 C++11 覆盖,统一继承根 CMake 标准
- Axis.cpp: 添加 #include <string> 显式包含
2026-07-03 03:52:40 +00:00

123 lines
4.2 KiB
C++
Raw 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.
/**
* @file types.h
* @author
* @brief
* @version 0.1
* @date 2026-07-02
*
* @copyright Copyright (c) 2026
*
*/
#pragma once
#include <cstdint>
#include <string>
namespace plcopen {
class Axis;
/** \typedef BOOL IEC 61131-3 BOOL 类型映射 */
using BOOL = bool;
/** \typedef REAL IEC 61131-3 REAL 类型映射(双精度浮点) */
using REAL = double;
/** \typedef WORD IEC 61131-3 WORD 类型映射(16 位无符号,常用于 ErrorID */
using WORD = std::uint16_t;
/** \typedef UINT IEC 61131-3 UINT 类型映射(32 位无符号) */
using UINT = std::uint32_t;
/**
* \enum MC_BUFFER_MODE
* \brief 运动指令缓冲与混合模式 (MC_BUFFER_MODE)
*
* 用于带 BufferMode 输入的功能块,决定新指令与当前运动的关系。
*/
enum class MC_BUFFER_MODE : std::uint8_t {
mcAborting = 0, /*!< 默认:立即执行,中断当前运动并清空缓冲 */
mcBuffered = 1, /*!< 等待前一指令 Done 后顺序执行,无混合 */
mcBlendingLow = 2, /*!< 混合:在衔接点取两指令速度的较低值 */
mcBlendingPrevious = 3, /*!< 混合:在衔接点保持前一指令速度 */
mcBlendingNext = 4, /*!< 混合:在衔接点使用当前指令速度 */
mcBlendingHigh = 5, /*!< 混合:在衔接点取两指令速度的较高值 */
};
/**
* \enum MC_DIRECTION
* \brief 定位运动方向 (MC_DIRECTION)
*/
enum class MC_DIRECTION : std::uint8_t {
mcPositiveDirection = 0, /*!< 正向运动 */
mcShortestWay = 1, /*!< 最短路径(线性轴默认策略) */
mcNegativeDirection = 2, /*!< 负向运动 */
mcCurrentDirection = 3, /*!< 保持当前运动方向 */
};
/**
* \enum MC_SOURCE
* \brief 运动数据读取来源 (MC_SOURCE)
*/
enum class MC_SOURCE : std::uint8_t {
mcCommandedValue = 0, /*!< 指令值 */
mcSetValue = 1, /*!< 设定值 */
mcActualValue = 2, /*!< 实际值 */
};
/**
* \enum MC_AXIS_STATE
* \brief 轴状态机状态 (PLCopen 状态图)
*
* \par 典型状态转换
* - Disabled → StandstillMC_Power.Enable = TRUE
* - Standstill → DiscreteMotionMC_MoveAbsolute / MC_MoveRelative
* - Standstill → ContinuousMotionMC_MoveVelocity
* - Standstill → HomingMC_Home
* - 任意 → ErrorStop:轴错误或功率故障
* - ErrorStop → StandstillMC_Reset
*
* \note 同一时刻仅有一个状态位为 TRUE(由 MC_ReadStatus 反映)。
*/
enum class MC_AXIS_STATE : std::uint8_t {
Disabled = 0, /*!< 初始/下电状态,功率未使能 */
Standstill, /*!< 静止,功率已使能,可接受运动指令 */
Homing, /*!< 回零进行中 (MC_Home) */
DiscreteMotion, /*!< 离散运动(点到点),完成后自动停止 */
ContinuousMotion, /*!< 连续运动(如 MC_MoveVelocity */
Stopping, /*!< MC_Stop 激活,减速中且拒绝新运动 */
ErrorStop, /*!< 错误停止,需 MC_Reset 恢复 */
SynchronizedMotion, /*!< 同步运动(Cam/Gear,本库预留) */
};
/**
* \enum MC_ERROR_ID
* \brief 功能块与轴通用错误码
*/
enum class MC_ERROR_ID : WORD {
mcNoError = 0, /*!< 无错误 */
mcInvalidParameter = 1, /*!< 参数非法(如速度 ≤ 0) */
mcInvalidState = 2, /*!< 当前状态不允许该操作 */
mcActionNotAllowed = 3, /*!< 轴未上电或处于 Stopping/ErrorStop */
mcAxisNotPowered = 4, /*!< 轴未使能 */
mcAxisNotHomed = 5, /*!< 轴未完成回零 */
mcCommandAborted = 6, /*!< 指令被中断 */
mcStopActive = 7, /*!< MC_Stop 占用轴 */
mcPowerFailure = 8, /*!< 功率级故障 */
mcFollowingError = 9, /*!< 跟随误差超限 */
};
/**
* \struct AXIS_REF
* \brief 轴引用 (VAR_IN_OUT),所有 MC 功能块的公共轴参数
*
* \details
* 在 IEC 61131-3 程序中作为 VAR_IN_OUT 传递;本 C++ 实现中,
* `axis` 指针由 Axis 对象构造时自动绑定,应用层无需手动设置。
*/
struct AXIS_REF {
UINT axisNo = 0; /*!< 轴编号(用户定义) */
std::string axisName; /*!< 轴名称 */
Axis* axis = nullptr; /*!< 内部绑定指针,指向仿真轴实例 */
};
}