fix tau bound and init bound bug

This commit is contained in:
hongyi.zhou
2023-07-03 17:19:41 +02:00
parent 053a17889f
commit bd7e811a64
5 changed files with 32 additions and 15 deletions
+12 -2
View File
@@ -55,6 +55,14 @@ class BlackBoxWrapper(gym.ObservationWrapper):
# self.traj_gen.set_mp_times(self.time_steps)
self.traj_gen.set_duration(self.duration, self.dt)
# check
self.tau_bound = [-np.inf, np.inf]
self.delay_bound = [-np.inf, np.inf]
if hasattr(self.traj_gen.phase_gn, "tau_bound"):
self.tau_bound = self.traj_gen.phase_gn.tau_bound
if hasattr(self.traj_gen.phase_gn, "delay_bound"):
self.delay_bound = self.traj_gen.phase_gn.delay_bound
# reward computation
self.reward_aggregation = reward_aggregation
@@ -139,7 +147,8 @@ class BlackBoxWrapper(gym.ObservationWrapper):
position, velocity = self.get_trajectory(action)
position, velocity = self.env.set_episode_arguments(action, position, velocity)
traj_is_valid, position, velocity = self.env.preprocessing_and_validity_callback(action, position, velocity)
traj_is_valid, position, velocity = self.env.preprocessing_and_validity_callback(action, position, velocity,
self.tau_bound, self.delay_bound)
trajectory_length = len(position)
rewards = np.zeros(shape=(trajectory_length,))
@@ -153,7 +162,8 @@ class BlackBoxWrapper(gym.ObservationWrapper):
if not traj_is_valid:
obs, trajectory_return, done, infos = self.env.invalid_traj_callback(action, position, velocity,
self.return_context_observation)
self.return_context_observation,
self.tau_bound, self.delay_bound)
return self.observation(obs), trajectory_return, done, infos
self.plan_steps += 1
+8 -2
View File
@@ -52,7 +52,8 @@ class RawInterfaceWrapper(gym.Wrapper):
"""
return self.env.dt
def preprocessing_and_validity_callback(self, action: np.ndarray, pos_traj: np.ndarray, vel_traj: np.ndarray) \
def preprocessing_and_validity_callback(self, action: np.ndarray, pos_traj: np.ndarray, vel_traj: np.ndarray,
tau_bound: list = None, delay_bound: list = None ) \
-> Tuple[bool, np.ndarray, np.ndarray]:
"""
Used to preprocess the action and check if the desired trajectory is valid.
@@ -61,6 +62,8 @@ class RawInterfaceWrapper(gym.Wrapper):
specified, else only traj_gen parameters
pos_traj: a vector instance of the raw position trajectory
vel_traj: a vector instance of the raw velocity trajectory
tau_bound: a list of two elements, the lower and upper bound of the trajectory length scaling factor
delay_bound: a list of two elements, the lower and upper bound of the time to wait before execute
Returns:
validity flag: bool, True if the raw trajectory is valid, False if not
pos_traj: a vector instance of the preprocessed position trajectory
@@ -97,7 +100,8 @@ class RawInterfaceWrapper(gym.Wrapper):
"""
return True
def invalid_traj_callback(self, action: np.ndarray, pos_traj: np.ndarray, vel_traj: np.ndarray) -> Tuple[np.ndarray, float, bool, dict]:
def invalid_traj_callback(self, action: np.ndarray, pos_traj: np.ndarray, vel_traj: np.ndarray,
tau_bound: list, delay_bound: list) -> Tuple[np.ndarray, float, bool, dict]:
"""
Used to return a artificial return from the env if the desired trajectory is invalid.
Args:
@@ -105,6 +109,8 @@ class RawInterfaceWrapper(gym.Wrapper):
specified, else only traj_gen parameters
pos_traj: a vector instance of the raw position trajectory
vel_traj: a vector instance of the raw velocity trajectory
tau_bound: a list of two elements, the lower and upper bound of the trajectory length scaling factor
delay_bound: a list of two elements, the lower and upper bound of the time to wait before execute
Returns:
obs: artificial observation if the trajectory is invalid, by default a zero vector
reward: artificial reward if the trajectory is invalid, by default 0