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:
chen
2026-07-03 10:01:06 +00:00
parent 7f73fb48ef
commit 0587f7ac6c
13 changed files with 685 additions and 94 deletions
+2
View File
@@ -9,6 +9,8 @@ project(MotionApp
set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/Src/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Src/MotionTickThread.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Src/UserAppThread.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Src/GlobalResource.cpp
)
# 工程源文件
+35
View File
@@ -0,0 +1,35 @@
/**
* @file GlobalResource.h
* @author
* @brief
* @version 0.1
* @date 2026-07-03
*
* @copyright Copyright (c) 2026
*
*/
#pragma once
#include "Axis.h"
#include "Types.h"
/**
* \brief 创建轴并注册到全局表
* \param id 轴编号
* \param name 轴名称
* \return 轴引用。若 id 已存在,返回已有轴的引用(不覆盖)
*/
plcopen::AXIS_REF& CreateAxis(plcopen::UINT id, const std::string& name);
/**
* \brief 通过编号获取轴引用
* \param id 轴编号
* \return AXIS_REF 引用。若不存在,返回 axis==nullptr 的哨兵引用
*/
plcopen::AXIS_REF& GetAxisRefById(plcopen::UINT id);
+20
View File
@@ -0,0 +1,20 @@
/**
* @file UserAppThread.h
* @author
* @brief
* @version 0.1
* @date 2026-07-03
*
* @copyright Copyright (c) 2026
*
*/
#pragma once
int UserAppThread();
+60
View File
@@ -0,0 +1,60 @@
/**
* @file GlobalResource.cpp
* @author
* @brief 全局轴资源管理 — 持有并管理所有轴实例
* @version 0.1
* @date 2026-07-03
*
* @copyright Copyright (c) 2026
*
*/
#include "GlobalResource.h"
#include <unordered_map>
#include <vector>
#include <mutex>
namespace {
// 轴实例存储 — 拥有所有轴的内存
std::vector<plcopen::Axis> g_axes;
// 快速查找表:id → AXIS_REF& (指向 g_axes 中的元素)
std::unordered_map<plcopen::UINT, std::size_t> g_indexMap;
// 线程安全
std::mutex g_mutex;
// id 不存在时返回的哨兵
plcopen::AXIS_REF g_invalidRef{0, "", nullptr};
} // namespace
plcopen::AXIS_REF& CreateAxis(plcopen::UINT id, const std::string& name) {
std::lock_guard<std::mutex> lock(g_mutex);
// id 已存在 → 返回已有轴的引用
auto it = g_indexMap.find(id);
if (it != g_indexMap.end()) {
return g_axes[it->second].ref();
}
// 新建轴
g_axes.emplace_back(id, name);
std::size_t idx = g_axes.size() - 1;
g_indexMap[id] = idx;
return g_axes[idx].ref();
}
plcopen::AXIS_REF& GetAxisRefById(plcopen::UINT id) {
std::lock_guard<std::mutex> lock(g_mutex);
auto it = g_indexMap.find(id);
if (it != g_indexMap.end()) {
return g_axes[it->second].ref();
}
g_invalidRef.axisNo = id;
g_invalidRef.axis = nullptr;
return g_invalidRef;
}
+30
View File
@@ -0,0 +1,30 @@
/**
* @file UserAppThread.cpp
* @author
* @brief
* @version 0.1
* @date 2026-07-03
*
* @copyright Copyright (c) 2026
*
*/
#include "UserAppThread.h"
#include "Axis.h"
#include "FunctionBlocks.h"
#include "MC_Power.h"
int UserAppThread()
{
plcopen::MC_Power mcPowerInstance0()
while(1)
{
}
return 0;
}
+1 -13
View File
@@ -13,17 +13,14 @@
#include <mutex>
#include <vector>
#include "MotionTickThread.h"
#include "UserAppThread.h"
#include "Axis.h"
#include "Types.h"
static int UserAppThread();
std::vector<plcopen::Axis> axisList;
int main()
{
plcopen::Axis axis1(1, "axis1");
plcopen::Axis axis2(2, "axis2");
axisList.push_back(axis1);
@@ -39,14 +36,5 @@ int main()
}
static int UserAppThread()
{
while(1)
{
}
return 0;
}