def __init__(self,
difficulty=1.0,
texturedir='/tmp/mujoco_textures',
hfield_dir='/tmp/mujoco_terrains',
regen_terrain=True,
*args, **kwargs):
Serializable.quick_init(self, locals())
self.difficulty = max(difficulty, self.MIN_DIFFICULTY)
self.texturedir = texturedir
self.hfield_dir = hfield_dir
model_cls = self.__class__.MODEL_CLASS
if model_cls is None:
raise "MODEL_CLASS unspecified!"
template_file_name = 'hill_' + model_cls.__module__.split('.')[-1] + '.xml.mako'
template_options=dict(
difficulty=self.difficulty,
texturedir=self.texturedir,
hfield_file=os.path.join(self.hfield_dir, self.HFIELD_FNAME))
file_path = os.path.join(MODEL_DIR, template_file_name)
lookup = mako.lookup.TemplateLookup(directories=[MODEL_DIR])
with open(file_path) as template_file:
template = mako.template.Template(
template_file.read(), lookup=lookup)
content = template.render(opts=template_options)
tmp_f, file_path = tempfile.mkstemp(text=True)
with open(file_path, 'w') as f:
f.write(content)
if self._iam_terrain_generator(regen_terrain):
self._gen_terrain(regen_terrain)
os.remove(self._get_lock_path())
inner_env = model_cls(*args, file_path=file_path, **kwargs) # file to the robot specifications
ProxyEnv.__init__(self, inner_env) # here is where the robot env will be initialized
os.close(tmp_f)
评论列表
文章目录