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

How to use txt file as a parameter to roslaunch file?

asked 2011-12-08 22:01:30 -0600

Felix Tr gravatar image

updated 2011-12-08 22:02:29 -0600

Hello All,

Background:

My idea is to receive not constant number of topics, to which I want to subscribe in my C code. I decided to do it in the next way: I will prepare a text file with the number and the name of the topics ---> convert it using launch file syntax to a string ---> parse the string in my C code ---> decide to which topics to subscribe.

In such a way I will only have to change the text file, while the launch file and the C code will not be changed.

Question:

I have written the next line of code in my launch file:

<param name="topics_list" textfile="$(find package_name)/file_name.txt"/>

And I have placed my text file in the appropriate folder. In my C file I do the next:

if ( nh.getParam("topics_list", topicsList) )
{
   ROS_INFO ("The contents of the file \"file_name.txt\" as a string are: %s\n",   
   topicsList); 
}
else
{
   ROS_INFO ("The topics list was not loaded succesfully. Aborting...\n");
   ros::shutdown();
}

It doesn´t work.

  1. Is my way correct?
  2. Why the above doesn´t work properly?

Thank you all in advance, Felix.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2011-12-08 22:15:52 -0600

dornhege gravatar image

updated 2011-12-12 23:37:01 -0600

If the textfile really is a list, you can actually make that a list of parameters, e.g. write a yaml file like:

topic_list:
 - topic1
 - topic2
 - topic3

and read in a list of parameters where you loaded that yaml in your launch.

If I name the file test.yaml and launch this test.launch:

<launch>
    <rosparam command="load" file="test.yaml" />
</launch>

It loads the parameters fine.

This page gives a code snippet to read in lists of parameters.

edit flag offensive delete link more

Comments

When I follow your instructions in this case, it doesn´t work. Are you sure, that the "yaml" file should be written that way?
Felix Tr gravatar image Felix Tr  ( 2011-12-12 23:16:12 -0600 )edit
I've added a sample launch file. For me this works fine. For proper projects the yaml should obvisouly be referenced by a package name.
dornhege gravatar image dornhege  ( 2011-12-12 23:37:54 -0600 )edit
Hi, thank you for your quick answer. I did it and I will try again, but how my "yaml" file should look like? In the same way you have suggested before? I have found a different suggestion here: "http://www.ros.org/wiki/roslaunch/XML/rosparam", do you have any comments about that
Felix Tr gravatar image Felix Tr  ( 2011-12-12 23:46:20 -0600 )edit
If you copy&paste the files I have in my post, it will work. The yaml file itself can look however you want in terms of structure, you can nest dictionaries and lists arbitrarily. The page you link to gives the yaml to rosparam, which should be equivalent than loading the same from a file.
dornhege gravatar image dornhege  ( 2011-12-12 23:48:52 -0600 )edit
Hi Dornhege, I think your suggestion worked well, except the last part...I have some problems there: http://answers.ros.org/question/3297/how-to-convert-xmlrpcxmlrpcvalue-into-string. If you have any idea, please let me know. - Felix Tr (0 mins ago)
Felix Tr gravatar image Felix Tr  ( 2011-12-13 05:01:55 -0600 )edit
-1

answered 2011-12-09 00:53:15 -0600

Felix Tr gravatar image

Hi Dornhege's

I have tried to do as you have advised. In particular, the appropriate code line in my launch file is:

<rosparam file="$(find guiPackageParametersToCallback)/topicList.yaml" command="load" />

But I receive a strange error, while launching this file:

error loading <rosparam> tag: 
    'param' attribute must be set for non-dictionary values XML is <rosparam command="load" file="$(find guiPackageParametersToCallback)/topicList.yaml"/>

I don´t understand the meaning of the error...

All the others:

Maybe there is a way to solve my problem in the initial way?

Thank you all, Felix.

edit flag offensive delete link more

Comments

It wants a name for the parameters you define. Either give the param attribute or you can set this directly in the yaml. I updated my post for this case.
dornhege gravatar image dornhege  ( 2011-12-09 04:09:50 -0600 )edit
Hi, I have looked at all your posts&answers and I could not find the mentioned post. I have also posted a new post connected to this issue: "http://answers.ros.org/question/3289/hoe-to-write-and-parse-yaml-file-for-ros" and I would be grateful to receive a comprehensive answer for it. Thank you :).
Felix Tr gravatar image Felix Tr  ( 2011-12-12 23:12:53 -0600 )edit
My post = my answer to this question.
dornhege gravatar image dornhege  ( 2011-12-12 23:33:55 -0600 )edit
Got it! You was completely right, about your explanation for the error. Thank you.
Felix Tr gravatar image Felix Tr  ( 2011-12-13 02:12:25 -0600 )edit

Question Tools

Stats

Asked: 2011-12-08 22:01:30 -0600

Seen: 3,635 times

Last updated: Dec 12 '11