Go to the documentation of this file.00001
00002
00003 import sys
00004 import os
00005 import commands
00006
00007
00008 def eus2urdf_for_gazebo_pyscript (name, collada_path, overwrite=True):
00009
00010 urdf_dir_path = commands.getoutput('rospack find hrpsys_gazebo_tutorials') + '/environment_models/' + name
00011 if overwrite:
00012 os.system("rm -rf %s" % urdf_dir_path)
00013 else:
00014 print "[eus2urdf] check if the same name model already exits"
00015 if os.path.exists(urdf_dir_path):
00016 print '[ERROR eus2urdf] the same name model already exits'
00017 exit(1)
00018
00019 print "[eus2urdf] make directory for urdf"
00020 os.mkdir(urdf_dir_path)
00021
00022 add_line_string = '<uri>file://%s</uri>' % name
00023 manifest_path = '%s/../manifest.xml' % urdf_dir_path
00024 if len(commands.getoutput("grep %s %s" % (add_line_string, manifest_path))) == 0:
00025 print "[eus2urdf] add file path to manifest.xml"
00026 os.system('sed -i -e \"s@ </models>@ %s\\n </models>@g\" %s' % (add_line_string, manifest_path))
00027
00028 print "[eus2urdf] make model.config in urdf directory"
00029 config_path = '%s/model.config' % urdf_dir_path
00030 os.system('echo "<?xml version=\'1.0\'?>\n<model>\n <name>%s</name>\n <version>0.1.0</version>\n <sdf>model.urdf</sdf>\n <description>\n This model was automatically generated by converting the eus model.\n </description>\n</model>\n" > %s' % (name, config_path))
00031
00032 print "[eus2urdf] convert collada to urdf"
00033 meshes_path = urdf_dir_path + '/meshes'
00034 urdf_path = urdf_dir_path + '/' + 'model.urdf'
00035 os.mkdir(meshes_path)
00036 os.system('rosrun collada_urdf_jsk_patch collada_to_urdf %s -G -A --mesh_output_dir %s --mesh_prefix "model://%s/meshes" -O %s' % (collada_path, meshes_path, name, urdf_path))
00037 os.system('sed -i -e "s@continuous@revolute@g" %s' % urdf_path)
00038 os.system('sed -i -e \"s@<robot name=\\"inst_kinsystem\\"@<robot name=\\"%s\\"@g\" %s' % (name, urdf_path))
00039 os.system('sed -i -e \"1,/ <link /s/ <link / <gazebo>\\n <static>false<\/static>\\n <\/gazebo>\\n <link /\" %s' % urdf_path)
00040
00041
00042 os.system('sed -i -e \"s@ <inertia ixx=\\\"1e-09\\\" ixy=\\\"0\\\" ixz=\\\"0\\\" iyy=\\\"1e-09\\\" iyz=\\\"0\\\" izz=\\\"1e-09\\\"/>@ <inertia ixx=\\\"1e-03\\\" ixy=\\\"0\\\" ixz=\\\"0\\\" iyy=\\\"1e-03\\\" iyz=\\\"0\\\" izz=\\\"1e-03\\\"/>@g\" %s' % urdf_path)
00043
00044
00045
00046 if __name__ == '__main__':
00047 if len(sys.argv) > 2:
00048 eus2urdf_for_gazebo_pyscript(sys.argv[1], sys.argv[2])