autodiff-rnea.cpp
Go to the documentation of this file.
2 
8 
9 using namespace CppAD;
10 
11 int main(void)
12 {
13  using CppAD::AD;
14  using namespace pinocchio;
15 
16  typedef ModelTpl<AD<double>> ADModel;
17  typedef DataTpl<AD<double>> ADData;
18  typedef Eigen::Matrix<AD<double>, Eigen::Dynamic, 1> ADVectorXs;
19 
20  Model model;
22  ADModel ad_model = model.cast<AD<double>>();
23  ADData ad_data(ad_model);
24 
25  int nq = ad_model.nq;
26  int nv = ad_model.nv;
27 
28  /***************************************************************************
29  * the model
30  **************************************************************************/
31  ADVectorXs ad_Q, ad_V, ad_A, ad_Y;
32 
33  ad_Q = ADVectorXs(nq);
34  ad_Q = pinocchio::neutral(ad_model);
35  ad_V = ADVectorXs(nv);
36  ad_V.setOnes();
37  ad_A = ADVectorXs(nv);
38  ad_A.setZero();
39 
40  // independent variable vector
41  Independent(ad_V);
42  ad_Y = pinocchio::rnea(ad_model, ad_data, ad_Q, ad_V, ad_A);
43  // the model tape
44  ADFun<double> fun(ad_V, ad_Y);
45 
46  Eigen::VectorXd dv = Eigen::VectorXd(nv);
47  dv.setOnes();
48  Eigen::VectorXd dtau_dv = fun.Jacobian(dv);
49 
50  /***************************************************************************
51  * comparison to analytical derivatives
52  **************************************************************************/
53  Data data(model);
54  Eigen::VectorXd Q(nq), V(nv), A(nv);
56  V.setOnes();
57  A.setZero();
59 
60  std::cout << "Analytical derivatives" << std::endl;
61  std::cout << data.dtau_dv << std::endl;
62  std::cout << "Automatic differentiation" << std::endl;
63  std::cout << dtau_dv.reshaped(nv, nv).transpose() << std::endl;
64 
65  if (data.dtau_dv.isApprox(dtau_dv.reshaped(nv, nv).transpose()))
66  {
67  std::cout << "Comparison from automatic differention to analytical derivatives succesful"
68  << std::endl;
69  }
70  else
71  {
72  std::cout << "Comparison from automatic differention to analytical derivatives NOT succesful"
73  << std::endl;
74  }
75 }
V
V
pinocchio::DataTpl
Definition: context/generic.hpp:25
autodiff-rnea.dv
dv
Definition: autodiff-rnea.py:27
rnea-derivatives.hpp
model.hpp
setup.data
data
Definition: cmake/cython/setup.in.py:48
pinocchio::buildModels::humanoidRandom
void humanoidRandom(ModelTpl< Scalar, Options, JointCollectionTpl > &model, bool usingFF=true)
Create a humanoid kinematic tree with 6-DOF limbs and random joint placements.
pinocchio::python::computeRNEADerivatives
bp::tuple computeRNEADerivatives(const context::Model &model, context::Data &data, const context::VectorXs &q, const context::VectorXs &v, const context::VectorXs &a)
Definition: expose-rnea-derivatives.cpp:38
CppAD
Definition: autodiff/cppad.hpp:146
rnea.hpp
anymal-simulation.model
model
Definition: anymal-simulation.py:8
codegen-rnea.nq
nq
Definition: codegen-rnea.py:18
joint-configuration.hpp
dcrba.Q
Q
Definition: dcrba.py:482
autodiff-rnea.dtau_dv
dtau_dv
Definition: autodiff-rnea.py:29
pinocchio::Dynamic
const int Dynamic
Definition: fwd.hpp:140
simulation-contact-dynamics.A
A
Definition: simulation-contact-dynamics.py:110
cppad.hpp
pinocchio::rnea
const DataTpl< Scalar, Options, JointCollectionTpl >::TangentVectorType & rnea(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 > &a)
The Recursive Newton-Euler algorithm. It computes the inverse dynamics, aka the joint torques accordi...
main
int main(void)
Definition: autodiff-rnea.cpp:11
codegen-rnea.nv
nv
Definition: codegen-rnea.py:19
pinocchio::neutral
void neutral(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ReturnType > &qout)
Return the neutral configuration element related to the model configuration space.
Definition: joint-configuration.hpp:363
sample-models.hpp
codegen-rnea.fun
fun
Definition: codegen-rnea.py:27
pinocchio::ModelTpl
Definition: context/generic.hpp:20
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


pinocchio
Author(s):
autogenerated on Thu Dec 19 2024 03:41:25