Parametrizing two nodes within one launch file

asked 2021-08-29 12:36:35 -0500

ravnicas gravatar image

updated 2021-08-30 13:43:59 -0500

Hello folks,

i've got a question about launch files. I wrote a dedicated class to access my robot. Since the functionality of moveit is limited at a crucial point - "getRobotState" does not work as intended when using the same node handle as my classes services (using multi threaded executor in that case). I have solved this issue by adding a second node with the sole purpose of being called from a move group interface.

Since i need both nodes in the same class, one for my own services and the other one to be called from moveit, i had at least no other idea than to start them directly within the main function.

This creates a problem within the launch files. How can i pass different arguments and node names to both of the nodes from the launch file? If i define a name, both of the nodes will have the same name. Also both of the nodes get the same arguments, this isn't a problem as long as all the arguments are namespaced or plain different, but makes parametrization unconvenient in comparison to single node classes.

cpp file:

int main(int argc, char *argv[])
{
rclcpp::init(argc, argv);

rclcpp::NodeOptions node_options;
node_options.automatically_declare_parameters_from_overrides(true);
std::shared_ptr<rclcpp::Node> node = rclcpp::Node::make_shared("node", node_options);
std::shared_ptr<rclcpp::Node> moveit_node = rclcpp::Node::make_shared("moveit_node", node_options);

MyCustomClass my_custom_class(node, moveit_node);

rclcpp::executors::SingleThreadedExecutor executor1;
executor1.add_node(moveit_node);
std::thread([&executor1]()
            { executor1.spin(); })
    .detach();

rclcpp::executors::MultiThreadedExecutor executor2;
executor2.add_node(node);
executor2.spin();

rclcpp::shutdown();
return EXIT_SUCCESS;
}

launch file:

server_node = Node(#name='cant_choose_this',
                   package='my_custom_class',
                   executable='my_custom_class',
                   #output='screen',
                   parameters=[robot_description,
                               robot_description_semantic,
                               kinematics_yaml],
                   arguments = ['--ros-args', '--log-level', 'INFO'])
edit retag flag offensive close merge delete

Comments

Would a sub-node help? Instead of creating two rclcpp::Nodes, create one Node, then call create_sub_node twice on it, passing the resulting Nodes into your Custom Class. I'm not familiar enough with sub-nodes to know exactly how they work, but you might be able to set the node names and parameters independently.. Just a thought.

ChuiV gravatar image ChuiV  ( 2021-09-03 10:20:25 -0500 )edit