feat: 实现 Axis 核心属性与 MC_Power 功能块
- Axis: 新增运动学/功率/错误管理属性(_position 等 10+ 项) - Axis: 新增 doPower()/readState()/cycle() 接口骨架 - MC_Power: 实现功率使能功能块(边沿检测 + 状态输出) - GlobalResource: 新增 CreateAxis/GetAxisRefById 全局轴管理 - App/CMakeLists.txt: 添加 GlobalResource.cpp 源文件 - docs: 更新 Axis 属性清单与 MC_Power 设计文档
This commit is contained in:
+73
-4
@@ -14,14 +14,83 @@
|
||||
|
||||
namespace plcopen {
|
||||
Axis::Axis(UINT axisNo, std::string name) {
|
||||
ref_.axisNo = axisNo;
|
||||
ref_.axisName = std::move(name);
|
||||
ref_.axis = this;
|
||||
_ref.axisNo = axisNo;
|
||||
_ref.axisName = std::move(name);
|
||||
_ref.axis = this;
|
||||
}
|
||||
|
||||
void Axis::cycle()
|
||||
{
|
||||
|
||||
if (_errorStop) return;
|
||||
|
||||
if (!_powerEnabled) return;
|
||||
|
||||
switch (_state) {
|
||||
case MC_AXIS_STATE::Disabled :
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case MC_AXIS_STATE::Standstill :
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case MC_AXIS_STATE::Stopping :
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// 独立运动
|
||||
case MC_AXIS_STATE::DiscreteMotion :
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// 持续运动
|
||||
case MC_AXIS_STATE::ContinuousMotion :
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// 同步运动
|
||||
case MC_AXIS_STATE::SynchronizedMotion :
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// 回零
|
||||
case MC_AXIS_STATE::Homing :
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Axis::doPower(bool en)
|
||||
{
|
||||
if(en)
|
||||
{
|
||||
_powerEnabled = true;
|
||||
}
|
||||
else {
|
||||
_powerEnabled = false;
|
||||
_activeCommand.type = MotionCommandType::None;
|
||||
_velocity = 0.0;
|
||||
_acceleration = 0.0;
|
||||
_errorStop = false;
|
||||
_state = MC_AXIS_STATE::Disabled;
|
||||
}
|
||||
}
|
||||
|
||||
MC_AXIS_STATE Axis::readState()
|
||||
{
|
||||
return _state;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* @file MC_Power.cpp
|
||||
* @author
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2026-07-03
|
||||
*
|
||||
* @copyright Copyright (c) 2026
|
||||
*
|
||||
*/
|
||||
|
||||
#include "MC_Power.h"
|
||||
#include "Types.h"
|
||||
|
||||
namespace plcopen {
|
||||
|
||||
MC_Power::MC_Power(AXIS_REF& axisRef)
|
||||
: _axisRef(axisRef) { }
|
||||
|
||||
void MC_Power::cycle()
|
||||
{
|
||||
if(_axisRef.axis == nullptr)
|
||||
{
|
||||
Error = true;
|
||||
ErrorID = MC_ERROR_ID::mcInvalidParameter;
|
||||
Status = false;
|
||||
Busy = false;
|
||||
return;
|
||||
}
|
||||
|
||||
Axis* axis = _axisRef.axis;
|
||||
Error = false;
|
||||
ErrorID = MC_ERROR_ID::mcNoError;
|
||||
|
||||
// 上升沿
|
||||
if(Enable && !_prevEnable)
|
||||
{
|
||||
axis->doPower(true);
|
||||
}
|
||||
|
||||
// 下降沿
|
||||
if(!Enable && _prevEnable)
|
||||
{
|
||||
axis->doPower(false);
|
||||
}
|
||||
|
||||
// 在使能状态下持续更新轴状态
|
||||
if(Enable)
|
||||
{
|
||||
auto state = axis->readState();
|
||||
if(state == MC_AXIS_STATE::Standstill)
|
||||
{
|
||||
Busy = false;
|
||||
Status = true;
|
||||
}
|
||||
else if(state == MC_AXIS_STATE::ErrorStop)
|
||||
{
|
||||
Busy = false;
|
||||
Status = false;
|
||||
Error = true;
|
||||
ErrorID = MC_ERROR_ID::mcPowerFailure;
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = false;
|
||||
Busy = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 保存前置状态
|
||||
_prevEnable = Enable;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user