1#include "device/motor/m9025.h"
10using namespace roboctrl;
13constexpr fp32 _rpm_to_rad_s = 2.f *
Pi_f / 60.f;
14constexpr fp32 _ecd_8192_to_rad = 2.f *
Pi_f / 8192.f;
16M9025::M9025(
const info_type& info):
22 this->angle_ = _ecd_8192_to_rad * static_cast<float>(utils::make_u16(pkg.angle_h, pkg.angle_l));
23 this->angle_speed_ = _rpm_to_rad_s * static_cast<float>(utils::make_i16(pkg.speed_h, pkg.speed_l));
24 this->torque_ = utils::make_i16(pkg.current_h, pkg.speed_l);
26 this->pid_.update(this->angle_speed_);
28 std::array<std::byte,8> data;
32 co_await roboctrl::get<io::can>(info_.can_name).send(0x200 + info_.id,data);
34 this->log_debug(
"angle:{}, speed:{}, torque:{}",this->angle_,this->angle_speed_,this->torque_);
44 pid_.
update(this->angle_speed_);
基于 Linux SocketCAN 的 CAN 总线封装。
auto spawn(task_context::task_type &&task)
添加一个协程任务到全局任务上下文中执行。
asio::awaitable< T > awaitable
协程任务类型。
void set_target(T target)
设置期望目标。
void update(T current)
根据当前值更新 PID 输出。
constexpr auto Pi_f
单精度浮点类型的 Pi 常量。