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

[Docking] Feature: support for not needing to set dock instances #4442

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
11 changes: 6 additions & 5 deletions nav2_bringup/params/nav2_params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,12 @@ docking_server:
filter_coef: 0.1

# Dock instances
docks: ['home_dock'] # Input your docks here
home_dock:
type: 'simple_charging_dock'
frame: map
pose: [0.0, 0.0, 0.0]
# The following example illustrates configuring dock instances.
# docks: ['home_dock'] # Input your docks here
# home_dock:
# type: 'simple_charging_dock'
# frame: map
# pose: [0.0, 0.0, 0.0]

controller:
k_phi: 3.0
Expand Down
37 changes: 27 additions & 10 deletions nav2_docking/opennav_docking/src/dock_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,32 @@ bool DockDatabase::initialize(
node_ = parent;
auto node = node_.lock();

if (getDockPlugins(node, tf) && getDockInstances(node)) {
RCLCPP_INFO(
if (!getDockPlugins(node, tf)) {
RCLCPP_ERROR(
node->get_logger(),
"Docking Server has %u dock types and %u dock instances available.",
this->plugin_size(), this->instance_size());
return true;
"An error occurred while getting the dock plugins!");
return false;
}

if (!getDockInstances(node)) {
RCLCPP_ERROR(
node->get_logger(),
"An error occurred while getting the dock instances!");
return false;
}

RCLCPP_INFO(
node->get_logger(),
"Docking Server has %u dock types and %u dock instances available.",
this->plugin_size(), this->instance_size());

reload_db_service_ = node->create_service<nav2_msgs::srv::ReloadDockDatabase>(
"~/reload_database",
std::bind(
&DockDatabase::reloadDbCb, this,
std::placeholders::_1, std::placeholders::_2));

return false;
return true;
}

void DockDatabase::activate()
Expand All @@ -71,10 +82,14 @@ void DockDatabase::reloadDbCb(
const std::shared_ptr<nav2_msgs::srv::ReloadDockDatabase::Request> request,
std::shared_ptr<nav2_msgs::srv::ReloadDockDatabase::Response> response)
{
auto node = node_.lock();
DockMap dock_instances;
if (utils::parseDockFile(request->filepath, node_.lock(), dock_instances)) {
if (utils::parseDockFile(request->filepath, node, dock_instances)) {
dock_instances_ = dock_instances;
response->success = true;
RCLCPP_INFO(
node->get_logger(),
"Dock database reloaded from file %s.", request->filepath.c_str());
return;
}
response->success = false;
Expand Down Expand Up @@ -194,10 +209,12 @@ bool DockDatabase::getDockInstances(const rclcpp_lifecycle::LifecycleNode::Share
return utils::parseDockParams(docks_param, node, dock_instances_);
}

RCLCPP_ERROR(
RCLCPP_WARN(
node->get_logger(),
"Dock database filepath nor dock parameters set. Unable to perform docking actions.");
return false;
"Dock database filepath nor dock parameters set. "
"Docking actions can only be executed specifying the dock pose via the action request. "
"Or update the dock database via the reload_database service.");
return true;
}

unsigned int DockDatabase::plugin_size() const
Expand Down
5 changes: 4 additions & 1 deletion nav2_docking/opennav_docking/test/test_dock_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ TEST(DatabaseTests, findTests)
TEST(DatabaseTests, reloadDbService)
{
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("test");
std::vector<std::string> plugins{"dockv1", "dockv2"};
std::vector<std::string> plugins{"dockv1"};
node->declare_parameter("dock_plugins", rclcpp::ParameterValue(plugins));
node->declare_parameter(
"dockv1.plugin",
rclcpp::ParameterValue("opennav_docking::SimpleChargingDock"));
opennav_docking::DockDatabase db;
db.initialize(node, nullptr);

Expand Down
Loading