make_fixed_model.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 import sys
4 import os
5 import commands
6 
7 
8 def make_fixed_model (name, eusurdf_package_path=commands.getoutput('rospack find eusurdf'), overwrite=True):
9  urdf_dir_path = eusurdf_package_path + '/models/' + name
10  fixed_urdf_dir_path = urdf_dir_path + '_fixed'
11  urdf_path = urdf_dir_path + '/' + 'model.urdf'
12  fixed_urdf_path = fixed_urdf_dir_path + '/' + 'model.urdf'
13 
14  if overwrite:
15  os.system("rm -rf %s" % fixed_urdf_dir_path)
16  else:
17  if os.path.exists(fixed_urdf_dir_path):
18  print '[ERROR] the same name fixed model already exits'
19  exit(1)
20 
21  os.system("cp -r %s %s" % (urdf_dir_path, fixed_urdf_dir_path))
22 
23  root_link_name = commands.getoutput('grep "link name=".*">" %s | head -n 1 | sed -e "s/ <link name=\\\"\(.*\)\\\">/\\1/"' % fixed_urdf_path)
24  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))
25 
26  os.system('sed -i -e "s@<robot name=\\"\(.*\)\\"@<robot name=\\"\\1_fixed\\"@g\" %s' % fixed_urdf_path)
27 
28 
29 if __name__ == '__main__':
30  if len(sys.argv) > 2:
31  make_fixed_model(sys.argv[1], eusurdf_package_path=sys.argv[2])
32  elif len(sys.argv) > 1:
33  make_fixed_model(sys.argv[1])
def make_fixed_model(name, eusurdf_package_path=commands.getoutput('rospack find eusurdf'), overwrite=True)


eusurdf
Author(s): Kei Okada , Youhei Kakiuchi , Masaki Murooka
autogenerated on Mon May 4 2020 03:39:35