duration.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_DURATION_H_
19 #define _ROS_DURATION_H_
20 
21 #include <math.h>
22 #include <stdint.h>
23 
24 namespace ros {
25 
26  void normalizeSecNSecSigned(int32_t& sec, int32_t& nsec);
27 
28  class Duration
29  {
30  public:
31  int32_t sec, nsec;
32 
33  Duration() : sec(0), nsec(0) {}
34  Duration(int32_t _sec, int32_t _nsec) : sec(_sec), nsec(_nsec)
35  {
36  normalizeSecNSecSigned(sec, nsec);
37  }
38 
39  double toSec() const { return (double)sec + 1e-9*(double)nsec; };
40  void fromSec(double t) { sec = (uint32_t) floor(t); nsec = (uint32_t) round((t-sec) * 1e9); };
41 
42  Duration& operator+=(const Duration &rhs);
43  Duration& operator-=(const Duration &rhs);
44  Duration& operator*=(double scale);
45  };
46 
47 }
48 
49 #endif
50 
ROSTIME_DECL void normalizeSecNSecSigned(int64_t &sec, int64_t &nsec)


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