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
This commit is contained in:
Daniel Agar
2022-03-23 15:46:54 -04:00
parent 875a2cc423
commit 3d08e031d2
+10 -2
View File
@@ -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 &timestamp_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