test_device_time_origin.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020-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 #include <gtest/gtest.h>
18 
19 #include <string>
20 
21 #include <boost/date_time/posix_time/posix_time_types.hpp>
22 
24 
25 namespace urg_stamped
26 {
27 TEST(DeviceTimeOriginTest, testEstimateOriginByAverage)
28 {
29  const boost::posix_time::time_duration delay = boost::posix_time::milliseconds(1);
30  const boost::posix_time::ptime time_req = boost::posix_time::microsec_clock::universal_time();
31  const boost::posix_time::ptime time_res = time_req + delay;
32  const uint64_t device_timestamp = 12345 * 1e3; // msec
33 
35  time_req, time_res, device_timestamp);
36  const ros::Time expected = ros::Time::fromBoost(
37  time_req - boost::posix_time::milliseconds(device_timestamp) + delay / 2);
38 
39  ASSERT_EQ(actual, expected);
40 }
41 
42 TEST(DeviceTimeOriginTest, testEstimateOrigin)
43 {
44  const boost::posix_time::time_duration delay = boost::posix_time::milliseconds(1);
45  const boost::posix_time::ptime time_req = boost::posix_time::microsec_clock::universal_time();
46  const boost::posix_time::ptime time_res = time_req + delay;
47  const uint64_t device_timestamp = 12345 * 1e3; // msec
48 
49  ros::Time time_at_device_timestamp;
51  time_res, device_timestamp, ros::Duration(ros::Time::fromBoost(delay).toSec()), time_at_device_timestamp);
52  const ros::Time expected = ros::Time::fromBoost(
53  time_req - boost::posix_time::milliseconds(device_timestamp) + delay / 2);
54 
55  ASSERT_EQ(time_at_device_timestamp, ros::Time::fromBoost(time_req + delay / 2));
56  ASSERT_EQ(actual, expected);
57 }
58 
59 TEST(DeviceTimeOriginTest, testDetectTimeJump)
60 {
61  const ros::Time last_origin = ros::Time(100000);
62 
63  ASSERT_FALSE(
64  device_time_origin::jump_detector::detectTimeJump(last_origin, last_origin + ros::Duration(1.00), 1.0));
65  ASSERT_TRUE(
66  device_time_origin::jump_detector::detectTimeJump(last_origin, last_origin + ros::Duration(1.01), 1.0));
67 
68  const ros::Time last_origin_not_init = ros::Time(0);
69 
70  ASSERT_FALSE(
72  last_origin_not_init, last_origin_not_init + ros::Duration(1.01), 1.0));
73 }
74 } // namespace urg_stamped
75 
76 int main(int argc, char** argv)
77 {
78  testing::InitGoogleTest(&argc, argv);
79 
80  return RUN_ALL_TESTS();
81 }
TEST(DeviceTimeOriginTest, testEstimateOriginByAverage)
ros::Time estimateOriginByAverage(const boost::posix_time::ptime &time_request, const boost::posix_time::ptime &time_response, const uint64_t &device_timestamp)
bool detectTimeJump(const ros::Time &last_device_time_origin, const ros::Time &current_device_time_origin, const double allowed_device_time_origin_diff)
int main(int argc, char **argv)
ros::Time estimateOrigin(const boost::posix_time::ptime &time_response, const uint64_t &device_timestamp, const ros::Duration &communication_delay, ros::Time &time_at_device_timestamp)
static Time fromBoost(const boost::posix_time::ptime &t)


urg_stamped
Author(s): Atsushi Watanabe
autogenerated on Tue May 11 2021 02:14:05