00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 import numpy
00034 from numpy import matrix, vsplit, sin, cos, reshape
00035 import rospy
00036 from pr2_calibration_estimation.single_transform import SingleTransform
00037
00038
00039
00040
00041 class TiltingLaser:
00042
00043
00044
00045
00046 def __init__(self, config = {"before_joint": [ 0, 0, 0, 0, 0, 0],
00047 "after_joint" : [ 0, 0, 0, 0, 0, 0],
00048 'gearing':1 } ):
00049 rospy.logdebug("Initializing tilting laser")
00050
00051 self._before_joint = SingleTransform()
00052 self._after_joint = SingleTransform()
00053
00054 if 'cov' in config.keys():
00055 self._cov_dict = config['cov']
00056 else:
00057 self._cov_dict = {}
00058
00059 param_vec = self.dict_to_params(config)
00060 self.inflate(param_vec)
00061
00062 def dict_to_params(self, config):
00063 param_vec = reshape(matrix([ config["before_joint"], config["after_joint"] ], float), (-1,1))
00064 param_vec = numpy.concatenate([param_vec, matrix([config["gearing"]])])
00065 assert(param_vec.size == self.get_length())
00066 return param_vec
00067
00068 def params_to_config(self, param_vec):
00069 assert(param_vec.shape == (13,1))
00070 return {"before_joint" : self._before_joint.params_to_config(param_vec[0:6, 0]),
00071 "after_joint" : self._before_joint.params_to_config(param_vec[6:12,0]),
00072 "gearing" : float(param_vec[12,0]),
00073 "cov" : self._cov_dict}
00074
00075 def calc_free(self, free_config):
00076
00077 assert( 'before_joint' in free_config )
00078 assert( 'after_joint' in free_config )
00079 assert( 'gearing' in free_config )
00080
00081
00082 flat_config = free_config['before_joint'] + free_config['after_joint'] + [free_config['gearing']]
00083 assert( len(flat_config) == self.get_length())
00084
00085
00086 flat_free = [x == 1 for x in flat_config]
00087
00088 return flat_free
00089
00090
00091 def inflate(self, param_vec):
00092 self._before_joint.inflate(param_vec[0:6,:])
00093 self._after_joint.inflate(param_vec[6:12,:])
00094 self._gearing = param_vec[12,0]
00095
00096
00097 def deflate(self):
00098 param_vec = matrix(numpy.zeros((13,1), float))
00099 param_vec[0:6,0] = self._before_joint.deflate()
00100 param_vec[6:12,0] = self._after_joint.deflate()
00101 param_vec[12,0] = self._gearing
00102 return param_vec
00103
00104
00105 def get_length(self):
00106 return 13
00107
00108 def compute_pose(self, joint_pos):
00109 joint_T = SingleTransform([0, 0, 0, 0, joint_pos[0]*self._gearing, 0])
00110 return self._before_joint.transform * joint_T.transform * self._after_joint.transform
00111
00112
00113
00114
00115 def project_point_to_3D(self, joint_pos):
00116 p = joint_pos[1]
00117 r = joint_pos[2]
00118 ray = reshape(matrix([cos(p)*r, sin(p)*r, 0, 1]), (-1,1))
00119
00120 result = self.compute_pose(joint_pos) * ray
00121 return result
00122
00123
00124
00125
00126
00127
00128
00129
00130 def project_to_3D(self, joint_pos):
00131 result = numpy.concatenate( [self.project_point_to_3D(x) for x in joint_pos], 1 )
00132 return result