|
1 | 1 | // |
2 | | -// Copyright (c) 2015-2019 CNRS INRIA |
| 2 | +// Copyright (c) 2015-2020 CNRS INRIA |
3 | 3 | // |
4 | 4 |
|
5 | | -#ifndef __pinocchio_rnea_hxx__ |
6 | | -#define __pinocchio_rnea_hxx__ |
| 5 | +#ifndef __pinocchio_algorithm_rnea_hxx__ |
| 6 | +#define __pinocchio_algorithm_rnea_hxx__ |
7 | 7 |
|
8 | 8 | /// @cond DEV |
9 | 9 |
|
@@ -473,8 +473,8 @@ namespace pinocchio |
473 | 473 | { |
474 | 474 | typedef typename Model::JointIndex JointIndex; |
475 | 475 |
|
476 | | - const JointIndex & i = jmodel.id(); |
477 | | - const JointIndex & parent = model.parents[i]; |
| 476 | + const JointIndex i = jmodel.id(); |
| 477 | + const JointIndex parent = model.parents[i]; |
478 | 478 | typename Data::RowMatrix6 & M6tmpR = data.M6tmpR; |
479 | 479 |
|
480 | 480 | typedef typename SizeDepType<JointModel::NV>::template ColsReturn<typename Data::Matrix6x>::Type ColsBlock; |
@@ -543,9 +543,84 @@ namespace pinocchio |
543 | 543 |
|
544 | 544 | return data.C; |
545 | 545 | } |
| 546 | + |
| 547 | + template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl> |
| 548 | + struct GetCoriolisMatrixBackwardStep |
| 549 | + : public fusion::JointUnaryVisitorBase< GetCoriolisMatrixBackwardStep<Scalar,Options,JointCollectionTpl> > |
| 550 | + { |
| 551 | + typedef ModelTpl<Scalar,Options,JointCollectionTpl> Model; |
| 552 | + typedef DataTpl<Scalar,Options,JointCollectionTpl> Data; |
| 553 | + |
| 554 | + typedef boost::fusion::vector<const Model &, |
| 555 | + Data & |
| 556 | + > ArgsType; |
| 557 | + |
| 558 | + template<typename JointModel> |
| 559 | + static void algo(const JointModelBase<JointModel> & jmodel, |
| 560 | + const Model & model, |
| 561 | + Data & data) |
| 562 | + { |
| 563 | + typedef typename Model::JointIndex JointIndex; |
| 564 | + typedef CoriolisMatrixBackwardStep<Scalar,Options,JointCollectionTpl> EquivalentPass; |
| 565 | + |
| 566 | + const JointIndex i = jmodel.id(); |
| 567 | + const JointIndex parent = model.parents[i]; |
| 568 | + typename Data::RowMatrix6 & M6tmpR = data.M6tmpR; |
| 569 | + |
| 570 | + typedef typename SizeDepType<JointModel::NV>::template ColsReturn<typename Data::Matrix6x>::Type ColsBlock; |
| 571 | + ColsBlock dJ_cols = jmodel.jointCols(data.dJ); |
| 572 | + ColsBlock J_cols = jmodel.jointCols(data.J); |
| 573 | + typename Data::Matrix6x & dFdv = data.Fcrb[0]; |
| 574 | + ColsBlock dFdv_cols = jmodel.jointCols(dFdv); |
| 575 | + |
| 576 | + motionSet::inertiaAction(data.oYcrb[i],dJ_cols,dFdv_cols); |
| 577 | + dFdv_cols.noalias() += data.vxI[i] * J_cols; |
| 578 | + |
| 579 | + data.C.block(jmodel.idx_v(),jmodel.idx_v(),jmodel.nv(),data.nvSubtree[i]).noalias() |
| 580 | + = J_cols.transpose() * dFdv.middleCols(jmodel.idx_v(),data.nvSubtree[i]); |
| 581 | + |
| 582 | + EquivalentPass::lhsInertiaMult(data.oYcrb[i],J_cols.transpose(),M6tmpR.topRows(jmodel.nv())); |
| 583 | + for(int j = data.parents_fromRow[(JointIndex)jmodel.idx_v()];j >= 0; j = data.parents_fromRow[(JointIndex)j]) |
| 584 | + data.C.middleRows(jmodel.idx_v(),jmodel.nv()).col(j).noalias() = M6tmpR.topRows(jmodel.nv()) * data.dJ.col(j); |
| 585 | + |
| 586 | + M6tmpR.topRows(jmodel.nv()).noalias() = J_cols.transpose() * data.vxI[i]; |
| 587 | + for(int j = data.parents_fromRow[(JointIndex)jmodel.idx_v()];j >= 0; j = data.parents_fromRow[(JointIndex)j]) |
| 588 | + data.C.middleRows(jmodel.idx_v(),jmodel.nv()).col(j).noalias() += M6tmpR.topRows(jmodel.nv()) * data.J.col(j); |
| 589 | + |
| 590 | + if(parent>0) |
| 591 | + { |
| 592 | + data.vxI[parent] += data.vxI[i]; |
| 593 | + } |
| 594 | + |
| 595 | + } |
| 596 | + }; |
| 597 | + |
| 598 | + template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl> |
| 599 | + inline const typename DataTpl<Scalar,Options,JointCollectionTpl>::MatrixXs & |
| 600 | + getCoriolisMatrix(const ModelTpl<Scalar,Options,JointCollectionTpl> & model, |
| 601 | + DataTpl<Scalar,Options,JointCollectionTpl> & data) |
| 602 | + { |
| 603 | + assert(model.check(data) && "data is not consistent with model."); |
| 604 | + |
| 605 | + typedef ModelTpl<Scalar,Options,JointCollectionTpl> Model; |
| 606 | + typedef typename Model::JointIndex JointIndex; |
| 607 | + |
| 608 | + for(JointIndex i=1; i<(JointIndex)model.njoints; ++i) |
| 609 | + { |
| 610 | + Inertia::vxi(data.ov[i],data.oinertias[i],data.vxI[i]); |
| 611 | + } |
| 612 | + |
| 613 | + typedef GetCoriolisMatrixBackwardStep<Scalar,Options,JointCollectionTpl> Pass2; |
| 614 | + for(JointIndex i=(JointIndex)(model.njoints-1); i>0; --i) |
| 615 | + { |
| 616 | + Pass2::run(model.joints[i],typename Pass2::ArgsType(model,data)); |
| 617 | + } |
| 618 | + |
| 619 | + return data.C; |
| 620 | + } |
546 | 621 |
|
547 | 622 | } // namespace pinocchio |
548 | 623 |
|
549 | 624 | /// @endcond |
550 | 625 |
|
551 | | -#endif // ifndef __pinocchio_rnea_hxx__ |
| 626 | +#endif // ifndef __pinocchio_algorithm_rnea_hxx__ |
0 commit comments