WPILibC++ 2024.3.2
frc::TimeInterpolatableBuffer< T > Class Template Reference

The TimeInterpolatableBuffer provides an easy way to estimate past measurements. More...

#include <frc/interpolation/TimeInterpolatableBuffer.h>

Public Member Functions

 TimeInterpolatableBuffer (units::second_t historySize, std::function< T(const T &, const T &, double)> func)
 Create a new TimeInterpolatableBuffer. More...
 
 TimeInterpolatableBuffer (units::second_t historySize)
 Create a new TimeInterpolatableBuffer. More...
 
void AddSample (units::second_t time, T sample)
 Add a sample to the buffer. More...
 
void Clear ()
 Clear all old samples. More...
 
std::optional< T > Sample (units::second_t time)
 Sample the buffer at the given time. More...
 
std::vector< std::pair< units::second_t, T > > & GetInternalBuffer ()
 Grant access to the internal sample buffer. More...
 
WPILIB_DLLEXPORT TimeInterpolatableBuffer (units::second_t historySize)
 

Detailed Description

template<typename T>
class frc::TimeInterpolatableBuffer< T >

The TimeInterpolatableBuffer provides an easy way to estimate past measurements.

One application might be in conjunction with the DifferentialDrivePoseEstimator, where knowledge of the robot pose at the time when vision or other global measurement were recorded is necessary, or for recording the past angles of mechanisms as measured by encoders.

When sampling this buffer, a user-provided function or wpi::Lerp can be used. For Pose2ds, we use Twists.

Template Parameters
TThe type stored in this buffer.

Constructor & Destructor Documentation

◆ TimeInterpolatableBuffer() [1/3]

template<typename T >
frc::TimeInterpolatableBuffer< T >::TimeInterpolatableBuffer ( units::second_t  historySize,
std::function< T(const T &, const T &, double)>  func 
)
inline

Create a new TimeInterpolatableBuffer.

Parameters
historySizeThe history size of the buffer.
funcThe function used to interpolate between values.

◆ TimeInterpolatableBuffer() [2/3]

template<typename T >
frc::TimeInterpolatableBuffer< T >::TimeInterpolatableBuffer ( units::second_t  historySize)
inlineexplicit

Create a new TimeInterpolatableBuffer.

By default, the interpolation function is wpi::Lerp except for Pose2d, which uses the pose exponential.

Parameters
historySizeThe history size of the buffer.

◆ TimeInterpolatableBuffer() [3/3]

WPILIB_DLLEXPORT frc::TimeInterpolatableBuffer< Pose2d >::TimeInterpolatableBuffer ( units::second_t  historySize)

Member Function Documentation

◆ AddSample()

template<typename T >
void frc::TimeInterpolatableBuffer< T >::AddSample ( units::second_t  time,
sample 
)
inline

Add a sample to the buffer.

Parameters
timeThe timestamp of the sample.
sampleThe sample object.

◆ Clear()

template<typename T >
void frc::TimeInterpolatableBuffer< T >::Clear ( )
inline

Clear all old samples.

◆ GetInternalBuffer()

template<typename T >
std::vector< std::pair< units::second_t, T > > & frc::TimeInterpolatableBuffer< T >::GetInternalBuffer ( )
inline

Grant access to the internal sample buffer.

Used in Pose Estimation to replay odometry inputs stored within this buffer.

◆ Sample()

template<typename T >
std::optional< T > frc::TimeInterpolatableBuffer< T >::Sample ( units::second_t  time)
inline

Sample the buffer at the given time.

If the buffer is empty, an empty optional is returned.

Parameters
timeThe time at which to sample the buffer.

The documentation for this class was generated from the following file: