ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

launch file doesn't use the parameters

asked 2021-01-18 21:53:17 -0600

Anirudhkochhar gravatar image

updated 2021-01-18 21:57:10 -0600

I am a beginner to ROS so am not sure why this is happening.

  <node name="hello_world_node" pkg="hello_world" type="" output="screen">
    <param name="freq" value="5" />
    <param name="text" value="Lauch file is working" />

this is my launch file.

and below is my node hello_world

#! /usr/bin/env python

import rospy

#initialising parameters
freq = rospy.get_param('freq',20)
text = rospy.get_param('text',"Hello World")
full_string = text + " %s" %rospy.get_time()
rate = rospy.Rate(freq)
while not rospy.is_shutdown():
    print full_string

now here is the weird part,

if i list out the parameters separately outside the node in the launch file it seems to work.


  <node name="hello_world_node" pkg="hello_world" type="" output="screen" />

  <param name="freq" value="0.5" />
  <param name="text" value="Hello World from Launch file" />


any idea why the second format works but the first one doesn't?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-01-18 23:16:21 -0600

cmcheung gravatar image

"You can also set private parameter across a group of nodes by using the ~param syntax (see ROS names) in a tag. The declared parameter will be set as a local parameter in the <node> tags that follow that are in the same scope (i.e. group or ns tag). "

You're making it a private param. In example 1, what do you get when you run the node and enter in the following command:

rosparam list

edit flag offensive delete link more


interesting, When i run only the node i don't get any parameters at all


this is what the command returns however when i run the example 1 launch file, i get

Anirudhkochhar gravatar image Anirudhkochhar  ( 2021-01-19 03:53:58 -0600 )edit

When you run only the node, there are no parameters that are being loaded.

In the output for example one, notice that the parameters exist, but they are under the name space /hello_world_node. So your code should be

 #initialising parameters
freq = rospy.get_param('/hello_world_node/freq',20)
text = rospy.get_param('/hello_world_node/text',"Hello World")

Or something to that effect. I can't guarantee that first slash is needed.

cmcheung gravatar image cmcheung  ( 2021-01-19 08:25:12 -0600 )edit

The syntax above accesses them with an absolute parameter name. You can also access private parameters by relative name with '~' syntax. For example:

freq = rospy.get_param('~freq`, 20)
tryan gravatar image tryan  ( 2021-01-22 08:28:43 -0600 )edit

thanks, that explains it rather well

Anirudhkochhar gravatar image Anirudhkochhar  ( 2021-01-22 10:22:19 -0600 )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

1 follower


Asked: 2021-01-18 21:53:17 -0600

Seen: 259 times

Last updated: Jan 18 '21