The current workflow requires modifying the core pfield_manager source code for every new robot, which violates the Open/Closed Principle.
Recommendation: Convert MotionPlugin and IKSolver into ROS 2 Plugins using pluginlib.
Benefits:
- Zero changes to
pfield_manager: It loads classes dynamically at runtime based on a string parameter.
- No Clutter: You can create a separate package (e.g.,
my_robot_pfield_plugin) for your specific robot files. You don't need to touch the core potential_fields repo at all.
Proposed Changes
-
Refactor ABCs for Pluginlib:
pluginlib requires a default constructor (0 arguments). You should add an initialize method to pass parameters after instantiation.
// In MotionPlugin
virtual void initialize(const std::string& name, rclcpp::Node::SharedPtr node) {
this->name = name;
// Use node to declare/get parameters like "franka_hostname"
}
-
Update pfield_manager.hpp:
Replace the hardcoded includes with a ClassLoader.
#include <pluginlib/class_loader.hpp>
// ...
pluginlib::ClassLoader<MotionPlugin> motion_plugin_loader_;
-
Update pfield_manager.cpp:
Replace the if/else block with dynamic loading:
// In Constructor
motion_plugin_loader_("potential_fields", "MotionPlugin"); // Package and Base Class
try {
this->motionPlugin = motion_plugin_loader_.createUniqueInstance(this->motionPluginType);
this->motionPlugin->initialize(this->motionPluginType, shared_from_this());
} catch(pluginlib::PluginlibException& ex) {
// Handle error
}
-
For the User (New Workflow):
The user now creates a separate package and adds a simple XML registration file.
my_robot_plugins.xml:
<library path="my_robot_lib">
<class name="my_robot" type="my_pkg::MyRobotPlugin" base_class_type="MotionPlugin">
<description>Plugin for My Robot</description>
</class>
</library>
CMakeLists.txt: No need to edit the core repo. Just export the plugin in the user's package.
The current workflow requires modifying the core
pfield_managersource code for every new robot, which violates the Open/Closed Principle.Recommendation: Convert
MotionPluginandIKSolverinto ROS 2 Plugins usingpluginlib.Benefits:
pfield_manager: It loads classes dynamically at runtime based on a string parameter.my_robot_pfield_plugin) for your specific robot files. You don't need to touch the corepotential_fieldsrepo at all.Proposed Changes
Refactor ABCs for Pluginlib:
pluginlibrequires a default constructor (0 arguments). You should add aninitializemethod to pass parameters after instantiation.Update
pfield_manager.hpp:Replace the hardcoded includes with a
ClassLoader.Update
pfield_manager.cpp:Replace the
if/elseblock with dynamic loading:For the User (New Workflow):
The user now creates a separate package and adds a simple XML registration file.
my_robot_plugins.xml:CMakeLists.txt: No need to edit the core repo. Just export the plugin in the user's package.