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