Skip to content

Commit

Permalink
AP_InertialSensor: ensure gyro samples are used when the rate loop bu…
Browse files Browse the repository at this point in the history
…ffer isn't
  • Loading branch information
andyp1per committed Sep 26, 2024
1 parent ceb6ac6 commit cc0198f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
6 changes: 3 additions & 3 deletions libraries/AP_InertialSensor/AP_InertialSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -821,11 +821,11 @@ class AP_InertialSensor : AP_AccelCal_Client
// are gyro samples being sourced from the rate loop buffer
bool use_rate_loop_gyro_samples() const;
// push a new gyro sample into the fast rate buffer
bool push_next_gyro_sample(uint8_t instance, const Vector3f& gyro);
bool push_next_gyro_sample(const Vector3f& gyro);
// run the filter parmeter update code.
void update_backend_filters();
private:
bool push_rate_loop_gyro(uint8_t instance) const;
// are rate loop samples enabled for this instance?
bool is_rate_loop_gyro_enabled(uint8_t instance) const;
};

namespace AP {
Expand Down
8 changes: 6 additions & 2 deletions libraries/AP_InertialSensor/AP_InertialSensor_Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,12 @@ void AP_InertialSensor_Backend::apply_gyro_filters(const uint8_t instance, const
}

#if AP_INERTIALSENSOR_FAST_SAMPLE_WINDOW_ENABLED
if (_imu.push_next_gyro_sample(instance, gyro_filtered)) {
// if we used the value, record it for publication to the front-end
if (_imu.is_rate_loop_gyro_enabled(instance)) {
if (_imu.push_next_gyro_sample(gyro_filtered)) {
// if we used the value, record it for publication to the front-end
_imu._gyro_filtered[instance] = gyro_filtered;
}
} else {
_imu._gyro_filtered[instance] = gyro_filtered;
}
#else
Expand Down
31 changes: 15 additions & 16 deletions libraries/AP_InertialSensor/FastRateBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool AP_InertialSensor::use_rate_loop_gyro_samples() const
}

// whether or not to push the current gyro sample
bool AP_InertialSensor::push_rate_loop_gyro(uint8_t instance) const
bool AP_InertialSensor::is_rate_loop_gyro_enabled(uint8_t instance) const
{
return use_rate_loop_gyro_samples() && fast_rate_buffer->use_rate_loop_gyro_samples() && instance == AP::ahrs().get_primary_gyro_index();
}
Expand Down Expand Up @@ -88,23 +88,22 @@ bool FastRateBuffer::get_next_gyro_sample(Vector3f& gyro)
return _rate_loop_gyro_window.pop(gyro);
}

bool AP_InertialSensor::push_next_gyro_sample(uint8_t instance, const Vector3f& gyro)
bool AP_InertialSensor::push_next_gyro_sample(const Vector3f& gyro)
{
if (push_rate_loop_gyro(instance)
&& ++fast_rate_buffer->rate_decimation_count >= fast_rate_buffer->rate_decimation) {
/*
tell the rate thread we have a new sample
*/
WITH_SEMAPHORE(fast_rate_buffer->_mutex);

if (!fast_rate_buffer->_rate_loop_gyro_window.push(gyro)) {
debug("dropped rate loop sample");
}
fast_rate_buffer->rate_decimation_count = 0;
fast_rate_buffer->_notifier.signal();
return true;
if (++fast_rate_buffer->rate_decimation_count < fast_rate_buffer->rate_decimation) {
return false;
}
/*
tell the rate thread we have a new sample
*/
WITH_SEMAPHORE(fast_rate_buffer->_mutex);

if (!fast_rate_buffer->_rate_loop_gyro_window.push(gyro)) {
debug("dropped rate loop sample");
}
return false;
fast_rate_buffer->rate_decimation_count = 0;
fast_rate_buffer->_notifier.signal();
return true;
}

void AP_InertialSensor::update_backend_filters()
Expand Down

0 comments on commit cc0198f

Please sign in to comment.