time.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
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 
18 #ifndef ROS_TIME_H_
19 #define ROS_TIME_H_
20 
21 #include <math.h>
22 #include <stdint.h>
23 
24 #include "ros/duration.h"
25 
26 namespace ros
27 {
28  void normalizeSecNSec(uint32_t &sec, uint32_t &nsec);
29 
30  class Time
31  {
32  public:
33  uint32_t sec, nsec;
34 
35  Time() : sec(0), nsec(0) {}
36  Time(uint32_t _sec, uint32_t _nsec) : sec(_sec), nsec(_nsec)
37  {
38  normalizeSecNSec(sec, nsec);
39  }
40 
41  double toSec() const { return (double)sec + 1e-9*(double)nsec; };
42  void fromSec(double t) { sec = (uint32_t) floor(t); nsec = (uint32_t) round((t-sec) * 1e9); };
43 
44  uint32_t toNsec() { return (uint32_t)sec*1000000000ull + (uint32_t)nsec; };
45  Time& fromNSec(int32_t t);
46 
47  Time& operator +=(const Duration &rhs);
48  Time& operator -=(const Duration &rhs);
49 
50  static Time now();
51  static void setNow( Time & new_now);
52  };
53 
54 }
55 
56 #endif
static void setNow(const Time &new_now)
ROSTIME_DECL void normalizeSecNSec(uint32_t &sec, uint32_t &nsec)
Definition: time.cpp:22
static Time now()


cob_hand_bridge
Author(s): Mathias Lüdtke
autogenerated on Tue Oct 20 2020 03:35:57