- 3.0.2 rigid body dynamics module.
OperationalModel.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 
8 #include "OperationalModelBase.h"
9 
10 namespace ct {
11 namespace rbd {
12 
20 template <size_t NUM_OUTPUTS, size_t NUM_JOINTS, size_t NUM_CONTACTPOINTS>
21 class OperationalModel : public OperationalModelBase<NUM_OUTPUTS, NUM_JOINTS, NUM_CONTACTPOINTS>
22 {
23 public:
24  typedef std::shared_ptr<OperationalModel<NUM_OUTPUTS, NUM_JOINTS, NUM_CONTACTPOINTS>> ptr;
26  full_body_model_ptr_t; // this is a pointer type to original system
28  typedef typename Base::state_t state_t;
29  typedef typename Base::jacobian_t jacobian_t; //JacobianType;
30  typedef typename Base::jacobian_inv_t jacobian_inv_t; //JacobianInverseType;
31  typedef typename Base::jacobian_class_ptr_t jacobian_class_ptr_t; //JacobianClassType;
32  typedef typename Base::coordinate_class_ptr_t coordinate_class_ptr_t; //CoordinateClassType;
33 
35  const jacobian_class_ptr_t& jacobianPtr,
36  const coordinate_class_ptr_t& coordinatePtr = nullptr)
37  : Base(jacobianPtr, coordinatePtr), fullModelPtr_(fullModelPtr), jacobianPtr_(jacobianPtr)
38  {
39  if (!fullModelPtr)
40  throw std::runtime_error("Model pointer in is not instantiated!");
41  if (!jacobianPtr)
42  throw std::runtime_error("Task space Jacobian pointer in is not instantiated!");
43  }
44 
45  OperationalModel() = delete;
47 
52  void update(const state_t& state) override
53  {
54  Base::state_ = state;
55 
56  fullModelPtr_->update(state);
57  Base::jacobianPtr_->updateState(state, fullModelPtr_->MInverse());
58 
59  // jacobian dager
60  const jacobian_inv_t& Jdager = Base::jacobianPtr_->JdagerLDLT();
61 
62  // rigid body coefficients
63  Base::M_ = Jdager.transpose() * fullModelPtr_->M() * Jdager;
64  Base::MInverse_ = Base::M_.ldlt().solve(Eigen::MatrixXd::Identity(NUM_OUTPUTS, NUM_OUTPUTS));
65  Base::C_ = Jdager.transpose() * fullModelPtr_->C() -
67  Base::G_ = Jdager.transpose() * fullModelPtr_->G();
68  Base::S_ = fullModelPtr_->S() * Jdager;
69  // contact jacobians
70  for (size_t i = 0; i < NUM_CONTACTPOINTS; i++)
71  Base::AllJc_[i] = fullModelPtr_->Jc(i) * Jdager;
72  }
73 
78  jacobian_class_ptr_t getJacobianPtr() { return jacobianPtr_; }
79  const typename Base::S_t& STransposeDager(
80  const Eigen::MatrixXd& orthogonalSystemS = Eigen::MatrixXd::Zero(NUM_JOINTS, 0))
81  {
82  Eigen::Matrix<double, NUM_JOINTS, NUM_JOINTS> fixedBaseMassMatrix =
83  (fullModelPtr_->S() * fullModelPtr_->MInverse() * fullModelPtr_->S().transpose())
84  .ldlt()
85  .solve(Eigen::MatrixXd::Identity(NUM_JOINTS, NUM_JOINTS));
86 
87  Eigen::Matrix<double, NUM_JOINTS, NUM_JOINTS> W0 = fixedBaseMassMatrix;
88  W0.setIdentity();
89 
90  Eigen::Matrix<double, NUM_JOINTS, NUM_JOINTS> W;
91  if (orthogonalSystemS.cols() != 0)
92  W = W0 -
93  W0 * orthogonalSystemS *
94  (orthogonalSystemS.transpose() * W0 * orthogonalSystemS)
95  .ldlt()
96  .solve(Eigen::MatrixXd::Identity(orthogonalSystemS.cols(), orthogonalSystemS.cols())) *
97  orthogonalSystemS.transpose() * W0;
98  else
99  W = W0;
100 
101  STransposeDager_ =
102  W * Base::S_ *
103  (Base::S_.transpose() * W * Base::S_).ldlt().solve(Eigen::MatrixXd::Identity(NUM_OUTPUTS, NUM_OUTPUTS));
104  return STransposeDager_;
105  }
106 
107 private:
108  full_body_model_ptr_t fullModelPtr_;
109  jacobian_class_ptr_t jacobianPtr_;
110  typename Base::S_t STransposeDager_;
111 };
112 
113 
114 template <>
115 inline void OperationalModel<0, 12, 4>::update(const state_t& state)
116 {
117  Base::state_ = state;
118  fullModelPtr_->update(state);
119 }
120 
121 template <>
123  const Eigen::MatrixXd& orthogonalSystemS)
124 {
125  STransposeDager_.setZero();
126  return STransposeDager_;
127 }
128 }
129 }
Base::jacobian_t jacobian_t
Definition: OperationalModel.h:29
OperationalJacobianBase< NUM_OUTPUTS, NUM_JOINTS >::ptr jacobian_class_ptr_t
Definition: OperationalModelBase.h:35
state_t state_
Definition: OperationalModelBase.h:105
OperationalModelBase< NUM_JOINTS+6, NUM_JOINTS, NUM_CONTACTPOINTS >::ptr full_body_model_ptr_t
Definition: OperationalModel.h:26
S_t S_
Definition: OperationalModelBase.h:111
Base::jacobian_inv_t jacobian_inv_t
Definition: OperationalModel.h:30
OperationalJacobianBase< NUM_OUTPUTS, NUM_JOINTS >::jacobian_inv_t jacobian_inv_t
Definition: OperationalModelBase.h:39
OperationalModel(const full_body_model_ptr_t &fullModelPtr, const jacobian_class_ptr_t &jacobianPtr, const coordinate_class_ptr_t &coordinatePtr=nullptr)
Definition: OperationalModel.h:34
M_t MInverse_
Definition: OperationalModelBase.h:108
~OperationalModel()
Definition: OperationalModel.h:46
void update(const state_t &state) override
Definition: OperationalModel.h:52
G_t G_
Definition: OperationalModelBase.h:110
M_t M_
Definition: OperationalModelBase.h:107
This is the class for the operational space model which gives access to the operational model paramet...
Definition: OperationalModel.h:21
std::shared_ptr< OperationalModel< NUM_OUTPUTS, NUM_JOINTS, NUM_CONTACTPOINTS > > ptr
Definition: OperationalModel.h:24
C_t C_
Definition: OperationalModelBase.h:109
for i
OperationalModelBase< NUM_OUTPUTS, NUM_JOINTS, NUM_CONTACTPOINTS > Base
Definition: OperationalModel.h:27
Eigen::Matrix< double, NUM_JOINTS, NUM_OUTPUTS > S_t
Definition: OperationalModelBase.h:45
Base::coordinate_class_ptr_t coordinate_class_ptr_t
Definition: OperationalModel.h:32
Base::jacobian_class_ptr_t jacobian_class_ptr_t
Definition: OperationalModel.h:31
Definition: OperationalModelBase.h:29
OperationalJacobianBase< NUM_OUTPUTS, NUM_JOINTS >::jacobian_t jacobian_t
Definition: OperationalModelBase.h:37
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_class_ptr_t getJacobianPtr()
Definition: OperationalModel.h:78
const Base::S_t & STransposeDager(const Eigen::MatrixXd &orthogonalSystemS=Eigen::MatrixXd::Zero(NUM_JOINTS, 0))
Definition: OperationalModel.h:79
jacobian_class_ptr_t jacobianPtr_
Definition: OperationalModelBase.h:102
Base::state_t state_t
Definition: OperationalModel.h:28
std::array< Jc_t, NUM_CONTACTPOINTS > AllJc_
Definition: OperationalModelBase.h:112
CoordinateBase< NUM_OUTPUTS, NUM_JOINTS >::ptr coordinate_class_ptr_t
Definition: OperationalModelBase.h:34
coordinate_vector_t toCoordinateVelocity() const
Definition: RBDState.h:144