Skip to content

Commit 4e7542f

Browse files
jmirabelOlivier Stasse
authored andcommitted
Avoid overflow in ros::Duration
* This was trigerring an exception "Duration is out of dual 32-bit * range"
1 parent 86cfdc7 commit 4e7542f

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/ros_publish.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ namespace dynamicgraph
143143
sotNOSIGNAL,
144144
MAKE_SIGNAL_STRING(name, true, "int", "trigger")),
145145
rate_ (ROS_JOINT_STATE_PUBLISHER_RATE),
146-
lastPublicated_ ()
146+
nextPublication_ ()
147147
{
148148

149149
try {
150-
lastPublicated_ = ros::Time::now ();
150+
nextPublication_ = ros::Time::now ();
151151
} catch (const std::exception& exc) {
152152
throw std::runtime_error ("Failed to call ros::Time::now ():" +
153153
std::string (exc.what ()));
@@ -220,7 +220,6 @@ namespace dynamicgraph
220220
}
221221

222222
//lock the mutex to avoid deleting the signal during a call to trigger
223-
while(! mutex_.try_lock() ){}
224223
signalDeregistration(signal);
225224
bindedSignal_.erase (signal);
226225
mutex_.unlock();
@@ -258,11 +257,10 @@ namespace dynamicgraph
258257
{
259258
typedef std::map<std::string, bindedSignal_t>::iterator iterator_t;
260259

261-
ros::Duration dt = ros::Time::now () - lastPublicated_;
262-
if (dt < rate_)
260+
if (ros::Time::now() <= nextPublication_)
263261
return dummy;
264262

265-
lastPublicated_ = ros::Time::now();
263+
nextPublication_ = ros::Time::now() + rate_;
266264

267265
while(! mutex_.try_lock() ){}
268266
for (iterator_t it = bindedSignal_.begin ();

src/ros_publish.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ namespace dynamicgraph
9393
std::map<std::string, bindedSignal_t> bindedSignal_;
9494
dynamicgraph::SignalTimeDependent<int,int> trigger_;
9595
ros::Duration rate_;
96-
ros::Time lastPublicated_;
96+
ros::Time nextPublication_;
9797
boost::interprocess::interprocess_mutex mutex_;
9898
};
9999
} // end of namespace dynamicgraph.

0 commit comments

Comments
 (0)