GCC Code Coverage Report


Directory: ./
File: include/crocoddyl/core/controls/poly-one.hpp
Date: 2025-01-30 11:01:55
Exec Total Coverage
Lines: 5 5 100.0%
Branches: 2 4 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2021, University of Edinburgh, University of Trento
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #ifndef CROCODDYL_CORE_CONTROLS_POLY_ONE_HPP_
10 #define CROCODDYL_CORE_CONTROLS_POLY_ONE_HPP_
11
12 #include "crocoddyl/core/control-base.hpp"
13 #include "crocoddyl/core/fwd.hpp"
14 #include "crocoddyl/core/utils/exception.hpp"
15
16 namespace crocoddyl {
17
18 /**
19 * @brief A polynomial function of time of degree one, that is a linear function
20 *
21 * The size of the parameters \f$\mathbf{u}\f$ is twice the size of the control
22 * input \f$\mathbf{w}\f$. The first half of \f$\mathbf{u}\f$ represents the
23 * value of w at time 0. The second half of \f$\mathbf{u}\f$ represents the
24 * value of \f$\mathbf{w}\f$ at time 0.5.
25 *
26 * The main computations are carried out in `calc`, `multiplyByJacobian` and
27 * `multiplyJacobianTransposeBy`, where the former computes control input
28 * \f$\mathbf{w}\in\mathbb{R}^{nw}\f$ from a set of control parameters
29 * \f$\mathbf{u}\in\mathbb{R}^{nu}\f$ where `nw` and `nu` represent the
30 * dimension of the control inputs and parameters, respectively, and the latter
31 * defines useful operations across the Jacobian of the control-parametrization
32 * model. Finally, `params` allows us to obtain the control parameters from the
33 * control input, i.e., it is the inverse of `calc`. Note that
34 * `multiplyByJacobian` and `multiplyJacobianTransposeBy` requires to run `calc`
35 * first.
36 *
37 * \sa `ControlParametrizationAbstractTpl`, `calc()`, `calcDiff()`,
38 * `createData()`, `params`, `multiplyByJacobian`, `multiplyJacobianTransposeBy`
39 */
40 template <typename _Scalar>
41 class ControlParametrizationModelPolyOneTpl
42 : public ControlParametrizationModelAbstractTpl<_Scalar> {
43 public:
44 typedef _Scalar Scalar;
45 typedef MathBaseTpl<Scalar> MathBase;
46 typedef ControlParametrizationDataAbstractTpl<Scalar>
47 ControlParametrizationDataAbstract;
48 typedef ControlParametrizationModelAbstractTpl<Scalar> Base;
49 typedef ControlParametrizationDataPolyOneTpl<Scalar> Data;
50 typedef typename MathBase::VectorXs VectorXs;
51 typedef typename MathBase::MatrixXs MatrixXs;
52
53 /**
54 * @brief Initialize the poly-one control parametrization
55 *
56 * @param[in] nw Dimension of control vector
57 */
58 explicit ControlParametrizationModelPolyOneTpl(const std::size_t nw);
59 virtual ~ControlParametrizationModelPolyOneTpl();
60
61 /**
62 * @brief Get the value of the control at the specified time
63 *
64 * @param[in] data Control-parametrization data
65 * @param[in] t Time in [0,1]
66 * @param[in] u Control parameters
67 */
68 virtual void calc(
69 const std::shared_ptr<ControlParametrizationDataAbstract>& data,
70 const Scalar t, const Eigen::Ref<const VectorXs>& u) const;
71
72 /**
73 * @brief Get the value of the Jacobian of the control with respect to the
74 * parameters
75 *
76 * It assumes that `calc()` has been run first
77 *
78 * @param[in] data Control-parametrization data
79 * @param[in] t Time in [0,1]
80 * @param[in] u Control parameters
81 */
82 virtual void calcDiff(
83 const std::shared_ptr<ControlParametrizationDataAbstract>& data,
84 const Scalar t, const Eigen::Ref<const VectorXs>& u) const;
85
86 /**
87 * @brief Create the control-parametrization data
88 *
89 * @return the control-parametrization data
90 */
91 virtual std::shared_ptr<ControlParametrizationDataAbstract> createData();
92
93 /**
94 * @brief Get a value of the control parameters such that the control at the
95 * specified time t is equal to the specified value w
96 *
97 * @param[in] data Control-parametrization data
98 * @param[in] t Time in [0,1]
99 * @param[in] w Control values
100 */
101 virtual void params(
102 const std::shared_ptr<ControlParametrizationDataAbstract>& data,
103 const Scalar t, const Eigen::Ref<const VectorXs>& w) const;
104
105 /**
106 * @brief Map the specified bounds from the control space to the parameter
107 * space
108 *
109 * @param[in] w_lb Control lower bound
110 * @param[in] w_ub Control lower bound
111 * @param[out] u_lb Control parameters lower bound
112 * @param[out] u_ub Control parameters upper bound
113 */
114 virtual void convertBounds(const Eigen::Ref<const VectorXs>& w_lb,
115 const Eigen::Ref<const VectorXs>& w_ub,
116 Eigen::Ref<VectorXs> u_lb,
117 Eigen::Ref<VectorXs> u_ub) const;
118
119 /**
120 * @brief Compute the product between a specified matrix and the Jacobian of
121 * the control (with respect to the parameters)
122 *
123 * It assumes that `calc()` has been run first
124 *
125 * @param[in] data Control-parametrization data
126 * @param[in] A A matrix to multiply times the Jacobian
127 * @param[out] out Product between the matrix A and the Jacobian of the
128 * control with respect to the parameters
129 * @param[in] op Assignment operator which sets, adds, or removes the
130 * given results
131 */
132 virtual void multiplyByJacobian(
133 const std::shared_ptr<ControlParametrizationDataAbstract>& data,
134 const Eigen::Ref<const MatrixXs>& A, Eigen::Ref<MatrixXs> out,
135 const AssignmentOp = setto) const;
136
137 /**
138 * @brief Compute the product between the transposed Jacobian of the control
139 * (with respect to the parameters) and a specified matrix
140 *
141 * It assumes that `calc()` has been run first
142 *
143 * @param[in] data Control-parametrization data
144 * @param[in] A A matrix to multiply times the Jacobian
145 * @param[out] out Product between the transposed Jacobian of the control
146 * with respect to the parameters and the matrix A
147 * @param[in] op Assignment operator which sets, adds, or removes the
148 * given results
149 */
150 virtual void multiplyJacobianTransposeBy(
151 const std::shared_ptr<ControlParametrizationDataAbstract>& data,
152 const Eigen::Ref<const MatrixXs>& A, Eigen::Ref<MatrixXs> out,
153 const AssignmentOp = setto) const;
154
155 protected:
156 using Base::nu_;
157 using Base::nw_;
158 };
159
160 template <typename _Scalar>
161 struct ControlParametrizationDataPolyOneTpl
162 : public ControlParametrizationDataAbstractTpl<_Scalar> {
163 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
164
165 typedef _Scalar Scalar;
166 typedef MathBaseTpl<Scalar> MathBase;
167 typedef ControlParametrizationDataAbstractTpl<Scalar> Base;
168 typedef typename MathBase::Vector2s Vector2s;
169
170 template <template <typename Scalar> class Model>
171 16782 explicit ControlParametrizationDataPolyOneTpl(Model<Scalar>* const model)
172
1/2
✓ Branch 2 taken 16782 times.
✗ Branch 3 not taken.
16782 : Base(model) {
173
1/2
✓ Branch 1 taken 16782 times.
✗ Branch 2 not taken.
16782 c.setZero();
174 16782 }
175
176 33568 virtual ~ControlParametrizationDataPolyOneTpl() {}
177
178 Vector2s c; //!< Coefficients of the linear control that depends on time
179 };
180
181 } // namespace crocoddyl
182
183 /* --- Details -------------------------------------------------------------- */
184 /* --- Details -------------------------------------------------------------- */
185 /* --- Details -------------------------------------------------------------- */
186 #include "crocoddyl/core/controls/poly-one.hxx"
187
188 #endif // CROCODDYL_CORE_CONTROLS_POLY_ONE_HPP_
189