feat: 添加多线程框架与轴周期接口
- 新增 MotionTickThread 线程模块 - main.cpp: 引入双线程架构(UserAppThread + MotionTickThread) - Axis: 新增 cycle() 接口,添加 #pragma once 头文件保护 - App/CMakeLists.txt: 链接 pthread,重组源文件列表 - .gitignore: 排除 docs/html、.vscode、compile_commands.json
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @file MotionTickThread.cpp
|
||||
* @author
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2026-07-03
|
||||
*
|
||||
* @copyright Copyright (c) 2026
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "MotionTickThread.h"
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param axisList
|
||||
*/
|
||||
void MotionTickThread(std::unique_ptr<std::vector<plcopen::Axis>> axisList)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
for (auto& axis : *axisList) {
|
||||
axis.cycle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+46
-2
@@ -1,8 +1,52 @@
|
||||
/**
|
||||
* @file main.cpp
|
||||
* @author
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2026-07-03
|
||||
*
|
||||
* @copyright Copyright (c) 2026
|
||||
*
|
||||
*/
|
||||
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include "MotionTickThread.h"
|
||||
#include "Axis.h"
|
||||
#include "Types.h"
|
||||
|
||||
static int UserAppThread();
|
||||
|
||||
|
||||
std::vector<plcopen::Axis> axisList;
|
||||
|
||||
int main()
|
||||
{
|
||||
plcopen::Axis axis();
|
||||
|
||||
plcopen::Axis axis1(1, "axis1");
|
||||
plcopen::Axis axis2(2, "axis2");
|
||||
axisList.push_back(axis1);
|
||||
axisList.push_back(axis2);
|
||||
|
||||
std::thread userAppThread(UserAppThread);
|
||||
std::thread motionTickThread(MotionTickThread,
|
||||
std::move(std::make_unique<std::vector<plcopen::Axis>>(axisList)));
|
||||
|
||||
motionTickThread.join();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int UserAppThread()
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user