Robotics StackExchange | Archived questions

howto pass argv to ros2 class_loader node

While I am porting imagepublisher of imagepipeline 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 imagepublisher imagepublisher image.png".

https://github.com/ros-perception/image_pipeline/blob/8d01c930e66bdeb58c4b138539a64ddea0b17e10/image_publisher/src/node/image_publisher.cpp#L53

manager.load(ros::thisnode::getName(), "imagepublisher/imagepublisher", remappings, myargv);

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 apicomposition ros2 run composition apicompositioncli imagepublsiher image_publisher::ImagePubisherNode image.png

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

Asked by yechun on 2018-11-20 05:51:55 UTC

Comments

Answers

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.

Asked by William on 2018-11-20 11:19:49 UTC

Comments

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"

Asked by yechun on 2018-11-21 02:06:31 UTC

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

Asked by yechun on 2018-11-23 03:28:46 UTC