Directory: | ./ |
---|---|
File: | include/crocoddyl/multibody/residuals/frame-rotation.hxx |
Date: | 2025-01-16 08:47:40 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 38 | 50 | 76.0% |
Branches: | 34 | 90 | 37.8% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2021-2022, LAAS-CNRS, University of Edinburgh | ||
5 | // Copyright note valid unless otherwise stated in individual files. | ||
6 | // All rights reserved. | ||
7 | /////////////////////////////////////////////////////////////////////////////// | ||
8 | |||
9 | #include <pinocchio/algorithm/frames.hpp> | ||
10 | |||
11 | #include "crocoddyl/multibody/residuals/frame-rotation.hpp" | ||
12 | |||
13 | namespace crocoddyl { | ||
14 | |||
15 | template <typename Scalar> | ||
16 | 351 | ResidualModelFrameRotationTpl<Scalar>::ResidualModelFrameRotationTpl( | |
17 | boost::shared_ptr<StateMultibody> state, const pinocchio::FrameIndex id, | ||
18 | const Matrix3s& Rref, const std::size_t nu) | ||
19 | : Base(state, 3, nu, true, false, false), | ||
20 | 351 | id_(id), | |
21 | 351 | Rref_(Rref), | |
22 |
2/4✓ Branch 1 taken 351 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 351 times.
✗ Branch 5 not taken.
|
351 | oRf_inv_(Rref.transpose()), |
23 |
2/4✓ Branch 2 taken 351 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 351 times.
✗ Branch 7 not taken.
|
702 | pin_model_(state->get_pinocchio()) { |
24 |
1/2✗ Branch 3 not taken.
✓ Branch 4 taken 351 times.
|
351 | if (static_cast<pinocchio::FrameIndex>(state->get_pinocchio()->nframes) <= |
25 | id) { | ||
26 | ✗ | throw_pretty( | |
27 | "Invalid argument: " | ||
28 | << "the frame index is wrong (it does not exist in the robot)"); | ||
29 | } | ||
30 | 351 | } | |
31 | |||
32 | template <typename Scalar> | ||
33 | 3 | ResidualModelFrameRotationTpl<Scalar>::ResidualModelFrameRotationTpl( | |
34 | boost::shared_ptr<StateMultibody> state, const pinocchio::FrameIndex id, | ||
35 | const Matrix3s& Rref) | ||
36 | : Base(state, 3, true, false, false), | ||
37 | 3 | id_(id), | |
38 | 3 | Rref_(Rref), | |
39 |
2/4✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | oRf_inv_(Rref.transpose()), |
40 |
2/4✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
|
6 | pin_model_(state->get_pinocchio()) { |
41 |
1/2✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
|
3 | if (static_cast<pinocchio::FrameIndex>(state->get_pinocchio()->nframes) <= |
42 | id) { | ||
43 | ✗ | throw_pretty( | |
44 | "Invalid argument: " | ||
45 | << "the frame index is wrong (it does not exist in the robot)"); | ||
46 | } | ||
47 | 3 | } | |
48 | |||
49 | template <typename Scalar> | ||
50 | 712 | ResidualModelFrameRotationTpl<Scalar>::~ResidualModelFrameRotationTpl() {} | |
51 | |||
52 | template <typename Scalar> | ||
53 | 8229 | void ResidualModelFrameRotationTpl<Scalar>::calc( | |
54 | const boost::shared_ptr<ResidualDataAbstract>& data, | ||
55 | const Eigen::Ref<const VectorXs>&, const Eigen::Ref<const VectorXs>&) { | ||
56 | 8229 | Data* d = static_cast<Data*>(data.get()); | |
57 | |||
58 | // Compute the frame rotation w.r.t. the reference frame | ||
59 | 8229 | pinocchio::updateFramePlacement(*pin_model_.get(), *d->pinocchio, id_); | |
60 |
2/4✓ Branch 4 taken 8229 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 8229 times.
✗ Branch 8 not taken.
|
8229 | d->rRf.noalias() = oRf_inv_ * d->pinocchio->oMf[id_].rotation(); |
61 |
1/2✓ Branch 3 taken 8229 times.
✗ Branch 4 not taken.
|
8229 | data->r = pinocchio::log3(d->rRf); |
62 | 8229 | } | |
63 | |||
64 | template <typename Scalar> | ||
65 | 292 | void ResidualModelFrameRotationTpl<Scalar>::calcDiff( | |
66 | const boost::shared_ptr<ResidualDataAbstract>& data, | ||
67 | const Eigen::Ref<const VectorXs>&, const Eigen::Ref<const VectorXs>&) { | ||
68 | 292 | Data* d = static_cast<Data*>(data.get()); | |
69 | |||
70 | // Compute the frame Jacobian at the error point | ||
71 | 292 | pinocchio::Jlog3(d->rRf, d->rJf); | |
72 | 292 | pinocchio::getFrameJacobian(*pin_model_.get(), *d->pinocchio, id_, | |
73 | 292 | pinocchio::LOCAL, d->fJf); | |
74 | |||
75 | // Compute the derivatives of the frame rotation | ||
76 | 292 | const std::size_t nv = state_->get_nv(); | |
77 |
4/8✓ Branch 2 taken 292 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 292 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 292 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 292 times.
✗ Branch 13 not taken.
|
292 | data->Rx.leftCols(nv).noalias() = d->rJf * d->fJf.template bottomRows<3>(); |
78 | 292 | } | |
79 | |||
80 | template <typename Scalar> | ||
81 | boost::shared_ptr<ResidualDataAbstractTpl<Scalar> > | ||
82 | 9556 | ResidualModelFrameRotationTpl<Scalar>::createData( | |
83 | DataCollectorAbstract* const data) { | ||
84 | ✗ | return boost::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), this, | |
85 |
1/2✓ Branch 2 taken 9556 times.
✗ Branch 3 not taken.
|
9556 | data); |
86 | } | ||
87 | |||
88 | template <typename Scalar> | ||
89 | 63 | void ResidualModelFrameRotationTpl<Scalar>::print(std::ostream& os) const { | |
90 |
7/14✓ Branch 2 taken 63 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 63 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 63 times.
✗ Branch 11 not taken.
✓ Branch 14 taken 63 times.
✗ Branch 15 not taken.
✓ Branch 18 taken 63 times.
✗ Branch 19 not taken.
✓ Branch 22 taken 63 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 63 times.
✗ Branch 26 not taken.
|
126 | const Eigen::IOFormat fmt(2, Eigen::DontAlignCols, ", ", ";\n", "", "", "[", |
91 | "]"); | ||
92 |
1/2✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
|
63 | typename pinocchio::SE3Tpl<Scalar>::Quaternion qref; |
93 |
1/2✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
|
63 | pinocchio::quaternion::assignQuaternion(qref, Rref_); |
94 | 63 | os << "ResidualModelFrameRotation {frame=" << pin_model_->frames[id_].name | |
95 |
7/14✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 63 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 63 times.
✗ Branch 9 not taken.
✓ Branch 12 taken 63 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 63 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 63 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 63 times.
✗ Branch 22 not taken.
|
126 | << ", qref=" << qref.coeffs().transpose().format(fmt) << "}"; |
96 | 63 | } | |
97 | |||
98 | template <typename Scalar> | ||
99 | ✗ | pinocchio::FrameIndex ResidualModelFrameRotationTpl<Scalar>::get_id() const { | |
100 | ✗ | return id_; | |
101 | } | ||
102 | |||
103 | template <typename Scalar> | ||
104 | const typename MathBaseTpl<Scalar>::Matrix3s& | ||
105 | ✗ | ResidualModelFrameRotationTpl<Scalar>::get_reference() const { | |
106 | ✗ | return Rref_; | |
107 | } | ||
108 | |||
109 | template <typename Scalar> | ||
110 | ✗ | void ResidualModelFrameRotationTpl<Scalar>::set_id( | |
111 | const pinocchio::FrameIndex id) { | ||
112 | ✗ | id_ = id; | |
113 | } | ||
114 | |||
115 | template <typename Scalar> | ||
116 | ✗ | void ResidualModelFrameRotationTpl<Scalar>::set_reference( | |
117 | const Matrix3s& rotation) { | ||
118 | ✗ | Rref_ = rotation; | |
119 | ✗ | oRf_inv_ = rotation.transpose(); | |
120 | } | ||
121 | |||
122 | } // namespace crocoddyl | ||
123 |