cpp对齐官方

This commit is contained in:
cyy_mac
2026-07-30 15:25:48 +08:00
parent dbfcb95566
commit f8b849397d
36 changed files with 2561 additions and 122 deletions

View File

@@ -0,0 +1,48 @@
#ifndef GO1_PRO_UNITREE_LEGGED_LOOP_H_
#define GO1_PRO_UNITREE_LEGGED_LOOP_H_
#include <atomic>
#include <boost/function.hpp>
#include <string>
#include <thread>
namespace UNITREE_LEGGED_SDK {
constexpr int THREAD_PRIORITY = 95;
typedef boost::function<void()> Callback;
class Loop {
public:
Loop(std::string name, float period, int bindCPU = -1)
: _name(name), _period(period), _bindCPU(bindCPU) {}
virtual ~Loop();
void start();
void shutdown();
virtual void functionCB() = 0;
private:
void entryFunc();
std::string _name;
float _period;
int _bindCPU;
bool _bind_cpu_flag = false;
bool _isrunning = false;
std::atomic<bool> _running_atomic{false};
std::thread _thread;
};
class LoopFunc : public Loop {
public:
LoopFunc(std::string name, float period, const Callback& cb)
: Loop(name, period), _fp(cb) {}
LoopFunc(std::string name, float period, int bindCPU, const Callback& cb)
: Loop(name, period, bindCPU), _fp(cb) {}
void functionCB() override { _fp(); }
private:
boost::function<void()> _fp;
};
} // namespace UNITREE_LEGGED_SDK
#endif