def residual(params, csm_predictions, base_link_rotations, initial_points, initial_base_link):
"""A functions that computes the residual error of the laser pose from URDF."""
# Get base_link to laser transform
base_link_to_laser = tf.transformations.compose_matrix(None,
None,
[params['laser_rot_x'],
params['laser_rot_y'],
params['laser_rot_z']],
[params['laser_trans_x'],
params['laser_trans_y'],
params['laser_trans_z']],
None)
# Now for each base_link_rotation predict the scans how they would appear in the rotated lasers
nr_points = csm_predictions[0].shape[0]
nr_predictions = len(csm_predictions)
data = np.zeros((nr_predictions * nr_points, 2))
model = np.zeros((nr_predictions * nr_points, 2))
for idx, (base_link_rotation, columns_observation) in enumerate(
zip(base_link_rotations, csm_predictions)):
# Pose of laser in the rotated/moved robot
laser_rotated_pose = (initial_base_link.dot(base_link_rotation)).dot(base_link_to_laser)
# Initial pose of the laser corresponding to initial_base_link
laser_initial_pose = initial_base_link.dot(base_link_to_laser)
# Transform matrix describing the motion if the laser translation/rotation
laser_rotation = np.linalg.inv(laser_initial_pose).dot(laser_rotated_pose)
# Now project the initially observed columns to predict their appearance in new pose
projected_columns_observation = (np.linalg.inv(laser_rotation).dot(initial_points.T)).T
# Put the model prediction and the data observation in their respective vectors
data[idx * nr_points:(idx + 1) * nr_points, :] = copy.deepcopy(columns_observation[:, :2])
model[idx * nr_points:(idx + 1) * nr_points, :] = copy.deepcopy(
projected_columns_observation[:, :2])
return data.flatten() - model.flatten()
I also noticed that this mostly happens In simulation, I set my model to fit to the data (correct lidar pose), which makes sense as the optimal solution is already set up. But when I make slight changes in the laser pose parameters, lmfit still have troubles. Only when the pose error is really big that lmfit converges. Where should I look into?

