37 import roslib; roslib.load_manifest(
'calibration_estimation')
43 from numpy
import matrix, vsplit, sin, cos, reshape, zeros, pi
54 cur_index = start_index
57 primitive_dict = dict()
60 for key, elem
in config_dict.items():
61 primitive_dict[key] = PrimitiveType(elem)
63 primitive_dict[key].start = cur_index
64 primitive_dict[key].end = cur_index + primitive_dict[key].get_length()
65 cur_index = primitive_dict[key].end
68 return primitive_dict, cur_index
73 for key, elem
in primitive_dict.items():
74 elem.inflate(param_vec[elem.start:elem.end,0])
79 for key, elem
in primitive_dict.items():
80 param_vec[elem.start:elem.end,0] = elem.deflate()
86 for key, elem
in config_dict.items():
87 if key
in free_dict.keys():
88 free = elem.calc_free(free_dict[key])
89 target_list[elem.start:elem.end] = free
94 for key, elem
in primitive_dict.items():
95 config_dict[key] = elem.params_to_config(param_vec[elem.start:elem.end,0])
102 urdf = URDF().parse(raw_urdf)
114 transforms = config_dict[
'transforms']
115 checkerboards = config_dict[
"checkerboards"]
116 config_dict = config_dict[
'sensors']
122 for joint_name
in urdf.joint_map.keys():
123 j = urdf.joint_map[joint_name]
125 j.origin =
Pose([0.0, 0.0, 0.0], [0.0, 0.0, 0.0])
126 if j.origin.rotation ==
None:
127 j.origin.rotation = [0.0, 0.0, 0.0]
128 if j.origin.position ==
None:
129 j.origin.position = [0.0, 0.0, 0.0]
133 for joint_name
in urdf.joint_map.keys():
134 joint_name = str(joint_name)
135 j = urdf.joint_map[joint_name]
136 rot = j.origin.rotation
138 p = j.origin.position + rot
143 for name, transform
in transforms.items():
144 transform = [eval(str(x))
for x
in transform]
149 rospy.logwarn(
"Transform not found in URDF %s", name)
157 chain_dict = config_dict[
'chains']
158 for chain_name
in config_dict[
'chains']:
160 this_config = config_dict[
'chains'][chain_name]
161 this_config[
'joints'] = urdf.get_chain(this_config[
'root'], this_config[
'tip'], links=
False)
162 this_config[
'active_joints'] = list()
163 this_config[
'axis'] = list()
164 this_config[
'transforms'] = dict()
165 this_config[
'gearing'] = config_dict[
'chains'][chain_name][
'gearing']
166 this_config[
'cov'] = config_dict[
'chains'][chain_name][
'cov']
167 for joint_name
in this_config[
"joints"]:
168 this_config[
'transforms'][joint_name] = self.
transforms[joint_name]
169 if urdf.joint_map[joint_name].joint_type
in [
'revolute',
'continuous'] :
170 this_config[
"active_joints"].append(joint_name)
171 axis = urdf.joint_map[joint_name].axis
172 this_config[
"axis"].append( sum( [i[0]*int(i[1])
for i
in zip([4,5,6], axis)] ) )
174 rot = urdf.joint_map[joint_name].origin.rotation
175 if rot !=
None and (sum([abs(x)
for x
in rot]) - rot[abs(this_config[
"axis"][-1])-4]) > 0.001:
176 print 'Joint origin is rotated, calibration will fail: ', joint_name
177 elif urdf.joint_map[joint_name].joint_type ==
'prismatic':
178 this_config[
"active_joints"].append(joint_name)
179 axis = urdf.joint_map[joint_name].axis
180 this_config[
"axis"].append( sum( [i[0]*int(i[1])
for i
in zip([1,2,3], axis)] ) )
181 elif urdf.joint_map[joint_name].joint_type !=
'fixed':
182 print 'Unknown joint type:', urdf.joint_map[joint_name].joint_type
184 self.urdf.add_link(
Link(chain_name+
"_cb_link"))
185 self.urdf.add_joint(
Joint(chain_name+
"_cb",this_config[
'tip'],chain_name+
"_cb_link",
"fixed",origin=
Pose([0.0,0.0,0.0],[0.0,0.0,0.0])))
186 self.
fakes += [chain_name+
"_cb_link", chain_name+
"_cb"]
188 self.
chains[chain_name].start = cur_index
189 self.
chains[chain_name].end = cur_index + self.
chains[chain_name].get_length()
190 cur_index = self.
chains[chain_name].end
194 if 'tilting_lasers' in config_dict.keys():
196 self.rectified_cams, cur_index =
init_primitive_dict(cur_index, config_dict[
"rectified_cams"], RectifiedCamera)
197 self.checkerboards, cur_index =
init_primitive_dict(cur_index, checkerboards, Checkerboard)
203 free_list = [0] * self.
length 213 config_dict[
"base_link"] = self.
base_link 214 config_dict[
"transforms"] = dict()
215 for key, elem
in self.transforms.items():
216 config_dict[
"transforms"][key] = elem.params_to_config(param_vec[elem.start:elem.end,0])
217 config_dict[
"transforms"][key][3:6] =
angle_axis_to_RPY(config_dict[
"transforms"][key][3:6])
218 config_dict[
"sensors"] = {}
227 for key, elem
in self.chains.items():
228 elem.inflate(param_vec[elem.start:elem.end,0])
229 for joint_name
in elem._joints:
230 elem._transforms[joint_name] = self.
transforms[joint_name]
236 param_vec = numpy.matrix( numpy.zeros((self.
length,1), float))
245 ''' Remove checkerboard links/joints. ''' 246 for joint
in self.urdf.joint_map.keys():
247 if joint
in self.
fakes:
248 self.urdf.joints.remove(self.urdf.joint_map[joint])
249 del self.urdf.joint_map[joint]
250 for link
in self.urdf.link_map.keys():
251 if link
in self.
fakes:
252 self.urdf.links.remove(self.urdf.link_map[link])
253 del self.urdf.link_map[link]
def inflate_primitive_dict(param_vec, primitive_dict)
def update_primitive_free(target_list, config_dict, free_dict)
def __init__(self, raw_urdf, config)
def deflate_primitive_dict(param_vec, primitive_dict)
def calc_free(self, free_dict)
def primitive_params_to_config(param_vec, primitive_dict)
def configure(self, urdf, config_dict)
def init_primitive_dict(start_index, config_dict, PrimitiveType)
def params_to_config(self, param_vec)
def inflate(self, param_vec)