One Motor 0.6.0
RoboMaster全平台一站式电机驱动库
载入中...
搜索中...
未找到
Traits.hpp
1#ifndef ONEMOTOR_TRAITS_HPP
2#define ONEMOTOR_TRAITS_HPP
3#include <cstdint>
4
5namespace OneMotor::Motor::DJI
6{
7 template <typename Derived>
9 {
10 static consteval bool has_gearbox()
11 {
12 return Derived::gearbox;
13 }
14
15 static constexpr float ecd_to_angle(const float ecd)
16 {
17 return ecd * 360.f / Derived::encoder_resolution;
18 }
19
20 template <uint8_t motor_id>
21 static consteval uint16_t control_id()
22 {
23 return Derived::template cal_control_id<motor_id>();
24 }
25
26 template <uint8_t motor_id>
27 static consteval uint8_t control_offset()
28 {
29 return Derived::template cal_control_offset<motor_id>();
30 }
31
32 template <uint8_t motor_id>
33 static consteval uint16_t feedback_id()
34 {
35 return Derived::template cal_feedback_id<motor_id>();
36 }
37 };
38
39 struct M3508Traits : MotorTraits<M3508Traits>
40 {
41 static constexpr uint16_t max_current = 16384;
42 static constexpr uint16_t encoder_resolution = 8192;
43 static constexpr bool gearbox = true;
44 static constexpr uint8_t reduction_ratio = 19;
45 static constexpr uint8_t max_id = 8;
46
47 template <uint8_t motor_id>
48 static consteval uint16_t cal_control_id()
49 {
50 if constexpr (motor_id <= 4)
51 {
52 return 0x200;
53 }
54 else
55 {
56 return 0x1FF;
57 }
58 }
59
60 template <uint8_t motor_id>
61 static consteval uint16_t cal_control_offset()
62 {
63 if constexpr (motor_id <= 4)
64 {
65 return (motor_id - 1) * 2;
66 }
67 else
68 {
69 return (motor_id - 4 - 1) * 2;
70 }
71 }
72
73 template <uint8_t motor_id>
74 static consteval uint16_t cal_feedback_id()
75 {
76 return motor_id + 0x200;
77 }
78 };
79
80 struct M2006Traits : MotorTraits<M2006Traits>
81 {
82 static constexpr uint16_t max_current = 16384;
83 static constexpr uint16_t encoder_resolution = 8192;
84 static constexpr bool gearbox = true;
85 static constexpr uint8_t reduction_ratio = 36;
86 static constexpr uint8_t max_id = 8;
87
88 template <uint8_t motor_id>
89 static consteval uint16_t cal_control_id()
90 {
91 if constexpr (motor_id <= 4)
92 {
93 return 0x200;
94 }
95 else
96 {
97 return 0x1FF;
98 }
99 }
100
101 template <uint8_t motor_id>
102 static consteval uint16_t cal_control_offset()
103 {
104 if constexpr (motor_id <= 4)
105 {
106 return (motor_id - 1) * 2;
107 }
108 else
109 {
110 return (motor_id - 4 - 1) * 2;
111 }
112 }
113
114 template <uint8_t motor_id>
115 static consteval uint16_t cal_feedback_id()
116 {
117 return motor_id + 0x200;
118 }
119 };
120
121 struct GM6020VoltageTraits : MotorTraits<GM6020VoltageTraits>
122 {
123 static constexpr uint16_t max_current = 16384;
124 static constexpr uint16_t encoder_resolution = 8192;
125 static constexpr bool gearbox = false;
126 static constexpr uint8_t max_id = 7;
127
128 template <uint8_t motor_id>
129 static consteval uint16_t cal_control_id()
130 {
131 if constexpr (motor_id <= 4)
132 {
133 return 0x1FF;
134 }
135 else
136 {
137 return 0x2FF;
138 }
139 }
140
141 template <uint8_t motor_id>
142 static consteval uint16_t cal_control_offset()
143 {
144 if constexpr (motor_id <= 4)
145 {
146 return (motor_id - 1) * 2;
147 }
148 else
149 {
150 return (motor_id - 4 - 1) * 2;
151 }
152 }
153
154 template <uint8_t motor_id>
155 static consteval uint16_t cal_feedback_id()
156 {
157 return motor_id + 0x204;
158 }
159 };
160
161 struct GM6020CurrentTraits : MotorTraits<GM6020CurrentTraits>
162 {
163 static constexpr uint16_t max_output = 25000;
164 static constexpr uint16_t encoder_resolution = 8192;
165 static constexpr bool gearbox = false;
166 static constexpr uint8_t max_id = 7;
167
168 template <uint8_t motor_id>
169 static consteval uint16_t cal_control_id()
170 {
171 if constexpr (motor_id <= 4)
172 {
173 return 0x1FE;
174 }
175 else
176 {
177 return 0x2FE;
178 }
179 }
180
181 template <uint8_t motor_id>
182 static consteval uint16_t cal_control_offset()
183 {
184 if constexpr (motor_id <= 4)
185 {
186 return (motor_id - 1) * 2;
187 }
188 else
189 {
190 return (motor_id - 4 - 1) * 2;
191 }
192 }
193
194 template <uint8_t motor_id>
195 static consteval uint16_t cal_feedback_id()
196 {
197 return motor_id + 0x204;
198 }
199 };
200}
201
202#endif //ONEMOTOR_TRAITS_HPP