75 uint8_t rx_data[8] = {0};
77 if (send({0x02, 0x38, 0x02})) {
79 if (uart_.
receive(rx_data, 8, 1)) {
81 for (uint8_t i = 2; i < 8; i++) {
82 checksum += rx_data[i];
84 if ((rx_data[0] == 0xff) && (rx_data[1] == 0xff) &&
85 (checksum == 0xff) && (rx_data[2] == id_)) {
87 int16_t count =
static_cast<int16_t
>(rx_data[6] << 8) | rx_data[5];
88 int16_t delta = count - prev_count_;
90 if (delta > (ppr_ / 2)) {
92 }
else if (delta < -(ppr_ / 2)) {
105 uint8_t upper, lower;
108 ref_ = std::clamp<float>(ref_, 0, 2 * M_PI);
109 target = ref_ / (2 * M_PI) * (ppr_ - 1);
110 upper =
static_cast<uint8_t
>(target >> 8);
111 lower =
static_cast<uint8_t
>(target);
112 res = send({0x03, 0x2A, lower, upper});
115 ref_ = std::clamp<float>(ref_, -1, 1);
116 target =
static_cast<uint16_t
>(abs(ref_ * 1023));
117 upper =
static_cast<uint8_t
>(target >> 8) | ((ref_ > 0) ? 0x04 : 0);
118 lower =
static_cast<uint8_t
>(target);
119 res = send({0x03, 0x2C, lower, upper});
140 tx.insert(tx.begin(), {0xff, 0xff, id_, size});