Skip to content

Commit

Permalink
Replace pointers with values
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher authored and destogl committed Nov 17, 2022
1 parent de3a01e commit 65d428b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,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 @@ -144,11 +144,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 @@ -178,11 +175,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)
{
diagnostics_updater_.setHardwareID("ros2_control");
diagnostics_updater_.add(
Expand Down Expand Up @@ -283,18 +277,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 @@ -304,13 +298,13 @@ controller_interface::ControllerInterfaceBaseSharedPtr ControllerManager::load_c

controller_interface::ControllerInterfaceBaseSharedPtr controller;

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);
}

ControllerSpec controller_spec;
Expand Down Expand Up @@ -1371,14 +1365,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 @@ -1490,11 +1484,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

0 comments on commit 65d428b

Please sign in to comment.