rosparam: Different output format on vectors

asked 2020-12-08 00:08:23 -0500

holunder gravatar image

updated 2020-12-08 08:56:26 -0500

When running the same ros package on different machines, I'm facing an issue with the rosparam get output syntax.

In most cases, I get the vector syntax, but on one machine I get the list syntax as described here.

Machine 1 (List)

user@machine1:~/foo$ rosparam get /my_grp/my_var
- 1.5
- 2.5
- 2.8
- 2.5

Machine 2 (Vector)

user@machine2:~/foo$ rosparam get /my_grp/my_var
[1.5, 2.5, 2.8, 2.5]

Since I'm parsing the output in a bash script, this difference raises further issues.

I'm running the same version of python-yaml on both machines

python-yaml/xenial,now 3.11-3build1 amd64 [installed,automatic]

ROS-kinetic-rosparam is the same:

ros-kinetic-rosparam/xenial,now 1.12.17-1xenial-20201103-022214+0000 amd64 [installed,automatic]

Furthermore, when setting a parameter on machine 1, I get a yaml warning:

user@machine1:~/foo$ rosparam set /my_grp/my_var_scalar 2
/opt/ros/kinetic/lib/python2.7/dist-packages/rosparam/__init__.py:375: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  set_param_raw(param, yaml.load(value), verbose=verbose)

What's the reason for different outputs of rosparam? Thanks in advance

Update 2020-12-08

I've further checked the yaml by running following piece of python code on both machines

import yaml as y
print(y.__version__)

Which returns 3.11 on machine 2 and 5.1.1 on machine 2. As mentioned above the apt package is 3.1.1 on both machines. Furthermore, on machine 2, there is PyYAML installed within pip.

So, i would like to rephrase the question: Whats the correct way to define the version of python-yaml (resp. PyYAML) to be used within ROS kinetic?

edit retag flag offensive close merge delete

Comments

just a question, why do you need to use a bash script, and cannot use a simple ROS (python) node? There it would be easy to do...

mgruhler gravatar image mgruhler  ( 2020-12-08 02:05:40 -0500 )edit

Already thought in this way, in my case running a bash script seems beneficial as I want to iterate over different parameter sets and record rosbags with them.

holunder gravatar image holunder  ( 2020-12-08 02:09:07 -0500 )edit

Added an update to the question

holunder gravatar image holunder  ( 2020-12-08 08:56:37 -0500 )edit
1

If you have a pip installed version of PyYAML, then it would seem to be expected the output is different between the two.

If that pip installed version is present on the PYTHONPATH your interpreter is going to find it.

gvdhoorn gravatar image gvdhoorn  ( 2020-12-08 10:11:41 -0500 )edit

python-yaml (installed by apt) is installed in /usr/lib/python2.7/dist-packages/yaml (Location found via dpkg -L python-yaml) So putting this path at the start of PYTHONPATH helped:

export PYTHONPATH="/usr/lib/python2.7/dist-packages:$PYTHONPATH"

Thanks.

holunder gravatar image holunder  ( 2020-12-08 23:38:07 -0500 )edit