Robotics Library  0.7.0
chrono.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009, Markus Rickert
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 // POSSIBILITY OF SUCH DAMAGE.
25 //
26 
27 #ifndef RL_UTIL_RTAI_CHRONO_H
28 #define RL_UTIL_RTAI_CHRONO_H
29 
30 #include <chrono>
31 #include <rtai_lxrt.h>
32 
33 namespace rl
34 {
35  namespace util
36  {
37  namespace rtai
38  {
39  namespace chrono
40  {
41  struct steady_clock
42  {
43  typedef ::std::chrono::nanoseconds duration;
44 
45  typedef duration::period period;
46 
47  typedef duration::rep rep;
48 
49  typedef ::std::chrono::time_point<steady_clock, duration> time_point;
50 
51  static constexpr bool is_monotonic = true;
52 
53  static constexpr bool is_steady = true;
54 
55  static time_point now()
56  {
57  return time_point(duration(::rt_get_cpu_time_ns()));
58  }
59  };
60 
61  struct system_clock
62  {
63  typedef ::std::chrono::nanoseconds duration;
64 
65  typedef duration::period period;
66 
67  typedef duration::rep rep;
68 
69  typedef ::std::chrono::time_point<system_clock, duration> time_point;
70 
71  static constexpr bool is_monotonic = false;
72 
73  static constexpr bool is_steady = false;
74 
75  static time_point now()
76  {
77  return time_point(duration(::rt_get_real_time_ns()));
78  }
79 
80  static ::std::time_t to_time_t(const time_point& t)
81  {
82  return ::std::time_t(
83  ::std::chrono::duration_cast< ::std::chrono::seconds>(
84  t.time_since_epoch()
85  ).count()
86  );
87  }
88 
89  static time_point from_time_t(std::time_t t)
90  {
91  return ::std::chrono::time_point_cast<system_clock::duration>(
92  ::std::chrono::time_point<system_clock, ::std::chrono::seconds>(
93  ::std::chrono::seconds(t)
94  )
95  );
96  }
97  };
98  }
99  }
100  }
101 }
102 
103 #endif // RL_UTIL_RTAI_CHRONO_H
rl::util::rtai::chrono::system_clock::now
static time_point now()
Definition: chrono.h:75
rl::util::rtai::chrono::system_clock::period
duration::period period
Definition: chrono.h:65
rl::util::rtai::chrono::system_clock::is_steady
static constexpr bool is_steady
Definition: chrono.h:73
rl::util::rtai::chrono::system_clock::duration
::std::chrono::nanoseconds duration
Definition: chrono.h:63
rl::util::rtai::chrono::system_clock::is_monotonic
static constexpr bool is_monotonic
Definition: chrono.h:71
rl::util::rtai::chrono::system_clock::rep
duration::rep rep
Definition: chrono.h:67
rl::util::rtai::chrono::steady_clock::rep
duration::rep rep
Definition: chrono.h:47
rl::util::rtai::chrono::steady_clock::now
static time_point now()
Definition: chrono.h:55
rl::util::rtai::chrono::steady_clock
Definition: chrono.h:42
rl::util::rtai::chrono::system_clock::to_time_t
::std::time_t to_time_t(const time_point &t)
Definition: chrono.h:80
rl::util::rtai::chrono::system_clock
Definition: chrono.h:62
rl::util::rtai::chrono::steady_clock::is_monotonic
static constexpr bool is_monotonic
Definition: chrono.h:51
rl::util::rtai::chrono::system_clock::from_time_t
static time_point from_time_t(std::time_t t)
Definition: chrono.h:89
rl::util::rtai::chrono::steady_clock::duration
::std::chrono::nanoseconds duration
Definition: chrono.h:43
rl::util::rtai::chrono::steady_clock::is_steady
static constexpr bool is_steady
Definition: chrono.h:53
rl::util::rtai::chrono::system_clock::time_point
::std::chrono::time_point< system_clock, duration > time_point
Definition: chrono.h:69
rl::util::rtai::chrono::steady_clock::period
duration::period period
Definition: chrono.h:45
rl::util::rtai::chrono::steady_clock::time_point
::std::chrono::time_point< steady_clock, duration > time_point
Definition: chrono.h:49
rl
Robotics Library.
Definition: AnalogInput.cpp:30