|
|
@ -280,12 +280,16 @@ class sprint(gym.Env):
|
|
|
|
self.player.terminate()
|
|
|
|
self.player.terminate()
|
|
|
|
|
|
|
|
|
|
|
|
def change_target(self):
|
|
|
|
def change_target(self):
|
|
|
|
# 生成一个 -10 到 +10 度之间的随机角度
|
|
|
|
original_angle = M.vector_angle(self.walk_rel_target)
|
|
|
|
orientations = random.choice([-1, 1])
|
|
|
|
random_angle_delta = np.random.uniform(-10, 10)
|
|
|
|
random_target = orientations * 10 # 单位是度
|
|
|
|
new_angle = (original_angle + np.radians(random_angle_delta)) * 3 * math.sin(time.time())
|
|
|
|
|
|
|
|
|
|
|
|
self.walk_rel_target = (15, random_target)
|
|
|
|
new_walk_rel_target = np.array([
|
|
|
|
|
|
|
|
np.cos(new_angle) * self.walk_distance,
|
|
|
|
|
|
|
|
np.sin(new_angle) * self.walk_distance
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.walk_rel_target = new_walk_rel_target
|
|
|
|
|
|
|
|
|
|
|
|
def step(self, action):
|
|
|
|
def step(self, action):
|
|
|
|
|
|
|
|
|
|
|
@ -294,7 +298,7 @@ class sprint(gym.Env):
|
|
|
|
|
|
|
|
|
|
|
|
w = self.player.world
|
|
|
|
w = self.player.world
|
|
|
|
current_time = time.time()
|
|
|
|
current_time = time.time()
|
|
|
|
if current_time - self.last_target_update_time > 0.8:
|
|
|
|
if current_time - self.last_target_update_time > 0.6:
|
|
|
|
self.change_target()
|
|
|
|
self.change_target()
|
|
|
|
self.last_target_update_time = current_time
|
|
|
|
self.last_target_update_time = current_time
|
|
|
|
|
|
|
|
|
|
|
@ -342,19 +346,16 @@ class sprint(gym.Env):
|
|
|
|
reward = robot_speed * (1 - direction_error / 10)
|
|
|
|
reward = robot_speed * (1 - direction_error / 10)
|
|
|
|
if self.player.behavior.is_ready("Get_Up"):
|
|
|
|
if self.player.behavior.is_ready("Get_Up"):
|
|
|
|
self.terminal = True
|
|
|
|
self.terminal = True
|
|
|
|
|
|
|
|
elif w.time_local_ms - self.reset_time > 30000:
|
|
|
|
elif w.time_local_ms - self.reset_time > 10000 * 2:
|
|
|
|
|
|
|
|
self.terminal = True
|
|
|
|
self.terminal = True
|
|
|
|
elif r.loc_torso_position[0] > 14.5:
|
|
|
|
elif r.loc_torso_position[0] > 14.5:
|
|
|
|
self.terminal = True
|
|
|
|
self.terminal = True
|
|
|
|
reward += 500
|
|
|
|
reward += 500
|
|
|
|
elif r.loc_torso_position[0] > 0:
|
|
|
|
elif r.loc_torso_position[0] > 0:
|
|
|
|
reward += r.loc_torso_position[0] * 10
|
|
|
|
reward += 3 * r.loc_torso_position[0]
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.terminal = False
|
|
|
|
self.terminal = False
|
|
|
|
return obs, reward, self.terminal, {}
|
|
|
|
return obs, reward, self.terminal, {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Train(Train_Base):
|
|
|
|
class Train(Train_Base):
|
|
|
|
def __init__(self, script) -> None:
|
|
|
|
def __init__(self, script) -> None:
|
|
|
|
super().__init__(script)
|
|
|
|
super().__init__(script)
|
|
|
|