center-of-mass-derivatives.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019-2021 CNRS INRIA
3 //
4 
5 #include "pinocchio/algorithm/center-of-mass.hpp"
6 #include "pinocchio/algorithm/joint-configuration.hpp"
7 #include "pinocchio/algorithm/compute-all-terms.hpp"
8 #include "pinocchio/algorithm/center-of-mass-derivatives.hpp"
9 #include "pinocchio/parsers/sample-models.hpp"
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;
22  buildModels::humanoid(model);
23 
24  Data data_ref(model);
25 
26  model.lowerPositionLimit.head<3>().fill(-1.);
27  model.upperPositionLimit.head<3>().fill(1.);
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);
51  centerOfMass(model,data,q,vq);
52  getCenterOfMassVelocityDerivatives(model,data,dvcom_dq);
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);
62  computeAllTerms(model,data,q,vq);
63  getCenterOfMassVelocityDerivatives(model,data,dvcom_dq);
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()
BOOST_AUTO_TEST_CASE(test_kinematics_derivatives_vcom)
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...
q
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...
aq
Definition: dcrba.py:441
ConfigVectorType lowerPositionLimit
Lower joint configuration limit.
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...
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.
data
void humanoid(ModelTpl< Scalar, Options, JointCollectionTpl > &model, bool usingFF=true)
Create a 28-DOF kinematic chain of a floating humanoid robot.
dq
Definition: dcrba.py:385
vq
Definition: dcrba.py:353
Main pinocchio namespace.
Definition: timings.cpp:30
int nv
Dimension of the velocity vector space.
Eigen::Matrix< Scalar, 3, Eigen::Dynamic, Options > Matrix3x
The 3d jacobian type (temporary)
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...
ConfigVectorType upperPositionLimit
Upper joint configuration limit.
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > VectorXd
Definition: conversions.cpp:14
void fill(Eigen::Ref< MatType > mat, const typename MatType::Scalar &value)


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:02