GCC Code Coverage Report


Directory: ./
File: include/crocoddyl/core/residuals/joint-effort.hxx
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 34 60 56.7%
Branches: 19 96 19.8%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2022-2025, Heriot-Watt University, University of Edinburgh
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #include "crocoddyl/core/residuals/joint-effort.hpp"
10
11 namespace crocoddyl {
12
13 template <typename Scalar>
14 597 ResidualModelJointEffortTpl<Scalar>::ResidualModelJointEffortTpl(
15 std::shared_ptr<StateAbstract> state,
16 std::shared_ptr<ActuationModelAbstract> actuation, const VectorXs& uref,
17 const std::size_t nu, const bool fwddyn)
18 : Base(state, actuation->get_nu(), nu, fwddyn ? false : true,
19 fwddyn ? false : true, true),
20 597 actuation_(actuation),
21
1/2
✓ Branch 1 taken 597 times.
✗ Branch 2 not taken.
597 uref_(uref),
22
3/6
✓ Branch 0 taken 597 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 597 times.
✗ Branch 3 not taken.
✓ Branch 8 taken 597 times.
✗ Branch 9 not taken.
597 fwddyn_(fwddyn) {
23
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 597 times.
597 if (nu_ == 0) {
24 throw_pretty("Invalid argument: "
25 << "it seems to be an autonomous system, if so, don't add "
26 "this residual function");
27 }
28 597 }
29
30 template <typename Scalar>
31 ResidualModelJointEffortTpl<Scalar>::ResidualModelJointEffortTpl(
32 std::shared_ptr<StateAbstract> state,
33 std::shared_ptr<ActuationModelAbstract> actuation, const VectorXs& uref)
34 : Base(state, actuation->get_nu(), state->get_nv(), true, true, true),
35 actuation_(actuation),
36 uref_(uref),
37 fwddyn_(false) {}
38
39 template <typename Scalar>
40 1 ResidualModelJointEffortTpl<Scalar>::ResidualModelJointEffortTpl(
41 std::shared_ptr<StateAbstract> state,
42 std::shared_ptr<ActuationModelAbstract> actuation, const std::size_t nu)
43 : Base(state, actuation->get_nu(), nu, true, true, true),
44 1 actuation_(actuation),
45
3/6
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
1 uref_(VectorXs::Zero(actuation->get_nu())),
46
1/2
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 fwddyn_(false) {
47
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (nu_ == 0) {
48 throw_pretty("Invalid argument: "
49 << "it seems to be an autonomous system, if so, don't add "
50 "this residual function");
51 }
52 1 }
53
54 template <typename Scalar>
55 1 ResidualModelJointEffortTpl<Scalar>::ResidualModelJointEffortTpl(
56 std::shared_ptr<StateAbstract> state,
57 std::shared_ptr<ActuationModelAbstract> actuation)
58 : Base(state, actuation->get_nu(), state->get_nv(), true, true, true),
59 1 actuation_(actuation),
60
4/8
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
1 uref_(VectorXs::Zero(actuation->get_nu())) {}
61
62 template <typename Scalar>
63 38100 void ResidualModelJointEffortTpl<Scalar>::calc(
64 const std::shared_ptr<ResidualDataAbstract>& data,
65 const Eigen::Ref<const VectorXs>&, const Eigen::Ref<const VectorXs>&) {
66 38100 Data* d = static_cast<Data*>(data.get());
67
1/2
✓ Branch 4 taken 38100 times.
✗ Branch 5 not taken.
38100 data->r = d->joint->tau - uref_;
68 38100 }
69
70 template <typename Scalar>
71 void ResidualModelJointEffortTpl<Scalar>::calc(
72 const std::shared_ptr<ResidualDataAbstract>& data,
73 const Eigen::Ref<const VectorXs>&) {
74 if (fwddyn_) {
75 data->r.setZero();
76 } else {
77 Data* d = static_cast<Data*>(data.get());
78 data->r = d->joint->tau - uref_;
79 }
80 }
81
82 template <typename Scalar>
83 6945 void ResidualModelJointEffortTpl<Scalar>::calcDiff(
84 const std::shared_ptr<ResidualDataAbstract>& data,
85 const Eigen::Ref<const VectorXs>&, const Eigen::Ref<const VectorXs>&) {
86 6945 Data* d = static_cast<Data*>(data.get());
87
2/4
✓ Branch 0 taken 6945 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6945 times.
6945 if (q_dependent_ || v_dependent_) {
88 data->Rx = d->joint->dtau_dx;
89 }
90 6945 data->Ru = d->joint->dtau_du;
91 6945 }
92
93 template <typename Scalar>
94 void ResidualModelJointEffortTpl<Scalar>::calcDiff(
95 const std::shared_ptr<ResidualDataAbstract>& data,
96 const Eigen::Ref<const VectorXs>&) {
97 if (fwddyn_) {
98 data->Rx.setZero();
99 } else {
100 Data* d = static_cast<Data*>(data.get());
101 data->Rx = d->joint->dtau_dx;
102 data->Ru = d->joint->dtau_du;
103 }
104 }
105
106 template <typename Scalar>
107 std::shared_ptr<ResidualDataAbstractTpl<Scalar> >
108 48185 ResidualModelJointEffortTpl<Scalar>::createData(
109 DataCollectorAbstract* const data) {
110
1/2
✓ Branch 1 taken 48185 times.
✗ Branch 2 not taken.
96370 std::shared_ptr<ResidualDataAbstract> d =
111 48185 std::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), this, data);
112 48185 return d;
113 }
114
115 template <typename Scalar>
116 template <typename NewScalar>
117 ResidualModelJointEffortTpl<NewScalar>
118 ResidualModelJointEffortTpl<Scalar>::cast() const {
119 typedef ResidualModelJointEffortTpl<NewScalar> ReturnType;
120 ReturnType ret(state_->template cast<NewScalar>(),
121 actuation_->template cast<NewScalar>(),
122 uref_.template cast<NewScalar>(), nu_, fwddyn_);
123 return ret;
124 }
125
126 template <typename Scalar>
127 void ResidualModelJointEffortTpl<Scalar>::print(std::ostream& os) const {
128 os << "ResidualModelJointEffort";
129 }
130
131 template <typename Scalar>
132 const typename MathBaseTpl<Scalar>::VectorXs&
133 1 ResidualModelJointEffortTpl<Scalar>::get_reference() const {
134 1 return uref_;
135 }
136
137 template <typename Scalar>
138 1 void ResidualModelJointEffortTpl<Scalar>::set_reference(
139 const VectorXs& reference) {
140
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (static_cast<std::size_t>(reference.size()) != nr_) {
141 throw_pretty("Invalid argument: "
142 << "the joint-effort reference has wrong dimension ("
143 << reference.size()
144 << " provided - it should be " + std::to_string(nr_) + ")")
145 }
146 1 uref_ = reference;
147 1 }
148
149 } // namespace crocoddyl
150