Go to the documentation of this file.00001
00002 """
00003 Publish specific transform between two links within a SDF file as 'static' tf transformation (with different name)
00004 """
00005
00006 import argparse
00007
00008 import rospy
00009 import tf
00010 import tf_conversions.posemath as pm
00011 from tf.transformations import *
00012
00013 import pysdf
00014
00015
00016
00017 def main():
00018 parser = argparse.ArgumentParser()
00019 parser.add_argument('-f', '--freq', type=float, default=10, help='Frequency TFs are published (default: 10 Hz)')
00020 parser.add_argument('sdf', help='SDF model to publish (e.g. coke_can)')
00021 parser.add_argument('source_from_tf', help='Base Frame from SDF')
00022 parser.add_argument('source_to_tf', help='Target Frame from SDF')
00023 parser.add_argument('target_from_tf', nargs='?', help='Published Base Frame')
00024 parser.add_argument('target_to_tf', nargs='?', help='Published Target Frame')
00025 args = parser.parse_args(rospy.myargv()[1:])
00026 source_from_tf, source_to_tf = args.source_from_tf, args.source_to_tf
00027 target_from_tf = args.target_from_tf if args.target_from_tf else source_from_tf
00028 target_to_tf = args.target_to_tf if args.target_to_tf else source_to_tf
00029
00030 rospy.init_node('sdf2extract_tfstatic')
00031
00032 sdf = pysdf.SDF(model=args.sdf)
00033 world = sdf.world
00034 from_link = world.get_link(source_from_tf)
00035 if not from_link:
00036 rospy.logerr('SDF %s does not contain source_from_tf %s' % (args.sdf, source_from_tf))
00037 return 1
00038 to_link = world.get_link(source_to_tf)
00039 if not to_link:
00040 rospy.logerr('SDF %s does not contain source_to_tf %s' % (args.sdf, source_to_tf))
00041 return 2
00042
00043 from_to_tf = concatenate_matrices(inverse_matrix(from_link.pose_world), to_link.pose_world)
00044 translation, quaternion = pysdf.homogeneous2translation_quaternion(from_to_tf)
00045
00046 tfBroadcaster = tf.TransformBroadcaster()
00047
00048 rospy.loginfo('Publishing TF %s -> %s from SDF %s as TF %s -> %s: t=%s q=%s' % (source_from_tf, source_to_tf, args.sdf, target_from_tf, target_to_tf, translation, quaternion))
00049 rospy.loginfo('Spinning')
00050 r = rospy.Rate(args.freq)
00051 while not rospy.is_shutdown():
00052 tfBroadcaster.sendTransform(translation, quaternion, rospy.get_rostime(), target_to_tf, target_from_tf)
00053 r.sleep()
00054
00055
00056 if __name__ == '__main__':
00057 main()