[ros-users] ros::time to boost::posix_time::ptime

Markus Bader markus.bader at tuwien.ac.at
Tue Jan 24 09:04:05 UTC 2012


Hi

Thanks to Lorenz and William for the quick answer
It would be nice to enhance the code for a back conversion back to
ros::Time who is in charge for that?
The downside would be that the resolution will be reduced if boost
time is compiled for six fraction digits (mirosec).

void fromBoost ( const boost::posix_time::ptime &src, ros::Time &des ) const {
    boost::posix_time::time_duration diff = src -
boost::posix_time::from_time_t(0);
    des.sec = diff.total_seconds();
#if defined(BOOST_DATE_TIME_HAS_NANOSECONDS)
    des.nsec = diff.fractional_seconds();
#else
    #warning boost time uses only microseconds nanoseconds are lost
    des.nsec = diff.fractional_seconds()*1000;
#endif
}



More information about the ros-users mailing list