5 #include "pinocchio/algorithm/joint-configuration.hpp" 6 #include "pinocchio/algorithm/kinematics.hpp" 7 #include "pinocchio/algorithm/kinematics-derivatives.hpp" 8 #include "pinocchio/algorithm/rnea-derivatives.hpp" 9 #include "pinocchio/algorithm/aba-derivatives.hpp" 10 #include "pinocchio/algorithm/aba.hpp" 11 #include "pinocchio/algorithm/rnea.hpp" 12 #include "pinocchio/algorithm/crba.hpp" 13 #include "pinocchio/algorithm/cholesky.hpp" 14 #include "pinocchio/parsers/urdf.hpp" 15 #include "pinocchio/parsers/sample-models.hpp" 16 #include "pinocchio/container/aligned-vector.hpp" 20 #include "pinocchio/utils/timer.hpp" 22 template<
typename Matrix1,
typename Matrix2,
typename Matrix3>
27 const Eigen::MatrixBase<Matrix1> & _drnea_dq,
28 const Eigen::MatrixBase<Matrix2> & _drnea_dv,
29 const Eigen::MatrixBase<Matrix3> & _drnea_da)
35 using namespace Eigen;
39 const double alpha = 1e-8;
44 for(
int k = 0; k < model.
nv; ++k)
48 tau_plus =
rnea(model,data_fd,q_plus,v,a);
50 drnea_dq.col(k) = (tau_plus - tau0)/alpha;
56 for(
int k = 0; k < model.
nv; ++k)
59 tau_plus =
rnea(model,data_fd,q,v_plus,a);
61 drnea_dv.col(k) = (tau_plus - tau0)/alpha;
66 drnea_da =
crba(model,data_fd,q);
67 drnea_da.template triangularView<Eigen::StrictlyLower>()
68 = drnea_da.transpose().template triangularView<Eigen::StrictlyLower>();
76 Eigen::MatrixXd & daba_dq,
77 Eigen::MatrixXd & daba_dv,
80 using namespace Eigen;
84 const double alpha = 1e-8;
89 for(
int k = 0; k < model.
nv; ++k)
93 a_plus =
aba(model,data_fd,q_plus,v,tau);
95 daba_dq.col(k) = (a_plus - a0)/alpha;
101 for(
int k = 0; k < model.
nv; ++k)
104 a_plus =
aba(model,data_fd,q,v_plus,tau);
106 daba_dv.col(k) = (a_plus - a0)/alpha;
114 int main(
int argc,
const char ** argv)
116 using namespace Eigen;
121 const int NBT = 1000*100;
124 std::cout <<
"(the time score in debug mode is not relevant) " << std::endl;
130 if(argc>1) filename = argv[1];
135 const std::string ff_option = argv[2];
136 if(ff_option ==
"-no-ff")
140 if( filename ==
"HS")
148 std::cout <<
"nq = " << model.
nq << std::endl;
149 std::cout <<
"nv = " << model.
nv << std::endl;
152 VectorXd qmax = Eigen::VectorXd::Ones(model.
nq);
159 for(
size_t i=0;
i<NBT;++
i)
162 qdots[
i] = Eigen::VectorXd::Random(model.
nv);
163 qddots[
i] = Eigen::VectorXd::Random(model.
nv);
164 taus[
i] = Eigen::VectorXd::Random(model.
nv);
169 MatrixXd drnea_da(MatrixXd::Zero(model.
nv,model.
nv));
171 MatrixXd daba_dq(MatrixXd::Zero(model.
nv,model.
nv));
172 MatrixXd daba_dv(MatrixXd::Zero(model.
nv,model.
nv));
180 std::cout <<
"FK= \t\t"; timer.
toc(std::cout,NBT);
187 std::cout <<
"FK derivatives= \t\t"; timer.
toc(std::cout,NBT);
192 rnea(model,data,qs[_smooth],qdots[_smooth],qddots[_smooth]);
194 std::cout <<
"RNEA= \t\t"; timer.
toc(std::cout,NBT);
200 drnea_dq,drnea_dv,drnea_da);
202 std::cout <<
"RNEA derivatives= \t\t"; timer.
toc(std::cout,NBT);
207 rnea_fd(model,data,qs[_smooth],qdots[_smooth],qddots[_smooth],
208 drnea_dq,drnea_dv,drnea_da);
210 std::cout <<
"RNEA finite differences= \t\t"; timer.
toc(std::cout,NBT/100);
215 aba(model,data,qs[_smooth],qdots[_smooth],taus[_smooth]);
217 std::cout <<
"ABA= \t\t"; timer.
toc(std::cout,NBT);
223 daba_dq,daba_dv,daba_dtau);
225 std::cout <<
"ABA derivatives= \t\t"; timer.
toc(std::cout,NBT);
230 aba_fd(model,data,qs[_smooth],qdots[_smooth],taus[_smooth],
231 daba_dq,daba_dv,daba_dtau);
233 std::cout <<
"ABA finite differences= \t\t"; timer.
toc(std::cout,NBT);
240 std::cout <<
"M.inverse() from ABA = \t\t"; timer.
toc(std::cout,NBT);
242 MatrixXd Minv(model.
nv,model.
nv); Minv.setZero();
246 crba(model,data,qs[_smooth]);
250 std::cout <<
"Minv from Cholesky = \t\t"; timer.
toc(std::cout,NBT);
252 std::cout <<
"--" << std::endl;
const DataTpl< Scalar, Options, JointCollectionTpl >::TangentVectorType & aba(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)
The Articulated-Body algorithm. It computes the forward dynamics, aka the joint accelerations given t...
const DataTpl< Scalar, Options, JointCollectionTpl >::MatrixXs & crba(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q)
Computes the upper triangular part of the joint space inertia matrix M by using the Composite Rigid B...
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor|Options > RowMatrixXs
Mat & computeMinv(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< Mat > &Minv)
Computes the inverse of the joint space inertia matrix M from its Cholesky factorization.
const DataTpl< Scalar, Options, JointCollectionTpl >::RowMatrixXs & computeMinverse(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q)
Computes the inverse of the joint space inertia matrix using Articulated Body formulation.
void rnea(const int num_threads, ModelPoolTpl< Scalar, Options, JointCollectionTpl > &pool, const Eigen::MatrixBase< ConfigVectorPool > &q, const Eigen::MatrixBase< TangentVectorPool1 > &v, const Eigen::MatrixBase< TangentVectorPool2 > &a, const Eigen::MatrixBase< TangentVectorPool3 > &tau)
The Recursive Newton-Euler algorithm. It computes the inverse dynamics, aka the joint torques accordi...
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...
const DataTpl< Scalar, Options, JointCollectionTpl >::MatrixXs & decompose(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data)
Compute the Cholesky decomposition of the joint space inertia matrix M contained in data...
int main(int argc, const char **argv)
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.
#define PINOCCHIO_MODEL_DIR
#define PINOCCHIO_EIGEN_CONST_CAST(TYPE, OBJ)
Macro for an automatic const_cast.
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.
bp::tuple computeRNEADerivatives(const Model &model, Data &data, const Eigen::VectorXd &q, const Eigen::VectorXd &v, const Eigen::VectorXd &a)
#define PINOCCHIO_ALIGNED_STD_VECTOR(Type)
void computeForwardKinematicsDerivatives(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)
Computes all the terms required to compute the derivatives of the placement, spatial velocity and acc...
ModelTpl< Scalar, Options, JointCollectionTpl > & buildModel(const std::string &filename, const typename ModelTpl< Scalar, Options, JointCollectionTpl >::JointModel &rootJoint, ModelTpl< Scalar, Options, JointCollectionTpl > &model, const bool verbose=false)
Build the model from a URDF file with a particular joint as root of the model tree inside the model g...
void aba_fd(const pinocchio::Model &model, pinocchio::Data &data_fd, const Eigen::VectorXd &q, const Eigen::VectorXd &v, const Eigen::VectorXd &tau, Eigen::MatrixXd &daba_dq, Eigen::MatrixXd &daba_dv, pinocchio::Data::RowMatrixXs &daba_dtau)
Main pinocchio namespace.
#define PINOCCHIO_EIGEN_PLAIN_ROW_MAJOR_TYPE(D)
Similar to macro PINOCCHIO_EIGEN_PLAIN_TYPE but with guaranty to provite a row major type...
int nv
Dimension of the velocity vector space.
void rnea_fd(const pinocchio::Model &model, pinocchio::Data &data_fd, const Eigen::VectorXd &q, const Eigen::VectorXd &v, const Eigen::VectorXd &a, const Eigen::MatrixBase< Matrix1 > &_drnea_dq, const Eigen::MatrixBase< Matrix2 > &_drnea_dv, const Eigen::MatrixBase< Matrix3 > &_drnea_da)
JointModelFreeFlyerTpl< double > JointModelFreeFlyer
void computeABADerivatives(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 Eigen::MatrixBase< MatrixType1 > &aba_partial_dq, const Eigen::MatrixBase< MatrixType2 > &aba_partial_dv, const Eigen::MatrixBase< MatrixType3 > &aba_partial_dtau)
The derivatives of the Articulated-Body algorithm.
void humanoidRandom(ModelTpl< Scalar, Options, JointCollectionTpl > &model, bool usingFF=true)
Create a humanoid kinematic tree with 6-DOF limbs and random joint placements.
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > VectorXd
int nq
Dimension of the configuration vector representation.