approximate_time.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * fkie_message_filters
4  * Copyright © 2018-2020 Fraunhofer FKIE
5  * Author: Timo Röhling
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ****************************************************************************/
20 
21 #ifndef INCLUDE_FKIE_MESSAGE_FILTERS_COMBINER_POLICIES_APPROXIMATE_TIME_H_
22 #define INCLUDE_FKIE_MESSAGE_FILTERS_COMBINER_POLICIES_APPROXIMATE_TIME_H_
23 
24 #include "policy_base.h"
25 #include <deque>
26 #include <mutex>
27 #include <ros/duration.h>
28 
29 namespace fkie_message_filters
30 {
31 namespace combiner_policies
32 {
33 
81 template<typename... IOs>
82 class ApproximateTime : public PolicyBase<IOs...>
83 {
84 public:
85  template<template<typename...> class, class...> friend class fkie_message_filters::Combiner;
86  using typename PolicyBase<IOs...>::EmitterCB;
87  using typename PolicyBase<IOs...>::IncomingTuples;
88  using typename PolicyBase<IOs...>::OutgoingTuple;
105  ApproximateTime& set_max_age(const ros::Duration& max_age) noexcept;
113  ApproximateTime& set_max_queue_size (std::size_t queue_size, const boost::optional<ros::Duration>& max_age = boost::none) noexcept;
120  ApproximateTime& set_max_timespan (const ros::Duration& max_delta) noexcept;
133  ApproximateTime& set_min_distance(std::size_t i, const ros::Duration& min_dist) noexcept;
134 protected:
139  template<std::size_t N>
140  void add(std::unique_lock<std::mutex>&, const std::tuple_element_t<N, IncomingTuples>&);
141  void reset() noexcept override;
142 private:
143  static constexpr std::size_t NUM_SLOTS = sizeof...(IOs);
144  static constexpr std::size_t UNSET = NUM_SLOTS;
145  using typename PolicyBase<IOs...>::MaybeOutgoingTuples;
146  using IncomingQueues = std::tuple<std::deque<helpers::io_tuple_t<IOs>>...>;
147  template<std::size_t N>
148  void discard_expired_at(const ros::Time& cutoff) noexcept;
149  void discard_expired(const ros::Time& cutoff) noexcept;
150  template<std::size_t N>
151  void prune_queue_at(std::size_t queue_size) noexcept;
152  template<std::size_t N>
153  bool can_still_improve_at() noexcept;
154  bool can_still_improve() noexcept;
155  ros::Duration pivot_timedelta(const ros::Time& ts) noexcept;
156  ros::Duration heads_timespan() noexcept;
157  bool determine_pivot() noexcept;
158  void drop_pivot() noexcept;
159  void emit_heads(std::unique_lock<std::mutex>&);
160  boost::optional<ros::Duration> max_age_;
162  boost::optional<ros::Duration> max_delta_;
163  std::size_t pivot_;
164  ros::Time pivot_ts_;
165  std::array<ros::Duration, NUM_SLOTS> min_dist_;
167  MaybeOutgoingTuples heads_;
168 };
169 
170 } // namespace combiner_policies
171 } // namespace fkie_message_filters
172 
173 #include "approximate_time_impl.h"
174 
175 #endif /* INCLUDE_FKIE_MESSAGE_FILTERS_COMBINER_POLICIES_APPROXIMATE_TIME_H_ */
Base class for combiner policies.
Definition: policy_base.h:37
void discard_expired_at(const ros::Time &cutoff) noexcept
std::tuple< helpers::io_tuple_t< IOs >... > IncomingTuples
Tuple type of incoming data tuples.
Definition: policy_base.h:42
ApproximateTime & set_min_distance(std::size_t i, const ros::Duration &min_dist) noexcept
Set the minimum distance between consecutive messages on a source.
std::function< void(const OutgoingTuple &)> EmitterCB
Callback for assembled outputs.
Definition: policy_base.h:46
ApproximateTime & set_max_queue_size(std::size_t queue_size, const boost::optional< ros::Duration > &max_age=boost::none) noexcept
Set maximum queue size.
void add(std::unique_lock< std::mutex > &, const std::tuple_element_t< N, IncomingTuples > &)
Input function.
ApproximateTime & set_max_age(const ros::Duration &max_age) noexcept
Set maximum age of any data in the queue.
std::array< ros::Duration, NUM_SLOTS > min_dist_
ApproximateTime & set_max_timespan(const ros::Duration &max_delta) noexcept
Set maximum permissible timestamp difference of matched messages.
std::tuple< boost::optional< helpers::io_tuple_t< IOs > >... > MaybeOutgoingTuples
Tuple of outgoing tuple candidates.
Definition: policy_base.h:64
ros::Duration pivot_timedelta(const ros::Time &ts) noexcept
helpers::io_tuple_t< helpers::io_concat_t< IOs... > > OutgoingTuple
Combined tuple type for data output.
Definition: policy_base.h:44
void reset() noexcept override
Reset internal state.
Primary namespace.
Definition: buffer.h:33
std::tuple< std::deque< helpers::io_tuple_t< IOs > >... > IncomingQueues
typename io_tuple< IO >::type io_tuple_t
Definition: io.h:111
Combine multiple sources into a single one.
Definition: combiner.h:72


fkie_message_filters
Author(s): Timo Röhling
autogenerated on Sun Sep 12 2021 02:52:12