Robotics StackExchange | Archived questions

converting ros::time to boost ptime: "Year is out of valid range" error

Hi there, I am new to the ROS and its community. I am looking for a function that can convert the ROS time to the boost::posix_time::ptime. Does anybody know about such function? I found an answer here, https://answers.ros.org/question/251966/conversion-from-ros-timestamp-to-iso-8601-time-format/" which is close to what I am looking for. However, when I use this .toBoost() function, an exception is thrown, " Year is out of valid range: 1400..100000". Also, I couldn't find the function .toBoost() in ros:Time class reference.

If anybody knows about such function then please let me know. Any suggestions/remarks are most welcomed! [edit 1] : example: ROS timestamp(1520004209.448167176) to boost time --> results into the error.

Thank you very much,

Asked by Toothless on 2018-03-26 04:50:29 UTC

Comments

" Year is out of valid range: 1400..100000"

that would seem to suggest something is wrong with your timestamps. Can you add some examples of stamps you try to convert to your question text? Use the edit button/link.

Asked by gvdhoorn on 2018-03-26 05:17:46 UTC

I've updated your question title, as there is a known conversion (#q251966) but you're encountering errors trying to use it. That would seem to be the real problem here.

Asked by gvdhoorn on 2018-03-26 05:27:19 UTC

The code is here. If you duplicate that and see what is being passed to the boost::posix_time::ptime::from_time_t(..) and nanoseconds(..) function?

Asked by gvdhoorn on 2018-03-26 06:38:09 UTC

Thank you gvdhoorn for the link. It is very useful.

Asked by Toothless on 2018-03-29 01:51:16 UTC

Have you figured out what's going wrong with your conversion?

Asked by gvdhoorn on 2018-03-29 01:52:53 UTC

In the code, a random string was passed to this function which might be the reason for this error. However, I didn't test it as I removed the need of this conversion from the code base.

Asked by Toothless on 2018-03-29 01:57:47 UTC

Answers