Go to the documentation of this file.
14 #include <boost/test/unit_test.hpp>
15 #include <boost/utility/binary.hpp>
16 #include <boost/test/tools/floating_point_comparison.hpp>
18 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
22 using namespace Eigen;
29 const VectorXd qmax = VectorXd::Ones(
model.nq);
31 VectorXd
v = VectorXd::Random(
model.nv);
34 data.M.triangularView<Eigen::StrictlyLower>() =
35 data.M.transpose().triangularView<Eigen::StrictlyLower>();
37 double kinetic_energy_ref = 0.5 *
v.transpose() *
data.M *
v;
40 BOOST_CHECK_SMALL(kinetic_energy_ref - kinetic_energy, 1e-12);
45 using namespace Eigen;
54 const VectorXd qmax = VectorXd::Ones(
model.nq);
56 VectorXd
v = VectorXd::Random(
model.nv);
59 data_ref.
M.triangularView<Eigen::StrictlyLower>() =
60 data_ref.
M.transpose().triangularView<Eigen::StrictlyLower>();
62 double kinetic_energy_ref = 0.5 *
v.transpose() * data_ref.
M *
v;
66 kinetic_energy_ref - kinetic_energy, Eigen::NumTraits<double>::dummy_precision());
71 using namespace Eigen;
78 const VectorXd qmax = VectorXd::Ones(
model.nq);
84 double potential_energy_ref = -data_ref.
mass[0] * (data_ref.com[0].dot(
model.gravity.linear()));
87 potential_energy_ref - potential_energy, Eigen::NumTraits<double>::dummy_precision());
92 using namespace Eigen;
99 const VectorXd qmax = VectorXd::Ones(
model.nq);
101 VectorXd
v = VectorXd::Random(
model.nv);
110 mechanical_energy_ref - mechanical_energy, Eigen::NumTraits<double>::dummy_precision());
113 template<
typename ConfigVectorType,
typename TangentVectorType>
116 const Eigen::MatrixBase<ConfigVectorType> & q,
117 const Eigen::MatrixBase<TangentVectorType> &
v)
121 data.M.triangularView<Eigen::StrictlyLower>() =
122 data.M.transpose().triangularView<Eigen::StrictlyLower>();
128 using namespace Eigen;
133 model.armature = VectorXd::Random(
model.nv) + VectorXd::Ones(
model.nv);
139 const VectorXd qmax = VectorXd::Ones(
model.nq);
141 VectorXd
v = VectorXd::Random(
model.nv);
142 VectorXd
a = VectorXd::Random(
model.nv);
144 const VectorXd tau_ref =
rnea(
model, data_ref,
q,
v,
a);
145 VectorXd tau_fd = VectorXd::Zero(
model.nv);
147 const double eps = 1e-8;
149 const double mechanical_energy =
data.kinetic_energy -
data.potential_energy;
153 for (Eigen::DenseIndex k = 0; k <
model.nv; ++k)
158 const SE3 oM1_plus = data_plus.oMi[1];
159 const SE3 Mdiff = oM1.actInv(oM1_plus);
163 f.toVector()[k] = mechanical_energy;
164 Force f_plus = Force::Zero();
165 f_plus.toVector()[k] = mechanical_energy_plus;
166 tau_fd.head<6>() -= (Mdiff.act(f_plus) -
f).toVector() /
eps;
170 tau_fd[k] = -(mechanical_energy_plus - mechanical_energy) /
eps;
176 const VectorXd v_plus =
v +
a *
eps;
180 const SE3 oM1_plus =
data.oMi[1];
181 const SE3 Mdiff = oM1.actInv(oM1_plus);
183 Mdiff.act(
Force(Mv_plus.head<6>()))
186 tau_fd += (Mv_plus -
Mv) /
eps;
187 std::cout <<
"tau_fd: " << tau_fd.transpose() << std::endl;
188 std::cout <<
"tau_ref: " << tau_ref.transpose() << std::endl;
190 BOOST_CHECK(tau_fd.isApprox(tau_ref, sqrt(
eps)));
193 BOOST_AUTO_TEST_SUITE_END()
MatrixXs M
The joint space inertia matrix (a square matrix of dim model.nv).
Scalar computePotentialEnergy(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data)
Computes the potential energy of the system, i.e. the potential energy linked to the gravity field....
std::vector< Scalar > mass
Vector of subtree mass. In other words, mass[j] is the mass of the subtree supported by joint ....
void forwardKinematics(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q)
Update the joint placements according to the current joint configuration.
Scalar kinetic_energy
Kinetic energy of the system.
void humanoidRandom(ModelTpl< Scalar, Options, JointCollectionTpl > &model, bool usingFF=true)
Create a humanoid kinematic tree with 6-DOF limbs and random joint placements.
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...
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.
Scalar potential_energy
Potential energy of the system.
Scalar computeMechanicalEnergy(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data)
Computes the mechanical energy of the system stored in data.mechanical_energy. The result is accessib...
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.
BOOST_AUTO_TEST_CASE(test_kinetic_energy)
void setZero(std::vector< MatType, Eigen::aligned_allocator< MatType > > &Ms)
Scalar computeKineticEnergy(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data)
Computes the kinetic energy of the system. The result is accessible through data.kinetic_energy.
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...
MatRes & Mv(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< Mat > &min, const Eigen::MatrixBase< MatRes > &mout)
Performs the multiplication by using the sparsity pattern of the M matrix.
Eigen::VectorXd evalMv(const pinocchio::Model &model, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType > &v)
Main pinocchio namespace.
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:43