diff --git a/libraries/RC_Channel/RC_Channel.cpp b/libraries/RC_Channel/RC_Channel.cpp index c1c3c37c91..75745ff57e 100644 --- a/libraries/RC_Channel/RC_Channel.cpp +++ b/libraries/RC_Channel/RC_Channel.cpp @@ -339,6 +339,25 @@ RC_Channel::norm_input() return _reverse * (float)(radio_in - radio_trim) / (float)(radio_max - radio_trim); } +/* + get percentage input from 0 to 100. This ignores the trim value. + */ +uint8_t +RC_Channel::percent_input() +{ + if (radio_in <= radio_min) { + return _reverse==-1?100:0; + } + if (radio_in >= radio_max) { + return _reverse==-1?0:100; + } + uint8_t ret = 100.0f * (radio_in - radio_min) / (float)(radio_max - radio_min); + if (_reverse == -1) { + ret = 100 - ret; + } + return ret; +} + float RC_Channel::norm_output() { diff --git a/libraries/RC_Channel/RC_Channel.h b/libraries/RC_Channel/RC_Channel.h index cd76e91a51..a5caf7b8ed 100644 --- a/libraries/RC_Channel/RC_Channel.h +++ b/libraries/RC_Channel/RC_Channel.h @@ -89,6 +89,7 @@ public: int16_t pwm_to_angle_dz(uint16_t dead_zone); int16_t pwm_to_angle(); float norm_input(); + uint8_t percent_input(); float norm_output(); int16_t angle_to_pwm(); int16_t pwm_to_range();