Skip to content

Commit 830184a

Browse files
Your NameBrechtSerckx
authored andcommitted
Callback for Get_Bus_Voltage_Current
1 parent a902334 commit 830184a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/ODriveCAN.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,13 @@ void ODriveCAN::onReceive(uint32_t id, uint8_t length, const uint8_t* data) {
178178
temperature_callback_(temperature, temperature_user_data_);
179179
break;
180180
}
181+
case Get_Bus_Voltage_Current_msg_t::cmd_id: {
182+
Get_Bus_Voltage_Current_msg_t bus_vi;
183+
bus_vi.decode_buf(data);
184+
if (busVI_callback_)
185+
busVI_callback_(bus_vi, busVI_user_data_);
186+
break;
187+
}
181188
default: {
182189
if (requested_msg_id_ == REQUEST_PENDING)
183190
return;

src/ODriveCAN.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ class ODriveCAN {
171171
* @brief Requests ODrive DC bus voltage and current
172172
*
173173
* This function will block and wait for up to timeout_ms (default 10msec) for ODrive to reply
174+
* May trigger onBusVI callback if it's registered.
174175
*/
175176
bool getBusVI(Get_Bus_Voltage_Current_msg_t& msg, uint16_t timeout_ms = 10);
176177

@@ -230,6 +231,14 @@ class ODriveCAN {
230231
temperature_user_data_ = user_data;
231232
}
232233

234+
/**
235+
* @brief Registers a callback for ODrive bus voltage/current feedback.
236+
*/
237+
void onBusVI(void (*callback)(Get_Bus_Voltage_Current_msg_t& feedback, void* user_data), void* user_data = nullptr) {
238+
busVI_callback_ = callback;
239+
busVI_user_data_ = user_data;
240+
}
241+
233242
/**
234243
* @brief Processes received CAN messages for the ODrive.
235244
*/
@@ -341,9 +350,11 @@ class ODriveCAN {
341350
void* feedback_user_data_;
342351
void* torques_user_data_;
343352
void* temperature_user_data_;
353+
void* busVI_user_data_;
344354

345355
void (*axis_state_callback_)(Heartbeat_msg_t& feedback, void* user_data) = nullptr;
346356
void (*feedback_callback_)(Get_Encoder_Estimates_msg_t& feedback, void* user_data) = nullptr;
347357
void (*torques_callback_)(Get_Torques_msg_t& feedback, void* user_data) = nullptr;
348358
void (*temperature_callback_)(Get_Temperature_msg_t& feedback, void* user_data) = nullptr;
359+
void (*busVI_callback_)(Get_Bus_Voltage_Current_msg_t& feedback, void* user_data) = nullptr;
349360
};

0 commit comments

Comments
 (0)