samplerobot_stabilizer.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 try:
4  from hrpsys.hrpsys_config import *
5  import OpenHRP
6 except:
7  print "import without hrpsys"
8  import rtm
9  from rtm import *
10  from OpenHRP import *
11  import waitInput
12  from waitInput import *
13  import socket
14  import time
15 
16 import math
17 from subprocess import check_output
18 from distutils.version import StrictVersion
19 
20 def init ():
21  global hcf, initial_pose, half_sitting_pose, hrpsys_version
22  hcf = HrpsysConfigurator()
23  hcf.getRTCList = hcf.getRTCListUnstable
24  hcf.init ("SampleRobot(Robot)0", "$(PROJECT_DIR)/../model/sample1.wrl")
25  # set initial pose from sample/controller/SampleController/etc/Sample.pos
26  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]
27  half_sitting_pose = [-0.000158,-0.570987,-0.000232,1.26437,-0.692521,0.000277,0.31129,-0.159481,-0.115399,-0.636277,0.0,0.0,0.0,-0.000158,-0.570987,-0.000232,1.26437,-0.692521,0.000277,0.31129,0.159481,0.115399,-0.636277,0.0,0.0,0.0,0.0,0.0,0.0]
28  hrpsys_version = hcf.seq.ref.get_component_profile().version
29  print("hrpsys_version = %s"%hrpsys_version)
30  if StrictVersion(hrpsys_version) >= StrictVersion('315.5.0'):
31  # on < 315.5.0 this outputs huge error log message
32  hcf.seq_svc.setJointAngles(initial_pose, 2.0)
33  hcf.seq_svc.waitInterpolation()
34  # Remove offset
35  for sen in ["rfsensor", "lfsensor"]:
36  ofp=hcf.rmfo_svc.getForceMomentOffsetParam(sen)[1];
37  ofp.link_offset_mass=1.9;ofp.link_offset_centroid=[0.08, 0, -0.03];
38  hcf.rmfo_svc.setForceMomentOffsetParam(sen, ofp);
39 
40 def calcCOP ():
41  cop_info=rtm.readDataPort(hcf.st.port("COPInfo")).data
42  lcopx=cop_info[1]/cop_info[2];lcopy=cop_info[0]/cop_info[2]
43  rcopx=cop_info[1+3]/cop_info[2+3];rcopy=cop_info[0+3]/cop_info[2+3]
44  return [[lcopx, lcopx], [rcopx, rcopy], # l cop, r cop
45  [(cop_info[1]+cop_info[1+3])/(cop_info[2]+cop_info[2+3]),(cop_info[0]+cop_info[0+3])/(cop_info[2]+cop_info[2+3])]] # total ZMP
46 
48  print >> sys.stderr, "1. getParameter"
49  stp = hcf.st_svc.getParameter()
50  print >> sys.stderr, " getParameter() => OK"
51 
53  print >> sys.stderr, "2. setParameter"
54  stp_org = hcf.st_svc.getParameter()
55  # for tpcc
56  stp_org.k_tpcc_p=[0.2, 0.2]
57  stp_org.k_tpcc_x=[4.0, 4.0]
58  stp_org.k_brot_p=[0.0, 0.0]
59  # for eefm
60  tmp_leg_inside_margin=71.12*1e-3
61  tmp_leg_outside_margin=71.12*1e-3
62  tmp_leg_front_margin=182.0*1e-3
63  tmp_leg_rear_margin=72.0*1e-3
64  rleg_vertices = [OpenHRP.StabilizerService.TwoDimensionVertex(pos=[tmp_leg_front_margin, tmp_leg_inside_margin]),
65  OpenHRP.StabilizerService.TwoDimensionVertex(pos=[tmp_leg_front_margin, -1*tmp_leg_outside_margin]),
66  OpenHRP.StabilizerService.TwoDimensionVertex(pos=[-1*tmp_leg_rear_margin, -1*tmp_leg_outside_margin]),
67  OpenHRP.StabilizerService.TwoDimensionVertex(pos=[-1*tmp_leg_rear_margin, tmp_leg_inside_margin])]
68  lleg_vertices = [OpenHRP.StabilizerService.TwoDimensionVertex(pos=[tmp_leg_front_margin, tmp_leg_outside_margin]),
69  OpenHRP.StabilizerService.TwoDimensionVertex(pos=[tmp_leg_front_margin, -1*tmp_leg_inside_margin]),
70  OpenHRP.StabilizerService.TwoDimensionVertex(pos=[-1*tmp_leg_rear_margin, -1*tmp_leg_inside_margin]),
71  OpenHRP.StabilizerService.TwoDimensionVertex(pos=[-1*tmp_leg_rear_margin, tmp_leg_outside_margin])]
72  rarm_vertices = rleg_vertices
73  larm_vertices = lleg_vertices
74  stp_org.eefm_support_polygon_vertices_sequence = map (lambda x : OpenHRP.StabilizerService.SupportPolygonVertices(vertices=x), [lleg_vertices, rleg_vertices, larm_vertices, rarm_vertices])
75  stp_org.eefm_leg_inside_margin=tmp_leg_inside_margin
76  stp_org.eefm_leg_outside_margin=tmp_leg_outside_margin
77  stp_org.eefm_leg_front_margin=tmp_leg_front_margin
78  stp_org.eefm_leg_rear_margin=tmp_leg_rear_margin
79  stp_org.eefm_k1=[-1.39899,-1.39899]
80  stp_org.eefm_k2=[-0.386111,-0.386111]
81  stp_org.eefm_k3=[-0.175068,-0.175068]
82  stp_org.eefm_rot_damping_gain = [[20*1.6*1.5, 20*1.6*1.5, 1e5]]*4
83  stp_org.eefm_pos_damping_gain = [[3500*50, 3500*50, 3500*1.0*1.5]]*4
84  stp_org.eefm_swing_rot_damping_gain = stp_org.eefm_rot_damping_gain[0]
85  stp_org.eefm_swing_pos_damping_gain = stp_org.eefm_pos_damping_gain[0]
86  stp_org.eefm_use_swing_damping=True
87  hcf.st_svc.setParameter(stp_org)
88  stp = hcf.st_svc.getParameter()
89  vcheck = stp.k_tpcc_p == stp_org.k_tpcc_p and stp.k_tpcc_x == stp_org.k_tpcc_x and stp.k_brot_p == stp_org.k_brot_p
90  if vcheck:
91  print >> sys.stderr, " setParameter() => OK", vcheck
92  assert(vcheck)
93 
95  stp = hcf.st_svc.getParameter()
96  stp.contact_decision_threshold=thre
97  hcf.st_svc.setParameter(stp)
98 
100  changeContactDecisionThre(10000) # [N]
101 
103  changeContactDecisionThre(50) # [N], default
104 
105 def saveLogForCheckParameter(log_fname="/tmp/test-samplerobot-stabilizer-check-param"):
106  hcf.setMaxLogLength(1);hcf.clearLog();time.sleep(0.1);hcf.saveLog(log_fname)
107 
108 def checkParameterFromLog(port_name, log_fname="/tmp/test-samplerobot-stabilizer-check-param", save_log=True, rtc_name="SampleRobot(Robot)0"):
109  if save_log:
110  saveLogForCheckParameter(log_fname)
111  return map(float, open(log_fname+"."+rtc_name+"_"+port_name, "r").readline().split(" ")[1:-1])
112 
113 def checkActualBaseAttitude(thre=5.0): # degree
114  '''Check whether the robot falls down based on actual robot base-link attitude.
115  '''
116  act_rpy = checkParameterFromLog("WAIST")[3:]
117  ret = abs(math.degrees(act_rpy[0])) < thre and abs(math.degrees(act_rpy[1])) < thre
118  print >> sys.stderr, " ret = ", ret, ", actual base rpy = (", act_rpy, ")"
119  return ret
120 
122  '''Print actual base pos and rot
123  '''
124  act_base = checkParameterFromLog("WAIST")
125  print >> sys.stderr, " actual base pos = ", act_base[0:3], "[m], actual base rpy = ", act_base[3:], "[rad]"
126 
127 def changeSTAlgorithm (new_st_alg):
128  stp = hcf.st_svc.getParameter()
129  if stp.st_algorithm != new_st_alg:
130  hcf.stopStabilizer()
131  stp.st_algorithm = new_st_alg
132  hcf.st_svc.setParameter(stp)
133  hcf.startStabilizer ()
134  # Wait for osscilation being samall
135  hcf.setJointAngles(hcf.getJointAngles(), 2.0);
136  hcf.waitInterpolation()
137 
139  print >> sys.stderr, "3. EEFMQP st + SequencePlayer loadPattern"
140  if hcf.pdc:
141  # Set initial pose of samplerobot-gopos000 before starting of ST
142  hcf.seq_svc.setJointAnglesSequenceFull([[0.000242, -0.403476, -0.000185, 0.832071, -0.427767, -6.928952e-05, 0.31129, -0.159481, -0.115399, -0.636277, 0.0, 0.0, 0.0, 0.000242, -0.403469, -0.000185, 0.832073, -0.427775, -6.928781e-05, 0.31129, 0.159481, 0.115399, -0.636277, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]], # jvss
143  [[0]*29], # vels
144  [[0]*29], # torques
145  [[-0.014759, -4.336272e-05, 0.668138]], # poss
146  [[-0.000245, -0.000862, 0.000171]], # rpys
147  [[0]*3], # accs
148  [[0.014052, 0.000203, -0.66798]], # zmps
149  [[0]*6*4], # wrenchs
150  [[1,1,0,0,1,1,1,1]], # optionals
151  [0.5]); # tms
152  hcf.stopAutoBalancer()
153  hcf.seq_svc.waitInterpolation()
154  stp = hcf.st_svc.getParameter()
155  stp.emergency_check_mode=OpenHRP.StabilizerService.NO_CHECK # Disable checking of emergency error because currently this error checker does not work correctly during walking.
156  hcf.st_svc.setParameter(stp)
157  #changeSTAlgorithm (OpenHRP.StabilizerService.EEFMQPCOP)
158  changeSTAlgorithm (OpenHRP.StabilizerService.EEFMQP)
159  hcf.startStabilizer()
160  # Exec loadPattern
161  HRPSYS_DIR=check_output(['pkg-config', 'hrpsys-base', '--variable=prefix']).rstrip()
162  hcf.loadPattern(HRPSYS_DIR+'/share/hrpsys/samples/SampleRobot/data/samplerobot-gopos000', 0.0)
163  hcf.waitInterpolation()
165  if ret:
166  print >> sys.stderr, " ST + loadPattern => OK"
167  assert(ret)
168  else:
169  print >> sys.stderr, " This sample is neglected in High-gain mode simulation"
170 
172  print >> sys.stderr, "4. start and stop TPCC st"
173  if hcf.pdc:
174  # setup controllers
175  hcf.startAutoBalancer()
176  changeSTAlgorithm (OpenHRP.StabilizerService.TPCC)
177  hcf.startStabilizer ()
178  #hcf.abc_svc.goPos(0.5, 0.1, 10)
179  #hcf.abc_svc.waitFootSteps()
181  if ret:
182  print >> sys.stderr, " Start and Stop Stabilizer => OK"
183  assert(ret)
184  else:
185  print >> sys.stderr, " This sample is neglected in High-gain mode simulation"
186 
188  print >> sys.stderr, "5. start and stop EEFMQP st"
189  if hcf.pdc:
190  # setup controllers
191  hcf.startAutoBalancer()
192  changeSTAlgorithm (OpenHRP.StabilizerService.EEFMQP)
193  hcf.startStabilizer()
194  hcf.abc_svc.goPos(0.3, 0, 0)
195  hcf.abc_svc.waitFootSteps()
197  if ret:
198  print >> sys.stderr, " Start and Stop Stabilizer => OK"
199  assert(ret)
200  else:
201  print >> sys.stderr, " This sample is neglected in High-gain mode simulation"
202 
204  print >> sys.stderr, "6. EEFMQPCOP + stair"
205  if hcf.pdc:
206  # setup controllers
208  changeSTAlgorithm (OpenHRP.StabilizerService.EEFMQPCOP)
209  hcf.startStabilizer()
210  hcf.startAutoBalancer()
211  hcf.seq_svc.setJointAngles(half_sitting_pose, 1.0);
212  hcf.waitInterpolation();
214  # set gg param
215  ggp = hcf.abc_svc.getGaitGeneratorParam()[1]
216  org_ggp = hcf.abc_svc.getGaitGeneratorParam()[1]
217  ggp.default_orbit_type = OpenHRP.AutoBalancerService.STAIR
218  ggp.swing_trajectory_time_offset_xy2z=0.1
219  ggp.swing_trajectory_delay_time_offset=0.2
220  ggp.toe_heel_phase_ratio=[0.05, 0.25, 0.20, 0.0, 0.18, 0.23, 0.09]
221  ggp.toe_pos_offset_x = 1e-3*182.0;
222  ggp.heel_pos_offset_x = 1e-3*-72.0;
223  ggp.toe_zmp_offset_x = 1e-3*182.0;
224  ggp.heel_zmp_offset_x = 1e-3*-72.0;
225  ggp.use_toe_heel_transition=True
226  ggp.use_toe_heel_auto_set = True
227  ggp.toe_angle = 20;
228  ggp.heel_angle = 10;
229  hcf.abc_svc.setGaitGeneratorParam(ggp)
231  hcf.setFootSteps([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,-0.09,0], [1,0,0,0], "rleg")]),
232  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.27,0.09,0.1], [1,0,0,0], "lleg")]),
233  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.27,-0.09,0.1], [1,0,0,0], "rleg")]),
234  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.54,0.09,0], [1,0,0,0], "lleg")]),
235  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.54,-0.09,0], [1,0,0,0], "rleg")])]);
237  hcf.abc_svc.waitFootSteps();
239  # finish
240  hcf.abc_svc.setGaitGeneratorParam(org_ggp)
243  if ret:
244  print >> sys.stderr, " ST + Stair => OK"
245  assert(ret)
246  else:
247  print >> sys.stderr, " This sample is neglected in High-gain mode simulation"
248 
250  print >> sys.stderr, "7. EEFMQPCOP + toeheel"
251  if hcf.pdc:
252  # setup controllers
253  hcf.startAutoBalancer()
254  hcf.co_svc.disableCollisionDetection()
255  changeSTAlgorithm (OpenHRP.StabilizerService.EEFMQPCOP)
256  hcf.startStabilizer()
257  hcf.seq_svc.setJointAngles(initial_pose, 2.0);
258  hcf.waitInterpolation();
259  # set gg param
260  ggp = hcf.abc_svc.getGaitGeneratorParam()[1]
261  org_ggp = hcf.abc_svc.getGaitGeneratorParam()[1]
262  ggp.default_orbit_type = OpenHRP.AutoBalancerService.RECTANGLE
263  ggp.swing_trajectory_time_offset_xy2z=0.1
264  ggp.swing_trajectory_delay_time_offset=0.2
265  ggp.toe_heel_phase_ratio=[0.05, 0.35, 0.20, 0.0, 0.13, 0.13, 0.14]
266  ggp.toe_pos_offset_x = 1e-3*182.0;
267  ggp.heel_pos_offset_x = 1e-3*-72.0;
268  ggp.toe_zmp_offset_x = 1e-3*182.0;
269  ggp.heel_zmp_offset_x = 1e-3*-72.0;
270  ggp.use_toe_heel_transition=True
271  ggp.use_toe_heel_auto_set=True
272  # test setFootStepsWithParam
273  ggp.default_double_support_ratio=0.7
274  hcf.abc_svc.setGaitGeneratorParam(ggp)
275  for sgn in [1, -1]:
276  hcf.setFootStepsWithParam([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,-0.09,0], [1,0,0,0], "rleg")]),
277  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([sgn*0.22,0.09,0], [1,0,0,0], "lleg")]),
278  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([sgn*0.44,-0.09,0], [1,0,0,0], "rleg")]),
279  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([sgn*0.44,0.09,0], [1,0,0,0], "lleg")])],
280  [OpenHRP.AutoBalancerService.StepParams([OpenHRP.AutoBalancerService.StepParam(step_height=0.0, step_time=1.0, toe_angle=0.0, heel_angle=0.0)]),
281  OpenHRP.AutoBalancerService.StepParams([OpenHRP.AutoBalancerService.StepParam(step_height=0.05, step_time=4.0, toe_angle=20.0, heel_angle=10.0)]),
282  OpenHRP.AutoBalancerService.StepParams([OpenHRP.AutoBalancerService.StepParam(step_height=0.05, step_time=4.0, toe_angle=20.0, heel_angle=10.0)]),
283  OpenHRP.AutoBalancerService.StepParams([OpenHRP.AutoBalancerService.StepParam(step_height=0.05, step_time=4.0, toe_angle=20.0, heel_angle=10.0)])])
284  hcf.abc_svc.waitFootSteps();
285  # test goPos
286  ggp.default_double_support_ratio=0.2
287  ggp.stride_parameter=[0.22,0.1,20.0,0.22]
288  ggp.toe_angle = 20;
289  ggp.heel_angle = 10;
290  hcf.abc_svc.setGaitGeneratorParam(ggp)
291  for sgn in [1, -1]:
292  hcf.abc_svc.goPos(sgn*0.66,sgn*0.2,sgn*40);
293  hcf.abc_svc.waitFootSteps();
294  # finish
295  hcf.abc_svc.setGaitGeneratorParam(org_ggp)
296  hcf.co_svc.enableCollisionDetection()
298  if ret:
299  print >> sys.stderr, " ST + ToeHeel => OK"
300  assert(ret)
301  else:
302  print >> sys.stderr, " This sample is neglected in High-gain mode simulation"
303 
305  print >> sys.stderr, "8. EEFMQPCOP st + Turn walk"
306  if hcf.pdc:
307  hcf.startAutoBalancer()
308  hcf.co_svc.disableCollisionDetection()
309  changeSTAlgorithm (OpenHRP.StabilizerService.EEFMQPCOP)
310  hcf.startStabilizer()
311  ggp = hcf.abc_svc.getGaitGeneratorParam()[1]
312  org_ggp = hcf.abc_svc.getGaitGeneratorParam()[1]
313  ggp.stride_parameter=[0.15, 0.15, 90.0, 0.05]
314  hcf.abc_svc.setGaitGeneratorParam(ggp)
315  hcf.abc_svc.goPos(0,-0.2,0);
316  hcf.abc_svc.waitFootSteps();
317  hcf.abc_svc.goPos(0,0,175);
318  hcf.abc_svc.waitFootSteps();
319  hcf.abc_svc.goPos(0.4,0.15,40);
320  hcf.abc_svc.waitFootSteps();
321  # Wait for non-st osscilation being samalpl
322  hcf.abc_svc.setGaitGeneratorParam(org_ggp)
323  hcf.co_svc.enableCollisionDetection()
325  if ret:
326  print >> sys.stderr, " ST + Turnwalk => OK"
327  assert(ret)
328  else:
329  print >> sys.stderr, " This sample is neglected in High-gain mode simulation"
330 
331 
333  # This example is from YoheiKakiuchi's comment : https://github.com/fkanehiro/hrpsys-base/issues/1098, https://github.com/fkanehiro/hrpsys-base/pull/1102#issuecomment-284609203
334  print >> sys.stderr, "9. ST Transition (in the air and on the ground)"
335  if hcf.pdc:
336  # Init
337  stp_org = hcf.st_svc.getParameter()
338  stp = hcf.st_svc.getParameter()
339  stp.transition_time = 0.1; # for fast checking
340  hcf.st_svc.setParameter(stp)
341  # Tests
342  print >> sys.stderr, " 9-1. Check in the air"
343  hcf.startStabilizer()
344  mimicInTheAir()
345  hcf.setJointAngles(hcf.getJointAngles(), stp.transition_time);hcf.waitInterpolation() # Wait transition
346  cmode1 = hcf.st_svc.getParameter().controller_mode
347  vcheck1 = (cmode1 == OpenHRP.StabilizerService.MODE_AIR)
348  print >> sys.stderr, " 9-2. Check on the ground"
350  hcf.setJointAngles(hcf.getJointAngles(), stp.transition_time);hcf.waitInterpolation() # Wait transition
351  cmode2 = hcf.st_svc.getParameter().controller_mode
352  vcheck2 = (cmode2 == OpenHRP.StabilizerService.MODE_ST)
353  print >> sys.stderr, " 9-3. Check in the air and then stopST"
354  mimicInTheAir()
355  hcf.setJointAngles(hcf.getJointAngles(), 0.01);hcf.waitInterpolation() # Wait until in the air flag is invoked in onExecute
356  hcf.stopStabilizer()
357  cmode3 = hcf.st_svc.getParameter().controller_mode
358  vcheck3 = (cmode3 == OpenHRP.StabilizerService.MODE_IDLE)
359  print >> sys.stderr, " 9-4. Check on the ground"
361  hcf.setJointAngles(hcf.getJointAngles(), 0.01);hcf.waitInterpolation() # Wait until on the ground flag is invoked in onExecute
362  hcf.startStabilizer()
363  cmode4 = hcf.st_svc.getParameter().controller_mode
364  vcheck4 = (cmode4 == OpenHRP.StabilizerService.MODE_ST)
365  # Finsh
366  hcf.st_svc.setParameter(stp_org)
367  vcheck_list = [vcheck1, vcheck2, vcheck3, vcheck4]
368  print >> sys.stderr, " ST Transition Air Ground vcheck = ", vcheck_list, ", cmode = ", [cmode1, cmode2, cmode3, cmode4]
369  if all(vcheck_list):
370  print >> sys.stderr, " ST Transition Air Ground => OK"
371  assert(all(vcheck_list))
372  else:
373  print >> sys.stderr, " This sample is neglected in High-gain mode simulation"
374 
376  print >> sys.stderr, "10. ST root rot change"
377  if hcf.pdc:
378  # 10deg
379  root_rot_x_pose=[-0.240857,-0.634561,0.012382,1.30211,-0.669201,0.073893,0.31129,-0.159481,-0.115399,-0.636277,0.0,0.0,0.0,-0.232865,-0.555515,0.011753,1.1356,-0.581653,0.06476,0.31129,0.159481,0.115399,-0.636277,0.0,0.0,0.0,0.0,0.0,0.0]
380  # 35deg
381  root_rot_y_pose=[-1.706033e-05,-1.04708,-0.000479,0.497763,-0.060719,-0.000105,0.31129,-0.159481,-0.115399,-0.636277,0.0,0.0,0.0,-1.690260e-05,-1.04693,-0.000479,0.497318,-0.060422,-0.000105,0.31129,0.159481,0.115399,-0.636277,0.0,0.0,0.0,0.0,0.0,0.0]
382  # 25deg
383  root_rot_z_pose=[-0.261382,-0.479591,-0.490714,1.26471,-0.722778,0.018041,0.31129,-0.159481,-0.115399,-0.636277,0.0,0.0,0.0,-0.313108,-0.610397,-0.535653,1.24943,-0.571839,-0.013257,0.31129,0.159481,0.115399,-0.636277,0.0,0.0,0.0,0.0,0.0,0.0]
384  # all 10deg
385  root_rot_xyz_pose=[-0.378611,-0.81283,-0.238181,1.23534,-0.577915,0.061071,0.31129,-0.159481,-0.115399,-0.636277,0.0,0.0,0.0,-0.351695,-0.768514,-0.225097,1.05221,-0.442267,0.050849,0.31129,0.159481,0.115399,-0.636277,0.0,0.0,0.0,0.0,0.0,0.0]
386  hcf.startAutoBalancer();
387  changeSTAlgorithm (OpenHRP.StabilizerService.EEFMQPCOP)
388  print >> sys.stderr, " init"
390  hcf.seq_svc.setJointAngles(root_rot_x_pose, 1.0);hcf.waitInterpolation();
391  hcf.seq_svc.setJointAngles(root_rot_x_pose, 1.0);hcf.waitInterpolation(); # dummy for wait
392  print >> sys.stderr, " root rot x done."
394  hcf.seq_svc.setJointAngles(root_rot_y_pose, 1.0);hcf.waitInterpolation();
395  hcf.seq_svc.setJointAngles(root_rot_y_pose, 1.0);hcf.waitInterpolation(); # dummy for wait
396  print >> sys.stderr, " root rot y done."
398  hcf.seq_svc.setJointAngles(root_rot_z_pose, 1.0);hcf.waitInterpolation();
399  hcf.seq_svc.setJointAngles(root_rot_z_pose, 1.0);hcf.waitInterpolation(); # dummy for wait
400  print >> sys.stderr, " root rot z done."
402  hcf.seq_svc.setJointAngles(root_rot_xyz_pose, 1.0);hcf.waitInterpolation();
403  hcf.seq_svc.setJointAngles(root_rot_xyz_pose, 1.0);hcf.waitInterpolation(); # dummy for wait
404  hcf.seq_svc.setJointAngles(initial_pose, 1.0);hcf.waitInterpolation();
405  print >> sys.stderr, " root rot xyz done."
407  if ret:
408  print >> sys.stderr, " ST root rot change => OK"
409  assert(ret)
410  else:
411  print >> sys.stderr, " This sample is neglected in High-gain mode simulation"
412 
413 def demoSTMimicRouchTerrainWalk (terrain_height_diff = 0.04):
414  print >> sys.stderr, "11. ST mimic rough terrain walk"
415  if hcf.pdc:
416  hcf.setFootSteps([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,-0.09,0], [1,0,0,0], "rleg")]),
417  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.22,0.09,terrain_height_diff], [1,0,0,0], "lleg")]),
418  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.44,-0.09,0], [1,0,0,0], "rleg")]),
419  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.44,0.09,0], [1,0,0,0], "lleg")])]);
420  hcf.abc_svc.waitFootSteps();
421  hcf.setFootSteps([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,-0.09,0], [1,0,0,0], "rleg")]),
422  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.22,0.09,-1*terrain_height_diff], [1,0,0,0], "lleg")]),
423  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.44,-0.09,0], [1,0,0,0], "rleg")]),
424  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.44,0.09,0], [1,0,0,0], "lleg")])]);
425  hcf.abc_svc.waitFootSteps();
427  if ret:
428  print >> sys.stderr, " ST mimic rough terrain walk => OK"
429  assert(ret)
430  else:
431  print >> sys.stderr, " This sample is neglected in High-gain mode simulation"
432 
433 
434 def demo():
435  OPENHRP3_DIR=check_output(['pkg-config', 'openhrp3.1', '--variable=prefix']).rstrip()
436  if os.path.exists(OPENHRP3_DIR+"/share/OpenHRP-3.1/sample/model/sample1_bush.wrl"):
437  init()
438  if StrictVersion(hrpsys_version) >= StrictVersion('315.5.0'):
450  else:
451  print >> sys.stderr, "Skip st test because of missing sample1_bush.wrl"
452 
453 if __name__ == '__main__':
454  demo()
def checkParameterFromLog(port_name, log_fname="/tmp/test-samplerobot-stabilizer-check-param", save_log=True, rtc_name="SampleRobot(Robot)0")
def readDataPort(port, timeout=1.0)
read data from a data port
Definition: jython/rtm.py:574
def saveLogForCheckParameter(log_fname="/tmp/test-samplerobot-stabilizer-check-param")
def demoSTMimicRouchTerrainWalk(terrain_height_diff=0.04)


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:51