-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_kinova.py
56 lines (48 loc) · 1.54 KB
/
run_kinova.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
from __future__ import print_function
import os, sys, time
from numpy import reshape, save, load
from configuration import config
from agent.ddpg import DDPG
from environment.turtlebot_obstacles import Turtlebot_obstacles
config.reward_param = 0.8
# env.launch()
def train(port):
config.api_port = port
config.state_dim = 9
config.action_bounds = [
[],
[]
]
config.action_dim = 6
env = Turtlebot_obstacles(config, port)
agent = DDPG(config)
# agent.load(load('savedir/weight_0.0.npy').item())
env.launch()
for episode in range(config.max_episode):
env.reset()
print('Episode:', episode+1)
env.start()
state, done = env.step([0, 0])
for step in range(config.max_step):
epsilon = 0.99999**env.epoch
action = agent.policy(reshape(state, [1, config.state_dim]), epsilon=epsilon)
state, done = env.step(reshape(action, [config.action_dim]))
if env.replay.buffersize>100:
batch = env.replay.batch()
agent.update(batch)
if done == 1:
break
if step >= config.max_step-1:
print(' | Timeout')
if (episode+1)%100 == 0:
save(
os.path.join(
'savedir',
'weight_'+str(config.reward_param)+'.npy'
),
agent.return_variables()
)
if env.epoch > config.max_epoch:
break
if __name__ == '__main__':
train(20000)