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

Dynamically load controllers #23

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions robot_controllers_interface/src/controller_loader.cpp
Expand Up @@ -46,11 +46,18 @@ bool ControllerLoader::init(const std::string& name, ControllerManager* manager)

if (nh.getParam("type", controller_type))
{
controller_ = plugin_loader_.createInstance(controller_type);
controller_->init(nh, manager);
// If plugin is bad, catch pluginlib exception
try
{
controller_ = plugin_loader_.createInstance(controller_type);
controller_->init(nh, manager);
}
catch (pluginlib::LibraryLoadException e)
{
return false;
}
return true;
}

ROS_ERROR_STREAM("Unable to load controller " << name.c_str());
return false;
}
Expand Down
35 changes: 26 additions & 9 deletions robot_controllers_interface/src/controller_manager.cpp
Expand Up @@ -254,7 +254,7 @@ void ControllerManager::execute(const robot_controllers_msgs::QueryControllerSta
robot_controllers_msgs::ControllerState state = goal->updates[i];

// Make sure controller exists
bool exists = false;
bool in_controller_list = false;
for (ControllerList::iterator c = controllers_.begin(); c != controllers_.end(); c++)
{
if ((*c)->getController()->getName() == state.name)
Expand All @@ -263,7 +263,7 @@ void ControllerManager::execute(const robot_controllers_msgs::QueryControllerSta
{
if (state.type == (*c)->getController()->getType())
{
exists = true;
in_controller_list = true;
break;
}
else
Expand All @@ -275,17 +275,34 @@ void ControllerManager::execute(const robot_controllers_msgs::QueryControllerSta
return;
}
}
exists = true;
in_controller_list = true;
break;
}
}
if (!exists)
if (!in_controller_list)
{
std::stringstream ss;
ss << "No such controller to update: " << state.name;
getState(result);
server_->setAborted(result, ss.str());
return;
// Check if controller exists on parameter server
ros::NodeHandle nh;
if (nh.hasParam(state.name))
{
// Create controller (in a loader)
if (!load(static_cast<std::string>(state.name)))
{
std::stringstream ss;
ss << "Failed to load controller: " << state.name;
getState(result);
server_->setAborted(result, ss.str());
return;
}
}
else
{
std::stringstream ss;
ss << "No such controller to update: " << state.name;
getState(result);
server_->setAborted(result, ss.str());
return;
}
}

// Update state
Expand Down