samplerobot_impedance_controller.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 init ():
17  global hcf, hrpsys_version
18  hcf = HrpsysConfigurator()
19  hcf.getRTCList = hcf.getRTCListUnstable
20  hcf.init ("SampleRobot(Robot)0", "$(PROJECT_DIR)/../model/sample1.wrl")
21  hrpsys_version = hcf.seq.ref.get_component_profile().version
22  print("hrpsys_version = %s"%hrpsys_version)
23  # set initial pose from sample/controller/SampleController/etc/Sample.pos
24  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]
25  hcf.seq_svc.setJointAngles(initial_pose, 2.0)
26  hcf.seq_svc.waitInterpolation()
27 
29  # 0. startImpedance + stopImpedance python interface
30  print >> sys.stderr, "0. startImpedance + stopImpedance python interface"
31  hcf.startImpedance("rarm")
32  hcf.startImpedance("larm")
33  hcf.stopImpedance("larm")
34  hcf.stopImpedance("rarm")
35 
37  # 1. Getter check
38  print >> sys.stderr, "1. Getter check"
39  all_get_ret = []
40  for limb in ["rarm", "larm"]:
41  all_get_ret.append(hcf.ic_svc.getImpedanceControllerParam(limb)[0])
42  print >> sys.stderr, " all_get_ret = ", all_get_ret
43  assert(all(all_get_ret))
44  print >> sys.stderr, " getImpedanceControllerParam => OK"
45 
47  # 2. Setter check
48  print >> sys.stderr, "2. Setter check"
49  all_set_ret = []
50  all_value_ret = []
51  for limb in ["rarm", "larm"]:
52  [ret1, icp1]=hcf.ic_svc.getImpedanceControllerParam(limb)
53  icp1.K_r=1.0
54  icp1.D_r=2.0
55  icp1.M_r=0.2
56  all_set_ret.append(hcf.ic_svc.setImpedanceControllerParam(limb, icp1))
57  [ret2, icp2]=hcf.ic_svc.getImpedanceControllerParam(limb)
58  all_value_ret.append((icp1.M_r == icp2.M_r) and (icp1.D_r == icp2.D_r) and (icp1.K_r == icp2.K_r))
59  print >> sys.stderr, " all_set_ret = ", all_set_ret, ", all_value_ret = ", all_value_ret
60  assert(all(all_set_ret) and all(all_value_ret))
61  print >> sys.stderr, " setImpedanceControllerParam => OK"
62 
64  # 3. Start impedance
65  print >> sys.stderr, "3. Start impedance"
66  all_start_ret = []
67  all_mode_ret = []
68  # start
69  for limb in ["rarm", "larm"]:
70  [ret, icp]=hcf.ic_svc.getImpedanceControllerParam(limb)
71  all_start_ret.append(hcf.ic_svc.startImpedanceControllerNoWait(limb))
72  all_mode_ret.append(icp.controller_mode == OpenHRP.ImpedanceControllerService.MODE_IDLE)
73  # wait and check
74  for limb in ["rarm", "larm"]:
75  hcf.ic_svc.waitImpedanceControllerTransition(limb)
76  [ret, icp]=hcf.ic_svc.getImpedanceControllerParam(limb)
77  all_mode_ret.append(icp.controller_mode == OpenHRP.ImpedanceControllerService.MODE_IMP)
78  # "already start" check
79  for limb in ["rarm", "larm"]:
80  all_start_ret.append(not hcf.ic_svc.startImpedanceControllerNoWait(limb))
81  print >> sys.stderr, " all_start_ret = ", all_start_ret, ", all_mode_ret = ", all_mode_ret
82  assert(all(all_start_ret) and all(all_mode_ret))
83  print >> sys.stderr, " startImpedanceController => OK"
84 
86  # 4. Set ref force and moment
87  print >> sys.stderr, "4. Set ref force and moment"
88  hcf.seq_svc.setWrenches([0,0,0,0,0,0,
89  0,0,0,0,0,0,
90  0,0,0,0,0,0,
91  20,10,-10,0,0,0,], 1.0);
92  hcf.seq_svc.waitInterpolation();
93  time.sleep(2)
94  hcf.seq_svc.setWrenches([0,0,0,0,0,0,
95  0,0,0,0,0,0,
96  0,0,0,0,0,0,
97  0,0,0,0,0,0,], 1.0);
98  hcf.seq_svc.waitInterpolation();
99  time.sleep(2)
100  hcf.seq_svc.setWrenches([0,0,0,0,0,0,
101  0,0,0,0,0,0,
102  0,0,0,0,0,0,
103  0,0,0,0.1,-0.1,0.1], 1.0);
104  hcf.seq_svc.waitInterpolation();
105  time.sleep(2)
106  hcf.seq_svc.setWrenches([0,0,0,0,0,0,
107  0,0,0,0,0,0,
108  0,0,0,0,0,0,
109  0,0,0,0,0,0], 1.0);
110  hcf.seq_svc.waitInterpolation();
111  time.sleep(2)
112 
114  # 5. Stop impedance
115  print >> sys.stderr, "5. Stop impedance"
116  all_stop_ret = []
117  all_mode_ret = []
118  # stop
119  for limb in ["rarm", "larm"]:
120  all_stop_ret.append(hcf.ic_svc.stopImpedanceControllerNoWait(limb))
121  # wait and check
122  for limb in ["rarm", "larm"]:
123  hcf.ic_svc.waitImpedanceControllerTransition(limb)
124  [ret, icp]=hcf.ic_svc.getImpedanceControllerParam(limb)
125  all_mode_ret.append(icp.controller_mode == OpenHRP.ImpedanceControllerService.MODE_IDLE)
126  # "already stop" check
127  for limb in ["rarm", "larm"]:
128  all_stop_ret.append(not hcf.ic_svc.stopImpedanceControllerNoWait(limb))
129  print >> sys.stderr, " all_stop_ret = ", all_stop_ret, ", all_mode_ret = ", all_mode_ret
130  assert(all(all_stop_ret) and all(all_mode_ret))
131  print >> sys.stderr, " stopImpedanceController => OK"
132 
134  # 6. Arm tracking check
135  print >> sys.stderr, "6. Arm tracking check"
136  hcf.ic_svc.startImpedanceController("rarm")
137  hcf.setJointAngle("RARM_ELBOW", -40.0, 0.5);
138  hcf.waitInterpolation()
139  hcf.setJointAngle("RARM_ELBOW", -70.0, 0.5);
140  hcf.waitInterpolation()
141 
143  # 7. World frame check
144  if hcf.kinematics_only_mode:
145  print >> sys.stderr, "7. World frame check"
146  # tempolarily set use_sh_base_pos_rpy
147  icp=hcf.ic_svc.getImpedanceControllerParam("rarm")[1]
148  icp.use_sh_base_pos_rpy = True
149  hcf.ic_svc.setImpedanceControllerParam("rarm", icp)
150  # test
151  hcf.seq_svc.setJointAngles(initial_pose, 2.0)
152  hcf.seq_svc.waitInterpolation()
153  hcf.setJointAngle("RLEG_ANKLE_P",40, 1);
154  hcf.waitInterpolation()
155  hcf.setJointAngle("RLEG_ANKLE_P",-40, 1);
156  hcf.waitInterpolation()
157  hcf.seq_svc.setJointAngles(initial_pose, 2.0)
158  hcf.seq_svc.waitInterpolation()
159  else:
160  print >> sys.stderr, "7. World frame check is not executed in non-kinematics-only-mode"
161 
163  # 8. World frame ref-force check
164  if hcf.kinematics_only_mode:
165  print >> sys.stderr, "8. World frame ref-force check"
166  # tempolarily set use_sh_base_pos_rpy
167  icp=hcf.ic_svc.getImpedanceControllerParam("rarm")[1]
168  icp.use_sh_base_pos_rpy = True
169  hcf.ic_svc.setImpedanceControllerParam("rarm", icp)
170  # test
171  hcf.seq_svc.setBaseRpy([0,0,0], 1.0);
172  hcf.seq_svc.waitInterpolation();
173  hcf.seq_svc.setWrenches([0,0,0,0,0,0,
174  0,0,0,0,0,0,
175  0,0,0,0,0,0,
176  -40,0,0,0,0,0], 1.0);
177  hcf.seq_svc.waitInterpolation();
178  hcf.seq_svc.setWrenches([0,0,0,0,0,0,
179  0,0,0,0,0,0,
180  0,0,0,0,0,0,
181  0,0,0,0,0,0], 1.0);
182  hcf.seq_svc.waitInterpolation();
183  hcf.seq_svc.setBaseRpy([0,45*3.14159/180,0], 1.0);
184  hcf.seq_svc.waitInterpolation();
185  hcf.seq_svc.setWrenches([0,0,0,0,0,0,
186  0,0,0,0,0,0,
187  0,0,0,0,0,0,
188  -40,0,0,0,0,0], 1.0);
189  hcf.seq_svc.waitInterpolation();
190  hcf.seq_svc.setWrenches([0,0,0,0,0,0,
191  0,0,0,0,0,0,
192  0,0,0,0,0,0,
193  0,0,0,0,0,0], 1.0);
194  hcf.seq_svc.waitInterpolation();
195  hcf.seq_svc.setBaseRpy([0,0,0], 1.0);
196  hcf.seq_svc.waitInterpolation();
197  else:
198  print >> sys.stderr, "8. World frame ref-force check is not executed in non-kinematics-only-mode"
199 
201  # 1. Object Contact Turnaround Detector set param check
202  print >> sys.stderr, "1. Object Contact Turnaround Detector set param check"
203  ret9 = True
204  detect_time_thre = 0.3
205  start_time_thre=0.3
206  for number_disturbance in [0, 1e-5, -1e-5]: # 1e-5 is smaller than dt
207  octdp=hcf.octd_svc.getObjectContactTurnaroundDetectorParam()[1];
208  octdp.detect_time_thre = detect_time_thre + number_disturbance
209  octdp.start_time_thre = start_time_thre + number_disturbance
210  hcf.octd_svc.setObjectContactTurnaroundDetectorParam(octdp);
211  octdp2=hcf.octd_svc.getObjectContactTurnaroundDetectorParam()[1];
212  print >> sys.stderr, " ", octdp2
213  ret9 = ret9 and (octdp2.detect_time_thre == detect_time_thre and octdp2.start_time_thre == start_time_thre)
214  assert(ret9)
215  print >> sys.stderr, " => OK"
216 
217 
218 def demo():
219  init()
220 
221  demoStartStopIMP ()
222  from distutils.version import StrictVersion
223  if StrictVersion(hrpsys_version) < StrictVersion('315.5.0'):
224  return
225 
234  demoOCTDCheck()
235 
236 if __name__ == '__main__':
237  demo()


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