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

Forside
Vedhæftede filer:
Indlæg som e-mail
+ (text/plain)
Slet denne besked
Besvar denne besked
Skribent: User discussions
Dato:  
Til: ros-users
Emne: Re: [ros-users] ros::time to boost::posix_time::ptime
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
}