From 3d08e031d2086421d24b87bfffa371f839a275ba Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Wed, 23 Mar 2022 15:46:54 -0400 Subject: [PATCH] rc_update: improve manual_switches simple protections - require back to back matching switch decode to match within 1 second - clear any previous manual switches if RC is unstable --- src/modules/rc_update/rc_update.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/modules/rc_update/rc_update.cpp b/src/modules/rc_update/rc_update.cpp index b357a9039b..9a43288d05 100644 --- a/src/modules/rc_update/rc_update.cpp +++ b/src/modules/rc_update/rc_update.cpp @@ -542,6 +542,12 @@ void RCUpdate::Run() } _last_timestamp_signal = input_rc.timestamp_last_signal; + + } else { + // RC input unstable or lost, clear any previous manual_switches + if (_manual_switches_last_publish.timestamp_sample != 0) { + _manual_switches_last_publish = {}; + } } memcpy(_rc_values_previous, input_rc.values, sizeof(input_rc.values[0]) * channel_count_limited); @@ -643,8 +649,10 @@ void RCUpdate::UpdateManualSwitches(const hrt_abstime ×tamp_sample) switches.video_switch = get_rc_sw2pos_position(rc_channels_s::FUNCTION_AUX_4, 0.5f); #endif - // last 2 switch updates identical (simple protection from bad RC data) - if (switches == _manual_switches_previous) { + // last 2 switch updates identical within 1 second (simple protection from bad RC data) + if ((switches == _manual_switches_previous) + && (switches.timestamp_sample < _manual_switches_previous.timestamp_sample + 1_s)) { + const bool switches_changed = (switches != _manual_switches_last_publish); // publish immediately on change or at ~1 Hz