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/rnea-second-order-derivatives.hpp" 10 #include "pinocchio/algorithm/aba-derivatives.hpp" 11 #include "pinocchio/algorithm/aba.hpp" 12 #include "pinocchio/algorithm/rnea.hpp" 13 #include "pinocchio/algorithm/crba.hpp" 14 #include "pinocchio/algorithm/cholesky.hpp" 15 #include "pinocchio/parsers/urdf.hpp" 16 #include "pinocchio/parsers/sample-models.hpp" 17 #include "pinocchio/container/aligned-vector.hpp" 21 #include "pinocchio/utils/timer.hpp" 23 template<
typename Matrix1,
typename Matrix2,
typename Matrix3>
28 const Eigen::MatrixBase<Matrix1> & _drnea_dq,
29 const Eigen::MatrixBase<Matrix2> & _drnea_dv,
30 const Eigen::MatrixBase<Matrix3> & _drnea_da)
36 using namespace Eigen;
40 const double alpha = 1e-8;
45 for(
int k = 0; k < model.
nv; ++k)
49 tau_plus =
rnea(model,data_fd,q_plus,v,a);
51 drnea_dq.col(k) = (tau_plus - tau0)/alpha;
57 for(
int k = 0; k < model.
nv; ++k)
60 tau_plus =
rnea(model,data_fd,q,v_plus,a);
62 drnea_dv.col(k) = (tau_plus - tau0)/alpha;
67 drnea_da =
crba(model,data_fd,q);
68 drnea_da.template triangularView<Eigen::StrictlyLower>()
69 = drnea_da.transpose().template triangularView<Eigen::StrictlyLower>();
77 Eigen::MatrixXd & daba_dq,
78 Eigen::MatrixXd & daba_dv,
81 using namespace Eigen;
85 const double alpha = 1e-8;
90 for(
int k = 0; k < model.
nv; ++k)
94 a_plus =
aba(model,data_fd,q_plus,v,tau);
96 daba_dq.col(k) = (a_plus -
a0)/alpha;
102 for(
int k = 0; k < model.
nv; ++k)
105 a_plus =
aba(model,data_fd,q,v_plus,tau);
107 daba_dv.col(k) = (a_plus -
a0)/alpha;
115 int main(
int argc,
const char ** argv)
117 using namespace Eigen;
122 const int NBT = 1000*100;
125 std::cout <<
"(the time score in debug mode is not relevant) " << std::endl;
131 if(argc>1) filename = argv[1];
136 const std::string ff_option = argv[2];
137 if(ff_option ==
"-no-ff")
141 if( filename ==
"HS")
149 std::cout <<
"nq = " << model.
nq << std::endl;
150 std::cout <<
"nv = " << model.
nv << std::endl;
153 VectorXd qmax = Eigen::VectorXd::Ones(model.
nq);
160 for(
size_t i=0;
i<NBT;++
i)
163 qdots[
i] = Eigen::VectorXd::Random(model.
nv);
164 qddots[
i] = Eigen::VectorXd::Random(model.
nv);
165 taus[
i] = Eigen::VectorXd::Random(model.
nv);
170 MatrixXd drnea_da(MatrixXd::Zero(model.
nv,model.
nv));
172 MatrixXd daba_dq(MatrixXd::Zero(model.
nv,model.
nv));
173 MatrixXd daba_dv(MatrixXd::Zero(model.
nv,model.
nv));
178 Tensor3x dtau2_dq(model.
nv, model.
nv, model.
nv);
179 Tensor3x dtau2_dv(model.
nv, model.
nv, model.
nv);
180 Tensor3x dtau2_dqv(model.
nv, model.
nv, model.
nv);
181 Tensor3x dtau_dadq(model.
nv, model.
nv, model.
nv);
192 std::cout <<
"FK= \t\t"; timer.
toc(std::cout,NBT);
199 std::cout <<
"FK derivatives= \t\t"; timer.
toc(std::cout,NBT);
204 rnea(model,data,
qs[_smooth],qdots[_smooth],qddots[_smooth]);
206 std::cout <<
"RNEA= \t\t"; timer.
toc(std::cout,NBT);
212 drnea_dq,drnea_dv,drnea_da);
214 std::cout <<
"RNEA derivatives= \t\t"; timer.
toc(std::cout,NBT);
219 qddots[_smooth], dtau2_dq, dtau2_dv, dtau2_dqv,
222 std::cout <<
"RNEA derivatives SO= \t\t";
223 timer.
toc(std::cout, NBT);
228 rnea_fd(model,data,
qs[_smooth],qdots[_smooth],qddots[_smooth],
229 drnea_dq,drnea_dv,drnea_da);
231 std::cout <<
"RNEA finite differences= \t\t"; timer.
toc(std::cout,NBT/100);
236 aba(model,data,
qs[_smooth],qdots[_smooth],taus[_smooth]);
238 std::cout <<
"ABA= \t\t"; timer.
toc(std::cout,NBT);
244 daba_dq,daba_dv,daba_dtau);
246 std::cout <<
"ABA derivatives= \t\t"; timer.
toc(std::cout,NBT);
251 aba_fd(model,data,
qs[_smooth],qdots[_smooth],taus[_smooth],
252 daba_dq,daba_dv,daba_dtau);
254 std::cout <<
"ABA finite differences= \t\t"; timer.
toc(std::cout,NBT);
261 std::cout <<
"M.inverse() from ABA = \t\t"; timer.
toc(std::cout,NBT);
263 MatrixXd Minv(model.
nv,model.
nv); Minv.setZero();
267 crba(model,data,
qs[_smooth]);
271 std::cout <<
"Minv from Cholesky = \t\t"; timer.
toc(std::cout,NBT);
273 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...
void ComputeRNEASecondOrderDerivatives(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, const Tensor1 &d2tau_dqdq, const Tensor2 &d2tau_dvdv, const Tensor3 &dtau_dqdv, const Tensor4 &dtau_dadq)
Computes the Second-Order partial derivatives of the Recursive Newton Euler Algorithm w...
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.