#ifndef GO1_PRO_UNITREE_LEGGED_LOOP_H_ #define GO1_PRO_UNITREE_LEGGED_LOOP_H_ #include #include #include #include namespace UNITREE_LEGGED_SDK { constexpr int THREAD_PRIORITY = 95; typedef boost::function 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 _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 _fp; }; } // namespace UNITREE_LEGGED_SDK #endif