Main Page
Namespaces
Classes
Files
File List
File Members
include
urg_stamped
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
{
26
class
TimestampOutlierRemover
27
{
28
protected
:
29
ros::Time
stamp_
;
30
ros::Duration
diff_max_
;
31
ros::Duration
interval_
;
32
size_t
outlier_cnt_
;
33
34
public
:
35
TimestampOutlierRemover
(
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
DurationBase< Duration >::toSec
double toSec() const
urg_stamped::TimestampOutlierRemover
Definition:
timestamp_outlier_remover.h:26
ros::Time
urg_stamped::TimestampOutlierRemover::diff_max_
ros::Duration diff_max_
Definition:
timestamp_outlier_remover.h:30
urg_stamped::TimestampOutlierRemover::TimestampOutlierRemover
TimestampOutlierRemover(const ros::Duration &diff_max, const ros::Duration &interval)
Definition:
timestamp_outlier_remover.h:35
urg_stamped::TimestampOutlierRemover::update
ros::Time update(const ros::Time &stamp)
Definition:
timestamp_outlier_remover.h:47
urg_stamped::TimestampOutlierRemover::reset
void reset()
Definition:
timestamp_outlier_remover.h:72
ros.h
urg_stamped
Definition:
device_time_origin.h:24
ros::Duration
urg_stamped::TimestampOutlierRemover::outlier_cnt_
size_t outlier_cnt_
Definition:
timestamp_outlier_remover.h:32
urg_stamped::TimestampOutlierRemover::stamp_
ros::Time stamp_
Definition:
timestamp_outlier_remover.h:29
urg_stamped::TimestampOutlierRemover::setInterval
void setInterval(const ros::Duration &interval)
Definition:
timestamp_outlier_remover.h:43
urg_stamped::TimestampOutlierRemover::interval_
ros::Duration interval_
Definition:
timestamp_outlier_remover.h:31
urg_stamped
Author(s): Atsushi Watanabe
autogenerated on Tue May 11 2021 02:14:05