Go to the documentation of this file.00001
00002
00003 import sys
00004 import os
00005 import commands
00006
00007
00008 def make_fixed_model (name, overwrite=True):
00009
00010 urdf_dir_path = commands.getoutput('rospack find hrpsys_gazebo_tutorials') + '/environment_models/' + name
00011 fixed_urdf_dir_path = urdf_dir_path + '_fixed'
00012 urdf_path = urdf_dir_path + '/' + 'model.urdf'
00013 fixed_urdf_path = fixed_urdf_dir_path + '/' + 'model.urdf'
00014
00015 if overwrite:
00016 os.system("rm -rf %s" % fixed_urdf_dir_path)
00017 else:
00018 if os.path.exists(fixed_urdf_dir_path):
00019 print '[ERROR] the same name fixed model already exits'
00020 exit(1)
00021
00022 os.system("cp -r %s %s" % (urdf_dir_path, fixed_urdf_dir_path))
00023
00024 root_link_name = commands.getoutput('grep "link name=".*">" %s | head -n 1 | sed -e "s/ <link name=\\\"\(.*\)\\\">/\\1/"' % fixed_urdf_path)
00025 os.system('sed -i -e \"s@</robot>@ <!-- Used for fixing robot to Gazebo \'base_link\' -->\\n <link name=\\\"world\\\"/>\\n <joint name=\\\"fixed\\\" type=\\\"fixed\\\">\\n <parent link=\\\"world\\\"/>\\n <child link=\\\"%s\\\"/>\\n </joint>\\n</robot>@g\" %s' % (root_link_name, fixed_urdf_path))
00026
00027 os.system('sed -i -e "s@<robot name=\\"\(.*\)\\"@<robot name=\\"\\1_fixed\\"@g\" %s' % fixed_urdf_path)
00028
00029
00030 if __name__ == '__main__':
00031 if len(sys.argv) > 1:
00032 make_fixed_model(sys.argv[1])