fix(uavcan): publish esc_status once per ESC status round (#28266)

* fix(uavcan): publish esc_status once per ESC status round

* refactor(uavcan): esc_status publishing nit-picks

---------

Co-authored-by: Matthias Grob <maetugr@gmail.com>
This commit is contained in:
Anil KircalialiandMatthias Grob authored and GitHub committed 2026-08-18 19:40:45 +02:00
1 parent 7740117b17
commit e8ea98b404
2 files changed
+22 -8

No files matched your search

+17 -8
View File
@@ -108,6 +108,7 @@ void UavcanEscController::update_outputs(float outputs[MAX_ACTUATORS], uint8_t o
void UavcanEscController::set_rotor_count(uint8_t count)
{
_rotor_count = count;
_seen_status_mask = 0; // the set of reporting ESC indices may change with the mixer configuration
}
void UavcanEscController::esc_status_sub_cb(const uavcan::ReceivedDataStructure<uavcan::equipment::esc::Status> &msg)
@@ -123,15 +124,23 @@ void UavcanEscController::esc_status_sub_cb(const uavcan::ReceivedDataStructure<
esc_report.esc_errorcount = msg.error_count;
esc_report.failures = get_failures(msg.esc_index, msg.getSrcNodeID().get());
_esc_status.esc_count = _rotor_count;
_esc_status.counter += 1;
_esc_status.esc_connectiontype = esc_status_s::ESC_CONNECTION_TYPE_CAN;
_esc_status.esc_online_flags = check_escs_status();
_esc_status.esc_armed_flags = (1 << _rotor_count) - 1;
_esc_status.timestamp = esc_report.timestamp;
// A repeated ESC index marks the start of a new round; publish once per round.
const uint16_t index_bit = 1u << msg.esc_index;
_failure_config.update();
_esc_status_pub.publish(failure_injection::process_esc(_failure_config, _esc_status));
if (_seen_status_mask & index_bit) {
_seen_status_mask = 0;
_esc_status.esc_count = _rotor_count;
_esc_status.counter += 1;
_esc_status.esc_connectiontype = esc_status_s::ESC_CONNECTION_TYPE_CAN;
_esc_status.esc_online_flags = check_escs_status();
_esc_status.esc_armed_flags = (1 << _rotor_count) - 1;
_esc_status.timestamp = esc_report.timestamp;
_failure_config.update();
_esc_status_pub.publish(failure_injection::process_esc(_failure_config, _esc_status));
}
_seen_status_mask |= index_bit;
}
// Register device capability for each ESC channel
+5
View File
@@ -126,6 +126,11 @@ private:
uint8_t _rotor_count{0};
// bitmask of ESC indices seen since the last publish; a repeat marks a new round
uint16_t _seen_status_mask{0};
static_assert(esc_status_s::CONNECTED_ESC_MAX <= 8 * sizeof(_seen_status_mask),
"_seen_status_mask cannot hold CONNECTED_ESC_MAX bits");
failure_injection::Config _failure_config;
/*