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 = '-'):
30 for i
in range(data.shape[1]):
32 plt.subplot(3, 2, i+1)
34 plt.plot(col, ls = style)
41 mserr = ((x - y) ** 2).mean(axis=axis)
58 min_err = float(
"inf")
60 for i
in range(-offset, offset+1):
61 x_new, y_new =
shift(x, y, i)
66 err =
error(x_new, y_new, axis)
72 print min_err, min_index
74 return min_err, min_index
77 def f(config, axis = 0):
79 sim_pos = config[
'/simulation/joint_states/position']
80 sim_pos[:,[2,1,0,3,4,5]] = sim_pos[:,[0,1,2,3,4,5]]
83 real_pos = config[
'/real/joint_states/position']
87 sim_pos, real_pos =
shift(sim_pos, real_pos, offset)
89 config[
'/simulation/joint_states/position'] = sim_pos
90 config[
'/real/joint_states/position'] = real_pos
108 from dynamic_tuner
import *
109 params = rospy.get_param(
"/optimizable_params")
110 values = rospy.get_param(
"/objective_values")
114 src_topic =
'/follow_joint_trajectory/goal' 115 dst_topic =
'/arm_controller/follow_joint_trajectory/goal' 117 src_bag =
'exp-real-7.bag' 118 dst_bag =
'test_sim.bag' 120 start = {
'/follow_joint_trajectory/status/status_list[0]/status':1,
'/arm_controller/follow_joint_trajectory/feedback/status/status':1}
121 end = {
'/arm_controller/follow_joint_trajectory/result':
None,
'/follow_joint_trajectory/result':
None}
123 dyn =
dynamic_tuner(params, values, src_bag, dst_bag, src_topic, dst_topic, objective = f, start_signal = start, end_signal = end)
131 from dynamic_tuner import * 132 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}) 135 from dynamic_tuner import * 136 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}) 140 sim_bag = rosbag.Bag('test_sim.bag', 'r') 141 bag = restamp(sim_bag, output_bag_file = 'sim-restamped.bag', prefix = SIM_PREFIX, start_signal = start_signal, end_signal = end_signal)
144 dyn._optimizer.optimize()
146 dyn._optimizer.set_params_config({
'/arm_controller/gains/elbow_joint/p':100001})
147 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 find_best_error(x, y, offset, axis=0)
def plot(data, style='-')
def restamp(bag, output_bag_file='restamped.bag', values=[], prefix="", start_signal={}, end_signal={})