forked from cb614611757/Kuka_Pybullet-for-pick-and-place
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
42 lines (35 loc) · 1.29 KB
/
main.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
import os, inspect
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(os.path.dirname(currentdir))
os.sys.path.insert(0,parentdir)
import gym
import numpy as np
import pdb
import cv2
from kuka_diverse_object_gym_env import KukaDiverseObjectEnv
import demo_policies as demo
save_path = './data/train_image/'
def main():
# environment = KukaCamGymEnv(renders=True, isDiscrete=False)
environment = KukaDiverseObjectEnv(renders=True, isDiscrete=False)
demo_policy_object = demo.policies['grasper']()
for i in range(1000):
done = False
index = 0
environment._reset()
# print(action)
# pdb.set_trace()
while (not done):
action = []
low_state = environment.state_vector()
action = demo_policy_object._choose_action(low_state)
print('action:',action)
state, reward, done, info = environment.next_step(action)
index += 1
print('step: ', index)
print('reward: ', reward)
image = environment._get_observation()
image_name = os.path.join(os.path.abspath(save_path), str(i) + str(index) + '.jpg')
cv2.imwrite(image_name, image)
if __name__=="__main__":
main()