ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org

# Integer to Ros::time

Hi!

I have a txt file with encoderdata and timestamps. I am reading from this file and want to put this timestamps in variables declared as Ros::time, but I cant manage to get this right. Is it possible to do this? The timestamp is coming from a msg like this.

ros::Time current_time_encoder;
current_time_encoder = msg->angle_timestamp1;

edit retag close merge delete

The essential question here is: What does the int mean?

( 2016-04-21 05:08:24 -0600 )edit

What do you mean?

( 2016-04-21 06:38:20 -0600 )edit
1

What does a time stamp of "5" mean for you? You'll have to convert this correctly. Check @Martin Günther s answer for reasonable guesses.

( 2016-04-21 09:12:49 -0600 )edit

Right. I (perhaps incorrectly) assumed that it's seconds/milliseconds/... since 1970-01-01 00:00. If not, you need to add/subtract an offset.

( 2016-04-21 09:24:17 -0600 )edit

Sort by » oldest newest most voted

So msg->angle_timestamp1 is an int, right?

If it's time in seconds (which is not a good idea, because the resolution is way too coarse), this should work:

ros::Time current_time_encoder(msg->angle_timestamp1);


If it's nanoseconds, this works:

ros::Time current_time_encoder(msg->angle_timestamp1 / 1e9, msg->angle_timestamp1 % 1e9);


Similarly 1e6 for microseconds, 1e3 for milliseconds.

more

thanks! small correction: e.g. for milliseconds we also need to multiply by 1e6.

  int nsecs = (msg->angle_timestamp1 % 1000) * 1000 * 1000;
int secs = msg->angle_timestamp1 / 1000;
ros::Time state_timestamp(secs, nsecs);

( 2019-03-08 01:57:40 -0600 )edit