ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

pass arg to node not working

asked 2020-06-07 08:09:11 -0500

dinesh gravatar image

Here is my launch file:

<launch>
    <node pkg="pure_vision" type="my_publisher" name="my_publisher" args="-arg1"/>
    <node pkg="pure_vision" type="pure_vision" name="pure_vision"/>
    <node pkg="rviz" type="rviz" name="rviz"/>
</launch>

Here is the command i'm running to launch this :

roslaunch pure_vision pure_vision_single_image.launch arg1:="bird.jpg"

But when i do the rostopic echo on the publising topic i'm not getting the data. This same node is working when i run this node after roscore i.e

rosrun pure_vision my_publisher bird.jpg
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-06-07 09:28:41 -0500

Weasfas gravatar image

updated 2020-06-08 09:44:17 -0500

Hi @dinesh,

If you need to change the parameter like that your should add and argument to the launch file.

E.g.: Launch file -> pure_vision_single_image.launch:

<?xml version="1.0"?>
<launch>
    <arg name="arg1" default="-arg1"/>
    <node pkg="pure_vision" type="my_publisher" name="my_publisher" args="$(arg arg1)"/>
    <node pkg="pure_vision" type="pure_vision" name="pure_vision"/>
    <node pkg="rviz" type="rviz" name="rviz"/>
</launch>

Command:

roslaunch pure_vision pure_vision_single_image.launch arg1:="image.jpg"
edit flag offensive delete link more

Comments

roslaunch pure_vision pure_vision_single_image.launch arg1:="ct.jpg" why is this not working?

dinesh gravatar image dinesh  ( 2020-06-07 23:13:23 -0500 )edit

Because with arg1:= instruction you are passing ar argument to the launch file not to the node, for this, as I said, you will need to add and argument to the launch file.

Weasfas gravatar image Weasfas  ( 2020-06-08 04:13:27 -0500 )edit

so what is the exact launch file and exact command to pass an image to the node in that launch file? i'm kind of confused.

dinesh gravatar image dinesh  ( 2020-06-08 04:37:22 -0500 )edit

I have edited the answer to be more clear. You just need to add and argument to the launch file.

Weasfas gravatar image Weasfas  ( 2020-06-08 09:43:19 -0500 )edit

Have you tested this way yourslef? cas still its not working for mine.

dinesh gravatar image dinesh  ( 2020-06-10 08:56:22 -0500 )edit

Well, I did not test it with the pute_vision package since I assume that is your own pakage and I am not able to clone it in particular. But I tested the launch file and command in one of my own packages and it works perfectly.

Also I assummed that you have programmed properly the fact of storing the parameters passed to the node since the first command (rosrun pure_vision my_publisher bird.jpg) you mentioned works for you.

int main(int argc, char **argv)
{
...
ROS_INFO("Passed arg to %s is %s", argv[0], argv[1]);
...
}

If the problem persist you can post here code chunks to start debuggin what is going on.

Weasfas gravatar image Weasfas  ( 2020-06-10 10:21:50 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2020-06-07 08:09:11 -0500

Seen: 291 times

Last updated: Jun 08 '20