[wpimath] Fix pose estimator performance (#4111)

Fixes #4087.
This commit is contained in:
Tyler Veness
2022-04-26 18:43:59 -07:00
committed by GitHub
parent 51bc893bc5
commit d926dd1610
12 changed files with 159 additions and 97 deletions

View File

@@ -7,6 +7,7 @@
#include <array>
#include <functional>
#include <map>
#include <optional>
#include <utility>
#include <vector>
@@ -81,12 +82,16 @@ class TimeInterpolatableBuffer {
void Clear() { m_pastSnapshots.clear(); }
/**
* Sample the buffer at the given time. If there are no elements in the
* buffer, calling this function results in undefined behavior.
* Sample the buffer at the given time. If the buffer is empty, an empty
* optional is returned.
*
* @param time The time at which to sample the buffer.
*/
T Sample(units::second_t time) {
std::optional<T> Sample(units::second_t time) {
if (m_pastSnapshots.empty()) {
return {};
}
// We will perform a binary search to find the index of the element in the
// vector that has a timestamp that is equal to or greater than the vision
// measurement timestamp.