| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////// | ||
| 2 | // BSD 3-Clause License | ||
| 3 | // | ||
| 4 | // Copyright (C) 2021-2025, University of Edinburgh, University of Trento, | ||
| 5 | // Heriot-Watt University | ||
| 6 | // Copyright note valid unless otherwise stated in individual files. | ||
| 7 | // All rights reserved. | ||
| 8 | /////////////////////////////////////////////////////////////////////////////// | ||
| 9 | |||
| 10 | #ifndef CROCODDYL_CORE_CONTROLS_POLY_ZERO_HPP_ | ||
| 11 | #define CROCODDYL_CORE_CONTROLS_POLY_ZERO_HPP_ | ||
| 12 | |||
| 13 | #include "crocoddyl/core/control-base.hpp" | ||
| 14 | #include "crocoddyl/core/fwd.hpp" | ||
| 15 | |||
| 16 | namespace crocoddyl { | ||
| 17 | |||
| 18 | /** | ||
| 19 | * @brief A polynomial function of time of degree zero, that is a constant | ||
| 20 | * | ||
| 21 | * The main computations are carrying out in `calc`, `multiplyByJacobian` and | ||
| 22 | * `multiplyJacobianTransposeBy`, where the former computes control input | ||
| 23 | * \f$\mathbf{w}\in\mathbb{R}^{nw}\f$ from a set of control parameters | ||
| 24 | * \f$\mathbf{u}\in\mathbb{R}^{nu}\f$ where `nw` and `nu` represent the | ||
| 25 | * dimension of the control inputs and parameters, respectively, and the latter | ||
| 26 | * defines useful operations across the Jacobian of the control-parametrization | ||
| 27 | * model. Finally, `params` allows us to obtain the control parameters from a | ||
| 28 | * the control input, i.e., it is the dual of `calc`. Note that | ||
| 29 | * `multiplyByJacobian` and `multiplyJacobianTransposeBy` requires to run `calc` | ||
| 30 | * first. | ||
| 31 | * | ||
| 32 | * \sa `ControlParametrizationAbstractTpl`, `calc()`, `calcDiff()`, | ||
| 33 | * `createData()`, `params`, `multiplyByJacobian`, `multiplyJacobianTransposeBy` | ||
| 34 | */ | ||
| 35 | template <typename _Scalar> | ||
| 36 | class ControlParametrizationModelPolyZeroTpl | ||
| 37 | : public ControlParametrizationModelAbstractTpl<_Scalar> { | ||
| 38 | public: | ||
| 39 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW | ||
| 40 | ✗ | CROCODDYL_DERIVED_CAST(ControlParametrizationModelBase, | |
| 41 | ControlParametrizationModelPolyZeroTpl) | ||
| 42 | |||
| 43 | typedef _Scalar Scalar; | ||
| 44 | typedef MathBaseTpl<Scalar> MathBase; | ||
| 45 | typedef ControlParametrizationDataAbstractTpl<Scalar> | ||
| 46 | ControlParametrizationDataAbstract; | ||
| 47 | typedef ControlParametrizationModelAbstractTpl<Scalar> Base; | ||
| 48 | typedef ControlParametrizationDataAbstractTpl<Scalar> Data; | ||
| 49 | typedef typename MathBase::VectorXs VectorXs; | ||
| 50 | typedef typename MathBase::MatrixXs MatrixXs; | ||
| 51 | |||
| 52 | /** | ||
| 53 | * @brief Initialize the poly-zero control parametrization | ||
| 54 | * | ||
| 55 | * @param[in] nw Dimension of control vector | ||
| 56 | */ | ||
| 57 | explicit ControlParametrizationModelPolyZeroTpl(const std::size_t nw); | ||
| 58 | ✗ | virtual ~ControlParametrizationModelPolyZeroTpl() = default; | |
| 59 | |||
| 60 | /** | ||
| 61 | * @brief Get the value of the control at the specified time | ||
| 62 | * | ||
| 63 | * @param[in] data Control-parametrization data | ||
| 64 | * @param[in] t Time in [0,1] | ||
| 65 | * @param[in] u Control parameters | ||
| 66 | */ | ||
| 67 | virtual void calc( | ||
| 68 | const std::shared_ptr<ControlParametrizationDataAbstract>& data, | ||
| 69 | const Scalar t, const Eigen::Ref<const VectorXs>& u) const override; | ||
| 70 | |||
| 71 | /** | ||
| 72 | * @brief Get the value of the Jacobian of the control with respect to the | ||
| 73 | * parameters | ||
| 74 | * | ||
| 75 | * It assumes that `calc()` has been run first | ||
| 76 | * | ||
| 77 | * @param[in] data Control-parametrization data | ||
| 78 | * @param[in] t Time in [0,1] | ||
| 79 | * @param[in] u Control parameters | ||
| 80 | */ | ||
| 81 | virtual void calcDiff( | ||
| 82 | const std::shared_ptr<ControlParametrizationDataAbstract>& data, | ||
| 83 | const Scalar t, const Eigen::Ref<const VectorXs>& u) const override; | ||
| 84 | |||
| 85 | /** | ||
| 86 | * @brief Create the control-parametrization data | ||
| 87 | * | ||
| 88 | * @return the control-parametrization data | ||
| 89 | */ | ||
| 90 | virtual std::shared_ptr<ControlParametrizationDataAbstract> createData() | ||
| 91 | override; | ||
| 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 u | ||
| 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 override; | ||
| 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 override; | ||
| 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 override; | ||
| 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 override; | ||
| 154 | |||
| 155 | template <typename NewScalar> | ||
| 156 | ControlParametrizationModelPolyZeroTpl<NewScalar> cast() const; | ||
| 157 | |||
| 158 | virtual void print(std::ostream& os) const override; | ||
| 159 | |||
| 160 | protected: | ||
| 161 | using Base::nu_; | ||
| 162 | using Base::nw_; | ||
| 163 | }; | ||
| 164 | |||
| 165 | } // namespace crocoddyl | ||
| 166 | |||
| 167 | /* --- Details -------------------------------------------------------------- */ | ||
| 168 | /* --- Details -------------------------------------------------------------- */ | ||
| 169 | /* --- Details -------------------------------------------------------------- */ | ||
| 170 | #include "crocoddyl/core/controls/poly-zero.hxx" | ||
| 171 | |||
| 172 | CROCODDYL_DECLARE_EXTERN_TEMPLATE_CLASS( | ||
| 173 | crocoddyl::ControlParametrizationModelPolyZeroTpl) | ||
| 174 | |||
| 175 | #endif // CROCODDYL_CORE_CONTROLS_POLY_ZERO_HPP_ | ||
| 176 |