Ask Your Question

howto pass argv to ros2 class_loader node

asked 2018-11-20 04:51:55 -0500

yechun gravatar image

updated 2018-11-20 04:57:38 -0500

While I am porting image_publisher of image_pipeline from ROS 1 to ROS 2, there is nodelet::Loader in ROS1 to provide load() API to pass argv to loader node. So that image filename could be passed from command line to class node by "rosrun image_publisher image_publisher image.png".

manager.load(ros::this_node::getName(), "image_publisher/image_publisher", remappings, my_argv);

But from ROS2 class_loader instead of plugin nodelet. what we expected is to use composition to pass image.png to imagePublisherNode like below:

ros2 run composition api_composition ros2 run composition api_composition_cli image_publsiher image_publisher::ImagePubisherNode image.png

How to pass argv such as image.png to class_loader node as class_loader::ClassLoader?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-11-20 10:19:49 -0500

William gravatar image

updated 2018-11-20 10:21:22 -0500

Currently you cannot, and in general I think it's a flawed assumption to think that nodes will always have access to command line arguments.

In the future we might add a way to expose the command line arguments to nodes loaded as components (when it makes sense), but in general nodes loaded as components are not necessarily ever given command line arguments. You can just make a service call to a component container in order to load a node and then there are no command line arguments associated with that node.

Instead, I'd recommend using a ROS parameter for that input, that way it can be passed as a command line argument or as a parameter when loading via a ROS service call.

edit flag offensive delete link more


thanks for guardians, ROS parameter is a good way, I could set parameter in the node ref to code with demo_nodes_cpp/parameter

And update parameter by below "ros2 param" command, this could fix my problem. thanks.

ros2 param set /my_node filename "image.png"

yechun gravatar image yechun  ( 2018-11-21 01:06:31 -0500 )edit

would you please share with me some demo example to passed as a command with line argument by using ROS parameter?

yechun gravatar image yechun  ( 2018-11-23 02:28:46 -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: 2018-11-20 04:51:55 -0500

Seen: 280 times

Last updated: Nov 20 '18