Skip to content

Commit

Permalink
Modified env.py to reflect new mujoco env wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
yidingjiang committed Jul 18, 2019
1 parent fa898c2 commit 8ed78b0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 35 deletions.
33 changes: 17 additions & 16 deletions assets/clevr_default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,27 @@
<joint name='obj3_slidex' type='slide' pos='0 0 0' axis='1 0 0' range='-10.3213 10.3' damping='0.5'/>
</body>

<body name='r_wrist_flex_link' pos='0 0.8 -0.1'>
<geom name='wf' type='capsule' fromto='0 -0.05 0 0 0.05 0' size='0.01' />
<joint name='r_wrist_flex_joint_y' type='slide' pos='0 0 0' axis='0 1 0' range='-10.3213 10.3' damping='.1' />
<joint name='r_wrist_flex_joint_x' type='slide' pos='0 0 0' axis='1 0 0' range='-10.3213 10.3' damping='.1' />
<body name='r_wrist_roll_link' pos='0 0 0'>
<joint name='r_wrist_roll_joint' type='hinge' pos='0 0 0' limited='true' axis='1 0 0' damping='0.1' range='-1.5 1.5'/>
<body name='tips_arm' pos='0 0 0'>
<geom name='tip_arml' type='sphere' pos='-0.1 0 -0.1' size='0.01' />
<geom name='tip_armr' type='sphere' pos='0.1 0 -0.1' size='0.01' />
</body>
<geom type='capsule' fromto='-0.1 0 0. +0.1 0 0' size='0.02' contype='1' conaffinity='1' />
<geom type='capsule' fromto='-0.1 0. 0 -0.1 0 -0.1' size='0.02' contype='1' conaffinity='1' />
<geom type='capsule' fromto='0.1 0. 0 0.1 0 -0.1' size='0.02' contype='1' conaffinity='1' />
</body>
<body pos='-0.4793 -0.1582 -0.2228' name='obj3'>
<geom size='0.1021 0.1021 0.1021' conaffinity='1' contype='1' density='1' rgba='0.2 1 0 1' type='box'/>
<joint pos='0 0 0' damping='0.75' type='free' limited='false' name='obj3_slide'/>
</body>

<body pos='0.3660 0.4967 -0.2166' name='obj4'>
<geom size='0.1083 0.0902 0.05' conaffinity='1' contype='1' density='1' rgba='0.2 1 0 1' type='box'/>
<joint pos='0 0 0' damping='0.75' type='free' limited='false' name='obj4_slide'/>
</body>

<body pos='0.469675315258 -0.205294383583 -0.2' name='point_mass'>
<geom type='sphere' contype='1' conaffinity='0' rgba='1 1 1 1' density='0.5' size='0.05' name='pm'/>
<joint type='slide' axis='1 0 0' damping='0.5' pos='0 0 0' name='pm_joint_x' range='-10.3213 10.3'/>
<joint type='slide' axis='0 1 0' damping='0.5' pos='0 0 0' name='pm_joint_y' range='-10.3213 10.3'/>
</body>

</worldbody>

<actuator>
<motor joint='r_wrist_flex_joint_y' ctrlrange='-2.0 2.0' ctrllimited='true' />
<motor joint='r_wrist_flex_joint_x' ctrlrange='-2.0 2.0' ctrllimited='true' />
<motor joint='pm_joint_x' ctrllimited='true' ctrlrange='-2.0 2.0'/>
<motor joint='pm_joint_y' ctrllimited='true' ctrlrange='-2.0 2.0'/>
</actuator>

</mujoco>
18 changes: 10 additions & 8 deletions env.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,25 @@

try:
import cv2
import mujoco
from gym.envs.mujoco import mujoco_env
import mujoco_env # custom mujoco_env
from dm_control import mujoco
except ImportError as e:
print(e)

DEFAULT_XML_PATH = os.path.join(__file__, 'assets/clevr_default.xml')
FIXED_PATH = os.path.join(__file__, 'templates', '10_fixed_objective.pkl')
file_dir = os.path.abspath(os.path.dirname(__file__))

DEFAULT_XML_PATH = os.path.join(file_dir, 'assets', 'clevr_default.xml')
FIXED_PATH = os.path.join(file_dir, 'templates', '10_fixed_objective.pkl')

# metadata
DEFAULT_METADATA_PATH = os.path.join(__file__, 'metadata', 'metadata.json')
VARIABLE_OBJ_METADATA_PATH = os.path.join(__file__, 'metadata',
DEFAULT_METADATA_PATH = os.path.join(file_dir, 'metadata', 'metadata.json')
VARIABLE_OBJ_METADATA_PATH = os.path.join(file_dir, 'metadata',
'variable_obj_meta_data.json')

# template_path
EVEN_Q_DIST_TEMPLATE = os.path.join(
__file__, 'templates/even_question_distribution.json')
VARIABLE_OBJ_TEMPLATE = os.path.join(__file__, 'templates',
file_dir, 'templates/even_question_distribution.json')
VARIABLE_OBJ_TEMPLATE = os.path.join(file_dir, 'templates',
'variable_object.json')


Expand Down
5 changes: 3 additions & 2 deletions mujoco_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


class MujocoEnv(gym.Env):
"""Mujoco environment that uses dm control's wrapper."""
"""Custom Mujoco environment that uses dm control's wrapper."""

def __init__(self, model_path, frame_skip, max_episode_steps=None,
reward_threshold=None):
Expand All @@ -39,7 +39,8 @@ def __init__(self, model_path, frame_skip, max_episode_steps=None,
if model_path.startswith('/'):
fullpath = model_path
else:
fullpath = os.path.join(os.path.dirname(__file__), 'assets', model_path)
fullpath = os.path.join(
os.path.abspath(os.path.dirname(__file__)), 'assets', model_path)

if not os.path.exists(fullpath):
raise IOError('File %s does not exist' % fullpath)
Expand Down
5 changes: 3 additions & 2 deletions utils/load_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
import six.moves.cPickle as pickle

# pre-generated questions
pregen_path = os.path.join(__file__, '..',
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
pregen_path = os.path.join(parent_dir,
'assets/pregenerated_data/all_question.pkl')
variable_input_pregen_path = os.path.join(
__file__, '..', 'assets/pregenerated_data/all_questions_variable_input.pkl')
parent_dir, 'assets/pregenerated_data/all_questions_variable_input.pkl')



Expand Down
14 changes: 7 additions & 7 deletions utils/xml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
import os
import xml.etree.ElementTree as ET

red_metal_path = os.path.join(__file__, '..', 'assets/textures/metal_red.png')
cyan_metal_path = os.path.join(__file__, '..', 'assets/textures/metal_cyan.png')
purple_metal_path = os.path.join(
__file__, '..', 'assets/textures/metal_purple.png')
green_metal_path = os.path.join(
__file__, '..', 'assets/textures/metal_green.png')
blue_metal_path = os.path.join(__file__, '..', 'assets/textures/metal_blue.png')
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))

red_metal_path = os.path.join(parent_dir, 'assets/textures/metal_red.png')
cyan_metal_path = os.path.join(parent_dir, 'assets/textures/metal_cyan.png')
purple_metal_path = os.path.join(parent_dir, 'assets/textures/metal_purple.png')
green_metal_path = os.path.join(parent_dir, 'assets/textures/metal_green.png')
blue_metal_path = os.path.join(parent_dir, 'assets/textures/metal_blue.png')


texture = {
Expand Down

0 comments on commit 8ed78b0

Please sign in to comment.