Frankx  0.2.0
A High-Level Motion API for Franka
kinematics.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <optional>
4 
5 #include <Eigen/Core>
6 #include <Eigen/Dense>
7 
8 
9 namespace frankx {
10 
11 struct Kinematics {
12  template <class MatT>
13  static Eigen::Matrix<typename MatT::Scalar, MatT::ColsAtCompileTime, MatT::RowsAtCompileTime> pseudoinverse(const MatT &mat, typename MatT::Scalar tolerance = typename MatT::Scalar{1e-4}) {
14  typedef typename MatT::Scalar Scalar;
15  auto svd = mat.jacobiSvd(Eigen::ComputeFullU | Eigen::ComputeFullV);
16  const auto &singularValues = svd.singularValues();
17  Eigen::Matrix<Scalar, MatT::ColsAtCompileTime, MatT::RowsAtCompileTime> singularValuesInv(mat.cols(), mat.rows());
18  singularValuesInv.setZero();
19  for (unsigned int i = 0; i < singularValues.size(); ++i) {
20  if (singularValues(i) > tolerance) {
21  singularValuesInv(i, i) = Scalar{1} / singularValues(i);
22 
23  } else {
24  singularValuesInv(i, i) = Scalar{0};
25  }
26  }
27  return svd.matrixV() * singularValuesInv * svd.matrixU().adjoint();
28  }
29 
31  size_t joint_index;
32  double value;
33 
35  };
36 
37  static std::array<double, 16> forward(const Eigen::Matrix<double, 7, 1>& q);
38  static std::array<double, 16> forwardElbow(const Eigen::Matrix<double, 7, 1>& q);
39  static Eigen::Matrix<double, 6, 1> forwardEuler(const Eigen::Matrix<double, 7, 1>& q);
40  static Eigen::Matrix<double, 6, 7> jacobian(const Eigen::Matrix<double, 7, 1>& q);
41  static Eigen::Matrix<double, 7, 1> inverse(const Eigen::Matrix<double, 6, 1>& x_target, const Eigen::Matrix<double, 7, 1>& q0, std::optional<NullSpaceHandling> null_space = std::nullopt);
42 };
43 
44 }
frankx::Kinematics
Definition: kinematics.hpp:11
frankx
Definition: __init__.py:1
frankx::Kinematics::forwardElbow
static std::array< double, 16 > forwardElbow(const Eigen::Matrix< double, 7, 1 > &q)
Definition: kinematics.cpp:64
frankx::Kinematics::NullSpaceHandling::joint_index
size_t joint_index
Definition: kinematics.hpp:31
frankx::Kinematics::forward
static std::array< double, 16 > forward(const Eigen::Matrix< double, 7, 1 > &q)
Definition: kinematics.cpp:8
frankx::Kinematics::NullSpaceHandling::value
double value
Definition: kinematics.hpp:32
frankx::Kinematics::pseudoinverse
static Eigen::Matrix< typename MatT::Scalar, MatT::ColsAtCompileTime, MatT::RowsAtCompileTime > pseudoinverse(const MatT &mat, typename MatT::Scalar tolerance=typename MatT::Scalar{1e-4})
Definition: kinematics.hpp:13
frankx::Kinematics::jacobian
static Eigen::Matrix< double, 6, 7 > jacobian(const Eigen::Matrix< double, 7, 1 > &q)
Definition: kinematics.cpp:145
frankx::Kinematics::forwardEuler
static Eigen::Matrix< double, 6, 1 > forwardEuler(const Eigen::Matrix< double, 7, 1 > &q)
Definition: kinematics.cpp:89
frankx::Kinematics::inverse
static Eigen::Matrix< double, 7, 1 > inverse(const Eigen::Matrix< double, 6, 1 > &x_target, const Eigen::Matrix< double, 7, 1 > &q0, std::optional< NullSpaceHandling > null_space=std::nullopt)
Definition: kinematics.cpp:221
frankx::Kinematics::NullSpaceHandling
Definition: kinematics.hpp:30
frankx::Kinematics::NullSpaceHandling::NullSpaceHandling
NullSpaceHandling(size_t joint_index, double value)
Definition: kinematics.hpp:34