samplerobot_auto_balancer.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 try:
00004     from hrpsys.hrpsys_config import *
00005     import OpenHRP
00006 except:
00007     print "import without hrpsys"
00008     import rtm
00009     from rtm import *
00010     from OpenHRP import *
00011     import waitInput
00012     from waitInput import *
00013     import socket
00014     import time
00015 
00016 def defJointGroups ():
00017     rleg_6dof_group = ['rleg', ['RLEG_HIP_R', 'RLEG_HIP_P', 'RLEG_HIP_Y', 'RLEG_KNEE', 'RLEG_ANKLE_P', 'RLEG_ANKLE_R']]
00018     lleg_6dof_group = ['lleg', ['LLEG_HIP_R', 'LLEG_HIP_P', 'LLEG_HIP_Y', 'LLEG_KNEE', 'LLEG_ANKLE_P', 'LLEG_ANKLE_R']]
00019     torso_group = ['torso', ['WAIST_P', 'WAIST_R', 'CHEST']]
00020     head_group = ['head', []]
00021     rarm_group = ['rarm', ['RARM_SHOULDER_P', 'RARM_SHOULDER_R', 'RARM_SHOULDER_Y', 'RARM_ELBOW', 'RARM_WRIST_Y', 'RARM_WRIST_P', 'RARM_WRIST_R']]
00022     larm_group = ['larm', ['LARM_SHOULDER_P', 'LARM_SHOULDER_R', 'LARM_SHOULDER_Y', 'LARM_ELBOW', 'LARM_WRIST_Y', 'LARM_WRIST_P', 'LARM_WRIST_R']]
00023     return [rleg_6dof_group, lleg_6dof_group, torso_group, head_group, rarm_group, larm_group]
00024 
00025 def init ():
00026     global hcf, initial_pose, arm_front_pose, half_sitting_pose, root_rot_x_pose, root_rot_y_pose, pose_list, hrpsys_version, four_legs_mode_pose
00027     hcf = HrpsysConfigurator()
00028     hcf.getRTCList = hcf.getRTCListUnstable
00029     hcf.init ("SampleRobot(Robot)0", "$(PROJECT_DIR)/../model/sample1.wrl")
00030     hcf.connectLoggerPort(hcf.abc, 'baseRpyOut') # Just for checking
00031     hcf.Groups = defJointGroups()
00032     # set initial pose from sample/controller/SampleController/etc/Sample.pos
00033     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]
00034     arm_front_pose = [-7.778932e-05,-0.378613,-0.00021,0.832039,-0.452564,0.000245,-1.5708,-0.159481,-0.115399,-0.349066,0.0,0.0,0.0,-7.778932e-05,-0.378613,-0.00021,0.832039,-0.452564,0.000245,-1.5708,0.159481,0.115399,-0.349066,0.0,0.0,0.0,0.0,0.0,0.0]
00035     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]
00036     root_rot_x_pose = [-0.241557,-0.634167,0.011778,1.30139,-0.668753,0.074236,0.31129,-0.159481,-0.115399,-0.636277,0.0,0.0,0.0,-0.233491,-0.555191,0.011181,1.13468,-0.580942,0.065086,0.31129,0.159481,0.115399,-0.636277,0.0,0.0,0.0,0.0,0.0,0.0]
00037     root_rot_y_pose = [8.251963e-05,-0.980029,-0.000384,1.02994,-0.398115,-0.000111,0.31129,-0.159481,-0.115399,-0.636277,0.0,0.0,0.0,8.252625e-05,-0.980033,-0.000384,1.02986,-0.398027,-0.000111,0.31129,0.159481,0.115399,-0.636277,0.0,0.0,0.0,0.0,0.0,0.0]
00038     four_legs_mode_pose = [0.0, -0.349066, 0.0, 0.820305, -0.471239, 0.0, 0.493231, 0.008013, 0.000304, -1.608, 0.008019, -0.456023, 0.637045, 0.0, -0.349066, 0.0, 0.820305, -0.471239, 0.0, 0.493231, -0.008013, -0.000304, -1.608, -0.008019, -0.456023, -0.637045, 0.0, 0.0, 0.0]
00039     pose_list=[half_sitting_pose, root_rot_x_pose, root_rot_y_pose, arm_front_pose, four_legs_mode_pose]
00040     hcf.seq_svc.setJointAngles(initial_pose, 2.0)
00041     hcf.waitInterpolation()
00042     hrpsys_version = hcf.seq.ref.get_component_profile().version
00043     print("hrpsys_version = %s"%hrpsys_version)
00044 
00045 def testPoseList(pose_list, initial_pose):
00046     for pose in pose_list:
00047         hcf.seq_svc.setJointAngles(pose, 1.0)
00048         hcf.waitInterpolation()
00049         hcf.seq_svc.setJointAngles(initial_pose, 1.0)
00050         hcf.waitInterpolation()
00051 
00052 def saveLogForCheckParameter(log_fname="/tmp/test-samplerobot-auto-balancer-check-param"):
00053     hcf.setMaxLogLength(1);hcf.clearLog();time.sleep(0.1);hcf.saveLog(log_fname)
00054 
00055 def checkParameterFromLog(port_name, log_fname="/tmp/test-samplerobot-auto-balancer-check-param", save_log=True, rtc_name="SampleRobot(Robot)0"):
00056     if save_log:
00057         saveLogForCheckParameter(log_fname)
00058     return map(float, open(log_fname+"."+rtc_name+"_"+port_name, "r").readline().split(" ")[1:-1])
00059 
00060 def checkActualBaseAttitude(ref_rpy = None, thre=0.1): # degree
00061     '''Check whether the robot falls down based on actual robot base-link attitude.
00062     '''
00063     act_rpy = checkParameterFromLog("WAIST")[3:]
00064     if ref_rpy == None:
00065         ref_rpy = checkParameterFromLog("baseRpyOut", rtc_name="sh", save_log=False)
00066     ret = abs(math.degrees(act_rpy[0]-ref_rpy[0])) < thre and abs(math.degrees(act_rpy[1]-ref_rpy[1])) < thre
00067     print >> sys.stderr, "  ret = ", ret, ", actual base rpy = (", act_rpy, "), ", "reference base rpy = (", ref_rpy, ")"
00068     assert (ret)
00069     return ret
00070 
00071 def Quaternion2Angle(q):
00072     w, v = q[0], q[1:]
00073     theta = math.acos(w) * 2.0
00074     return theta
00075 
00076 def Quaternion2RotMatrixZ(q):
00077     theta = Quaternion2Angle(q)
00078     return numpy.array([[numpy.cos(theta), -numpy.sin(theta), 0],
00079                         [numpy.sin(theta),  numpy.cos(theta), 0],
00080                         [               0,                 0, 1]])
00081 
00082 
00083 def calcDiffFootMidCoords (prev_dst_foot_midcoords):
00084     '''Calculate difference from previous dst_foot_midcoords and current dst_foot_midcoords.
00085     Returns difx, dify, difth, which are gopos parameters
00086     '''
00087     new_dst_foot_midcoords=hcf.abc_svc.getFootstepParam()[1].dst_foot_midcoords
00088     # Check diff
00089     difxy = (Quaternion2RotMatrixZ(prev_dst_foot_midcoords.rot).transpose()).dot((numpy.array([new_dst_foot_midcoords.pos])-numpy.array([prev_dst_foot_midcoords.pos])).transpose())
00090     difth = math.degrees(Quaternion2Angle(new_dst_foot_midcoords.rot)-Quaternion2Angle(prev_dst_foot_midcoords.rot))
00091     return [difxy[0,0], difxy[1,0], difth]
00092 
00093 def checkGoPosParam (goalx, goaly, goalth, prev_dst_foot_midcoords):
00094     '''Check whether goPos argument are correctly achieved based on dst_foot_midcoords values.
00095     goPos params should be "new_dst_foot_midcoords - prev_dst_foot_midcoords"
00096     '''
00097     # Check diff
00098     [difx, dify, difth] = calcDiffFootMidCoords(prev_dst_foot_midcoords)
00099     ret = (abs(difx-goalx) < 5e-5 and abs(dify-goaly) < 5e-5 and abs(difth-goalth) < 1e-2)
00100     print >> sys.stderr, "  Check goPosParam (diff = ", (difx-goalx), "[m], ", (dify-goaly), "[m], ", (difth-goalth), "[deg])"
00101     print >> sys.stderr, "  => ", ret
00102     assert(ret)
00103     return ret
00104 
00105 def calcVelListFromPosList(pos_list, dt):
00106     '''Calculate velocity list from position list.
00107     Element of pos_list and vel_list should be list like [0,0,0].
00108     '''
00109     vel_list=[]
00110     ppos=pos_list[0]
00111     for pos in pos_list:
00112         vel_list.append(map(lambda x, y: (x-y)/dt, pos, ppos));
00113         ppos=pos
00114     return vel_list
00115 
00116 def checkTooLargeABCCogAcc (acc_thre = 5.0): # [m/s^2]
00117     '''Check ABC too large cog acceleration.
00118     This is used discontinuous cog trajectory.
00119     '''
00120     # Parse COG [m] and tm [s]
00121     cog_list=[]
00122     tm_list=[]
00123     for line in open("/tmp/test-abc-log.abc_cogOut", "r"):
00124         tm_list.append(float(line.split(" ")[0]));
00125         cog_list.append(map(float, line.split(" ")[1:-1]));
00126     cog_list=cog_list[:-1000] # ?? Neglect latter elements
00127     dt = tm_list[1]-tm_list[0] # [s]
00128     # Calculate velocity and acceleration
00129     dcog_list=calcVelListFromPosList(cog_list, dt)
00130     ddcog_list=calcVelListFromPosList(dcog_list, dt)
00131     # Check max
00132     max_cogx_acc = max(map(lambda x : abs(x[0]), ddcog_list))
00133     max_cogy_acc = max(map(lambda x : abs(x[1]), ddcog_list))
00134     ret = (max_cogx_acc < acc_thre) and (max_cogy_acc < acc_thre)
00135     print >> sys.stderr, "  Check acc x = ", max_cogx_acc, ", y = ", max_cogy_acc, ", thre = ", acc_thre, "[m/s^2], ret = ", ret
00136     assert(ret)
00137 
00138 def demoAutoBalancerFixFeet ():
00139     print >> sys.stderr, "1. AutoBalancer mode by fixing feet"
00140     hcf.startAutoBalancer(["rleg", "lleg"]);
00141     hcf.seq_svc.setJointAngles(arm_front_pose, 1.0)
00142     hcf.waitInterpolation()
00143     hcf.seq_svc.setJointAngles(initial_pose, 1.0)
00144     hcf.waitInterpolation()
00145     hcf.stopAutoBalancer();
00146     checkActualBaseAttitude()
00147     print >> sys.stderr, "  Start and Stop AutoBalancer by fixing feet=>OK"
00148 
00149 def demoAutoBalancerFixFeetHands ():
00150     print >> sys.stderr, "2. AutoBalancer mode by fixing hands and feet"
00151     hcf.startAutoBalancer()
00152     hcf.seq_svc.setJointAngles(arm_front_pose, 1.0)
00153     hcf.waitInterpolation()
00154     hcf.seq_svc.setJointAngles(initial_pose, 1.0)
00155     hcf.waitInterpolation()
00156     hcf.stopAutoBalancer();
00157     checkActualBaseAttitude()
00158     print >> sys.stderr, "  Start and Stop AutoBalancer by fixing hands and feet=>OK"
00159 
00160 def demoAutoBalancerGetParam():
00161     print >> sys.stderr, "3. getAutoBalancerParam"
00162     ret = hcf.abc_svc.getAutoBalancerParam()
00163     if ret[0]:
00164         print >> sys.stderr, "  getAutoBalancerParam() => OK"
00165 
00166 def demoAutoBalancerSetParam():
00167     print >> sys.stderr, "4. setAutoBalancerParam"
00168     abcp=hcf.abc_svc.getAutoBalancerParam()[1]
00169     abcp.default_zmp_offsets = [[0.1,0,0], [0.1,0,0], [0,0,0], [0,0,0]]
00170     hcf.abc_svc.setAutoBalancerParam(abcp)
00171     print >> sys.stderr, "  default_zmp_offsets setting check in start and stop"
00172     hcf.startAutoBalancer(["rleg", "lleg"]);
00173     hcf.stopAutoBalancer();
00174     ret=hcf.abc_svc.getAutoBalancerParam()
00175     flag = (ret[0] and numpy.allclose(ret[1].default_zmp_offsets, abcp.default_zmp_offsets, 1e-6))
00176     if flag:
00177         print >> sys.stderr, "  setAutoBalancerParam() => OK"
00178     assert (flag), (ret[0], ret[1].default_zmp_offsets, abcp.default_zmp_offsets)
00179     abcp.default_zmp_offsets = [[0,0,0], [0,0,0], [0,0,0], [0,0,0]]
00180     hcf.abc_svc.setAutoBalancerParam(abcp)
00181 
00182 def demoAutoBalancerTestPoses():
00183     print >> sys.stderr, "5. change base height, base rot x, base rot y, and upper body while AutoBalancer mode"
00184     hcf.startAutoBalancer(["rleg", "lleg"]);
00185     testPoseList(pose_list, initial_pose)
00186     hcf.stopAutoBalancer();
00187     checkActualBaseAttitude()
00188 
00189 def demoAutoBalancerStartStopCheck():
00190     print >> sys.stderr, "6. start stop check"
00191     abcp=hcf.abc_svc.getAutoBalancerParam()[1]
00192     abcp.default_zmp_offsets = [[-0.05,0.05,0], [-0.05,0.05,0], [0,0,0], [0,0,0]]
00193     hcf.abc_svc.setAutoBalancerParam(abcp)
00194     hcf.setMaxLogLength(1500)
00195     for pose in pose_list:
00196         hcf.seq_svc.setJointAngles(pose, 1.0)
00197         hcf.waitInterpolation()
00198         hcf.clearLog()
00199         hcf.startAutoBalancer(["rleg", "lleg"]);
00200         hcf.stopAutoBalancer();
00201         hcf.saveLog("/tmp/test-samplerobot-abc-startstop-{0}".format(pose_list.index(pose)))
00202     abcp.default_zmp_offsets = [[0,0,0], [0,0,0], [0,0,0], [0,0,0]]
00203     hcf.abc_svc.setAutoBalancerParam(abcp)
00204     hcf.seq_svc.setJointAngles(initial_pose, 1.0)
00205     hcf.waitInterpolation()
00206     checkActualBaseAttitude()
00207 
00208 def demoAutoBalancerBalanceAgainstHandForce():
00209     print >> sys.stderr, "7. balance against hand force"
00210     hcf.startAutoBalancer(["rleg", "lleg"]);
00211     hcf.seq_svc.setWrenches([0,0,0,0,0,0,
00212                              0,0,0,0,0,0,
00213                              0,0,0,0,0,0,
00214                              0,0,-50,0,0,0,], 1.0); # rhsensor
00215     hcf.waitInterpolation();
00216     hcf.seq_svc.setWrenches([0,0,0,0,0,0,
00217                              0,0,0,0,0,0,
00218                              0,0,0,0,0,0,
00219                              0,0,0,0,0,0,], 1.0);
00220     hcf.waitInterpolation();
00221     hcf.stopAutoBalancer();
00222     checkActualBaseAttitude()
00223 
00224 def demoAutoBalancerBalanceWithArms():
00225     print >> sys.stderr, "8. balance with arms"
00226     hcf.seq_svc.setJointAngles(four_legs_mode_pose, 1.0)
00227     hcf.waitInterpolation()
00228     abcp=hcf.abc_svc.getAutoBalancerParam()[1]
00229     abcp.leg_names = ['rleg', 'lleg', 'rarm', 'larm']
00230     hcf.abc_svc.setAutoBalancerParam(abcp)
00231     hcf.startAutoBalancer();
00232     print >> sys.stderr, "  startAutoBalancer with arms"
00233     hcf.stopAutoBalancer();
00234     print >> sys.stderr, "  stopAutoBalancer"
00235     abcp.leg_names = ['rleg', 'lleg']
00236     hcf.abc_svc.setAutoBalancerParam(abcp)
00237     checkActualBaseAttitude()
00238     hcf.seq_svc.setJointAngles(initial_pose, 1.0)
00239     hcf.waitInterpolation()
00240 
00241 def demoGaitGeneratorBaseTformCheck ():
00242     print >> sys.stderr, "0. baseTform check"
00243     # Set parameter
00244     orig_ggp = hcf.abc_svc.getGaitGeneratorParam()[1]
00245     orig_abcp = hcf.abc_svc.getAutoBalancerParam()[1]
00246     hcf.co_svc.disableCollisionDetection()
00247     ggp = hcf.abc_svc.getGaitGeneratorParam()[1]
00248     ggp.stride_parameter = [0.2, 0.1, 20, 0.15]
00249     ggp.default_step_time = 0.5
00250     hcf.abc_svc.setGaitGeneratorParam(ggp)
00251     abcp = hcf.abc_svc.getAutoBalancerParam()[1]
00252     abcp.transition_time = 0.1
00253     hcf.abc_svc.setAutoBalancerParam(abcp)
00254     btf0 = checkParameterFromLog("baseTformOut", rtc_name="abc")
00255     # Check start ABC
00256     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
00257                                            [[0]*29], # vels
00258                                            [[0]*29], # torques
00259                                            [[btf0[0]+0.2+-0.014759, btf0[1]+-0.1+-4.336272e-05, 0.668138]], # poss
00260                                            [[-0.000245, -0.000862, 0.000171]], # rpys
00261                                            [[0]*3], # accs
00262                                            [[0.014052, 0.000203, -0.66798]], # zmps
00263                                            [[0]*6*4], # wrenchs
00264                                            [[1,1,0,0,1,1,1,1]], # optionals
00265                                            [0.5]); # tms
00266     hcf.waitInterpolation()
00267     btf1 = checkParameterFromLog("baseTformOut", rtc_name="abc")
00268     hcf.startAutoBalancer()
00269     btf2 = checkParameterFromLog("baseTformOut", rtc_name="abc")
00270     # Check stop ABC
00271     hcf.abc_svc.goPos(-0.2, 0.1, 0)
00272     hcf.abc_svc.waitFootSteps()
00273     btf3 = checkParameterFromLog("baseTformOut", rtc_name="abc")
00274     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
00275                                            [[0]*29], # vels
00276                                            [[0]*29], # torques
00277                                            [[btf0[0]+-0.014759, btf0[1]+-4.336272e-05, 0.668138]], # poss
00278                                            [[-0.000245, -0.000862, 0.000171]], # rpys
00279                                            [[0]*3], # accs
00280                                            [[0.014052, 0.000203, -0.66798]], # zmps
00281                                            [[0]*6*4], # wrenchs
00282                                            [[1,1,0,0,1,1,1,1]], # optionals
00283                                            [0.1]); # tms
00284     hcf.waitInterpolation()
00285     hcf.stopAutoBalancer()
00286     btf4 = checkParameterFromLog("baseTformOut", rtc_name="abc")
00287     # Finalize
00288     hcf.abc_svc.setGaitGeneratorParam(orig_ggp)
00289     hcf.abc_svc.setAutoBalancerParam(orig_abcp)
00290     hcf.co_svc.enableCollisionDetection()
00291     # Check values (currently pos x,y only 1[mm])
00292     startABC_OK = all(map (lambda x,y : abs(x-y)<1*1e-3, btf1[0:3], btf2[0:3]))
00293     stopABC_OK  = all(map (lambda x,y : abs(x-y)<1*1e-3, btf3[0:3], btf4[0:3]))
00294     print >> sys.stderr, "  before startABC = ", btf1[0:3], ", after startABC = ", btf2[0:3], ", diff = ", startABC_OK
00295     print >> sys.stderr, "  before stopABC  = ", btf3[0:3], ", after stopABC  = ", btf4[0:3], ", diff = ", stopABC_OK
00296     assert(startABC_OK and stopABC_OK)
00297 
00298 def demoGaitGeneratorGoPos():
00299     print >> sys.stderr, "1. goPos"
00300     hcf.startAutoBalancer();
00301     # initialize dst_foot_midcoords
00302     hcf.abc_svc.goPos(0,0,0)
00303     hcf.abc_svc.waitFootSteps()
00304     # gopos check 1
00305     goalx=0.1;goaly=0.1;goalth=20.0
00306     prev_dst_foot_midcoords=hcf.abc_svc.getFootstepParam()[1].dst_foot_midcoords
00307     hcf.abc_svc.goPos(goalx, goaly, goalth)
00308     hcf.abc_svc.waitFootSteps()
00309     checkGoPosParam(goalx, goaly, goalth, prev_dst_foot_midcoords)
00310     # gopos check 2
00311     goalx=-0.1;goaly=-0.1;goalth=-10.0
00312     prev_dst_foot_midcoords=hcf.abc_svc.getFootstepParam()[1].dst_foot_midcoords
00313     hcf.abc_svc.goPos(goalx, goaly, goalth)
00314     hcf.abc_svc.waitFootSteps()
00315     checkGoPosParam(goalx, goaly, goalth, prev_dst_foot_midcoords)
00316     checkActualBaseAttitude()
00317     print >> sys.stderr, "  goPos()=>OK"
00318 
00319 def demoGaitGeneratorGoVelocity():
00320     print >> sys.stderr, "2. goVelocity and goStop"
00321     print >> sys.stderr, "  goVelocity few steps"
00322     hcf.abc_svc.goVelocity(-0.1, -0.05, -20)
00323     time.sleep(1)
00324     hcf.abc_svc.goStop()
00325     checkActualBaseAttitude()
00326     print >> sys.stderr, "  goVelocity few steps=>OK"
00327     print >> sys.stderr, "  Check discontinuity of COG by checking too large COG acc."
00328     hcf.setMaxLogLength(10000)
00329     hcf.clearLog()
00330     hcf.abc_svc.goVelocity(0,0,0) # One step overwrite
00331     hcf.abc_svc.goStop()
00332     hcf.saveLog("/tmp/test-abc-log");
00333     checkTooLargeABCCogAcc()
00334 
00335 def demoGaitGeneratorSetFootSteps():
00336     print >> sys.stderr, "3. setFootSteps"
00337     hcf.setFootSteps([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,-0.09,0], [1,0,0,0], "rleg")]),
00338                       OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,0.09,0], [1,0,0,0], "lleg")])])
00339     hcf.abc_svc.waitFootSteps()
00340     hcf.setFootSteps([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,-0.09,0], [1,0,0,0], "rleg")]),
00341                       OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.15,0.09,0], [1,0,0,0], "lleg")]),
00342                       OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.3,-0.09,0], [1,0,0,0], "rleg")]),
00343                       OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.3,0.09,0], [1,0,0,0], "lleg")])])
00344     hcf.abc_svc.waitFootSteps()
00345     checkActualBaseAttitude()
00346     print >> sys.stderr, "  setFootSteps()=>OK"
00347 
00348 def demoGaitGeneratorChangePoseWhileWalking():
00349     print >> sys.stderr, "4. Change base height, base rot x, base rot y, and upper body while walking"
00350     hcf.abc_svc.waitFootSteps()
00351     hcf.abc_svc.goVelocity(0,0,0)
00352     testPoseList(pose_list, initial_pose)
00353     hcf.abc_svc.goStop()
00354     checkActualBaseAttitude()
00355 
00356 def demoGaitGeneratorGetParam():
00357     print >> sys.stderr, "5. getGaitGeneratorParam"
00358     ret = hcf.abc_svc.getGaitGeneratorParam()
00359     if ret[0]:
00360         print >> sys.stderr, "  getGaitGeneratorParam() => OK"
00361 
00362 def demoGaitGeneratorSetParam():
00363     print >> sys.stderr, "6. setGaitGeneratorParam"
00364     ggp_org = hcf.abc_svc.getGaitGeneratorParam()[1]
00365     ggp = hcf.abc_svc.getGaitGeneratorParam()[1]
00366     ggp.default_step_time = 0.9
00367     ggp.default_step_height = 0.15
00368     ggp.default_double_support_ratio = 0.4
00369     ggp.swing_trajectory_delay_time_offset = 0.20
00370     ggp.default_orbit_type = OpenHRP.AutoBalancerService.RECTANGLE;
00371     hcf.abc_svc.setGaitGeneratorParam(ggp)
00372     ret = hcf.abc_svc.getGaitGeneratorParam()
00373     if ret[0] and ret[1].default_step_time == ggp.default_step_time and ret[1].default_step_height == ggp.default_step_height and ret[1].default_double_support_ratio == ggp.default_double_support_ratio and ret[1].default_orbit_type == ggp.default_orbit_type:
00374         print >> sys.stderr, "  setGaitGeneratorParam() => OK"
00375     hcf.abc_svc.goPos(0.2,0,0)
00376     hcf.abc_svc.waitFootSteps()
00377     hcf.abc_svc.setGaitGeneratorParam(ggp_org) # revert parameter
00378 
00379 def demoGaitGeneratorNonDefaultStrideStop():
00380     print >> sys.stderr, "7. non-default stride"
00381     hcf.setFootSteps([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,-0.09,0], [1,0,0,0], "rleg")]),
00382                       OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.15,0.09,0], [1,0,0,0], "lleg")])])
00383     hcf.abc_svc.waitFootSteps()
00384     hcf.setFootSteps([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,-0.09,0], [1,0,0,0], "rleg")]),
00385                       OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,0.09,0], [1,0,0,0], "lleg")])])
00386     hcf.abc_svc.waitFootSteps()
00387     checkActualBaseAttitude()
00388     print >> sys.stderr, "  Non default Stride()=>OK"
00389 
00390 def demoGaitGeneratorToeHeelContact():
00391     print >> sys.stderr, "8. Use toe heel contact"
00392     ggp=hcf.abc_svc.getGaitGeneratorParam()[1];
00393     ggp.toe_pos_offset_x = 1e-3*182.0;
00394     ggp.heel_pos_offset_x = 1e-3*-72.0;
00395     ggp.toe_zmp_offset_x = 1e-3*182.0;
00396     ggp.heel_zmp_offset_x = 1e-3*-72.0;
00397     ggp.toe_angle = 20;
00398     ggp.heel_angle = 10;
00399     hcf.abc_svc.setGaitGeneratorParam(ggp);
00400     hcf.abc_svc.goPos(0.3, 0, 0);
00401     hcf.abc_svc.waitFootSteps()
00402     ggp.toe_angle = 0;
00403     ggp.heel_angle = 0;
00404     hcf.abc_svc.setGaitGeneratorParam(ggp);
00405     checkActualBaseAttitude()
00406     print >> sys.stderr, "  Toe heel contact=>OK"
00407 
00408 def demoGaitGeneratorStopStartSyncCheck():
00409     print >> sys.stderr, "9. Stop and start auto balancer sync check2"
00410     print >> sys.stderr, "  Check 9-1 Sync after setFootSteps"
00411     hcf.startAutoBalancer();
00412     hcf.setFootSteps([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,-0.09,0], [1,0,0,0], "rleg")]),
00413                       OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.1,0.09,0], [1,0,0,0], "lleg")])]);
00414     hcf.abc_svc.waitFootSteps();
00415     hcf.stopAutoBalancer();
00416     print >> sys.stderr, "    Sync after setFootSteps => OK"
00417     print >> sys.stderr, "  Check 9-2 Sync from setJointAngles at the beginning"
00418     open_stride_pose = [0.00026722677758058496, -0.3170503560247552, -0.0002054613599000865, 0.8240549352035262, -0.5061434785447525, -8.67443660992421e-05, 0.3112899999999996, -0.15948099999999998, -0.11539900000000003, -0.6362769999999993, 0.0, 0.0, 0.0, 0.00023087433689200683, -0.4751295978345554, -0.00021953834197007937, 0.8048588066686679, -0.3288687069275527, -8.676469399681631e-05, 0.3112899999999996, 0.15948099999999998, 0.11539900000000003, -0.6362769999999993, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
00419     hcf.seq_svc.setJointAngles(open_stride_pose, 2.0);
00420     hcf.waitInterpolation();
00421     hcf.startAutoBalancer();
00422     hcf.setFootSteps([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,-0.09,0], [1,0,0,0], "rleg")]),
00423                       OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.1,0.09,0], [1,0,0,0], "lleg")])]);
00424     hcf.abc_svc.waitFootSteps();
00425     hcf.stopAutoBalancer();
00426     print >> sys.stderr, "    Sync from setJointAngle at the beginning => OK"
00427     print >> sys.stderr, "  Check 9-3 Sync from setJointAngles"
00428     hcf.startAutoBalancer();
00429     hcf.seq_svc.setJointAngles(initial_pose, 2.0);
00430     hcf.waitInterpolation();
00431     hcf.stopAutoBalancer();
00432     print >> sys.stderr, "    Sync from setJointAngle => OK"
00433 
00434 def demoGaitGeneratorEmergencyStop():
00435     print >> sys.stderr, "10. Emergency stop"
00436     hcf.startAutoBalancer();
00437     hcf.abc_svc.goPos(0,0,90);
00438     print >> sys.stderr, "  Start goPos and wait for 4 steps"
00439     for idx in range(4): # Wait for 4 steps including initial double support phase
00440         # Wait for 1 steps
00441         hcf.seq_svc.setJointAngles(initial_pose, hcf.abc_svc.getGaitGeneratorParam()[1].default_step_time);
00442         hcf.waitInterpolation();
00443     print >> sys.stderr, "  Emergency stoping"
00444     hcf.abc_svc.emergencyStop();
00445     print >> sys.stderr, "  Align foot steps"
00446     hcf.abc_svc.goPos(0,0,0);
00447     checkActualBaseAttitude()
00448 
00449 def demoGaitGeneratorGetRemainingSteps():
00450     print >> sys.stderr, "11. Get remaining foot steps"
00451     hcf.abc_svc.goPos(0.3,0.1,15);
00452     fslist=hcf.abc_svc.getRemainingFootstepSequence()[1]
00453     while fslist != []:
00454         fslist=hcf.abc_svc.getRemainingFootstepSequence()[1]
00455         print >> sys.stderr, "  Remaining footstep ", len(fslist)
00456         # Wait for 1 step
00457         hcf.seq_svc.setJointAngles(initial_pose, hcf.abc_svc.getGaitGeneratorParam()[1].default_step_time);
00458         hcf.waitInterpolation();
00459     checkActualBaseAttitude()
00460 
00461 def demoGaitGeneratorChangeStepParam():
00462     print >> sys.stderr, "12. Change step param with setFootSteps"
00463     ggp_org=hcf.abc_svc.getGaitGeneratorParam()[1];
00464     # dummy setting
00465     ggp=hcf.abc_svc.getGaitGeneratorParam()[1];
00466     ggp.toe_angle = 50;
00467     ggp.heel_angle = 50;
00468     hcf.abc_svc.setGaitGeneratorParam(ggp);
00469     hcf.setFootStepsWithParam([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,-0.09,0], [1,0,0,0], "rleg")]),
00470                                OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.1,0.09,0], [1,0,0,0], "lleg")]),
00471                                OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.2,-0.09,0], [1,0,0,0], "rleg")]),
00472                                OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.2,0.09,0], [1,0,0,0], "lleg")])],
00473                               [OpenHRP.AutoBalancerService.StepParams([OpenHRP.AutoBalancerService.StepParam(step_height=0.0, step_time=1.0, toe_angle=0.0, heel_angle=0.0)]),
00474                                OpenHRP.AutoBalancerService.StepParams([OpenHRP.AutoBalancerService.StepParam(step_height=0.05, step_time=2.0, toe_angle=0.0, heel_angle=0.0)]),
00475                                OpenHRP.AutoBalancerService.StepParams([OpenHRP.AutoBalancerService.StepParam(step_height=0.05, step_time=1.0, toe_angle=0.0, heel_angle=0.0)]),
00476                                OpenHRP.AutoBalancerService.StepParams([OpenHRP.AutoBalancerService.StepParam(step_height=0.05, step_time=2.0, toe_angle=0.0, heel_angle=0.0)])])
00477     hcf.abc_svc.waitFootSteps()
00478     hcf.setFootStepsWithParam([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,-0.09,0], [1,0,0,0], "rleg")]),
00479                                OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.1,0.09,0], [1,0,0,0], "lleg")]),
00480                                OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.2,-0.09,0], [1,0,0,0], "rleg")]),
00481                                OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.2,0.09,0], [1,0,0,0], "lleg")])],
00482                               [OpenHRP.AutoBalancerService.StepParams([OpenHRP.AutoBalancerService.StepParam(step_height=0.0, step_time=1.0, toe_angle=0.0, heel_angle=0.0)]),
00483                                OpenHRP.AutoBalancerService.StepParams([OpenHRP.AutoBalancerService.StepParam(step_height=0.1, step_time=1.0, toe_angle=0.0, heel_angle=0.0)]),
00484                                OpenHRP.AutoBalancerService.StepParams([OpenHRP.AutoBalancerService.StepParam(step_height=0.05, step_time=1.0, toe_angle=0.0, heel_angle=0.0)]),
00485                                OpenHRP.AutoBalancerService.StepParams([OpenHRP.AutoBalancerService.StepParam(step_height=0.1, step_time=1.0, toe_angle=0.0, heel_angle=0.0)])])
00486     hcf.abc_svc.waitFootSteps()
00487     hcf.setFootStepsWithParam([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,-0.09,0], [1,0,0,0], "rleg")]),
00488                                OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.1,0.09,0], [1,0,0,0], "lleg")]),
00489                                OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.2,-0.09,0], [1,0,0,0], "rleg")]),
00490                                OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.2,0.09,0], [1,0,0,0], "lleg")])],
00491                               [OpenHRP.AutoBalancerService.StepParams([OpenHRP.AutoBalancerService.StepParam(step_height=0.0, step_time=1.0, toe_angle=0.0, heel_angle=0.0)]),
00492                                OpenHRP.AutoBalancerService.StepParams([OpenHRP.AutoBalancerService.StepParam(step_height=0.05, step_time=1.0, toe_angle=0.0, heel_angle=0.0)]),
00493                                OpenHRP.AutoBalancerService.StepParams([OpenHRP.AutoBalancerService.StepParam(step_height=0.05, step_time=1.0, toe_angle=20.0, heel_angle=5.0)]),
00494                                OpenHRP.AutoBalancerService.StepParams([OpenHRP.AutoBalancerService.StepParam(step_height=0.05, step_time=1.0, toe_angle=10.0, heel_angle=10.0)])])
00495     hcf.abc_svc.waitFootSteps()
00496     hcf.abc_svc.setGaitGeneratorParam(ggp_org);
00497     checkActualBaseAttitude()
00498 
00499 def demoGaitGeneratorOverwriteFootsteps(overwrite_offset_idx = 1):
00500     print >> sys.stderr, "13. Overwrite footsteps during walking."
00501     hcf.startAutoBalancer()
00502     demoGaitGeneratorOverwriteFootstepsBase("x", overwrite_offset_idx, True) # Overwrite by X direction foot steps
00503     hcf.seq_svc.setJointAngles(initial_pose, 1.0*overwrite_offset_idx)
00504     hcf.seq_svc.waitInterpolation()
00505     demoGaitGeneratorOverwriteFootstepsBase("y", overwrite_offset_idx, True) # Overwrite by Y direction foot steps
00506     hcf.seq_svc.setJointAngles(initial_pose, 1.0*overwrite_offset_idx)
00507     hcf.seq_svc.waitInterpolation()
00508     demoGaitGeneratorOverwriteFootstepsBase("x", overwrite_offset_idx, True) # Overwrite by X direction foot steps
00509     hcf.abc_svc.waitFootSteps()
00510     checkActualBaseAttitude()
00511 
00512 def demoGaitGeneratorOverwriteFootstepsBase(axis, overwrite_offset_idx = 1, init_fs = False):
00513     if init_fs:
00514         hcf.setFootSteps([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,  -0.09,0], [1,0,0,0], "rleg")]),
00515                           OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.1, 0.09,0], [1,0,0,0], "lleg")]),
00516                           OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.2,-0.09,0], [1,0,0,0], "rleg")]),
00517                           OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.3, 0.09,0], [1,0,0,0], "lleg")]),
00518                           OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.4,-0.09,0], [1,0,0,0], "rleg")]),
00519                           OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.4, 0.09,0], [1,0,0,0], "lleg")])]);
00520     print >> sys.stderr, "  Overwrite footsteps ", overwrite_offset_idx
00521     # Get remaining footstep
00522     [remain_fs, current_fs_idx]=hcf.abc_svc.getRemainingFootstepSequence()[1:]
00523     #print >> sys.stderr, remain_fs
00524     print >> sys.stderr, "    Remaining legs = ", map(lambda fs : fs.leg, remain_fs)
00525     print >> sys.stderr, "    Remaining idx  = ", map(lambda idx : current_fs_idx+idx, range(len(remain_fs)))
00526     # Footstep index to be overwritten
00527     overwrite_fs_idx = current_fs_idx + overwrite_offset_idx
00528     print >> sys.stderr, "    Overwrite index = ",overwrite_fs_idx, ", leg = ", remain_fs[overwrite_offset_idx].leg
00529     # Calc new footsteps
00530     import numpy
00531     support_fs = remain_fs[overwrite_offset_idx-1] # support fs before overwritten fs
00532     if axis == "x":
00533         pos_offset = [0.1, 0, 0]
00534         pos_offset2 = [0.2, 0, 0]
00535     else:
00536         pos_offset = [0, (0.1 if support_fs.leg =='rleg' else -0.1), 0]
00537         pos_offset2 = pos_offset
00538     fpos1=list(numpy.array(support_fs.pos) + numpy.array([0, 2.0*(0.09 if support_fs.leg =='rleg' else -0.09) ,0]) + numpy.array(pos_offset))
00539     fpos2=list(numpy.array(support_fs.pos) + numpy.array(pos_offset))
00540     fpos3=list(numpy.array(support_fs.pos) + numpy.array([0, 2.0*(0.09 if support_fs.leg =='rleg' else -0.09) ,0]) + numpy.array(pos_offset2))
00541     fpos4=list(numpy.array(support_fs.pos) + numpy.array(pos_offset2))
00542     new_fs =[OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep(support_fs.pos, [1,0,0,0], support_fs.leg)]),
00543              OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep(fpos1,          [1,0,0,0], "lleg" if support_fs.leg =='rleg' else "rleg")]),
00544              OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep(fpos2,          [1,0,0,0], support_fs.leg)]),
00545              OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep(fpos3,          [1,0,0,0], "lleg" if support_fs.leg =='rleg' else "rleg")]),
00546              OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep(fpos4,          [1,0,0,0], support_fs.leg)])]
00547     hcf.abc_svc.setFootSteps(new_fs, overwrite_fs_idx);
00548 
00549 def demoGaitGeneratorFixHand():
00550     print >> sys.stderr, "14. Fix arm walking"
00551     hcf.stopAutoBalancer()
00552     hcf.startAutoBalancer()
00553     # Set pose
00554     abcp=hcf.abc_svc.getAutoBalancerParam()[1]
00555     abcp.default_zmp_offsets=[[0.01, 0.0, 0.0], [0.01, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]] # Setting default_zmp_offsets is not necessary for fix mode. Just for debugging for default_zmp_offsets in hand fix mode.
00556     hcf.abc_svc.setAutoBalancerParam(abcp)
00557     dualarm_push_pose=[-3.998549e-05,-0.710564,-0.000264,1.41027,-0.680767,-2.335251e-05,-0.541944,-0.091558,0.122667,-1.02616,-1.71287,-0.056837,1.5708,-3.996804e-05,-0.710511,-0.000264,1.41016,-0.680706,-2.333505e-05,-0.542,0.091393,-0.122578,-1.02608,1.71267,-0.05677,-1.5708,0.006809,0.000101,-0.000163]
00558     hcf.seq_svc.setJointAngles(dualarm_push_pose, 1.0)
00559     hcf.waitInterpolation()
00560     print >> sys.stderr, "  Walk without fixing arm" 
00561     abcp=hcf.abc_svc.getAutoBalancerParam()[1]
00562     abcp.is_hand_fix_mode=False
00563     hcf.abc_svc.setAutoBalancerParam(abcp)
00564     hcf.abc_svc.goPos(0.3,0,0)
00565     hcf.abc_svc.waitFootSteps()
00566     hcf.abc_svc.goPos(0,0.2,0)
00567     hcf.abc_svc.waitFootSteps()
00568     hcf.abc_svc.goPos(0,0,30)
00569     hcf.abc_svc.waitFootSteps()
00570     print >> sys.stderr, "  Walk with fixing arm" 
00571     abcp=hcf.abc_svc.getAutoBalancerParam()[1]
00572     abcp.is_hand_fix_mode=True
00573     hcf.abc_svc.setAutoBalancerParam(abcp)
00574     hcf.abc_svc.goPos(0.3,0,0)
00575     hcf.abc_svc.waitFootSteps()
00576     hcf.abc_svc.goPos(0,-0.2,0)
00577     hcf.abc_svc.waitFootSteps()
00578     hcf.abc_svc.goPos(0,0,-30)
00579     hcf.abc_svc.waitFootSteps()
00580     abcp=hcf.abc_svc.getAutoBalancerParam()[1]
00581     abcp.is_hand_fix_mode=False
00582     abcp.default_zmp_offsets=[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]
00583     hcf.abc_svc.setAutoBalancerParam(abcp)
00584     ref_rpy = checkParameterFromLog("baseRpyOut", rtc_name="abc")
00585     hcf.stopAutoBalancer()
00586     checkActualBaseAttitude(ref_rpy)
00587     print >> sys.stderr, "  Fix hand=>OK"
00588 
00589 def demoGaitGeneratorOverwriteCurrentFootstep():
00590     print >> sys.stderr, "15. Overwrite current footstep"
00591     hcf.seq_svc.setJointAngles(initial_pose, 1.0)
00592     hcf.waitInterpolation()
00593     hcf.startAutoBalancer()
00594     # decrease zmp weight for arms
00595     orig_ggp = hcf.abc_svc.getGaitGeneratorParam()[1]
00596     ggp = hcf.abc_svc.getGaitGeneratorParam()[1]
00597     ggp.overwritable_footstep_index_offset = 0
00598     ggp.default_orbit_type=OpenHRP.AutoBalancerService.RECTANGLE
00599     hcf.abc_svc.setGaitGeneratorParam(ggp)
00600     # start walking
00601     hcf.abc_svc.goVelocity(0,0,0);
00602     hcf.seq_svc.setJointAngles(initial_pose, 2.0);hcf.waitInterpolation() #  wait 2 step using dummy waitInterpolation
00603     hcf.abc_svc.goVelocity(0.1,0,0);
00604     hcf.seq_svc.setJointAngles(initial_pose, 2.0);hcf.waitInterpolation() #  wait 2 step using dummy waitInterpolation
00605     hcf.abc_svc.goVelocity(0,0.1,0);
00606     hcf.seq_svc.setJointAngles(initial_pose, 2.0);hcf.waitInterpolation() #  wait 2 step using dummy waitInterpolation
00607     hcf.abc_svc.goStop()
00608     checkActualBaseAttitude()
00609     print >> sys.stderr, "  Overwrite current footstep=>OK"
00610     # reset params
00611     hcf.abc_svc.setGaitGeneratorParam(orig_ggp)
00612 
00613 def demoGaitGeneratorGoPosOverwrite():
00614     print >> sys.stderr, "16. goPos overwriting"
00615     hcf.startAutoBalancer();
00616     print >> sys.stderr, "  Overwrite goPos by goPos"
00617     # Initialize dst_foot_midcoords
00618     hcf.abc_svc.goPos(0,0.001,0);
00619     hcf.abc_svc.waitFootSteps();
00620     goalx=0.3;goaly=0.1;goalth=15.0
00621     prev_dst_foot_midcoords=hcf.abc_svc.getFootstepParam()[1].dst_foot_midcoords
00622     hcf.abc_svc.goPos(0.2,-0.1,-5) # initial gopos
00623     hcf.seq_svc.setJointAngles(initial_pose, 2.0);hcf.waitInterpolation() #  wait 2 step using dummy waitInterpolation
00624     hcf.abc_svc.goPos(goalx,goaly,goalth) # overwrite gopos
00625     hcf.abc_svc.waitFootSteps()
00626     checkGoPosParam(goalx, goaly, goalth, prev_dst_foot_midcoords)
00627     print >> sys.stderr, "  Overwrite setFootSteps by goPos"
00628     prev_dst_foot_midcoords=hcf.abc_svc.getFootstepParam()[1].dst_foot_midcoords
00629     hcf.setFootSteps([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,-0.09,0], [1,0,0,0], "rleg")]),
00630                       OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.1,0.09,0], [1,0,0,0], "lleg")]),
00631                       OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.2,-0.09,0], [1,0,0,0], "rleg")]),
00632                       OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.3,0.09,0], [1,0,0,0], "lleg")]),
00633                       OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.3,-0.09,0], [1,0,0,0], "rleg")])
00634                       ]) # initial setfootsteps
00635     hcf.seq_svc.setJointAngles(initial_pose, 2.0);hcf.waitInterpolation() #  wait 2 step using dummy waitInterpolation
00636     hcf.abc_svc.goPos(goalx,goaly,goalth) # overwrite gopos
00637     hcf.abc_svc.waitFootSteps()
00638     checkGoPosParam(goalx, goaly, goalth, prev_dst_foot_midcoords)
00639 
00640 def demoGaitGeneratorGrasplessManipMode():
00641     print >> sys.stderr, "17. Graspless manip mode"
00642     hcf.startAutoBalancer();
00643     # Initialize and pose define
00644     dualarm_push_pose=[-3.998549e-05,-0.710564,-0.000264,1.41027,-0.680767,-2.335251e-05,-0.541944,-0.091558,0.122667,-1.02616,-1.71287,-0.056837,1.5708,-3.996804e-05,-0.710511,-0.000264,1.41016,-0.680706,-2.333505e-05,-0.542,0.091393,-0.122578,-1.02608,1.71267,-0.05677,-1.5708,0.006809,0.000101,-0.000163]
00645     hcf.seq_svc.setJointAngles(dualarm_push_pose, 0.5)
00646     hcf.waitInterpolation()
00647     # hands 50[mm] fwd from dualarm_push_pose
00648     av_fwd = [-5.579249e-05,-0.760285,-0.000277,1.44619,-0.660772,-2.615057e-05,-0.7752,-0.080815,0.116555,-0.935667,-1.70514,-0.045373,1.309,-5.577374e-05,-0.760232,-0.000277,1.44608,-0.660715,-2.613350e-05,-0.77525,0.080663,-0.116463,-0.935597,1.70494,-0.045325,-1.309,0.157668,0.000123,-0.000152]
00649     # hands 50[mm] bwd from dualarm_push_pose
00650     av_bwd = [-1.901820e-05,-0.641174,-0.00025,1.36927,-0.717047,-2.260319e-05,-0.305537,-0.099557,0.134675,-1.04208,-1.72497,-0.065256,1.309,-1.900236e-05,-0.641122,-0.00025,1.36915,-0.71698,-2.258509e-05,-0.305624,0.099383,-0.134605,-1.04197,1.72476,-0.06517,-1.309,-0.22394,5.625198e-05,-0.000165]
00651     # hands 50[mm] right from dualarm_push_pose
00652     av_right = [-0.005678,-0.711398,0.006148,1.40852,-0.678974,0.011103,-0.575284,-0.179786,0.092155,-0.999366,-1.74805,0.048205,1.309,-0.005686,-0.710309,0.006143,1.4098,-0.681345,0.011103,-0.520691,0.002033,-0.154878,-1.05585,1.6731,-0.161177,-1.309,0.015053,0.024788,-0.023196]
00653     # hands 50[mm] left from dualarm_push_pose
00654     av_left = [0.005607,-0.71036,-0.006671,1.40991,-0.681404,-0.011151,-0.52064,-0.002193,0.154967,-1.05593,-1.67329,-0.161246,1.309,0.005598,-0.711343,-0.006677,1.4084,-0.67891,-0.011151,-0.575342,0.179622,-0.092066,-0.999287,1.74785,0.04827,-1.309,0.015056,-0.024583,0.02287]
00655     # hands 10[deg] right turn from dualarm_push_pose
00656     av_rturn = [0.023512,-0.71245,0.014216,1.40899,-0.677868,-0.01575,-0.462682,0.040789,0.154221,-1.10667,-1.66067,-0.2349,1.309,0.023442,-0.708029,0.014161,1.40823,-0.68153,-0.015763,-0.61987,0.217174,-0.105089,-0.949927,1.75163,0.120793,-1.309,0.013747,-0.058774,-0.084435]
00657     # hands 10[deg] left turn from dualarm_push_pose
00658     av_lturn = [-0.023522,-0.708079,-0.014689,1.40835,-0.681597,0.015717,-0.619803,-0.217337,0.105179,-0.950004,-1.75184,0.120733,1.309,-0.02359,-0.712393,-0.014744,1.40889,-0.677813,0.0157,-0.462722,-0.040951,-0.154135,-1.10659,1.66048,-0.234826,-1.309,0.013715,0.058979,0.084109]
00659     # parameter setting
00660     org_abcp=hcf.abc_svc.getAutoBalancerParam()[1]
00661     abcp=hcf.abc_svc.getAutoBalancerParam()[1]
00662     abcp.graspless_manip_mode=True
00663     abcp.is_hand_fix_mode=True
00664     abcp.graspless_manip_reference_trans_rot=[1.0, 0.0, 0.0, 1.365307e-06] # trans rot for dualarm_push_pose
00665     abcp.graspless_manip_reference_trans_pos=[0.450037, 1.049436e-06, 0.869818] # trans pos for dualarm_push_pose
00666     abcp.graspless_manip_p_gain=[1,1,1]
00667     hcf.abc_svc.setAutoBalancerParam(abcp)
00668     hcf.co_svc.disableCollisionDetection()
00669     # Check one foot_midcoords movement
00670     gv_pose_list = [av_fwd, av_bwd, av_left, av_right, av_lturn, av_rturn]
00671     ref_footmid_diff = [[50*1e-3,0,0],
00672                         [-50*1e-3,0,0],
00673                         [0, 50*1e-3,0],
00674                         [0,-50*1e-3,0],
00675                         [0,0, 10],
00676                         [0,0,-10]]
00677     ret=True
00678     hcf.abc_svc.waitFootSteps()
00679     for idx in range(len(gv_pose_list)):
00680         pose = gv_pose_list[idx]
00681         prev_dst_foot_midcoords=hcf.abc_svc.getFootstepParam()[1].dst_foot_midcoords
00682         yvel = -0.0001 if (idx%2==0) else 0.0001 # Iff even number test, start with rleg. Otherwise, lleg.
00683         hcf.abc_svc.goVelocity(0,yvel,0);
00684         hcf.seq_svc.setJointAngles(pose, 0.4)
00685         hcf.waitInterpolation()
00686         hcf.seq_svc.setJointAngles(pose, 1.6);hcf.waitInterpolation() # Dummy 2step
00687         hcf.abc_svc.goStop()
00688         diff=numpy.array(ref_footmid_diff[idx])-numpy.array(calcDiffFootMidCoords(prev_dst_foot_midcoords))
00689         if idx == 4 or idx == 5:
00690             tmpret = abs(diff[2]) < 1.0 # TODO, check pos
00691         else:
00692             tmpret = abs(diff[0]) < 1e-3 and abs(diff[1]) < 1e-3 and abs(diff[2]) < 1.0
00693         ret = ret and tmpret
00694         print >> sys.stderr, "  ret = ", tmpret, ", diff = ", diff
00695     # Finishing
00696     if ret:
00697         print >> sys.stderr, "  total is OK"
00698     assert(ret)
00699     hcf.co_svc.enableCollisionDetection()
00700     hcf.seq_svc.setJointAngles(dualarm_push_pose, 0.5)
00701     hcf.waitInterpolation()
00702     hcf.abc_svc.setAutoBalancerParam(org_abcp)
00703 
00704 def demoGaitGeneratorSetFootStepsWithArms():
00705     print >> sys.stderr, "18. Trot Walking"
00706     hcf.stopAutoBalancer()
00707     hcf.seq_svc.setJointAngles(four_legs_mode_pose, 1.0)
00708     hcf.waitInterpolation()
00709     # use arms
00710     orig_abcp = hcf.abc_svc.getAutoBalancerParam()[1]
00711     abcp = hcf.abc_svc.getAutoBalancerParam()[1]
00712     abcp.leg_names = ['rleg', 'lleg', 'rarm', 'larm']
00713     hcf.abc_svc.setAutoBalancerParam(abcp)
00714     # decrease zmp weight for arms
00715     orig_ggp = hcf.abc_svc.getGaitGeneratorParam()[1]
00716     ggp = hcf.abc_svc.getGaitGeneratorParam()[1]
00717     ggp.zmp_weight_map = [1.0, 1.0, 0.01, 0.01]
00718     ggp.default_step_height = 0.01
00719     hcf.abc_svc.setGaitGeneratorParam(ggp)
00720     # start walking
00721     hcf.startAutoBalancer()
00722     hcf.setFootSteps([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,-0.09,0], [1,0,0,0], "rleg"),
00723                                                              OpenHRP.AutoBalancerService.Footstep([0.23,0.21,0.86], [1,0,0,0], "larm")]),
00724                       OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,0.09,0], [1,0,0,0], "lleg"),
00725                                                              OpenHRP.AutoBalancerService.Footstep([0.23,-0.21,0.86], [1,0,0,0], "rarm")])])
00726     hcf.abc_svc.waitFootSteps()
00727     checkActualBaseAttitude()
00728     print >> sys.stderr, "  setFootSteps()=>OK"
00729     # reset params
00730     hcf.stopAutoBalancer()
00731     hcf.abc_svc.setAutoBalancerParam(orig_abcp)
00732     hcf.abc_svc.setGaitGeneratorParam(orig_ggp)
00733     hcf.startAutoBalancer()
00734 
00735 def demoGaitGeneratorChangeStrideLimitationType():
00736     print >> sys.stderr, "19. Change stride limitation type to CIRCLE"
00737     hcf.startAutoBalancer();
00738     # initialize dst_foot_midcoords
00739     hcf.abc_svc.goPos(0,0,0)
00740     hcf.abc_svc.waitFootSteps()
00741     # set params
00742     orig_ggp = hcf.abc_svc.getGaitGeneratorParam()[1]
00743     ggp = hcf.abc_svc.getGaitGeneratorParam()[1]
00744     ggp.stride_limitation_type = OpenHRP.AutoBalancerService.CIRCLE
00745     ggp.stride_limitation_for_circle_type = [0.15, 0.25, 10, 0.1, 0.1]
00746     ggp.leg_margin = [182.0*1e-3, 72.0*1e-3, 71.12*1e-3, 71.12*1e-3]
00747     hcf.abc_svc.setGaitGeneratorParam(ggp)
00748     # gopos check 1
00749     goalx=0.3;goaly=0.3;goalth=20.0
00750     prev_dst_foot_midcoords=hcf.abc_svc.getFootstepParam()[1].dst_foot_midcoords
00751     hcf.abc_svc.goPos(goalx, goaly, goalth)
00752     hcf.abc_svc.waitFootSteps()
00753     checkGoPosParam(goalx, goaly, goalth, prev_dst_foot_midcoords)
00754     # gopos check 2
00755     goalx=-0.3;goaly=-0.3;goalth=-10.0
00756     prev_dst_foot_midcoords=hcf.abc_svc.getFootstepParam()[1].dst_foot_midcoords
00757     hcf.abc_svc.goPos(goalx, goaly, goalth)
00758     hcf.abc_svc.waitFootSteps()
00759     checkGoPosParam(goalx, goaly, goalth, prev_dst_foot_midcoords)
00760     checkActualBaseAttitude()
00761     print >> sys.stderr, "  Change stride limitation type to CIRCLE=>OK"
00762     # reset params
00763     hcf.abc_svc.setGaitGeneratorParam(orig_ggp)
00764 
00765 def demoStandingPosResetting():
00766     print >> sys.stderr, "demoStandingPosResetting"
00767     hcf.abc_svc.goPos(0,0,math.degrees(-1*checkParameterFromLog("WAIST")[5])); # Rot yaw
00768     hcf.abc_svc.waitFootSteps()
00769     hcf.abc_svc.goPos(0,-1*checkParameterFromLog("WAIST")[1],0); # Pos Y
00770     hcf.abc_svc.waitFootSteps()
00771 
00772 def demo():
00773     start_time = time.time()
00774     init()
00775     from distutils.version import StrictVersion
00776     if StrictVersion(hrpsys_version) >= StrictVersion('315.5.0'):
00777         # sample for AutoBalancer mode
00778         demoAutoBalancerFixFeet()
00779         demoAutoBalancerFixFeetHands()
00780         demoAutoBalancerGetParam()
00781         demoAutoBalancerSetParam()
00782         demoAutoBalancerTestPoses()
00783         demoAutoBalancerStartStopCheck()
00784         demoAutoBalancerBalanceAgainstHandForce()
00785         demoAutoBalancerBalanceWithArms()
00786         # sample for walk pattern generation by AutoBalancer RTC
00787         demoGaitGeneratorBaseTformCheck()
00788         demoGaitGeneratorGoPos()
00789         demoGaitGeneratorGoVelocity()
00790         demoGaitGeneratorSetFootSteps()
00791         demoGaitGeneratorChangePoseWhileWalking()
00792         demoGaitGeneratorGetParam()
00793         demoGaitGeneratorSetParam()
00794         demoGaitGeneratorNonDefaultStrideStop()
00795         demoGaitGeneratorToeHeelContact()
00796         demoGaitGeneratorStopStartSyncCheck()
00797         demoGaitGeneratorEmergencyStop()
00798         demoGaitGeneratorGetRemainingSteps()
00799         demoGaitGeneratorChangeStepParam()
00800         demoGaitGeneratorOverwriteFootsteps()
00801         demoGaitGeneratorOverwriteFootsteps(2)
00802         #demoStandingPosResetting()
00803         demoGaitGeneratorFixHand()
00804         demoGaitGeneratorOverwriteCurrentFootstep()
00805         demoGaitGeneratorGoPosOverwrite()
00806         demoGaitGeneratorGrasplessManipMode()
00807         demoGaitGeneratorSetFootStepsWithArms()
00808         demoGaitGeneratorChangeStrideLimitationType()
00809     print >> sys.stderr, "All samplerobot_auto_balancer.py demo time ", (time.time()-start_time), "[s]"
00810 
00811 if __name__ == '__main__':
00812     demo()
00813 


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Wed May 15 2019 05:02:18