GCC Code Coverage Report


Directory: ./
File: include/crocoddyl/multibody/actuations/full.hpp
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 24 27 88.9%
Branches: 14 84 16.7%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2022, LAAS-CNRS, University of Edinburgh
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #ifndef CROCODDYL_MULTIBODY_ACTUATIONS_FULL_HPP_
10 #define CROCODDYL_MULTIBODY_ACTUATIONS_FULL_HPP_
11
12 #include "crocoddyl/core/actuation-base.hpp"
13 #include "crocoddyl/core/state-base.hpp"
14 #include "crocoddyl/multibody/fwd.hpp"
15
16 namespace crocoddyl {
17
18 /**
19 * @brief Full actuation model
20 *
21 * This actuation model applies input controls for all the `nv` dimensions of
22 * the system.
23 *
24 * Both actuation and Jacobians are computed analytically by `calc` and
25 * `calcDiff`, respectively.
26 *
27 * \sa `ActuationModelAbstractTpl`, `calc()`, `calcDiff()`, `createData()`
28 */
29 template <typename _Scalar>
30 class ActuationModelFullTpl : public ActuationModelAbstractTpl<_Scalar> {
31 public:
32 typedef _Scalar Scalar;
33 typedef MathBaseTpl<Scalar> MathBase;
34 typedef ActuationModelAbstractTpl<Scalar> Base;
35 typedef ActuationDataAbstractTpl<Scalar> Data;
36 typedef StateAbstractTpl<Scalar> StateAbstract;
37 typedef typename MathBase::VectorXs VectorXs;
38 typedef typename MathBase::MatrixXs MatrixXs;
39
40 /**
41 * @brief Initialize the full actuation model
42 *
43 * @param[in] state State of the dynamical system
44 */
45 875 explicit ActuationModelFullTpl(boost::shared_ptr<StateAbstract> state)
46 875 : Base(state, state->get_nv()) {};
47 1754 virtual ~ActuationModelFullTpl() {};
48
49 /**
50 * @brief Compute the full actuation
51 *
52 * @param[in] data Full actuation data
53 * @param[in] x State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$
54 * @param[in] u Joint torque input \f$\mathbf{u}\in\mathbb{R}^{nu}\f$
55 */
56 41280 virtual void calc(const boost::shared_ptr<Data>& data,
57 const Eigen::Ref<const VectorXs>& /*x*/,
58 const Eigen::Ref<const VectorXs>& u) {
59
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 41280 times.
41280 if (static_cast<std::size_t>(u.size()) != nu_) {
60 throw_pretty(
61 "Invalid argument: " << "u has wrong dimension (it should be " +
62 std::to_string(nu_) + ")");
63 }
64 41280 data->tau = u;
65 41280 };
66
67 /**
68 * @brief Compute the Jacobians of the full actuation model
69 *
70 * @param[in] data Full actuation data
71 * @param[in] x State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$
72 * @param[in] u Joint torque input \f$\mathbf{u}\in\mathbb{R}^{nu}\f$
73 */
74 #ifndef NDEBUG
75 12039 virtual void calcDiff(const boost::shared_ptr<Data>& data,
76 const Eigen::Ref<const VectorXs>& /*x*/,
77 const Eigen::Ref<const VectorXs>&) {
78 #else
79 virtual void calcDiff(const boost::shared_ptr<Data>&,
80 const Eigen::Ref<const VectorXs>& /*x*/,
81 const Eigen::Ref<const VectorXs>&) {
82 #endif
83 // The derivatives has constant values which were set in createData.
84
2/12
✓ Branch 3 taken 12039 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 12039 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
12039 assert_pretty(data->dtau_dx.isZero(), "dtau_dx has wrong value");
85
3/14
✓ Branch 6 taken 12039 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 12039 times.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 12039 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
12039 assert_pretty(MatrixXs(data->dtau_du)
86 .isApprox(MatrixXs::Identity(state_->get_nv(), nu_)),
87 "dtau_du has wrong value");
88 12039 };
89
90 4994 virtual void commands(const boost::shared_ptr<Data>& data,
91 const Eigen::Ref<const VectorXs>&,
92 const Eigen::Ref<const VectorXs>& tau) {
93
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4994 times.
4994 if (static_cast<std::size_t>(tau.size()) != nu_) {
94 throw_pretty(
95 "Invalid argument: " << "tau has wrong dimension (it should be " +
96 std::to_string(nu_) + ")");
97 }
98 4994 data->u = tau;
99 4994 }
100
101 #ifndef NDEBUG
102 1268 virtual void torqueTransform(const boost::shared_ptr<Data>& data,
103 const Eigen::Ref<const VectorXs>&,
104 const Eigen::Ref<const VectorXs>&) {
105 #else
106 virtual void torqueTransform(const boost::shared_ptr<Data>&,
107 const Eigen::Ref<const VectorXs>&,
108 const Eigen::Ref<const VectorXs>&) {
109 #endif
110 // The torque transform has constant values which were set in createData.
111
3/14
✓ Branch 4 taken 1268 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1268 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1268 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1268 assert_pretty(MatrixXs(data->Mtau).isApprox(MatrixXs::Identity(nu_, nu_)),
112 "Mtau has wrong value");
113 1268 }
114
115 /**
116 * @brief Create the full actuation data
117 *
118 * @param[in] data shared data (it should be of type DataCollectorContactTpl)
119 * @return the cost data.
120 */
121 34456 virtual boost::shared_ptr<Data> createData() {
122
1/2
✓ Branch 1 taken 34456 times.
✗ Branch 2 not taken.
34456 boost::shared_ptr<Data> data =
123 34456 boost::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), this);
124
2/4
✓ Branch 2 taken 34456 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 34456 times.
✗ Branch 6 not taken.
34456 data->dtau_du.diagonal().setOnes();
125
1/2
✓ Branch 2 taken 34456 times.
✗ Branch 3 not taken.
34456 data->Mtau.setIdentity();
126 34456 return data;
127 };
128
129 protected:
130 using Base::nu_;
131 using Base::state_;
132 };
133
134 } // namespace crocoddyl
135
136 #endif // CROCODDYL_MULTIBODY_ACTUATIONS_FULL_HPP_
137