Directory: | ./ |
---|---|
File: | include/crocoddyl/multibody/actuations/full.hpp |
Date: | 2025-03-26 19:23:43 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 28 | 34 | 82.4% |
Branches: | 17 | 90 | 18.9% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2019-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 | #ifndef CROCODDYL_MULTIBODY_ACTUATIONS_FULL_HPP_ | ||
11 | #define CROCODDYL_MULTIBODY_ACTUATIONS_FULL_HPP_ | ||
12 | |||
13 | #include "crocoddyl/core/actuation-base.hpp" | ||
14 | #include "crocoddyl/core/state-base.hpp" | ||
15 | #include "crocoddyl/multibody/fwd.hpp" | ||
16 | |||
17 | namespace crocoddyl { | ||
18 | |||
19 | /** | ||
20 | * @brief Full actuation model | ||
21 | * | ||
22 | * This actuation model applies input controls for all the `nv` dimensions of | ||
23 | * the system. | ||
24 | * | ||
25 | * Both actuation and Jacobians are computed analytically by `calc` and | ||
26 | * `calcDiff`, respectively. | ||
27 | * | ||
28 | * \sa `ActuationModelAbstractTpl`, `calc()`, `calcDiff()`, `createData()` | ||
29 | */ | ||
30 | template <typename _Scalar> | ||
31 | class ActuationModelFullTpl : public ActuationModelAbstractTpl<_Scalar> { | ||
32 | public: | ||
33 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW | ||
34 | 240 | CROCODDYL_DERIVED_CAST(ActuationModelBase, ActuationModelFullTpl) | |
35 | |||
36 | typedef _Scalar Scalar; | ||
37 | typedef MathBaseTpl<Scalar> MathBase; | ||
38 | typedef ActuationModelAbstractTpl<Scalar> Base; | ||
39 | typedef ActuationDataAbstractTpl<Scalar> Data; | ||
40 | typedef StateAbstractTpl<Scalar> StateAbstract; | ||
41 | typedef typename MathBase::VectorXs VectorXs; | ||
42 | typedef typename MathBase::MatrixXs MatrixXs; | ||
43 | |||
44 | /** | ||
45 | * @brief Initialize the full actuation model | ||
46 | * | ||
47 | * @param[in] state State of the dynamical system | ||
48 | */ | ||
49 | 905 | explicit ActuationModelFullTpl(std::shared_ptr<StateAbstract> state) | |
50 |
1/2✓ Branch 4 taken 905 times.
✗ Branch 5 not taken.
|
905 | : Base(state, state->get_nv()) {}; |
51 | 1934 | virtual ~ActuationModelFullTpl() = default; | |
52 | |||
53 | /** | ||
54 | * @brief Compute the full actuation | ||
55 | * | ||
56 | * @param[in] data Full actuation data | ||
57 | * @param[in] x State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$ | ||
58 | * @param[in] u Joint torque input \f$\mathbf{u}\in\mathbb{R}^{nu}\f$ | ||
59 | */ | ||
60 | 39802 | virtual void calc(const std::shared_ptr<Data>& data, | |
61 | const Eigen::Ref<const VectorXs>& /*x*/, | ||
62 | const Eigen::Ref<const VectorXs>& u) override { | ||
63 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 39802 times.
|
39802 | if (static_cast<std::size_t>(u.size()) != nu_) { |
64 | ✗ | throw_pretty( | |
65 | "Invalid argument: " << "u has wrong dimension (it should be " + | ||
66 | std::to_string(nu_) + ")"); | ||
67 | } | ||
68 | 39802 | data->tau = u; | |
69 | 39802 | }; | |
70 | |||
71 | /** | ||
72 | * @brief Compute the Jacobians of the full actuation model | ||
73 | * | ||
74 | * @param[in] data Full actuation data | ||
75 | * @param[in] x State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$ | ||
76 | * @param[in] u Joint torque input \f$\mathbf{u}\in\mathbb{R}^{nu}\f$ | ||
77 | */ | ||
78 | #ifndef NDEBUG | ||
79 | 11789 | virtual void calcDiff(const std::shared_ptr<Data>& data, | |
80 | const Eigen::Ref<const VectorXs>& /*x*/, | ||
81 | const Eigen::Ref<const VectorXs>&) override { | ||
82 | #else | ||
83 | virtual void calcDiff(const std::shared_ptr<Data>&, | ||
84 | const Eigen::Ref<const VectorXs>& /*x*/, | ||
85 | const Eigen::Ref<const VectorXs>&) override { | ||
86 | #endif | ||
87 | // The derivatives has constant values which were set in createData. | ||
88 |
2/12✓ Branch 3 taken 11789 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 11789 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.
|
11789 | assert_pretty(data->dtau_dx.isZero(), "dtau_dx has wrong value"); |
89 |
4/16✓ Branch 5 taken 11789 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 11789 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 11789 times.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 11789 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
|
11789 | assert_pretty(MatrixXs(data->dtau_du) |
90 | .isApprox(MatrixXs::Identity(state_->get_nv(), nu_)), | ||
91 | "dtau_du has wrong value"); | ||
92 | 11789 | }; | |
93 | |||
94 | 5001 | virtual void commands(const std::shared_ptr<Data>& data, | |
95 | const Eigen::Ref<const VectorXs>&, | ||
96 | const Eigen::Ref<const VectorXs>& tau) override { | ||
97 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 5001 times.
|
5001 | if (static_cast<std::size_t>(tau.size()) != nu_) { |
98 | ✗ | throw_pretty( | |
99 | "Invalid argument: " << "tau has wrong dimension (it should be " + | ||
100 | std::to_string(nu_) + ")"); | ||
101 | } | ||
102 | 5001 | data->u = tau; | |
103 | 5001 | } | |
104 | |||
105 | #ifndef NDEBUG | ||
106 | 1275 | virtual void torqueTransform(const std::shared_ptr<Data>& data, | |
107 | const Eigen::Ref<const VectorXs>&, | ||
108 | const Eigen::Ref<const VectorXs>&) override { | ||
109 | #else | ||
110 | virtual void torqueTransform(const std::shared_ptr<Data>&, | ||
111 | const Eigen::Ref<const VectorXs>&, | ||
112 | const Eigen::Ref<const VectorXs>&) override { | ||
113 | #endif | ||
114 | // The torque transform has constant values which were set in createData. | ||
115 |
3/14✓ Branch 4 taken 1275 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1275 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1275 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.
|
1275 | assert_pretty(MatrixXs(data->Mtau).isApprox(MatrixXs::Identity(nu_, nu_)), |
116 | "Mtau has wrong value"); | ||
117 | 1275 | } | |
118 | |||
119 | /** | ||
120 | * @brief Create the full actuation data | ||
121 | * | ||
122 | * @param[in] data shared data (it should be of type DataCollectorContactTpl) | ||
123 | * @return the cost data. | ||
124 | */ | ||
125 | 34154 | virtual std::shared_ptr<Data> createData() override { | |
126 |
1/2✓ Branch 1 taken 34154 times.
✗ Branch 2 not taken.
|
34154 | std::shared_ptr<Data> data = |
127 | 34154 | std::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), this); | |
128 |
2/4✓ Branch 2 taken 34154 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 34154 times.
✗ Branch 6 not taken.
|
34154 | data->dtau_du.diagonal().setOnes(); |
129 |
1/2✓ Branch 2 taken 34154 times.
✗ Branch 3 not taken.
|
34154 | data->Mtau.setIdentity(); |
130 | 34154 | return data; | |
131 | ✗ | }; | |
132 | |||
133 | template <typename NewScalar> | ||
134 | 60 | ActuationModelFullTpl<NewScalar> cast() const { | |
135 | typedef ActuationModelFullTpl<NewScalar> ReturnType; | ||
136 |
1/2✓ Branch 3 taken 60 times.
✗ Branch 4 not taken.
|
60 | ReturnType ret(state_->template cast<NewScalar>()); |
137 | 60 | return ret; | |
138 | } | ||
139 | |||
140 | /** | ||
141 | * @brief Print relevant information of the joint-effort residual | ||
142 | * | ||
143 | * @param[out] os Output stream object | ||
144 | */ | ||
145 | ✗ | virtual void print(std::ostream& os) const override { | |
146 | ✗ | os << "ActuationModelFull {nu=" << nu_ << ", nv=" << state_->get_nv() | |
147 | ✗ | << "}"; | |
148 | } | ||
149 | |||
150 | protected: | ||
151 | using Base::nu_; | ||
152 | using Base::state_; | ||
153 | }; | ||
154 | |||
155 | } // namespace crocoddyl | ||
156 | |||
157 | extern template class CROCODDYL_EXPLICIT_INSTANTIATION_DECLARATION_DLLAPI | ||
158 | crocoddyl::ActuationModelFullTpl<double>; | ||
159 | extern template class CROCODDYL_EXPLICIT_INSTANTIATION_DECLARATION_DLLAPI | ||
160 | crocoddyl::ActuationModelFullTpl<float>; | ||
161 | |||
162 | #endif // CROCODDYL_MULTIBODY_ACTUATIONS_FULL_HPP_ | ||
163 |