in safety_gym/envs/world.py [0:0]
def __init__(self, path):
base_path = os.path.join(BASE_DIR, path)
self.sim = MjSim(load_model_from_path(base_path))
self.sim.forward()
# Needed to figure out z-height of free joint of offset body
self.z_height = self.sim.data.get_body_xpos('robot')[2]
# Get a list of geoms in the robot
self.geom_names = [n for n in self.sim.model.geom_names if n != 'floor']
# Needed to figure out the observation spaces
self.nq = self.sim.model.nq
self.nv = self.sim.model.nv
# Needed to figure out action space
self.nu = self.sim.model.nu
# Needed to figure out observation space
# See engine.py for an explanation for why we treat these separately
self.hinge_pos_names = []
self.hinge_vel_names = []
self.ballquat_names = []
self.ballangvel_names = []
self.sensor_dim = {}
for name in self.sim.model.sensor_names:
id = self.sim.model.sensor_name2id(name)
self.sensor_dim[name] = self.sim.model.sensor_dim[id]
sensor_type = self.sim.model.sensor_type[id]
if self.sim.model.sensor_objtype[id] == const.OBJ_JOINT:
joint_id = self.sim.model.sensor_objid[id]
joint_type = self.sim.model.jnt_type[joint_id]
if joint_type == const.JNT_HINGE:
if sensor_type == const.SENS_JOINTPOS:
self.hinge_pos_names.append(name)
elif sensor_type == const.SENS_JOINTVEL:
self.hinge_vel_names.append(name)
else:
t = self.sim.model.sensor_type[i]
raise ValueError('Unrecognized sensor type {} for joint'.format(t))
elif joint_type == const.JNT_BALL:
if sensor_type == const.SENS_BALLQUAT:
self.ballquat_names.append(name)
elif sensor_type == const.SENS_BALLANGVEL:
self.ballangvel_names.append(name)
elif joint_type == const.JNT_SLIDE:
# Adding slide joints is trivially easy in code,
# but this removes one of the good properties about our observations.
# (That we are invariant to relative whole-world transforms)
# If slide joints are added we sould ensure this stays true!
raise ValueError('Slide joints in robots not currently supported')