GKD.RoboCtrl
RoboMaster Linux 电控:异步 IO、设备驱动与机器人控制
载入中...
搜索中...
未找到
j6006.h
1#pragma once
2
4#include "device/motor/protocol.hpp"
5
6namespace roboctrl::device {
7
8class j6006 : public motor_base, public logable<j6006> {
9public:
10 struct info_type {
11 using key_type = std::string;
12 using owner_type = j6006;
13 std::string name;
14 std::string can_name;
15 uint16_t id {};
16 uint16_t master_id {0};
17 fp32 radius {1.f};
18 motor_protocol::j6006_ranges feedback_range {};
19 fp32 max_speed {45.f};
20 int direction {1};
21 std::chrono::steady_clock::duration control_time {std::chrono::milliseconds{1}};
22 std::chrono::steady_clock::duration offline_timeout {std::chrono::milliseconds{100}};
23 const std::string& key() const { return name; }
24 };
25
26 static bool valid_configuration(const info_type& info) {
27 return !info.name.empty() && !info.can_name.empty() && info.id >= 1 && info.id <= 15
28 && info.master_id <= 0x7ff && std::isfinite(info.radius) && info.radius > 0.f
29 && motor_protocol::valid_ranges(info.feedback_range)
30 && std::isfinite(info.max_speed) && info.max_speed > 0.f
31 && info.max_speed <= info.feedback_range.velocity_max
32 && (info.direction == 1 || info.direction == -1)
33 && info.control_time > std::chrono::steady_clock::duration::zero()
34 && info.offline_timeout >= info.control_time;
35 }
36 explicit j6006(const info_type& info);
37 void connect();
38 void start();
39 std::string desc() const { return std::format("J6006 motor {} on {}", info_.name, info_.can_name); }
41 awaitable<void> set_angle_speed(fp32 speed) override;
42 awaitable<void> enable() override { set_enabled(true); co_return; }
43 void disable() override;
44 void set_enabled(bool enabled) override;
45 awaitable<void> task();
46 awaitable<void> stop_output();
47 fp32 target_angle_speed() const override { return target_speed_; }
48 uint16_t encoder_raw() const { return encoder_raw_; }
49 uint8_t status() const { return status_; }
50 bool faulted() const override { return fault_latched_ || (status_ >= 8 && status_ <= 14); }
51 fp32 command_speed() const {
52 return motor_protocol::gated_j6006_velocity(target_speed_, enabled_ && !fault_latched_, !offline(), status_);
53 }
54 fp32 current_feedback_raw() const override { return 0.f; } // Feedback is torque Nm.
55
56private:
57 info_type info_;
58 fp32 target_speed_ {0.f};
59 uint16_t encoder_raw_ {0};
60 uint8_t status_ {0xff};
61 bool connected_ {false};
62 bool started_ {false};
63 bool enabled_ {false};
64 bool previous_enabled_ {false};
65 bool fault_latched_ {false};
66};
67
68static_assert(motor<j6006>);
69
70} // namespace roboctrl::device
bool faulted() const override
Definition j6006.h:50
awaitable< void > set_angle_speed(fp32 speed) override
Definition j6006.cpp:38
void disable() override
Definition j6006.cpp:44
awaitable< void > enable() override
Definition j6006.h:42
awaitable< void > set(fp32 linear_speed) override
Definition j6006.cpp:36
void set_enabled(bool enabled) override
Definition j6006.cpp:50
用于提供日志功能的辅助基类 通过CRTP模式实现,要求派生类实现desc()方法以提供描述信息,在继承时传入派生类自身类型作为模板参数。 继承这个类后,派生类可以方便地使用log_debug、log_i...
Definition logger.h:178
电机基础组件。
asio::awaitable< T > awaitable
协程任务类型。
Definition async.hpp:46
bool offline() const
判断设备是否离线
Definition base.hpp:56
fp32 linear_speed() const
获取电机线速度(单位为m/s)
Definition base.hpp:95
float fp32
单精度浮点别名。
Definition utils.hpp:22