send_urdf_fragment.py
Go to the documentation of this file.
00001 #!/usr/bin/python2
00002 
00003 # Copyright (c) 2013-2015, Rethink Robotics
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions are met:
00008 #
00009 # 1. Redistributions of source code must retain the above copyright notice,
00010 #    this list of conditions and the following disclaimer.
00011 # 2. Redistributions in binary form must reproduce the above copyright
00012 #    notice, this list of conditions and the following disclaimer in the
00013 #    documentation and/or other materials provided with the distribution.
00014 # 3. Neither the name of the Rethink Robotics nor the names of its
00015 #    contributors may be used to endorse or promote products derived from
00016 #    this software without specific prior written permission.
00017 #
00018 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00022 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 # POSSIBILITY OF SUCH DAMAGE.
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     # The updating the time parameter tells
00058     # the robot that this is a new configuration.
00059     # Only update the time when an updated internal
00060     # model is required. Do not continuously update
00061     # the time parameter.
00062     msg.time = rospy.Time.now()
00063     # link to attach this urdf to onboard the robot
00064     msg.link = parent_link
00065     # root linkage in your URDF Fragment
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) # 5hz
00070     while not rospy.is_shutdown():
00071         # Only one publish is necessary, but here we
00072         # will continue to publish until ctrl+c is invoked
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())


baxter_examples
Author(s): Rethink Robotics Inc.
autogenerated on Sat Jun 8 2019 20:16:28