@@ -157,10 +157,7 @@ namespace dynamicgraph
157157 nextPublication_ = ros::Time::now ();
158158 else
159159 {
160- struct timeval timeofday;
161- gettimeofday (&timeofday,NULL );
162- nextPublicationRT_.tv_sec = timeofday.tv_sec ;
163- nextPublicationRT_.tv_usec = timeofday.tv_usec ;
160+ clock_gettime (CLOCK_REALTIME,&nextPublicationRT_);
164161 }
165162 } catch (const std::exception& exc) {
166163 throw std::runtime_error (" Failed to call ros::Time::now ():" +
@@ -274,41 +271,27 @@ namespace dynamicgraph
274271
275272 typedef std::map<std::string, bindedSignal_t>::iterator iterator_t ;
276273 ros::Time aTime;
277- struct timeval aTimeRT;
278274 if (ros::Time::isSimTime ())
279275 {
280276 aTime= ros::Time::now ();
281- dgRTLOG () << " nextPublication_:"
282- << " " << nextPublication_.sec
283- << " " << nextPublication_.nsec
284- << " " << ros::Time::isValid ()
285- << " " << ros::Time::isSimTime ();
286-
287277 if (aTime <= nextPublication_)
288278 return dummy;
289279
290280 nextPublication_ = aTime + rate_;
291281 }
292282 else
293283 {
294- struct timeval aTimeRT;
295- gettimeofday (&aTimeRT,NULL );
296- // dgRTLOG() << "nextPublicationRT_:"
297- // << " " << nextPublicationRT_.tv_sec
298- // << " " << nextPublicationRT_.tv_usec
299- // << " " << ros::Time::isValid()
300- // << " " << ros::Time::isSimTime()
301- // << std::endl;
284+ struct timespec aTimeRT;
285+ clock_gettime (CLOCK_REALTIME,&aTimeRT);
302286 nextPublicationRT_.tv_sec = aTimeRT.tv_sec + rate_.sec ;
303- nextPublicationRT_.tv_usec = aTimeRT.tv_usec + rate_.nsec / 1000 ;
304- if (nextPublicationRT_.tv_usec > 1000000 )
287+ nextPublicationRT_.tv_nsec = aTimeRT.tv_nsec + rate_.nsec ;
288+ if (nextPublicationRT_.tv_nsec > 1000000000 )
305289 {
306- nextPublicationRT_.tv_usec -= 1000000 ;
290+ nextPublicationRT_.tv_nsec -= 1000000000 ;
307291 nextPublicationRT_.tv_sec +=1 ;
308292 }
309293 }
310294
311- // dgRTLOG() << "after nextPublication_" << std::endl;
312295 boost::mutex::scoped_lock lock (mutex_);
313296
314297 for (iterator_t it = bindedSignal_.begin ();
0 commit comments