33 int16_t speed_rpm = 0;
34 int16_t given_current = 0;
35 uint8_t temperate = 0;
38struct motor_upload_pkg {
43 uint8_t current_h : 1;
44 uint8_t current_l : 1;
45 uint8_t temperature : 1;
47} __attribute__((packed));
49inline motor_measure parse_motor_upload_pkg(io::byte_span data)
51 motor_upload_pkg pkg = utils::from_bytes<motor_upload_pkg>(data);
53 .ecd = utils::make_u16(pkg.angle_h, pkg.angle_l),
54 .speed_rpm = utils::make_i16(pkg.speed_h, pkg.speed_l),
55 .given_current = utils::make_i16(pkg.current_h, pkg.current_l),
56 .temperate =
static_cast<uint8_t
>(pkg.temperature)
66 float angle_speed_ {};
90 inline fp32 rpm()
const {
return angle_speed_ * 60.f / (2.f *
Pi_f); }
116 std::derived_from<T, motor_base>
and
118 {
t.set(std::declval<float>()) } -> std::same_as<awaitable<void>>;
119 {
t.enable() } -> std::same_as<awaitable<void>>;
120 {
t.task() } -> std::same_as<awaitable<void>>;
139template<motor motor_type,utils::controller controller_type>
140requires (std::is_convertible_v<float, typename controller_type::input_type> &&
141 std::is_convertible_v<typename controller_type::state_type, float >)
143 using motor_key_type =
typename motor_type::info_type::key_type;
145 controller_type controller;
150 typename controller_type::params_type controller_params;
155 controlled_motor(
const motor_key_type& name,
const typename controller_type::params_type& controller_params):
156 name{name},controller{controller_params}{}
164 controller.update(state);
216template<motor motor_type>
224enum class dir :
int {
asio::awaitable< T > awaitable
协程任务类型。
awaitable< void > set_motor(const typename motor_type::info_type::key_type &key, fp32 value)
设置电机目标状态
fp32 angle_speed() const
获取电机角速度(单位为rad/s)
fp32 linear_speed() const
获取电机线速度(单位为m/s)
fp32 torque() const
获取电机扭矩(单位为A)
fp32 angle() const
获取电机角度(单位为rad)
motor_type & motor() const
获取电机对象
awaitable< void > set(float state)
设置电机目标状态
motor_base(const std::chrono::nanoseconds offline_timeout, fp32 radius)
fp32 linear_speed() const
获取电机线速度(单位为m/s)
fp32 angle_speed() const
获取电机角速度(单位为rad/s)
fp32 torque() const
获取电机扭矩(单位为A)
fp32 angle() const
获取电机角度(单位为rad)
fp32 rpm() const
获取电机转速(单位为rpm)
constexpr auto Pi_f
单精度浮点类型的 Pi 常量。