timestamp_outlier_remover.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018-2021 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 URG_STAMPED_TIMESTAMP_OUTLIER_REMOVER_H
18 #define URG_STAMPED_TIMESTAMP_OUTLIER_REMOVER_H
19 
20 #include <ros/ros.h>
21 
22 #include <cmath>
23 
24 namespace urg_stamped
25 {
27 {
28 protected:
32  size_t outlier_cnt_;
33 
34 public:
36  const ros::Duration& diff_max,
37  const ros::Duration& interval)
38  : diff_max_(diff_max)
39  , interval_(interval)
40  , outlier_cnt_(0)
41  {
42  }
43  void setInterval(const ros::Duration& interval)
44  {
45  interval_ = interval;
46  }
47  ros::Time update(const ros::Time& stamp)
48  {
49  if (stamp_ == ros::Time())
50  stamp_ = stamp - interval_;
51 
52  const auto interval = stamp - stamp_;
53  const int scan_num = lround(interval.toSec() / interval_.toSec());
54  const double interval_remainder = remainder(interval.toSec(), interval_.toSec());
55 
56  if (fabs(interval_remainder) > diff_max_.toSec())
57  {
58  stamp_ += interval_ * scan_num;
59  if (outlier_cnt_ >= 1)
60  stamp_ = stamp;
61 
62  outlier_cnt_++;
63  }
64  else
65  {
66  stamp_ = stamp;
67  outlier_cnt_ = 0;
68  }
69 
70  return stamp_;
71  }
72  void reset()
73  {
74  stamp_ = ros::Time();
75  }
76 };
77 } // namespace urg_stamped
78 
79 #endif // URG_STAMPED_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 Tue May 11 2021 02:14:05