-
Notifications
You must be signed in to change notification settings - Fork 27
/
test_hironx.py
executable file
·584 lines (500 loc) · 26.8 KB
/
test_hironx.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
#!/usr/bin/env python
# -*- coding: utf-8 -*-
PKG = 'hironx_ros_bridge'
# rosbuild needs load_manifest
try:
import roslib
import hironx_ros_bridge
except:
import roslib; roslib.load_manifest(PKG)
import hironx_ros_bridge
from hironx_ros_bridge import hironx_client as hironx
from hrpsys.hrpsys_config import euler_from_matrix
from hrpsys import rtm
import os
import unittest
import time
import tempfile
import math
import random
import numpy
from rtm import connectPorts, disconnectPorts
class TestHiro(unittest.TestCase):
@classmethod
def setUpClass(cls):
#modelfile = rospy.get_param("hironx/collada_model_filepath")
#rtm.nshost = 'hiro024'
#robotname = "RobotHardware0"
cls.robot = hironx.HIRONX()
#cls.robot.init(robotname=robotname, url=modelfile)
cls.robot.init()
@classmethod
def tearDownClass(cls):
#self.write_output_to_pdf("test-hironx.pdf") # don't know how to call this mehtod
True
def test_goInitial(self):
self.limbbody_init()
self.robot.goInitial()
# def test_goOffPose(self):
# self.limbbody_init()
# self.robot.goOffPose()
###
def set_joint_angles_no_wait_test (self):
# send initial pose
av0 = [-0.6, 0, -100, 15.2, 9.4, 3.2]
av1 = [-0.6, -90, -100, 15.2, 9.4, 3.2]
self.robot.setJointAnglesOfGroup( "rarm" , av0, 5)
pose0 = robot.getReferencePose("RARM_JOINT5")
print pose0
# make sure setJointAnglesOfGroup with wait
tm0 = time.time()
self.robot.setJointAnglesOfGroup( "rarm" , av1, 5)
self.robot.setJointAnglesOfGroup( "rarm" , av0, 5)
tm1 = time.time()
pose1 = self.robot.getReferencePose("RARM_JOINT5")
print "setJointAnglesOfGroup : reach goal? ", numpy.linalg.norm(numpy.array(pose1)-numpy.array(pose0)) < 5.0e-3
print " : spend 10 sec?", abs((tm1 - tm0) - 10.0) < 0.1, " " , tm1 - tm0
# make sure setJointAnglesOfGorup with wita=False returns immediately
self.robot.setJointAnglesOfGroup( "rarm" , av1, 5)
tm0 = time.time()
self.robot.setJointAnglesOfGroup( "rarm" , av0, 5, wait=False)
tm1 = time.time()
pose1 = self.robot.getReferencePose("RARM_JOINT5")
print "setJointAnglesOfGroup(wait=False)", numpy.linalg.norm(numpy.array(pose1)-numpy.array(pose0)) > 5.0e-3
print " : spend 10 sec?", abs((tm1 - tm0) - 0.0) < 0.1, " " , tm1 - tm0
# make sure that waitInterpolationOfGroup wait until target reaches the goal
self.robot.waitInterpolationOfGroup("rarm")
tm1 = time.time()
pose1 = self.robot.getReferencePose("RARM_JOINT5")
print "waitInterpolationOfGroup", numpy.linalg.norm(numpy.array(pose1)-numpy.array(pose0)) < 5.0e-3
print " : spend 10 sec?", abs((tm1 - tm0) - 5.0) < 0.1, " " , tm1 - tm0
# load from log data, [[p0,p1,....p25],[p0,p1,....p25],...,[p0,p1,....p25]]
def check_q_data(self,name):
import math
data = []
name = name+".q"
f = open(name)
start_time = None
for line in f:
current_time = float(line.split(' ')[0])
current_value = float(line.split(' ')[7])
if not start_time:
start_time = current_time
data.append([current_time, current_value*180/math.pi])
# print "%f %f" % (current_time - start_time, current_value*180/math.pi)
f.close()
self.filenames.append(name)
return data
# load from log data, [[p0,p1,....p25],[p0,p1,....p25],...,[p0,p1,....p25]] # degree
def load_log_data(self,name):
import math
data = []
f = open(name)
start_time = None
for line in f:
data.append([float(i)*180/math.pi for i in line.split(' ')[1:-1]])
# print "%f %f" % (current_time - start_time, current_value*180/math.pi)
f.close()
self.filenames.append(name)
return data
def check_log_data(self, data, idx, tm_data, min_data, max_data, acc_thre=0.06, tm_thre=0.1): # expected, time, min, max of index
_tm_data = len(data)/200.0
_min_data = min([d[idx] for d in data])
_max_data = max([d[idx] for d in data])
_tm_thre = tm_thre
# min_data = [min_data, min_thre]
if isinstance(min_data, (int, float)):
min_data = [min_data, 5]
if isinstance(max_data, (int, float)):
max_data = [max_data, 5]
print "time (= ", _tm_data, ") == ", tm_data, " -> ", abs(_tm_data - tm_data) < tm_data*_tm_thre
print " min (= ", _min_data, ") == ", min_data, " -> ", abs(_min_data - min_data[0]) < min_data[1]
print " max (= ", _max_data, ") == ", max_data, " -> ", abs(_max_data - max_data[0]) < max_data[1]
self.assertTrue(abs(_tm_data - tm_data) < tm_data*_tm_thre)
self.assertTrue(abs(_min_data - min_data[0]) < min_data[1])
self.assertTrue(abs(_max_data - max_data[0]) < max_data[1])
# check acceleration
flag = True
for i in range(1, len(data)-1):
for j in range(len(data[i])):
p0 = data[i-1][j]
p1 = data[i+0][j]
p2 = data[i+1][j]
v0 = p1 - p0
v1 = p2 - p1
if abs(v1 - v0) > acc_thre:
flag = False
print("Acceleration vaiorated! : n = %d, idx %d, p0 %f, p1 %f, p2 %f, v1 %f, v2 %f, acc %f (%f)" % (i, j, p0, p1, p2, v0, v1, v1-v0, (v1-v0)/180.0*math.pi))
self.assertTrue(flag)
def write_d_dd_data(self, name):
name_d = os.path.splitext(name)[0]+".dq"
name_dd = os.path.splitext(name)[0]+".ddq"
f = open(name)
f_d = open(name_d, 'w')
f_dd = open(name_dd, 'w')
line_0 = None
line_1 = None
line_2 = None
for line_0 in f:
if line_2 and line_1 :
tm = float(line_1.split(' ')[0])
f_d.write(str(tm))
f_dd.write(str(tm))
for i in range(1,len(line_0.split(' '))-1):
p0 = float(line_0.split(' ')[i])
p1 = float(line_1.split(' ')[i])
p2 = float(line_2.split(' ')[i])
v0 = p1 - p0
v1 = p2 - p1
f_d.write(" %.10f"%v0)
f_dd.write(" %.10f"%(v1 - v0))
f_d.write('\n')
f_dd.write('\n')
line_2 = line_1
line_1 = line_0
f.close()
f_d.close()
f_dd.close()
print "[%s] write %s"%(__file__, name_d)
print "[%s] write %s"%(__file__, name_dd)
def write_all_joint_pdf(self, name, pdf_name):
print "[%s] write pdf %s from log data %s"%(__file__, pdf_name, name)
self.write_d_dd_data(name)
_pdf_names = []
for _name in [name, os.path.splitext(name)[0]+".dq", os.path.splitext(name)[0]+".ddq"]:
_pdf_names.append(_name+"_"+pdf_name)
cmd = "gnuplot -p -e \"set terminal pdf; set output '"+_pdf_names[-1]+"'; plot "
f = open(_name)
l = f.readline().split(' ')[:-1]
f.close()
for i in range(1,len(l)):
cmd += "'"+_name+"' using 1:"+str(i+1)+" title 'joint "+str(i)+"' with lines"
if i != len(l)-1:
cmd += ","
cmd += "\""
os.system(cmd)
cmd_str = 'pdfunite '+' '.join(_pdf_names) + ' ' + pdf_name
cmd_str = cmd_str.replace('(', '\(')
cmd_str = cmd_str.replace(')', '\)')
os.system(cmd_str)
return
def check_acceleration(self, name):
name1 = name+".q"
name2 = name+".acc"
f1 = open(name1)
f2 = open(name2, 'w')
line_0 = None
line_1 = None
line_2 = None
for line_0 in f1:
if line_2 and line_1 :
tm = float(line_1.split(' ')[0])
f2.write(str(tm))
for i in range(1,len(line_0.split(' '))-1):
p0 = float(line_0.split(' ')[i])
p1 = float(line_1.split(' ')[i])
p2 = float(line_2.split(' ')[i])
v0 = p1 - p0
v1 = p2 - p1
if abs(v1 - v0) > 0.0001:
print("%s Acceleration vaiorated! : p0 %f, p1 %f, p2 %f, v1 %f, v2 %f, acc %f" % (name, p0, p1, p2, v0, v1, v1-v0))
self.assertTrue(abs(v1 - v0) < 0.0001)
f2.write(' ' + str(v1 - v0))
f2.write('\n')
line_2 = line_1
line_1 = line_0
f1.close()
f2.close()
def fullbody_init (self):
self.filenames = []
self.robot.seq_svc.removeJointGroup("larm")
self.robot.seq_svc.removeJointGroup("rarm")
self.robot.seq_svc.removeJointGroup("head")
#self.robot.seq_svc.removeJointGroup("torso") we use torso for sleep certain time, so not remove this
self.filename_base = tempfile.mkstemp()[1]
def test_fullbody_setJointAngles_Wait (self):
self.fullbody_init()
# move to initiali position
self.robot.setJointAngles([0, 0, 0, 0, -0.6, 0, -120, 15.2, 9.4, 3.2, 0,0,0,0, -0.6, 0, -100,-15.2, 9.4,-3.2, 0, 0, 0, 0], 5);
self.robot.waitInterpolation()
self.robot.clearLog()
self.robot.setJointAngles([0, 0, 0, 0, -0.6, 0, -140, 15.2, 9.4, 3.2, 0,0,0,0, -0.6, 0, -100,-15.2, 9.4,-3.2, 0, 0, 0, 0], 5);
self.robot.waitInterpolation()
self.robot.setJointAngles([0, 0, 0, 0, -0.6, 0, -100, 15.2, 9.4, 3.2, 0,0,0,0, -0.6, 0, -100,-15.2, 9.4,-3.2, 0, 0, 0, 0], 5);
self.robot.waitInterpolation()
filename = self.filename_base + "-wait"
self.robot.saveLog(filename)
q_filename = filename+"."+self.robot.rh.name()+"_q"
data = self.load_log_data(q_filename)
print "check setJointAngles(wait=True)"
self.check_log_data(data, 6, 10.0, -140.0, -100.0)
return True
def test_fullbody_setJointAngles_NoWait (self):
self.fullbody_init()
clear_time = [4.5, 4.0, 3.5, 3.0, 2.5, 2.0, 1.5, 1.0]
self.robot.setJointAngles([0, 0, 0, 0, -0.6, 0, -100, 15.2, 9.4, 3.2, 0,0,0,0, -0.6, 0, -100,-15.2, 9.4,-3.2, 0, 0, 0, 0], 5);
self.robot.waitInterpolation()
for i in range(len(clear_time)):
self.robot.clearLog()
self.robot.setJointAngles([0, 0, 0, 0, -0.6, 0, -140, 15.2, 9.4, 3.2, 0,0,0,0, -0.6, 0, -100,-15.2, 9.4,-3.2, 0, 0, 0, 0], 5);
self.robot.setJointAnglesOfGroup("torso", [0], clear_time[i], wait=True);# time.sleep(clear_time[i]);
self.robot.setJointAngles([0, 0, 0, 0, -0.6, 0, -100, 15.2, 9.4, 3.2, 0,0,0,0, -0.6, 0, -100,-15.2, 9.4,-3.2, 0, 0, 0, 0], 5);
self.robot.waitInterpolation()
filename = self.filename_base + "-no-wait-"+str(clear_time[i])
self.robot.saveLog(filename)
q_filename = filename+"."+self.robot.rh.name()+"_q"
data = self.load_log_data(q_filename)
print "check setJointAngles(wait=True)"
self.check_log_data(data, 6, (10.0 - (5 - clear_time[i])), [-140+i*40/len(clear_time),20], -100.0)
def test_fullbody_setJointAngles_Clear (self):
self.fullbody_init()
# check if clear stops interpolation
clear_time = [4.5, 4.0, 3.5, 3.0, 2.5, 2.0, 1.5, 1.0]
for i in range(len(clear_time)):
self.robot.setJointAngles([0, 0, 0, 0, -0.6, 0, -100, 15.2, 9.4, 3.2, 0,0,0,0, -0.6, 0, -100,-15.2, 9.4,-3.2, 0, 0, 0, 0], 5);
self.robot.waitInterpolation()
self.robot.clearLog()
self.robot.setJointAngles([0, 0, 0, 0, -0.6, 0, -100, 15.2, 9.4, 3.2, 0,0,0,0, -0.6, 0, -100,-15.2, 9.4,-3.2, 0, 0, 0, 0], 5-clear_time[i]);
self.robot.waitInterpolation()
self.robot.setJointAngles([0, 0, 0, 0, -0.6, 0, -140, 15.2, 9.4, 3.2, 0,0,0,0, -0.6, 0, -100,-15.2, 9.4,-3.2, 0, 0, 0, 0], 5);
self.robot.setJointAnglesOfGroup("torso", [0], clear_time[i], wait=True);# time.sleep(clear_time[i]);
self.robot.clear()
self.robot.waitInterpolation()
filename = self.filename_base + "-clear-"+str(clear_time[i])
self.robot.saveLog(filename)
q_filename = filename+"."+self.robot.rh.name()+"_q"
data = self.load_log_data(q_filename)
print "check setJointAngles(Clear)"
self.check_log_data(data, 6, 5, [-140+(i+1)*40/len(clear_time),20], -100.0, acc_thre=0.2)
def test_fullbody_setJointAngles_minus(self):
self.fullbody_init()
self.robot.el_svc.setServoErrorLimit("all", 0.01) # default is 0.18
self.robot.setJointAngles([0, 0, 0, 0, -0.6, 0, -120, 15.2, 9.4, 3.2, 0,0,0,0, -0.6, 0, -100,-15.2, 9.4,-3.2, 0, 0, 0, 0], 3);
self.robot.waitInterpolation()
self.robot.clearLog()
self.robot.setJointAngles([0, 0, 0, 0, -0.6, 0, -120, 15.2, 9.4, 3.2, 0,0,0,0, -0.6, 0, -100,-15.2, 9.4,-3.2, 0, 0, 0, 0], 1);
self.robot.waitInterpolation()
self.robot.setJointAngles([0, 0, 0, 0, -0.6, 0, -140, 15.2, 9.4, 3.2, 0,0,0,0, -0.6, 0, -100,-15.2, 9.4,-3.2, 0, 0, 0, 0], -1);
self.robot.waitInterpolation()
self.robot.setJointAngles([0, 0, 0, 0, -0.6, 0, -140, 15.2, 9.4, 3.2, 0,0,0,0, -0.6, 0, -100,-15.2, 9.4,-3.2, 0, 0, 0, 0], 3);
self.robot.waitInterpolation()
self.robot.setJointAngles([0, 0, 0, 0, -0.6, 0, -120, 15.2, 9.4, 3.2, 0,0,0,0, -0.6, 0, -100,-15.2, 9.4,-3.2, 0, 0, 0, 0], 0);
self.robot.waitInterpolation()
self.robot.setJointAngles([0, 0, 0, 0, -0.6, 0, -120, 15.2, 9.4, 3.2, 0,0,0,0, -0.6, 0, -100,-15.2, 9.4,-3.2, 0, 0, 0, 0], 1);
self.robot.waitInterpolation()
self.robot.setJointAngles([0, 0, 0, 0, -0.6, 0, -140, 15.2, 9.4, 3.2, 0,0,0,0, -0.6, 0, -100,-15.2, 9.4,-3.2, 0, 0, 0, 0], 0.1);
self.robot.waitInterpolation()
self.robot.setJointAngles([0, 0, 0, 0, -0.6, 0, -140, 15.2, 9.4, 3.2, 0,0,0,0, -0.6, 0, -100,-15.2, 9.4,-3.2, 0, 0, 0, 0], 1.0);
self.robot.waitInterpolation()
self.robot.setJointAngles([0, 0, 0, 0, -0.6, 0, -120, 15.2, 9.4, 3.2, 0,0,0,0, -0.6, 0, -100,-15.2, 9.4,-3.2, 0, 0, 0, 0], 0.05);
self.robot.waitInterpolation()
self.robot.setJointAngles([0, 0, 0, 0, -0.6, 0, -120, 15.2, 9.4, 3.2, 0,0,0,0, -0.6, 0, -100,-15.2, 9.4,-3.2, 0, 0, 0, 0], 1.0);
self.robot.waitInterpolation()
filename = self.filename_base + "-minus"
self.robot.saveLog(filename)
# write pdf file
q_filename = filename+"."+self.robot.rh.name()+"_q"
self.write_all_joint_pdf(q_filename, "full_minus_check.pdf")
# assertion
data = self.load_log_data(q_filename)
print "check setJointAngles(minus)"
self.check_log_data(data, 6, 7.19, -140, -120.0, acc_thre = 1.0)
self.robot.el_svc.setServoErrorLimit("all", 0.18) # default is 0.18
####
def limbbody_init (self):
self.filenames = []
self.robot.setSelfGroups()
self.filename_base = tempfile.mkstemp()[1]
def assertTrue(self,a):
assert(a)
def test_rarm_setJointAngles_Wait (self):
self.limbbody_init()
# move to initiali position
self.robot.setJointAnglesOfGroup("rarm",[-0.6, 0, -120, 15.2, 9.4, 3.2], 5, wait=False);
self.robot.waitInterpolationOfGroup("rarm")
self.robot.clearLog()
self.robot.setJointAnglesOfGroup("rarm", [-0.6, 0, -140, 15.2, 9.4, 3.2], 5, wait=False);
self.robot.waitInterpolationOfGroup("rarm")
self.robot.setJointAnglesOfGroup("rarm", [-0.6, 0, -100, 15.2, 9.4, 3.2], 5, wait=False);
self.robot.waitInterpolationOfGroup("rarm")
self.robot.setJointAnglesOfGroup("rarm", [-0.6, 0, -100, 15.2, 9.4, 3.2], 5, wait=False);
self.robot.waitInterpolationOfGroup("rarm")
filename = self.filename_base + "-wait"
self.robot.saveLog(filename)
q_filename = filename+"."+self.robot.rh.name()+"_q"
data = self.load_log_data(q_filename)
print "check setJointAnglesOfGroup(wait=True)"
self.check_log_data(data, 6, 15.0, -140.0, -100.0)
return True
def test_rarm_setJointAngles_NoWait (self):
self.limbbody_init()
clear_time = [4.5, 4.0, 3.5, 3.0, 2.5, 2.0, 1.5, 1.0]
self.robot.setJointAnglesOfGroup("rarm", [-0.6, 0, -100, 15.2, 9.4, 3.2], 5, wait=False);
self.robot.waitInterpolationOfGroup("rarm")
for i in range(len(clear_time)):
self.robot.clearLog()
self.robot.setJointAnglesOfGroup("rarm", [-0.6, 0, -140, 15.2, 9.4, 3.2], 5, wait=False);
self.robot.setJointAnglesOfGroup("larm", [-0.6, 0, -100, 15.2, 9.4, 3.2], clear_time[i], wait=True);# time.sleep(clear_time[i]);
self.robot.setJointAnglesOfGroup("rarm",[-0.6, 0, -100, 15.2, 9.4, 3.2], 5, wait=False);
self.robot.waitInterpolationOfGroup("rarm")
filename = self.filename_base + "-no-wait-"+str(clear_time[i])
self.robot.saveLog(filename)
q_filename = filename+"."+self.robot.rh.name()+"_q"
data = self.load_log_data(q_filename)
print "check setJointAnglesOfGroup(wait=True) "+str(clear_time[i])
self.check_log_data(data, 6, (10.0 - (5 - clear_time[i])), [(-140+i*40/len(clear_time)),20], -100.0)
def test_rarm_setJointAngles_Clear (self):
self.limbbody_init()
# check if clear stops interpolation
clear_time = [4.5, 4.0, 3.5, 3.0, 2.5, 2.0, 1.5, 1.0]
for i in range(len(clear_time)):
self.robot.setJointAnglesOfGroup("rarm", [-0.6, 0, -120, 15.2, 9.4, 3.2], 5, wait=False);
self.robot.waitInterpolationOfGroup("rarm")
self.robot.clearLog()
self.robot.setJointAnglesOfGroup("rarm", [-0.6, 0, -100, 15.2, 9.4, 3.2], 5, wait=False);
self.robot.waitInterpolationOfGroup("rarm")
self.robot.setJointAnglesOfGroup("rarm", [-0.6, 0, -140, 15.2, 9.4, 3.2], 5, wait=False);
self.robot.setJointAnglesOfGroup("larm", [-0.6, 0, -100, 15.2, 9.4, 3.2], clear_time[i], wait=True);# time.sleep(clear_time[i]);
self.robot.clearOfGroup("rarm")
self.robot.waitInterpolationOfGroup("rarm")
filename = self.filename_base + "-clear-"+str(clear_time[i])
self.robot.saveLog(filename)
q_filename = filename+"."+self.robot.rh.name()+"_q"
data = self.load_log_data(q_filename)
print "check setJointAnglesOfGroup(clear) "+str(clear_time[i])
self.check_log_data(data, 6, (5 + clear_time[i]), [(-140+i*40/len(clear_time)),20], -100.0)
def test_rarm_setJointAnglesOfGroup_Override_Acceleration (self):
self.limbbody_init()
#disconnectPorts(self.robot.rh.port("q"), self.robot.log.port("q"))
#connectPorts(self.robot.el.port("q"), self.robot.log.port("q"))
#self.robot.setJointAnglesOfGroup("rarm", [ 25, -139, -157, 45, 0, 0], 3, wait=False);
#self.robot.setJointAnglesOfGroup("larm", [-25, -139, -157, -45, 0, 0], 3, wait=False);
self.robot.setJointAnglesOfGroup("rarm", [-0.6, 0, -120, 15.2, 9.4, 3.2], 3, wait=False);
self.robot.setJointAnglesOfGroup("larm", [ 0.6, 0, -120,-15.2, 9.4,-3.2], 3, wait=False);
self.robot.waitInterpolationOfGroup("rarm")
self.robot.clearLog()
#self.robot.log_svc.maxLength(200*30)
# self.robot.setJointAnglesOfGroup("rarm", [-0.6, 0, -140, 15.2, 9.4, 3.2], 3, wait=False);
# time.sleep(1.5);
# self.robot.setJointAnglesOfGroup("rarm", [-0.6, 0, -100, 15.2, 9.4, 3.2], 3, wait=False);
# self.robot.waitInterpolationOfGroup("rarm")
# self.robot.setJointAnglesOfGroup("rarm", [-0.6, 0, -100, 15.2, 9.4, 3.2], 3, wait=False);
# self.robot.setJointAnglesOfGroup("larm", [ 0.6, 0, -140,-15.2, 9.4,-3.2], 3, wait=False);
# time.sleep(1.5);
# self.robot.setJointAnglesOfGroup("larm", [ 0.6, 0, -120,-15.2, 9.4,-3.2], 3, wait=False);
# self.robot.setJointAnglesOfGroup("rarm", [-0.6, 0, -100, 15.2, 9.4, 3.2], 3, wait=False);
# self.robot.waitInterpolationOfGroup("rarm")
# self.robot.waitInterpolationOfGroup("larm")
# self.robot.setJointAnglesOfGroup("larm", [ 0.6, 0, -120,-15.2, 9.4,-3.2], 0.1, wait=False);
# self.robot.setJointAnglesOfGroup("rarm", [-0.6, 0, -100, 15.2, 9.4, 3.2], 0.1, wait=False);
# self.robot.waitInterpolationOfGroup("rarm")
# self.robot.waitInterpolationOfGroup("larm")
# self.robot.setJointAnglesOfGroup("rarm", [ 25, -139, -157, 45, 0, 0], 3, wait=False);
# self.robot.setJointAnglesOfGroup("larm", [-25, -139, -157, -45, 0, 0], 3, wait=False);
# time.sleep(2.5);
# for i in range(1,10):
# time.sleep(i/30.0)
# self.robot.setJointAnglesOfGroup("larm",
# [ 0.6, 0, -120,-15.2, 9.4,-3.2]+numpy.random.normal(0,1,6),
# 3, wait=False);
for i in range(3):
self.robot.setJointAnglesOfGroup("rarm",
[-0.6, 0, -100, 15.2, 9.4, 3.2]+numpy.random.normal(0,1,6),
3, wait=False);
self.robot.setJointAnglesOfGroup("larm", [-0.6, 0, -100, 15.2, 9.4, 3.2], 1.5, wait=True);# time.sleep(clear_time[i]);
#self.robot.setJointAnglesOfGroup("larm", [ 0.6, 0, -120,-15.2, 9.4,-3.2], 1, wait=False);
#self.robot.setJointAnglesOfGroup("rarm", [-0.6, 0, -120, 15.2, 9.4, 3.2], 1, wait=False);
#self.robot.waitInterpolationOfGroup("rarm")
#self.robot.waitInterpolationOfGroup("larm")
self.robot.setJointAnglesOfGroup("rarm", [-0.6, 0, -140, 15.2, 9.4, 3.2], 3, wait=False);
self.robot.setJointAnglesOfGroup("larm", [-0.6, 0, -100, 15.2, 9.4, 3.2], 1.5, wait=True);# time.sleep(clear_time[i]);
self.robot.setJointAnglesOfGroup("rarm", [-0.6, 0, -120, 15.2, 9.4, 3.2], 3, wait=False);
#time.sleep(1.5)
#self.robot.setJointAnglesOfGroup("larm", [ 0.6, 0, -120,-15.2, 9.4,-3.2], 0, wait=False);
#self.robot.setJointAnglesOfGroup("rarm", [-0.6, 0, -120, 15.2, 9.4, 3.2], 0, wait=False);
self.robot.waitInterpolationOfGroup("rarm")
filename = self.filename_base + "-no-wait2"
self.robot.saveLog(filename)
# write pdf file
q_filename = filename+"."+self.robot.rh.name()+"_q"
self.write_all_joint_pdf(q_filename, "rarm_accel_check.pdf")
# assertion
data = self.load_log_data(q_filename)
print "check setJointAnglesOfGroup(Override_acceleratoin)"
self.check_log_data(data, 6, 9, -135, -100.0)
def write_output_to_pdf (self,name):
print ";; write log data to "+name
global filenames
import os
cmd = "gnuplot -p -e \"set terminal pdf; set output '"+name+"'; plot "
for name in self.filenames:
cmd += "'"+name+"' using 0:8 title '"+name+"' with lines"
if name != self.filenames[-1]:
cmd += ","
cmd += "\""
os.system(cmd)
return cmd
def test_rarm_setJointAnglesOfGroup_minus(self):
self.limbbody_init()
self.robot.el_svc.setServoErrorLimit("all", 0.01) # default is 0.18
self.robot.setJointAnglesOfGroup("rarm", [-0.6, 0, -120, 15.2, 9.4, 3.2], 3, wait=False);
self.robot.setJointAnglesOfGroup("larm", [ 0.6, 0, -120,-15.2, 9.4,-3.2], 3, wait=False);
self.robot.waitInterpolationOfGroup("rarm")
self.robot.clearLog()
self.robot.setJointAnglesOfGroup("rarm", [-0.6, 0, -120, 15.2, 9.4, 3.2], 1, wait=False);
self.robot.setJointAnglesOfGroup("larm", [ 0.6, 0, -120,-15.2, 9.4,-3.2], 1, wait=False);
self.robot.waitInterpolationOfGroup("rarm")
self.robot.setJointAnglesOfGroup("rarm", [ 0.6, 0, -120,-15.2, 9.4,-3.2], -1, wait=True);
self.robot.setJointAnglesOfGroup("rarm", [ 0.6, 0, -140,-15.2, 9.4,-3.2], -1, wait=True);
self.robot.setJointAnglesOfGroup("rarm", [ 0.6, 0, -140,-15.2, 9.4,-3.2], 3, wait=True);
self.robot.setJointAnglesOfGroup("rarm", [ 0.6, 0, -120,-15.2, 9.4,-3.2], 0, wait=True);
self.robot.setJointAnglesOfGroup("rarm", [ 0.6, 0, -120,-15.2, 9.4,-3.2], 1.0, wait=True);
self.robot.setJointAnglesOfGroup("rarm", [ 0.6, 0, -140,-15.2, 9.4,-3.2], 0.1, wait=True);
self.robot.setJointAnglesOfGroup("rarm", [ 0.6, 0, -140,-15.2, 9.4,-3.2], 1.0, wait=True);
self.robot.setJointAnglesOfGroup("rarm", [ 0.6, 0, -120,-15.2, 9.4,-3.2], 0.05, wait=True);
self.robot.setJointAnglesOfGroup("rarm", [ 0.6, 0, -120,-15.2, 9.4,-3.2], 1.0, wait=True);
#self.robot.setJointAnglesOfGroup("rarm", [ 0.6, 0, -140,-15.2, 9.4,-3.2], 1.0, wait=True);
filename = self.filename_base + "-minus"
self.robot.saveLog(filename)
# write pdf file
q_filename = filename+"."+self.robot.rh.name()+"_q"
self.write_all_joint_pdf(q_filename, "rarm_minus_check.pdf")
# assertion
data = self.load_log_data(q_filename)
print "check setJointAnglesOfGroup(minus)"
self.check_log_data(data, 6, 7.19, -140, -120.0, acc_thre = 1.5, tm_thre = 0.3)
self.robot.el_svc.setServoErrorLimit("all", 0.18) # default is 0.18
def testSetTargetPoseBothArm(self):
tm = 10
self.robot.goInitial()
posl1 = self.robot.getCurrentPosition('LARM_JOINT5')
posl2 = self.robot.getCurrentPosition('LARM_JOINT5')
posr1 = self.robot.getCurrentPosition('RARM_JOINT5')
posr2 = self.robot.getCurrentPosition('RARM_JOINT5')
rpyl1 = self.robot.getCurrentRPY('LARM_JOINT5')
rpyr1 = self.robot.getCurrentRPY('RARM_JOINT5')
posr1[0] += 0.05
posr2[2] += 0.08
posl1[0] -= 0.09
posl2[2] -= 0.07
# Til here initializing.
if not self.robot.setTargetPose('larm', posl1, rpyl1, tm):
assert(False)
if not self.robot.setTargetPose('rarm', posr1, rpyr1, tm):
assert(False)
print('Before waitInterpolationOfGroup(larm) begins.')
self.robot.waitInterpolationOfGroup('larm')
print('waitInterpolationOfGroup(larm) returned.')
self.robot.waitInterpolationOfGroup('rarm') # just to make sure
print('waitInterpolationOfGroup(rarm) returned.')
if not self.robot.setTargetPose('larm', posl2, rpyl1, tm):
assert(False)
if not self.robot.setTargetPose('rarm', posr2, rpyr1, tm):
assert(False)
# Making sure if reached here. If any error occurred. If not reached
# assert false should be returned earlier.
assert(True)
#unittest.main()
if __name__ == '__main__':
import rostest
rostest.rosrun(PKG, 'test_hronx', TestHiro)