- 3.0.2 rigid body dynamics module.
OperationalJacobianBase.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_OUTPUTS, size_t NUM_JOINTS, typename SCALAR>
20 class OperationalJacobianBase : public JacobianBase<NUM_OUTPUTS, NUM_JOINTS, SCALAR>
21 {
22 public:
23  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
24  typedef std::shared_ptr<OperationalJacobianBase<NUM_OUTPUTS, NUM_JOINTS, SCALAR>> ptr;
28  typedef Eigen::Matrix<SCALAR, 6 + NUM_JOINTS, 6 + NUM_JOINTS> square_matrix_t;
29  typedef Eigen::Matrix<SCALAR, Eigen::Dynamic, Eigen::Dynamic> MatrixXs;
30 
31 
32  OperationalJacobianBase() { resetUpdatedFlags(); }
41  void updateState(const state_t& state, const square_matrix_t& weighting = square_matrix_t::Identity())
42  {
43  resetUpdatedFlags();
44  state_ = state;
45  W_ = weighting;
46  }
47 
49  const jacobian_t& J()
50  {
51  if (JUpdated_ == true)
52  return J_;
53 
54  JUpdated_ = true;
55  getJacobianOrigin(state_, J_);
56  return J_;
57  }
58 
60  const jacobian_t& dJdt()
61  {
62  if (dJdtUpdated_ == true)
63  return dJdt_;
64 
65  dJdtUpdated_ = true;
66  getJacobianOriginDerivative(state_, dJdt_);
67  return dJdt_;
68  }
69 
71  const jacobian_inv_t& JdagerLDLT()
72  {
73  if (JdagerUpdated_ == true)
74  return Jdager_;
75 
76  JdagerUpdated_ = true;
77  Jdager_ = W_ * J().transpose() *
78  (J() * W_ * J().transpose()).ldlt().solve(MatrixXs::Identity(NUM_OUTPUTS, NUM_OUTPUTS));
79  return Jdager_;
80  }
81 
82  const jacobian_inv_t& JdagerSVD()
83  {
84  if (JdagerUpdated_ == true)
85  return Jdager_;
86 
87  JdagerUpdated_ = true;
88  Eigen::JacobiSVD<MatrixXs> svd(J(), Eigen::ComputeThinU | Eigen::ComputeThinV);
89  Eigen::Matrix<SCALAR, Eigen::Dynamic, 1> sing_values(
90  svd.matrixV().cols(), 1); // size of E has same size as columns of V
91  sing_values = (svd.singularValues().array() > 1e-9).select(svd.singularValues().array().inverse(), 0);
92  Jdager_ = svd.matrixV() * sing_values.asDiagonal() * svd.matrixU().transpose();
93  return Jdager_;
94  }
95 
97  const jacobian_inv_t& dJdagerdt()
98  {
99  // if(dJdagerdtUpdated_==true) return dJdagerdt_;
100 
101  dJdagerdtUpdated_ = true;
102  dJdagerdt_ = -JdagerLDLT() * dJdt() * JdagerLDLT();
103  return dJdagerdt_;
104  }
105 
107  const square_matrix_t& P()
108  {
109  if (PUpdated_ == true)
110  return P_;
111 
112  PUpdated_ = true;
113  P_ = square_matrix_t::Identity() - JdagerLDLT() * J();
114  return P_;
115  }
116 
118  const square_matrix_t& dPdt()
119  {
120  if (dPdtUpdated_ == true)
121  return dPdt_;
122 
123  dPdtUpdated_ = true;
124  dPdt_ = -JdagerLDLT() * dJdt() * P();
125  return dPdt_;
126  }
127 
132  virtual void resetUserUpdatedFlags() {}
139  virtual void getJacobianOrigin(const state_t& state, jacobian_t& J) = 0;
140 
147  virtual void getJacobianOriginDerivative(const state_t& state, jacobian_t& dJdt) = 0;
148 
149 
150 protected:
151  jacobian_t J_;
152 
153 private:
154  virtual void resetUpdatedFlags()
155  {
156  JUpdated_ = false;
157  dJdtUpdated_ = false;
158  JdagerUpdated_ = false;
159  dJdagerdtUpdated_ = false;
160  PUpdated_ = false;
161  dPdtUpdated_ = false;
163  }
164 
165  /*
166  * variables
167  */
168  bool JUpdated_;
169  bool dJdtUpdated_;
170  bool JdagerUpdated_;
171  bool dJdagerdtUpdated_;
172  bool PUpdated_;
173  bool dPdtUpdated_;
174 
175  state_t state_;
176  square_matrix_t W_;
177 
178  jacobian_t dJdt_;
179  jacobian_inv_t Jdager_;
180  jacobian_inv_t dJdagerdt_;
181  square_matrix_t P_;
182  square_matrix_t dPdt_;
183 };
184 
185 } // namespace tpl
186 
187 template <size_t NUM_OUTPUTS, size_t NUM_JOINTS>
189 
190 } // namespace rbd
191 } // namespace ct
const jacobian_inv_t & JdagerSVD()
Definition: OperationalJacobianBase.h:82
OperationalJacobianBase()
Definition: OperationalJacobianBase.h:32
JacobianBase< NUM_OUTPUTS, NUM_JOINTS, SCALAR >::state_t state_t
Definition: OperationalJacobianBase.h:25
Eigen::Matrix< SCALAR, 6+NUM_JOINTS, NUM_OUTPUTS > jacobian_inv_t
Definition: JacobianBase.h:25
Definition: OperationalJacobianBase.h:20
const jacobian_inv_t & dJdagerdt()
This method calculates the time derivative of right inverse.
Definition: OperationalJacobianBase.h:97
virtual ~OperationalJacobianBase()
Definition: OperationalJacobianBase.h:33
const jacobian_inv_t & JdagerLDLT()
This method calculates the right inverse using W as the weighting matrix.
Definition: OperationalJacobianBase.h:71
const square_matrix_t & dPdt()
This method calculates the time derivative of the null space projector.
Definition: OperationalJacobianBase.h:118
Eigen::Matrix< SCALAR, Eigen::Dynamic, Eigen::Dynamic > MatrixXs
Definition: OperationalJacobianBase.h:29
Definition: JacobianBase.h:19
const jacobian_t & dJdt()
This method gets the time derivative of the floating-base Jacobian.
Definition: OperationalJacobianBase.h:60
const square_matrix_t & P()
This method calculates the null space projector.
Definition: OperationalJacobianBase.h:107
JacobianBase< NUM_OUTPUTS, NUM_JOINTS, SCALAR >::jacobian_inv_t jacobian_inv_t
Definition: OperationalJacobianBase.h:27
JacobianBase< NUM_OUTPUTS, NUM_JOINTS, SCALAR >::jacobian_t jacobian_t
Definition: OperationalJacobianBase.h:26
void updateState(const state_t &state, const square_matrix_t &weighting=square_matrix_t::Identity())
Definition: OperationalJacobianBase.h:41
virtual void getJacobianOrigin(const state_t &state, jacobian_t &J)=0
Eigen::Matrix< SCALAR, 6+NUM_JOINTS, 6+NUM_JOINTS > square_matrix_t
Definition: OperationalJacobianBase.h:28
void ldlt(const Eigen::Matrix< SCALAR, Eigen::Dynamic, Eigen::Dynamic > &A, Eigen::Matrix< SCALAR, Eigen::Dynamic, Eigen::Dynamic > &L, Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 > &d)
jacobian_t J_
Definition: OperationalJacobianBase.h:151
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef std::shared_ptr< OperationalJacobianBase< NUM_OUTPUTS, NUM_JOINTS, SCALAR > > ptr
Definition: OperationalJacobianBase.h:24
Eigen::Matrix< SCALAR, NUM_OUTPUTS, 6+NUM_JOINTS > jacobian_t
Definition: JacobianBase.h:24
virtual void getJacobianOriginDerivative(const state_t &state, jacobian_t &dJdt)=0
const jacobian_t & J()
This method gets the floating-base Jacobian.
Definition: OperationalJacobianBase.h:49
virtual void resetUserUpdatedFlags()
Definition: OperationalJacobianBase.h:132