Skip to content

Commit a5402ee

Browse files
[testing sprint] final test coverage and debug logging in planner/controller servers (#1924)
* adding CLI test * adding tests for more lines to map_server * fix last test * adding out of bounds and higher bounds checks * adding planner tests for plugins working * add cleanup * working * ping * adding more testing and debug info messages
1 parent fd49876 commit a5402ee

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

nav2_controller/include/nav2_controller/nav2_controller.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,6 @@ class ControllerServer : public nav2_util::LifecycleNode
189189
return twist_thresh;
190190
}
191191

192-
void pluginFailed(const std::string & name, const pluginlib::PluginlibException & ex)
193-
{
194-
RCLCPP_FATAL(get_logger(), "Failed to create %s. Exception: %s", name.c_str(), ex.what());
195-
exit(-1);
196-
}
197-
198192
// The controller needs a costmap node
199193
std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros_;
200194
std::unique_ptr<nav2_util::NodeThread> costmap_thread_;
@@ -234,7 +228,6 @@ class ControllerServer : public nav2_util::LifecycleNode
234228
double min_theta_velocity_threshold_;
235229

236230
// Whether we've published the single controller warning yet
237-
bool single_controller_warning_given_{false};
238231
geometry_msgs::msg::Pose end_pose_;
239232
};
240233

nav2_controller/src/nav2_controller.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ ControllerServer::on_configure(const rclcpp_lifecycle::State & state)
113113
progress_checker_id_.c_str(), progress_checker_type_.c_str());
114114
progress_checker_->initialize(node, progress_checker_id_);
115115
} catch (const pluginlib::PluginlibException & ex) {
116-
pluginFailed("progress_checker", ex);
116+
RCLCPP_FATAL(
117+
get_logger(),
118+
"Failed to create progress_checker. Exception: %s", ex.what());
117119
}
118120
try {
119121
goal_checker_type_ = nav2_util::get_plugin_type_param(node, goal_checker_id_);
@@ -123,7 +125,9 @@ ControllerServer::on_configure(const rclcpp_lifecycle::State & state)
123125
goal_checker_id_.c_str(), goal_checker_type_.c_str());
124126
goal_checker_->initialize(node, goal_checker_id_);
125127
} catch (const pluginlib::PluginlibException & ex) {
126-
pluginFailed("goal_checker", ex);
128+
RCLCPP_FATAL(
129+
get_logger(),
130+
"Failed to create goal_checker. Exception: %s", ex.what());
127131
}
128132

129133
for (size_t i = 0; i != controller_ids_.size(); i++) {
@@ -139,7 +143,9 @@ ControllerServer::on_configure(const rclcpp_lifecycle::State & state)
139143
costmap_ros_->getTfBuffer(), costmap_ros_);
140144
controllers_.insert({controller_ids_[i], controller});
141145
} catch (const pluginlib::PluginlibException & ex) {
142-
pluginFailed("controller", ex);
146+
RCLCPP_FATAL(
147+
get_logger(),
148+
"Failed to create controller. Exception: %s", ex.what());
143149
}
144150
}
145151

@@ -238,13 +244,10 @@ bool ControllerServer::findControllerId(
238244
{
239245
if (controllers_.find(c_name) == controllers_.end()) {
240246
if (controllers_.size() == 1 && c_name.empty()) {
241-
if (!single_controller_warning_given_) {
242-
RCLCPP_WARN(
243-
get_logger(), "No controller was specified in action call."
244-
" Server will use only plugin loaded %s. "
245-
"This warning will appear once.", controller_ids_concat_.c_str());
246-
single_controller_warning_given_ = true;
247-
}
247+
RCLCPP_WARN_ONCE(
248+
get_logger(), "No controller was specified in action call."
249+
" Server will use only plugin loaded %s. "
250+
"This warning will appear once.", controller_ids_concat_.c_str());
248251
current_controller = controllers_.begin()->first;
249252
} else {
250253
RCLCPP_ERROR(
@@ -254,6 +257,7 @@ bool ControllerServer::findControllerId(
254257
return false;
255258
}
256259
} else {
260+
RCLCPP_DEBUG(get_logger(), "Selected controller: %s.", c_name.c_str());
257261
current_controller = c_name;
258262
}
259263

@@ -390,7 +394,12 @@ void ControllerServer::updateGlobalPath()
390394
void ControllerServer::publishVelocity(const geometry_msgs::msg::TwistStamped & velocity)
391395
{
392396
auto cmd_vel = std::make_unique<geometry_msgs::msg::Twist>(velocity.twist);
393-
vel_publisher_->publish(std::move(cmd_vel));
397+
if (
398+
vel_publisher_->is_activated() &&
399+
this->count_subscribers(vel_publisher_->get_topic_name()) > 0)
400+
{
401+
vel_publisher_->publish(std::move(cmd_vel));
402+
}
394403
}
395404

396405
void ControllerServer::publishZeroVelocity()

nav2_planner/src/planner_server.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ PlannerServer::on_configure(const rclcpp_lifecycle::State & state)
103103
RCLCPP_FATAL(
104104
get_logger(), "Failed to create global planner. Exception: %s",
105105
ex.what());
106-
exit(-1);
107106
}
108107
}
109108

nav2_system_tests/src/planning/test_planner_plugins.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,18 @@ using nav2_util::TestCostmap;
2929
using ComputePathToPoseCommand = geometry_msgs::msg::PoseStamped;
3030
using ComputePathToPoseResult = nav_msgs::msg::Path;
3131

32+
void callback(const nav_msgs::msg::Path::ConstSharedPtr /*grid*/)
33+
{
34+
}
35+
3236
TEST(testPluginMap, Failures)
3337
{
3438
auto obj = std::make_shared<nav2_system_tests::NavFnPlannerTester>();
3539
rclcpp_lifecycle::State state;
40+
obj->set_parameter(rclcpp::Parameter("expected_planner_frequency", 0.0001));
3641
obj->onConfigure(state);
42+
obj->create_subscription<nav_msgs::msg::Path>(
43+
"plan", rclcpp::SystemDefaultsQoS(), callback);
3744

3845
geometry_msgs::msg::PoseStamped start;
3946
geometry_msgs::msg::PoseStamped goal;

0 commit comments

Comments
 (0)