Skip to content

Commit e16f178

Browse files
Pedro-RoqueJoelJ18
authored andcommitted
Control Allocator: Add option for metric allocation (skip normalization) (PX4#24199)
* add: metric allocation * add: actual files * rft: moved metric allocation to pseudo-inverse via flag with public method * del: removed metric allocation test and added test in pseudo-inverse testing * rft: deleted extra newline at the end of pseudo inverse test file * feat: removed unnecessary log include
1 parent ced0b40 commit e16f178

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

src/lib/control_allocation/control_allocation/ControlAllocationPseudoInverse.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ ControlAllocationPseudoInverse::setEffectivenessMatrix(
5151
update_normalization_scale);
5252
_mix_update_needed = true;
5353
_normalization_needs_update = update_normalization_scale;
54+
55+
if (_metric_allocation && update_normalization_scale) {
56+
// adding #include <px4_platform_common/log.h> + PX4_WARN leads to failed linking on test
57+
_normalization_needs_update = false;
58+
}
5459
}
5560

5661
void
@@ -59,12 +64,15 @@ ControlAllocationPseudoInverse::updatePseudoInverse()
5964
if (_mix_update_needed) {
6065
matrix::geninv(_effectiveness, _mix);
6166

62-
if (_normalization_needs_update && !_had_actuator_failure) {
63-
updateControlAllocationMatrixScale();
64-
_normalization_needs_update = false;
67+
if (!_metric_allocation) {
68+
if (_normalization_needs_update && !_had_actuator_failure) {
69+
updateControlAllocationMatrixScale();
70+
_normalization_needs_update = false;
71+
}
72+
73+
normalizeControlAllocationMatrix();
6574
}
6675

67-
normalizeControlAllocationMatrix();
6876
_mix_update_needed = false;
6977
}
7078
}

src/lib/control_allocation/control_allocation/ControlAllocationPseudoInverse.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ class ControlAllocationPseudoInverse: public ControlAllocation
5757
void setEffectivenessMatrix(const matrix::Matrix<float, NUM_AXES, NUM_ACTUATORS> &effectiveness,
5858
const ActuatorVector &actuator_trim, const ActuatorVector &linearization_point, int num_actuators,
5959
bool update_normalization_scale) override;
60+
void setMetricAllocation(bool metric_allocation) { _metric_allocation = metric_allocation; }
6061

6162
protected:
6263
matrix::Matrix<float, NUM_ACTUATORS, NUM_AXES> _mix;
6364

6465
bool _mix_update_needed{false};
66+
bool _metric_allocation{false};
6567

6668
/**
6769
* Recalculate pseudo inverse if required.

src/lib/control_allocation/control_allocation/ControlAllocationPseudoInverseTest.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,27 @@ TEST(ControlAllocationTest, AllZeroCase)
6767
EXPECT_EQ(actuator_sp, actuator_sp_expected);
6868
EXPECT_EQ(control_allocated, control_allocated_expected);
6969
}
70+
71+
TEST(ControlAllocationMetricTest, AllZeroCase)
72+
{
73+
ControlAllocationPseudoInverse method;
74+
75+
matrix::Vector<float, 6> control_sp;
76+
matrix::Vector<float, 6> control_allocated;
77+
matrix::Vector<float, 6> control_allocated_expected;
78+
matrix::Matrix<float, 6, 16> effectiveness;
79+
matrix::Vector<float, 16> actuator_sp;
80+
matrix::Vector<float, 16> actuator_trim;
81+
matrix::Vector<float, 16> linearization_point;
82+
matrix::Vector<float, 16> actuator_sp_expected;
83+
84+
method.setMetricAllocation(true);
85+
method.setEffectivenessMatrix(effectiveness, actuator_trim, linearization_point, 16, false);
86+
method.setControlSetpoint(control_sp);
87+
method.allocate();
88+
actuator_sp = method.getActuatorSetpoint();
89+
control_allocated_expected = method.getAllocatedControl();
90+
91+
EXPECT_EQ(actuator_sp, actuator_sp_expected);
92+
EXPECT_EQ(control_allocated, control_allocated_expected);
93+
}

0 commit comments

Comments
 (0)