-
Notifications
You must be signed in to change notification settings - Fork 1
/
manual_control.py
executable file
·59 lines (49 loc) · 2.09 KB
/
manual_control.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
import argparse
import time
import gym
import gym_insertion # noqa: F401
import numpy as np
from PIL import Image
def main():
parser = argparse.ArgumentParser("Insertion, Manual mode")
parser.add_argument('--host', default="127.0.0.1", type=str, help='IP of the server')
parser.add_argument('--port', default=9081, type=int, help='Port that should be used to connect to the server')
args = parser.parse_args()
env = gym.make('insertion-v0', kwargs={'host': args.host, "port": args.port, "use_coord": False})
goal_coord = env.goal_coord
print(f"Goal coord: {goal_coord}")
# Action: [0, 0, 0, 0, 0, 0] # New coord: x, y, z, alpha, beta, gamma
go_down_action = np.asarray([0, -1, 0, 0, 0, 0])
go_up_action = np.asarray([0, 1, 0, 0, 0, 0])
go_left_action = np.asarray([-1, 0, 0, 0, 0, 0])
go_right_action = np.asarray([1, 0, 0, 0, 0, 0])
rotate_action = np.asarray([0, 0, 0, -1, 0, 0])
delay = 1
for i in range(5):
print("Rotating")
new_state, reward, done, infos = env.step(rotate_action)
print(f"New coord: {infos['coord']}, Done: {done}", flush=True)
for i in range(5):
print("Going down")
new_state, reward, done, infos = env.step(go_down_action)
print(f"New coord: {infos['coord']}, Done: {done}", flush=True)
img = Image.fromarray(np.asarray(new_state))
img.save(f"../Img_{i}.jpg", "JPEG")
time.sleep(delay)
for _ in range(5):
print("Going up")
new_state, reward, done, infos = env.step(go_up_action)
print(f"New coord: {infos['coord']}, Done: {done}", flush=True)
time.sleep(delay)
for _ in range(5):
print("Going left")
new_state, reward, done, infos = env.step(go_left_action)
print(f"New coord: {infos['coord']}, Done: {done}", flush=True)
time.sleep(delay)
for _ in range(5):
print("Going right")
new_state, reward, done, infos = env.step(go_right_action)
print(f"New coord: {infos['coord']}, Done: {done}", flush=True)
time.sleep(delay)
if __name__ == "__main__":
main()