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

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.

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

this is my launch file.

and below is my node hello_world

#! /usr/bin/env python

import rospy
rospy.init_node("hello_world")


#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
    rate.sleep()

now here is the weird part,

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

<launch>

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

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

</launch>

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
0

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

cmcheung gravatar image

http://wiki.ros.org/roslaunch/XML/param

"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

Comments

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

/rosdistro
/rosversion
/run_id

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

/hello_world_node/freq
/hello_world_node/text
/rosdistro
/roslaunch/uris/host_anirudh
/rosversion
/run_id
Anirudhkochhar gravatar image Anirudhkochhar  ( 2021-01-19 03:53:58 -0600 )edit
1

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

Question Tools

1 follower

Stats

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

Seen: 861 times

Last updated: Jan 18 '21