-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_controller.py
More file actions
50 lines (43 loc) · 1.12 KB
/
Copy pathcustom_controller.py
File metadata and controls
50 lines (43 loc) · 1.12 KB
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
import os
import gym
import random
import gym_panda
from numpy import savetxt
from action_select import action_select
from action_select_nn import nn_action_select
from action_select_knn import knn_action_select
from reward-functions.rewardmodel_classification import train_model
training = False # False if replaying
env = gym.make("panda-v0")
action_space = [0, 1, 2, 3, 4]
dones = False
gamma = 0 #Exploration-exploitation coefficient
env.reset()
f = 0
k = 2
checkpoint = 50
while True:
if dones:
print(counter1, counter2)
obs = env.reset()
dones = False
if f >= 50 and f%25==0:
checkpoint = 25 * k
k += 1/3
action = 2
counter1 = 0
counter2 = 0
print(f"Next Checkpoint: {checkpoint}")
while not dones:
print(action)
counter1 += 1
obs, reward, dones, info = env.step(action)
env.render()
f = info['ep_count']
g = random.uniform(0, 1)
prev_action = action
if g >= gamma:
action = nn_action_select(obs)
counter2 += 1
else:
action = random.choice(action_space)