Skip to content
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

ekf2: RingBuffer pop_first_older_than() invalidate all older samples #23412

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
40 changes: 20 additions & 20 deletions src/modules/ekf2/EKF/RingBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,38 +119,38 @@ class RingBuffer

bool pop_first_older_than(const uint64_t &timestamp, data_type *sample)
{
// start looking from newest observation data
bool found = false;

for (uint8_t i = 0; i < _size; i++) {
// start looking from newest observation data
int index = (_head - i);
index = index < 0 ? _size + index : index;

if (timestamp >= _buffer[index].time_us && timestamp < _buffer[index].time_us + (uint64_t)1e5) {
*sample = _buffer[index];
if ((_buffer[index].time_us != 0) && (timestamp >= _buffer[index].time_us)) {

// Now we can set the tail to the item which
// comes after the one we removed since we don't
// want to have any older data in the buffer
if (index == _head) {
_tail = _head;
_first_write = true;
if (!found && (timestamp < _buffer[index].time_us + 100'000)) {
*sample = _buffer[index];

} else {
_tail = (index + 1) % _size;
}
// Now we can set the tail to the item which
// comes after the one we removed since we don't
// want to have any older data in the buffer
if (index == _head) {
_tail = _head;
_first_write = true;

_buffer[index].time_us = 0;
} else {
_tail = (index + 1) % _size;
}

return true;
}
found = true;
}

if (index == _tail) {
// we have reached the tail and haven't got a
// match
return false;
// invalidate any older data
_buffer[index].time_us = 0;
}
}

return false;
return found;
}

int get_used_size() const { return sizeof(*this) + sizeof(data_type) * entries(); }
Expand Down
Loading