Robotics StackExchange | Archived questions

roslaunch parameter has additional newlines when set using command=

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?

Asked by Felix Duvallet on 2015-10-01 03:08:45 UTC

Comments

Answers

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 = '')

Asked by Magnus on 2020-11-23 13:16:37 UTC

Comments