1 from timeout
import timeout
3 import matplotlib.pyplot
as plt
4 rospy.init_node(
'tester')
18 data_sim = config[
'/simulation/joint_states/position']
19 data_real = config[
'/real/joint_states/position']
26 def plot(data, style = '-'):
28 print "single plot %d" % data.shape[1]
32 for i
in range(data.shape[1]):
34 plt.subplot(3, 2, i+1)
38 plt.plot(col, ls = style)
45 mserr = ((x - y) ** 2).mean(axis=axis)
46 print "################# individual errors ###################" 63 min_err = float(
"inf")
65 for i
in range(-offset, offset+1):
66 x_new, y_new =
shift(x, y, i)
71 err =
error(x_new, y_new, axis)
77 print min_err, min_index
79 return min_err, min_index
82 def f(config, axis = 0):
84 print "the config is:" 86 sim_pos = config[
'/simulation/joint_states/position']
90 real_pos = config[
'/real/joint_states/position']
92 sim_pos = sim_pos[:,[1,3,4,5,6,8]]
93 real_pos = real_pos[:,[1,3,4,5,6,8]]
97 sim_pos, real_pos =
shift(sim_pos, real_pos, offset)
99 config[
'/simulation/joint_states/position'] = sim_pos
100 config[
'/real/joint_states/position'] = real_pos
122 from dynamic_tuner
import *
123 params = rospy.get_param(
"/optimizable_params")
124 values = rospy.get_param(
"/objective_values")
131 src_topic =
'/haptix_deka_controller/command' 132 dst_topic =
'/haptix_deka_controller/command' 135 src_bag =
'exp-rand-01.bag' 136 dst_bag =
'test_sim.bag' 144 print "ready to start" 146 dyn =
dynamic_tuner(params, values, src_bag, dst_bag, src_topic, dst_topic, objective = f, start_signal = start, end_signal = end)
156 from dynamic_tuner import * 157 start_simulation('exp-real-7.bag', 'test_sim.bag', '/follow_joint_trajectory/goal', '/arm_controller/follow_joint_trajectory/goal', {'/follow_joint_trajectory/goal':None, '/arm_controller/follow_joint_trajectory/goal':None}, {'/arm_controller/follow_joint_trajectory/result':None, '/follow_joint_trajectory/result':None}) 160 from dynamic_tuner import * 161 start_simulation('exp-real-7.bag', 'test_sim.bag', '/follow_joint_trajectory/goal', '/arm_controller/follow_joint_trajectory/goal', {'/follow_joint_trajectory/status/status_list[0]/status':1, '/arm_controller/follow_joint_trajectory/feedback/status/status':1}, {'/arm_controller/follow_joint_trajectory/result':None, '/follow_joint_trajectory/result':None}) 165 sim_bag = rosbag.Bag('test_sim.bag', 'r') 166 bag = restamp(sim_bag, output_bag_file = 'sim-restamped.bag', prefix = SIM_PREFIX, start_signal = start_signal, end_signal = end_signal)
169 dyn._optimizer.optimize()
171 dyn._optimizer.set_params_config({
'/arm_controller/gains/elbow_joint/p':100001})
172 desc = dyn.get_params_desc([
'/arm_controller/gains/elbow_joint/p',
'/arm_controller/gains/elbow_joint/i',
'/arm_controller/gains/wrist_3_joint/d'])
def plot(data, style='-')
def find_best_error(x, y, offset, axis=0)
def restamp(bag, output_bag_file='restamped.bag', values=[], prefix="", start_signal={}, end_signal={})