This utility class serves as an in-memory cache of time-dependent vector values.
Note that this is a standalone class, not a Drake System. It is primarily intended to support the Drake System primitive VectorLogSink, but can be used independently.
When the log becomes full, adding more data will cause the allocated space to double in size. If avoiding memory allocation during some performance-critical phase is desired, clients can call Reserve() to pre-allocate log storage.
This object imposes no constraints on the stored data. For example, times passed to AddData() need not be increasing in order of insertion, values are allowed to be infinite, NaN, etc.
T | The scalar type, which must be one of the default scalars. |
#include <drake/systems/primitives/vector_log.h>
Public Member Functions | |
VectorLog (int input_size) | |
Constructs the vector log. More... | |
int64_t | get_input_size () const |
Reports the size of the log's input vector. More... | |
int | num_samples () const |
Returns the number of samples taken since construction or last Clear(). More... | |
Eigen::VectorBlock< const VectorX< T > > | sample_times () const |
Accesses the logged time stamps. More... | |
Eigen::Block< const MatrixX< T >, Eigen::Dynamic, Eigen::Dynamic, true > | data () const |
Accesses the logged data. More... | |
void | Reserve (int64_t capacity) |
Reserve storage for at least capacity samples. More... | |
void | Clear () |
Clears the logged data. More... | |
void | AddData (const T &time, const VectorX< T > &sample) |
Adds a sample to the data set with the associated time value. More... | |
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable | |
VectorLog (const VectorLog &)=default | |
VectorLog & | operator= (const VectorLog &)=default |
VectorLog (VectorLog &&)=default | |
VectorLog & | operator= (VectorLog &&)=default |
Static Public Attributes | |
static constexpr int64_t | kDefaultCapacity = 1000 |
The default capacity of vector log allocation, expressed as a number of samples. More... | |
Constructs the vector log.
input_size | Dimension of the per-time step data set. |
void AddData | ( | const T & | time, |
const VectorX< T > & | sample | ||
) |
Adds a sample
to the data set with the associated time
value.
The new sample and time are added to the end of the log. No constraints are imposed on the values oftime
or sample
.
time | The time value for this sample. |
sample | A vector of data of the declared size for this log. |
void Clear | ( | ) |
Clears the logged data.
Eigen::Block<const MatrixX<T>, Eigen::Dynamic, Eigen::Dynamic, true > data | ( | ) | const |
Accesses the logged data.
The InnerPanel parameter of the return type indicates that the compiler can assume aligned access to the data.
int64_t get_input_size | ( | ) | const |
Reports the size of the log's input vector.
void Reserve | ( | int64_t | capacity | ) |
Reserve storage for at least capacity
samples.
At construction, there will be at least kDefaultCapacity
; use this method to reserve more.
Eigen::VectorBlock<const VectorX<T> > sample_times | ( | ) | const |
Accesses the logged time stamps.
|
static |
The default capacity of vector log allocation, expressed as a number of samples.
Chosen to be large enough that most systems won't need to allocate during simulation advance steps.