Skip to content

Commit 7e2f9d9

Browse files
committed
fix pinv bug
1 parent 7a64e2b commit 7e2f9d9

File tree

2 files changed

+2
-14
lines changed

2 files changed

+2
-14
lines changed

ik_solvers/src/pseudoinverse.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,10 @@ auto least_squares(const Eigen::MatrixXd & jac) -> Eigen::MatrixXd
1212
return jac.completeOrthogonalDecomposition().pseudoInverse();
1313
}
1414

15-
auto damped_least_squares(const Eigen::MatrixXd & jac, const Eigen::VectorXd & damping) -> Eigen::MatrixXd
16-
{
17-
if (damping.size() != jac.rows()) {
18-
throw std::invalid_argument("Damping vector must have the same size as the number of rows in the Jacobian.");
19-
}
20-
return jac.transpose() * ((jac * jac.transpose()) + damping.asDiagonal().toDenseMatrix()).inverse();
21-
}
22-
2315
auto damped_least_squares(const Eigen::MatrixXd & jac, double damping) -> Eigen::MatrixXd
2416
{
25-
return damped_least_squares(jac, damping * Eigen::MatrixXd::Identity(jac.rows(), jac.rows()));
17+
const Eigen::MatrixXd eye = Eigen::MatrixXd::Identity(jac.rows(), jac.rows());
18+
return jac.transpose() * ((jac * jac.transpose()) + (damping * eye)).inverse();
2619
}
2720

2821
} // namespace ik_solvers::pinv

ik_solvers/src/pseudoinverse.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ namespace ik_solvers::pinv
2828
/// Calculate the pseudoinverse of a Jacobian matrix using the Moore-Penrose method.
2929
auto least_squares(const Eigen::MatrixXd & jac) -> Eigen::MatrixXd;
3030

31-
/// Calculate the pseudoinverse of a Jacobian matrix using the damped least squares method.
32-
///
33-
/// This version allows for more granular selection of the damping values to tune the solution velocities.
34-
auto damped_least_squares(const Eigen::MatrixXd & jac, const Eigen::VectorXd & damping) -> Eigen::MatrixXd;
35-
3631
/// Calculate the pseudoinverse of a Jacobian matrix using the damped least squares method.
3732
auto damped_least_squares(const Eigen::MatrixXd & jac, double damping) -> Eigen::MatrixXd;
3833

0 commit comments

Comments
 (0)