GCC Code Coverage Report


Directory: ./
File: include/crocoddyl/multibody/residuals/frame-translation.hxx
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 32 48 66.7%
Branches: 31 88 35.2%

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 #include <pinocchio/algorithm/frames.hpp>
11
12 #include "crocoddyl/multibody/residuals/frame-translation.hpp"
13
14 namespace crocoddyl {
15
16 template <typename Scalar>
17 344 ResidualModelFrameTranslationTpl<Scalar>::ResidualModelFrameTranslationTpl(
18 std::shared_ptr<StateMultibody> state, const pinocchio::FrameIndex id,
19 const Vector3s& xref, const std::size_t nu)
20 : Base(state, 3, nu, true, false, false),
21 344 id_(id),
22 344 xref_(xref),
23
3/6
✓ Branch 2 taken 344 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 344 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 344 times.
✗ Branch 11 not taken.
344 pin_model_(state->get_pinocchio()) {
24
2/4
✓ Branch 2 taken 344 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 344 times.
344 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 344 }
31
32 template <typename Scalar>
33 3 ResidualModelFrameTranslationTpl<Scalar>::ResidualModelFrameTranslationTpl(
34 std::shared_ptr<StateMultibody> state, const pinocchio::FrameIndex id,
35 const Vector3s& xref)
36 : Base(state, 3, true, false, false),
37 3 id_(id),
38 3 xref_(xref),
39
3/6
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
3 pin_model_(state->get_pinocchio()) {
40
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
3 if (static_cast<pinocchio::FrameIndex>(state->get_pinocchio()->nframes) <=
41 id) {
42 throw_pretty(
43 "Invalid argument: "
44 << "the frame index is wrong (it does not exist in the robot)");
45 }
46 3 }
47
48 template <typename Scalar>
49 8213 void ResidualModelFrameTranslationTpl<Scalar>::calc(
50 const std::shared_ptr<ResidualDataAbstract>& data,
51 const Eigen::Ref<const VectorXs>&, const Eigen::Ref<const VectorXs>&) {
52 // Compute the frame translation w.r.t. the reference frame
53 8213 Data* d = static_cast<Data*>(data.get());
54 8213 pinocchio::updateFramePlacement(*pin_model_.get(), *d->pinocchio, id_);
55
1/2
✓ Branch 5 taken 8213 times.
✗ Branch 6 not taken.
8213 data->r = d->pinocchio->oMf[id_].translation() - xref_;
56 8213 }
57
58 template <typename Scalar>
59 280 void ResidualModelFrameTranslationTpl<Scalar>::calcDiff(
60 const std::shared_ptr<ResidualDataAbstract>& data,
61 const Eigen::Ref<const VectorXs>&, const Eigen::Ref<const VectorXs>&) {
62 280 Data* d = static_cast<Data*>(data.get());
63
64 // Compute the derivatives of the frame translation
65 280 const std::size_t nv = state_->get_nv();
66 280 pinocchio::getFrameJacobian(*pin_model_.get(), *d->pinocchio, id_,
67 280 pinocchio::LOCAL, d->fJf);
68
3/6
✓ Branch 1 taken 280 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 280 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 280 times.
✗ Branch 8 not taken.
280 d->Rx.leftCols(nv).noalias() =
69
2/4
✓ Branch 3 taken 280 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 280 times.
✗ Branch 7 not taken.
280 d->pinocchio->oMf[id_].rotation() * d->fJf.template topRows<3>();
70 ;
71 280 }
72
73 template <typename Scalar>
74 std::shared_ptr<ResidualDataAbstractTpl<Scalar> >
75 9550 ResidualModelFrameTranslationTpl<Scalar>::createData(
76 DataCollectorAbstract* const data) {
77 return std::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), this,
78
1/2
✓ Branch 2 taken 9550 times.
✗ Branch 3 not taken.
9550 data);
79 }
80
81 template <typename Scalar>
82 template <typename NewScalar>
83 ResidualModelFrameTranslationTpl<NewScalar>
84 ResidualModelFrameTranslationTpl<Scalar>::cast() const {
85 typedef ResidualModelFrameTranslationTpl<NewScalar> ReturnType;
86 typedef StateMultibodyTpl<NewScalar> StateType;
87 ReturnType ret(
88 std::static_pointer_cast<StateType>(state_->template cast<NewScalar>()),
89 id_, xref_.template cast<NewScalar>(), nu_);
90 return ret;
91 }
92
93 template <typename Scalar>
94 63 void ResidualModelFrameTranslationTpl<Scalar>::print(std::ostream& os) const {
95
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", "", "", "[",
96 "]");
97 63 os << "ResidualModelFrameTranslation {frame=" << pin_model_->frames[id_].name
98
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=" << xref_.transpose().format(fmt) << "}";
99 63 }
100
101 template <typename Scalar>
102 pinocchio::FrameIndex ResidualModelFrameTranslationTpl<Scalar>::get_id() const {
103 return id_;
104 }
105
106 template <typename Scalar>
107 const typename MathBaseTpl<Scalar>::Vector3s&
108 ResidualModelFrameTranslationTpl<Scalar>::get_reference() const {
109 return xref_;
110 }
111
112 template <typename Scalar>
113 void ResidualModelFrameTranslationTpl<Scalar>::set_id(
114 const pinocchio::FrameIndex id) {
115 id_ = id;
116 }
117
118 template <typename Scalar>
119 void ResidualModelFrameTranslationTpl<Scalar>::set_reference(
120 const Vector3s& translation) {
121 xref_ = translation;
122 }
123
124 } // namespace crocoddyl
125