Ask Your Question
1

roslaunch parameter has additional newlines when set using command=

asked 2015-10-01 03:08:45 -0600

Felix Duvallet gravatar image

I'm trying to set a ROS parameter in a launch file. The parameter is the file path to some resource, so that it can be used by the node later:

param.launch

<launch>
    <param name="filename"
     type="str"
     command="$(find param_pkg)/scripts/param.py"
     />
</launch>

The python script finds the file and prints its location:

param.py

#! /usr/bin/python
print('/path/to/file')

The python script works fine, and just prints the file location (with no additional whitespace):

$ rosrun param_pkg param.py:

/path/to/file

However, the parameter set by the launch file gets a trailing newline and some additional ticks:

$ rosparam get /filename

'/path/to/file

  '

(note the two lines.) If I set the parameter manually (value=), there are no additional ticks or whitespace: $ rosparam get filename_manual:

/path/to/file

Why is this whitespace present only when I set the roslaunch parameter by running a python command, and how can I get it to be the same value as manually setting the param value?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-11-23 12:16:37 -0600

Magnus gravatar image

updated 2020-11-23 12:16:51 -0600

It because your python script is printing with newline endings. Print without a newline.

Python 2:

sys.stdout.write("/path/to/file")

Python 3:

print("/path/to/file", end = '')
edit flag offensive delete link more

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

Stats

Asked: 2015-10-01 03:08:45 -0600

Seen: 181 times

Last updated: Nov 23 '20