From 7170e638c5a7d68ce8fe2fbff03cd8679eb85bba Mon Sep 17 00:00:00 2001 From: Balduin Date: Wed, 18 Feb 2026 09:45:49 +0100 Subject: [PATCH] Allocation: separate accessing shared state from slew limiting introducing more variables than strictly necessary to clearly specify what is input and what is output. no functional change --- .../control_allocation/ControlAllocation.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/lib/control_allocation/control_allocation/ControlAllocation.cpp b/src/lib/control_allocation/control_allocation/ControlAllocation.cpp index dfdf9ca7f7..b00ec97321 100644 --- a/src/lib/control_allocation/control_allocation/ControlAllocation.cpp +++ b/src/lib/control_allocation/control_allocation/ControlAllocation.cpp @@ -112,15 +112,23 @@ void ControlAllocation::applySlewRateLimit(float dt) { for (int i = 0; i < _num_actuators; i++) { if (_actuator_slew_rate_limit(i) > FLT_EPSILON) { + + float input = _actuator_sp(i); + float previous = _prev_actuator_sp(i); + float delta_sp_max = dt * (_actuator_max(i) - _actuator_min(i)) / _actuator_slew_rate_limit(i); - float delta_sp = _actuator_sp(i) - _prev_actuator_sp(i); + float delta_sp = input - previous; + + float output = input; if (delta_sp > delta_sp_max) { - _actuator_sp(i) = _prev_actuator_sp(i) + delta_sp_max; + output = previous + delta_sp_max; } else if (delta_sp < -delta_sp_max) { - _actuator_sp(i) = _prev_actuator_sp(i) - delta_sp_max; + output = previous - delta_sp_max; } + + _actuator_sp(i) = output; } } }