Skip to content

Added a complementary filter to rangefinder data (for 3.6) #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: mttr-rebase-3.6.7
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Copter: fixed rangefinder filter when out of range
don't input invalid data into the filter, allowing it to reset if data
is more than 1s old
  • Loading branch information
tridge committed Jun 2, 2021
commit c09a888b5ebde78e30419363ee99d1710a0cb95a
14 changes: 6 additions & 8 deletions ArduCopter/sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,18 @@ void Copter::read_rangefinder(void)
target_filter_hz = RANGEFINDER_WPNAV_FILT_MIN_HZ;
}

// prevent sharp changes to the filter time constant
const float alt_filter_slew_alpha = 0.98;
rangefinder_state.filter_hz = rangefinder_state.filter_hz * alt_filter_slew_alpha + target_filter_hz * (1-alt_filter_slew_alpha);

if (target_filter_hz > rangefinder_state.filter_hz) {
// when raising target freq we use a reset to prevent a numerical error in the complementary filter
if (!is_equal(target_filter_hz,rangefinder_state.filter_hz)) {
// when changing target freq we use a reset to prevent a numerical error in the complementary filter
rangefinder_state.filter_hz = target_filter_hz;
rangefinder_state.alt_cm_filt.set_cutoff_frequency(rangefinder_state.filter_hz);
rangefinder_state.alt_cm_filt.reset();
}

// apply complementary filter
rangefinder_state.alt_cm_filt.set_cutoff_frequency(rangefinder_state.filter_hz);
float rangefinder_alt_flt = rangefinder_state.alt_cm_filt.apply(rangefinder_alt_meas, inertial_nav.get_altitude(), AP_HAL::micros());
if (rangefinder_alt_meas_valid) {
rangefinder_state.alt_cm_filt.apply(rangefinder_alt_meas, inertial_nav.get_altitude(), AP_HAL::micros());
}
const float rangefinder_alt_flt = rangefinder_state.alt_cm_filt.get();

// temporary debug log message to look at the
// performance of the complementary filter
Expand Down