Skip to content
Snippets Groups Projects
Commit 4e7542fe authored by Joseph Mirabel's avatar Joseph Mirabel Committed by olivier stasse
Browse files

Avoid overflow in ros::Duration

* This was trigerring an exception "Duration is out of dual 32-bit
* range"
parent 86cfdc71
No related branches found
No related tags found
No related merge requests found
......@@ -143,11 +143,11 @@ namespace dynamicgraph
sotNOSIGNAL,
MAKE_SIGNAL_STRING(name, true, "int", "trigger")),
rate_ (ROS_JOINT_STATE_PUBLISHER_RATE),
lastPublicated_ ()
nextPublication_ ()
{
try {
lastPublicated_ = ros::Time::now ();
nextPublication_ = ros::Time::now ();
} catch (const std::exception& exc) {
throw std::runtime_error ("Failed to call ros::Time::now ():" +
std::string (exc.what ()));
......@@ -220,7 +220,6 @@ namespace dynamicgraph
}
//lock the mutex to avoid deleting the signal during a call to trigger
while(! mutex_.try_lock() ){}
signalDeregistration(signal);
bindedSignal_.erase (signal);
mutex_.unlock();
......@@ -258,11 +257,10 @@ namespace dynamicgraph
{
typedef std::map<std::string, bindedSignal_t>::iterator iterator_t;
ros::Duration dt = ros::Time::now () - lastPublicated_;
if (dt < rate_)
if (ros::Time::now() <= nextPublication_)
return dummy;
lastPublicated_ = ros::Time::now();
nextPublication_ = ros::Time::now() + rate_;
while(! mutex_.try_lock() ){}
for (iterator_t it = bindedSignal_.begin ();
......
......@@ -93,7 +93,7 @@ namespace dynamicgraph
std::map<std::string, bindedSignal_t> bindedSignal_;
dynamicgraph::SignalTimeDependent<int,int> trigger_;
ros::Duration rate_;
ros::Time lastPublicated_;
ros::Time nextPublication_;
boost::interprocess::interprocess_mutex mutex_;
};
} // end of namespace dynamicgraph.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment