From f34fbdf0d3c9371efd6569e691790d711b64fd90 Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Mon, 5 Jun 2023 14:02:36 +0200 Subject: [PATCH] rc_update: throttle trim centering fix for reverse channel The entire logic did not work for the case when the throttle channel is reversed because then QGC sets trim = max for that channel and the result is only half the throttle range. --- src/modules/rc_update/rc_update.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modules/rc_update/rc_update.cpp b/src/modules/rc_update/rc_update.cpp index af4931c472..bb764901d3 100644 --- a/src/modules/rc_update/rc_update.cpp +++ b/src/modules/rc_update/rc_update.cpp @@ -210,8 +210,12 @@ void RCUpdate::parameters_updated() const uint16_t throttle_min = _parameters.min[throttle_channel]; const uint16_t throttle_trim = _parameters.trim[throttle_channel]; const uint16_t throttle_max = _parameters.max[throttle_channel]; + const bool throttle_rev = _parameters.rev[throttle_channel]; - if (throttle_min == throttle_trim) { + const bool normal_case = !throttle_rev && (throttle_trim == throttle_min); + const bool reversed_case = throttle_rev && (throttle_trim == throttle_max); + + if (normal_case || reversed_case) { const uint16_t new_throttle_trim = (throttle_min + throttle_max) / 2; _parameters.trim[throttle_channel] = new_throttle_trim; }