forked from Gregwar/rl-baselines3-zoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_one_value.py
78 lines (62 loc) · 1.89 KB
/
test_one_value.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import torch
import torch.nn as nn
import numpy as np
from rl_zoo3 import ALGOS
import gymnasium
import gym_footsteps_planning
from rl_zoo3.utils import get_model_path
from tqdm import tqdm
import math
env_name = "footsteps-planning-any-withball-v0"
exp_nb = 0
algo = "td3"
folder = "logs"
max_episode_len = 90
obstacle_coordinates = [0.3, 0]
def rotation_arround_obstacle(theta: float, center: list = obstacle_coordinates, radius: float = 0.3) -> list:
x = center[0] + radius * np.cos(np.deg2rad(180 - theta))
y = center[1] + radius * np.sin(np.deg2rad(180 - theta))
return [x, y, np.deg2rad(-theta)]
#Catch eye figure situation
reset_dict = {
"start_foot_pose": [1.0, -0.15, math.pi/4],
"start_support_foot": "right",
"target_foot_pose": [0.0, 0.0, 0.0],
"target_support_foot": "right",
"obstacle_radius":0.15,
}
reset_dict = {
"start_foot_pose": [1.0, -0.15, math.pi/4],
"start_support_foot": "right",
"target_foot_pose": [0.0, 0.0, 0.0],
"target_support_foot": "right",
"obstacle_radius":0.15,
}
reset_dict["target_foot_pose"] = rotation_arround_obstacle(45)
print(f"Env. Name: {env_name}, Exp. Number: {exp_nb}, Algo: {algo}")
env = gymnasium.make(env_name, disable_env_checker=True)
_, model_path, log_path = get_model_path(
exp_nb,
folder,
algo,
env_name,
True, # load-best
False, # load-checkpoint
False, # load-last-checkpoint
)
parameters = {
"env": env,
}
model = ALGOS[algo].load(model_path, device="cuda", **parameters)
obs, infos = env.reset(options=reset_dict)
done = False
total_reward = 0
total_step = 0
env.render()
while (not done) & (total_step < max_episode_len):
action, lstm_states = model.predict(obs, deterministic=True)
obs, reward, done, truncated, infos = env.step(action)
total_step += 1
total_reward += reward
print(f"Total reward: {total_reward}, Total steps: {total_step}")
input()