-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay_model.py
130 lines (90 loc) · 2.85 KB
/
play_model.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from enviroments.SliderEnv import SliderEnv
import time
import os
import glob
import numpy as np
from stable_baselines3 import PPO
trial_name = "model_v15-forward3-5-3-stairs"
# trial_name = "model_v17-forward3-obst"
# trial_name = "model_v17-forward8-omni"
# trial_name = "model_v17-forward3-obst"
trial_name = "model_v17-forward2"
trial_name = "model_v15-forward3-5-1"
model_save_path = "./trained_models/" + trial_name
env = SliderEnv(trial_name)
model = PPO.load(model_save_path + "/model-938", env=env)
forward = False
speed = 1.0
target_x = 0.0
target_y = 0.0
i = 0
while True:
# Reset enviroment
obs = env.reset()
env.step_time = 1.0
# Render things
for i in range(10000):
i+=1
action, _state = model.predict(obs, deterministic=False)
#print(action)
#print()
# i = 0
# for value in obs:
# print(round(value, 2), i)
# i += 1
# print()
# action = [-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0]
# print(action)
# pos = [
# obs[18],
# obs[22],
# obs[14],
# obs[30],
# obs[26],
# obs[20],
# obs[24],
# obs[16],
# obs[32],
# obs[28],
# ]
# # write a row to the csv file
# # writer.writerow(action)
# print(pos)
# writer.writerow(pos)
# if i > 50:
# speed = 1.0
# if i > 2 * np.pi * 150:
# speed = 0.0
# env.v_ref = [0.8, 0.0]
# if forward:
# env.v_ref = [0.8, 0]
# else:
# env.v_ref = [0.0, 0]
# p_x = env.data.qpos[0]
# p_y = env.data.qpos[1]
# print(p_x, p_y)
# env.v_ref = [(np.sin(i / 100)) * 0.4 + 0.4, 0.0, 0.0
# if(abs(p_x - target_x) < 0.1 and abs(p_y - target_y) < 0.1):
# target_x = np.random.uniform(-1, 1)
# target_y = np.random.uniform(-1, 1)
# print((target_x - p_x), (target_y - p_y))
# env.v_ref = [max(-0.3, min(0.3, (target_x - p_x) * 1.0)), max( -0.4, min(0.4, (target_y - p_y) * 1.0)), 0.0]
# env.v_ref = [0.2, 0, 0]
# env.v_ref = [(np.cos(i / 150))/2.0 * speed, (np.sin(i / 150))/2.0 * speed, 0.0]
# print("SWITCH")
obs, reward, done, info = env.step(action)
env.render()
#quat = np.array([obs[10], obs[11], obs[12], obs[13]])
#print(quat)
# print(round(obs[-2], 2))
# print(obs[1])
# print(obs[2])
# print(reward)
# print(reward)
# print(0.1 + 200 * (action[10:15] + 1) * 0.5 + 50)
# if(done):
# env.reset()
time.sleep(0.015)
# input()
# time.sleep(0.1)
writer.close()