pass arg to node not working
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
Asked by dinesh on 2020-06-07 08:09:11 UTC
Answers
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"
Asked by Weasfas on 2020-06-07 09:28:41 UTC
Comments
roslaunch pure_vision pure_vision_single_image.launch arg1:="ct.jpg" why is this not working?
Asked by dinesh on 2020-06-07 23:13:23 UTC
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.
Asked by Weasfas on 2020-06-08 04:13:27 UTC
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.
Asked by dinesh on 2020-06-08 04:37:22 UTC
I have edited the answer to be more clear. You just need to add and argument to the launch file.
Asked by Weasfas on 2020-06-08 09:43:19 UTC
Have you tested this way yourslef? cas still its not working for mine.
Asked by dinesh on 2020-06-10 08:56:22 UTC
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.
Asked by Weasfas on 2020-06-10 10:21:50 UTC
Comments