5#include <Eigen/Geometry> 
   10namespace tinyrobotics {
 
   17    template <
typename Scalar>
 
   18    Eigen::Matrix<Scalar, 3, 3> 
skew(
const Eigen::Matrix<Scalar, 3, 3>& input) {
 
   19        return 0.5 * (input - input.transpose());
 
   28    template <
typename Scalar>
 
   29    Eigen::Matrix<Scalar, 3, 3> 
skew(
const Eigen::Matrix<Scalar, 3, 1>& input) {
 
   30        Eigen::Matrix<Scalar, 3, 3> out;
 
   31        out << Scalar(0), -input(2), input(1), input(2), Scalar(0), -input(0), -input(1), input(0), Scalar(0);
 
   41    template <
typename Scalar>
 
   42    Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> 
null(
 
   43        const Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>& A) {
 
   44        Eigen::FullPivLU<Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>> lu(A);
 
   45        Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> A_null_space = lu.kernel();
 
   55    template <
typename Scalar>
 
   56    Eigen::Matrix<Scalar, 6, 6> 
cross_spatial(
const Eigen::Matrix<Scalar, 6, 1>& v) {
 
   57        Eigen::Matrix<Scalar, 6, 6> vcross;
 
   58        vcross << 0, -v(2), v(1), 0, 0, 0, v(2), 0, -v(0), 0, 0, 0, -v(1), v(0), 0, 0, 0, 0, 0, -v(5), v(4), 0, -v(2),
 
   59            v(1), v(5), 0, -v(3), v(2), 0, -v(0), -v(4), v(3), 0, -v(1), v(0), 0;
 
   69    template <
typename Scalar>
 
   70    Eigen::Matrix<Scalar, 6, 6> 
cross_motion(
const Eigen::Matrix<Scalar, 6, 1>& v) {
 
   79    template <
typename Scalar>
 
   81        Eigen::Matrix<Scalar, 6, 6> X = Eigen::Matrix<Scalar, 6, 6>::Identity();
 
   82        X.block(3, 0, 3, 3)           = -
skew(xyz);
 
   93    template <
typename Scalar>
 
   94    Eigen::Matrix<Scalar, 6, 6> 
rpy_to_spatial(
const Eigen::Matrix<Scalar, 3, 1>& rpy) {
 
   95        Eigen::Matrix<Scalar, 3, 3> E = rx(rpy(0)) * ry(rpy(1)) * rz(rpy(2));
 
   96        Eigen::Matrix<Scalar, 6, 6> X = Eigen::Matrix<Scalar, 6, 6>::Identity();
 
   97        X.block(0, 0, 3, 3)           = E;
 
   98        X.block(3, 3, 3, 3)           = E;
 
  109    template <
typename Scalar>
 
  111        Eigen::Matrix<Scalar, 6, 6> X = Eigen::Matrix<Scalar, 6, 6>::Zero();
 
  112        X.block(0, 0, 3, 3)           = H.rotation();
 
  113        X.block(3, 3, 3, 3)           = H.rotation();
 
  114        X.block(3, 0, 3, 3)           = 
skew(Eigen::Matrix<Scalar, 3, 1>(H.translation())) * H.rotation();
 
  127    template <
typename Scalar>
 
  129                                                   const Eigen::Matrix<Scalar, 3, 1>& c,
 
  130                                                   const Eigen::Matrix<Scalar, 3, 3>& I) {
 
  131        Eigen::Matrix<Scalar, 6, 6> Ic;
 
  132        Eigen::Matrix<Scalar, 3, 3> C = 
skew(c);
 
  134        Ic.block(0, 0, 3, 3) = I + m * C * C.transpose();
 
  135        Ic.block(0, 3, 3, 3) = m * C;
 
  136        Ic.block(3, 0, 3, 3) = m * C.transpose();
 
  137        Ic.block(3, 3, 3, 3) = m * Eigen::Matrix<Scalar, 3, 3>::Identity();
 
Eigen::Matrix< Scalar, 3, 3 > skew(const Eigen::Matrix< Scalar, 3, 3 > &input)
Computes the skew of a 3x3 vector.
Definition: Math.hpp:18
Eigen::Matrix< Scalar, 6, 6 > translation_to_spatial(const Eigen::Matrix< Scalar, 3, 1 > &xyz)
Spatial coordinate transform from a xyz translation.
Definition: Math.hpp:80
Eigen::Matrix< Scalar, 6, 6 > homogeneous_to_spatial(const Eigen::Transform< Scalar, 3, Eigen::Isometry > &H)
Spatial coordinate transform from homogeneous transformation matrix.
Definition: Math.hpp:110
Eigen::Matrix< Scalar, 6, 6 > rpy_to_spatial(const Eigen::Matrix< Scalar, 3, 1 > &rpy)
Spatial coordinate transform from roll-pitch-yaw angles.
Definition: Math.hpp:94
Eigen::Matrix< Scalar, 6, 6 > cross_motion(const Eigen::Matrix< Scalar, 6, 1 > &v)
Computes the 6x6 cross-product matrix for a motion vector and a force vector.
Definition: Math.hpp:70
Eigen::Matrix< Scalar, 6, 6 > cross_spatial(const Eigen::Matrix< Scalar, 6, 1 > &v)
Computes the 6x6 cross-product matrix for a 6D spatial vector.
Definition: Math.hpp:56
Eigen::Matrix< Scalar, 6, 6 > inertia_to_spatial(const Scalar m, const Eigen::Matrix< Scalar, 3, 1 > &c, const Eigen::Matrix< Scalar, 3, 3 > &I)
Spatial inertia matrix from inertia parameters.
Definition: Math.hpp:128
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > null(const Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > &A)
Computes an orthonormal basis for the null space of a matrix.
Definition: Math.hpp:42