From 77d5165c0159c8c2bec52da85bec9f5702b4a9cf Mon Sep 17 00:00:00 2001 From: Randy Mackay Date: Sat, 22 Feb 2020 12:22:13 +0900 Subject: [PATCH] RC_Channel: add norm_input_ignore_trim same as norm_input but ignores the trim value --- libraries/RC_Channel/RC_Channel.cpp | 12 ++++++++++++ libraries/RC_Channel/RC_Channel.h | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/libraries/RC_Channel/RC_Channel.cpp b/libraries/RC_Channel/RC_Channel.cpp index 00aec8f99e..81d6b001ee 100644 --- a/libraries/RC_Channel/RC_Channel.cpp +++ b/libraries/RC_Channel/RC_Channel.cpp @@ -308,6 +308,18 @@ RC_Channel::norm_input_dz() const return constrain_float(ret, -1.0f, 1.0f); } +// return a normalised input for a channel, in range -1 to 1, +// ignores trim and deadzone +float RC_Channel::norm_input_ignore_trim() const +{ + // sanity check min and max to avoid divide by zero + if (radio_max <= radio_min) { + return 0.0f; + } + const float ret = (reversed ? -2.0f : 2.0f) * (((float)(radio_in - radio_min) / (float)(radio_max - radio_min)) - 0.5f); + return constrain_float(ret, -1.0f, 1.0f); +} + /* get percentage input from 0 to 100. This ignores the trim value. */ diff --git a/libraries/RC_Channel/RC_Channel.h b/libraries/RC_Channel/RC_Channel.h index c36b08f5c8..220f0cd907 100644 --- a/libraries/RC_Channel/RC_Channel.h +++ b/libraries/RC_Channel/RC_Channel.h @@ -52,6 +52,10 @@ public: */ float norm_input_dz() const; + // return a normalised input for a channel, in range -1 to 1, + // ignores trim and deadzone + float norm_input_ignore_trim() const; + uint8_t percent_input() const; int16_t pwm_to_range() const; int16_t pwm_to_range_dz(uint16_t dead_zone) const;