From 14c4257a59183082f08ef7a749634b463a6a8f5c Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Fri, 3 Nov 2023 17:34:30 +0100 Subject: [PATCH] ActuatorEffectivenessRotors: Use modern parameter interface for rotor count This lead to a compiler warning with arm-none-eabi-gcc 12+ about the variable count potentially being a dangling pointer. --- .../ActuatorEffectivenessRotors.cpp | 11 +---------- .../ActuatorEffectivenessRotors.hpp | 5 ++++- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/modules/control_allocator/ActuatorEffectiveness/ActuatorEffectivenessRotors.cpp b/src/modules/control_allocator/ActuatorEffectiveness/ActuatorEffectivenessRotors.cpp index 29a2dea9be..5164acff05 100644 --- a/src/modules/control_allocator/ActuatorEffectiveness/ActuatorEffectivenessRotors.cpp +++ b/src/modules/control_allocator/ActuatorEffectiveness/ActuatorEffectivenessRotors.cpp @@ -79,8 +79,6 @@ ActuatorEffectivenessRotors::ActuatorEffectivenessRotors(ModuleParams *parent, A } } - _count_handle = param_find("CA_ROTOR_COUNT"); - updateParams(); } @@ -88,14 +86,7 @@ void ActuatorEffectivenessRotors::updateParams() { ModuleParams::updateParams(); - int32_t count = 0; - - if (param_get(_count_handle, &count) != 0) { - PX4_ERR("param_get failed"); - return; - } - - _geometry.num_rotors = math::min(NUM_ROTORS_MAX, (int)count); + _geometry.num_rotors = math::min(NUM_ROTORS_MAX, static_cast(_param_ca_rotor_count.get())); for (int i = 0; i < _geometry.num_rotors; ++i) { Vector3f &position = _geometry.rotors[i].position; diff --git a/src/modules/control_allocator/ActuatorEffectiveness/ActuatorEffectivenessRotors.hpp b/src/modules/control_allocator/ActuatorEffectiveness/ActuatorEffectivenessRotors.hpp index 14f96b7dab..3844df4c84 100644 --- a/src/modules/control_allocator/ActuatorEffectiveness/ActuatorEffectivenessRotors.hpp +++ b/src/modules/control_allocator/ActuatorEffectiveness/ActuatorEffectivenessRotors.hpp @@ -147,7 +147,10 @@ private: param_t tilt_index; }; ParamHandles _param_handles[NUM_ROTORS_MAX]; - param_t _count_handle; Geometry _geometry{}; + + DEFINE_PARAMETERS( + (ParamInt) _param_ca_rotor_count + ) };