NonRtTiming.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2017, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarX
19  * @author Mirko Waechter( mirko.waechter at kit dot edu)
20  * @date 2018
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 #include <time.h>
27 
28 #include <IceUtil/Time.h>
29 
30 #include "RtTiming.h"
31 
32 namespace armarx
33 {
34  inline IceUtil::Time
36  {
37  using namespace rt_timing::constants;
38 
39  struct timespec ts;
40  clock_gettime(CLOCK_REALTIME, &ts);
41  return IceUtil::Time::microSeconds(ts.tv_sec * seconds2MicroSeconds +
42  ts.tv_nsec / nanoSeconds2MicroSeconds);
43  }
44 
45  inline IceUtil::Time
47  {
48  // This is the "real time" clock, i.e. NTP-synchronized and relative to epoch.
49  IceUtil::Time now_real_time = armarx::nonRtNow();
50  // This is not relative to epoch and not NTP-synchronized.
51  IceUtil::Time now_monotonic_raw = armarx::rtNow();
52 
53  /*
54  * Assumption for small very small time deltas (i.e. "time" is close to "now"):
55  *
56  * time_real_time - now_real_time == time_monotic_raw - now_monotonic_raw
57  * =>
58  * time_real_time = time_monotic_raw - now_monotonic_raw + now_real_time
59  */
60  //
61  IceUtil::Time time_real_time = time_monotic_raw - now_monotonic_raw + now_real_time;
62  ARMARX_DEBUG << VAROUT(time_monotic_raw) << " vs. " << VAROUT(time_real_time);
63  return time_real_time;
64  }
65 
66 } // namespace armarx
armarx::nonRtNow
IceUtil::Time nonRtNow()
Definition: NonRtTiming.h:35
RtTiming.h
armarx::rt_timing::constants::seconds2MicroSeconds
constexpr const std::int64_t seconds2MicroSeconds
Definition: RtTiming.h:34
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:182
armarx::mapRtTimestampToNonRtTimestamp
IceUtil::Time mapRtTimestampToNonRtTimestamp(const IceUtil::Time &time_monotic_raw)
Definition: NonRtTiming.h:46
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::rtNow
IceUtil::Time rtNow()
Definition: RtTiming.h:40