Skip to content

Commit 5dd7ad1

Browse files
authored
feat(controller-server): publish_zero_velocity parameter (#4675)
* feat(controller-server): `publish_zero_velocity` parameter For optionally publishing a zero velocity command reference on goal exit. Publishing a zero velocity is not desired when we are following consecutive path segments that end with a velocity. Signed-off-by: Rein Appeldoorn <rein.appeldoorn@nobleo.nl> * processed comments Signed-off-by: Rein Appeldoorn <rein.appeldoorn@nobleo.nl> * comments Steve Signed-off-by: Rein Appeldoorn <rein.appeldoorn@nobleo.nl> --------- Signed-off-by: Rein Appeldoorn <rein.appeldoorn@nobleo.nl>
1 parent d4c3faa commit 5dd7ad1

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

‎nav2_controller/include/nav2_controller/controller_server.hpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ class ControllerServer : public nav2_util::LifecycleNode
176176
* @brief Calls velocity publisher to publish zero velocity
177177
*/
178178
void publishZeroVelocity();
179+
/**
180+
* @brief Called on goal exit
181+
*/
182+
void onGoalExit();
179183
/**
180184
* @brief Checks if goal is reached
181185
* @return true or false
@@ -267,6 +271,7 @@ class ControllerServer : public nav2_util::LifecycleNode
267271

268272
double failure_tolerance_;
269273
bool use_realtime_priority_;
274+
bool publish_zero_velocity_;
270275
rclcpp::Duration costmap_update_timeout_;
271276

272277
// Whether we've published the single controller warning yet

‎nav2_controller/src/controller_server.cpp‎

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)