ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Convert Time Stamp from rosbag(Topic) to Understandable Format Y/M/D H:M:S

asked 2021-10-14 10:22:15 -0500

Vini71 gravatar image

updated 2021-10-14 15:09:16 -0500

Hi someone would you know what the following TimeStamp means? and how to convert it to seconds or other understable format such year/month/day Hour:Minutes:Seconds?

I have a car-robot that has driven 80 meters in about 1 min of simulation. However when I recorded the rosbag I had the: First Timestamp =1,63277521885359E+018 and the Last TimeStamp from this topic (odom) = 1,63277529735619E+018

I do not know to convert this data to an understandable format such as Y/M/D H:M:S Some tool makes the trick? Or some Python Library such as DateTime (how to specific use, suitable class to apply?)

I have done some research herehttps://discourse.ros.org/t/times... But these steps seem too complex http://wiki.ros.org/rosbag/Cookbook

In addition, I got another column in my rosbag called field.header.sec that intuitively should return the seconds. But assessing this data again. The first/end data are:

T0 = 7348 TF = 8036

Subtracting these values I have 688 seconds = 11 minutes. And this is Not realistic because I have killed the simulation and the rosbag after 2 minutes( max) and the car in the simulation achieved the goal after 1 min, not 11 minutes.... I wonder how to understand and convert the TimeStamp extracted from rosbags. If someone could help me, I would be very grateful

Beginning of csv file (localizer or odom topic)

https://aws1.discourse-cdn.com/busine...

End of csv file

https://aws1.discourse-cdn.com/busine...

edit retag flag offensive close merge delete

Comments

Did you cross-post this to ROS Discourse here?

gvdhoorn gravatar image gvdhoorn  ( 2021-10-14 13:12:15 -0500 )edit

yes sorry I am trying to get as much ideas as possible to help on this issue.

Vini71 gravatar image Vini71  ( 2021-10-14 14:37:20 -0500 )edit

That's not how it works, and is actually pretty annoying. At best it leads to duplicated answers. In most cases it leads to wasted effort.

And it's not such a special problem. The Q&As I've linked in my answer already discuss this, and they're years old.

gvdhoorn gravatar image gvdhoorn  ( 2021-10-14 14:47:46 -0500 )edit

Ok....I respect your point of view...because actually there are different channels, different experts that will visualize...so..., I think different..but ok.

Could you take a look at my own answer below, please? I am trying to figure out what is wrong with the code.

Vini71 gravatar image Vini71  ( 2021-10-14 14:52:13 -0500 )edit

It's not just my point of view: https://en.wikipedia.org/wiki/Crosspo...

gvdhoorn gravatar image gvdhoorn  ( 2021-10-14 15:04:04 -0500 )edit

Hummm ok I got the idea @gvdhoorn, I have tooken a quick read...so much rules to be aware...not easy. But thanks to share these rules to me. I will try to follow all of them. Additionally let me ask you, I have edited the question on ROS Discourse, and instead put the whole question as here I have just put this link of ROS Answers for other ROS users visualize. Would this be the right manner or not? I mean if I wish that some question be visualized by different communities...which is the right way?? And thanks again for your answer!! It saved my time!

Vini71 gravatar image Vini71  ( 2021-10-14 15:15:14 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2021-10-14 13:07:11 -0500

gvdhoorn gravatar image

updated 2021-10-14 15:09:52 -0500

I have a car-robot that has driven 80 meters in about 1 min of simulation. However when I recorded the rosbag I had the: First Timestamp =1,63277521885359E+018 and the Last TimeStamp from this topic (odom) = 1,63277529735619E+018

I do not know to convert this data to an understandable format such as Y/M/D H:M:S Some tool makes the trick?

Afaik, this is just a Unix Epoch stamp. See #q273953 or #q296045 for instance.

If you run rosbag info /path/to/your.bag, it should show you something like this (from here):

start:       Jun 17 2010 14:24:58.83 (1276809898.83)
end:         Jun 17 2010 14:25:00.01 (1276809900.01)

note the number in brackets: that's the Unix Epoch stamp. The 'human readable' version is printed before it.

In addition, I got another column in my rosbag called field.header.sec that intuitively should return the seconds.

field.header.seq is not a timestamp. Is the sequence ID field. That's just a message counter.

Refer to std_msgs/Header:

# sequence ID: consecutively increasing ID 
uint32 seq

Edit:

but for the data I have, that is

unix_epoch_timestamp_t0 Out[29]: 1632775218853592670

and unix_epoch_timestamp_tf Out[30]: 1632775297356186066

1632775218853592670 is not a valid Unix Epoch stamp. Or at least, not for the functions you are using, as they will expect a resolution of seconds. Note the warning epochconverter.com gives you:

Assuming that this timestamp is in nanoseconds

You're likely concatenating the seconds and the nanoseconds from the std_msgs/Header colums in your .csv as strings, and then trying to interpret that as a single number. That doesn't work.

You can probably pass time.localtime(..) a float, in the form of seconds.nanoseconds:

>>> time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime(1632775297.356186066))
'Mon, 27 Sep 2021 22:41:37 +0000'

Note that your format string doesn't allow for showing the nanosecond precision of the stamp, and Python renders this in my local timezone (UTC+2). I'm also not sure hard-coding a +0000 for the time-zone is a good idea.

edit flag offensive delete link more
0

answered 2021-10-14 15:10:42 -0500

Vini71 gravatar image

updated 2021-10-14 15:19:10 -0500

Hi @gvdhoorn you are right! Thanks very much

I have found the solution with Python to process this data:

import datetime 
import pandas as pd
import time
import numpy as np

df = pd.read_csv(r'op_localizer_pose.csv')

print("Original csv: \n")
print(df)
time_stamp_array = df["%time"]
print(time_stamp_array)

epoch = 40246871
unix_epoch_timestamp_t0 = time_stamp_array[0]
unix_epoch_timestamp_tf = time_stamp_array.iloc[-1]


#time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime(epoch))
example = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(epoch))
print("Exanple feasible", example)

T_Initial = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(unix_epoch_timestamp_t0/1e9))
print("Initial time trip", T_Initial)

T_Final = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(unix_epoch_timestamp_tf/1e9))
print("Initial time trip", T_Final)
edit flag offensive delete link more

Comments

I'm not exactly sure why you keep posting updates as answers.

My edit contains exactly the same solution?

gvdhoorn gravatar image gvdhoorn  ( 2021-10-14 15:12:20 -0500 )edit

Actually my update is regarding the exact code that converts the data...the other links you provided is a good start point, more generic I would say, but does not solve the entire problem. With the code above from my own answer any user can get the code, compile and get the solution...it is pretty good to help beginners :)

Vini71 gravatar image Vini71  ( 2021-10-14 15:23:57 -0500 )edit

@gvdhoorn sorry I have not seen your edit before...yes your edit is the solution...how can I vote to it as correct answer? I am not seeing the checkbox anymore to accept your answers

Vini71 gravatar image Vini71  ( 2021-10-14 15:32:56 -0500 )edit

I think it's because you directly closed it instead of using the checkbox at the left to mark it as answered. I've unclosed it and marked @gvdhoorn's answer as the correct one. Closing the question is more for if we need to lock it down due to spamming etc.

tfoote gravatar image tfoote  ( 2021-10-14 16:45:17 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2021-10-14 10:22:15 -0500

Seen: 2,609 times

Last updated: Oct 14 '21