37 import roslib; roslib.load_manifest(
'pr2_calibration_estimation')
43 from numpy
import matrix, concatenate
45 from pr2_calibration_estimation.sensors.chain_sensor
import ChainSensor
46 from pr2_calibration_estimation.sensors.multi_sensor
import MultiSensor
47 from pr2_calibration_estimation.sensors.tilting_laser_sensor
import TiltingLaserSensor
48 from pr2_calibration_estimation.robot_params
import RobotParams
49 from pr2_calibration_estimation.opt_runner
import ErrorCalc
52 from sensor_msgs.msg
import JointState
56 config = yaml.load(
''' 58 before_chain: [transformA] 60 after_chain: [transformB] 63 robot_params = RobotParams()
64 robot_params.configure( yaml.load(
''' 73 transformA: [0, 0, 0, 0, 0, 0] 74 transformB: [0, 0, 0, 0, 0, 0] 83 free_dict = yaml.load(
''' 92 transformA: [1, 0, 0, 0, 0, 0] 93 transformB: [0, 0, 0, 0, 0, 0] 100 chainM = ChainMeasurement( chain_id=
"chainA", chain_state=JointState(position=[0]))
102 sensor = ChainSensor(config, chainM,
"boardA" )
103 sensor.update_config(robot_params)
105 target_pts = matrix([[1, 2, 1, 2],
110 calc = ErrorCalc(robot_params, free_dict, [])
112 expanded_param_vec = robot_params.deflate()
113 free_list = robot_params.calc_free(free_dict)
114 opt_param_mat = expanded_param_vec[numpy.where(free_list), 0].copy()
115 opt_param = numpy.array(opt_param_mat)[0]
117 J = calc.single_sensor_params_jacobian(opt_param, target_pts, sensor)
123 configA = yaml.load(
''' 125 before_chain: [transformA] 127 after_chain: [transformB] 130 configB = yaml.load(
''' 132 before_chain: [transformA] 134 after_chain: [transformB] 137 robot_params = RobotParams()
138 robot_params.configure( yaml.load(
''' 147 transformA: [0, 0, 0, 0, 0, 0] 148 transformB: [0, 0, 0, 0, 0, 0] 157 free_dict = yaml.load(
''' 166 transformA: [0, 0, 0, 0, 0, 0] 167 transformB: [0, 0, 0, 0, 0, 0] 174 sensorA = ChainSensor(configA, ChainMeasurement( chain_id=
"chainA", chain_state=JointState(position=[0])),
"boardA")
176 sensorB = ChainSensor(configB, ChainMeasurement( chain_id=
"chainB", chain_state=JointState(position=[0])),
"boardA")
178 multisensor = MultiSensor(
None)
179 multisensor.sensors = [sensorA, sensorB]
180 multisensor.checkerboard =
"boardA" 182 pose_param_vec = numpy.array([0, 0, 0, 0, 0, 0])
183 calc = ErrorCalc(robot_params, free_dict, [])
185 expanded_param_vec = robot_params.deflate()
186 free_list = robot_params.calc_free(free_dict)
187 opt_param_mat = expanded_param_vec[numpy.where(free_list), 0].copy()
188 opt_param = numpy.array(opt_param_mat)[0]
190 J = calc.multisensor_pose_jacobian(opt_param, pose_param_vec, multisensor)
196 configA = yaml.load(
''' 198 before_chain: [transformA] 203 configB = yaml.load(
''' 207 after_chain: [transformB] 210 robot_params = RobotParams()
211 robot_params.configure( yaml.load(
''' 219 before_joint: [0, 0, 0, 0, 0, 0] 220 after_joint: [0, 0, 0, 0, 0, 0] 223 transformA: [0, 0, 0, 0, 0, 0] 224 transformB: [0, 0, 0, 0, 0, 0] 238 free_dict = yaml.load(
''' 246 before_joint: [1, 0, 0, 0, 0, 0] 247 after_joint: [0, 0, 0, 0, 0, 0] 250 transformA: [0, 0, 0, 0, 0, 0] 251 transformB: [1, 0, 0, 0, 0, 0] 261 sensorA = ChainSensor(configA, ChainMeasurement( chain_id=
"chainA", chain_state=JointState(position=[0])),
"boardA")
262 sensorB = ChainSensor(configB, ChainMeasurement( chain_id=
"chainB", chain_state=JointState(position=[0])),
"boardB")
263 laserB = TiltingLaserSensor({
'laser_id':
'laserB'}, LaserMeasurement( laser_id=
"laserB",
264 joint_points=[ JointState(position=[0,0,2]) ] ) )
266 multisensorA = MultiSensor(
None)
267 multisensorA.sensors = [sensorA]
268 multisensorA.checkerboard =
"boardA" 269 multisensorA.update_config(robot_params)
271 multisensorB = MultiSensor(
None)
272 multisensorB.sensors = [sensorB, laserB]
273 multisensorB.checkerboard =
"boardB" 274 multisensorB.update_config(robot_params)
276 poseA = numpy.array([1, 0, 0, 0, 0, 0])
277 poseB = numpy.array([2, 0, 0, 0, 0, 0])
279 calc = ErrorCalc(robot_params, free_dict, [multisensorA, multisensorB])
281 expanded_param_vec = robot_params.deflate()
282 free_list = robot_params.calc_free(free_dict)
283 opt_param_mat = expanded_param_vec[numpy.where(free_list), 0].copy()
284 opt_param = numpy.array(opt_param_mat)[0]
285 opt_all_vec = concatenate([opt_param, poseA, poseB])
287 print "Calculating Sparse" 288 J = calc.calculate_jacobian(opt_all_vec)
289 numpy.savetxt(
"J_sparse.txt", J, fmt=
"% 4.3f")
293 print "Calculating Dense" 294 from scipy.optimize.slsqp
import approx_jacobian
295 J_naive = approx_jacobian(opt_all_vec, calc.calculate_error, 1e-6)
296 numpy.savetxt(
"J_naive.txt", J_naive, fmt=
"% 4.3f")
299 self.assertAlmostEqual(numpy.linalg.norm(J-J_naive), 0.0, 6)
301 if __name__ ==
'__main__':
305 rostest.unitrun(
'pr2_calibration_estimation',
'test_full_J', TestFullJacobian, coverage_packages=[
'pr2_calibration_estimation.opt_runner'])
def test_single_sensor(self)
def test_full_jacobian(self)
def test_multisensor_pose_jacobian(self)