34 generate the srdf according to the urdf 35 syntax generate_hand_srdf [output filename] 40 from xml.dom.minidom
import parse
45 from rosgraph.names
import load_mappings
51 def __init__(self, urdf_str=None, load=True, save=True):
53 while not rospy.has_param(
'robot_description'):
55 rospy.loginfo(
"waiting for robot_description")
58 urdf_str = rospy.get_param(
'robot_description')
60 robot = URDF.from_xml_string(urdf_str)
62 extracted_prefix =
False 64 ff = mf = rf = lf = th =
False 67 hand_name =
"right_hand" 70 for key
in robot.link_map:
71 link = robot.link_map[key]
73 if hasattr(link.visual.geometry,
'filename'):
74 filename = os.path.basename(link.visual.geometry.filename)
75 if filename ==
"biotac_decimated.dae":
79 for key
in robot.joint_map:
81 if not extracted_prefix:
82 prefix = key.split(
"_")[0] +
"_" 83 rospy.loginfo(
"Found prefix:" + prefix)
84 extracted_prefix =
True 86 hand_name =
"left_hand" 88 if not ff
and key.endswith(
"FFJ4"):
90 if not mf
and key.endswith(
"MFJ4"):
92 if not rf
and key.endswith(
"RFJ4"):
94 if not lf
and key.endswith(
"LFJ4"):
96 if not th
and key.endswith(
"THJ4"):
98 if is_lite
and key.endswith(
"WRJ2"):
101 rospy.logdebug(
"Found fingers (ff mf rf lf th)" + str(ff) + str(mf) + str(rf) + str(lf) + str(th))
102 rospy.logdebug(
"is_lite: " + str(is_lite))
103 rospy.logdebug(
"is_biotac: " + str(is_biotac))
104 rospy.logdebug(
"Hand name: " + str(hand_name))
106 mappings = load_mappings([
'prefix:=' + str(prefix),
107 'robot_name:=' + robot.name,
108 'ff:=' + str(int(ff)),
109 'mf:=' + str(int(mf)),
110 'rf:=' + str(int(rf)),
111 'lf:=' + str(int(lf)),
112 'th:=' + str(int(th)),
113 'is_lite:=' + str(int(is_lite)),
114 'is_biotac:=' + str(int(is_biotac)),
115 'hand_name:=' + str(hand_name)
119 rospack = rospkg.RosPack()
120 package_path = rospack.get_path(
'sr_moveit_hand_config')
121 srdf_xacro_filename = package_path +
"/config/shadowhands_prefix.srdf.xacro" 122 rospy.loginfo(
"File loaded " + srdf_xacro_filename)
125 srdf_xacro_file = open(srdf_xacro_filename,
'r') 132 if len(sys.argv) > 1:
133 OUTPUT_PATH = sys.argv[1]
135 if (OUTPUT_PATH.startswith(
"_")
or 136 OUTPUT_PATH.startswith(
"--")):
142 rospy.loginfo(
"Loading SRDF on parameter server")
143 robot_description_param = rospy.resolve_name(
'robot_description') +
"_semantic" 144 rospy.set_param(robot_description_param,
145 self.srdf_xacro_xml.toprettyxml(indent=
' '))
147 OUTPUT_PATH = package_path +
"/config/generated_shadowhand.srdf" 148 FW = open(OUTPUT_PATH,
"wb")
149 FW.write(self.srdf_xacro_xml.toprettyxml(indent=
' '))
152 OUTPUT_PATH = package_path +
"/config/generated_shadowhand.urdf" 153 FW = open(OUTPUT_PATH,
"wb")
157 srdf_xacro_file.close()
162 if __name__ ==
'__main__':
163 rospy.init_node(
'hand_srdf_generator', anonymous=
True)
def process_includes(elt, macros=None, symbols=None)
def process_doc(doc, in_order=False, just_deps=False, just_includes=False, mappings=None, xacro_ns=True, kwargs)
def __init__(self, urdf_str=None, load=True, save=True)