mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-02 09:11:36 +08:00
ekf2: improve ring buffer sizing and dynamically allocate
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2015 PX4 Development Team. All rights reserved.
|
||||
* Copyright (C) 2015-2022 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -46,7 +46,7 @@ class RingBuffer
|
||||
{
|
||||
public:
|
||||
explicit RingBuffer(size_t size) { allocate(size); }
|
||||
RingBuffer() { allocate(1); }
|
||||
RingBuffer() = delete;
|
||||
~RingBuffer() { delete[] _buffer; }
|
||||
|
||||
// no copy, assignment, move, move assignment
|
||||
@@ -155,6 +155,19 @@ public:
|
||||
|
||||
int get_total_size() const { return sizeof(*this) + sizeof(data_type) * _size; }
|
||||
|
||||
int entries() const
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
for (uint8_t i = 0; i < _size; i++) {
|
||||
if (_buffer[i].time_us != 0) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
private:
|
||||
data_type *_buffer{nullptr};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user