- 3.0.2 rigid body dynamics module.
OperationalModelBase.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 
10 #include <ct/rbd/state/RBDState.h>
11 #include "../coordinate/CoordinateBase.h"
12 
13 namespace ct {
14 namespace rbd {
15 
28 template <size_t NUM_OUTPUTS, size_t NUM_JOINTS, size_t NUM_CONTACTPOINTS>
30 {
31 public:
32  typedef std::shared_ptr<OperationalModelBase<NUM_OUTPUTS, NUM_JOINTS, NUM_CONTACTPOINTS>> ptr;
33 
36 
39  jacobian_inv_t; //JacobianInverseType;
40 
42  typedef Eigen::Matrix<double, NUM_OUTPUTS, NUM_OUTPUTS> M_t;
43  typedef Eigen::Matrix<double, NUM_OUTPUTS, 1> C_t;
44  typedef Eigen::Matrix<double, NUM_OUTPUTS, 1> G_t;
45  typedef Eigen::Matrix<double, NUM_JOINTS, NUM_OUTPUTS> S_t;
46  typedef Eigen::Matrix<double, 3, NUM_OUTPUTS> Jc_t;
47 
48  OperationalModelBase(const jacobian_class_ptr_t& jacobianPtr = nullptr,
49  const coordinate_class_ptr_t& coordinatePtr = nullptr)
50  : jacobianPtr_(jacobianPtr), coordinatePtr_(coordinatePtr){};
51 
52  virtual ~OperationalModelBase(){};
53 
55  const M_t& M() const { return M_; }
57  const M_t& MInverse() const { return MInverse_; }
59  const C_t& C() const { return C_; }
61  const G_t& G() const { return G_; }
63  const S_t& S() const { return S_; }
65  const std::array<Jc_t, NUM_CONTACTPOINTS>& AllJc() const { return AllJc_; }
67  const Jc_t& Jc(size_t i) const { return AllJc_[i]; }
69  Eigen::Matrix<double, NUM_OUTPUTS, 1> getPositions()
70  {
71  if (coordinatePtr_)
72  return coordinatePtr_->getCoordinate(state_);
73  else
74  return state_.toCoordinatePosition().template head<NUM_OUTPUTS>();
75  }
76 
78  Eigen::Matrix<double, NUM_OUTPUTS, 1> getVelocities()
79  {
80  if (jacobianPtr_)
82  else
83  return state_.toCoordinateVelocity().template head<NUM_OUTPUTS>();
84  }
85 
87  Eigen::Matrix<double, NUM_OUTPUTS, 1> getAccelerations(Eigen::Matrix<double, NUM_JOINTS + 6, 1> qdd)
88  {
89  if (jacobianPtr_)
90  return jacobianPtr_->J() * qdd + jacobianPtr_->dJdt() * state_.toCoordinateVelocity();
91  else
92  return qdd.template head<NUM_OUTPUTS>();
93  }
94 
99  virtual void update(const state_t& state) = 0;
100 
101 protected:
102  jacobian_class_ptr_t jacobianPtr_;
103  coordinate_class_ptr_t coordinatePtr_;
104 
105  state_t state_;
106 
107  M_t M_;
109  C_t C_;
110  G_t G_;
111  S_t S_;
112  std::array<Jc_t, NUM_CONTACTPOINTS> AllJc_;
113 };
114 
115 } // end of rbd namespace
116 } // end of os namespace
virtual ~OperationalModelBase()
Definition: OperationalModelBase.h:52
OperationalJacobianBase< NUM_OUTPUTS, NUM_JOINTS >::ptr jacobian_class_ptr_t
Definition: OperationalModelBase.h:35
Eigen::Matrix< double, NUM_OUTPUTS, 1 > getPositions()
Get the coordinate position.
Definition: OperationalModelBase.h:69
Eigen::Matrix< double, NUM_OUTPUTS, 1 > getVelocities()
Get the coordinate velocity.
Definition: OperationalModelBase.h:78
state_t state_
Definition: OperationalModelBase.h:105
std::shared_ptr< CoordinateBase< NUM_OUTPUTS, NUM_JOINTS > > ptr
Definition: CoordinateBase.h:21
S_t S_
Definition: OperationalModelBase.h:111
Definition: OperationalJacobianBase.h:20
OperationalJacobianBase< NUM_OUTPUTS, NUM_JOINTS >::jacobian_inv_t jacobian_inv_t
Definition: OperationalModelBase.h:39
coordinate_vector_t toCoordinatePosition() const
Definition: RBDState.h:136
Eigen::Matrix< double, NUM_OUTPUTS, 1 > G_t
Definition: OperationalModelBase.h:44
coordinate_class_ptr_t coordinatePtr_
Definition: OperationalModelBase.h:103
M_t MInverse_
Definition: OperationalModelBase.h:108
G_t G_
Definition: OperationalModelBase.h:110
M_t M_
Definition: OperationalModelBase.h:107
const S_t & S() const
Get the selection matrix: S.
Definition: OperationalModelBase.h:63
C_t C_
Definition: OperationalModelBase.h:109
const M_t & MInverse() const
Get the inertia matrix inverse: M^{-1}.
Definition: OperationalModelBase.h:57
OperationalModelBase(const jacobian_class_ptr_t &jacobianPtr=nullptr, const coordinate_class_ptr_t &coordinatePtr=nullptr)
Definition: OperationalModelBase.h:48
Eigen::Matrix< double, NUM_OUTPUTS, NUM_OUTPUTS > M_t
Definition: OperationalModelBase.h:42
Eigen::Matrix< double, NUM_JOINTS, NUM_OUTPUTS > S_t
Definition: OperationalModelBase.h:45
Eigen::Matrix< double, NUM_OUTPUTS, 1 > getAccelerations(Eigen::Matrix< double, NUM_JOINTS+6, 1 > qdd)
Get the coordinate acceleration.
Definition: OperationalModelBase.h:87
const G_t & G() const
Get the gravity force vector: G.
Definition: OperationalModelBase.h:61
const C_t & C() const
Get the Coriolis force vector: C.
Definition: OperationalModelBase.h:59
const Jc_t & Jc(size_t i) const
Get the ith contact Jacobian: Jc[i].
Definition: OperationalModelBase.h:67
Definition: OperationalModelBase.h:29
virtual void update(const state_t &state)=0
OperationalJacobianBase< NUM_OUTPUTS, NUM_JOINTS >::jacobian_t jacobian_t
Definition: OperationalModelBase.h:37
Eigen::Matrix< double, 3, NUM_OUTPUTS > Jc_t
Definition: OperationalModelBase.h:46
const std::array< Jc_t, NUM_CONTACTPOINTS > & AllJc() const
Get all of the contact Jacobians: Jc.
Definition: OperationalModelBase.h:65
jacobian_class_ptr_t jacobianPtr_
Definition: OperationalModelBase.h:102
std::array< Jc_t, NUM_CONTACTPOINTS > AllJc_
Definition: OperationalModelBase.h:112
RBDState< NUM_JOINTS > state_t
Definition: OperationalModelBase.h:41
Eigen::Matrix< double, NUM_OUTPUTS, 1 > C_t
Definition: OperationalModelBase.h:43
CoordinateBase< NUM_OUTPUTS, NUM_JOINTS >::ptr coordinate_class_ptr_t
Definition: OperationalModelBase.h:34
coordinate_vector_t toCoordinateVelocity() const
Definition: RBDState.h:144
const M_t & M() const
Get the inertia matrix: M.
Definition: OperationalModelBase.h:55
std::shared_ptr< OperationalModelBase< NUM_OUTPUTS, NUM_JOINTS, NUM_CONTACTPOINTS > > ptr
Definition: OperationalModelBase.h:32