|
7 | 7 |
|
8 | 8 | #include "pinocchio/algorithm/check.hpp" |
9 | 9 | #include "pinocchio/algorithm/kinematics.hpp" |
| 10 | +#include "pinocchio/algorithm/kinematics-derivatives.hpp" |
10 | 11 | #include "pinocchio/spatial/skew.hpp" |
11 | 12 | #include "pinocchio/spatial/symmetric3.hpp" |
12 | 13 |
|
@@ -557,6 +558,76 @@ namespace pinocchio |
557 | 558 |
|
558 | 559 | return data.potentialEnergyRegressor; |
559 | 560 | } |
| 561 | + |
| 562 | + template< |
| 563 | + typename Scalar, |
| 564 | + int Options, |
| 565 | + template<typename, int> |
| 566 | + class JointCollectionTpl, |
| 567 | + typename ConfigVectorType, |
| 568 | + typename TangentVectorType> |
| 569 | + std::pair< |
| 570 | + typename DataTpl<Scalar, Options, JointCollectionTpl>::MatrixXs, |
| 571 | + typename DataTpl<Scalar, Options, JointCollectionTpl>::MatrixXs> |
| 572 | + computeMomentumRegressor( |
| 573 | + const ModelTpl<Scalar, Options, JointCollectionTpl> & model, |
| 574 | + DataTpl<Scalar, Options, JointCollectionTpl> & data, |
| 575 | + const Eigen::MatrixBase<ConfigVectorType> & q, |
| 576 | + const Eigen::MatrixBase<TangentVectorType> & v) |
| 577 | + { |
| 578 | + typedef context::Data::Matrix6x Matrix6x; |
| 579 | + typedef context::Data::MatrixXs MatrixXs; |
| 580 | + |
| 581 | + // symbolic jacobian of the spatial kinetic energy |
| 582 | + auto spatialKineticEnergyJacobian = |
| 583 | + [](const Eigen::Vector3d & v, const Eigen::Vector3d & w) -> Eigen::Matrix<double, 6, 10> { |
| 584 | + Eigen::Matrix<double, 10, 6> jacobian; |
| 585 | + jacobian << v[0], v[1], v[2], 0, 0, 0, 0, w[2], -w[1], 0, -v[2], v[1], -w[2], 0, w[0], v[2], |
| 586 | + 0, -v[0], w[1], -w[0], 0, -v[1], v[0], 0, 0, 0, 0, w[0], 0, 0, 0, 0, 0, w[1], w[0], 0, 0, 0, |
| 587 | + 0, 0, w[1], 0, 0, 0, 0, w[2], 0, w[0], 0, 0, 0, 0, w[2], w[1], 0, 0, 0, 0, 0, w[2]; |
| 588 | + |
| 589 | + return jacobian.transpose(); |
| 590 | + }; |
| 591 | + |
| 592 | + // zero the regressors |
| 593 | + data.momentumRegressor.setZero(); |
| 594 | + data.dpartial_lagrangian_q.setZero(); |
| 595 | + |
| 596 | + auto zero_v = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>::Zero(model.nv); |
| 597 | + |
| 598 | + // first compute the momentum regressor with gravity terms included |
| 599 | + computeJointTorqueRegressor(model, data, q, zero_v, v); |
| 600 | + MatrixXs momentum_with_gravity = data.jointTorqueRegressor.eval(); |
| 601 | + |
| 602 | + // compute the gravity component of the regressor |
| 603 | + computeJointTorqueRegressor(model, data, q, zero_v, zero_v); |
| 604 | + MatrixXs gravity_regressor = data.jointTorqueRegressor.eval(); |
| 605 | + |
| 606 | + data.momentumRegressor = momentum_with_gravity - gravity_regressor; |
| 607 | + |
| 608 | + for (JointIndex joint_id = 1; joint_id < (JointIndex)model.njoints; ++joint_id) |
| 609 | + { |
| 610 | + |
| 611 | + Motion v_i = getVelocity(model, data, joint_id, LOCAL); |
| 612 | + |
| 613 | + Matrix6x partial_dq(Matrix6x::Zero(6, model.nv)); |
| 614 | + Matrix6x dvb_dv(Matrix6x::Zero(6, model.nv)); |
| 615 | + |
| 616 | + getJointVelocityDerivatives(model, data, joint_id, LOCAL, partial_dq, dvb_dv); |
| 617 | + |
| 618 | + // auto dvb_dv = velocity_derivatives.second; |
| 619 | + auto phik_dv = spatialKineticEnergyJacobian(v_i.linear(), v_i.angular()); |
| 620 | + |
| 621 | + auto phik_dv_joint = dvb_dv.transpose() * phik_dv; |
| 622 | + data.dpartial_lagrangian_q.middleCols((joint_id - 1) * 10, 10) = phik_dv_joint; |
| 623 | + } |
| 624 | + |
| 625 | + // Subtract the static regressor to get the final result |
| 626 | + data.dpartial_lagrangian_q -= gravity_regressor; |
| 627 | + |
| 628 | + return std::make_pair(data.momentumRegressor.eval(), data.dpartial_lagrangian_q.eval()); |
| 629 | + } |
| 630 | + |
560 | 631 | } // namespace pinocchio |
561 | 632 |
|
562 | 633 | #endif // ifndef __pinocchio_algorithm_regressor_hxx__ |
0 commit comments