7 print "import without hrpsys" 12 from waitInput
import *
19 global hcf, pitch_poses, roll_poses, yaw_poses, roll_pitch_poses, initial_pose, hrpsys_version
20 hcf = HrpsysConfigurator()
21 hcf.getRTCList = hcf.getRTCListUnstable
22 hcf.init (
"SampleRobot(Robot)0",
"$(PROJECT_DIR)/../model/sample1.wrl")
23 hcf.connectLoggerPort(hcf.kf,
'baseRpyCurrent')
38 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]
40 pitch_pose1=[0.000112,-0.553688,-0.00028,1.15739,-0.602847,-1.330313e-05,0.31129,-0.159481,-0.115399,-0.636277,0.0,0.0,0.0,0.000112,-0.553703,-0.00028,1.15739,-0.602833,-1.330597e-05,0.31129,0.159481,0.115399,-0.636277,0.0,0.0,0.0,0.0,0.0,0.0]
41 pitch_pose2=[8.200401e-05,-0.980787,-0.000375,0.598284,-0.140235,-9.749026e-05,0.31129,-0.159481,-0.115399,-0.636277,0.0,0.0,0.0,8.206224e-05,-0.980716,-0.000375,0.598026,-0.140049,-9.749664e-05,0.31129,0.159481,0.115399,-0.636277,0.0,0.0,0.0,0.0,0.0,0.0]
42 pitch_pose3=[0.000229,0.313052,-0.000276,0.779751,-0.568344,-3.437126e-05,0.31129,-0.159481,-0.115399,-0.636277,0.0,0.0,0.0,0.000229,0.313082,-0.000276,0.779709,-0.568332,-3.436731e-05,0.31129,0.159481,0.115399,-0.636277,0.0,0.0,0.0,0.0,0.0,0.0]
43 pitch_poses = [pitch_pose1, pitch_pose2, pitch_pose3]
45 roll_pose1=[0.000112,-0.553688,-0.00028,1.15739,-0.602847,-1.330313e-05,0.31129,-0.159481,-0.115399,-0.636277,0.0,0.0,0.0,0.000112,-0.553703,-0.00028,1.15739,-0.602833,-1.330597e-05,0.31129,0.159481,0.115399,-0.636277,0.0,0.0,0.0,0.0,0.0,0.0]
46 roll_pose2=[-0.475317,-0.568231,0.022036,1.1549,-0.595553,0.138268,0.31129,-0.159481,-0.115399,-0.636277,0.0,0.0,0.0,-0.447984,-0.378428,0.020283,0.753855,-0.383755,0.106576,0.31129,0.159481,0.115399,-0.636277,0.0,0.0,0.0,0.0,0.0,0.0]
47 roll_pose3=[0.44835,-0.377793,-0.020814,0.752451,-0.38309,-0.106633,0.31129,-0.159481,-0.115399,-0.636277,0.0,0.0,0.0,0.475616,-0.567819,-0.022616,1.15389,-0.595074,-0.138377,0.31129,0.159481,0.115399,-0.636277,0.0,0.0,0.0,0.0,0.0,0.0]
48 roll_poses = [roll_pose1, roll_pose2, roll_pose3]
50 yaw_pose1=[-0.000113, -0.523213, -0.000225, 1.15585, -0.631772, 0.000245, 0.31129, -0.159481, -0.115399, -0.636277, 0.0, 0.0, 0.0, -0.000113, -0.523213, -0.000225, 1.15585, -0.631772, 0.000245, 0.31129, 0.159481, 0.115399, -0.636277, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
51 yaw_pose2=[-0.000113, -0.523213, -0.000225, 1.15585, -0.631772, 0.000245, 0.31129, -0.159481, -0.115399, -0.636277, 0.0, 0.0, 0.0, -0.000113, -0.523213, -0.000225, 1.15585, -0.631772, 0.000245, 0.31129, 0.159481, 0.115399, -0.636277, 0.0, 0.0, 0.0, 0.0, 0.0, 0.785398]
52 yaw_pose3=[-0.000113, -0.523213, -0.000225, 1.15585, -0.631772, 0.000245, 0.31129, -0.159481, -0.115399, -0.636277, 0.0, 0.0, 0.0, -0.000113, -0.523213, -0.000225, 1.15585, -0.631772, 0.000245, 0.31129, 0.159481, 0.115399, -0.636277, 0.0, 0.0, 0.0, 0.0, 0.0, 1.5708]
53 yaw_poses = [yaw_pose1, yaw_pose2, yaw_pose3]
55 roll_pitch_pose1=[0.000111,-0.681981,-0.000333,1.41142,-0.728577,-7.604916e-05,0.31129,-0.159481,-0.115399,-0.636277,0.0,0.0,0.0,0.000111,-0.682003,-0.000333,1.41142,-0.728553,-7.605437e-05,0.31129,0.159481,0.115399,-0.636277,0.0,0.0,0.0,0.0,0.0,0.0]
56 roll_pitch_pose2=[-0.486326,-1.18821,-0.026531,0.908889,-0.267927,0.130916,0.31129,-0.159481,-0.115399,-0.636277,0.0,0.0,0.0,-0.430362,-0.964194,0.009303,0.590166,-0.173131,0.103544,0.31129,0.159481,0.115399,-0.636277,0.0,0.0,0.0,0.0,0.0,0.0]
57 roll_pitch_pose3=[0.463158,0.281851,-0.0701,0.747965,-0.514677,-0.108534,0.31129,-0.159481,-0.115399,-0.636277,0.0,0.0,0.0,0.486068,0.189331,-0.083976,1.08676,-0.76299,-0.139173,0.31129,0.159481,0.115399,-0.636277,0.0,0.0,0.0,0.0,0.0,0.0]
58 roll_pitch_poses = [roll_pitch_pose1, roll_pitch_pose2, roll_pitch_pose3]
59 hrpsys_version = hcf.seq.ref.get_component_profile().version
60 print(
"hrpsys_version = %s"%hrpsys_version)
66 hcf.log_svc.save(
"/tmp/test-kf-samplerobot-{0}".format(optional_out_file_name))
69 estimated_base_rpy_ret=[]
70 for line
in open(
"/tmp/test-kf-samplerobot-{0}.kf_baseRpyCurrent".format(optional_out_file_name),
"r"): 71 estimated_base_rpy_ret.append(line.split(" ")[0:-1])
74 for line
in open(
"/tmp/test-kf-samplerobot-{0}.SampleRobot(Robot)0_WAIST".format(optional_out_file_name),
"r"): 75 act_rpy_ret.append(line.split(" ")[0:-1])
77 initial_sec=int(act_rpy_ret[0][0].split(
".")[0])
78 tm_list=map (
lambda x : int(x[0].split(
".")[0])-initial_sec + float(x[0].split(
".")[1]) * 1e-6, act_rpy_ret)
81 import matplotlib.pyplot
as plt
83 color_list = [
'r', 'g', 'b']
85 plt.plot(tm_list,
map(
lambda x : 180.0 * float(x[1+3+idx]) / math.pi, act_rpy_ret), color=color_list[idx])
86 plt.plot(tm_list,
map(
lambda x : 180.0 * float(x[1+idx]) / math.pi, estimated_base_rpy_ret),
"--", color=color_list[idx])
87 plt.xlabel(
"Time [s]")
88 plt.ylabel(
"Angle [deg]")
89 plt.title(
"KF actual-estimated data (motion time = {0})".format(optional_out_file_name))
90 plt.legend((
"Actual roll",
"Estimated base roll",
91 "Actual pitch",
"Estimated base pitch",
92 "Actual yaw",
"Estimated base yaw"))
93 plt.savefig(
"/tmp/test-kf-samplerobot-data-{0}.eps".format(optional_out_file_name))
95 print >> sys.stderr,
"No plot" 98 hcf.seq_svc.setJointAngles(poses[1], time*0.25)
99 hcf.seq_svc.waitInterpolation()
100 hcf.seq_svc.setJointAngles(poses[2], time*0.5)
101 hcf.seq_svc.waitInterpolation()
102 hcf.seq_svc.setJointAngles(poses[0], time*0.25)
103 hcf.seq_svc.waitInterpolation()
130 hcf.abc_svc.goPos(0.1,0,0)
131 hcf.abc_svc.waitFootSteps()
134 print >> sys.stderr,
"1. getParameter" 135 ret=hcf.kf_svc.getKalmanFilterParam()
137 print >> sys.stderr,
" getKalmanFilterParam() => OK" 141 print >> sys.stderr,
"2. setParameter" 142 kfp=hcf.kf_svc.getKalmanFilterParam()[1]
146 ret=hcf.kf_svc.setKalmanFilterParam(kfp)
147 kfp2=hcf.kf_svc.getKalmanFilterParam()[1]
148 ret2 = ret
and kfp.Q_angle == kfp2.Q_angle
and kfp.Q_rate == kfp2.Q_rate
and kfp.R_angle == kfp2.R_angle
150 print >> sys.stderr,
" setKalmanFilterParam() => OK" 155 from distutils.version
import StrictVersion
156 if StrictVersion(hrpsys_version) >= StrictVersion(
'315.5.0'):
161 hcf.abc_svc.startAutoBalancer([
"rleg",
"lleg"])
163 for alg
in [OpenHRP.KalmanFilterService.RPYKalmanFilter, OpenHRP.KalmanFilterService.QuaternionExtendedKalmanFilter]:
164 kfp=hcf.kf_svc.getKalmanFilterParam()[1]
165 kfp.kf_algorithm = alg
166 hcf.kf_svc.setKalmanFilterParam(kfp)
168 hcf.kf_svc.resetKalmanFilterState()
169 hcf.seq_svc.setJointAngles(pitch_poses[0], 1.0)
170 hcf.seq_svc.waitInterpolation()
171 test_kf_plot(test_pitch_bending_2s,
"pitch-bending-2s"+str(alg))
174 hcf.seq_svc.setJointAngles(roll_poses[0], 1.0)
175 hcf.seq_svc.waitInterpolation()
176 test_kf_plot(test_roll_bending_2s,
"roll-bending-2s"+str(alg))
179 hcf.seq_svc.setJointAngles(yaw_poses[0], 1.0)
180 hcf.seq_svc.waitInterpolation()
181 test_kf_plot(test_yaw_bending_2s,
"yaw-bending-4s"+str(alg))
184 hcf.seq_svc.setJointAngles(roll_pitch_poses[0], 1.0)
185 hcf.seq_svc.waitInterpolation()
186 test_kf_plot(test_roll_pitch_bending_4s,
"roll-pitch-bending-4s"+str(alg))
188 hcf.seq_svc.setJointAngles(initial_pose, 1.0)
192 hcf.seq_svc.waitInterpolation()
195 if __name__ ==
'__main__':
def test_roll_pitch_bending_4s()
def demoGetKalmanFilterParameter()
def test_pitch_bending_2s()
def test_yaw_bending_4s()
def test_kf_plot(test_motion_func, optional_out_file_name)
def demoSetKalmanFilterParameter()
def test_roll_bending_4s()
def test_roll_pitch_bending_2s()
def test_roll_bending_2s()
def test_pitch_bending_4s()
def test_bending_common(time, poses)
def test_yaw_bending_2s()