-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.py
84 lines (69 loc) · 2.01 KB
/
report.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
# Software License Agreement (BSD License)
#
# Copyright (c) 2023, UFACTORY, Inc.
# All rights reserved.
#
# Author: Vinman <vinman.wen@ufactory.cc> <vinman.cub@gmail.com>
"""
Description: read report data example
1. requires firmware 2.1.0 and above support
"""
import os
import sys
import time
import datetime
import json
# sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../../..'))
from xarm.core.comm import SocketPort
from xarm.core.utils import convert
#######################################################
"""
Just for test example
"""
if len(sys.argv) >= 2:
ip = sys.argv[1]
else:
try:
from configparser import ConfigParser
parser = ConfigParser()
parser.read('../robot.conf')
ip = parser.get('xArm', 'ip')
except:
ip = input('Please input the xArm ip address:')
if not ip:
print('input error, exit')
sys.exit(1)
########################################################
report = {
'ip': ip,
'data': []
}
try:
sock = SocketPort(ip, 30001)
while sock.connected:
data = sock.read(timeout=1)
if data == -1:
time.sleep(0.1)
continue
now = datetime.datetime.now()
total = convert.bytes_to_u32(data[0:4])
angles = convert.bytes_to_fp32s(data[7:35], 7)
poses = convert.bytes_to_fp32s(data[35:59], 6)
print('total={}, now={}'.format(total, datetime.datetime.now()))
# print('angles: {}'.format(angles))
# print('poses: {}'.format(poses))
# save the report
report['data'].append({
'timestamp': str(now),
'total': total,
'data': str(data),
'angles': angles,
'poses': poses
})
except KeyboardInterrupt:
print("Saving report...") # quit
# dump saved frames
with open("report_{}_{}.json".format(ip,datetime.datetime.now().strftime("%Y%m%d%H%M%S")), 'w') as fd:
json.dump(report,fd)
sys.exit()