ros melodic library with custom message
Dependents: Robot_team1_QEI_Douglas Robot_team1
Diff: ros_lib/ros/duration.h
- Revision:
- 1:afa33e06a2ca
- Parent:
- 0:020db18a476d
diff -r 020db18a476d -r afa33e06a2ca ros_lib/ros/duration.h --- a/ros_lib/ros/duration.h Wed Oct 30 14:59:49 2019 +0000 +++ b/ros_lib/ros/duration.h Tue Nov 12 13:54:52 2019 +0000 @@ -38,36 +38,29 @@ #include <math.h> #include <stdint.h> -namespace ros -{ - -void normalizeSecNSecSigned(int32_t& sec, int32_t& nsec); +namespace ros { -class Duration -{ -public: - int32_t sec, nsec; + void normalizeSecNSecSigned(int32_t& sec, int32_t& nsec); - Duration() : sec(0), nsec(0) {} - Duration(int32_t _sec, int32_t _nsec) : sec(_sec), nsec(_nsec) + class Duration { - normalizeSecNSecSigned(sec, nsec); - } + public: + int32_t sec, nsec; - double toSec() const - { - return (double)sec + 1e-9 * (double)nsec; + Duration() : sec(0), nsec(0) {} + Duration(int32_t _sec, int32_t _nsec) : sec(_sec), nsec(_nsec) + { + normalizeSecNSecSigned(sec, nsec); + } + + double round(double number) { return number < 0.0 ? ceil(number - 0.5): floor(number + 0.5); } + double toSec() const { return (double)sec + 1e-9*(double)nsec; }; + void fromSec(double t) { sec = (uint32_t) floor(t); nsec = (uint32_t) round((t-sec) * 1e9); }; + + Duration& operator+=(const Duration &rhs); + Duration& operator-=(const Duration &rhs); + Duration& operator*=(double scale); }; - void fromSec(double t) - { - sec = (uint32_t) floor(t); - nsec = (uint32_t) round((t - sec) * 1e9); - }; - - Duration& operator+=(const Duration &rhs); - Duration& operator-=(const Duration &rhs); - Duration& operator*=(double scale); -}; }