GKD.RoboCtrl
载入中...
搜索中...
未找到
super_cap.cpp
1#include "device/super_cap.h"
2#include "core/async.hpp"
3#include "io/can.h"
4#include "utils/utils.hpp"
5
6using namespace roboctrl::device;
7
9{
10 uint8_t errorCode;
11 float chassisPower;
12 uint16_t chassisPowerlimit;
13 uint8_t capEnergy;
14} __attribute__((packed));
15
16bool super_cap::init(const super_cap::info_type& info){
17 info_ = info;
18
19 roboctrl::get<roboctrl::io::can>(info.can_name).on_data(0x51,[&](const __super_cap_recive_pkg& pkg){
20 chassis_power_ = pkg.chassisPower;
21 chassis_power_limit_ = pkg.chassisPowerlimit;
22 energy_ = pkg.capEnergy;
23 log_info("error code : {},chassis_power: {}, chassis_power_limit: {}, energy: {}",pkg.errorCode,chassis_power_,chassis_power_limit_,energy_);
24 });
25
26 return true;
27}
28
30{
31 std::array<std::byte,8> data;
32
33 if(enable)
34 data[0] = utils::to_byte(1);
35 else
36 data[0] = utils::to_byte(0);
37
38 data[1] = utils::to_byte(power_limit & 0xff);
39 data[2] = utils::to_byte(power_limit >> 8);
40 data[3] = utils::to_byte(50 & 0xff);
41 data[4] = utils::to_byte(50 >> 8);
42
43 co_await roboctrl::get<roboctrl::io::can>(info_.can_name).send(0x61,data);
44}
异步任务上下文组件。
基于 Linux SocketCAN 的 CAN 总线封装。
awaitable< void > set(bool enable, uint16_t power_limit)
设置超电状态
Definition super_cap.cpp:29
void log_info(std::format_string< Args... > fmt, Args &&...args) const
输出info日志
Definition logger.h:214
asio::awaitable< T > awaitable
协程任务类型。
Definition async.hpp:42
设备模块
Definition base.hpp:25
constexpr std::byte to_byte(std::integral auto v) noexcept
辅助将整数转换为 std::byte。
Definition utils.hpp:169
常用数值与字节工具集合。