Ask Your Question

Unable to publish multiple static transformations using tf

asked 2018-04-04 06:08:06 -0600

Ravi Joshi gravatar image

I have 10 static transformations. Each one is saved in a separate yaml file. I want to publish these transformations using StaticTransformBroadcaster. Please see the code snippet below-

def main():
    # create tf static transform broadcaster
    tf_broadcaster = tf2_ros.StaticTransformBroadcaster()

    for i in range(10):
        calibFile = str(i) + '_calibration.yaml'

        with open(calibFile, 'r') as f:
            params = yaml.load(f)

        static_transformStamped = TransformStamped()

        static_transformStamped.header.stamp =
        static_transformStamped.header.frame_id = params['parent']
        static_transformStamped.child_frame_id = params['child']

        static_transformStamped.transform.translation = params['trans']
        static_transformStamped.transform.rotation = params['rot']

        # publish static transformation

    # infinite loop

Iteratively I am reading each transform and then by using tf, I am trying to publish them. However, the above code doesn't work. It just publishes the last transform only.

My objective is to publish all static transformations. I am using ROS Indigo on Ubuntu 14.04 LTS OS.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2018-04-04 06:55:15 -0600

gvdhoorn gravatar image

updated 2018-04-04 13:00:39 -0600

I believe you're running into a peculiarity / TF2 specific characteristic of static transform publishers. From #q261815:

Since it's a latched topic it's recommended to only have one Static Transform Publisher per process.

You can resolve this by sending multiple transforms at once via a single broadcaster.

edit flag offensive delete link more



Thanks a lot. It worked like a charm.

Ravi Joshi gravatar imageRavi Joshi ( 2018-04-04 21:41:12 -0600 )edit

answered 2018-04-04 12:07:44 -0600

Gayan Brahmanage gravatar image

updated 2018-04-04 12:09:54 -0600

Try with the following piece of codes

import rospy
import roslib
import tf

def handle_transform(parent, child, tr):
    br.sendTransform((tr[0], tr[1], 0), tf.transformations.quaternion_from_euler(0, 0, tr[2]),, child,parent)

if __name__ == "__main__":

    rospy.init_node('tfpublisher', anonymous=True) #make node
    rate = rospy.Rate(10) # 5hz

    br = tf.TransformBroadcaster() 
    while not rospy.is_shutdown():

        handle_transform("base_link", "scans", [0,0,0])     

edit flag offensive delete link more


This seems to use tf, not tf2. Static transforms are handled differently between the two.

gvdhoorn gravatar imagegvdhoorn ( 2018-04-04 13:00:24 -0600 )edit

Thank you very much. I upvoted your suggestion. However, it is better to use StaticTransformBroadcaster from tf2.

Ravi Joshi gravatar imageRavi Joshi ( 2018-04-04 21:42:53 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2018-04-04 06:08:06 -0600

Seen: 974 times

Last updated: Apr 04 '18