Skip to content

Improving the workflow for supporting new Robots #38

Description

@Sharwin24

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

  1. 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"
    }
  2. Update pfield_manager.hpp:
    Replace the hardcoded includes with a ClassLoader.

    #include <pluginlib/class_loader.hpp>
    // ...
    pluginlib::ClassLoader<MotionPlugin> motion_plugin_loader_;
  3. 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
    }
  4. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions