Unable to publish multiple static transformations using tf
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 = rospy.Time.now()
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
tf_broadcaster.sendTransform(static_transformStamped)
# infinite loop
rospy.spin()
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.