sdf2tfstatic_node.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 """
00003 Publish all links within a SDF file as 'static' tf transformation
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 submodelsToBeIgnored = []
00016 tfBroadcaster = None
00017 world = None
00018 tfs = []
00019 
00020 
00021 def calculate_tfs(prefix):
00022   world.for_all_joints(calculate_joint_tf)
00023   for tf in tfs:
00024     tf[0] = prefix + pysdf.sdf2tfname(tf[0])
00025     tf[1] = prefix + pysdf.sdf2tfname(tf[1])
00026 
00027 
00028 def calculate_joint_tf(joint, full_jointname):
00029   full_prefix = full_jointname.replace(joint.name, '')
00030   rel_tf = concatenate_matrices(inverse_matrix(joint.tree_parent_link.pose_world), joint.tree_child_link.pose_world)
00031   translation, quaternion = pysdf.homogeneous2translation_quaternion(rel_tf)
00032   tfs.append([full_prefix + joint.parent, full_prefix + joint.child, translation, quaternion])
00033 
00034 
00035 def publish_tf():
00036   for tf in tfs:
00037     #print(tf)
00038     tfBroadcaster.sendTransform(tf[2], tf[3], rospy.get_rostime(), tf[1], tf[0])
00039 
00040 
00041 def main():
00042   parser = argparse.ArgumentParser()
00043   parser.add_argument('-f', '--freq', type=float, default=10, help='Frequency TFs are published (default: 10 Hz)')
00044   parser.add_argument('-p', '--prefix', default='', help='Publish with prefix')
00045   parser.add_argument('sdf', help='SDF model to publish (e.g. coke_can)')
00046   args = parser.parse_args(rospy.myargv()[1:])
00047 
00048   rospy.init_node('sdf2tfstatic')
00049 
00050   global submodelsToBeIgnored
00051   submodelsToBeIgnored = rospy.get_param('~ignore_submodels_of', '').split(';')
00052   rospy.loginfo('Ignoring submodels of: ' + str(submodelsToBeIgnored))
00053 
00054   global tfBroadcaster
00055   tfBroadcaster = tf.TransformBroadcaster()
00056 
00057   global world
00058   sdf = pysdf.SDF(model=args.sdf)
00059   world = sdf.world
00060 
00061   calculate_tfs(args.prefix)
00062 
00063   rospy.loginfo('Spinning')
00064   r = rospy.Rate(args.freq)
00065   while not rospy.is_shutdown():
00066     publish_tf();
00067     r.sleep()
00068 
00069 
00070 if __name__ == '__main__':
00071   main()


gazebo2rviz
Author(s): Andreas Bihlmaier
autogenerated on Mon Oct 6 2014 17:26:45