codegen-rnea.cpp
Go to the documentation of this file.
2 
3 #include <iosfwd>
7 
8 using namespace CppAD;
9 using namespace CppAD::cg;
10 
11 int main(void)
12 {
13  // use a special object for source code generation
14  using CGD = CG<double>;
15  using ADCG = AD<CGD>;
16  using namespace pinocchio;
17 
18  typedef ModelTpl<ADCG> ADModel;
19  typedef DataTpl<ADCG> ADData;
20  typedef Eigen::Matrix<ADCG, Eigen::Dynamic, 1> ADVectorXs;
21 
22  Model model;
24  ADModel ad_model = model.cast<ADCG>();
25  ADData ad_data(ad_model);
26 
27  /***************************************************************************
28  * the model
29  **************************************************************************/
30 
31  // independent variable vector
32 
33  ADVectorXs ad_X, ad_Y;
34  ad_X = ADVectorXs(ad_model.nq + ad_model.nv);
35  ad_Y = ADVectorXs(ad_model.nv);
36  ADVectorXs zeros = ADVectorXs::Zero(ad_model.nv);
37  Independent(ad_X);
39  ad_model, ad_data, ad_X.head(ad_model.nq), ad_X.segment(ad_model.nq, ad_model.nv), zeros);
40  ad_Y = ad_data.tau;
41  ADFun<CGD> fun(ad_X, ad_Y); // the model tape
42 
43  /***************************************************************************
44  * Generate the C source code
45  **************************************************************************/
46 
50  CodeHandler<double> handler;
51  CppAD::vector<CGD> indVars(65);
52  handler.makeVariables(indVars);
53 
54  CppAD::vector<CGD> jac = fun.Jacobian(indVars);
55 
56  LanguageC<double> langC("double");
57  LangCDefaultVariableNameGenerator<double> nameGen;
58 
59  std::ostringstream code;
60  handler.generateCode(code, langC, jac, nameGen);
61  std::cout << code.str();
62 }
pinocchio::DataTpl
Definition: context/generic.hpp:25
cppadcg.hpp
codegen-rnea.jac
jac
Definition: codegen-rnea.py:41
model.hpp
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.
CppAD
Definition: autodiff/cppad.hpp:146
rnea.hpp
codegen-rnea.langC
langC
Definition: codegen-rnea.py:43
anymal-simulation.model
model
Definition: anymal-simulation.py:8
codegen-rnea.handler
handler
Definition: codegen-rnea.py:36
codegen-rnea.nameGen
nameGen
Definition: codegen-rnea.py:44
codegen-rnea.code
code
Definition: codegen-rnea.py:45
main
int main(void)
Definition: codegen-rnea.cpp:11
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...
sample-models.hpp
codegen-rnea.fun
fun
Definition: codegen-rnea.py:27
pinocchio::ModelTpl
Definition: context/generic.hpp:20
CppAD::cg
Definition: codegen/cppadcg.hpp:95
codegen-rnea.indVars
indVars
Definition: codegen-rnea.py:38
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


pinocchio
Author(s):
autogenerated on Sun Dec 22 2024 03:41:08