finish up beerpong, walker2d and ant needs more extensions, fix import bugs.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
<joint axis="0 -1 0" name="leg_joint" pos="0 0 0.6" range="-150 0" type="hinge"/>
|
||||
<geom friction="0.9" fromto="0 0 0.6 0 0 0.1" name="leg_geom" size="0.04" type="capsule"/>
|
||||
<body name="foot" pos="0.2/2 0 0.1">
|
||||
<site name="foot_right_site" pos="0 0 0.04" size="0.02 0.02 0.02" rgba="0 0 1 1" type="sphere"/>
|
||||
<joint axis="0 -1 0" name="foot_joint" pos="0 0 0.1" range="-45 45" type="hinge"/>
|
||||
<geom friction="0.9" fromto="-0.0 0 0.1 0.2 0 0.1" name="foot_geom" size="0.06" type="capsule"/>
|
||||
</body>
|
||||
@@ -34,6 +35,7 @@
|
||||
<joint axis="0 -1 0" name="leg_left_joint" pos="0 0 0.6" range="-150 0" type="hinge"/>
|
||||
<geom friction="0.9" fromto="0 0 0.6 0 0 0.1" name="leg_left_geom" rgba=".7 .3 .6 1" size="0.04" type="capsule"/>
|
||||
<body name="foot_left" pos="0.2/2 0 0.1">
|
||||
<site name="foot_left_site" pos="0 0 0.04" size="0.02 0.02 0.02" rgba="1 0 0 1" type="sphere"/>
|
||||
<joint axis="0 -1 0" name="foot_left_joint" pos="0 0 0.1" range="-45 45" type="hinge"/>
|
||||
<geom friction="1.9" fromto="-0.0 0 0.1 0.2 0 0.1" name="foot_left_geom" rgba=".7 .3 .6 1" size="0.06" type="capsule"/>
|
||||
</body>
|
||||
@@ -59,4 +61,4 @@
|
||||
<material name="MatPlane" reflectance="0.5" shininess="1" specular="1" texrepeat="60 60" texture="texplane"/>
|
||||
<material name="geom" texture="texgeom" texuniform="true"/>
|
||||
</asset>
|
||||
</mujoco>
|
||||
</mujoco>
|
||||
|
||||
@@ -4,6 +4,10 @@ import numpy as np
|
||||
|
||||
MAX_EPISODE_STEPS_WALKERJUMP = 300
|
||||
|
||||
# TODO: Right now this environment only considers jumping to a specific height, which is not nice. It should be extended
|
||||
# to the same structure as the Hopper, where the angles are randomized (->contexts) and the agent should jump as height
|
||||
# as possible, while landing at a specific target position
|
||||
|
||||
|
||||
class ALRWalker2dJumpEnv(Walker2dEnv):
|
||||
"""
|
||||
@@ -21,14 +25,12 @@ class ALRWalker2dJumpEnv(Walker2dEnv):
|
||||
healthy_angle_range=(-1.0, 1.0),
|
||||
reset_noise_scale=5e-3,
|
||||
penalty=0,
|
||||
context=True,
|
||||
exclude_current_positions_from_observation=True,
|
||||
max_episode_steps=300):
|
||||
self.current_step = 0
|
||||
self.max_episode_steps = max_episode_steps
|
||||
self.max_height = 0
|
||||
self._penalty = penalty
|
||||
self.context = context
|
||||
self.goal = 0
|
||||
xml_file = os.path.join(os.path.dirname(__file__), "assets", xml_file)
|
||||
super().__init__(xml_file, forward_reward_weight, ctrl_cost_weight, healthy_reward, terminate_when_unhealthy,
|
||||
@@ -43,31 +45,24 @@ class ALRWalker2dJumpEnv(Walker2dEnv):
|
||||
|
||||
self.max_height = max(height, self.max_height)
|
||||
|
||||
fell_over = height < 0.2
|
||||
done = fell_over
|
||||
done = height < 0.2
|
||||
|
||||
ctrl_cost = self.control_cost(action)
|
||||
costs = ctrl_cost
|
||||
|
||||
rewards = 0
|
||||
if self.current_step >= self.max_episode_steps or done:
|
||||
done = True
|
||||
height_goal_distance = -10 * (np.linalg.norm(self.max_height - self.goal)) if self.context else self.max_height
|
||||
height_goal_distance = -10 * (np.linalg.norm(self.max_height - self.goal))
|
||||
healthy_reward = self.healthy_reward * self.current_step
|
||||
|
||||
rewards = height_goal_distance + healthy_reward
|
||||
else:
|
||||
# penalty not needed
|
||||
rewards = 0
|
||||
rewards += ((action[:2] > 0) * self._penalty).sum() if self.current_step < 4 else 0
|
||||
rewards += ((action[3:5] > 0) * self._penalty).sum() if self.current_step < 4 else 0
|
||||
|
||||
|
||||
observation = self._get_obs()
|
||||
reward = rewards - costs
|
||||
info = {
|
||||
'height': height,
|
||||
'max_height': self.max_height,
|
||||
'goal' : self.goal,
|
||||
'goal': self.goal,
|
||||
}
|
||||
|
||||
return observation, reward, done, info
|
||||
@@ -78,7 +73,7 @@ class ALRWalker2dJumpEnv(Walker2dEnv):
|
||||
def reset(self):
|
||||
self.current_step = 0
|
||||
self.max_height = 0
|
||||
self.goal = np.random.uniform(1.5, 2.5, 1) # 1.5 3.0
|
||||
self.goal = np.random.uniform(1.5, 2.5, 1) # 1.5 3.0
|
||||
return super().reset()
|
||||
|
||||
# overwrite reset_model to make it deterministic
|
||||
@@ -99,8 +94,7 @@ if __name__ == '__main__':
|
||||
env = ALRWalker2dJumpEnv()
|
||||
obs = env.reset()
|
||||
|
||||
for i in range(2000):
|
||||
# objective.load_result("/tmp/cma")
|
||||
for i in range(6000):
|
||||
# test with random actions
|
||||
ac = env.action_space.sample()
|
||||
obs, rew, d, info = env.step(ac)
|
||||
@@ -110,4 +104,4 @@ if __name__ == '__main__':
|
||||
print('After ', i, ' steps, done: ', d)
|
||||
env.reset()
|
||||
|
||||
env.close()
|
||||
env.close()
|
||||
|
||||
Reference in New Issue
Block a user