Skip to content

Commit ac685dc

Browse files
authored
Fixed issue where we were trying to reduce the error in two places (#383)
1 parent ba89a2f commit ac685dc

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

trajopt/src/kinematic_terms.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -152,29 +152,32 @@ void DynamicCartPoseErrCalculator::Plot(const tesseract_visualization::Visualiza
152152
MatrixXd DynamicCartPoseJacCalculator::operator()(const VectorXd& dof_vals) const
153153
{
154154
// Duplicated from calcForwardNumJac in trajopt_sco/src/num_diff.cpp, but with ignoring tolerances
155-
tesseract_common::TransformMap state = manip_->calcFwdKin(dof_vals);
156-
Isometry3d source_tf = state[source_frame_] * source_frame_offset_;
157-
Isometry3d target_tf = state[target_frame_] * target_frame_offset_;
158-
VectorXd err = tesseract_common::calcTransformError(target_tf, source_tf);
155+
auto calc_error = [this](const VectorXd& vals) -> VectorXd {
156+
tesseract_common::TransformMap state = manip_->calcFwdKin(vals);
157+
Isometry3d source_tf = state[source_frame_] * source_frame_offset_;
158+
Isometry3d target_tf = state[target_frame_] * target_frame_offset_;
159+
VectorXd err;
160+
err = tesseract_common::calcTransformErrorJac(target_tf, source_tf);
159161

162+
VectorXd reduced_err(indices_.size());
163+
for (int i = 0; i < indices_.size(); ++i)
164+
reduced_err[i] = err[indices_[i]];
165+
166+
return reduced_err;
167+
};
168+
169+
VectorXd err = calc_error(dof_vals);
160170
Eigen::MatrixXd jac0(err.size(), dof_vals.size());
161171
Eigen::VectorXd dof_vals_pert = dof_vals;
162172
for (int i = 0; i < dof_vals.size(); ++i)
163173
{
164174
dof_vals_pert(i) = dof_vals(i) + epsilon_;
165-
tesseract_common::TransformMap state_pert = manip_->calcFwdKin(dof_vals_pert);
166-
Isometry3d source_tf_pert = state_pert[source_frame_] * source_frame_offset_;
167-
Isometry3d target_tf_pert = state_pert[target_frame_] * target_frame_offset_;
168-
VectorXd err_pert = tesseract_common::calcTransformError(target_tf_pert, source_tf_pert);
175+
VectorXd err_pert = calc_error(dof_vals_pert);
169176
jac0.col(i) = (err_pert - err) / epsilon_;
170177
dof_vals_pert(i) = dof_vals(i);
171178
}
172179

173-
MatrixXd reduced_jac(indices_.size(), manip_->numJoints());
174-
for (int i = 0; i < indices_.size(); ++i)
175-
reduced_jac.row(i) = jac0.row(indices_[i]);
176-
177-
return reduced_jac; // This is available in 3.4 jac0(indices_, Eigen::all);
180+
return jac0; // This is available in 3.4 jac0(indices_, Eigen::all);
178181
}
179182

180183
CartPoseErrCalculator::CartPoseErrCalculator(tesseract_kinematics::JointGroup::ConstPtr manip,
@@ -295,11 +298,7 @@ MatrixXd CartPoseJacCalculator::operator()(const VectorXd& dof_vals) const
295298
dof_vals_pert(i) = dof_vals(i);
296299
}
297300

298-
MatrixXd reduced_jac(indices_.size(), manip_->numJoints());
299-
for (int i = 0; i < indices_.size(); ++i)
300-
reduced_jac.row(i) = jac0.row(indices_[i]);
301-
302-
return reduced_jac; // This is available in 3.4 jac0(indices_, Eigen::all);
301+
return jac0; // This is available in 3.4 jac0(indices_, Eigen::all);
303302
}
304303

305304
MatrixXd CartVelJacCalculator::operator()(const VectorXd& dof_vals) const

0 commit comments

Comments
 (0)