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 ...@@ -143,11 +143,11 @@ namespace dynamicgraph
sotNOSIGNAL, sotNOSIGNAL,
MAKE_SIGNAL_STRING(name, true, "int", "trigger")), MAKE_SIGNAL_STRING(name, true, "int", "trigger")),
rate_ (ROS_JOINT_STATE_PUBLISHER_RATE), rate_ (ROS_JOINT_STATE_PUBLISHER_RATE),
lastPublicated_ () nextPublication_ ()
{ {
try { try {
lastPublicated_ = ros::Time::now (); nextPublication_ = ros::Time::now ();
} catch (const std::exception& exc) { } catch (const std::exception& exc) {
throw std::runtime_error ("Failed to call ros::Time::now ():" + throw std::runtime_error ("Failed to call ros::Time::now ():" +
std::string (exc.what ())); std::string (exc.what ()));
...@@ -220,7 +220,6 @@ namespace dynamicgraph ...@@ -220,7 +220,6 @@ namespace dynamicgraph
} }
//lock the mutex to avoid deleting the signal during a call to trigger //lock the mutex to avoid deleting the signal during a call to trigger
while(! mutex_.try_lock() ){}
signalDeregistration(signal); signalDeregistration(signal);
bindedSignal_.erase (signal); bindedSignal_.erase (signal);
mutex_.unlock(); mutex_.unlock();
...@@ -258,11 +257,10 @@ namespace dynamicgraph ...@@ -258,11 +257,10 @@ namespace dynamicgraph
{ {
typedef std::map<std::string, bindedSignal_t>::iterator iterator_t; typedef std::map<std::string, bindedSignal_t>::iterator iterator_t;
ros::Duration dt = ros::Time::now () - lastPublicated_; if (ros::Time::now() <= nextPublication_)
if (dt < rate_)
return dummy; return dummy;
lastPublicated_ = ros::Time::now(); nextPublication_ = ros::Time::now() + rate_;
while(! mutex_.try_lock() ){} while(! mutex_.try_lock() ){}
for (iterator_t it = bindedSignal_.begin (); for (iterator_t it = bindedSignal_.begin ();
......
...@@ -93,7 +93,7 @@ namespace dynamicgraph ...@@ -93,7 +93,7 @@ namespace dynamicgraph
std::map<std::string, bindedSignal_t> bindedSignal_; std::map<std::string, bindedSignal_t> bindedSignal_;
dynamicgraph::SignalTimeDependent<int,int> trigger_; dynamicgraph::SignalTimeDependent<int,int> trigger_;
ros::Duration rate_; ros::Duration rate_;
ros::Time lastPublicated_; ros::Time nextPublication_;
boost::interprocess::interprocess_mutex mutex_; boost::interprocess::interprocess_mutex mutex_;
}; };
} // end of namespace dynamicgraph. } // 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