- Axis: 新增运动学/功率/错误管理属性(_position 等 10+ 项) - Axis: 新增 doPower()/readState()/cycle() 接口骨架 - MC_Power: 实现功率使能功能块(边沿检测 + 状态输出) - GlobalResource: 新增 CreateAxis/GetAxisRefById 全局轴管理 - App/CMakeLists.txt: 添加 GlobalResource.cpp 源文件 - docs: 更新 Axis 属性清单与 MC_Power 设计文档
96 lines
2.1 KiB
C++
96 lines
2.1 KiB
C++
/**
|
|
* @file Axis.h
|
|
* @author your name (you@domain.com)
|
|
* @brief
|
|
* @version 0.1
|
|
* @date 2026-07-02
|
|
*
|
|
* @copyright Copyright (c) 2026
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "Types.h"
|
|
|
|
namespace plcopen {
|
|
/**
|
|
* \enum MotionCommandType
|
|
* \brief 内部运动指令类型(功能块 → 轴模型映射)
|
|
*/
|
|
enum class MotionCommandType {
|
|
None, /*!< 无活动指令 */
|
|
PointToPoint, /*!< MC_MoveAbsolute / MC_MoveRelative */
|
|
Velocity, /*!< MC_MoveVelocity */
|
|
Stop, /*!< MC_Stop */
|
|
Halt, /*!< MC_Halt */
|
|
Home, /*!< MC_Home */
|
|
};
|
|
|
|
|
|
/**
|
|
* \struct MotionCommand
|
|
* \brief 当前活动运动指令的参数快照
|
|
*/
|
|
struct MotionCommand {
|
|
MotionCommandType type = MotionCommandType::None;
|
|
REAL targetPosition = 0.0;
|
|
REAL targetVelocity = 0.0;
|
|
REAL maxVelocity = 0.0;
|
|
REAL acceleration = 0.0;
|
|
REAL deceleration = 0.0;
|
|
REAL homePosition = 0.0;
|
|
MC_AXIS_STATE resultingState = MC_AXIS_STATE::DiscreteMotion;
|
|
};
|
|
|
|
/**
|
|
* \class Axis
|
|
* \brief 单轴仿真对象,实现 PLCopen 轴状态机与运动学
|
|
* \note 不要在功能块 cycle() 之外直接修改 Axis 内部状态。
|
|
*/
|
|
|
|
class Axis {
|
|
public:
|
|
/**
|
|
* \brief 构造轴
|
|
* \param axisNo 轴编号
|
|
* \param name 轴名称
|
|
*/
|
|
explicit Axis(UINT axisNo = 1, std::string name = "Axis1");
|
|
|
|
void cycle();
|
|
MC_AXIS_STATE readState();
|
|
|
|
void doPower(bool en);
|
|
|
|
/** \brief 获取轴编号 */
|
|
UINT axisNo() const { return _ref.axisNo; }
|
|
|
|
/** \brief 获取内部 AXIS_REF(供全局注册表使用) */
|
|
AXIS_REF& ref() { return _ref; }
|
|
|
|
private:
|
|
AXIS_REF _ref;
|
|
MC_AXIS_STATE _state = MC_AXIS_STATE::Disabled;
|
|
MC_AXIS_STATE _resultingSstate = MC_AXIS_STATE::Disabled;
|
|
|
|
MotionCommand _activeCommand;
|
|
|
|
// 运动学属性
|
|
REAL _position;
|
|
REAL _actualPosition;
|
|
REAL _velocity;
|
|
REAL _actualVelocity;
|
|
REAL _acceleration;
|
|
REAL _actualAcceleration;
|
|
|
|
// 功率与使能
|
|
BOOL _powerEnabled;
|
|
BOOL _homed;
|
|
|
|
// 错误管理
|
|
MC_ERROR_ID _errorId;
|
|
BOOL _errorStop;
|
|
};
|
|
|
|
} |