diff --git a/src/lib/control_allocation/control_allocation/ControlAllocationPseudoInverse.cpp b/src/lib/control_allocation/control_allocation/ControlAllocationPseudoInverse.cpp index 5d86814d7e67..0dc512b4edf3 100644 --- a/src/lib/control_allocation/control_allocation/ControlAllocationPseudoInverse.cpp +++ b/src/lib/control_allocation/control_allocation/ControlAllocationPseudoInverse.cpp @@ -51,6 +51,11 @@ ControlAllocationPseudoInverse::setEffectivenessMatrix( update_normalization_scale); _mix_update_needed = true; _normalization_needs_update = update_normalization_scale; + + if (_metric_allocation && update_normalization_scale) { + // adding #include + PX4_WARN leads to failed linking on test + _normalization_needs_update = false; + } } void @@ -59,12 +64,15 @@ ControlAllocationPseudoInverse::updatePseudoInverse() if (_mix_update_needed) { matrix::geninv(_effectiveness, _mix); - if (_normalization_needs_update && !_had_actuator_failure) { - updateControlAllocationMatrixScale(); - _normalization_needs_update = false; + if (!_metric_allocation) { + if (_normalization_needs_update && !_had_actuator_failure) { + updateControlAllocationMatrixScale(); + _normalization_needs_update = false; + } + + normalizeControlAllocationMatrix(); } - normalizeControlAllocationMatrix(); _mix_update_needed = false; } } diff --git a/src/lib/control_allocation/control_allocation/ControlAllocationPseudoInverse.hpp b/src/lib/control_allocation/control_allocation/ControlAllocationPseudoInverse.hpp index 27c367376bd5..d4527cc1f4e4 100644 --- a/src/lib/control_allocation/control_allocation/ControlAllocationPseudoInverse.hpp +++ b/src/lib/control_allocation/control_allocation/ControlAllocationPseudoInverse.hpp @@ -57,11 +57,13 @@ class ControlAllocationPseudoInverse: public ControlAllocation void setEffectivenessMatrix(const matrix::Matrix &effectiveness, const ActuatorVector &actuator_trim, const ActuatorVector &linearization_point, int num_actuators, bool update_normalization_scale) override; + void setMetricAllocation(bool metric_allocation) { _metric_allocation = metric_allocation; } protected: matrix::Matrix _mix; bool _mix_update_needed{false}; + bool _metric_allocation{false}; /** * Recalculate pseudo inverse if required. diff --git a/src/lib/control_allocation/control_allocation/ControlAllocationPseudoInverseTest.cpp b/src/lib/control_allocation/control_allocation/ControlAllocationPseudoInverseTest.cpp index 89faab8c92ea..0eafbc6c26c4 100644 --- a/src/lib/control_allocation/control_allocation/ControlAllocationPseudoInverseTest.cpp +++ b/src/lib/control_allocation/control_allocation/ControlAllocationPseudoInverseTest.cpp @@ -67,3 +67,27 @@ TEST(ControlAllocationTest, AllZeroCase) EXPECT_EQ(actuator_sp, actuator_sp_expected); EXPECT_EQ(control_allocated, control_allocated_expected); } + +TEST(ControlAllocationMetricTest, AllZeroCase) +{ + ControlAllocationPseudoInverse method; + + matrix::Vector control_sp; + matrix::Vector control_allocated; + matrix::Vector control_allocated_expected; + matrix::Matrix effectiveness; + matrix::Vector actuator_sp; + matrix::Vector actuator_trim; + matrix::Vector linearization_point; + matrix::Vector actuator_sp_expected; + + method.setMetricAllocation(true); + method.setEffectivenessMatrix(effectiveness, actuator_trim, linearization_point, 16, false); + method.setControlSetpoint(control_sp); + method.allocate(); + actuator_sp = method.getActuatorSetpoint(); + control_allocated_expected = method.getAllocatedControl(); + + EXPECT_EQ(actuator_sp, actuator_sp_expected); + EXPECT_EQ(control_allocated, control_allocated_expected); +}