Skip to content

Commit

Permalink
AP_NavEKF: avoid copying all but the best element when recalling time…
Browse files Browse the repository at this point in the history
…-horizon data
  • Loading branch information
peterbarker authored and tridge committed Aug 27, 2024
1 parent 44ae148 commit 00dc150
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion libraries/AP_NavEKF/EKF_Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ uint32_t ekf_ring_buffer::time_ms(uint8_t idx) const
bool ekf_ring_buffer::recall(void *element, const uint32_t sample_time_ms)
{
bool ret = false;
uint8_t best_index = 0; // only valid when ret becomes true
while (count > 0) {
const uint32_t toldest = time_ms(oldest);
const int32_t dt = sample_time_ms - toldest;
const bool matches = dt >= 0 && dt < 100;
if (matches) {
memcpy(element, get_offset(oldest), elsize);
best_index = oldest;
ret = true;
}
if (dt < 0) {
Expand All @@ -70,6 +71,11 @@ bool ekf_ring_buffer::recall(void *element, const uint32_t sample_time_ms)
count--;
oldest = (oldest+1) % size;
}

if (ret) {
memcpy(element, get_offset(best_index), elsize);
}

return ret;
}

Expand Down

0 comments on commit 00dc150

Please sign in to comment.