Crocoddyl
 
Loading...
Searching...
No Matches
control-base.hpp
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.
9
10#ifndef CROCODDYL_CORE_CONTROL_BASE_HPP_
11#define CROCODDYL_CORE_CONTROL_BASE_HPP_
12
13#include "crocoddyl/core/fwd.hpp"
14
15namespace crocoddyl {
16
24
47template <typename _Scalar>
50 public:
51 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
52
53 typedef _Scalar Scalar;
57 typedef typename MathBase::VectorXs VectorXs;
58 typedef typename MathBase::MatrixXs MatrixXs;
59
67 const std::size_t nu);
69
77 virtual void calc(
78 const std::shared_ptr<ControlParametrizationDataAbstract>& data,
79 const Scalar t, const Eigen::Ref<const VectorXs>& u) const = 0;
80
91 virtual void calcDiff(
92 const std::shared_ptr<ControlParametrizationDataAbstract>& data,
93 const Scalar t, const Eigen::Ref<const VectorXs>& u) const = 0;
94
100 virtual std::shared_ptr<ControlParametrizationDataAbstract> createData();
101
110 virtual void params(
111 const std::shared_ptr<ControlParametrizationDataAbstract>& data,
112 const Scalar t, const Eigen::Ref<const VectorXs>& w) const = 0;
113
123 virtual void convertBounds(const Eigen::Ref<const VectorXs>& w_lb,
124 const Eigen::Ref<const VectorXs>& w_ub,
125 Eigen::Ref<VectorXs> u_lb,
126 Eigen::Ref<VectorXs> u_ub) const = 0;
127
141 virtual void multiplyByJacobian(
142 const std::shared_ptr<ControlParametrizationDataAbstract>& data,
143 const Eigen::Ref<const MatrixXs>& A, Eigen::Ref<MatrixXs> out,
144 const AssignmentOp op = setto) const = 0;
145
146 virtual MatrixXs multiplyByJacobian_J(
147 const std::shared_ptr<ControlParametrizationDataAbstract>& data,
148 const Eigen::Ref<const MatrixXs>& A, const AssignmentOp op = setto) const;
149
165 const std::shared_ptr<ControlParametrizationDataAbstract>& data,
166 const Eigen::Ref<const MatrixXs>& A, Eigen::Ref<MatrixXs> out,
167 const AssignmentOp op = setto) const = 0;
168
169 virtual MatrixXs multiplyJacobianTransposeBy_J(
170 const std::shared_ptr<ControlParametrizationDataAbstract>& data,
171 const Eigen::Ref<const MatrixXs>& A, const AssignmentOp op = setto) const;
172
176 virtual bool checkData(
177 const std::shared_ptr<ControlParametrizationDataAbstract>& data);
178
182 template <class Scalar>
183 friend std::ostream& operator<<(
184 std::ostream& os,
186
192 virtual void print(std::ostream& os) const;
193
197 std::size_t get_nw() const;
198
202 std::size_t get_nu() const;
203
204 protected:
205 std::size_t nw_;
206 std::size_t nu_;
208};
209
210template <typename _Scalar>
212 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
213
214 typedef _Scalar Scalar;
216 typedef typename MathBase::VectorXs VectorXs;
217 typedef typename MathBase::MatrixXs MatrixXs;
218
219 template <template <typename Scalar> class Model>
220 explicit ControlParametrizationDataAbstractTpl(Model<Scalar>* const model)
221 : w(model->get_nw()),
222 u(model->get_nu()),
223 dw_du(model->get_nw(), model->get_nu()) {
224 w.setZero();
225 u.setZero();
226 dw_du.setZero();
227 }
228 virtual ~ControlParametrizationDataAbstractTpl() = default;
229
230 VectorXs w;
231 VectorXs u;
232 MatrixXs dw_du;
234};
235
236} // namespace crocoddyl
237
238/* --- Details -------------------------------------------------------------- */
239/* --- Details -------------------------------------------------------------- */
240/* --- Details -------------------------------------------------------------- */
241#include "crocoddyl/core/control-base.hxx"
242
243CROCODDYL_DECLARE_EXTERN_TEMPLATE_CLASS(
245CROCODDYL_DECLARE_EXTERN_TEMPLATE_STRUCT(
247
248#endif // CROCODDYL_CORE_CONTROL_BASE_HPP_
Abstract class for the control trajectory parametrization.
friend std::ostream & operator<<(std::ostream &os, const ControlParametrizationModelAbstractTpl< Scalar > &model)
Print information on the control model.
virtual void calcDiff(const std::shared_ptr< ControlParametrizationDataAbstract > &data, const Scalar t, const Eigen::Ref< const VectorXs > &u) const =0
Get the value of the Jacobian of the control with respect to the parameters.
virtual void calc(const std::shared_ptr< ControlParametrizationDataAbstract > &data, const Scalar t, const Eigen::Ref< const VectorXs > &u) const =0
Get the value of the control at the specified time.
virtual void multiplyJacobianTransposeBy(const std::shared_ptr< ControlParametrizationDataAbstract > &data, const Eigen::Ref< const MatrixXs > &A, Eigen::Ref< MatrixXs > out, const AssignmentOp op=setto) const =0
Compute the product between the transpose of the derivative of the control input with respect to the ...
virtual bool checkData(const std::shared_ptr< ControlParametrizationDataAbstract > &data)
Checks that a specific data belongs to this model.
virtual void print(std::ostream &os) const
Print relevant information of the control model.
ControlParametrizationModelAbstractTpl(const std::size_t nw, const std::size_t nu)
Initialize the control dimensions.
virtual void multiplyByJacobian(const std::shared_ptr< ControlParametrizationDataAbstract > &data, const Eigen::Ref< const MatrixXs > &A, Eigen::Ref< MatrixXs > out, const AssignmentOp op=setto) const =0
Compute the product between the given matrix A and the derivative of the control input with respect t...
virtual std::shared_ptr< ControlParametrizationDataAbstract > createData()
Create the control-parametrization data.
std::size_t nu_
Control parameters dimension.
std::size_t get_nw() const
Return the dimension of the control inputs.
virtual void convertBounds(const Eigen::Ref< const VectorXs > &w_lb, const Eigen::Ref< const VectorXs > &w_ub, Eigen::Ref< VectorXs > u_lb, Eigen::Ref< VectorXs > u_ub) const =0
Convert the bounds on the control inputs w to bounds on the control parameters u.
virtual void params(const std::shared_ptr< ControlParametrizationDataAbstract > &data, const Scalar t, const Eigen::Ref< const VectorXs > &w) const =0
Update the control parameters u for a specified time t given the control input w.
std::size_t get_nu() const
Return the dimension of control parameters.
VectorXs w
value of the differential control
VectorXs u
value of the control parameters