-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_6DOF_environment.py
64 lines (46 loc) · 1.48 KB
/
test_6DOF_environment.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
"""
Script to test functionality of the 6DOF environment
"""
from genericpath import isfile
from my_environment.envs import Rocket6DOF
from gym.wrappers import RecordVideo
# Import the initial conditions from the setup file
from gym.wrappers import RecordVideo
import pandas as pd
import os
pd.options.plotting.backend = "plotly"
from stable_baselines3.ppo.ppo import PPO
from main_6DOF import load_config
sb3_config, env_config, = load_config()
# Instantiate the environment
env = Rocket6DOF(**env_config)
# env=RecordVideo(env,video_folder="video_6DOF")
def get_action(action_type = 'null'):
# [delta_y, delta_z, thrust]
if action_type == 'null':
return [0.0, 0.0, -1]
elif action_type == 'constant':
return [1.0, 1.0, -0.5]
elif os.path.isfile('model_brisk-donkey-8.zip'):
model = PPO.load('model_brisk-donkey-8.zip')
action, __, = model.predict(obs)
return action
# Initialize the environment
done = False
obs = env.reset()
env.render(mode="human")
landing_attempts = 1
succesful_landings = 0
while landing_attempts <= 10:
action = get_action()
obs, rew, done, info = env.step(action)
env.render(mode="human")
if done:
landing_attempts += 1
if info['is_succesful'] is True:
succesful_landings +=1
print(info["landing_conditions"])
env.reset()
env.render(mode="human")
print(f"The success rate is:{succesful_landings/landing_attempts*100}%")
env.close()