- 3.0.2 rigid body dynamics module.
OperationalModelRBD.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 
10 #include "OperationalModelBase.h"
11 
12 namespace ct {
13 namespace rbd {
14 namespace tpl {
15 
21 template <class RBDContainer, size_t NUM_CONTACTPOINTS, typename SCALAR = double>
23  : public OperationalModelBase<RBDContainer::NJOINTS + 6, RBDContainer::NJOINTS, NUM_CONTACTPOINTS>
24 {
25 public:
26  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
27 
28  typedef Eigen::Matrix<SCALAR, 3, 3> Matrix3s;
29  typedef Eigen::Matrix<SCALAR, 3, 1> Vector3s;
30 
31  enum
32  {
33  NUM_OUTPUTS = RBDContainer::NJOINTS + 6,
34  NUM_JOINTS = RBDContainer::NJOINTS,
35  };
36 
37  typedef std::shared_ptr<OperationalModelRBD<RBDContainer, NUM_CONTACTPOINTS>> ptr;
39  typedef typename Base::state_t state_t;
40 
41  OperationalModelRBD(const typename RBDContainer::Ptr_t& rbdContainerPtr,
42  const std::array<EndEffector<NUM_JOINTS>, NUM_CONTACTPOINTS>& endEffectorArray)
43  : rbdContainerPtr_(rbdContainerPtr), endEffectorArray_(endEffectorArray)
44  {
45  }
46 
52  void update(const state_t& state) override
53  {
54  Base::state_ = state;
55 
56  // rotation matrix
57  Matrix3s o_R_b = state.basePose().getRotationMatrix().toImplementation();
58 
59  // Mass matrix
60  Base::M_ = rbdContainerPtr_->jSim().update(state.jointPositions());
61  Base::MInverse_ = Base::M_.ldlt().solve(Eigen::MatrixXd::Identity(18, 18));
62 
63  rbdContainerPtr_->inverseDynamics().setJointStatus(state.jointPositions());
64  Eigen::Matrix<SCALAR, 6, 1> baseWrench;
65  Eigen::Matrix<SCALAR, 12, 1> jointForces;
66 
67  // centrifugal vector
68  Eigen::Matrix<SCALAR, 6, 1> trunkVel;
69  trunkVel << state.baseLocalAngularVelocity().toImplementation(), state.baseLinearVelocity().toImplementation();
70  rbdContainerPtr_->inverseDynamics().C_terms_fully_actuated(
71  baseWrench, jointForces, trunkVel, state.jointVelocities());
72  Base::C_ << baseWrench, jointForces;
73 
74  // gravity vector
75  rbdContainerPtr_->inverseDynamics().G_terms_fully_actuated(
76  baseWrench, jointForces, state.basePose().computeGravityB6D());
77  Base::G_ << baseWrench, jointForces;
78 
79  // Selection matrix
80  Base::S_ << Eigen::MatrixXd::Zero(12, 6), Eigen::MatrixXd::Identity(12, 12);
81 
82  // contact jacobians
83  for (size_t j = 0; j < NUM_CONTACTPOINTS; j++)
84  {
85  Vector3s b_r_f = rbdContainerPtr_->getEEPositionInBase(j, state.jointPositions()).toImplementation();
86  Eigen::Matrix<SCALAR, 3, NUM_JOINTS> b_J_f =
87  rbdContainerPtr_->getJacobianBaseEEbyId(j, state.jointPositions()).template bottomRows<3>();
88 
90  } // end of j loop
91  }
92 
93 private:
94  typename RBDContainer::Ptr_t rbdContainerPtr_;
95  std::array<EndEffector<NUM_JOINTS>, NUM_CONTACTPOINTS> endEffectorArray_;
96 };
97 
98 } // namespace tpl
99 
100 template <class RBDContainer, size_t NUM_CONTACTPOINTS>
102 
103 } // end of rbd namespace
104 } // end of os namespace
This is a class for expressing the RBD equations of an articulated robot as an operational model...
Definition: OperationalModelRBD.h:22
Eigen::Matrix< SCALAR, 3, 1 > Vector3s
Definition: OperationalModelRBD.h:29
Eigen::Matrix< SCALAR, 6, 1 > computeGravityB6D(const Vector3Tpl &gravityW=gravity3DW()) const
This methods returns the 6D gravity vector expressed in the Base frame.
Definition: RigidBodyPose.h:380
state_t state_
Definition: OperationalModelBase.h:105
RigidBodyPose_t & basePose()
get base pose
Definition: RBDState.h:67
OperationalModelRBD(const typename RBDContainer::Ptr_t &rbdContainerPtr, const std::array< EndEffector< NUM_JOINTS >, NUM_CONTACTPOINTS > &endEffectorArray)
Definition: OperationalModelRBD.h:41
JointState< NJOINTS, SCALAR >::JointPositionBlock jointPositions()
get joint positions
Definition: RBDState.h:99
~OperationalModelRBD()
Definition: OperationalModelRBD.h:47
S_t S_
Definition: OperationalModelBase.h:111
joint states and base states
Definition: RBDState.h:27
Definition: OperationalModelRBD.h:33
void update(const state_t &state) override
Definition: OperationalModelRBD.h:52
M_t MInverse_
Definition: OperationalModelBase.h:108
G_t G_
Definition: OperationalModelBase.h:110
M_t M_
Definition: OperationalModelBase.h:107
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef Eigen::Matrix< SCALAR, 3, 3 > Matrix3s
Definition: OperationalModelRBD.h:28
kindr::Velocity< SCALAR, 3 > & baseLinearVelocity()
get base linear velocity
Definition: RBDState.h:86
C_t C_
Definition: OperationalModelBase.h:109
OperationalModelBase< NUM_OUTPUTS, NUM_JOINTS, NUM_CONTACTPOINTS > Base
Definition: OperationalModelRBD.h:38
kindr::LocalAngularVelocity< SCALAR > & baseLocalAngularVelocity()
get base local angular velocity
Definition: RBDState.h:75
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
JointState< NJOINTS, SCALAR >::JointPositionBlock jointVelocities()
get joint velocities
Definition: RBDState.h:108
Definition: OperationalModelBase.h:29
kindr::RotationMatrix< SCALAR > getRotationMatrix() const
This method returns the rotation matrix from base to inertia frame. This method returns which is the...
Definition: RigidBodyPose.h:150
Definition: OperationalModelRBD.h:34
std::shared_ptr< OperationalModelRBD< RBDContainer, NUM_CONTACTPOINTS > > ptr
Definition: OperationalModelRBD.h:37
Definition: EndEffector.h:15
std::array< Jc_t, NUM_CONTACTPOINTS > AllJc_
Definition: OperationalModelBase.h:112
Base::state_t state_t
Definition: OperationalModelRBD.h:39