diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..11a2af0 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,15 @@ +{ + "configurations": [ + { + "name": "Linux", + "compileCommands": "${workspaceFolder}/build/compile_commands.json", + "cStandard": "c17", + "cppStandard": "c++17", + "intelliSenseMode": "linux-gcc-x64" + }, + { + + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..82cca88 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "clangd.arguments": ["--compile-commands-dir=build"], +} + + + diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..d0d59ec --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,70 @@ +# Motion — AI Agent Instructions + +本项目是一个 **PLCopen 运动控制库** 的 C++ 实现,模拟 IEC 61131-3 标准的轴控制功能。 + +## 快速开始 + +```bash +# Debug 构建 +cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug +cmake --build build + +# 运行 +./build/Debug/UNIX/MotionApp +``` + +## 项目结构 + +``` +Motion/ +├── CMakeLists.txt # 根构建文件 (C++17) +├── AGENTS.md # AI 代理指令 (本文件) +├── App/ # 可执行目标 MotionApp +│ ├── CMakeLists.txt # (注意: 覆盖为 C++11) +│ ├── Inc/ # 应用级头文件 +│ └── Src/main.cpp # 入口点 +└── MotionLib/ # 共享库 libMotionLib.so + ├── CMakeLists.txt # (C++17) + ├── Inc/ + │ ├── Types.h # IEC 61131-3 类型映射 & 枚举 + │ └── Axis.h # 轴类 & 运动命令 + └── Src/Axis.cpp # 构造函数实现 +``` + +## 架构要点 + +- **命名空间**: 所有运动控制代码在 `namespace plcopen { ... }` 中 +- **两层架构**: `MotionLib` (共享库, 领域逻辑) → `MotionApp` (可执行文件, 入口) +- **轴状态机**: `Disabled → Standstill → DiscreteMotion/ContinuousMotion/Homing → Stopping/ErrorStop` +- **轴引用**: `AXIS_REF` 结构体持有轴编号、名称和指向 `Axis` 实例的指针 + +## 编码约定 + +| 项目 | 规范 | +|------|------| +| 语言标准 | C++17 (根), 但 `App/` 使用 C++11 | +| 命名空间 | 小写: `plcopen` | +| 类 | PascalCase: `Axis`, `MotionCommand` | +| 枚举类 | SCREAMING_SNAKE_CASE, 值带 `mc` 前缀 | +| 类型别名 | UPPER_SNAKE_CASE: `BOOL`, `REAL`, `UINT` | +| 成员变量 | `snake_case`, 引用用 `ref_` 前缀 | +| 文档 | Doxygen 格式 (`@brief`, `@param`, `@return`) | +| 平台输出 | `build//UNIX/` (Linux), `WIN32/` (Windows), `APPLE/` (macOS) | + +## 关键约定 + +- 包含策略: `.cpp` 引入对应 `.h`, `.h` 引入所需公共头文件 +- 无第三方库依赖, 无测试框架 +- 使用 `enum class` 而非裸枚举 +- GCC UTF-8 编译标志已启用 + +## 当前开发状态 + +- [x] 类型系统 (Types.h) +- [x] 轴引用与基础 Axis 类 +- [ ] 轴状态机转换逻辑 (`cycle()` 方法) +- [ ] 运动学 (轨迹规划) +- [ ] 功能块 (MC_Power, MC_MoveAbsolute, MC_Stop 等) +- [ ] 应用逻辑 (main.cpp 初始化/循环) +- [ ] 单元测试 (GTest/Catch2) +- [ ] API 文档 diff --git a/App/CMakeLists.txt b/App/CMakeLists.txt index c324ff5..ec00022 100644 --- a/App/CMakeLists.txt +++ b/App/CMakeLists.txt @@ -6,10 +6,6 @@ project(MotionApp VERSION 0.1 DESCRIPTION "Test") -# C/C++ 标准版本 -set(CMAKE_C_STANDARD 11) -set(CMAKE_CXX_STANDARD 11) - # 指定在当前目录或以下目录下通过命令(如 add_executable() )链接稍后创建的任何目标时要使用的库或标志 LINK_LIBRARIES(m) diff --git a/CMakeLists.txt b/CMakeLists.txt index 659ed1e..32aa61f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,9 +34,9 @@ elseif(UNIX) # 注意:Linux和macOS都满足UNIX为TRUE,所以通常先判 endif() -set(CMAKE_C_STANDARD 17) +set(CMAKE_C_STANDARD 20) set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) add_subdirectory(${CMAKE_SOURCE_DIR}/MotionLib) diff --git a/MotionLib/Inc/Types.h b/MotionLib/Inc/Types.h index c6a16b0..b7ea440 100644 --- a/MotionLib/Inc/Types.h +++ b/MotionLib/Inc/Types.h @@ -8,6 +8,7 @@ * @copyright Copyright (c) 2026 * */ +#pragma once #include #include namespace plcopen { diff --git a/MotionLib/Src/Axis.cpp b/MotionLib/Src/Axis.cpp index 30f6275..081ed5f 100644 --- a/MotionLib/Src/Axis.cpp +++ b/MotionLib/Src/Axis.cpp @@ -8,6 +8,7 @@ * @copyright Copyright (c) 2026 * */ +#include #include "Types.h" #include "Axis.h" diff --git a/compile_commands.json b/compile_commands.json new file mode 120000 index 0000000..2bdb02a --- /dev/null +++ b/compile_commands.json @@ -0,0 +1 @@ +/home/chen/Workspace/T153/App/Motion/build/compile_commands.json \ No newline at end of file