codegen-crba.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 INRIA
3 //
4 
5 #include "pinocchio/codegen/cppadcg.hpp" // this file should be included first before all the others!
7 
11 
12 #include <iostream>
13 
14 int main(int argc, const char ** argv)
15 {
16  using namespace pinocchio;
17  using namespace Eigen;
18 
19  std::string filename =
21  + std::string("/example-robot-data/robots/ur_description/urdf/ur5_robot.urdf");
22  if (argc > 1)
23  filename = argv[1];
24 
25  std::cout << "Opening file: " << filename << std::endl;
26 
27  // Load the model
28  Model model;
30 
31  CodeGenCRBA<double> crba_code_gen(model);
32 
33  // Generate the lib if it does not exist and load it afterwards.
34  crba_code_gen.initLib();
35  crba_code_gen.compileAndLoadLib(PINOCCHIO_CXX_COMPILER);
36 
37  // Use it with a random configuration samples in the bounds of the joint limits
38  VectorXd q = randomConfiguration(model);
39  crba_code_gen.evalFunction(q);
40 
41  // Retrieve the result
42  MatrixXd & M = crba_code_gen.M;
43 
44  // And make it symmetric if needed
45  M.template triangularView<Eigen::StrictlyLower>() =
46  M.transpose().template triangularView<Eigen::StrictlyLower>();
47 
48  // You can check the result with the classic CRBA
49  Data data_check(model);
50  crba(model, data_check, q, Convention::WORLD);
51 
52  data_check.M.triangularView<Eigen::StrictlyLower>() =
53  data_check.M.transpose().triangularView<Eigen::StrictlyLower>();
54 
55  const MatrixXd & M_check = data_check.M;
56  if (M_check.isApprox(M))
57  {
58  std::cout << "Super! The two results are the same." << std::endl;
59  return 0;
60  }
61  else
62  {
63  std::cout << "Not Super! The results do not match." << std::endl;
64  return -1;
65  }
66 }
pinocchio::DataTpl::M
MatrixXs M
The joint space inertia matrix (a square matrix of dim model.nv).
Definition: multibody/data.hpp:199
pinocchio::CodeGenBase::initLib
void initLib()
Definition: code-generator-base.hpp:78
Eigen
pinocchio::CodeGenCRBA::M
MatrixXs M
Definition: code-generator-algo.hpp:341
pinocchio::DataTpl
Definition: context/generic.hpp:25
cppadcg.hpp
main
int main(int argc, const char **argv)
Definition: codegen-crba.cpp:14
pinocchio::Convention::WORLD
@ WORLD
code-generator-algo.hpp
pinocchio::crba
const DataTpl< Scalar, Options, JointCollectionTpl >::MatrixXs & crba(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Convention convention=Convention::LOCAL)
Computes the upper triangular part of the joint space inertia matrix M by using the Composite Rigid B...
pinocchio::randomConfiguration
void randomConfiguration(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorIn1 > &lowerLimits, const Eigen::MatrixBase< ConfigVectorIn2 > &upperLimits, const Eigen::MatrixBase< ReturnType > &qout)
Generate a configuration vector uniformly sampled among provided limits.
Definition: joint-configuration.hpp:315
joint-configuration.hpp
filename
filename
urdf.hpp
pinocchio::urdf::buildModel
ModelTpl< Scalar, Options, JointCollectionTpl > & buildModel(const std::string &filename, const typename ModelTpl< Scalar, Options, JointCollectionTpl >::JointModel &rootJoint, const std::string &rootJointName, ModelTpl< Scalar, Options, JointCollectionTpl > &model, const bool verbose=false)
Build the model from a URDF file with a particular joint as root of the model tree inside the model g...
M
M
pinocchio::CodeGenCRBA
Definition: code-generator-algo.hpp:262
pinocchio::q
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > & q
Definition: joint-configuration.hpp:1083
pinocchio::CodeGenBase::compileAndLoadLib
void compileAndLoadLib(const std::string &gcc_path)
Definition: code-generator-base.hpp:117
pinocchio::CodeGenCRBA::evalFunction
void evalFunction(const Eigen::MatrixBase< ConfigVectorType > &q)
Definition: code-generator-algo.hpp:319
pinocchio::ModelTpl
Definition: context/generic.hpp:20
crba.hpp
pinocchio::model
JointCollectionTpl & model
Definition: joint-configuration.hpp:1082
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27
PINOCCHIO_MODEL_DIR
#define PINOCCHIO_MODEL_DIR
Definition: build-reduced-model.cpp:11


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