74 int index =
static_cast<int>(name.find_last_of(
'/'));
76 node_name_ = name.substr(index + 1) +
"_subscriber";
78 node_name_ = name +
"_subscriber";
82 std::function<void(
const ConstPtr&)> register_call =
84 msg_subscriber_ = node_->CreateReader<T>(channel, register_call);
86 std::lock_guard<std::mutex> lock(buffer_mutex_);
87 buffer_queue_.set_capacity(FLAGS_obs_msg_buffer_size);
100 std::lock_guard<std::mutex> lock(buffer_mutex_);
102 AERROR <<
"msg buffer is uninitialized.";
105 if (buffer_queue_.empty()) {
106 AERROR <<
"msg buffer is empty.";
109 if (buffer_queue_.front().first - FLAGS_obs_buffer_match_precision >
111 AERROR <<
"Your timestamp (" << timestamp
112 <<
") is earlier than the oldest timestamp ("
113 << buffer_queue_.front().first <<
").";
116 if (buffer_queue_.back().first + FLAGS_obs_buffer_match_precision <
118 AERROR <<
"Your timestamp (" << timestamp
119 <<
") is newer than the latest timestamp ("
120 << buffer_queue_.back().first <<
").";
125 double distance = std::numeric_limits<double>::max();
126 int idx =
static_cast<int>(buffer_queue_.size()) - 1;
127 for (; idx >= 0; --idx) {
128 double temp_distance = fabs(timestamp - buffer_queue_[idx].first);
129 if (temp_distance >= distance) {
132 distance = temp_distance;
134 *msg = buffer_queue_[idx + 1].second;
156 std::vector<ObjectPair>* msgs) {
157 std::lock_guard<std::mutex> lock(buffer_mutex_);
159 AERROR <<
"Message buffer is uninitialized.";
162 if (buffer_queue_.empty()) {
163 AERROR <<
"Message buffer is empty.";
166 if (buffer_queue_.front().first - FLAGS_obs_buffer_match_precision >
168 AERROR <<
"Your timestamp (" << timestamp <<
") is earlier than the oldest "
169 <<
"timestamp (" << buffer_queue_.front().first <<
").";
172 if (buffer_queue_.back().first + FLAGS_obs_buffer_match_precision <
174 AERROR <<
"Your timestamp (" << timestamp <<
") is newer than the latest "
175 <<
"timestamp (" << buffer_queue_.back().first <<
").";
179 const double lower_timestamp = timestamp - period;
180 const double upper_timestamp = timestamp + period;
181 for (
const auto& obj_pair : buffer_queue_) {
182 if (obj_pair.first < lower_timestamp) {
185 if (obj_pair.first > upper_timestamp) {
188 msgs->push_back(obj_pair);