@@ -64,6 +64,7 @@ ControllerServer::ControllerServer(const rclcpp::NodeOptions & options)
6464
6565 declare_parameter (" failure_tolerance" , rclcpp::ParameterValue (0.0 ));
6666 declare_parameter (" use_realtime_priority" , rclcpp::ParameterValue (false ));
67+ declare_parameter (" publish_zero_velocity" , rclcpp::ParameterValue (true ));
6768 declare_parameter (" costmap_update_timeout" , 0.30 ); // 300ms
6869
6970 // The costmap node is used in the implementation of the controller
@@ -130,6 +131,7 @@ ControllerServer::on_configure(const rclcpp_lifecycle::State & /*state*/)
130131 get_parameter (" speed_limit_topic" , speed_limit_topic);
131132 get_parameter (" failure_tolerance" , failure_tolerance_);
132133 get_parameter (" use_realtime_priority" , use_realtime_priority_);
134+ get_parameter (" publish_zero_velocity" , publish_zero_velocity_);
133135
134136 costmap_ros_->configure ();
135137 // Launch a thread to run the costmap node
@@ -476,7 +478,7 @@ void ControllerServer::computeControl()
476478 if (controllers_[current_controller_]->cancel ()) {
477479 RCLCPP_INFO (get_logger (), " Cancellation was successful. Stopping the robot." );
478480 action_server_->terminate_all ();
479- publishZeroVelocity ();
481+ onGoalExit ();
480482 return ;
481483 } else {
482484 RCLCPP_INFO_THROTTLE (
@@ -513,63 +515,63 @@ void ControllerServer::computeControl()
513515 }
514516 } catch (nav2_core::InvalidController & e) {
515517 RCLCPP_ERROR (this ->get_logger (), " %s" , e.what ());
516- publishZeroVelocity ();
518+ onGoalExit ();
517519 std::shared_ptr<Action::Result> result = std::make_shared<Action::Result>();
518520 result->error_code = Action::Result::INVALID_CONTROLLER;
519521 action_server_->terminate_current (result);
520522 return ;
521523 } catch (nav2_core::ControllerTFError & e) {
522524 RCLCPP_ERROR (this ->get_logger (), " %s" , e.what ());
523- publishZeroVelocity ();
525+ onGoalExit ();
524526 std::shared_ptr<Action::Result> result = std::make_shared<Action::Result>();
525527 result->error_code = Action::Result::TF_ERROR;
526528 action_server_->terminate_current (result);
527529 return ;
528530 } catch (nav2_core::NoValidControl & e) {
529531 RCLCPP_ERROR (this ->get_logger (), " %s" , e.what ());
530- publishZeroVelocity ();
532+ onGoalExit ();
531533 std::shared_ptr<Action::Result> result = std::make_shared<Action::Result>();
532534 result->error_code = Action::Result::NO_VALID_CONTROL;
533535 action_server_->terminate_current (result);
534536 return ;
535537 } catch (nav2_core::FailedToMakeProgress & e) {
536538 RCLCPP_ERROR (this ->get_logger (), " %s" , e.what ());
537- publishZeroVelocity ();
539+ onGoalExit ();
538540 std::shared_ptr<Action::Result> result = std::make_shared<Action::Result>();
539541 result->error_code = Action::Result::FAILED_TO_MAKE_PROGRESS;
540542 action_server_->terminate_current (result);
541543 return ;
542544 } catch (nav2_core::PatienceExceeded & e) {
543545 RCLCPP_ERROR (this ->get_logger (), " %s" , e.what ());
544- publishZeroVelocity ();
546+ onGoalExit ();
545547 std::shared_ptr<Action::Result> result = std::make_shared<Action::Result>();
546548 result->error_code = Action::Result::PATIENCE_EXCEEDED;
547549 action_server_->terminate_current (result);
548550 return ;
549551 } catch (nav2_core::InvalidPath & e) {
550552 RCLCPP_ERROR (this ->get_logger (), " %s" , e.what ());
551- publishZeroVelocity ();
553+ onGoalExit ();
552554 std::shared_ptr<Action::Result> result = std::make_shared<Action::Result>();
553555 result->error_code = Action::Result::INVALID_PATH;
554556 action_server_->terminate_current (result);
555557 return ;
556558 } catch (nav2_core::ControllerTimedOut & e) {
557559 RCLCPP_ERROR (this ->get_logger (), " %s" , e.what ());
558- publishZeroVelocity ();
560+ onGoalExit ();
559561 std::shared_ptr<Action::Result> result = std::make_shared<Action::Result>();
560562 result->error_code = Action::Result::CONTROLLER_TIMED_OUT;
561563 action_server_->terminate_current (result);
562564 return ;
563565 } catch (nav2_core::ControllerException & e) {
564566 RCLCPP_ERROR (this ->get_logger (), " %s" , e.what ());
565- publishZeroVelocity ();
567+ onGoalExit ();
566568 std::shared_ptr<Action::Result> result = std::make_shared<Action::Result>();
567569 result->error_code = Action::Result::UNKNOWN;
568570 action_server_->terminate_current (result);
569571 return ;
570572 } catch (std::exception & e) {
571573 RCLCPP_ERROR (this ->get_logger (), " %s" , e.what ());
572- publishZeroVelocity ();
574+ onGoalExit ();
573575 std::shared_ptr<Action::Result> result = std::make_shared<Action::Result>();
574576 result->error_code = Action::Result::UNKNOWN;
575577 action_server_->terminate_current (result);
@@ -578,7 +580,7 @@ void ControllerServer::computeControl()
578580
579581 RCLCPP_DEBUG (get_logger (), " Controller succeeded, setting result" );
580582
581- publishZeroVelocity ();
583+ onGoalExit ();
582584
583585 // TODO(orduno) #861 Handle a pending preemption and set controller name
584586 action_server_->succeeded_current ();
@@ -746,6 +748,13 @@ void ControllerServer::publishZeroVelocity()
746748 velocity.header .frame_id = costmap_ros_->getBaseFrameID ();
747749 velocity.header .stamp = now ();
748750 publishVelocity (velocity);
751+ }
752+
753+ void ControllerServer::onGoalExit ()
754+ {
755+ if (publish_zero_velocity_) {
756+ publishZeroVelocity ();
757+ }
749758
750759 // Reset the state of the controllers after the task has ended
751760 ControllerMap::iterator it;
0 commit comments