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

Replace pointers with values #849

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,8 @@ class ControllerManager : public rclcpp::Node

std::shared_ptr<rclcpp::Executor> executor_;

std::shared_ptr<pluginlib::ClassLoader<controller_interface::ControllerInterface>> loader_;
std::shared_ptr<pluginlib::ClassLoader<controller_interface::ChainableControllerInterface>>
chainable_loader_;
pluginlib::ClassLoader<controller_interface::ControllerInterface> loader_;
pluginlib::ClassLoader<controller_interface::ChainableControllerInterface> chainable_loader_;

/// Best effort (non real-time safe) callback group, e.g., service callbacks.
/**
Expand Down
41 changes: 17 additions & 24 deletions controller_manager/src/controller_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,8 @@ ControllerManager::ControllerManager(
resource_manager_(std::make_unique<hardware_interface::ResourceManager>()),
diagnostics_updater_(this),
executor_(executor),
loader_(std::make_shared<pluginlib::ClassLoader<controller_interface::ControllerInterface>>(
kControllerInterfaceNamespace, kControllerInterfaceClassName)),
chainable_loader_(
std::make_shared<pluginlib::ClassLoader<controller_interface::ChainableControllerInterface>>(
kControllerInterfaceNamespace, kChainableControllerInterfaceClassName))
loader_(kControllerInterfaceNamespace, kControllerInterfaceClassName),
chainable_loader_(kControllerInterfaceNamespace, kChainableControllerInterfaceClassName)
{
if (!get_parameter("update_rate", update_rate_))
{
Expand Down Expand Up @@ -172,11 +169,8 @@ ControllerManager::ControllerManager(
resource_manager_(std::move(resource_manager)),
diagnostics_updater_(this),
executor_(executor),
loader_(std::make_shared<pluginlib::ClassLoader<controller_interface::ControllerInterface>>(
kControllerInterfaceNamespace, kControllerInterfaceClassName)),
chainable_loader_(
std::make_shared<pluginlib::ClassLoader<controller_interface::ChainableControllerInterface>>(
kControllerInterfaceNamespace, kChainableControllerInterfaceClassName))
loader_(kControllerInterfaceNamespace, kControllerInterfaceClassName),
chainable_loader_(kControllerInterfaceNamespace, kChainableControllerInterfaceClassName)
{
if (!get_parameter("update_rate", update_rate_))
{
Expand Down Expand Up @@ -296,18 +290,18 @@ controller_interface::ControllerInterfaceBaseSharedPtr ControllerManager::load_c
RCLCPP_INFO(get_logger(), "Loading controller '%s'", controller_name.c_str());

if (
!loader_->isClassAvailable(controller_type) &&
!chainable_loader_->isClassAvailable(controller_type))
!loader_.isClassAvailable(controller_type) &&
!chainable_loader_.isClassAvailable(controller_type))
{
RCLCPP_ERROR(
get_logger(), "Loader for controller '%s' (type '%s') not found.", controller_name.c_str(),
controller_type.c_str());
RCLCPP_INFO(get_logger(), "Available classes:");
for (const auto & available_class : loader_->getDeclaredClasses())
for (const auto & available_class : loader_.getDeclaredClasses())
{
RCLCPP_INFO(get_logger(), " %s", available_class.c_str());
}
for (const auto & available_class : chainable_loader_->getDeclaredClasses())
for (const auto & available_class : chainable_loader_.getDeclaredClasses())
{
RCLCPP_INFO(get_logger(), " %s", available_class.c_str());
}
Expand All @@ -319,13 +313,13 @@ controller_interface::ControllerInterfaceBaseSharedPtr ControllerManager::load_c

try
{
if (loader_->isClassAvailable(controller_type))
if (loader_.isClassAvailable(controller_type))
{
controller = loader_->createSharedInstance(controller_type);
controller = loader_.createSharedInstance(controller_type);
}
if (chainable_loader_->isClassAvailable(controller_type))
if (chainable_loader_.isClassAvailable(controller_type))
{
controller = chainable_loader_->createSharedInstance(controller_type);
controller = chainable_loader_.createSharedInstance(controller_type);
}
}
catch (const pluginlib::CreateClassException & e)
Expand Down Expand Up @@ -1415,14 +1409,14 @@ void ControllerManager::list_controller_types_srv_cb(
std::lock_guard<std::mutex> guard(services_lock_);
RCLCPP_DEBUG(get_logger(), "list types service locked");

auto cur_types = loader_->getDeclaredClasses();
auto cur_types = loader_.getDeclaredClasses();
for (const auto & cur_type : cur_types)
{
response->types.push_back(cur_type);
response->base_classes.push_back(kControllerInterfaceClassName);
RCLCPP_DEBUG(get_logger(), "%s", cur_type.c_str());
}
cur_types = chainable_loader_->getDeclaredClasses();
cur_types = chainable_loader_.getDeclaredClasses();
for (const auto & cur_type : cur_types)
{
response->types.push_back(cur_type);
Expand Down Expand Up @@ -1534,11 +1528,10 @@ void ControllerManager::reload_controller_libraries_service_cb(
assert(loaded_controllers.empty());

// Force a reload on all the PluginLoaders (internally, this recreates the plugin loaders)
loader_ = std::make_shared<pluginlib::ClassLoader<controller_interface::ControllerInterface>>(
loader_ = pluginlib::ClassLoader<controller_interface::ControllerInterface>(
kControllerInterfaceNamespace, kControllerInterfaceClassName);
chainable_loader_ =
std::make_shared<pluginlib::ClassLoader<controller_interface::ChainableControllerInterface>>(
kControllerInterfaceNamespace, kChainableControllerInterfaceClassName);
chainable_loader_ = pluginlib::ClassLoader<controller_interface::ChainableControllerInterface>(
kControllerInterfaceNamespace, kChainableControllerInterfaceClassName);
RCLCPP_INFO(
get_logger(), "Controller manager: reloaded controller libraries for '%s'",
kControllerInterfaceNamespace);
Expand Down
Loading