sample4legrobot_auto_balancer.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 
18 def init ():
19  global hcf, initial_pose, hrpsys_version
20  hcf = HrpsysConfigurator()
21  hcf.getRTCList = hcf.getRTCListUnstable
22  hcf.init ("Sample4LegRobot(Robot)0", "$(PROJECT_DIR)/../model/sample_4leg_robot.wrl")
23  initial_pose = [-0.000135, -0.523291, -0.000225, 1.15585, -0.631694, 0.000267,
24  -0.000135, -0.523291, -0.000225, 1.15585, -0.631694, 0.000267,
25  -0.000113, -0.523291, -0.000225, 1.15585, -0.631693, 0.000245,
26  -0.000113, -0.523291, -0.000225, 1.15585, -0.631693, 0.000245]
27  # initial_pose = [0, -0.378613, 0, 0.832038, -0.452564, 0,
28  # 0, -0.378613, 0, 0.832038, -0.452564, 0,
29  # 0, -0.378613, 0, 0.832038, -0.452564, 0,
30  # 0, -0.378613, 0, 0.832038, -0.452564, 0,]
31  hcf.seq_svc.setJointAngles(initial_pose, 2.0)
32  hcf.waitInterpolation()
33  # set abc param
34  abcp=hcf.abc_svc.getAutoBalancerParam()[1]
35  abcp.leg_names = ['rleg', 'lleg', 'rarm', 'larm']
36  hcf.abc_svc.setAutoBalancerParam(abcp)
37  # set gg param
38  ggp = hcf.abc_svc.getGaitGeneratorParam()[1]
39  ggp.leg_default_translate_pos = [[0.0, -0.19, 0.0], [0.0, 0.19, 0.0], [0.7, -0.19, 0.0], [0.7, 0.19, 0.0]]
40  ggp.zmp_weight_map = [1.0]*4
41  ggp.default_step_height = 0.065 # see https://github.com/fkanehiro/hrpsys-base/issues/801
42  hcf.abc_svc.setGaitGeneratorParam(ggp)
43  hcf.startAutoBalancer(limbs=['rleg','lleg','rarm','larm'])
44  hrpsys_version = hcf.seq.ref.get_component_profile().version
45  print("hrpsys_version = %s"%hrpsys_version)
46 
47 def demoGaitGeneratorSetFootSteps(print_str="1. setFootSteps"):
48  print >> sys.stderr, print_str
49  hcf.setFootSteps([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.0+0.00,-0.19,0], [1,0,0,0], "rleg"),
50  OpenHRP.AutoBalancerService.Footstep([0.7+0.00,+0.19,0], [1,0,0,0], "larm")]),
51  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.0+0.15,+0.19,0], [1,0,0,0], "lleg"),
52  OpenHRP.AutoBalancerService.Footstep([0.7+0.15,-0.19,0], [1,0,0,0], "rarm")]),
53  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.0+0.30,-0.19,0], [1,0,0,0], "rleg"),
54  OpenHRP.AutoBalancerService.Footstep([0.7+0.30,+0.19,0], [1,0,0,0], "larm")]),
55  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.0+0.45,+0.19,0], [1,0,0,0], "lleg"),
56  OpenHRP.AutoBalancerService.Footstep([0.7+0.45,-0.19,0], [1,0,0,0], "rarm")]),
57  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.0+0.45,-0.19,0], [1,0,0,0], "rleg"),
58  OpenHRP.AutoBalancerService.Footstep([0.7+0.45,+0.19,0], [1,0,0,0], "larm")])])
59  hcf.abc_svc.waitFootSteps()
60 
62  ggp=hcf.abc_svc.getGaitGeneratorParam()[1];
63  ggp.swing_trajectory_delay_time_offset=0.05;
64  ggp.default_orbit_type=OpenHRP.AutoBalancerService.RECTANGLE;
65  hcf.abc_svc.setGaitGeneratorParam(ggp)
66  demoGaitGeneratorSetFootSteps("2. setFootSteps with Rectangle orbit");
67 
69  ggp=hcf.abc_svc.getGaitGeneratorParam()[1];
70  ggp.swing_trajectory_delay_time_offset=0.05;
71  ggp.swing_trajectory_final_distance_weight=3.0;
72  ggp.default_orbit_type=OpenHRP.AutoBalancerService.CYCLOIDDELAY;
73  hcf.abc_svc.setGaitGeneratorParam(ggp)
74  demoGaitGeneratorSetFootSteps("3. setFootSteps with Cycloiddelay orbit");
75 
76 def demoGaitGeneratorSetFootStepsCrawl(print_str="4. setFootSteps in Crawl"):
77  print >> sys.stderr, print_str
78  hcf.setFootSteps([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.0+0.00,-0.19,0], [1,0,0,0], "rleg")]),
79  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.7+0.01,+0.19,0], [1,0,0,0], "larm")]),
80  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.0+0.01,+0.19,0], [1,0,0,0], "lleg")]),
81  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.7+0.01,-0.19,0], [1,0,0,0], "rarm")]),
82  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0.0+0.01,-0.19,0], [1,0,0,0], "rleg")])])
83  hcf.abc_svc.waitFootSteps()
84 
85 def demoGoPosQuadruped(gait_type=OpenHRP.AutoBalancerService.TROT, print_str="5. go pos in trot"):
86  print >> sys.stderr, print_str
87  # set gait type
88  abcp=hcf.abc_svc.getAutoBalancerParam()[1]
89  abcp.default_gait_type = gait_type
90  hcf.abc_svc.setAutoBalancerParam(abcp)
91  # set default translate pos
92  ggp = hcf.abc_svc.getGaitGeneratorParam()[1]
93  ggp.leg_default_translate_pos = [[0.0, -0.19, 0.0], [0.0, 0.19, 0.0], [0.7, -0.19, 0.0], [0.7, 0.19, 0.0]]
94  hcf.abc_svc.setGaitGeneratorParam(ggp)
95  # go pos
96  hcf.abc_svc.goPos(-0.5, +0.2, 20)
97  hcf.abc_svc.waitFootSteps()
98 
99 def demoGoVelocityQuadruped(gait_type=OpenHRP.AutoBalancerService.TROT, print_str="7. go velocity in trot"):
100  print >> sys.stderr, print_str
101  # set gait type
102  abcp=hcf.abc_svc.getAutoBalancerParam()[1]
103  abcp.default_gait_type = gait_type
104  hcf.abc_svc.setAutoBalancerParam(abcp)
105  # set default translate pos
106  ggp = hcf.abc_svc.getGaitGeneratorParam()[1]
107  ggp.leg_default_translate_pos = [[0.0, -0.19, 0.0], [0.0, 0.19, 0.0], [0.7, -0.19, 0.0], [0.7, 0.19, 0.0]]
108  hcf.abc_svc.setGaitGeneratorParam(ggp)
109  # go pos
110  hcf.abc_svc.goVelocity(-0.1, -0.05, -20)
111  time.sleep(3)
112  hcf.abc_svc.goStop()
113 
114 def demo():
115  init()
120  demoGoPosQuadruped(gait_type=OpenHRP.AutoBalancerService.TROT, print_str="5. go pos in trot")
121  demoGoPosQuadruped(gait_type=OpenHRP.AutoBalancerService.PACE, print_str="6. go pos in pace")
122  demoGoVelocityQuadruped(gait_type=OpenHRP.AutoBalancerService.TROT, print_str="7. go velocity in trot")
123 
124 if __name__ == '__main__':
125  demo()
def demoGoPosQuadruped(gait_type=OpenHRP.AutoBalancerService.TROT, print_str="5. go pos in trot")
def demoGaitGeneratorSetFootSteps(print_str="1. setFootSteps")
def demoGaitGeneratorSetFootStepsCrawl(print_str="4. setFootSteps in Crawl")
def demoGoVelocityQuadruped(gait_type=OpenHRP.AutoBalancerService.TROT, print_str="7. go velocity in trot")


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