@@ -103,6 +103,12 @@ WindowedOptimizer::WindowedOptimizer(
103103 ros::names::resolve (params_->reset_service ),
104104 &WindowedOptimizer::resetServiceCallback,
105105 this );
106+
107+ // Subscribe to a reset message that will reset the optimizer to the initial state
108+ reset_subscriber_ = node_handle_.subscribe (
109+ ros::names::resolve (params_->reset_service ), 10 ,
110+ &WindowedOptimizer::resetMessageCallback,
111+ this );
106112}
107113
108114WindowedOptimizer::~WindowedOptimizer ()
@@ -416,6 +422,40 @@ void WindowedOptimizer::processQueue(fuse_core::Transaction& transaction)
416422 }
417423}
418424
425+ void WindowedOptimizer::resetMessageCallback (const std_msgs::Empty::ConstPtr&){
426+ // Tell all the plugins to stop
427+ stopPlugins ();
428+ // Reset the optimizer state
429+ {
430+ std::lock_guard<std::mutex> lock (optimization_requested_mutex_);
431+ optimization_request_ = false ;
432+ }
433+ started_ = false ;
434+ ignited_ = false ;
435+ setStartTime (ros::Time (0 , 0 ));
436+ // DANGER: The optimizationLoop() function obtains the lock optimization_mutex_ lock and the
437+ // pending_transactions_mutex_ lock at the same time. We perform a parallel locking scheme here to
438+ // prevent the possibility of deadlocks.
439+ {
440+ std::lock_guard<std::mutex> lock (optimization_mutex_);
441+ // Clear all pending transactions
442+ {
443+ std::lock_guard<std::mutex> lock (pending_transactions_mutex_);
444+ pending_transactions_.clear ();
445+ }
446+ // Clear the graph and marginal tracking states
447+ graph_->clear ();
448+ marginal_transaction_ = fuse_core::Transaction ();
449+ }
450+ // Perform any required reset operations for derived classes
451+ onReset ();
452+ // Tell all the plugins to start
453+ startPlugins ();
454+ // Test for auto-start
455+ autostart ();
456+ return ;
457+ }
458+
419459bool WindowedOptimizer::resetServiceCallback (std_srvs::Empty::Request&, std_srvs::Empty::Response&)
420460{
421461 // Tell all the plugins to stop
0 commit comments