uavcan: more efficient calculation of esc.RawCommand.cmd array size
Build all targets / Scan for Board Targets (push) Has been cancelled
Build all targets / Build [${{ matrix.runner }}][${{ matrix.group }}] (push) Has been cancelled
Build all targets / Upload Artifacts (push) Has been cancelled
Checks / build (NO_NINJA_BUILD=1 px4_fmu-v5_default) (push) Has been cancelled
Checks / build (NO_NINJA_BUILD=1 px4_sitl_default) (push) Has been cancelled
Checks / build (check_format) (push) Has been cancelled
Checks / build (check_newlines) (push) Has been cancelled
Checks / build (module_documentation) (push) Has been cancelled
Checks / build (px4_fmu-v2_default stack_check) (push) Has been cancelled
Checks / build (px4_sitl_allyes) (push) Has been cancelled
Checks / build (shellcheck_all) (push) Has been cancelled
Checks / build (tests) (push) Has been cancelled
Checks / build (tests_coverage) (push) Has been cancelled
Checks / build (validate_module_configs) (push) Has been cancelled
Clang Tidy / build (push) Has been cancelled
MacOS build / build (px4_fmu-v5_default) (push) Has been cancelled
MacOS build / build (px4_sitl) (push) Has been cancelled
Ubuntu environment build / Build and Test (ubuntu:22.04) (push) Has been cancelled
Ubuntu environment build / Build and Test (ubuntu:24.04) (push) Has been cancelled
Container build / Set Tags and Variables (push) Has been cancelled
Container build / Build Container (amd64) (push) Has been cancelled
Container build / Build Container (arm64) (push) Has been cancelled
Container build / Deploy To Registry (push) Has been cancelled
EKF Update Change Indicator / unit_tests (push) Has been cancelled
Failsafe Simulator Build / build (failsafe_web) (push) Has been cancelled
FLASH usage analysis / Analyzing px4_fmu-v5x (push) Has been cancelled
FLASH usage analysis / Analyzing px4_fmu-v6x (push) Has been cancelled
FLASH usage analysis / Publish Results (push) Has been cancelled
ITCM check / Checking nxp_tropic-community (push) Has been cancelled
ITCM check / Checking px4_fmu-v5x (push) Has been cancelled
ITCM check / Checking px4_fmu-v6xrt (push) Has been cancelled
MAVROS Mission Tests / build (map[mission:MC_mission_box vehicle:iris]) (push) Has been cancelled
MAVROS Offboard Tests / build (map[test_file:mavros_posix_tests_offboard_posctl.test vehicle:iris]) (push) Has been cancelled
Nuttx Target with extra env config / build (px4_fmu-v5_default) (push) Has been cancelled
Python CI Checks / build (push) Has been cancelled
ROS Integration Tests / build (push) Has been cancelled
ROS Translation Node Tests / Build and test (map[ros_version:humble ubuntu:jammy]) (push) Has been cancelled
ROS Translation Node Tests / Build and test (map[ros_version:jazzy ubuntu:noble]) (push) Has been cancelled
SITL Tests / Testing PX4 tailsitter (push) Has been cancelled
SITL Tests / Testing PX4 iris (push) Has been cancelled
SITL Tests / Testing PX4 standard_vtol (push) Has been cancelled
Handle stale issues and PRs / stale (push) Has been cancelled
Fuzzing / Fuzzing (push) Has been cancelled

This commit is contained in:
Matthias Grob
2025-10-28 16:03:55 +01:00
committed by Jacob Dahl
parent c44e0be18a
commit ae03630570
3 changed files with 19 additions and 33 deletions
+3 -26
View File
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (C) 2014 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
@@ -74,20 +74,13 @@ UavcanEscController::init()
_uavcan_pub_raw_cmd.getTransferSender().setIfaceMask(iface_mask);
}
char param_name[17];
for (unsigned i = 0; i < MAX_ACTUATORS; ++i) {
snprintf(param_name, sizeof(param_name), "UAVCAN_EC_FUNC%d", i + 1);
_param_handles[i] = param_find(param_name);
}
_initialized = true;
return res;
}
void
UavcanEscController::update_outputs(uint16_t outputs[MAX_ACTUATORS], unsigned total_outputs)
UavcanEscController::update_outputs(uint16_t outputs[MAX_ACTUATORS], uint8_t output_array_size)
{
// TODO: configurable rate limit
const auto timestamp = _node.getMonotonicTime();
@@ -100,26 +93,10 @@ UavcanEscController::update_outputs(uint16_t outputs[MAX_ACTUATORS], unsigned to
uavcan::equipment::esc::RawCommand msg = {};
// directly output values from mixer
for (unsigned i = 0; i < total_outputs; i++) {
for (unsigned i = 0; i < output_array_size; i++) {
msg.cmd.push_back(static_cast<int>(outputs[i]));
}
// but only output as many channels as are configured
uint8_t min_size = 0;
for (int i = 0; i < MAX_ACTUATORS; i++) {
int32_t val = 0;
if (param_get(_param_handles[i], &val) == 0) {
if (val > 0) {
min_size = i + 1;
}
}
}
msg.cmd.resize(min_size);
_uavcan_pub_raw_cmd.broadcast(msg);
}
+2 -5
View File
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (C) 2014 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
@@ -71,7 +71,7 @@ public:
bool initialized() { return _initialized; };
void update_outputs(uint16_t outputs[MAX_ACTUATORS], unsigned total_outputs);
void update_outputs(uint16_t outputs[MAX_ACTUATORS], uint8_t output_array_size);
/**
* Sets the number of rotors and enable timer
@@ -114,7 +114,4 @@ private:
uavcan::INode &_node;
uavcan::Publisher<uavcan::equipment::esc::RawCommand> _uavcan_pub_raw_cmd;
uavcan::Subscriber<uavcan::equipment::esc::Status, StatusCbBinder> _uavcan_sub_status;
param_t _param_handles[MAX_ACTUATORS] {PARAM_INVALID};
};
+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;