@@ -35,6 +35,8 @@ def __init__(self,
3535 walker ,
3636 arena ,
3737 moving_target = False ,
38+ target_relative = False ,
39+ target_relative_dist = 1.5 ,
3840 steps_before_moving_target = 10 ,
3941 distance_tolerance = DEFAULT_DISTANCE_TOLERANCE_TO_TARGET ,
4042 target_spawn_position = None ,
@@ -49,6 +51,10 @@ def __init__(self,
4951 arena: an instance of `locomotion.arenas.floors.Floor`.
5052 moving_target: bool, Whether the target should move after receiving the
5153 walker reaches it.
54+ target_relative: bool, Whether the target be set relative to its current
55+ position.
56+ target_relative_dist: float, new target distance range if
57+ using target_relative.
5258 steps_before_moving_target: int, the number of steps before the target
5359 moves, if moving_target==True.
5460 distance_tolerance: Accepted to distance to the target position before
@@ -90,6 +96,8 @@ def __init__(self,
9096
9197 self ._distance_tolerance = distance_tolerance
9298 self ._moving_target = moving_target
99+ self ._target_relative = target_relative
100+ self ._target_relative_dist = target_relative_dist
93101 self ._steps_before_moving_target = steps_before_moving_target
94102 self ._reward_step_counter = 0
95103
@@ -196,8 +204,16 @@ def after_step(self, physics, random_state):
196204 self ._reward_step_counter >= self ._steps_before_moving_target ):
197205
198206 # Reset the target position.
199- target_x , target_y = variation .evaluate (
200- self ._target_spawn_position , random_state = random_state )
207+ if self ._target_relative :
208+ walker_pos = physics .bind (self ._walker .root_body ).xpos [:2 ]
209+ target_x , target_y = random_state .uniform (
210+ - np .array ([self ._target_relative_dist , self ._target_relative_dist ]),
211+ np .array ([self ._target_relative_dist , self ._target_relative_dist ]))
212+ target_x += walker_pos [0 ]
213+ target_y += walker_pos [1 ]
214+ else :
215+ target_x , target_y = variation .evaluate (
216+ self ._target_spawn_position , random_state = random_state )
201217 physics .bind (self ._target ).pos = [target_x , target_y , 0. ]
202218
203219 # Reset the number of steps at the target for the moving target.
0 commit comments