fancy_gym/alr_envs/envs/mujoco/beerpong/mp_wrapper.py

44 lines
1.3 KiB
Python
Raw Normal View History

2022-07-06 09:18:41 +02:00
from typing import Union, Tuple
import numpy as np
from alr_envs.black_box.raw_interface_wrapper import RawInterfaceWrapper
class MPWrapper(RawInterfaceWrapper):
2022-07-07 10:47:04 +02:00
@property
def context_mask(self) -> np.ndarray:
2022-07-06 09:18:41 +02:00
return np.hstack([
[False] * 7, # cos
[False] * 7, # sin
[False] * 7, # joint velocities
[False] * 3, # cup_goal_diff_final
[False] * 3, # cup_goal_diff_top
[True] * 2, # xy position of cup
2022-07-07 10:47:04 +02:00
# [False] # env steps
2022-07-06 09:18:41 +02:00
])
@property
def current_pos(self) -> Union[float, int, np.ndarray, Tuple]:
2022-07-13 13:28:39 +02:00
return self.data.qpos[0:7].copy()
2022-07-06 09:18:41 +02:00
@property
def current_vel(self) -> Union[float, int, np.ndarray, Tuple]:
2022-07-13 13:28:39 +02:00
return self.data.qvel[0:7].copy()
2022-07-06 09:18:41 +02:00
# TODO: Fix this
def _episode_callback(self, action: np.ndarray, mp) -> Tuple[np.ndarray, Union[np.ndarray, None]]:
if mp.learn_tau:
2022-07-13 13:28:39 +02:00
self.release_step = action[0] / self.dt # Tau value
2022-07-06 09:18:41 +02:00
return action, None
else:
return action, None
def set_context(self, context):
xyz = np.zeros(3)
xyz[:2] = context
xyz[-1] = 0.840
2022-07-13 13:28:39 +02:00
self.model.body_pos[self.cup_table_id] = xyz
return self.get_observation_from_step(self.get_obs())