Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 import os
00031 import sys
00032 import argparse
00033
00034 import rospy
00035 import xacro_jade
00036
00037 from baxter_core_msgs.msg import (
00038 URDFConfiguration,
00039 )
00040
00041 def xacro_parse(filename):
00042 doc = xacro_jade.parse(None, filename)
00043 xacro_jade.process_doc(doc, in_order=True)
00044 return doc.toprettyxml(indent=' ')
00045
00046 def send_urdf(parent_link, root_joint, urdf_filename):
00047 """
00048 Send the URDF Fragment located at the specified path to
00049 modify the electric gripper on Baxter.
00050
00051 @param parent_link: parent link to attach the URDF fragment to
00052 (usually <side>_hand)
00053 @param root_joint: root link of the URDF fragment (usually <side>_gripper_base)
00054 @param urdf_filename: path to the urdf XML file to load into xacro and send
00055 """
00056 msg = URDFConfiguration()
00057
00058
00059
00060
00061
00062 msg.time = rospy.Time.now()
00063
00064 msg.link = parent_link
00065
00066 msg.joint = root_joint
00067 msg.urdf = xacro_parse(urdf_filename)
00068 pub = rospy.Publisher('/robot/urdf', URDFConfiguration, queue_size=10)
00069 rate = rospy.Rate(5)
00070 while not rospy.is_shutdown():
00071
00072
00073 pub.publish(msg)
00074 rate.sleep()
00075
00076 def main():
00077 """RSDK URDF Fragment Example:
00078 This example shows a proof of concept for
00079 adding your URDF fragment to the robot's
00080 onboard URDF (which is currently in use).
00081 """
00082 arg_fmt = argparse.RawDescriptionHelpFormatter
00083 parser = argparse.ArgumentParser(formatter_class=arg_fmt,
00084 description=main.__doc__)
00085 required = parser.add_argument_group('required arguments')
00086 required.add_argument(
00087 '-f', '--file', metavar='PATH', required=True,
00088 help='Path to URDF file to send'
00089 )
00090 required.add_argument(
00091 '-l', '--link', required=False, default="left_hand",
00092 help='URDF Link already to attach fragment to (usually <left/right>_hand)'
00093 )
00094 required.add_argument(
00095 '-j', '--joint', required=False, default="left_gripper_base",
00096 help='Root joint for fragment (usually <left/right>_gripper_base)'
00097 )
00098 args = parser.parse_args(rospy.myargv()[1:])
00099
00100 rospy.init_node('rsdk_configure_urdf', anonymous=True)
00101
00102 if not os.access(args.file, os.R_OK):
00103 rospy.logerr("Cannot read file at '%s'" % (args.file,))
00104 return 1
00105 send_urdf(args.link, args.joint, args.file)
00106 return 0
00107
00108 if __name__ == '__main__':
00109 sys.exit(main())