From 642bf8761f71362114e39e933f80113165736c85 Mon Sep 17 00:00:00 2001 From: Dominik Roth Date: Fri, 2 Feb 2024 16:51:18 +0100 Subject: [PATCH] Fix: BP was not returning new infos (smoothness metrics) --- fancy_gym/envs/mujoco/__init__.py | 2 +- fancy_gym/envs/mujoco/box_pushing/box_pushing_env.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/fancy_gym/envs/mujoco/__init__.py b/fancy_gym/envs/mujoco/__init__.py index 4bdab68..8dc6cfc 100644 --- a/fancy_gym/envs/mujoco/__init__.py +++ b/fancy_gym/envs/mujoco/__init__.py @@ -1,7 +1,7 @@ from .ant_jump.ant_jump import AntJumpEnv from .beerpong.beerpong import BeerPongEnv, BeerPongEnvStepBasedEpisodicReward from .half_cheetah_jump.half_cheetah_jump import HalfCheetahJumpEnv -from .hopper_jump.hopper_jump import HopperJumpEnv +from .hopper_jump.hopper_jump import HopperJumpEnv, HopperJumpMarkovRew from .hopper_jump.hopper_jump_on_box import HopperJumpOnBoxEnv from .hopper_throw.hopper_throw import HopperThrowEnv from .hopper_throw.hopper_throw_in_basket import HopperThrowInBasketEnv diff --git a/fancy_gym/envs/mujoco/box_pushing/box_pushing_env.py b/fancy_gym/envs/mujoco/box_pushing/box_pushing_env.py index 9ac03dd..a508d84 100644 --- a/fancy_gym/envs/mujoco/box_pushing/box_pushing_env.py +++ b/fancy_gym/envs/mujoco/box_pushing/box_pushing_env.py @@ -50,6 +50,7 @@ class BoxPushingEnvBase(MujocoEnv, utils.EzPickle): self._desired_rod_quat = desired_rod_quat self._episode_energy = 0. + self.velocity_profile = [] self.observation_space = spaces.Box( low=-np.inf, high=np.inf, shape=(28,), dtype=np.float64 @@ -68,6 +69,8 @@ class BoxPushingEnvBase(MujocoEnv, utils.EzPickle): unstable_simulation = False + self.velocity_profile.append(self.data.qvel[:7].copy()) + try: self.do_simulation(resultant_action, self.frame_skip) except Exception as e: @@ -97,11 +100,15 @@ class BoxPushingEnvBase(MujocoEnv, utils.EzPickle): obs = self._get_obs() box_goal_pos_dist = 0. if not episode_end else np.linalg.norm(box_pos - target_pos) box_goal_quat_dist = 0. if not episode_end else rotation_distance(box_quat, target_quat) + mean_squared_jerk, maximum_jerk, dimensionless_jerk = (0.0,0.0,0.0) if not episode_end else self.calculate_smoothness_metrics(np.array(self.velocity_profile), self.dt) infos = { 'episode_end': episode_end, 'box_goal_pos_dist': box_goal_pos_dist, 'box_goal_rot_dist': box_goal_quat_dist, 'episode_energy': 0. if not episode_end else self._episode_energy, + 'mean_squared_jerk': mean_squared_jerk, + 'maximum_jerk': maximum_jerk, + 'dimensionless_jerk': dimensionless_jerk, 'is_success': True if episode_end and box_goal_pos_dist < 0.05 and box_goal_quat_dist < 0.5 else False, 'num_steps': self._steps }