84 if (msg.
id >= 0x201 && msg.
id < 0x201 + 8) {
85 C6x0 *motor = motors_[msg.
id - 0x201];
88 static_cast<int16_t
>(msg.
data[0] << 8 | msg.
data[1]);
89 int16_t delta = count - motor->prev_count_;
92 }
else if (delta < -4096) {
96 motor->prev_count_ = count;
98 motor->rpm_ =
static_cast<int16_t
>(msg.
data[2] << 8 | msg.
data[3]);
100 static_cast<int16_t
>(msg.
data[4] << 8 | msg.
data[5]);
109 for (
size_t i = 0; i < 4; ++i) {
111 msg.
data[i * 2] = motors_[i]->target_current_ >> 8;
112 msg.
data[i * 2 + 1] = motors_[i]->target_current_;
121 for (
size_t i = 0; i < 4; ++i) {
122 if (motors_[i + 4]) {
123 msg.
data[i * 2] = motors_[i + 4]->target_current_ >> 8;
124 msg.
data[i * 2 + 1] = motors_[i + 4]->target_current_;
132 std::array<C6x0 *, 8> motors_{};
138 :
EncoderBase{8192}, manager_{manager}, type_{type}, id_{id} {
154 return current_ * 25000 / 16384;
161 target_current_ = current;
164 target_current_ = current * 16384 / 25000;
174 int16_t prev_count_ = 0;
176 int16_t current_ = 0;
177 int16_t target_current_ = 0;
bool update()
Definition c6x0.hpp:81
Manager(peripheral::CANBase &can)
Definition c6x0.hpp:79
float get_rps() override
Definition c6x0.hpp:145
void set_current(int16_t current)
Definition c6x0.hpp:158
Type
Definition c6x0.hpp:61
C6x0(Manager &manager, Type type, ID id)
Definition c6x0.hpp:137
float get_rpm() override
Definition c6x0.hpp:147
int16_t get_current()
Definition c6x0.hpp:149
~C6x0()
Definition c6x0.hpp:143
Definition encoder_base.hpp:10
void set_count(int64_t count)
Definition encoder_base.hpp:28
int64_t get_count()
Definition encoder_base.hpp:16
Definition can_base.hpp:10
virtual bool transmit(const Message &msg, uint32_t timeout)=0
virtual bool receive(Message &msg, uint32_t timeout)=0
constexpr std::underlying_type_t< T > to_underlying(T value) noexcept
Definition utility.hpp:23
Definition can_base.hpp:17
uint32_t id
Definition can_base.hpp:19
uint8_t dlc
Definition can_base.hpp:20
IDType id_type
Definition can_base.hpp:18
std::array< uint8_t, 8 > data
Definition can_base.hpp:21
#define TUTRCOS_VERIFY(expr)
Definition utility.hpp:16