- 3.0.2 rigid body dynamics module.
FrameJacobian.h
Go to the documentation of this file.
1 /**********************************************************************************************************************
2 This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich.
3 Licensed under the BSD-2 license (see LICENSE file in main directory)
4 **********************************************************************************************************************/
5 
6 #pragma once
7 
9 
10 namespace ct {
11 namespace rbd {
12 namespace tpl {
13 
19 template <size_t NUM_JOINTS, typename SCALAR>
21 {
22 public:
23  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
24 
25  typedef Eigen::Matrix<SCALAR, 3, 3> Matrix3s;
26  typedef Eigen::Matrix<SCALAR, 3, 1> Vector3s;
27 
38  static void FromBaseJacobianToInertiaJacobian(const Matrix3s& i_R_b,
39  const Vector3s& b_r_point,
40  const Eigen::Matrix<SCALAR, 6, NUM_JOINTS>& b_J_point,
41  Eigen::Matrix<SCALAR, 6, NUM_JOINTS + 6>& i_J_point)
42  {
43  // orientation
44  Eigen::Matrix<SCALAR, 3, NUM_JOINTS + 6> i_J_poitOrientation;
45  FromBaseJacToInertiaJacOrientation(i_R_b, b_r_point, b_J_point.template topRows<3>(), i_J_poitOrientation);
46  // translation
47  Eigen::Matrix<SCALAR, 3, NUM_JOINTS + 6> i_J_poitTranslation;
48  FromBaseJacToInertiaJacTranslation(i_R_b, b_r_point, b_J_point.template bottomRows<3>(), i_J_poitTranslation);
49 
50  i_J_point << i_J_poitOrientation, i_J_poitTranslation;
51  }
52 
61  static void FromBaseJacToInertiaJacOrientation(const Matrix3s& i_R_b,
62  const Vector3s& b_r_point,
63  const Eigen::Matrix<SCALAR, 3, NUM_JOINTS>& b_J_point,
64  Eigen::Matrix<SCALAR, 3, NUM_JOINTS + 6>& i_J_point)
65  {
66  i_J_point << i_R_b, Matrix3s::Zero(), i_R_b * b_J_point;
67  }
68 
77  static void FromBaseJacToInertiaJacTranslation(const Matrix3s& i_R_b,
78  const Vector3s& b_r_point,
79  const Eigen::Matrix<SCALAR, 3, NUM_JOINTS>& b_J_point,
80  Eigen::Matrix<SCALAR, 3, NUM_JOINTS + 6>& i_J_point)
81  {
82  i_J_point << -i_R_b * CrossProductMatrix(b_r_point), i_R_b, i_R_b * b_J_point;
83  }
84 
85 
98  const Eigen::Matrix<SCALAR, NUM_JOINTS + 6, 1>& generalizedVelocities,
99  const Matrix3s& i_R_b,
100  const Vector3s& b_r_point,
101  const Eigen::Matrix<SCALAR, 6, NUM_JOINTS>& b_J_point,
102  const Eigen::Matrix<SCALAR, 6, NUM_JOINTS>& b_dJdt_point,
103  Eigen::Matrix<SCALAR, 6, NUM_JOINTS + 6>& i_dJdt_point)
104  {
105  // orientation
106  Eigen::Matrix<SCALAR, 3, NUM_JOINTS + 6> i_dJdt_pointOrientation;
107  FromBaseJacobianDevToInertiaJacobianDevOrientation(generalizedVelocities, i_R_b, b_r_point,
108  b_J_point.template topRows<3>(), b_dJdt_point.template topRows<3>(), i_dJdt_pointOrientation);
109  // translation
110  Eigen::Matrix<SCALAR, 3, NUM_JOINTS + 6> i_dJdt_pointTranslation;
111  FromBaseJacobianDevToInertiaJacobianDevTranslation(generalizedVelocities, i_R_b, b_r_point,
112  b_J_point.template bottomRows<3>(), b_dJdt_point.template bottomRows<3>(), i_dJdt_pointTranslation);
113 
114  i_dJdt_point << i_dJdt_pointOrientation, i_dJdt_pointTranslation;
115  }
116 
129  const Eigen::Matrix<SCALAR, NUM_JOINTS + 6, 1>& generalizedVelocities,
130  const Matrix3s& i_R_b,
131  const Vector3s& b_r_point,
132  const Eigen::Matrix<SCALAR, 3, NUM_JOINTS>& b_J_point,
133  const Eigen::Matrix<SCALAR, 3, NUM_JOINTS>& b_dJdt_point,
134  Eigen::Matrix<SCALAR, 3, NUM_JOINTS + 6>& i_dJdt_point)
135  {
136  // rotation matrix time derivatives
137  Matrix3s i_dRdt_b = i_R_b * CrossProductMatrix(generalizedVelocities.template head<3>());
138  // orientation
139  i_dJdt_point << i_dRdt_b, Matrix3s::Zero(), i_dRdt_b * b_J_point + i_R_b * b_dJdt_point;
140  }
141 
154  const Eigen::Matrix<SCALAR, NUM_JOINTS + 6, 1>& generalizedVelocities,
155  const Matrix3s& i_R_b,
156  const Vector3s& b_r_point,
157  const Eigen::Matrix<SCALAR, 3, NUM_JOINTS>& b_J_point,
158  const Eigen::Matrix<SCALAR, 3, NUM_JOINTS>& b_dJdt_point,
159  Eigen::Matrix<SCALAR, 3, NUM_JOINTS + 6>& i_dJdt_point)
160  {
161  // velocity of the point in the base frame
162  Vector3s b_v_point = b_J_point * generalizedVelocities.template tail<NUM_JOINTS>();
163  // rotation matrix time derivatives
164  Matrix3s i_dRdt_b = i_R_b * CrossProductMatrix(generalizedVelocities.template head<3>());
165  // translation
166  i_dJdt_point << -i_dRdt_b * CrossProductMatrix(b_r_point) - i_R_b * CrossProductMatrix(b_v_point), i_dRdt_b,
167  i_dRdt_b * b_J_point + i_R_b * b_dJdt_point;
168  }
169 
170 private:
171  /*
172  * calculates the skew matrix for vector cross product
173  */
174  template <typename Derived>
175  static Matrix3s CrossProductMatrix(const Eigen::DenseBase<Derived>& in)
176  {
177  if (in.innerSize() != 3 || in.outerSize() != 1)
178  throw std::runtime_error("Input argument should be a 3-by-1 vector.");
179 
180  Matrix3s out;
181  out << SCALAR(0.0), -in(2), +in(1), +in(2), SCALAR(0.0), -in(0), -in(1), +in(0), SCALAR(0.0);
182  return out;
183  }
184 };
185 
186 } // namespace tpl
187 
188 template <size_t NUM_JOINTS>
190 
191 } // namespace rbd
192 } // namespace ct
static void FromBaseJacToInertiaJacOrientation(const Matrix3s &i_R_b, const Vector3s &b_r_point, const Eigen::Matrix< SCALAR, 3, NUM_JOINTS > &b_J_point, Eigen::Matrix< SCALAR, 3, NUM_JOINTS+6 > &i_J_point)
Definition: FrameJacobian.h:61
This class provides methods for converting the non-inertia base frame Jacobian matrix to an user defi...
Definition: FrameJacobian.h:20
FrameJacobian()
Definition: FrameJacobian.h:28
CppAD::AD< CppAD::cg::CG< double > > SCALAR
Eigen::Matrix< SCALAR, 3, 1 > Vector3s
Definition: FrameJacobian.h:26
~FrameJacobian()
Definition: FrameJacobian.h:29
static void FromBaseJacobianToInertiaJacobian(const Matrix3s &i_R_b, const Vector3s &b_r_point, const Eigen::Matrix< SCALAR, 6, NUM_JOINTS > &b_J_point, Eigen::Matrix< SCALAR, 6, NUM_JOINTS+6 > &i_J_point)
Definition: FrameJacobian.h:38
static void FromBaseJacToInertiaJacTranslation(const Matrix3s &i_R_b, const Vector3s &b_r_point, const Eigen::Matrix< SCALAR, 3, NUM_JOINTS > &b_J_point, Eigen::Matrix< SCALAR, 3, NUM_JOINTS+6 > &i_J_point)
Definition: FrameJacobian.h:77
static void FromBaseJacobianDevToInertiaJacobianDevTranslation(const Eigen::Matrix< SCALAR, NUM_JOINTS+6, 1 > &generalizedVelocities, const Matrix3s &i_R_b, const Vector3s &b_r_point, const Eigen::Matrix< SCALAR, 3, NUM_JOINTS > &b_J_point, const Eigen::Matrix< SCALAR, 3, NUM_JOINTS > &b_dJdt_point, Eigen::Matrix< SCALAR, 3, NUM_JOINTS+6 > &i_dJdt_point)
Definition: FrameJacobian.h:153
static void FromBaseJacobianDevToInertiaJacobianDevOrientation(const Eigen::Matrix< SCALAR, NUM_JOINTS+6, 1 > &generalizedVelocities, const Matrix3s &i_R_b, const Vector3s &b_r_point, const Eigen::Matrix< SCALAR, 3, NUM_JOINTS > &b_J_point, const Eigen::Matrix< SCALAR, 3, NUM_JOINTS > &b_dJdt_point, Eigen::Matrix< SCALAR, 3, NUM_JOINTS+6 > &i_dJdt_point)
Definition: FrameJacobian.h:128
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef Eigen::Matrix< SCALAR, 3, 3 > Matrix3s
Definition: FrameJacobian.h:25
static void FromBaseJacobianDevToInertiaJacobianDev(const Eigen::Matrix< SCALAR, NUM_JOINTS+6, 1 > &generalizedVelocities, const Matrix3s &i_R_b, const Vector3s &b_r_point, const Eigen::Matrix< SCALAR, 6, NUM_JOINTS > &b_J_point, const Eigen::Matrix< SCALAR, 6, NUM_JOINTS > &b_dJdt_point, Eigen::Matrix< SCALAR, 6, NUM_JOINTS+6 > &i_dJdt_point)
Definition: FrameJacobian.h:97