ros / geometry

Packages for common geometric calculations including the ROS transform library, "tf". Also includes ROS bindings for "bullet" physics engine and "kdl" kinematics/dynamics package.
173 stars 275 forks source link

`getFrameStrings()` fails if it called just after `rospy.init_node()` from tf 1.11.9 #152

Closed k-okada closed 7 years ago

k-okada commented 7 years ago

I have travous on tf 1.11.9, where getFrameStrings() fails if it called just after rospy.init_node()

$ ./hoge.py 
Traceback (most recent call last):
  File "./hoge.py", line 8, in <module>
    print tflistener.getFrameStrings()
  File "/opt/ros/indigo/lib/python2.7/dist-packages/tf/listener.py", line 98, in getFrameStrings
    return [p for p, _ in data.items()]

the code is

$ cat hoge.py 
#!/usr/bin/env python

import rospy
import tf
import time
rospy.init_node('test_tf')
tflistener = tf.TransformListener()
#time.sleep(1)
print tflistener.getFrameStrings()

and if we comment in time.sleep() then it works ok.This does not happens on 1.11.8, so maybe because of #149. I do not well understand how tflistener.getFrameStrings called on 1.11.8, but for example, we can avoid this problem by.

    def getFrameStrings(self):
        """ Not a recommended API, only here for backwards compatibility """
        data = yaml.load(self._buffer.all_frames_as_yaml())
        return data and [p for p, _ in data.items()]
tfoote commented 7 years ago

Ahh, if there's no data, by default the yaml parser creates a list but if there's data it's a dict. PS As that's a deprecated API please switch to one of the supported ones like: allFramesAsString()