integrate-derivatives.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019-2020 INRIA
3 //
4 
7 
13 
15 
16 #include <casadi/casadi.hpp>
17 
18 #include <iostream>
19 #include <boost/test/unit_test.hpp>
20 #include <boost/utility/binary.hpp>
21 
22 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
23 
24 BOOST_AUTO_TEST_CASE(test_integrate)
25 {
26  typedef double Scalar;
27  typedef casadi::SX ADScalar;
28 
30  typedef Model::Data Data;
31 
32  typedef pinocchio::ModelTpl<ADScalar> ADModel;
33  typedef ADModel::Data ADData;
34 
35  Model model;
37  model.lowerPositionLimit.head<3>().fill(-1.);
38  model.upperPositionLimit.head<3>().fill(1.);
39  Data data(model);
40 
41  typedef Model::ConfigVectorType ConfigVector;
42  typedef Model::TangentVectorType TangentVector;
43  ConfigVector q(model.nq);
45  TangentVector v(TangentVector::Random(model.nv));
46  TangentVector a(TangentVector::Random(model.nv));
47 
48  typedef ADModel::ConfigVectorType ConfigVectorAD;
49  ADModel ad_model = model.cast<ADScalar>();
50  ADData ad_data(ad_model);
51 
53 
54  casadi::SX cs_q = casadi::SX::sym("q", model.nq);
55  casadi::SX cs_v_int = casadi::SX::sym("v_inc", model.nv);
56 
57  ConfigVectorAD q_ad(model.nq), v_int_ad(model.nv), q_int_ad(model.nq);
58  q_ad = Eigen::Map<ConfigVectorAD>(static_cast<std::vector<ADScalar>>(cs_q).data(), model.nq, 1);
59  v_int_ad =
60  Eigen::Map<ConfigVectorAD>(static_cast<std::vector<ADScalar>>(cs_v_int).data(), model.nv, 1);
61 
62  pinocchio::integrate(ad_model, q_ad, v_int_ad, q_int_ad);
63  casadi::SX cs_q_int(model.nq, 1);
64  pinocchio::casadi::copy(q_int_ad, cs_q_int);
65 
66  casadi::Function eval_integrate(
67  "eval_integrate", casadi::SXVector{cs_q, cs_v_int}, casadi::SXVector{cs_q_int});
68  std::vector<double> q_vec((size_t)model.nq);
69  Eigen::Map<ConfigVector>(q_vec.data(), model.nq, 1) = q;
70 
71  std::vector<double> v_int_vec((size_t)model.nv);
72  Eigen::Map<TangentVector>(v_int_vec.data(), model.nv, 1).setZero();
73  casadi::DM q_int_res = eval_integrate(casadi::DMVector{q_vec, v_int_vec})[0];
74 
75  Data::ConfigVectorType q_int_vec = Eigen::Map<Data::TangentVectorType>(
76  static_cast<std::vector<double>>(q_int_res).data(), model.nq, 1);
77 
78  ConfigVector q_plus(model.nq);
79  pinocchio::integrate(model, q, TangentVector::Zero(model.nv), q_plus);
80 
81  BOOST_CHECK(q_plus.isApprox(q_int_vec));
82 }
83 
84 BOOST_AUTO_TEST_SUITE_END()
pinocchio.casadi::sym
void sym(const Eigen::MatrixBase< MatrixDerived > &eig_mat, std::string const &name)
Definition: autodiff/casadi.hpp:230
rnea-derivatives.hpp
setup.data
data
Definition: cmake/cython/setup.in.py:48
pinocchio::python::Scalar
context::Scalar Scalar
Definition: admm-solver.cpp:29
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::context::Model
ModelTpl< Scalar, Options > Model
Definition: bindings/python/context/generic.hpp:63
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
rnea.hpp
aba-derivatives.hpp
casadi-algo.hpp
aba.hpp
anymal-simulation.model
model
Definition: anymal-simulation.py:8
joint-configuration.hpp
pinocchio::integrate
void integrate(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType > &v, const Eigen::MatrixBase< ReturnType > &qout)
Integrate a configuration vector for the specified model for a tangent vector during one unit time.
Definition: joint-configuration.hpp:70
pinocchio::python::context::Data
DataTpl< Scalar, Options > Data
Definition: bindings/python/context/generic.hpp:64
cartpole.v
v
Definition: cartpole.py:153
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(test_integrate)
Definition: integrate-derivatives.cpp:24
q
q
a
Vec3f a
fill
fill
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...
pinocchio.casadi::copy
void copy(::casadi::Matrix< Scalar > const &src, Eigen::MatrixBase< MT > &dst)
Definition: autodiff/casadi.hpp:154
casadi.hpp
sample-models.hpp
pinocchio::ModelTpl
Definition: context/generic.hpp:20


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