make_urdf_static_model_for_gazebo.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 import sys
00004 import os
00005 import commands
00006 
00007 
00008 def make_static_model (name, urdf_path = (os.getenv("HOME") + "/.gazebo/models"), overwrite=True):
00009 
00010     urdf_dir_path = urdf_path + "/" + name
00011     static_urdf_dir_path = urdf_dir_path + '_static'
00012     urdf_path = urdf_dir_path + '/' + 'model.urdf'
00013     static_urdf_path = static_urdf_dir_path + '/' + 'model.urdf'
00014 
00015     if overwrite:
00016         os.system("rm -rf %s" % static_urdf_dir_path)
00017     else:
00018         if os.path.exists(static_urdf_dir_path):
00019             print '[ERROR] the same name static model already exits'
00020             exit(1)
00021     
00022     os.system("cp -r %s %s" % (urdf_dir_path, static_urdf_dir_path))
00023 
00024     if len(commands.getoutput("grep \"<static>false</static>\" %s" % static_urdf_path)) != 0:
00025         os.system('sed -i -e \"s@<static>false</static>@<static>true</static>@g\" %s' % static_urdf_path)
00026     elif len(commands.getoutput("grep \"<static>true</static>\" %s" % static_urdf_path)) == 0:
00027         os.system('sed -i -e \"s@  <link @  <gazebo>\\n    <static>true</static>\\n  </gazebo>\\n  <link @g\" %s' % static_urdf_path)
00028         # os.system('sed -i -e \"s@</robot>@  <gazebo>\\n    <static>true</static>\\n  </gazebo>\\n</robot>@g\" %s' % static_urdf_path)
00029 
00030     os.system('sed -i -e "s@<robot name=\\"\(.*\)\\"@<robot name=\\"\\1_static\\"@g\" %s' % static_urdf_path)
00031 
00032 
00033 if __name__ == '__main__':
00034     if len(sys.argv) > 2:
00035         make_static_model(sys.argv[1], sys.argv[2])
00036     elif len(sys.argv) > 1:
00037         make_static_model(sys.argv[1])


eusgazebo
Author(s): Masaki Murooka
autogenerated on Wed Sep 16 2015 10:54:41