GCC Code Coverage Report


Directory: ./
File: include/crocoddyl/multibody/residuals/contact-control-gravity.hxx
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 37 46 80.4%
Branches: 31 74 41.9%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2020-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/rnea-derivatives.hpp>
11 #include <pinocchio/algorithm/rnea.hpp>
12
13 #include "crocoddyl/multibody/residuals/contact-control-gravity.hpp"
14
15 namespace crocoddyl {
16
17 template <typename Scalar>
18 39 ResidualModelContactControlGravTpl<Scalar>::ResidualModelContactControlGravTpl(
19 std::shared_ptr<StateMultibody> state, const std::size_t nu)
20 39 : Base(state, state->get_nv(), nu, true, false, true),
21
3/6
✓ Branch 4 taken 39 times.
✗ Branch 5 not taken.
✓ Branch 9 taken 39 times.
✗ Branch 10 not taken.
✓ Branch 13 taken 39 times.
✗ Branch 14 not taken.
39 pin_model_(*state->get_pinocchio()) {
22
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
39 if (nu_ == 0) {
23 throw_pretty("Invalid argument: "
24 << "it seems to be an autonomous system, if so, don't add "
25 "this residual function");
26 }
27 39 }
28
29 template <typename Scalar>
30 1 ResidualModelContactControlGravTpl<Scalar>::ResidualModelContactControlGravTpl(
31 std::shared_ptr<StateMultibody> state)
32 2 : Base(state, state->get_nv(), state->get_nv(), true, false, true),
33
3/6
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
1 pin_model_(*state->get_pinocchio()) {}
34
35 template <typename Scalar>
36 2772 void ResidualModelContactControlGravTpl<Scalar>::calc(
37 const std::shared_ptr<ResidualDataAbstract> &data,
38 const Eigen::Ref<const VectorXs> &x, const Eigen::Ref<const VectorXs> &) {
39 2772 Data *d = static_cast<Data *>(data.get());
40
41 const Eigen::VectorBlock<const Eigen::Ref<const VectorXs>, Eigen::Dynamic> q =
42
2/4
✓ Branch 2 taken 2772 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2772 times.
✗ Branch 6 not taken.
2772 x.head(state_->get_nq());
43
2/4
✓ Branch 2 taken 2772 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 2772 times.
✗ Branch 7 not taken.
2772 data->r = d->actuation->tau - pinocchio::computeStaticTorque(
44
1/2
✓ Branch 1 taken 2772 times.
✗ Branch 2 not taken.
2772 pin_model_, d->pinocchio, q, d->fext);
45 2772 }
46
47 template <typename Scalar>
48 2030 void ResidualModelContactControlGravTpl<Scalar>::calc(
49 const std::shared_ptr<ResidualDataAbstract> &data,
50 const Eigen::Ref<const VectorXs> &x) {
51 2030 Data *d = static_cast<Data *>(data.get());
52
53 const Eigen::VectorBlock<const Eigen::Ref<const VectorXs>, Eigen::Dynamic> q =
54
2/4
✓ Branch 2 taken 2030 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2030 times.
✗ Branch 6 not taken.
2030 x.head(state_->get_nq());
55
3/6
✓ Branch 1 taken 2030 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2030 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 2030 times.
✗ Branch 9 not taken.
2030 data->r = -pinocchio::computeGeneralizedGravity(pin_model_, d->pinocchio, q);
56 2030 }
57
58 template <typename Scalar>
59 39 void ResidualModelContactControlGravTpl<Scalar>::calcDiff(
60 const std::shared_ptr<ResidualDataAbstract> &data,
61 const Eigen::Ref<const VectorXs> &x, const Eigen::Ref<const VectorXs> &) {
62 39 Data *d = static_cast<Data *>(data.get());
63
64 const Eigen::VectorBlock<const Eigen::Ref<const VectorXs>, Eigen::Dynamic> q =
65
2/4
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 39 times.
✗ Branch 6 not taken.
39 x.head(state_->get_nq());
66 Eigen::Block<MatrixXs, Eigen::Dynamic, Eigen::Dynamic, true> Rq =
67
2/4
✓ Branch 3 taken 39 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 39 times.
✗ Branch 7 not taken.
39 data->Rx.leftCols(state_->get_nv());
68 39 pinocchio::computeStaticTorqueDerivatives(pin_model_, d->pinocchio, q,
69
1/2
✓ Branch 1 taken 39 times.
✗ Branch 2 not taken.
39 d->fext, Rq);
70
1/2
✓ Branch 1 taken 39 times.
✗ Branch 2 not taken.
39 Rq *= Scalar(-1);
71
1/2
✓ Branch 3 taken 39 times.
✗ Branch 4 not taken.
39 data->Ru = d->actuation->dtau_du;
72 39 }
73
74 template <typename Scalar>
75 39 void ResidualModelContactControlGravTpl<Scalar>::calcDiff(
76 const std::shared_ptr<ResidualDataAbstract> &data,
77 const Eigen::Ref<const VectorXs> &x) {
78 39 Data *d = static_cast<Data *>(data.get());
79
80 const Eigen::VectorBlock<const Eigen::Ref<const VectorXs>, Eigen::Dynamic> q =
81
2/4
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 39 times.
✗ Branch 6 not taken.
39 x.head(state_->get_nq());
82 Eigen::Block<MatrixXs, Eigen::Dynamic, Eigen::Dynamic, true> Rq =
83
2/4
✓ Branch 3 taken 39 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 39 times.
✗ Branch 7 not taken.
39 data->Rx.leftCols(state_->get_nv());
84
1/2
✓ Branch 1 taken 39 times.
✗ Branch 2 not taken.
39 pinocchio::computeGeneralizedGravityDerivatives(pin_model_, d->pinocchio, q,
85 Rq);
86
1/2
✓ Branch 1 taken 39 times.
✗ Branch 2 not taken.
39 Rq *= Scalar(-1);
87 39 }
88
89 template <typename Scalar>
90 std::shared_ptr<ResidualDataAbstractTpl<Scalar> >
91 2774 ResidualModelContactControlGravTpl<Scalar>::createData(
92 DataCollectorAbstract *const data) {
93 return std::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), this,
94
1/2
✓ Branch 2 taken 2774 times.
✗ Branch 3 not taken.
2774 data);
95 }
96
97 template <typename Scalar>
98 template <typename NewScalar>
99 ResidualModelContactControlGravTpl<NewScalar>
100 ResidualModelContactControlGravTpl<Scalar>::cast() const {
101 typedef ResidualModelContactControlGravTpl<NewScalar> ReturnType;
102 typedef StateMultibodyTpl<NewScalar> StateType;
103 ReturnType ret(
104 std::static_pointer_cast<StateType>(state_->template cast<NewScalar>()),
105 nu_);
106 return ret;
107 }
108
109 template <typename Scalar>
110 void ResidualModelContactControlGravTpl<Scalar>::print(std::ostream &os) const {
111 os << "ResidualModelContactControlGrav";
112 }
113
114 } // namespace crocoddyl
115