Crocoddyl
 
Loading...
Searching...
No Matches
control.hpp
1
2// BSD 3-Clause License
3//
4// Copyright (C) 2021-2023, LAAS-CNRS, New York University, Max Planck
5// Gesellschaft,
6// University of Edinburgh, University of Trento,
7// Heriot-Watt University
8// Copyright note valid unless otherwise stated in individual files.
9// All rights reserved.
11
12#ifndef CROCODDYL_CORE_NUMDIFF_CONTROL_HPP_
13#define CROCODDYL_CORE_NUMDIFF_CONTROL_HPP_
14
15#include <boost/make_shared.hpp>
16#include <memory>
17#include <vector>
18
19#include "crocoddyl/core/control-base.hpp"
20#include "crocoddyl/core/fwd.hpp"
21
22namespace crocoddyl {
23
24template <typename _Scalar>
27 public:
28 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
29
30 typedef _Scalar Scalar;
36 typedef typename MathBase::VectorXs VectorXs;
37 typedef typename MathBase::MatrixXs MatrixXs;
38
44 explicit ControlParametrizationModelNumDiffTpl(std::shared_ptr<Base> model);
46
54 void calc(const std::shared_ptr<ControlParametrizationDataAbstract>& data,
55 const Scalar t, const Eigen::Ref<const VectorXs>& u) const;
56
65 void calcDiff(const std::shared_ptr<ControlParametrizationDataAbstract>& data,
66 const Scalar t, const Eigen::Ref<const VectorXs>& u) const;
67
73 virtual std::shared_ptr<ControlParametrizationDataAbstract> createData();
74
83 void params(const std::shared_ptr<ControlParametrizationDataAbstract>& data,
84 const Scalar t, const Eigen::Ref<const VectorXs>& w) const;
85
95 void convertBounds(const Eigen::Ref<const VectorXs>& w_lb,
96 const Eigen::Ref<const VectorXs>& w_ub,
97 Eigen::Ref<VectorXs> u_lb,
98 Eigen::Ref<VectorXs> u_ub) const;
99
112 const std::shared_ptr<ControlParametrizationDataAbstract>& data,
113 const Eigen::Ref<const MatrixXs>& A, Eigen::Ref<MatrixXs> out,
114 const AssignmentOp = setto) const;
115
128 const std::shared_ptr<ControlParametrizationDataAbstract>& data,
129 const Eigen::Ref<const MatrixXs>& A, Eigen::Ref<MatrixXs> out,
130 const AssignmentOp = setto) const;
131
137 const std::shared_ptr<Base>& get_model() const;
138
143 const Scalar get_disturbance() const;
144
149 void set_disturbance(const Scalar disturbance);
150
151 private:
152 std::shared_ptr<Base>
153 model_;
154 Scalar e_jac_;
156
157 protected:
158 using Base::nu_;
159 using Base::nw_;
160};
161
162template <typename _Scalar>
164 : public ControlParametrizationDataAbstractTpl<_Scalar> {
165 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
166
167 typedef _Scalar Scalar;
169 typedef typename MathBase::VectorXs VectorXs;
170 typedef typename MathBase::MatrixXs MatrixXs;
172
173 template <template <typename Scalar> class Model>
174 explicit ControlParametrizationDataNumDiffTpl(Model<Scalar>* const model)
175 : Base(model), du(model->get_nu()) {
176 du.setZero();
177
178 const std::size_t nu = model->get_model()->get_nu();
179 data_0 = model->get_model()->createData();
180 for (std::size_t i = 0; i < nu; ++i) {
181 data_u.push_back(model->get_model()->createData());
182 }
183 }
184
186
187 VectorXs du;
188 std::shared_ptr<Base> data_0;
189 std::vector<std::shared_ptr<Base> >
191};
192
193} // namespace crocoddyl
194
195/* --- Details -------------------------------------------------------------- */
196/* --- Details -------------------------------------------------------------- */
197/* --- Details -------------------------------------------------------------- */
198#include "crocoddyl/core/numdiff/control.hxx"
199
200#endif // CROCODDYL_CORE_NUMDIFF_CONTROL_HPP_
Abstract class for the control trajectory parametrization.
std::size_t nu_
Control parameters dimension.
const std::shared_ptr< Base > & get_model() const
Get the model_ object.
void multiplyJacobianTransposeBy(const std::shared_ptr< ControlParametrizationDataAbstract > &data, const Eigen::Ref< const MatrixXs > &A, Eigen::Ref< MatrixXs > out, const AssignmentOp=setto) const
Compute the product between the transposed Jacobian of the control (with respect to the parameters) a...
const Scalar get_disturbance() const
Return the disturbance constant used in the numerical differentiation routine.
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
Convert the bounds on the control to bounds on the control parameters.
void set_disturbance(const Scalar disturbance)
Modify the disturbance constant used in the numerical differentiation routine.
ControlParametrizationModelNumDiffTpl(std::shared_ptr< Base > model)
Construct a new ControlParametrizationModelNumDiff object.
void calc(const std::shared_ptr< ControlParametrizationDataAbstract > &data, const Scalar t, const Eigen::Ref< const VectorXs > &u) const
Get the value of the control at the specified time.
virtual std::shared_ptr< ControlParametrizationDataAbstract > createData()
Create the control-parametrization data.
void params(const std::shared_ptr< ControlParametrizationDataAbstract > &data, const Scalar t, const Eigen::Ref< const VectorXs > &w) const
Get a value of the control parameters such that the control at the specified time t is equal to the s...
void multiplyByJacobian(const std::shared_ptr< ControlParametrizationDataAbstract > &data, const Eigen::Ref< const MatrixXs > &A, Eigen::Ref< MatrixXs > out, const AssignmentOp=setto) const
Compute the product between a specified matrix and the Jacobian of the control (with respect to the p...
void calcDiff(const std::shared_ptr< ControlParametrizationDataAbstract > &data, const Scalar t, const Eigen::Ref< const VectorXs > &u) const
Get the value of the Jacobian of the control with respect to the parameters.
std::vector< std::shared_ptr< Base > > data_u
The temporary data associated with the control variation.
Definition control.hpp:190
VectorXs du
temporary variable used for finite differencing
Definition control.hpp:187
std::shared_ptr< Base > data_0
The data that contains the final results.
Definition control.hpp:188