| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////// | ||
| 2 | // BSD 3-Clause License | ||
| 3 | // | ||
| 4 | // Copyright (C) 2021-2025, LAAS-CNRS, University of Edinburgh | ||
| 5 | // Copyright note valid unless otherwise stated in individual files. | ||
| 6 | // All rights reserved. | ||
| 7 | /////////////////////////////////////////////////////////////////////////////// | ||
| 8 | |||
| 9 | namespace crocoddyl { | ||
| 10 | |||
| 11 | template <typename Scalar> | ||
| 12 | ✗ | ResidualModelFramePlacementTpl<Scalar>::ResidualModelFramePlacementTpl( | |
| 13 | std::shared_ptr<StateMultibody> state, const pinocchio::FrameIndex id, | ||
| 14 | const SE3& pref, const std::size_t nu) | ||
| 15 | : Base(state, 6, nu, true, false, false), | ||
| 16 | ✗ | id_(id), | |
| 17 | ✗ | pref_(pref), | |
| 18 | ✗ | oMf_inv_(pref.inverse()), | |
| 19 | ✗ | pin_model_(state->get_pinocchio()) { | |
| 20 | ✗ | if (static_cast<pinocchio::FrameIndex>(state->get_pinocchio()->nframes) <= | |
| 21 | id) { | ||
| 22 | ✗ | throw_pretty( | |
| 23 | "Invalid argument: " | ||
| 24 | << "the frame index is wrong (it does not exist in the robot)"); | ||
| 25 | } | ||
| 26 | ✗ | } | |
| 27 | |||
| 28 | template <typename Scalar> | ||
| 29 | ✗ | ResidualModelFramePlacementTpl<Scalar>::ResidualModelFramePlacementTpl( | |
| 30 | std::shared_ptr<StateMultibody> state, const pinocchio::FrameIndex id, | ||
| 31 | const SE3& pref) | ||
| 32 | : Base(state, 6, true, false, false), | ||
| 33 | ✗ | id_(id), | |
| 34 | ✗ | pref_(pref), | |
| 35 | ✗ | oMf_inv_(pref.inverse()), | |
| 36 | ✗ | pin_model_(state->get_pinocchio()) { | |
| 37 | ✗ | if (static_cast<pinocchio::FrameIndex>(state->get_pinocchio()->nframes) <= | |
| 38 | id) { | ||
| 39 | ✗ | throw_pretty( | |
| 40 | "Invalid argument: " | ||
| 41 | << "the frame index is wrong (it does not exist in the robot)"); | ||
| 42 | } | ||
| 43 | ✗ | } | |
| 44 | |||
| 45 | template <typename Scalar> | ||
| 46 | ✗ | void ResidualModelFramePlacementTpl<Scalar>::calc( | |
| 47 | const std::shared_ptr<ResidualDataAbstract>& data, | ||
| 48 | const Eigen::Ref<const VectorXs>&, const Eigen::Ref<const VectorXs>&) { | ||
| 49 | ✗ | Data* d = static_cast<Data*>(data.get()); | |
| 50 | |||
| 51 | // Compute the frame placement w.r.t. the reference frame | ||
| 52 | ✗ | pinocchio::updateFramePlacement(*pin_model_.get(), *d->pinocchio, id_); | |
| 53 | ✗ | d->rMf = oMf_inv_ * d->pinocchio->oMf[id_]; | |
| 54 | ✗ | data->r = pinocchio::log6(d->rMf).toVector(); | |
| 55 | ✗ | } | |
| 56 | |||
| 57 | template <typename Scalar> | ||
| 58 | ✗ | void ResidualModelFramePlacementTpl<Scalar>::calcDiff( | |
| 59 | const std::shared_ptr<ResidualDataAbstract>& data, | ||
| 60 | const Eigen::Ref<const VectorXs>&, const Eigen::Ref<const VectorXs>&) { | ||
| 61 | ✗ | Data* d = static_cast<Data*>(data.get()); | |
| 62 | |||
| 63 | // Compute the derivatives of the frame placement | ||
| 64 | ✗ | const std::size_t nv = state_->get_nv(); | |
| 65 | ✗ | pinocchio::Jlog6(d->rMf, d->rJf); | |
| 66 | ✗ | pinocchio::getFrameJacobian(*pin_model_.get(), *d->pinocchio, id_, | |
| 67 | ✗ | pinocchio::LOCAL, d->fJf); | |
| 68 | ✗ | data->Rx.leftCols(nv).noalias() = d->rJf * d->fJf; | |
| 69 | ✗ | } | |
| 70 | |||
| 71 | template <typename Scalar> | ||
| 72 | std::shared_ptr<ResidualDataAbstractTpl<Scalar> > | ||
| 73 | ✗ | ResidualModelFramePlacementTpl<Scalar>::createData( | |
| 74 | DataCollectorAbstract* const data) { | ||
| 75 | ✗ | return std::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), this, | |
| 76 | ✗ | data); | |
| 77 | } | ||
| 78 | |||
| 79 | template <typename Scalar> | ||
| 80 | template <typename NewScalar> | ||
| 81 | ResidualModelFramePlacementTpl<NewScalar> | ||
| 82 | ✗ | ResidualModelFramePlacementTpl<Scalar>::cast() const { | |
| 83 | typedef ResidualModelFramePlacementTpl<NewScalar> ReturnType; | ||
| 84 | typedef StateMultibodyTpl<NewScalar> StateType; | ||
| 85 | ✗ | ReturnType ret( | |
| 86 | ✗ | std::static_pointer_cast<StateType>(state_->template cast<NewScalar>()), | |
| 87 | ✗ | id_, pref_.template cast<NewScalar>(), nu_); | |
| 88 | ✗ | return ret; | |
| 89 | } | ||
| 90 | |||
| 91 | template <typename Scalar> | ||
| 92 | ✗ | void ResidualModelFramePlacementTpl<Scalar>::print(std::ostream& os) const { | |
| 93 | ✗ | const Eigen::IOFormat fmt(2, Eigen::DontAlignCols, ", ", ";\n", "", "", "[", | |
| 94 | "]"); | ||
| 95 | ✗ | typename SE3::Quaternion qref; | |
| 96 | ✗ | pinocchio::quaternion::assignQuaternion(qref, pref_.rotation()); | |
| 97 | ✗ | os << "ResidualModelFramePlacement {frame=" << pin_model_->frames[id_].name | |
| 98 | ✗ | << ", tref=" << pref_.translation().transpose().format(fmt) | |
| 99 | ✗ | << ", qref=" << qref.coeffs().transpose().format(fmt) << "}"; | |
| 100 | ✗ | } | |
| 101 | |||
| 102 | template <typename Scalar> | ||
| 103 | ✗ | pinocchio::FrameIndex ResidualModelFramePlacementTpl<Scalar>::get_id() const { | |
| 104 | ✗ | return id_; | |
| 105 | } | ||
| 106 | |||
| 107 | template <typename Scalar> | ||
| 108 | const pinocchio::SE3Tpl<Scalar>& | ||
| 109 | ✗ | ResidualModelFramePlacementTpl<Scalar>::get_reference() const { | |
| 110 | ✗ | return pref_; | |
| 111 | } | ||
| 112 | |||
| 113 | template <typename Scalar> | ||
| 114 | ✗ | void ResidualModelFramePlacementTpl<Scalar>::set_id( | |
| 115 | const pinocchio::FrameIndex id) { | ||
| 116 | ✗ | id_ = id; | |
| 117 | ✗ | } | |
| 118 | |||
| 119 | template <typename Scalar> | ||
| 120 | ✗ | void ResidualModelFramePlacementTpl<Scalar>::set_reference( | |
| 121 | const SE3& placement) { | ||
| 122 | ✗ | pref_ = placement; | |
| 123 | ✗ | oMf_inv_ = placement.inverse(); | |
| 124 | ✗ | } | |
| 125 | |||
| 126 | } // namespace crocoddyl | ||
| 127 |