updated incorrect angle normalization.

This commit is contained in:
Fabian 2021-03-22 15:25:22 +01:00
parent b7b5af03ba
commit 89439f7532
2 changed files with 10 additions and 8 deletions

View File

@ -8,7 +8,9 @@ from alr_envs.utils.utils import angle_normalize
class ALRReacherEnv(mujoco_env.MujocoEnv, utils.EzPickle):
def __init__(self, steps_before_reward=200, n_links=5, balance=True):
def __init__(self, steps_before_reward=200, n_links=5, balance=True, file_name=None):
utils.EzPickle.__init__(**locals())
self._steps = 0
self.steps_before_reward = steps_before_reward
self.n_links = n_links
@ -29,7 +31,6 @@ class ALRReacherEnv(mujoco_env.MujocoEnv, utils.EzPickle):
else:
raise ValueError(f"Invalid number of links {n_links}, only 5 or 7 allowed.")
utils.EzPickle.__init__(steps_before_reward=steps_before_reward, n_links=n_links, balance=balance)
mujoco_env.MujocoEnv.__init__(self, os.path.join(os.path.dirname(__file__), "assets", file_name), 2)
def step(self, a):

View File

@ -11,10 +11,11 @@ def angle_normalize(x, type="deg"):
Returns:
"""
if type not in ["deg", "rad"]: raise ValueError(f"Invalid type {type}. Choose one of 'deg' or 'rad'.")
if type == "deg":
return ((x + np.pi) % (2 * np.pi)) - np.pi
elif type == "rad":
x = np.deg2rad(x) # x * pi / 180
two_pi = 2 * np.pi
return x - two_pi * np.floor((x + np.pi) / two_pi)
else:
raise ValueError(f"Invalid type {type}. Choose on of 'deg' or 'rad'.")