Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle transition failures in all servers (#4708) #26

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion nav2_behaviors/src/behavior_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ BehaviorServer::~BehaviorServer()
}

nav2_util::CallbackReturn
BehaviorServer::on_configure(const rclcpp_lifecycle::State & /*state*/)
BehaviorServer::on_configure(const rclcpp_lifecycle::State & state)
{
RCLCPP_INFO(get_logger(), "Configuring");

Expand All @@ -92,6 +92,7 @@ BehaviorServer::on_configure(const rclcpp_lifecycle::State & /*state*/)

behavior_types_.resize(behavior_ids_.size());
if (!loadBehaviorPlugins()) {
on_cleanup(state);
return nav2_util::CallbackReturn::FAILURE;
}

Expand Down
6 changes: 4 additions & 2 deletions nav2_bt_navigator/src/bt_navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ BtNavigator::~BtNavigator()
}

nav2_util::CallbackReturn
BtNavigator::on_configure(const rclcpp_lifecycle::State & /*state*/)
BtNavigator::on_configure(const rclcpp_lifecycle::State & state)
{
RCLCPP_INFO(get_logger(), "Configuring");

Expand Down Expand Up @@ -170,6 +170,7 @@ BtNavigator::on_configure(const rclcpp_lifecycle::State & /*state*/)
get_logger(), "Failed to create navigator id %s of type %s."
" Exception: %s", navigator_ids[i].c_str(), navigator_type.c_str(),
ex.what());
on_cleanup(state);
return nav2_util::CallbackReturn::FAILURE;
}
}
Expand All @@ -183,11 +184,12 @@ BtNavigator::on_configure(const rclcpp_lifecycle::State & /*state*/)
}

nav2_util::CallbackReturn
BtNavigator::on_activate(const rclcpp_lifecycle::State & /*state*/)
BtNavigator::on_activate(const rclcpp_lifecycle::State & state)
{
RCLCPP_INFO(get_logger(), "Activating");
for (size_t i = 0; i != navigators_.size(); i++) {
if (!navigators_[i]->on_activate()) {
on_deactivate(state);
return nav2_util::CallbackReturn::FAILURE;
}
}
Expand Down
3 changes: 2 additions & 1 deletion nav2_collision_monitor/src/collision_detector_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CollisionDetector::~CollisionDetector()
}

nav2_util::CallbackReturn
CollisionDetector::on_configure(const rclcpp_lifecycle::State & /*state*/)
CollisionDetector::on_configure(const rclcpp_lifecycle::State & state)
{
RCLCPP_INFO(get_logger(), "Configuring");

Expand All @@ -57,6 +57,7 @@ CollisionDetector::on_configure(const rclcpp_lifecycle::State & /*state*/)

// Obtaining ROS parameters
if (!getParameters()) {
on_cleanup(state);
return nav2_util::CallbackReturn::FAILURE;
}

Expand Down
3 changes: 2 additions & 1 deletion nav2_collision_monitor/src/collision_monitor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ CollisionMonitor::~CollisionMonitor()
}

nav2_util::CallbackReturn
CollisionMonitor::on_configure(const rclcpp_lifecycle::State & /*state*/)
CollisionMonitor::on_configure(const rclcpp_lifecycle::State & state)
{
RCLCPP_INFO(get_logger(), "Configuring");

Expand All @@ -58,6 +58,7 @@ CollisionMonitor::on_configure(const rclcpp_lifecycle::State & /*state*/)

// Obtaining ROS parameters
if (!getParameters(cmd_vel_in_topic, cmd_vel_out_topic)) {
on_cleanup(state);
return nav2_util::CallbackReturn::FAILURE;
}

Expand Down
4 changes: 3 additions & 1 deletion nav2_controller/src/controller_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ControllerServer::~ControllerServer()
}

nav2_util::CallbackReturn
ControllerServer::on_configure(const rclcpp_lifecycle::State & /*state*/)
ControllerServer::on_configure(const rclcpp_lifecycle::State & state)
{
RCLCPP_INFO(get_logger(), "Configuring controller interface");

Expand Down Expand Up @@ -160,6 +160,7 @@ ControllerServer::on_configure(const rclcpp_lifecycle::State & /*state*/)
RCLCPP_FATAL(
get_logger(),
"Failed to create goal checker. Exception: %s", ex.what());
on_cleanup(state);
return nav2_util::CallbackReturn::FAILURE;
}
}
Expand Down Expand Up @@ -188,6 +189,7 @@ ControllerServer::on_configure(const rclcpp_lifecycle::State & /*state*/)
RCLCPP_FATAL(
get_logger(),
"Failed to create controller. Exception: %s", ex.what());
on_cleanup(state);
return nav2_util::CallbackReturn::FAILURE;
}
}
Expand Down
3 changes: 2 additions & 1 deletion nav2_planner/src/planner_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ PlannerServer::~PlannerServer()
}

