unittest/cppadcg/contact-dynamics.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2021 INRIA
3 //
4 
10 
11 #include <boost/test/unit_test.hpp>
12 #include <boost/utility/binary.hpp>
13 
14 using namespace pinocchio;
15 
16 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
17 
18 BOOST_AUTO_TEST_CASE(test_constraint_dynamics_code_generation)
19 {
20  typedef double Scalar;
21  typedef CppAD::cg::CG<Scalar> CGScalar;
22  typedef CppAD::AD<CGScalar> ADScalar;
23 
24  typedef Eigen::Matrix<ADScalar, Eigen::Dynamic, 1> ADVector;
25 
27  typedef Model::Data Data;
28 
29  typedef pinocchio::ModelTpl<ADScalar> ADModel;
30  typedef ADModel::Data ADData;
31 
32  Model model;
34  model.lowerPositionLimit.head<3>().fill(-1.);
35  model.upperPositionLimit.head<3>().fill(1.);
36  Data data(model);
37 
38  const std::string RF = "rleg6_joint";
39  const std::string LF = "lleg6_joint";
40 
43 
44  RigidConstraintModel ci_RF(CONTACT_6D, model.getJointId(RF), LOCAL);
45  contact_models_6D3D.push_back(ci_RF);
46  contact_datas_6D3D.push_back(RigidConstraintData(ci_RF));
47  RigidConstraintModel ci_LF(CONTACT_3D, model.getJointId(LF), LOCAL);
48  contact_models_6D3D.push_back(ci_LF);
49  contact_datas_6D3D.push_back(RigidConstraintData(ci_LF));
50 
51  Eigen::VectorXd q = Eigen::VectorXd::Random(model.nq);
52  Eigen::VectorXd v = Eigen::VectorXd::Random(model.nv);
53  Eigen::VectorXd tau = Eigen::VectorXd::Random(model.nv);
54  std::vector<Eigen::VectorXd> results_q(2, Eigen::VectorXd::Zero(model.nq));
55  std::vector<Eigen::VectorXd> results_v(2, Eigen::VectorXd::Zero(model.nv));
56 
57  CodeGenConstraintDynamics<double> cg_constraintDynamics(model, contact_models_6D3D);
58  cg_constraintDynamics.initLib();
59  cg_constraintDynamics.loadLib();
60  cg_constraintDynamics.evalFunction(q, v, tau);
61 
62  pinocchio::initConstraintDynamics(model, data, contact_models_6D3D);
64  model, data, q, v, tau, contact_models_6D3D, contact_datas_6D3D, 0.);
65  BOOST_CHECK(data.ddq.isApprox(cg_constraintDynamics.ddq));
66  BOOST_CHECK(data.lambda_c.isApprox(cg_constraintDynamics.lambda_c));
67 }
68 
69 BOOST_AUTO_TEST_SUITE_END()
pinocchio::RigidConstraintData
RigidConstraintDataTpl< context::Scalar, context::Options > RigidConstraintData
Definition: algorithm/fwd.hpp:27
pinocchio::CodeGenBase::initLib
void initLib()
Definition: code-generator-base.hpp:78
pinocchio::DataTpl
Definition: context/generic.hpp:25
cppadcg.hpp
code-generator-algo.hpp
model.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::CodeGenConstraintDynamics::evalFunction
void evalFunction(const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVector1 > &v, const Eigen::MatrixBase< TangentVector2 > &tau)
Definition: code-generator-algo.hpp:991
pinocchio::CONTACT_6D
@ CONTACT_6D
Point contact model.
Definition: algorithm/contact-info.hpp:22
forward-dynamics-derivatives.tau
tau
Definition: forward-dynamics-derivatives.py:25
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(test_constraint_dynamics_code_generation)
Definition: unittest/cppadcg/contact-dynamics.cpp:18
pinocchio::CodeGenConstraintDynamics
Definition: code-generator-algo.hpp:873
pinocchio::CodeGenBase::loadLib
void loadLib(const bool generate_if_not_exist=true, const std::string &gcc_path="/usr/bin/gcc", const std::string &compile_options="-Ofast")
Definition: code-generator-base.hpp:123
pinocchio::RigidConstraintModelTpl
Definition: algorithm/constraints/fwd.hpp:14
pinocchio::python::context::Data
DataTpl< Scalar, Options > Data
Definition: bindings/python/context/generic.hpp:64
pinocchio::Data
DataTpl< context::Scalar, context::Options > Data
Definition: multibody/fwd.hpp:34
pinocchio::RigidConstraintDataTpl
Definition: algorithm/constraints/fwd.hpp:16
pinocchio::initConstraintDynamics
void initConstraintDynamics(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const std::vector< RigidConstraintModelTpl< Scalar, Options >, Allocator > &contact_models)
Init the forward dynamics data according to the contact information contained in contact_models.
pinocchio::CodeGenConstraintDynamics::ddq
VectorXs ddq
Definition: code-generator-algo.hpp:1041
PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR
#define PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(T)
Definition: container/aligned-vector.hpp:13
pinocchio::q
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > & q
Definition: joint-configuration.hpp:1083
pinocchio::v
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > const Eigen::MatrixBase< TangentVectorType > & v
Definition: joint-configuration.hpp:1084
pinocchio::CodeGenConstraintDynamics::lambda_c
VectorXs lambda_c
Definition: code-generator-algo.hpp:1041
fill
fill
contact-dynamics.hpp
sample-models.hpp
pinocchio::ModelTpl
Definition: context/generic.hpp:20
pinocchio::CONTACT_3D
@ CONTACT_3D
Definition: algorithm/contact-info.hpp:21
pinocchio::constraintDynamics
const DataTpl< Scalar, Options, JointCollectionTpl >::TangentVectorType & constraintDynamics(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 std::vector< RigidConstraintModelTpl< Scalar, Options >, ConstraintModelAllocator > &contact_models, std::vector< RigidConstraintDataTpl< Scalar, Options >, ConstraintDataAllocator > &contact_datas, ProximalSettingsTpl< Scalar > &settings)
Computes the forward dynamics with contact constraints according to a given list of contact informati...
pinocchio::Model
ModelTpl< context::Scalar, context::Options > Model
Definition: multibody/fwd.hpp:33
pinocchio::model
JointCollectionTpl & model
Definition: joint-configuration.hpp:1082
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27
pinocchio::LOCAL
@ LOCAL
Definition: multibody/fwd.hpp:50


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