I have written a simple talker node that get the publishing rate [..] using a command line parameter server.
A bit of a nit-pick, but there is no such thing as a "command line parameter server".
What happens when you use the _<identifier>:=<value>
syntax is that rosrun
will pass those to the node and treats those as private parameters of the node. See wiki/rosbash - rosrun for the documentation.
But I am using a launch file to initiate a talker and a listener node at the same time. Is there any way that I can use some command line parameter so that I can vary the rate every time without having to change the program ?
Certainly.
You'd just use the param
tag in your launch file as a child of the node
tag. See wiki/roslaunch/XML/node for the documentation of node
(which links to param
).
A short example:
<node name=".." pkg=".." type="..">
<param name="rate" value="50" />
</node>
Edit:
sure, I can do that. But if I want to change the value every time I run the launch file, I should have to edit the launch file itself. Can I pass the rate parameter like
roslaunch performance_test py_test.launch _rate:=50
Roslaunch works a little different from rosrun
, but something like that is possible.
You'd want to take a look at the arg
tag (docs).
For your specific example (I've added a default
here, which is not actually necessary, but could be a nice thing to do for simple launch files):
<arg name="rate" default="50" />
<node name=".." pkg=".." type="..">
<param name="rate" value="$(arg rate)" />
</node>
Then invoke it as follows:
roslaunch performance_test py_test.launch rate:=50
although with the default
being 50
already this won't result in any different behaviour of course.
Please note that in the end your question is a duplicate of quite a few others, one of which would be #q29461.
Originally posted by gvdhoorn with karma: 86574 on 2018-12-20
This answer was ACCEPTED on the original site
Post score: 2
Original comments
Comment by Brolin on 2018-12-20:
sure, I can do that. But if I want to change the value every time I run the launch file, I should have to edit the launch file itself. Can I pass the rate parameter like
roslaunch performance_test py_test.launch _rate:=50
Comment by Brolin on 2018-12-22:
thank you @gvdhoorn.