GCC Code Coverage Report


Directory: ./
File: include/crocoddyl/multibody/residuals/com-position.hxx
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 25 31 80.6%
Branches: 19 44 43.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 "crocoddyl/multibody/residuals/com-position.hpp"
11
12 namespace crocoddyl {
13
14 template <typename Scalar>
15 356 ResidualModelCoMPositionTpl<Scalar>::ResidualModelCoMPositionTpl(
16 std::shared_ptr<StateMultibody> state, const Vector3s& cref,
17 const std::size_t nu)
18
2/4
✓ Branch 2 taken 356 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 356 times.
✗ Branch 7 not taken.
356 : Base(state, 3, nu, true, false, false), cref_(cref) {}
19
20 template <typename Scalar>
21 4 ResidualModelCoMPositionTpl<Scalar>::ResidualModelCoMPositionTpl(
22 std::shared_ptr<StateMultibody> state, const Vector3s& cref)
23
2/4
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
4 : Base(state, 3, true, false, false), cref_(cref) {}
24
25 template <typename Scalar>
26 8251 void ResidualModelCoMPositionTpl<Scalar>::calc(
27 const std::shared_ptr<ResidualDataAbstract>& data,
28 const Eigen::Ref<const VectorXs>&, const Eigen::Ref<const VectorXs>&) {
29 // Compute the residual residual give the reference CoMPosition position
30 8251 Data* d = static_cast<Data*>(data.get());
31
1/2
✓ Branch 4 taken 8251 times.
✗ Branch 5 not taken.
8251 data->r = d->pinocchio->com[0] - cref_;
32 8251 }
33
34 template <typename Scalar>
35 312 void ResidualModelCoMPositionTpl<Scalar>::calcDiff(
36 const std::shared_ptr<ResidualDataAbstract>& data,
37 const Eigen::Ref<const VectorXs>&, const Eigen::Ref<const VectorXs>&) {
38 312 Data* d = static_cast<Data*>(data.get());
39
40 // Compute the derivatives of the frame placement
41 312 const std::size_t nv = state_->get_nv();
42
1/2
✓ Branch 3 taken 312 times.
✗ Branch 4 not taken.
312 data->Rx.leftCols(nv) = d->pinocchio->Jcom;
43 312 }
44
45 template <typename Scalar>
46 std::shared_ptr<ResidualDataAbstractTpl<Scalar> >
47 9564 ResidualModelCoMPositionTpl<Scalar>::createData(
48 DataCollectorAbstract* const data) {
49 return std::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), this,
50
1/2
✓ Branch 2 taken 9564 times.
✗ Branch 3 not taken.
9564 data);
51 }
52
53 template <typename Scalar>
54 template <typename NewScalar>
55 ResidualModelCoMPositionTpl<NewScalar>
56 ResidualModelCoMPositionTpl<Scalar>::cast() const {
57 typedef ResidualModelCoMPositionTpl<NewScalar> ReturnType;
58 typedef StateMultibodyTpl<NewScalar> StateType;
59 ReturnType ret(
60 std::static_pointer_cast<StateType>(state_->template cast<NewScalar>()),
61 cref_.template cast<NewScalar>(), nu_);
62 return ret;
63 }
64
65 template <typename Scalar>
66 63 void ResidualModelCoMPositionTpl<Scalar>::print(std::ostream& os) const {
67
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", "", "", "[",
68 "]");
69
4/8
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 63 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 63 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 63 times.
✗ Branch 11 not taken.
126 os << "ResidualModelCoMPosition {cref=" << cref_.transpose().format(fmt)
70
1/2
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
63 << "}";
71 63 }
72
73 template <typename Scalar>
74 const typename MathBaseTpl<Scalar>::Vector3s&
75 1 ResidualModelCoMPositionTpl<Scalar>::get_reference() const {
76 1 return cref_;
77 }
78
79 template <typename Scalar>
80 1 void ResidualModelCoMPositionTpl<Scalar>::set_reference(const Vector3s& cref) {
81 1 cref_ = cref;
82 1 }
83
84 } // namespace crocoddyl
85