GCC Code Coverage Report


Directory: ./
File: include/crocoddyl/core/actuation/squashing-base.hpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 15 27 55.6%
Branches: 14 50 28.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2025, University of Edinburgh, IRI: CSIC-UPC,
5 // Heriot-Watt University
6 // Copyright note valid unless otherwise stated in individual files.
7 // All rights reserved.
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #ifndef CROCODDYL_CORE_SQUASHING_BASE_HPP_
11 #define CROCODDYL_CORE_SQUASHING_BASE_HPP_
12
13 #include <boost/core/demangle.hpp>
14 #include <memory>
15 #include <stdexcept>
16
17 #include "crocoddyl/core/fwd.hpp"
18 #include "crocoddyl/core/mathbase.hpp"
19
20 namespace crocoddyl {
21
22 class SquashingModelBase {
23 public:
24 640 virtual ~SquashingModelBase() = default;
25
26
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✓ Branch 5 taken 25 times.
✗ Branch 6 not taken.
100 CROCODDYL_BASE_CAST(SquashingModelBase, SquashingModelAbstractTpl)
27 };
28
29 template <typename _Scalar>
30 class SquashingModelAbstractTpl : public SquashingModelBase {
31 public:
32 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
33
34 typedef _Scalar Scalar;
35 typedef MathBaseTpl<Scalar> MathBase;
36 typedef SquashingDataAbstractTpl<Scalar> SquashingDataAbstract;
37 typedef typename MathBase::VectorXs VectorXs;
38
39
4/8
✓ Branch 2 taken 293 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 293 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 293 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 293 times.
✗ Branch 12 not taken.
293 SquashingModelAbstractTpl(const std::size_t ns) : ns_(ns) {
40
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 293 times.
293 if (ns_ == 0) {
41 throw_pretty("Invalid argument: " << "ns cannot be zero");
42 }
43 293 };
44 640 virtual ~SquashingModelAbstractTpl() = default;
45
46 virtual void calc(const std::shared_ptr<SquashingDataAbstract>& data,
47 const Eigen::Ref<const VectorXs>& s) = 0;
48 virtual void calcDiff(const std::shared_ptr<SquashingDataAbstract>& data,
49 const Eigen::Ref<const VectorXs>& s) = 0;
50 8105 virtual std::shared_ptr<SquashingDataAbstract> createData() {
51 return std::allocate_shared<SquashingDataAbstract>(
52
1/2
✓ Branch 2 taken 8105 times.
✗ Branch 3 not taken.
16210 Eigen::aligned_allocator<SquashingDataAbstract>(), this);
53 }
54
55 /**
56 * @brief Print information on the actuation model
57 */
58 template <class Scalar>
59 friend std::ostream& operator<<(
60 std::ostream& os, const SquashingModelAbstractTpl<Scalar>& model);
61
62 /**
63 * @brief Print relevant information of the squashing model
64 *
65 * @param[out] os Output stream object
66 */
67 virtual void print(std::ostream& os) const {
68 os << boost::core::demangle(typeid(*this).name());
69 }
70
71 24317 std::size_t get_ns() const { return ns_; };
72 const VectorXs& get_s_lb() const { return s_lb_; };
73 const VectorXs& get_s_ub() const { return s_ub_; };
74
75 void set_s_lb(const VectorXs& s_lb) { s_lb_ = s_lb; };
76 void set_s_ub(const VectorXs& s_ub) { s_ub_ = s_ub; };
77
78 protected:
79 std::size_t ns_;
80 VectorXs u_ub_; // Squashing function upper bound
81 VectorXs u_lb_; // Squashing function lower bound
82 VectorXs
83 s_ub_; // Bound for the s variable (to apply using the Quadratic barrier)
84 VectorXs
85 s_lb_; // Bound for the s variable (to apply using the Quadratic barrier)
86 SquashingModelAbstractTpl() : ns_(0) {};
87 };
88
89 template <typename _Scalar>
90 struct SquashingDataAbstractTpl {
91 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
92
93 typedef _Scalar Scalar;
94 typedef MathBaseTpl<Scalar> MathBase;
95 typedef typename MathBase::VectorXs VectorXs;
96 typedef typename MathBase::MatrixXs MatrixXs;
97
98 template <template <typename Scalar> class Model>
99 8113 explicit SquashingDataAbstractTpl(Model<Scalar>* const model)
100
4/8
✓ Branch 2 taken 8105 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 8105 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 8105 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 8105 times.
✗ Branch 12 not taken.
8113 : u(model->get_ns()), du_ds(model->get_ns(), model->get_ns()) {
101
1/2
✓ Branch 1 taken 8105 times.
✗ Branch 2 not taken.
8113 u.setZero();
102
1/2
✓ Branch 1 taken 8105 times.
✗ Branch 2 not taken.
8113 du_ds.setZero();
103 8113 }
104 SquashingDataAbstractTpl() {}
105 16214 virtual ~SquashingDataAbstractTpl() = default;
106
107 VectorXs u;
108 MatrixXs du_ds;
109 };
110
111 template <class Scalar>
112 std::ostream& operator<<(std::ostream& os,
113 const SquashingModelAbstractTpl<Scalar>& model) {
114 model.print(os);
115 return os;
116 }
117
118 } // namespace crocoddyl
119
120 CROCODDYL_DECLARE_EXTERN_TEMPLATE_CLASS(crocoddyl::SquashingModelAbstractTpl)
121 CROCODDYL_DECLARE_EXTERN_TEMPLATE_STRUCT(crocoddyl::SquashingDataAbstractTpl)
122
123 #endif // CROCODDYL_CORE_SQUASHING_BASE_HPP_
124