Parametrizing two nodes within one launch file

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

ravnicas gravatar image

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

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;
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.spin(); })

rclcpp::executors::MultiThreadedExecutor executor2;


launch file:

server_node = Node(#name='cant_choose_this',
                   arguments = ['--ros-args', '--log-level', 'INFO'])
edit retag flag offensive close merge delete


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 -0600 )edit