unittest/center-of-mass-derivatives.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019-2021 CNRS INRIA
3 //
4 
10 
11 #include <boost/test/unit_test.hpp>
12 #include <boost/utility/binary.hpp>
13 
14 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
15 
16 BOOST_AUTO_TEST_CASE(test_kinematics_derivatives_vcom)
17 {
18  using namespace Eigen;
19  using namespace pinocchio;
20 
21  Model model;
23 
24  Data data_ref(model);
25 
26  model.lowerPositionLimit.head<3>().fill(-1.);
27  model.upperPositionLimit.head<3>().fill(1.);
28  VectorXd q = randomConfiguration(model);
29  VectorXd vq(VectorXd::Random(model.nv));
30  VectorXd aq(VectorXd::Random(model.nv));
31 
32  // Approximate dvcom_dq by finite diff.
33  centerOfMass(model, data_ref, q, vq);
34  const Eigen::Vector3d vcom0 = data_ref.vcom[0];
35  const double alpha = 1e-8;
36  Eigen::VectorXd dq = VectorXd::Zero(model.nv);
37  Data::Matrix3x dvcom_dqn(3, model.nv);
38 
39  for (int k = 0; k < model.nv; ++k)
40  {
41  dq[k] = alpha;
42  centerOfMass(model, data_ref, integrate(model, q, dq), vq);
43  dvcom_dqn.col(k) = (data_ref.vcom[0] - vcom0) / alpha;
44  dq[k] = 0;
45  }
46 
47  {
48  // Compute dvcom_dq using the algorithm
49  Data data(model);
50  Data::Matrix3x dvcom_dq = Data::Matrix3x::Zero(3, model.nv);
53 
54  // Check that algo result and finite-diff approx are similar.
55  BOOST_CHECK(dvcom_dq.isApprox(dvcom_dqn, sqrt(alpha)));
56  }
57 
58  {
59  // Compute dvcom_dq using the algorithm
60  Data data(model);
61  Data::Matrix3x dvcom_dq = Data::Matrix3x::Zero(3, model.nv);
64 
65  // Check that algo result and finite-diff approx are similar.
66  BOOST_CHECK(dvcom_dq.isApprox(dvcom_dqn, sqrt(alpha)));
67  }
68 }
69 
70 BOOST_AUTO_TEST_SUITE_END()
Eigen
pinocchio::DataTpl
Definition: context/generic.hpp:25
compute-all-terms.hpp
dcrba.aq
aq
Definition: dcrba.py:533
setup.data
data
Definition: cmake/cython/setup.in.py:48
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
anymal-simulation.model
model
Definition: anymal-simulation.py:8
center-of-mass.hpp
joint-configuration.hpp
reachable-workspace-with-collisions.alpha
float alpha
Definition: reachable-workspace-with-collisions.py:162
pinocchio::DataTpl::Matrix3x
Eigen::Matrix< Scalar, 3, Eigen::Dynamic, Options > Matrix3x
The 3d jacobian type (temporary)
Definition: multibody/data.hpp:94
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::getCenterOfMassVelocityDerivatives
void getCenterOfMassVelocityDerivatives(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< Matrix3xOut > &vcom_partial_dq)
Computes the partial derivatie of the center-of-mass velocity with respect to the joint configuration...
q
q
center-of-mass-derivatives.hpp
pinocchio::buildModels::humanoid
void humanoid(ModelTpl< Scalar, Options, JointCollectionTpl > &model, bool usingFF=true)
Create a 28-DOF kinematic chain of a floating humanoid robot.
fill
fill
dcrba.dq
dq
Definition: dcrba.py:459
sample-models.hpp
dcrba.vq
vq
Definition: dcrba.py:420
pinocchio::ModelTpl
Definition: context/generic.hpp:20
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(test_kinematics_derivatives_vcom)
Definition: unittest/center-of-mass-derivatives.cpp:16
pinocchio::computeAllTerms
void computeAllTerms(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType > &v)
Computes efficiently all the terms needed for dynamic simulation. It is equivalent to the call at the...
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27
pinocchio::centerOfMass
const DataTpl< Scalar, Options, JointCollectionTpl >::Vector3 & centerOfMass(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const bool computeSubtreeComs=true)
Computes the center of mass position of a given model according to a particular joint configuration....


pinocchio
Author(s):
autogenerated on Fri Nov 1 2024 02:41:39