From 7edf8c0e0ab07e73815f4290223582511f5d3e76 Mon Sep 17 00:00:00 2001 From: Grant Morphett Date: Fri, 30 Oct 2015 16:46:03 +1100 Subject: [PATCH] RC_Channel: New method to detect if channel is in trim location This is a new method which will return true if an RC_Channel has a PWM value that is at its TRIM value plus or minus the allowed dead zone around the TRIM. --- libraries/RC_Channel/RC_Channel.cpp | 8 ++++++++ libraries/RC_Channel/RC_Channel.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/libraries/RC_Channel/RC_Channel.cpp b/libraries/RC_Channel/RC_Channel.cpp index 2ee9e09374..581a306e36 100644 --- a/libraries/RC_Channel/RC_Channel.cpp +++ b/libraries/RC_Channel/RC_Channel.cpp @@ -511,3 +511,11 @@ uint16_t RC_Channel::get_limit_pwm(LimitValue limit) const // invalid limit value, return trim return radio_trim; } + +/* + Return true if the channel is at trim and within the DZ +*/ +bool RC_Channel::in_trim_dz() +{ + return is_bounded(radio_in, radio_trim - _dead_zone, radio_trim + _dead_zone); +} diff --git a/libraries/RC_Channel/RC_Channel.h b/libraries/RC_Channel/RC_Channel.h index 4dfe990ec1..3562b13b06 100644 --- a/libraries/RC_Channel/RC_Channel.h +++ b/libraries/RC_Channel/RC_Channel.h @@ -135,6 +135,8 @@ public: static RC_Channel *rc_channel(uint8_t i); + bool in_trim_dz(); + private: AP_Int8 _reverse; AP_Int16 _dead_zone;