time.h
Go to the documentation of this file.
1 #include "sick_scan/sick_scan_base.h" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2010, Willow Garage, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Willow Garage, Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
35 
36 #ifndef ROS_TIME_H_INCLUDED
37 #define ROS_TIME_H_INCLUDED
38 
39 /*********************************************************************
40  ** Pragmas
41  *********************************************************************/
42 
43 #ifdef _MSC_VER
44  // Rostime has some magic interface that doesn't directly include
45  // its implementation, this just disables those warnings.
46  #pragma warning(disable: 4244)
47  #pragma warning(disable: 4661)
48 #endif
49 
50 /*********************************************************************
51  ** Headers
52  *********************************************************************/
53 
54 #include <ros/platform.h>
55 #include <iostream>
56 #include <cmath>
57 #include <ros/exception.h>
58 #include "duration.h"
59 //#include <boost/math/special_functions/round.hpp>
60 #include "rostime_decl.h"
61 
62 /*********************************************************************
63  ** Cross Platform Headers
64  *********************************************************************/
65 
66 #ifdef WIN32
67  #include <sys/timeb.h>
68 #else
69  #include <sys/time.h>
70 #endif
71 
72 namespace boost {
73  namespace posix_time {
74  class ptime;
75  class time_duration;
76  }
77 }
78 
79 namespace roswrap
80 {
81 
82  /*********************************************************************
83  ** Exceptions
84  *********************************************************************/
85 
90  {
91  public:
93  : Exception("Cannot use ros::Time::now() before the first NodeHandle has been created or ros::start() has been called. "
94  "If this is a standalone app or test that just uses ros::Time and does not communicate over ROS, you may also call ros::Time::init()")
95  {}
96  };
97 
104  {
105  public:
107  : Exception("This windows platform does not "
108  "support the high-performance timing api.")
109  {}
110  };
111 
112  /*********************************************************************
113  ** Functions
114  *********************************************************************/
115 
116  ROSTIME_DECL void normalizeSecNSec(uint64_t& sec, uint64_t& nsec);
117  ROSTIME_DECL void normalizeSecNSec(uint32_t& sec, uint32_t& nsec);
118  ROSTIME_DECL void normalizeSecNSecUnsigned(int64_t& sec, int64_t& nsec);
119 
120  /*********************************************************************
121  ** Time Classes
122  *********************************************************************/
123 
128  template<class T, class D>
129  class TimeBase
130  {
131  public:
132  uint32_t sec, nsec;
133 
134  TimeBase() : sec(0), nsec(0) { }
135  TimeBase(uint32_t _sec, uint32_t _nsec) : sec(_sec), nsec(_nsec)
136  {
138  }
139  explicit TimeBase(double t) { fromSec(t); }
140  ~TimeBase() {}
141  D operator-(const T &rhs) const;
142  T operator+(const D &rhs) const;
143  T operator-(const D &rhs) const;
144  T& operator+=(const D &rhs);
145  T& operator-=(const D &rhs);
146  bool operator==(const T &rhs) const;
147  inline bool operator!=(const T &rhs) const { return !(*static_cast<const T*>(this) == rhs); }
148  bool operator>(const T &rhs) const;
149  bool operator<(const T &rhs) const;
150  bool operator>=(const T &rhs) const;
151  bool operator<=(const T &rhs) const;
152 
153  double toSec() const { return (double)sec + 1e-9*(double)nsec; };
154  T& fromSec(double t) {
155  sec = (uint32_t)floor(t);
156  nsec = (uint32_t)std::round((t-sec) * 1e9);
157  // avoid rounding errors
158  sec += (nsec / 1000000000ul);
159  nsec %= 1000000000ul;
160  return *static_cast<T*>(this);
161  }
162 
163  uint64_t toNSec() const {return (uint64_t)sec*1000000000ull + (uint64_t)nsec; }
164  T& fromNSec(uint64_t t);
165 
166  inline bool isZero() const { return sec == 0 && nsec == 0; }
167  inline bool is_zero() const { return isZero(); }
168  //boost::posix_time::ptime toBoost() const;
169 
170  };
171 
177  class ROSTIME_DECL Time : public TimeBase<Time, Duration>
178  {
179  public:
181  : TimeBase<Time, Duration>()
182  {}
183 
184  Time(uint32_t _sec, uint32_t _nsec)
185  : TimeBase<Time, Duration>(_sec, _nsec)
186  {}
187 
188  explicit Time(double t) { fromSec(t); }
189 
194  static Time now();
199  static bool sleepUntil(const Time& end);
200 
201  static void init();
202  static void shutdown();
203  static void setNow(const Time& new_now);
204  static bool useSystemTime();
205  static bool isSimTime();
206  static bool isSystemTime();
207 
211  static bool isValid();
215  static bool waitForValid();
219  static bool waitForValid(const ros::WallDuration& timeout);
220 
221  //static Time fromBoost(const boost::posix_time::ptime& t);
222  //static Time fromBoost(const boost::posix_time::time_duration& d);
223  };
224 
225  extern ROSTIME_DECL const Time TIME_MAX;
226  extern ROSTIME_DECL const Time TIME_MIN;
227 
233  class ROSTIME_DECL WallTime : public TimeBase<WallTime, WallDuration>
234  {
235  public:
238  {}
239 
240  WallTime(uint32_t _sec, uint32_t _nsec)
241  : TimeBase<WallTime, WallDuration>(_sec, _nsec)
242  {}
243 
244  explicit WallTime(double t) { fromSec(t); }
245 
249  static WallTime now();
250 
255  static bool sleepUntil(const WallTime& end);
256 
257  static bool isSystemTime() { return true; }
258  };
259 
260  ROSTIME_DECL std::ostream &operator <<(std::ostream &os, const Time &rhs);
261  ROSTIME_DECL std::ostream &operator <<(std::ostream &os, const WallTime &rhs);
262 }
263 
264 #endif // ROS_TIME_H
265 
roswrap::TimeBase::toSec
double toSec() const
Definition: time.h:155
roswrap::Exception
Base class for all exceptions thrown by ROS.
Definition: exception.h:40
roswrap::Time::Time
Time(double t)
Definition: time.h:188
roswrap::TimeBase::operator>=
bool operator>=(const T &rhs) const
Definition: impl/time.h:157
roswrap::WallTime
Time representation. Always wall-clock time.
Definition: time.h:233
roswrap::Time
Time representation. May either represent wall clock time or ROS clock time.
Definition: time.h:177
roswrap::TimeBase::operator<
bool operator<(const T &rhs) const
Definition: impl/time.h:127
roswrap::TimeBase::isZero
bool isZero() const
Definition: time.h:168
roswrap::WallTime::isSystemTime
static bool isSystemTime()
Definition: time.h:257
roswrap::TimeBase::nsec
uint32_t nsec
Definition: time.h:134
roswrap::NoHighPerformanceTimersException::NoHighPerformanceTimersException
NoHighPerformanceTimersException()
Definition: time.h:106
roswrap::TimeBase::toNSec
uint64_t toNSec() const
Definition: time.h:165
roswrap::Time::Time
Time()
Definition: time.h:180
roswrap::operator<<
std::ostream & operator<<(std::ostream &os, const Time &rhs)
Definition: time_modi.cpp:394
roswrap::shutdown
ROSCPP_DECL void shutdown()
Disconnects everything and unregisters from the master. It is generally not necessary to call this fu...
Definition: rossimu.cpp:269
roswrap::NoHighPerformanceTimersException
Thrown if windoze high perf. timestamping is unavailable.
Definition: time.h:103
roswrap::TIME_MIN
const Time TIME_MIN(0, 1)
Definition: time.h:226
roswrap::normalizeSecNSecUnsigned
void normalizeSecNSecUnsigned(int64_t &sec, int64_t &nsec)
Definition: time_modi.cpp:594
boost
roswrap::TimeBase::operator+
T operator+(const D &rhs) const
Definition: impl/time.h:94
roswrap::TimeBase::~TimeBase
~TimeBase()
Definition: time.h:142
roswrap::TimeBase
Base class for Time implementations. Provides storage, common functions and operator overloads....
Definition: time.h:129
roswrap::WallTime::WallTime
WallTime()
Definition: time.h:236
roswrap::TIME_MAX
const ROSTIME_DECL Time TIME_MAX
ROS::now
ROS::Time now(void)
Definition: ros_wrapper.cpp:116
roswrap::TimeBase::operator==
bool operator==(const T &rhs) const
Definition: impl/time.h:121
nsec
uint32_t nsec(const rosTime &time)
Definition: sick_ros_wrapper.h:175
roswrap::WallTime::WallTime
WallTime(double t)
Definition: time.h:244
roswrap::TimeBase::operator+=
T & operator+=(const D &rhs)
Definition: impl/time.h:107
roswrap::Duration
Duration representation for use with the Time class.
Definition: duration.h:109
roswrap::TimeBase::operator<=
bool operator<=(const T &rhs) const
Definition: impl/time.h:147
duration.h
roswrap::TimeBase::fromNSec
T & fromNSec(uint64_t t)
Definition: impl/time.h:67
roswrap::TimeBase::operator>
bool operator>(const T &rhs) const
Definition: impl/time.h:137
roswrap
Definition: param_modi.cpp:41
roswrap::TimeBase::operator!=
bool operator!=(const T &rhs) const
Definition: time.h:149
roswrap::WallDuration
Duration representation for use with the WallTime class.
Definition: duration.h:137
sec
uint32_t sec(const rosTime &time)
Definition: sick_ros_wrapper.h:174
roswrap::TimeBase::operator-
D operator-(const T &rhs) const
Definition: impl/time.h:81
Time
Definition: Time.hpp:51
roswrap::TimeBase::is_zero
bool is_zero() const
Definition: time.h:169
sick_scan_base.h
sick_generic_device_finder.timeout
timeout
Definition: sick_generic_device_finder.py:113
roswrap::WallTime::WallTime
WallTime(uint32_t _sec, uint32_t _nsec)
Definition: time.h:240
roswrap::normalizeSecNSec
void normalizeSecNSec(uint64_t &sec, uint64_t &nsec)
Definition: time_modi.cpp:571
roswrap::TimeBase::TimeBase
TimeBase()
Definition: time.h:136
roswrap::TimeBase::sec
uint32_t sec
Definition: time.h:134
ros::WallDuration
roswrap::TimeBase::fromSec
T & fromSec(double t)
Definition: time.h:156
roswrap::TimeNotInitializedException
Thrown if the ros subsystem hasn't been initialised before use.
Definition: time.h:89
roswrap::Time::Time
Time(uint32_t _sec, uint32_t _nsec)
Definition: time.h:184
ROSTIME_DECL
#define ROSTIME_DECL
Definition: rostime_decl.h:53
roswrap::TimeBase::operator-=
T & operator-=(const D &rhs)
Definition: impl/time.h:114
t
geometry_msgs::TransformStamped t
roswrap::init
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROS initialization function.
rostime_decl.h


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:12