7 print "import without hrpsys" 12 from waitInput
import *
16 from subprocess
import check_output
20 return filter(
lambda x : x[0]!=
'tc', hcf.getRTCListUnstable())
23 global hcf, initial_pose, limit_table_list, bodyinfo, hrpsys_version
24 hcf = HrpsysConfigurator()
25 hcf.getRTCList = getRTCList
26 hcf.init (
"SampleRobot(Robot)0",
"$(PROJECT_DIR)/../model/sample1.wrl")
27 initial_pose = [-7.779e-005, -0.378613, -0.000209793, 0.832038, -0.452564, 0.000244781, 0.31129, -0.159481, -0.115399, -0.636277, 0, 0, 0, -7.77902e-005, -0.378613, -0.000209794, 0.832038, -0.452564, 0.000244781, 0.31129, 0.159481, 0.115399, -0.636277, 0, 0, 0, 0, 0, 0]
29 HRPSYS_DIR=check_output([
'pkg-config',
'hrpsys-base',
'--variable=prefix']).rstrip()
30 f=open(
"{}/share/hrpsys/samples/SampleRobot/SampleRobot.500.el.conf".format(HRPSYS_DIR))
31 limit_table_str=filter(
lambda x : x.find(
"joint_limit_table") > -1 , f.readlines())[0]
32 limit_table_list=limit_table_str.split(
":")[1:]
35 bodyinfo=hcf.getBodyInfo(
"$(PROJECT_DIR)/../model/sample1.wrl")
37 hcf.seq_svc.setJointAngles(initial_pose, 2.0)
38 hcf.seq_svc.waitInterpolation()
39 hrpsys_version = hcf.seq.ref.get_component_profile().version
40 print(
"hrpsys_version = %s"%hrpsys_version)
44 from distutils.version
import StrictVersion
45 if StrictVersion(hrpsys_version) >= StrictVersion(
'315.5.0'):
52 print >> sys.stderr,
"1. demo all jointLimitTables" 53 for table_idx
in range(len(limit_table_list)/6):
57 return 180.0*ang/3.14159
60 return 3.14159*ang/180.0
63 self_joint_name = limit_table_list[0+table_idx*6].replace(
' ',
'')
64 target_joint_name = limit_table_list[1+table_idx*6].replace(
' ',
'')
65 self_jointId = filter(
lambda x : x.name == self_joint_name, bodyinfo._get_links())[0].jointId
66 target_jointId = filter(
lambda x : x.name == target_joint_name, bodyinfo._get_links())[0].jointId
67 target_llimit=float(limit_table_list[2+table_idx*6])
68 target_ulimit=float(limit_table_list[3+table_idx*6])
69 self_llimits=
map(
lambda x : float(x), limit_table_list[4+table_idx*6].split(
","))
70 self_ulimits=
map(
lambda x : float(x), limit_table_list[5+table_idx*6].split(
","))
71 return [self_joint_name, target_joint_name,
72 self_jointId, target_jointId,
73 target_llimit, target_ulimit,
74 self_llimits, self_ulimits]
77 [self_joint_name, target_joint_name,
78 self_jointId, target_jointId,
79 target_llimit, target_ulimit,
81 lret =
testOneLimitTable(self_jointId, target_jointId, self_llimits, target_llimit, target_ulimit, -1, debug, loop_mod)
82 uret =
testOneLimitTable(self_jointId, target_jointId, self_ulimits, target_llimit, target_ulimit, 1, debug, loop_mod)
83 print >> sys.stderr,
"lower limit check(", self_joint_name,
",", target_joint_name,
")=", lret
84 print >> sys.stderr,
"upper limit check(", self_joint_name,
",", target_joint_name,
")=", uret
88 def testOneLimitTable (self_jointId, target_jointId, limit_table, target_llimit, target_ulimit, angle_violation, debug=True, loop_mod=1, thre=1e-2):
89 tmp_pose=
map(
lambda x : x, initial_pose)
91 for idx
in range(int(target_ulimit-target_llimit+1)):
97 tmp_pose[target_jointId]=
deg2rad(target_llimit + idx);
98 tmp_pose[self_jointId]=
deg2rad(limit_table[idx]);
100 hcf.seq_svc.setJointAngles(tmp_pose, 1);
102 hcf.seq_svc.setJointAngles(tmp_pose, 0.01);
103 hcf.seq_svc.waitInterpolation()
106 hcf.seq_svc.setJointAngles(tmp_pose, 0.01);hcf.seq_svc.waitInterpolation();
108 el_out1 = hcf.getActualState().command
109 ret1 = abs(
rad2deg(el_out1[self_jointId])-limit_table[idx]) < thre
and abs(
rad2deg(el_out1[target_jointId])- (target_llimit + idx)) < thre
111 tmp_pose[self_jointId]=
deg2rad(limit_table[idx]+angle_violation);
112 hcf.seq_svc.setJointAngles(tmp_pose, 0.01);
113 hcf.seq_svc.waitInterpolation()
116 hcf.seq_svc.setJointAngles(tmp_pose, 0.01);hcf.seq_svc.waitInterpolation()
118 el_out2 = hcf.getActualState().command
119 ret2 = abs(
rad2deg(el_out2[self_jointId]) - limit_table[int(round(
rad2deg(el_out2[target_jointId])-target_llimit))]) < thre
120 ret2 = ret2
and abs(el_out2[self_jointId] - (limit_table[idx]+angle_violation)) > thre
123 print " ret = (", ret1,
",", ret2,
")" 124 print " self=(o1=",
rad2deg(el_out1[self_jointId]),
", o2=",
rad2deg(el_out2[self_jointId]),
", limit=", limit_table[idx],
") ",
" target=(o1=",
rad2deg(el_out1[target_jointId]),
", o2=",
rad2deg(el_out2[target_jointId]),
", limit=", target_llimit + idx,
") [deg]" 127 hcf.seq_svc.waitInterpolation()
128 hcf.seq_svc.setJointAngles(initial_pose, 1);
129 hcf.seq_svc.waitInterpolation()
133 print >> sys.stderr,
" ", joint_name
135 link_info=filter(
lambda x : x.name==joint_name, bodyinfo._get_links())[0]
136 hcf.seq_svc.setJointAngle(joint_name, math.radians(1)+link_info.ulimit[0], 1)
137 hcf.waitInterpolation()
139 hcf.seq_svc.setJointAngle(joint_name, math.radians(1)+link_info.ulimit[0], 0.01);hcf.waitInterpolation()
141 tmppose = hcf.getActualState().command
142 ret = tmppose[link_info.jointId] <= link_info.ulimit[0]
143 print >> sys.stderr,
" ulimit = ", ret,
"(elout=", tmppose[link_info.jointId],
", limit=", link_info.ulimit[0],
")" 146 hcf.seq_svc.setJointAngle(joint_name, math.radians(-1)+link_info.llimit[0], 1)
147 hcf.waitInterpolation()
149 hcf.seq_svc.setJointAngle(joint_name, math.radians(-1)+link_info.llimit[0], 0.01);hcf.waitInterpolation()
151 tmppose = hcf.getActualState().command
152 ret = tmppose[link_info.jointId] >= link_info.llimit[0]
153 print >> sys.stderr,
" llimit = ", ret,
"(elout=", tmppose[link_info.jointId],
", limit=", link_info.llimit[0],
")" 156 hcf.seq_svc.setJointAngles(initial_pose, 1.0)
157 hcf.waitInterpolation()
160 print >> sys.stderr,
"2. Check Position limit" 166 link_info=filter(
lambda x : x.name==joint_name, bodyinfo._get_links())[0]
168 if not(len(link_info.lvlimit) == 1
and len(link_info.uvlimit) == 1):
169 print >> sys.stderr,
" ", joint_name,
" test neglected because no lvlimit and uvlimit are found." 171 for is_upper_limit
in [
True,
False]:
172 print >> sys.stderr,
" ", joint_name,
", uvlimit" if is_upper_limit
else ", lvlimit" 174 hcf.el_svc.setServoErrorLimit(
"all", 100000)
177 target_angle = (math.degrees( link_info.ulimit[0]
if is_upper_limit
else link_info.llimit[0] )*0.99)
178 vel_limit = link_info.uvlimit[0]
if is_upper_limit
else link_info.lvlimit[0]
179 wait_time = abs(target_angle/math.degrees(vel_limit) * 1.1)
180 hcf.setJointAngle(joint_name, math.degrees(initial_pose[link_info.jointId]), 0.1)
181 hcf.waitInterpolation()
182 hcf.setJointAngle(joint_name, target_angle, 0.002)
183 hcf.waitInterpolation()
184 hcf.setJointAngle(joint_name, target_angle, wait_time)
185 hcf.waitInterpolation()
187 hcf.setJointAngle(joint_name, target_angle, 0.01);hcf.waitInterpolation()
188 hcf.saveLog(
"/tmp/test-samplerobot-el-vel-check")
191 reach_angle = math.degrees(hcf.getActualState().command[link_info.jointId])
192 is_reached = abs(reach_angle - target_angle) < thre
195 for line
in open(
"/tmp/test-samplerobot-el-vel-check.SampleRobot(Robot)0_q",
"r"): 196 poslist.append(float(line.split(" ")[link_info.jointId+1]))
197 tmp =
map(
lambda x,y : x-y, poslist[1:], poslist[0:-1])
198 max_ret_vel =
max(tmp)/dt
if is_upper_limit
else min(tmp)/dt
199 is_vel_limited = abs(max_ret_vel - vel_limit) < thre
201 hcf.el_svc.setServoErrorLimit(
"all", (0.2-0.02))
202 hcf.setJointAngle(joint_name, math.degrees(initial_pose[link_info.jointId]), 0.5)
203 hcf.waitInterpolation()
205 print >> sys.stderr,
" is_reached =", is_reached,
", is_vel_limited =", is_vel_limited,
206 print >> sys.stderr,
", target_angle =", target_angle,
"[deg], reach_angle =", reach_angle,
"[deg], max_ret_vel =", max_ret_vel,
"[rad/s], vel_limit =", vel_limit,
"[rad/s]" 207 assert(is_reached
and is_vel_limited)
210 print >> sys.stderr,
"3. Check Velocity limit" 215 link_info=filter(
lambda x : x.name==joint_name, bodyinfo._get_links())[0]
216 for is_upper_limit
in [
True,
False]:
217 print >> sys.stderr,
" ", joint_name,
", uvlimit" if is_upper_limit
else ", lvlimit" 219 error_limit = 0.002
if is_upper_limit
else -0.002
220 hcf.el_svc.setServoErrorLimit(
"all", abs(error_limit))
223 target_angle = 3.0
if is_upper_limit
else -3.0
225 hcf.setJointAngle(joint_name, math.degrees(initial_pose[link_info.jointId]), 0.1)
226 hcf.waitInterpolation()
227 hcf.setJointAngle(joint_name, target_angle, 0.002)
228 hcf.waitInterpolation()
229 hcf.setJointAngle(joint_name, target_angle, wait_time)
230 hcf.waitInterpolation()
232 hcf.setJointAngle(joint_name, target_angle, 0.01);hcf.waitInterpolation()
233 hcf.saveLog(
"/tmp/test-samplerobot-el-err-check")
236 reach_angle = math.degrees(hcf.getActualState().command[link_info.jointId])
237 is_reached = abs(reach_angle - target_angle) < thre
240 for line
in open(
"/tmp/test-samplerobot-el-err-check.SampleRobot(Robot)0_q",
"r"): 241 poslist.append(float(line.split(" ")[link_info.jointId+1]))
243 for line
in open(
"/tmp/test-samplerobot-el-err-check.el_q",
"r"): 244 refposlist.append(float(line.split(" ")[link_info.jointId+1]))
245 tmp =
map(
lambda x,y : x-y, refposlist, poslist)
246 max_ret_err =
max(tmp)
if is_upper_limit
else min(tmp)
247 is_err_limited = abs(max_ret_err - error_limit) < thre
249 hcf.el_svc.setServoErrorLimit(
"all", (0.2-0.02))
250 hcf.setJointAngle(joint_name, math.degrees(initial_pose[link_info.jointId]), 0.5)
251 hcf.waitInterpolation()
253 print >> sys.stderr,
" is_reached =", is_reached,
", is_err_limited =", is_err_limited,
254 print >> sys.stderr,
", target_angle =", target_angle,
"[deg], reach_angle =", reach_angle,
"[deg], max_ret_err =", max_ret_err,
"[rad], err_limit =", error_limit,
"[rad]" 255 assert(is_reached
and is_err_limited)
258 print >> sys.stderr,
"4. Check Error limit" 263 if __name__ ==
'__main__':
def setAndCheckJointErrorLimit(joint_name, thre=1e-5)
def demoTestAllLimitTables()
def setAndCheckJointLimit(joint_name)
def testOneLimitTable(self_jointId, target_jointId, limit_table, target_llimit, target_ulimit, angle_violation, debug=True, loop_mod=1, thre=1e-2)
def getJointLimitTableInfo(table_idx=0)
def testLimitTables(table_idx=0, debug=True, loop_mod=1)
def setAndCheckJointVelocityLimit(joint_name, thre=1e-5, dt=0.002)