An organizer for switching between multiple different plugins of the same type. More...
#include <plugin_mux.h>
Public Types | |
using | SwitchCallback = std::function< void(const std::string &, const std::string &)> |
alias for the function-type of the callback fired when the plugin switches. More... | |
Public Member Functions | |
void | addPlugin (const std::string &plugin_name, const std::string &plugin_class_name) |
Create an instance of the given plugin_class_name and save it with the given plugin_name. More... | |
T & | getCurrentPlugin () |
Get the Current Plugin. More... | |
std::string | getCurrentPluginName () const |
Get the Current Plugin Name. More... | |
T & | getPlugin (const std::string &name) |
Get the Specified Plugin. More... | |
std::vector< std::string > | getPluginNames () const |
Get the current list of plugin names. More... | |
bool | hasPlugin (const std::string &name) const |
Check to see if a plugin exists. More... | |
PluginMux (const std::string &plugin_package, const std::string &plugin_class, const std::string ¶meter_name, const std::string &default_value, const std::string &ros_name="current_plugin", const std::string &switch_service_name="switch_plugin") | |
Main Constructor - Loads plugin(s) and sets up ROS interfaces. More... | |
void | setSwitchCallback (SwitchCallback switch_callback) |
Set the callback fired when the plugin switches. More... | |
bool | usePlugin (const std::string &name) |
C++ Interface for switching to a given plugin. More... | |
Protected Member Functions | |
bool | switchPluginService (nav_2d_msgs::SwitchPlugin::Request &req, nav_2d_msgs::SwitchPlugin::Response &resp) |
ROS Interface for Switching Plugins. More... | |
Protected Attributes | |
std::string | current_plugin_ |
ros::Publisher | current_plugin_pub_ |
pluginlib::ClassLoader< T > | plugin_loader_ |
std::map< std::string, boost::shared_ptr< T > > | plugins_ |
ros::NodeHandle | private_nh_ |
std::string | ros_name_ |
SwitchCallback | switch_callback_ |
ros::ServiceServer | switch_plugin_srv_ |
An organizer for switching between multiple different plugins of the same type.
The different plugins are specified using a list of strings on the parameter server, each of which is a namespace. The specific type and additional parameters for each plugin are specified on the parameter server in that namespace. All the plugins are loaded initially, but only one is the "current" plugin at any particular time, which is published on a latched topic AND stored on the ROS parameter server. You can switch which plugin is current either through a C++ or ROS interface.
Definition at line 59 of file plugin_mux.h.
using nav_2d_utils::PluginMux< T >::SwitchCallback = std::function<void(const std::string&, const std::string&)> |
alias for the function-type of the callback fired when the plugin switches.
The first parameter will be the namespace of the plugin that was previously used. The second parameter will be the namespace of the plugin that is being switched to.
Definition at line 170 of file plugin_mux.h.
nav_2d_utils::PluginMux< T >::PluginMux | ( | const std::string & | plugin_package, |
const std::string & | plugin_class, | ||
const std::string & | parameter_name, | ||
const std::string & | default_value, | ||
const std::string & | ros_name = "current_plugin" , |
||
const std::string & | switch_service_name = "switch_plugin" |
||
) |
Main Constructor - Loads plugin(s) and sets up ROS interfaces.
plugin_package | The package of the plugin type |
plugin_class | The class name for the plugin type |
parameter_name | Name of parameter for the namespaces. |
default_value | If class name is not specified, which plugin should be loaded |
ros_name | ROS name for setting up topic and parameter |
switch_service_name | ROS name for setting up the ROS service |
Definition at line 221 of file plugin_mux.h.
void nav_2d_utils::PluginMux< T >::addPlugin | ( | const std::string & | plugin_name, |
const std::string & | plugin_class_name | ||
) |
Create an instance of the given plugin_class_name and save it with the given plugin_name.
plugin_name | Namespace for the new plugin |
plugin_class_name | Class type name for the new plugin |
Definition at line 258 of file plugin_mux.h.
|
inline |
Get the Current Plugin.
Definition at line 146 of file plugin_mux.h.
|
inline |
Get the Current Plugin Name.
Definition at line 115 of file plugin_mux.h.
|
inline |
Get the Specified Plugin.
name | Name of plugin to get |
Definition at line 135 of file plugin_mux.h.
|
inline |
Get the current list of plugin names.
Definition at line 154 of file plugin_mux.h.
|
inline |
Check to see if a plugin exists.
name | Namespace to set current plugin to |
Definition at line 125 of file plugin_mux.h.
|
inline |
Set the callback fired when the plugin switches.
In addition to switching which plugin is being used via directly calling usePlugin
a switch can also be triggered externally via ROS service. In such a case, other classes may want to know when this happens. This is accomplished using the SwitchCallback, which will be called regardless of how the plugin is switched.
Definition at line 180 of file plugin_mux.h.
|
inlineprotected |
ROS Interface for Switching Plugins.
Definition at line 186 of file plugin_mux.h.
|
inline |
C++ Interface for switching to a given plugin.
name | Namespace to set current plugin to |
Definition at line 89 of file plugin_mux.h.
|
protected |
Definition at line 205 of file plugin_mux.h.
|
protected |
Definition at line 209 of file plugin_mux.h.
|
protected |
Definition at line 203 of file plugin_mux.h.
|
protected |
Definition at line 204 of file plugin_mux.h.
|
protected |
Definition at line 210 of file plugin_mux.h.
|
protected |
Definition at line 211 of file plugin_mux.h.
|
protected |
Definition at line 214 of file plugin_mux.h.
|
protected |
Definition at line 208 of file plugin_mux.h.