uavcan: more efficient calculation of esc.RawCommand.cmd array size

This commit is contained in:
Matthias Grob
2025-11-03 08:18:55 -09:00
committed by Jacob Dahl
parent c44e0be18a
commit ae03630570
3 changed files with 19 additions and 33 deletions
+14 -2
View File
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (c) 2014-2022 PX4 Development Team. All rights reserved.
* Copyright (c) 2014-2025 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -1082,7 +1082,19 @@ bool UavcanMixingInterfaceESC::updateOutputs(uint16_t outputs[MAX_ACTUATORS], un
unsigned num_control_groups_updated)
{
if (_esc_controller.initialized()) {
_esc_controller.update_outputs(outputs, num_outputs);
// num_outputs is the maximum possible number of outputs (8)
// output_array_size adapts to the highest output index that is mapped (4 for a quad)
// this allows for sending less CAN frames depending on what output indices are mapped
uint8_t output_array_size = 0;
for (int i = MAX_ACTUATORS - 1; i >= 0; i--) {
if (mixingOutput().isFunctionSet(i)) {
output_array_size = i + 1;
break;
}
}
_esc_controller.update_outputs(outputs, output_array_size);
}
return true;