pinocchio_dynamics_solver_derivatives.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019, Wolfgang Merkt
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without specific
15 // prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 
31 
32 #include <pinocchio/algorithm/aba-derivatives.hpp>
33 #include <pinocchio/algorithm/joint-configuration.hpp>
34 
35 namespace exotica
36 {
38 {
40 
41  Eigen::Block<Eigen::MatrixXd> da_dx = fx_.block(num_velocities_, 0, num_velocities_, get_num_state_derivative());
42  Eigen::Block<Eigen::MatrixXd> da_du = fu_.block(num_velocities_, 0, num_velocities_, num_controls_);
43 
44  switch (integrator_)
45  {
46  // Forward Euler (RK1)
47  case Integrator::RK1:
48  {
49  Fx_.topRows(num_velocities_).setZero();
50  Fx_.bottomRows(num_velocities_).noalias() = dt_ * da_dx;
51  Fx_.topRightCorner(num_velocities_, num_velocities_).diagonal().array() += dt_;
54  Fx_.bottomRightCorner(num_velocities_, num_velocities_).diagonal().array() += 1.0;
55 
56  Fu_.topRows(num_velocities_).setZero();
57  Fu_.bottomRows(num_velocities_).noalias() = dt_ * da_du;
59  }
60  break;
61  // Semi-implicit Euler
62  case Integrator::SymplecticEuler:
63  {
64  Eigen::VectorXd dx_v = dt_ * x.tail(num_velocities_) + dt_ * dt_ * pinocchio_data_->ddq;
65 
66  Fx_.topRows(num_velocities_).noalias() = dt_ * dt_ * da_dx;
67  Fx_.bottomRows(num_velocities_).noalias() = dt_ * da_dx;
68  Fx_.topRightCorner(num_velocities_, num_velocities_).diagonal().array() += dt_;
71  Fx_.bottomRightCorner(num_velocities_, num_velocities_).diagonal().array() += 1.0;
72 
73  Fu_.topRows(num_velocities_).noalias() = dt_ * dt_ * da_du;
74  Fu_.bottomRows(num_velocities_).noalias() = dt_ * da_du;
76  }
77  break;
78  default:
79  ThrowPretty("Not implemented!");
80  };
81 }
82 
83 Eigen::MatrixXd PinocchioDynamicsSolver::fx(const StateVector& x, const ControlVector& u)
84 {
85  // Four quadrants should be: 0, Identity, ddq_dq, ddq_dv
86  // 0 and Identity are set during initialisation. Here, we pass references to ddq_dq, ddq_dv to the algorithm.
87  // pinocchio::computeABADerivatives(model_, *pinocchio_data_.get(), x.head(num_positions_), x.tail(num_velocities_), u, fx_.block(num_velocities_, 0, num_velocities_, num_velocities_), fx_.block(num_velocities_, num_velocities_, num_velocities_, num_velocities_), fu_.bottomRightCorner(num_velocities_, num_velocities_));
88 
89  // This causes redundant computations but this method is no longer called in solvers.
90  ComputeDerivatives(x, u);
91 
92  return fx_;
93 }
94 
95 Eigen::MatrixXd PinocchioDynamicsSolver::fu(const StateVector& x, const ControlVector& u)
96 {
97  // NB: ddq_dtau is computed with the same call - i.e., we are duplicating computation.
98  // pinocchio::computeABADerivatives(model_, *pinocchio_data_.get(), x.head(num_positions_), x.tail(num_velocities_), u, fx_.block(num_velocities_, 0, num_velocities_, num_velocities_), fx_.block(num_velocities_, num_velocities_, num_velocities_, num_velocities_), fu_.bottomRightCorner(num_velocities_, num_velocities_));
99 
100  // This causes redundant computations but this method is no longer called in solvers.
101  ComputeDerivatives(x, u);
102 
103  return fu_;
104 }
105 
106 } // namespace exotica
void ComputeDerivatives(const StateVector &x, const ControlVector &u) override
void dIntegrateTransport(const LieGroupGenericTpl< LieGroupCollection > &lg, const Eigen::MatrixBase< Config_t > &q, const Eigen::MatrixBase< Tangent_t > &v, const Eigen::MatrixBase< JacobianIn_t > &J_in, const Eigen::MatrixBase< JacobianOut_t > &J_out, const ArgumentPosition arg)
#define ThrowPretty(m)
ControlDerivative fu(const StateVector &x, const ControlVector &u) override
void dIntegrate(const LieGroupGenericTpl< LieGroupCollection > &lg, const Eigen::MatrixBase< Config_t > &q, const Eigen::MatrixBase< Tangent_t > &v, const Eigen::MatrixBase< JacobianOut_t > &J, const ArgumentPosition arg, const AssignmentOperatorType op=SETTO)
Eigen::Matrix< T, NU, 1 > ControlVector
StateDerivative fx(const StateVector &x, const ControlVector &u) override
std::unique_ptr< pinocchio::Data > pinocchio_data_
void computeABADerivatives(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType1 > &v, const Eigen::MatrixBase< TangentVectorType2 > &tau, const Eigen::MatrixBase< MatrixType1 > &aba_partial_dq, const Eigen::MatrixBase< MatrixType2 > &aba_partial_dv, const Eigen::MatrixBase< MatrixType3 > &aba_partial_dtau)
Eigen::Matrix< T, NX, 1 > StateVector


exotica_pinocchio_dynamics_solver
Author(s):
autogenerated on Sat Apr 10 2021 02:35:54