sprint
Her-darling 1 week ago
parent d7ca7b6b99
commit d95a4d3be8

@ -233,7 +233,7 @@ class sprint(gym.Env):
w = self.player.world
t = w.time_local_ms
self.reset_time = t
self.generate_random_target()
self.generate_random_target(self.Gen_player_pos[:2])
distance = np.linalg.norm(self.walk_target[:2] - self.Gen_player_pos[:2])
self.walk_distance = distance
self.walk_rel_target = M.rotate_2d_vec(
@ -283,13 +283,12 @@ class sprint(gym.Env):
self.player.terminate()
def generate_random_target(self, x_range=(-15, 15), y_range=(-10, 10)):
r = self.player.world.robot
def generate_random_target(self, position, x_range=(-15, 15), y_range=(-10, 10)):
while True:
x = np.random.uniform(x_range[0], x_range[1])
y = np.random.uniform(y_range[0], y_range[1])
if np.linalg.norm(np.array([x, y]) - r.loc_head_position[:2]) >= 15:
if np.linalg.norm(np.array([x, y]) - position) >= 10:
break
self.walk_target = np.array([x, y])
@ -303,13 +302,13 @@ class sprint(gym.Env):
action_mult = 1 if internal_dist > 0.2 else (0.7 / 0.2) * internal_dist + 0.3
self.walk_rel_target = M.rotate_2d_vec(
(self.walk_target[0] - r.loc_head_position[0], self.walk_target[1] - r.loc_head_position[1]), -r.imu_torso_orientation)
self.walk_distance = np.linalg.norm(self.walk_target[:2] - r.loc_head_position[:2])
if self.walk_distance < 0.5:
self.generate_random_target()
self.walk_distance = np.linalg.norm(self.walk_target - r.loc_head_position[:2])
if self.walk_distance <= 0.5:
self.generate_random_target(r.loc_head_position[:2])
self.walk_rel_target = M.rotate_2d_vec(
(self.walk_target[0] - r.loc_head_position[0], self.walk_target[1] - r.loc_head_position[1]),
-r.imu_torso_orientation)
self.walk_distance = np.linalg.norm(self.walk_target[:2] - r.loc_head_position[:2])
self.walk_distance = np.linalg.norm(self.walk_target - r.loc_head_position[:2])
self.walk_rel_orientation = M.vector_angle(self.walk_rel_target) * 0.3
# exponential moving average
self.act = 0.8 * self.act + 0.2 * action * action_mult * 0.7
@ -344,15 +343,13 @@ class sprint(gym.Env):
obs = self.observe()
robot_speed = np.linalg.norm(r.loc_torso_velocity[:2])
direction_error = abs(self.walk_rel_orientation)
direction_error = min(direction_error, 20)
reward = robot_speed * (1 - direction_error / 20)
if self.walk_distance < 0.8:
direction_error = min(direction_error, 10)
reward = robot_speed * (1 - direction_error / 10) * 0.6
if self.walk_distance < 0.5:
reward += 10
if self.player.behavior.is_ready("Get_Up"):
self.terminal = True
elif w.time_local_ms - self.reset_time > 300000:
self.terminal = True
else:
self.terminal = False
return obs, reward, self.terminal, {}

Loading…
Cancel
Save