GCC Code Coverage Report


Directory: ./
File: include/crocoddyl/multibody/residuals/frame-placement.hxx
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 39 51 76.5%
Branches: 37 96 38.5%

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-placement.hpp"
12
13 namespace crocoddyl {
14
15 template <typename Scalar>
16 905 ResidualModelFramePlacementTpl<Scalar>::ResidualModelFramePlacementTpl(
17 boost::shared_ptr<StateMultibody> state, const pinocchio::FrameIndex id,
18 const SE3& pref, const std::size_t nu)
19 : Base(state, 6, nu, true, false, false),
20 905 id_(id),
21 905 pref_(pref),
22
1/2
✓ Branch 1 taken 905 times.
✗ Branch 2 not taken.
905 oMf_inv_(pref.inverse()),
23
2/4
✓ Branch 2 taken 905 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 905 times.
✗ Branch 7 not taken.
1810 pin_model_(state->get_pinocchio()) {
24
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 905 times.
905 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 905 }
31
32 template <typename Scalar>
33 10 ResidualModelFramePlacementTpl<Scalar>::ResidualModelFramePlacementTpl(
34 boost::shared_ptr<StateMultibody> state, const pinocchio::FrameIndex id,
35 const SE3& pref)
36 : Base(state, 6, true, false, false),
37 10 id_(id),
38 10 pref_(pref),
39
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 oMf_inv_(pref.inverse()),
40
2/4
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
20 pin_model_(state->get_pinocchio()) {
41
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
10 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 10 }
48
49 template <typename Scalar>
50 1834 ResidualModelFramePlacementTpl<Scalar>::~ResidualModelFramePlacementTpl() {}
51
52 template <typename Scalar>
53 38306 void ResidualModelFramePlacementTpl<Scalar>::calc(
54 const boost::shared_ptr<ResidualDataAbstract>& data,
55 const Eigen::Ref<const VectorXs>&, const Eigen::Ref<const VectorXs>&) {
56 38306 Data* d = static_cast<Data*>(data.get());
57
58 // Compute the frame placement w.r.t. the reference frame
59 38306 pinocchio::updateFramePlacement(*pin_model_.get(), *d->pinocchio, id_);
60
1/2
✓ Branch 3 taken 38306 times.
✗ Branch 4 not taken.
38306 d->rMf = oMf_inv_ * d->pinocchio->oMf[id_];
61
2/4
✓ Branch 2 taken 38306 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 38306 times.
✗ Branch 7 not taken.
38306 data->r = pinocchio::log6(d->rMf).toVector();
62 38306 }
63
64 template <typename Scalar>
65 8455 void ResidualModelFramePlacementTpl<Scalar>::calcDiff(
66 const boost::shared_ptr<ResidualDataAbstract>& data,
67 const Eigen::Ref<const VectorXs>&, const Eigen::Ref<const VectorXs>&) {
68 8455 Data* d = static_cast<Data*>(data.get());
69
70 // Compute the derivatives of the frame placement
71 8455 const std::size_t nv = state_->get_nv();
72 8455 pinocchio::Jlog6(d->rMf, d->rJf);
73 8455 pinocchio::getFrameJacobian(*pin_model_.get(), *d->pinocchio, id_,
74 8455 pinocchio::LOCAL, d->fJf);
75
3/6
✓ Branch 3 taken 8455 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 8455 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 8455 times.
✗ Branch 10 not taken.
8455 data->Rx.leftCols(nv).noalias() = d->rJf * d->fJf;
76 8455 }
77
78 template <typename Scalar>
79 boost::shared_ptr<ResidualDataAbstractTpl<Scalar> >
80 46652 ResidualModelFramePlacementTpl<Scalar>::createData(
81 DataCollectorAbstract* const data) {
82 return boost::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), this,
83
1/2
✓ Branch 2 taken 46652 times.
✗ Branch 3 not taken.
46652 data);
84 }
85
86 template <typename Scalar>
87 63 void ResidualModelFramePlacementTpl<Scalar>::print(std::ostream& os) const {
88
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", "", "", "[",
89 "]");
90
1/2
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
63 typename SE3::Quaternion qref;
91
2/4
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 63 times.
✗ Branch 5 not taken.
63 pinocchio::quaternion::assignQuaternion(qref, pref_.rotation());
92 63 os << "ResidualModelFramePlacement {frame=" << pin_model_->frames[id_].name
93
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 11 taken 63 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 63 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 63 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 63 times.
✗ Branch 21 not taken.
126 << ", tref=" << pref_.translation().transpose().format(fmt)
94
5/10
✓ 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 11 taken 63 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 63 times.
✗ Branch 15 not taken.
63 << ", qref=" << qref.coeffs().transpose().format(fmt) << "}";
95 63 }
96
97 template <typename Scalar>
98 pinocchio::FrameIndex ResidualModelFramePlacementTpl<Scalar>::get_id() const {
99 return id_;
100 }
101
102 template <typename Scalar>
103 const pinocchio::SE3Tpl<Scalar>&
104 ResidualModelFramePlacementTpl<Scalar>::get_reference() const {
105 return pref_;
106 }
107
108 template <typename Scalar>
109 void ResidualModelFramePlacementTpl<Scalar>::set_id(
110 const pinocchio::FrameIndex id) {
111 id_ = id;
112 }
113
114 template <typename Scalar>
115 void ResidualModelFramePlacementTpl<Scalar>::set_reference(
116 const SE3& placement) {
117 pref_ = placement;
118 oMf_inv_ = placement.inverse();
119 }
120
121 } // namespace crocoddyl
122