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

Supplying filename arguments to launch files

asked 2015-06-25 11:55:23 -0500

kamek gravatar image

I have a node that has a filename as a private parameter. The files can be located anywhere and have really long filenames. What I would like to do is

$ roslaunch package_name launch_file.launch file:=reallylongfilename12345932.txt

where I running this command from the directory containing the file, so I can take advantage of tab-completing the filenames. I have an arg in my launch file called file that accepts this filename, but not the path. As a result, my node cannot open the file because it doesn't have the full path, just the name.

Short of hardcoding in the path in the launch file, and being able to tab-complete the long file names, is there a way I can pass the full path of the file to my parameter?

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
3

answered 2015-06-25 17:32:29 -0500

Maxim Rovbo gravatar image

You can create a script that takes the name of the file as a parameter and forms the correct roslaunch call with the full path. So, if you have a package "mypackage", a launchfile "test.launch", than you could create a script mypackage/scripts/helper.bash :

#!/bin/bash

if [ "$1" != "" ]; then
  echo "Full path to the file:"
  echo "$PWD/$1"

  roslaunch mypackage test.launch file:="$PWD/$1"
else 
  echo "$0: file not specified"
fi

If you want to pass the filename "filename" from the local directory you could use the following command :

rosrun mypackage helper.bash filename
edit flag offensive delete link more

Comments

Thanks, this is actually the approach I had taken but I was checking if there was some built-in functionality I didn't know about. Thanks again!

kamek gravatar image kamek  ( 2015-06-29 11:32:45 -0500 )edit
1

answered 2015-06-25 12:45:48 -0500

Thomas D gravatar image

When using roslaunch it starts all nodes thinking they are in your ~/.ros/ directory. So you can create a symlink in your ~/.ros/ directory to the actual file you want to load. Then set your arg to look at the symlink by default. When creating the symlink you will be able to use tab completion.

edit flag offensive delete link more
0

answered 2020-06-30 09:19:08 -0500

anonymous user

Anonymous

I found this way to pass the current shell path to the xml launch file:

<arg name="file_path"  default="$(env PWD)"/>

and then the file name to read

<arg name="file_name"  default="file_name"/>

Finally, I pass the file name as a parameter to my C++ package:

<node pkg="pkg_name"  type="node_type"    name="node_name"  output="screen" >
   <param name="file_name"  value="$(arg file_name)"  type="string" />
</node>

Then, I use these arguments as entries for a C++ file in which I concatenate the two arguments.

Note : I get the value of these arguments in my C++ program through

std::string path, file;
ros::param::get("/node_name/file_path", path);
ros::param::get("/node_name/file_name", file);

I am using Ubuntu 18.04 with ROS Melodic. Hope it can help.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2015-06-25 11:55:23 -0500

Seen: 2,047 times

Last updated: Jun 25 '15