timestamp_outlier_remover.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 The urg_stamped Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef TIMESTAMP_OUTLIER_REMOVER_H
18 #define TIMESTAMP_OUTLIER_REMOVER_H
19 
20 #include <ros/ros.h>
21 
22 #include <cmath>
23 
25 {
26 protected:
30  size_t outlier_cnt_;
31 
32 public:
34  const ros::Duration &diff_max,
35  const ros::Duration &interval)
36  : diff_max_(diff_max)
37  , interval_(interval)
38  , outlier_cnt_(0)
39  {
40  }
41  void setInterval(const ros::Duration &interval)
42  {
43  interval_ = interval;
44  }
45  ros::Time update(const ros::Time &stamp)
46  {
47  if (stamp_ == ros::Time())
48  stamp_ = stamp - interval_;
49 
50  const auto interval = stamp - stamp_;
51  const int scan_num = lround(interval.toSec() / interval_.toSec());
52  const double interval_remainder = remainder(interval.toSec(), interval_.toSec());
53 
54  if (fabs(interval_remainder) > diff_max_.toSec())
55  {
56  stamp_ += interval_ * scan_num;
57  if (outlier_cnt_ >= 1)
58  stamp_ = stamp;
59 
60  outlier_cnt_++;
61  }
62  else
63  {
64  stamp_ = stamp;
65  outlier_cnt_ = 0;
66  }
67 
68  return stamp_;
69  }
70  void reset()
71  {
72  stamp_ = ros::Time();
73  }
74 };
75 
76 #endif // TIMESTAMP_OUTLIER_REMOVER_H
TimestampOutlierRemover(const ros::Duration &diff_max, const ros::Duration &interval)
ros::Time update(const ros::Time &stamp)
void setInterval(const ros::Duration &interval)


urg_stamped
Author(s): Atsushi Watanabe
autogenerated on Thu Jun 6 2019 19:55:59