How can I set the node_name when using ClassLoader and NodeFactory
I would like to use the class_loader::ClassLoader
and rclcpp_components::NodeFactory
to create multiple nodes, while specifying the node_name
as argument, instead of hard coded string in the class definition.
What I have right now is this:
std::string lib_name = "my_lib";
std::string library_path = ament_index_cpp::get_package_prefix("my_package")+"/lib/lib" + lib_name + ".so";
auto loader = new class_loader::ClassLoader(library_path);
auto classes = loader->getAvailableClasses<rclcpp_components::NodeFactory>();
rclcpp::NodeOptions options;
auto node_factory = loader->createInstance<rclcpp_components::NodeFactory>(type);
auto wrapper = node_factory->create_node_instance(options);
Environment
- galactic
- Ubuntu 20.04
I think one Option could be to create my own version of NodeFactory, that takes additional arguments, e.g. the node_name right?