7 print "import without hrpsys" 12 from waitInput
import *
17 global hcf, initial_pose, hrpsys_version
18 hcf = HrpsysConfigurator()
19 hcf.getRTCList = hcf.getRTCListUnstable
20 hcf.init (
"SampleRobot(Robot)0",
"$(PROJECT_DIR)/../model/sample1.wrl")
22 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.637045, -7.77902e-005, -0.378613, -0.000209794, 0.832038, -0.452564, 0.000244781, 0.31129, 0.159481, 0.115399, -0.636277, 0, 0, -0.637045, 0, 0, 0]
23 hcf.seq_svc.setJointAngles(initial_pose, 2.5)
24 hcf.waitInterpolation()
25 hrpsys_version = hcf.seq.ref.get_component_profile().version
26 print(
"hrpsys_version = %s"%hrpsys_version)
29 hcf.setMaxLogLength(1);hcf.clearLog();time.sleep(0.1);hcf.saveLog(log_fname)
31 def checkParameterFromLog(port_name, log_fname="/tmp/test-samplerobot-remove-force-offset-check-param", save_log=True, rtc_name="rmfo"):
34 return map(float, open(log_fname+
"."+rtc_name+
"_"+port_name,
"r").readline().split(" ")[1:-1])
37 print >> sys.stderr,
"1. GetForceMomentOffsetParam" 38 for fs_name
in [
"rhsensor",
"lhsensor"]:
39 ret = hcf.rmfo_svc.getForceMomentOffsetParam(fs_name)
41 print >> sys.stderr,
" getForceMomentOffsetParam('", fs_name,
"') => OK" 42 assert(ret[0]
is True)
45 print >> sys.stderr,
"2. SetForceMomentOffsetParam" 46 print >> sys.stderr,
" Force and moment are large because of link offsets" 48 for fs_name
in [
"rhsensor",
"lhsensor"]:
51 print >> sys.stderr,
" no-offset-removed force moment (",fs_name,
") ", fm,
"=> ", vret
53 print >> sys.stderr,
" Set link offsets (link_offset_centroid and link_offset_mass are identified value)." 55 r_fmop = hcf.rmfo_svc.getForceMomentOffsetParam(
"rhsensor")[1]
56 r_fmop.link_offset_centroid = [0,0.0368,-0.076271]
57 r_fmop.link_offset_mass = 0.80011
58 l_fmop = hcf.rmfo_svc.getForceMomentOffsetParam(
"lhsensor")[1]
59 l_fmop.link_offset_centroid = [0,-0.0368,-0.076271]
60 l_fmop.link_offset_mass = 0.80011
62 hcf.rmfo_svc.setForceMomentOffsetParam(
"rhsensor", r_fmop)
63 hcf.rmfo_svc.setForceMomentOffsetParam(
"lhsensor", l_fmop)
65 ret = hcf.rmfo_svc.getForceMomentOffsetParam(
"rhsensor")
66 if ret[0]
and ret[1].link_offset_mass == r_fmop.link_offset_mass
and ret[1].link_offset_centroid == r_fmop.link_offset_centroid:
67 print >> sys.stderr,
" getForceMomentOffsetParam('rhsensor') => OK" 68 assert((ret[0]
and ret[1].link_offset_mass == r_fmop.link_offset_mass
and ret[1].link_offset_centroid == r_fmop.link_offset_centroid))
69 ret = hcf.rmfo_svc.getForceMomentOffsetParam(
"lhsensor")
70 if ret[0]
and ret[1].link_offset_mass == l_fmop.link_offset_mass
and ret[1].link_offset_centroid == l_fmop.link_offset_centroid:
71 print >> sys.stderr,
" getForceMomentOffsetParam('lhsensor') => OK" 72 assert((ret[0]
and ret[1].link_offset_mass == l_fmop.link_offset_mass
and ret[1].link_offset_centroid == l_fmop.link_offset_centroid))
73 print >> sys.stderr,
" Force and moment are reduced" 75 for fs_name
in [
"rhsensor",
"lhsensor"]:
78 print >> sys.stderr,
" no-offset-removed force moment (",fs_name,
") ", fm,
"=> ", vret
82 print >> sys.stderr,
"3. Dump and load parameter file" 83 print >> sys.stderr,
" Get and set param" 84 r_fmop = hcf.rmfo_svc.getForceMomentOffsetParam(
"rhsensor")[1]
85 r_fmop.link_offset_centroid = [0,0.0368,-0.076271]
86 r_fmop.link_offset_mass = 0.80011
87 l_fmop = hcf.rmfo_svc.getForceMomentOffsetParam(
"lhsensor")[1]
88 l_fmop.link_offset_centroid = [0,-0.0368,-0.076271]
89 l_fmop.link_offset_mass = 0.80011
90 hcf.rmfo_svc.setForceMomentOffsetParam(
"rhsensor", r_fmop)
91 hcf.rmfo_svc.setForceMomentOffsetParam(
"lhsensor", l_fmop)
92 print >> sys.stderr,
" Dump param as file" 93 ret = hcf.rmfo_svc.dumpForceMomentOffsetParams(
"/tmp/test-rmfo-offsets.dat")
94 print >> sys.stderr,
" Value check" 95 data_str=filter(
lambda x : x.find(
"lhsensor") >= 0, open(
"/tmp/test-rmfo-offsets.dat",
"r").read().split("\n"))[0]
96 vcheck =
map(float, data_str.split(
" ")[7:10]) == l_fmop.link_offset_centroid
and float(data_str.split(
" ")[10]) == l_fmop.link_offset_mass
97 data_str=filter(
lambda x : x.find(
"rhsensor") >= 0, open(
"/tmp/test-rmfo-offsets.dat",
"r").read().split("\n"))[0]
98 vcheck = vcheck
and map(float, data_str.split(
" ")[7:10]) == r_fmop.link_offset_centroid
and float(data_str.split(
" ")[10]) == r_fmop.link_offset_mass
100 if ret
and os.path.exists(
"/tmp/test-rmfo-offsets.dat")
and vcheck:
101 print >> sys.stderr,
" dumpForceMomentOffsetParams => OK" 102 assert((ret
and os.path.exists(
"/tmp/test-rmfo-offsets.dat")
and vcheck))
103 print >> sys.stderr,
" Resetting values" 104 r_fmop2 = hcf.rmfo_svc.getForceMomentOffsetParam(
"rhsensor")[1]
105 r_fmop2.link_offset_centroid = [0,0,0]
106 r_fmop2.link_offset_mass = 0
107 l_fmop2 = hcf.rmfo_svc.getForceMomentOffsetParam(
"lhsensor")[1]
108 l_fmop2.link_offset_centroid = [0,0,0]
109 l_fmop2.link_offset_mass = 0
110 hcf.rmfo_svc.setForceMomentOffsetParam(
"rhsensor", r_fmop2)
111 hcf.rmfo_svc.setForceMomentOffsetParam(
"lhsensor", l_fmop2)
112 print >> sys.stderr,
" Load from file" 113 ret = hcf.rmfo_svc.loadForceMomentOffsetParams(
"/tmp/test-rmfo-offsets.dat")
114 r_fmop3 = hcf.rmfo_svc.getForceMomentOffsetParam(
"rhsensor")[1]
115 l_fmop3 = hcf.rmfo_svc.getForceMomentOffsetParam(
"lhsensor")[1]
116 vcheck = r_fmop3.link_offset_mass == r_fmop.link_offset_mass
and r_fmop3.link_offset_centroid == r_fmop.link_offset_centroid
and l_fmop3.link_offset_mass == l_fmop.link_offset_mass
and l_fmop3.link_offset_centroid == l_fmop.link_offset_centroid
118 print >> sys.stderr,
" loadForceMomentOffsetParams => OK" 119 assert((ret
and vcheck))
122 print >> sys.stderr,
"4. remove force sensor offset" 123 print >> sys.stderr,
" Test valid calibration" 124 ret = hcf.removeForceSensorOffsetRMFO(tm=1.0)
125 print >> sys.stderr,
" Test invalid calibration" 126 ret = ret
and not hcf.removeForceSensorOffsetRMFO([
"testtest"], 1.0)
128 print >> sys.stderr,
" removeforcesensorlinkoffset => OK" 134 from distutils.version
import StrictVersion
135 if StrictVersion(hrpsys_version) >= StrictVersion(
'315.5.0'):
141 if __name__ ==
'__main__':
def demoRemoveForceSensorOffsetRMFO()
def demoDumpLoadForceMomentOffsetParams()
def demoSetForceMomentOffsetParam()
def checkParameterFromLog(port_name, log_fname="/tmp/test-samplerobot-remove-force-offset-check-param", save_log=True, rtc_name="rmfo")
def demoGetForceMomentOffsetParam()
def saveLogForCheckParameter(log_fname="/tmp/test-samplerobot-remove-force-offset-check-param")