Thanks Matt for you suggestion. I tried this epsfcn value but it doesn't seem to have any effect. I am not sure where to put it actually. I couldn’t find a detailed documentation of the minimize(function).
--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To post to this group, send email to lmfi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/98629ff5-7e07-4c69-a1bc-306e19b54b12%40googlegroups.com.
OrderedDict([('front_laser_rot_x', 3.141592653589793), ('front_laser_rot_y', -0.0), ('front_laser_rot_z', -0.65644682438400015), ('front_laser_trans_x', 0.39483264551099995), ('front_laser_trans_y', -0.11629361362399998), ('front_laser_trans_z', 0.1125), ('rear_laser_rot_x', 3.141592653589793), ('rear_laser_rot_y', -6.1629758220391534e-33), ('rear_laser_rot_z', 2.2785545254699997), ('rear_laser_trans_x', -0.39811236099900005), ('rear_laser_trans_y', 0.12254920721599999), ('rear_laser_trans_z', 0.1125)])
Residual error : 0.221663666888
OrderedDict([('front_laser_rot_x', 3.141592653589793), ('front_laser_rot_y', -0.0), ('front_laser_rot_z', -0.65644682438400015), ('front_laser_trans_x', 0.39483264551099995), ('front_laser_trans_y', -0.11629361362399998), ('front_laser_trans_z', 0.1125), ('rear_laser_rot_x', 3.141592653589793), ('rear_laser_rot_y', -6.1629758220391534e-33), ('rear_laser_rot_z', 2.2785545254699997), ('rear_laser_trans_x', -0.39811236099900005), ('rear_laser_trans_y', 0.12254920721599999), ('rear_laser_trans_z', 0.1125)])
Residual error : 0.221663666888
OrderedDict([('front_laser_rot_x', 3.141592653589793), ('front_laser_rot_y', -0.0), ('front_laser_rot_z', -0.65644682438400015), ('front_laser_trans_x', 0.39483264551099995), ('front_laser_trans_y', -0.11629361362399998), ('front_laser_trans_z', 0.1125), ('rear_laser_rot_x', 3.141592653589793), ('rear_laser_rot_y', -6.1629758220391534e-33), ('rear_laser_rot_z', 2.2785545254699997), ('rear_laser_trans_x', -0.39811236099900005), ('rear_laser_trans_y', 0.12254920721599999), ('rear_laser_trans_z', 0.1125)])
Residual error : 0.221663666888
OrderedDict([('front_laser_rot_x', 3.141592653589793), ('front_laser_rot_y', -0.0), ('front_laser_rot_z', -0.65644682438400015), ('front_laser_trans_x', 0.39483264551099995), ('front_laser_trans_y', -0.11629361362399998), ('front_laser_trans_z', 0.1125), ('rear_laser_rot_x', 3.141592653589793), ('rear_laser_rot_y', -6.1629758220391534e-33), ('rear_laser_rot_z', 2.2785545254699997), ('rear_laser_trans_x', -0.39811236099900005), ('rear_laser_trans_y', 0.12254920721599999), ('rear_laser_trans_z', 0.1125)])
Residual error : 0.221663666888
[[Variables]]
front_laser_rot_x: 3.141593 (fixed)
front_laser_rot_y: -0 (fixed)
front_laser_rot_z: -0.65644682 +/- 0 (-0.00%) (init=-0.6564468)
front_laser_trans_x: 0.3948326 (fixed)
front_laser_trans_y: -0.1162936 (fixed)
front_laser_trans_z: 0.1125 (fixed)
rear_laser_rot_x: 3.141593 (fixed)
rear_laser_rot_y: -6.162976e-33 (fixed)
rear_laser_rot_z: 2.278555 (fixed)
rear_laser_trans_x: -0.3981124 (fixed)
rear_laser_trans_y: 0.1225492 (fixed)
rear_laser_trans_z: 0.1125 (fixed)
def residual(params, master, master_csm_predictions,
master_initial_points, initial_base_link, base_link_rotations):
"""A functions that computes the residual error of the laser pose from URDF."""
# Get base_link to laser transform
base_link_to_laser = CalibUtils.params_to_matrix(master + '_laser', params)
# Now for each base_link_rotation predict the columns how they would appear in the rotated lasers
nr_points = master_csm_predictions[0].shape[0]
nr_predictions = len(master_csm_predictions)
data_master = np.zeros((nr_predictions * nr_points, 2))
model_master = np.zeros((nr_predictions * nr_points, 2))
for idx, (base_link_rotation, master_csm_prediction) in enumerate(
zip(base_link_rotations, master_csm_predictions)):
# Pose of laser in the rotated/moved robot
laser_rotated_pose = (initial_base_link.dot(base_link_rotation)).dot(base_link_to_laser)
# Initial pose of the laser corresponding to initial_base_link
laser_initial_pose = initial_base_link.dot(base_link_to_laser)
# Transform matrix describing the 21motion if the laser translation/rotation
laser_rotation = np.linalg.inv(laser_initial_pose).dot(laser_rotated_pose)
# Now project the initially observed columns to predict their appearance in new pose
projected_columns_observation = (np.linalg.inv(laser_rotation).dot(master_initial_points.T)).T
# Put the model prediction and the data observation in their respective vectors
data_master[idx * nr_points:(idx + 1) * nr_points, :] = copy.deepcopy(master_csm_prediction[:, :2])
model_master[idx * nr_points:(idx + 1) * nr_points, :] = copy.deepcopy(
projected_columns_observation[:, :2])
print params.valuesdict()
print "Residual error : ", np.mean(np.absolute(data_master - model_master))
return data_master - model_master
Residual error : 0.00377279291488
[[Variables]]
front_laser_rot_x: 3.141593 (fixed)
front_laser_rot_y: 6.162976e-33 (fixed)
front_laser_rot_z: -0.77248327 +/- 0.000340 (0.04%) (init=-0.8564468)
front_laser_trans_x: 0.3948326 (fixed)
front_laser_trans_y: -0.1162936 (fixed)
front_laser_trans_z: 0.1125 (fixed)
rear_laser_rot_x: 3.141593 (fixed)
rear_laser_rot_y: -6.162976e-33 (fixed)
rear_laser_rot_z: 2.478555 (fixed)
rear_laser_trans_x: -0.3981124 (fixed)
rear_laser_trans_y: 0.1225492 (fixed)
rear_laser_trans_z: 0.1125 (fixed)