ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
I believe there is a mistake here:
printf("ros time is : %u\n", ros::Time::now().toSec());
From the API documentation for double ros::TimeBase<..>::toSec() const, we see it returns a double
.
You are trying to print it as an unsigned int
(%u
), which is not the same type.
If you change the format specifier to %f
instead, it should start printing values you are expecting.
2 | No.2 Revision |
I believe there is a mistake here:
printf("ros time is : %u\n", ros::Time::now().toSec());
From the API documentation for double ros::TimeBase<..>::toSec() const, we see it returns a double
.
You are trying to print it as an Unsigned decimal integer (unsigned int
%u
, see here), which is not the same type.type. So the bytes that constitute the double
returned by toSec()
are being interpreted as an integer
by printf(..)
.
This would seem to be the cause of the strange values (2917579440
interpreted as a Unix epoch is Thursday, June 15, 2062 6:44:00 AM
).
If you change the format specifier to %f
instead, it should start printing values you are expecting.
3 | No.3 Revision |
I believe there is a mistake here:
printf("ros time is : %u\n", ros::Time::now().toSec());
From the API documentation for double ros::TimeBase<..>::toSec() const, we see it returns a double
.
You are trying to print it as an Unsigned decimal integer (%u
, see here), which is not the same type. So the bytes that constitute the double
returned by toSec()
are being interpreted as an integer
by printf(..)
.
The compiler helps here:
warning: format '%u' expects argument of type 'unsigned int', but argument 2 has type 'double'
This would seem to be the cause of the strange values (2917579440
interpreted as a Unix epoch is Thursday, June 15, 2062 6:44:00 AM
).
If you change the format specifier to %f
instead, it should start printing values you are expecting.
Edit:
According to your opinion, I have modified the code but the ros time has not changed
Please show the full code and what it outputs. And also tell us how you start things.
As-is, your code sample doesn't compile (ros::init(..)
takes at least one additional argument), and is also missing a ros::NodeHandle
.
Without a ros::NodeHandle
, I get:
terminate called after throwing an instance of 'ros::TimeNotInitializedException' what(): Cannot use ros::Time::now() before the first NodeHandle has been created or ros::start() has been called. 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()