TimeStamp: from Scalar to unsigned long int?
I have been thinking in this apparently silly issue.
Now we have a TimeStamp
class based on a Scalar
, thus, a double
.
Time stamps contain the seconds passed since 1970-01-01 midnight, now is something like 1535984912.645843518
.
In ROS, TimeStamps are encoded by two unsigned int
, one for seconds and the other for nanoseconds. I think maybe a unsigned long int
encoding nanoseconds would be enough (until year 3330).
I think we should move to that implementation for two reasons:
- Compatibility: Now, when casting to
Scalar
a rounding to the double representation is performed changing a little. Then, comparing with ROS timestamps is not possible (getNanoSeconds()
does not return the same value as initialized). This simple test does not work:
unsigned long int sec = 5;
unsigned long int nano = 1e5;
wolf::TimeStamp t(sec,nano);
ASSERT_EQ(t.getSeconds(),sec);
ASSERT_EQ(t.getNanoSeconds(),nano);
- Equally check: Comparing two doubles with
operator==
is unrecommended (current implementation), however, we know that it may be useful (the sameTimeStamp
). - Enough precision: We won't require more than nanoseconds precision, and
Scalar
hasn't a constant precision. Actually, since the seconds are a quite large number, I really don't know which precision do we have.
@jsola ,@asantamaria,@artivis are you ok with this change? Is there any reason to keep with the Scalar
? Obviously, the API will remain unchanged.
Edited by Joan Vallvé Navarro