@@ -157,10 +157,7 @@ namespace dynamicgraph
157
157
nextPublication_ = ros::Time::now ();
158
158
else
159
159
{
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_);
164
161
}
165
162
} catch (const std::exception & exc) {
166
163
throw std::runtime_error (" Failed to call ros::Time::now ():" +
@@ -274,41 +271,27 @@ namespace dynamicgraph
274
271
275
272
typedef std::map<std::string, bindedSignal_t>::iterator iterator_t ;
276
273
ros::Time aTime;
277
- struct timeval aTimeRT;
278
274
if (ros::Time::isSimTime ())
279
275
{
280
276
aTime= ros::Time::now ();
281
- dgRTLOG () << " nextPublication_:"
282
- << " " << nextPublication_.sec
283
- << " " << nextPublication_.nsec
284
- << " " << ros::Time::isValid ()
285
- << " " << ros::Time::isSimTime ();
286
-
287
277
if (aTime <= nextPublication_)
288
278
return dummy;
289
279
290
280
nextPublication_ = aTime + rate_;
291
281
}
292
282
else
293
283
{
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);
302
286
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 )
305
289
{
306
- nextPublicationRT_.tv_usec -= 1000000 ;
290
+ nextPublicationRT_.tv_nsec -= 1000000000 ;
307
291
nextPublicationRT_.tv_sec +=1 ;
308
292
}
309
293
}
310
294
311
- // dgRTLOG() << "after nextPublication_" << std::endl;
312
295
boost::mutex::scoped_lock lock (mutex_);
313
296
314
297
for (iterator_t it = bindedSignal_.begin ();
0 commit comments