nav2_util::CallbackReturn
PlannerServer::on_configure(const rclcpp_lifecycle::State & /*state*/)
PlannerServer::on_configure(const rclcpp_lifecycle::State & state)
{
RCLCPP_INFO(get_logger(), "Configuring");

Expand Down Expand Up @@ -111,6 +111,7 @@ PlannerServer::on_configure(const rclcpp_lifecycle::State & /*state*/)
RCLCPP_FATAL(
get_logger(), "Failed to create global planner. Exception: %s",
ex.what());
on_cleanup(state);
return nav2_util::CallbackReturn::FAILURE;
}
}
Expand Down
5 changes: 3 additions & 2 deletions nav2_smoother/src/nav2_smoother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ SmootherServer::~SmootherServer()
}

nav2_util::CallbackReturn
SmootherServer::on_configure(const rclcpp_lifecycle::State &)
SmootherServer::on_configure(const rclcpp_lifecycle::State & state)
{
RCLCPP_INFO(get_logger(), "Configuring smoother server");

Expand Down Expand Up @@ -98,6 +98,7 @@ SmootherServer::on_configure(const rclcpp_lifecycle::State &)
*costmap_sub_, *footprint_sub_, this->get_name());

if (!loadSmootherPlugins()) {
on_cleanup(state);
return nav2_util::CallbackReturn::FAILURE;
}

Expand Down Expand Up @@ -155,7 +156,7 @@ bool SmootherServer::loadSmootherPlugins()
}

nav2_util::CallbackReturn
SmootherServer::on_activate(const rclcpp_lifecycle::State &)
SmootherServer::on_activate(const rclcpp_lifecycle::State & /*state*/)
{
RCLCPP_INFO(get_logger(), "Activating");

Expand Down
36 changes: 25 additions & 11 deletions nav2_velocity_smoother/src/velocity_smoother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ VelocitySmoother::~VelocitySmoother()
}

nav2_util::CallbackReturn
VelocitySmoother::on_configure(const rclcpp_lifecycle::State &)
VelocitySmoother::on_configure(const rclcpp_lifecycle::State & state)
{
RCLCPP_INFO(get_logger(), "Configuring velocity smoother");
auto node = shared_from_this();
Expand Down Expand Up @@ -76,16 +76,23 @@ VelocitySmoother::on_configure(const rclcpp_lifecycle::State &)

for (unsigned int i = 0; i != 3; i++) {
if (max_decels_[i] > 0.0) {
throw std::runtime_error(
"Positive values set of deceleration! These should be negative to slow down!");
RCLCPP_ERROR(
get_logger(),
"Positive values set of deceleration! These should be negative to slow down!");
on_cleanup(state);
return nav2_util::CallbackReturn::FAILURE;
}
if (max_accels_[i] < 0.0) {
throw std::runtime_error(
"Negative values set of acceleration! These should be positive to speed up!");
RCLCPP_ERROR(
get_logger(),
"Negative values set of acceleration! These should be positive to speed up!");
on_cleanup(state);
return nav2_util::CallbackReturn::FAILURE;
}
if (min_velocities_[i] > max_velocities_[i]) {
throw std::runtime_error(
"Min velocities are higher than max velocities!");
RCLCPP_ERROR(get_logger(), "Min velocities are higher than max velocities!");
on_cleanup(state);
return nav2_util::CallbackReturn::FAILURE;
}
}

Expand All @@ -104,9 +111,12 @@ VelocitySmoother::on_configure(const rclcpp_lifecycle::State &)
if (max_velocities_.size() != 3 || min_velocities_.size() != 3 ||
max_accels_.size() != 3 || max_decels_.size() != 3 || deadband_velocities_.size() != 3)
{
throw std::runtime_error(
"Invalid setting of kinematic and/or deadband limits!"
" All limits must be size of 3 representing (x, y, theta).");
RCLCPP_ERROR(
get_logger(),
"Invalid setting of kinematic and/or deadband limits!"
" All limits must be size of 3 representing (x, y, theta).");
on_cleanup(state);
return nav2_util::CallbackReturn::FAILURE;
}

// Get control type
Expand All @@ -116,7 +126,11 @@ VelocitySmoother::on_configure(const rclcpp_lifecycle::State &)
open_loop_ = false;
odom_smoother_ = std::make_unique<nav2_util::OdomSmoother>(node, odom_duration_, odom_topic_);
} else {
throw std::runtime_error("Invalid feedback_type, options are OPEN_LOOP and CLOSED_LOOP.");
RCLCPP_ERROR(
get_logger(),
"Invalid feedback_type, options are OPEN_LOOP and CLOSED_LOOP.");
on_cleanup(state);
return nav2_util::CallbackReturn::FAILURE;
}

