7 print "import without hrpsys" 12 from waitInput
import *
19 global hcf, init_pose, reset_pose, wrench_command0, wrench_command1, hrpsys_version
20 hcf = HrpsysConfigurator()
21 hcf.getRTCList = hcf.getRTCListUnstable
22 hcf.init (
"SampleRobot(Robot)0",
"$(PROJECT_DIR)/../model/sample1.wrl")
23 hrpsys_version = hcf.seq.ref.get_component_profile().version
24 print(
"hrpsys_version = %s"%hrpsys_version)
26 hcf.connectLoggerPort(hcf.rfu,
'ref_rhsensorOut')
27 hcf.connectLoggerPort(hcf.rfu,
'ref_lhsensorOut')
31 print >> sys.stderr,
"1. getParam" 32 for limb_name
in [
'rarm',
'larm']:
33 [ret, rfup] = hcf.rfu_svc.getReferenceForceUpdaterParam(limb_name)
35 [ret, rfup] = hcf.rfu_svc.getReferenceForceUpdaterParam(
'rarm2')
37 print >> sys.stderr,
" =>OK" 40 print >> sys.stderr,
"2. setParam" 41 print >> sys.stderr,
" Valid limb access" 42 for limb_name
in [
'rarm',
'larm']:
43 [ret, rfup] = hcf.rfu_svc.getReferenceForceUpdaterParam(limb_name)
44 ret = hcf.rfu_svc.setReferenceForceUpdaterParam(limb_name, rfup)
46 print >> sys.stderr,
" Invalid limb access" 47 ret = hcf.rfu_svc.setReferenceForceUpdaterParam(
'rarm2', rfup)
49 print >> sys.stderr,
" =>OK" 52 print >> sys.stderr,
"3. Reference Force Update" 56 p = hcf.rfu_svc.getReferenceForceUpdaterParam(
'larm')[1]
60 r_fmop = hcf.rmfo_svc.getForceMomentOffsetParam(
"rhsensor")[1]
61 r_fmop.link_offset_centroid = [0,0.0368,-0.076271]
62 r_fmop.link_offset_mass = 0.80011
63 l_fmop = hcf.rmfo_svc.getForceMomentOffsetParam(
"lhsensor")[1]
64 l_fmop.link_offset_centroid = [0,-0.0368,-0.076271]
65 l_fmop.link_offset_mass = 0.80011
67 hcf.rmfo_svc.setForceMomentOffsetParam(
"rhsensor", r_fmop)
68 hcf.rmfo_svc.setForceMomentOffsetParam(
"lhsensor", l_fmop)
69 for armName,portName
in zip([
'rarm',
'larm'],[
'ref_rhsensorOut',
'ref_lhsensorOut']):
70 hcf.rfu_svc.setReferenceForceUpdaterParam(armName,p)
71 print >> sys.stderr,
" 3."+str(i)+
". set ref_force from seq [10,0,0]";i+=1
73 hcf.seq_svc.setWrenches([0]*12+[10,0,0,0,0,0]*2,1);time.sleep(1)
75 print >> sys.stderr, portName,portData[0:3]
76 ret = np.linalg.norm(portData) > 9.9;
79 print >> sys.stderr,
" 3."+str(i)+
". start/stop param for " + armName; i+=1
81 hcf.rfu_svc.startReferenceForceUpdater(armName);time.sleep(1)
83 print >> sys.stderr, portName,portData[0:3]
84 ret = np.linalg.norm(portData) < 0.1;
87 hcf.rfu_svc.stopReferenceForceUpdater(armName);time.sleep(1)
89 print >> sys.stderr, portName,portData[0:3]
90 ret = np.linalg.norm(portData) > 9.9;
93 print >> sys.stderr,
" 3."+str(i)+
". set ref_force from seq [0,0,0]";i+=1
94 hcf.seq_svc.setWrenches([0]*24,1);time.sleep(1)
97 print >> sys.stderr,
"4. setParam while active" 98 print >> sys.stderr,
" 4.0 Start" 99 hcf.rfu_svc.startReferenceForceUpdater(
'rarm')
100 print >> sys.stderr,
" 4.1 Check setParam without any changes" 101 [ret, rfup_org] = hcf.rfu_svc.getReferenceForceUpdaterParam(
'rarm')
102 ret = hcf.rfu_svc.setReferenceForceUpdaterParam(
'rarm', rfup_org)
104 print >> sys.stderr,
" 4.2 Check setParam which cannot be changed while active" 105 [ret, rfup] = hcf.rfu_svc.getReferenceForceUpdaterParam(
'rarm')
107 ret = hcf.rfu_svc.setReferenceForceUpdaterParam(
'rarm', rfup)
109 [ret, rfup] = hcf.rfu_svc.getReferenceForceUpdaterParam(
'rarm')
110 rfup.update_freq = rfup.update_freq*10
111 ret = hcf.rfu_svc.setReferenceForceUpdaterParam(
'rarm', rfup)
113 [ret, rfup] = hcf.rfu_svc.getReferenceForceUpdaterParam(
'rarm')
114 rfup.update_time_ratio = rfup.update_time_ratio*10
115 ret = hcf.rfu_svc.setReferenceForceUpdaterParam(
'rarm', rfup)
117 print >> sys.stderr,
" 4.3 Check setParam which can be changed while active" 118 [ret, rfup] = hcf.rfu_svc.getReferenceForceUpdaterParam(
'rarm')
119 rfup.motion_dir = tmp_value = [0,0,-1]
120 ret = hcf.rfu_svc.setReferenceForceUpdaterParam(
'rarm', rfup)
121 print >> sys.stderr,
" motion_dir ..." 122 assert(ret
and (map (
lambda x,y : abs(x-y)<1e-5, hcf.rfu_svc.getReferenceForceUpdaterParam(
'rarm')[1].motion_dir, tmp_value)))
123 rfup.p_gain = tmp_value = rfup.p_gain*0.1
124 ret = hcf.rfu_svc.setReferenceForceUpdaterParam(
'rarm', rfup)
125 print >> sys.stderr,
" p_gain ..." 126 assert(ret
and (abs(hcf.rfu_svc.getReferenceForceUpdaterParam(
'rarm')[1].p_gain-tmp_value) < 1e-5))
127 rfup.d_gain = tmp_value = rfup.d_gain*0.1
128 ret = hcf.rfu_svc.setReferenceForceUpdaterParam(
'rarm', rfup)
129 print >> sys.stderr,
" d_gain ..." 130 assert(ret
and (abs(hcf.rfu_svc.getReferenceForceUpdaterParam(
'rarm')[1].d_gain-tmp_value) < 1e-5))
131 rfup.i_gain = rfup.i_gain*0.1
132 ret = hcf.rfu_svc.setReferenceForceUpdaterParam(
'rarm', rfup)
133 print >> sys.stderr,
" i_gain ..." 134 assert(ret
and (abs(hcf.rfu_svc.getReferenceForceUpdaterParam(
'rarm')[1].i_gain-tmp_value) < 1e-5))
135 rfup.is_hold_value = tmp_value =
not rfup.is_hold_value
136 ret = hcf.rfu_svc.setReferenceForceUpdaterParam(
'rarm', rfup)
137 print >> sys.stderr,
" is_hold_value ..." 138 assert(ret
and hcf.rfu_svc.getReferenceForceUpdaterParam(
'rarm')[1].is_hold_value == tmp_value)
139 print >> sys.stderr,
" 4.4 Stop" 140 hcf.rfu_svc.stopReferenceForceUpdater(
'rarm')
141 hcf.rfu_svc.setReferenceForceUpdaterParam(
'rarm', rfup_org)
142 print >> sys.stderr,
" =>OK" 145 print >> sys.stderr,
"5. FootOriginExtMoment" 146 ret = hcf.rfu_svc.startReferenceForceUpdater(
'footoriginextmoment')
147 ret = hcf.rfu_svc.stopReferenceForceUpdater(
'footoriginextmoment')
and ret
149 print >> sys.stderr,
" =>OK" 152 hcf.setMaxLogLength(1);hcf.clearLog();time.sleep(0.1);hcf.saveLog(log_fname)
154 def checkDataPortFromLog(port_name, log_fname="/tmp/test-samplerobot-reference-force-updater-check-port",save_log=True, rtc_name="rfu"):
157 return map(float, open(log_fname+
"."+rtc_name+
"_"+port_name,
"r").readline().split(" ")[1:-1])
161 from distutils.version
import StrictVersion
162 if StrictVersion(hrpsys_version) >= StrictVersion(
'315.9.0'):
166 if StrictVersion(hrpsys_version) >= StrictVersion(
'315.13.0'):
170 if __name__ ==
'__main__':
def demoSetReferecenForceUpdateParam()
def demoReferenceForceUpdater()
def demoGetReferecenForceUpdateParam()
def demoSetReferecenForceUpdateParamWhileActive()
def saveLogForCheckParameter(log_fname="/tmp/test-samplerobot-reference-force-updater-check-port")
def demoReferecenForceUpdateParamFootOriginExtMoment()
def checkDataPortFromLog(port_name, log_fname="/tmp/test-samplerobot-reference-force-updater-check-port", save_log=True, rtc_name="rfu")