samplerobot_collision_detector.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 def vector_equal_eps (vec1, vec2, eps=1e-5):
17  if len(vec1) == len(vec2):
18  for e1, e2 in zip(vec1, vec2):
19  if abs(e1 - e2) > eps:
20  return False
21  return True
22  else:
23  return False
24 
25 def init ():
26  global hcf, init_pose, col_safe_pose, col_fail_pose, hrpsys_version
27  hcf = HrpsysConfigurator()
28  hcf.getRTCList = hcf.getRTCListUnstable
29  hcf.init ("SampleRobot(Robot)0", "$(PROJECT_DIR)/../model/sample1.wrl")
30  init_pose = [0]*29
31  col_safe_pose = [0.0,-0.349066,0.0,0.820305,-0.471239,0.0,0.523599,0.0,0.0,-1.74533,0.15708,-0.113446,0.0,0.0,-0.349066,0.0,0.820305,-0.471239,0.0,0.523599,0.0,0.0,-1.74533,-0.15708,-0.113446,0.0,0.0,0.0,0.0]
32  col_fail_pose = [0.0,-0.349066,0.0,0.820305,-0.471239,0.0,0.845363,0.03992,0.250074,-1.32816,0.167513,0.016204,0.0,0.0,-0.349066,0.0,0.820305,-0.471239,0.0,0.523599,0.0,0.0,-1.74533,-0.15708,-0.113446,0.0,0.0,0.0,0.0]
33  hrpsys_version = hcf.co.ref.get_component_profile().version
34  print >> sys.stderr, "hrpsys_version = %s"%hrpsys_version
35 
36 # demo functions
38  print >> sys.stderr, "1. CollisionCheck in safe pose"
39  hcf.seq_svc.setJointAngles(col_safe_pose, 3.0);
40  hcf.waitInterpolation();
41  counter = 0
42  while (counter < 20) and (not vector_equal_eps([x / 180 * math.pi for x in hcf.getJointAngles()], col_safe_pose)):
43  time.sleep(0.2)
44  counter = counter + 1
45  assert(counter != 20)
46  cs=hcf.co_svc.getCollisionStatus()[1]
47  if cs.safe_posture:
48  print >> sys.stderr, " => Safe pose"
49  assert(cs.safe_posture is True)
50 
52  print >> sys.stderr, "2. CollisionCheck in fail pose"
53  hcf.seq_svc.setJointAngles(col_fail_pose, 3.0);
54  hcf.waitInterpolation();
55  cs=hcf.co_svc.getCollisionStatus()[1]
56  if not cs.safe_posture:
57  print >> sys.stderr, " => Successfully stop fail pose"
58  assert((not cs.safe_posture) is True)
59  hcf.seq_svc.setJointAngles(col_safe_pose, 3.0);
60  hcf.waitInterpolation();
61  cs=hcf.co_svc.getCollisionStatus()[1]
62  if cs.safe_posture:
63  print >> sys.stderr, " => Successfully return to safe pose"
64  assert(cs.safe_posture is True)
65 
67  print >> sys.stderr, "3. CollisionCheck in fail pose with 0.1[m] tolerance"
68  hcf.co_svc.setTolerance("all", 0.1); # [m]
69  hcf.seq_svc.setJointAngles(col_fail_pose, 1.0);
70  hcf.waitInterpolation();
71  cs=hcf.co_svc.getCollisionStatus()[1]
72  if not cs.safe_posture:
73  print >> sys.stderr, " => Successfully stop fail pose (0.1[m] tolerance)"
74  assert((not cs.safe_posture) is True)
75  hcf.co_svc.setTolerance("all", 0.0); # [m]
76  hcf.seq_svc.setJointAngles(col_safe_pose, 3.0);
77  hcf.waitInterpolation();
78  cs=hcf.co_svc.getCollisionStatus()[1]
79  if cs.safe_posture:
80  print >> sys.stderr, " => Successfully return to safe pose"
81  assert(cs.safe_posture is True)
82 
84  print >> sys.stderr, "4. CollisionDetection enable and disable"
85  hcf.seq_svc.setJointAngles(col_safe_pose, 1.0);
86  hcf.waitInterpolation();
87  if hcf.co_svc.disableCollisionDetection():
88  print >> sys.stderr, " => Successfully disabled when no collision"
89  assert(hcf.co_svc.disableCollisionDetection() is True)
90  if hcf.co_svc.enableCollisionDetection():
91  print >> sys.stderr, " => Successfully enabled when no collision"
92  assert(hcf.co_svc.enableCollisionDetection() is True)
93  hcf.seq_svc.setJointAngles(col_fail_pose, 1.0);
94  hcf.waitInterpolation();
95  if not hcf.co_svc.disableCollisionDetection():
96  print >> sys.stderr, " => Successfully inhibit disabling when collision"
97  assert((not hcf.co_svc.disableCollisionDetection()) is True)
98  hcf.seq_svc.setJointAngles(col_safe_pose, 1.0);
99  hcf.waitInterpolation();
100 
102  if hcf.abc_svc != None:
103  print >> sys.stderr, "5. Collision mask test"
104  hcf.co_svc.setTolerance("all", 0); # [m]
105  hcf.startAutoBalancer()
106  print >> sys.stderr, " 5.1 Collision mask among legs : Check RLEG_ANKLE_R - LLEG_ANKLE_R"
107  print >> sys.stderr, " Desired behavior : Robot stops when legs collision."
108  hcf.setFootSteps([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,-0.09,0],[1,0,0,0],"rleg")]),
109  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,0.0,0],[1,0,0,0],"lleg")])])
110  hcf.abc_svc.waitFootSteps();
111  hcf.setFootSteps([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,-0.09,0],[1,0,0,0],"rleg")]),
112  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,0.09,0],[1,0,0,0],"lleg")])])
113  hcf.abc_svc.waitFootSteps();
114  print >> sys.stderr, " => Successfully mask works. Legs joints stops when collision."
115  print >> sys.stderr, " 5.2 Collision mask between leg and arm : Check RLEG_HIP_R and RARM_WRIST*"
116  print >> sys.stderr, " Desired behavior : Leg joints moves and arm joints stops when collision."
117  hcf.seq_svc.setJointAngles(col_safe_pose, 1.0);
118  hcf.waitInterpolation();
119  hcf.abc_svc.goVelocity(0,0,0);
120  hcf.seq_svc.setJointAngles(col_fail_pose, 1.0);
121  hcf.waitInterpolation();
122  hcf.seq_svc.setJointAngles(col_safe_pose, 3.0);
123  hcf.waitInterpolation();
124  hcf.abc_svc.goStop();
125  print >> sys.stderr, " => Successfully mask works. Arm joints stops and leg joints moves."
126  print >> sys.stderr, " 5.3 Collision mask between leg and arm : Check RLEG_HIP_R and RARM_WRIST* and RLEG_ANKLE_R and LLEG_ANKLE_R (combination of 5.1 and 5.2)"
127  print >> sys.stderr, " Desired behavior : First, arm stops and legs moves."
128  hcf.seq_svc.setJointAngles(col_safe_pose, 1.0);
129  hcf.waitInterpolation();
130  print >> sys.stderr, " Desired behavior : Next, arm keeps stopping and legs stops."
131  hcf.setFootSteps([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,-0.09,0],[1,0,0,0],"rleg")]),
132  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,0.0,0],[1,0,0,0],"lleg")])])
133  hcf.abc_svc.waitFootSteps();
134  hcf.setFootSteps([OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,-0.09,0],[1,0,0,0],"rleg")]),
135  OpenHRP.AutoBalancerService.Footsteps([OpenHRP.AutoBalancerService.Footstep([0,0.09,0],[1,0,0,0],"lleg")])])
136  hcf.abc_svc.waitFootSteps();
137  print >> sys.stderr, " => Successfully mask works with combined situation."
138  hcf.stopAutoBalancer()
139 
140 def demo():
141  init()
146  #demoCollisionMask()
147 
149  init()
150  from distutils.version import StrictVersion
151  if StrictVersion(hrpsys_version) >= StrictVersion('315.10.0'):
156 
157 if __name__ == '__main__':
158  demo()


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