preferred way to broadcast transforms with rospy/tf2 (class vs. not)

asked 2017-07-05 16:20:24 -0500

jwhendy gravatar image

I'm going through the tf2 tutorials after finishing the tf tutorials and was struck by a pretty big deviation in the tf2 tutorials toward using a class:

class FixedTFBroadcaster:

    def __init__(self):
        self.pub_tf = rospy.Publisher('/tf', tf2_msgs.msg.TFMessage, queue_size=1)

        while not rospy.is_shutdown():

            t = geometry_msgs.msg.TransformStamped()                                  

            ### define TransformStamped() attributes

            tfm = tf2_msgs.msg.TFMessage([t])

if __name__ == '__main__':
    tfb = FixedTFBroadcaster()

I'm pretty new, but this looks like it's publishing a transform message to the /tf topic directly.

Just below in the next section, the tutorial walks through publishing a moving transform and uses "the old way" of a tf2_ros.TransformBroadcaster(), defines the same t TransformStamped() attributes, and then calls sendTransform(t).

  • Did I miss something about why one vs. the other? Is it preferred to define an object that appears to just replicate what sendTransform() already does?

  • Am I correct that these essentially do the same thing, adding the transform to the /tf tree

  • Perhaps the tutorial is just trying to illustrate that a fixed transform like carrot1 can be done a better way than the first round (and thus, one should prefer setting t once and then just sending it vs. defining it over and over in a less efficient way).

Thanks for any clarification.

edit retag flag offensive close merge delete