Robotics StackExchange | Archived questions

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

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():
            rospy.sleep(0.1)

            t = geometry_msgs.msg.TransformStamped()                                  

            ### define TransformStamped() attributes

            tfm = tf2_msgs.msg.TFMessage([t])
            self.pub_tf.publish(tfm)

if __name__ == '__main__':
    rospy.init_node('my_tf2_broadcaster')
    tfb = FixedTFBroadcaster()
    rospy.spin()

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).

Thanks for any clarification.

Asked by jwhendy on 2017-07-05 16:20:24 UTC

Comments

Answers