mars_lib 0.1.0.2abe2576fe7f
Modular and Robust Sensor-Fusion
Loading...
Searching...
No Matches
buffer.h
Go to the documentation of this file.
1// Copyright (C) 2021 Christian Brommer and Martin Scheiber, Control of Networked Systems, University of Klagenfurt,
2// Austria.
3//
4// All rights reserved.
5//
6// This software is licensed under the terms of the BSD-2-Clause-License with
7// no commercial use allowed, the full terms of which are made available
8// in the LICENSE file. No license in patents is granted.
9//
10// You can contact the authors at <christian.brommer@ieee.org>
11// and <martin.scheiber@ieee.org>.
12
13#ifndef BUFFER_H
14#define BUFFER_H
15
17#include <mars/time.h>
19#include <algorithm>
20#include <cmath>
21#include <deque>
22#include <iostream>
23#include <set>
24#include <vector>
25
26namespace mars
27{
34class Buffer
35{
36public:
42
47 Buffer(const int& size);
48
53 void set_max_buffer_size(const int& size);
54
59 void set_keep_last_sensor_handle(const bool& value);
60
66
71
76 bool IsEmpty() const;
77
82 inline int get_length() const
83 {
84 return static_cast<int>(data_.size());
85 }
86
90 void PrintBufferEntries() const;
91
98
105
112
119
126
133 bool get_latest_sensor_handle_state(const std::shared_ptr<SensorAbsClass>& sensor_handle,
134 BufferEntryType* entry) const;
135
143 bool get_latest_sensor_handle_state(const std::shared_ptr<SensorAbsClass>& sensor_handle, BufferEntryType* entry,
144 int* index) const;
145
152 bool get_oldest_sensor_handle_state(const std::shared_ptr<SensorAbsClass>& sensor_handle,
153 BufferEntryType* entry) const;
154
161 bool get_latest_sensor_handle_measurement(const std::shared_ptr<SensorAbsClass>& sensor_handle,
162 BufferEntryType* entry) const;
163
171 bool get_sensor_handle_measurements(const std::shared_ptr<SensorAbsClass>& sensor_handle,
172 std::vector<const BufferEntryType*>* entries) const;
173
181 bool get_closest_state(const Time& timestamp, BufferEntryType* entry) const;
182 bool get_closest_state(const Time& timestamp, BufferEntryType* entry, int* index) const;
183
190 bool get_entry_at_idx(const int& index, BufferEntryType* entry) const;
191
197 bool RemoveSensorFromBuffer(const std::shared_ptr<SensorAbsClass>& sensor_handle);
198
208 int AddEntrySorted(const BufferEntryType& new_entry, const bool& after = true);
209
216 int FindClosestTimestamp(const Time& timestamp) const;
217
225 bool ClearStatesStartingAtIdx(const int& idx);
226
231 bool IsSorted() const;
232
238 bool OverwriteDataAtIndex(const BufferEntryType& new_entry, const int& index);
239
251 bool get_intermediate_entry_pair(const std::shared_ptr<SensorAbsClass>& sensor_handle, BufferEntryType* imu_state,
252 BufferEntryType* sensor_state) const;
253
259 bool CheckForLastSensorHandleWithState(const std::shared_ptr<SensorAbsClass>& sensor_handle) const;
260
265
266private:
270 std::deque<BufferEntryType> data_;
271
275 int max_buffer_size_{ 2000 };
276
282
283 bool verbose_{ false };
284};
285} // namespace mars
286
287#endif // BUFFER_H
Definition buffer_entry_type.h:41
BufferClass that holds mars::BufferEntryType elements and provides access methods.
Definition buffer.h:35
void set_keep_last_sensor_handle(const bool &value)
set_keep_last_sensor_handle
int get_max_buffer_size() const
get_max_buffer_size
bool get_latest_sensor_handle_measurement(const std::shared_ptr< SensorAbsClass > &sensor_handle, BufferEntryType *entry) const
get_latest_sensor_handle_measurement
int max_buffer_size_
defines the max size at wich the oldest entry is removed
Definition buffer.h:275
bool keep_last_sensor_handle_
If true, the last entry of a sensor state entry will be keept in the buffer.
Definition buffer.h:281
Buffer()
Buffer default constructor max buffer size is set to 400 by default.
bool get_latest_sensor_handle_state(const std::shared_ptr< SensorAbsClass > &sensor_handle, BufferEntryType *entry) const
get_latest_sensor_handle_state
bool get_latest_sensor_handle_state(const std::shared_ptr< SensorAbsClass > &sensor_handle, BufferEntryType *entry, int *index) const
get_latest_sensor_handle_state
bool RemoveSensorFromBuffer(const std::shared_ptr< SensorAbsClass > &sensor_handle)
RemoveSensorFromBuffer Removes all entrys that are associated with the given sensor handle.
int FindClosestTimestamp(const Time &timestamp) const
FindClosestTimestamp Returns the index of the entry which is the closest to the specified 'timestamp'...
bool get_intermediate_entry_pair(const std::shared_ptr< SensorAbsClass > &sensor_handle, BufferEntryType *imu_state, BufferEntryType *sensor_state) const
get_latest_interm_entrie Get last state pair of imu prop and sensor update
bool get_closest_state(const Time &timestamp, BufferEntryType *entry) const
get_closest_state
bool get_sensor_handle_measurements(const std::shared_ptr< SensorAbsClass > &sensor_handle, std::vector< const BufferEntryType * > *entries) const
get_sensor_handle_measurements
int RemoveOverflowEntrys()
RemoveOverflowEntrys Removes the oldest entries if max buffer size is reached.
bool get_latest_entry(BufferEntryType *entry) const
get_latest_entry Returns the last buffer entry
bool get_latest_state(BufferEntryType *entry) const
get_latest_state returns the most recent state entry
bool get_oldest_sensor_handle_state(const std::shared_ptr< SensorAbsClass > &sensor_handle, BufferEntryType *entry) const
get_oldest_sensor_handle_state
bool CheckForLastSensorHandleWithState(const std::shared_ptr< SensorAbsClass > &sensor_handle) const
CheckForLastSensorHandleWithState Checks if the given sensor handle only exists once in the buffer an...
bool IsSorted() const
Checks if all buffer entrys are correctly sorted by time.
Buffer(const int &size)
Buffer constructor.
bool get_entry_at_idx(const int &index, BufferEntryType *entry) const
get_entry_at_idx
bool get_oldest_core_state(BufferEntryType *entry) const
get_oldest_core_state Gets the oldest entry with metadata_ core_state
std::deque< BufferEntryType > data_
deque container that holds the buffer entries
Definition buffer.h:270
bool IsEmpty() const
IsEmpty.
bool OverwriteDataAtIndex(const BufferEntryType &new_entry, const int &index)
InsertDataAtIndex Adds 'entry' at buffer position 'index'.
int get_length() const
get_length
Definition buffer.h:82
void set_max_buffer_size(const int &size)
set_max_buffer_size
bool get_latest_init_state(BufferEntryType *entry) const
Gets the latest entry with init_state as metadata.
int AddEntrySorted(const BufferEntryType &new_entry, const bool &after=true)
AddEntrySorted Adds a new entry to the buffer and ensures the buffer is sorted.
void PrintBufferEntries() const
PrintBufferEntries prints all buffer entries in a formatted way.
bool verbose_
Increased cmd output.
Definition buffer.h:283
bool ClearStatesStartingAtIdx(const int &idx)
Deletes all states after, and including the given index This also deletes all auto generated states.
bool get_closest_state(const Time &timestamp, BufferEntryType *entry, int *index) const
void ResetBufferData()
Removes all entrys from the buffer.
bool get_oldest_state(BufferEntryType *entry) const
get_oldest_state Gets the oldest entry with metadata in the state group
Definition time.h:20
Definition buffer.h:27