-
Notifications
You must be signed in to change notification settings - Fork 1
/
record_teach_traj.py
46 lines (43 loc) · 1.39 KB
/
record_teach_traj.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
from socket import *
import json
import os
from pathlib import Path
from datetime import datetime
## Parameter
serverName = '10.5.5.100'
serverPort = 10000
BUFSIZ = 4096 # Larger than 3500
ADDR = (serverName,serverPort)
DT = datetime.now()
DT_format = DT.strftime('%Y%m%d%H%M%S')
Traj_name = 'Traj'+DT_format
# Traj_name = 'Traj'
## Traj Dir
Path(os.getcwd()+'/traj').mkdir(exist_ok=True,parents=True)
traj_path = Path('traj/'+Traj_name+'.txt')
traj_path.touch(exist_ok=True)
traj_file = open(traj_path,'a')
## Start Recording
counter = 0
while True:
counter = counter + 1
print('Please move to the {} point...\n press \'q\' to quit\n press enter to proceed\n'.format(counter))
func = input()
collected = False
if func == 'q':
print('Trajector is saved at ',end='')
print(os.path.join(Path(os.getcwd()+'/traj'),Traj_name))
break
else:
while not collected:
try:
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect(ADDR)
returnData = clientSocket.recv(BUFSIZ)
Data = json.loads(returnData.decode())
print(Data['joint_actual_position'])
traj_file.write(str(Data['joint_actual_position'])[1:-1]+'\n')
clientSocket.close()
collected = True
except json.decoder.JSONDecodeError:
continue