Ask Your Question

What is the correct way to use ROS2 composition and the class_loader for node classes which take arguments in the constructor?

asked 2017-05-14 05:31:29 -0500

edw gravatar image

updated 2017-05-14 09:09:36 -0500

Referring to the demos in the composition package in ROS2:

I believe that the examples all assume nodes which pass no arguments to the constructor. (This appears to be hard-coded in the class_loader code in ${ROS_WS}/install/include/class_loader/meta_object.h for example.)

As a simple example, if I want to extend the demo to use a single publisher and two subscribers, each with two different names, what is the preferred way to do this? Can the node name(and other variables) be set after construction? Can the class_loader be extended to take arguments?

In practice, I will have two or more nodes that are initialized using two different config files at runtime. The code for those nodes is identical and the node_name, initialization filenames etc. are set at runtime and create two unique nodes doing different things to the data that is subscribed to depending on the models that are read in at initialization.


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-04-19 12:48:06 -0500

emersonknapp gravatar image

You are correct that there is an explicit hardcoded assumption that Components must be default-constructible. The intention is that you do not use arguments for configuration, and instead use ROS parameters for this purpose, rather than constructor or command-line arguments.

edit flag offensive delete link more


You are correct that there is an explicit hardcoded assumption

should that be implicit?

gvdhoorn gravatar image gvdhoorn  ( 2021-04-19 12:55:00 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2017-05-14 05:31:29 -0500

Seen: 504 times

Last updated: Apr 19