Ask Your Question
0

Integer to Ros::time

asked 2016-04-21 03:13:30 -0500

Bert gravatar image

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 flag offensive close merge delete

Comments

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

dornhege gravatar image dornhege  ( 2016-04-21 05:08:24 -0500 )edit

What do you mean?

Bert gravatar image Bert  ( 2016-04-21 06:38:20 -0500 )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.

dornhege gravatar image dornhege  ( 2016-04-21 09:12:49 -0500 )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.

Martin Günther gravatar image Martin Günther  ( 2016-04-21 09:24:17 -0500 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2016-04-21 04:34:29 -0500

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.

edit flag offensive delete link more

Comments

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);
r7vme gravatar image r7vme  ( 2019-03-08 01:57:40 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-04-21 03:13:30 -0500

Seen: 1,780 times

Last updated: Apr 21 '16