// Setup inputs / outputs
Expand Down
15 changes: 9 additions & 6 deletions nav2_velocity_smoother/test/test_velocity_smoother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ class VelSmootherShim : public nav2_velocity_smoother::VelocitySmoother
public:
VelSmootherShim()
: VelocitySmoother() {}
void configure(const rclcpp_lifecycle::State & state) {this->on_configure(state);}
nav2_util::CallbackReturn configure(const rclcpp_lifecycle::State & state)
{
return this->on_configure(state);
}
void activate(const rclcpp_lifecycle::State & state) {this->on_activate(state);}
void deactivate(const rclcpp_lifecycle::State & state) {this->on_deactivate(state);}
void cleanup(const rclcpp_lifecycle::State & state) {this->on_cleanup(state);}
Expand Down Expand Up @@ -587,10 +590,10 @@ TEST(VelocitySmootherTest, testInvalidParams)
std::vector<double> max_vels{0.0, 0.0}; // invalid size
smoother->declare_parameter("max_velocity", rclcpp::ParameterValue(max_vels));
rclcpp_lifecycle::State state;
EXPECT_THROW(smoother->configure(state), std::runtime_error);
EXPECT_EQ(smoother->configure(state), nav2_util::CallbackReturn::FAILURE);

smoother->set_parameter(rclcpp::Parameter("feedback", std::string("LAWLS")));
EXPECT_THROW(smoother->configure(state), std::runtime_error);
EXPECT_EQ(smoother->configure(state), nav2_util::CallbackReturn::FAILURE);
}

TEST(VelocitySmootherTest, testInvalidParamsAccelDecel)
Expand All @@ -606,13 +609,13 @@ TEST(VelocitySmootherTest, testInvalidParamsAccelDecel)
smoother->declare_parameter("max_velocity", rclcpp::ParameterValue(bad_test_max_vel));
smoother->declare_parameter("min_velocity", rclcpp::ParameterValue(bad_test_min_vel));
rclcpp_lifecycle::State state;
EXPECT_THROW(smoother->configure(state), std::runtime_error);
EXPECT_EQ(smoother->configure(state), nav2_util::CallbackReturn::FAILURE);

smoother->set_parameter(rclcpp::Parameter("max_accel", rclcpp::ParameterValue(bad_test_accel)));
EXPECT_THROW(smoother->configure(state), std::runtime_error);
EXPECT_EQ(smoother->configure(state), nav2_util::CallbackReturn::FAILURE);

smoother->set_parameter(rclcpp::Parameter("max_decel", rclcpp::ParameterValue(bad_test_decel)));
EXPECT_THROW(smoother->configure(state), std::runtime_error);
EXPECT_EQ(smoother->configure(state), nav2_util::CallbackReturn::FAILURE);
}

TEST(VelocitySmootherTest, testDynamicParameter)
Expand Down
3 changes: 2 additions & 1 deletion nav2_waypoint_follower/src/waypoint_follower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ WaypointFollower::~WaypointFollower()
}

nav2_util::CallbackReturn
WaypointFollower::on_configure(const rclcpp_lifecycle::State & /*state*/)
WaypointFollower::on_configure(const rclcpp_lifecycle::State & state)
{
RCLCPP_INFO(get_logger(), "Configuring");

Expand Down Expand Up @@ -92,6 +92,7 @@ WaypointFollower::on_configure(const rclcpp_lifecycle::State & /*state*/)
RCLCPP_FATAL(
get_logger(),
"Failed to create waypoint_task_executor. Exception: %s", ex.what());
on_cleanup(state);
}

return nav2_util::CallbackReturn::SUCCESS;
Expand Down