10 #ifndef CROCODDYL_CORE_COST_BASE_HPP_
11 #define CROCODDYL_CORE_COST_BASE_HPP_
13 #include "crocoddyl/core/activation-base.hpp"
14 #include "crocoddyl/core/activations/quadratic.hpp"
15 #include "crocoddyl/core/data-collector-base.hpp"
16 #include "crocoddyl/core/fwd.hpp"
17 #include "crocoddyl/core/residual-base.hpp"
18 #include "crocoddyl/core/state-base.hpp"
19 #include "crocoddyl/core/utils/deprecate.hpp"
63 template <
typename _Scalar>
66 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
68 typedef _Scalar Scalar;
76 typedef typename MathBase::VectorXs VectorXs;
77 typedef typename MathBase::MatrixXs MatrixXs;
87 std::shared_ptr<ActivationModelAbstract> activation,
88 std::shared_ptr<ResidualModelAbstract> residual);
98 std::shared_ptr<ActivationModelAbstract> activation,
99 const std::size_t nu);
110 std::shared_ptr<ActivationModelAbstract> activation);
122 std::shared_ptr<ResidualModelAbstract> residual);
135 const std::size_t nr,
const std::size_t nu);
149 const std::size_t nr);
159 virtual void calc(
const std::shared_ptr<CostDataAbstract>& data,
160 const Eigen::Ref<const VectorXs>& x,
161 const Eigen::Ref<const VectorXs>& u) = 0;
173 virtual void calc(
const std::shared_ptr<CostDataAbstract>& data,
174 const Eigen::Ref<const VectorXs>& x);
186 virtual void calcDiff(
const std::shared_ptr<CostDataAbstract>& data,
187 const Eigen::Ref<const VectorXs>& x,
188 const Eigen::Ref<const VectorXs>& u) = 0;
201 virtual void calcDiff(
const std::shared_ptr<CostDataAbstract>& data,
202 const Eigen::Ref<const VectorXs>& x);
221 const std::shared_ptr<StateAbstract>&
get_state()
const;
241 template <
class Scalar>
248 template <
class ReferenceType>
254 template <
class ReferenceType>
262 virtual void print(std::ostream& os)
const;
284 template <
typename _Scalar>
286 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
288 typedef _Scalar Scalar;
293 typedef typename MathBase::VectorXs VectorXs;
294 typedef typename MathBase::MatrixXs MatrixXs;
296 template <
template <
typename Scalar>
class Model>
300 activation(model->get_activation()->createData()),
301 residual(model->get_residual()->createData(data)),
303 Lx(model->get_state()->get_ndx()),
305 Lxx(model->get_state()->get_ndx(), model->get_state()->get_ndx()),
306 Lxu(model->get_state()->get_ndx(), model->get_nu()),
307 Luu(model->get_nu(), model->get_nu()) {
317 "Use residual.r",
const VectorXs& get_r()
const {
return residual->r; };)
320 const MatrixXs& get_Rx()
const {
return residual->Rx; };)
323 const MatrixXs& get_Ru()
const {
return residual->Ru; };)
325 "Use residual.r",
void set_r(
const VectorXs& r) { residual->r = r; };)
328 void set_Rx(
const MatrixXs& Rx) { residual->Rx = Rx; };)
331 void set_Ru(
const MatrixXs& Ru) { residual->Ru = Ru; };)
334 std::shared_ptr<ActivationDataAbstract> activation;
335 std::shared_ptr<ResidualDataAbstract> residual;
349 #include "crocoddyl/core/cost-base.hxx"
Abstract class for cost models.
std::shared_ptr< ActivationModelAbstract > activation_
Activation model.
virtual std::shared_ptr< CostDataAbstract > createData(DataCollectorAbstract *const data)
Create the cost data.
virtual void calcDiff(const std::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the Jacobian and Hessian of the cost functions with respect to the state only.
const std::shared_ptr< ActivationModelAbstract > & get_activation() const
Return the activation model.
virtual void calc(const std::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)=0
Compute the cost value and its residual vector.
std::shared_ptr< StateAbstract > state_
State description.
virtual void set_referenceImpl(const std::type_info &, const void *)
Modify the cost reference.
void set_reference(ReferenceType ref)
Modify the cost reference.
CostModelAbstractTpl(std::shared_ptr< StateAbstract > state, const std::size_t nr)
virtual void calc(const std::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the total cost value for nodes that depends only on the state.
CostModelAbstractTpl(std::shared_ptr< StateAbstract > state, std::shared_ptr< ActivationModelAbstract > activation, std::shared_ptr< ResidualModelAbstract > residual)
Initialize the cost model.
virtual void print(std::ostream &os) const
Print relevant information of the cost model.
friend std::ostream & operator<<(std::ostream &os, const CostModelAbstractTpl< Scalar > &model)
Print information on the cost model.
CostModelAbstractTpl(std::shared_ptr< StateAbstract > state, std::shared_ptr< ResidualModelAbstract > residual)
CostModelAbstractTpl(std::shared_ptr< StateAbstract > state, const std::size_t nr, const std::size_t nu)
CostModelAbstractTpl(std::shared_ptr< StateAbstract > state, std::shared_ptr< ActivationModelAbstract > activation, const std::size_t nu)
Initialize the cost model.
virtual void get_referenceImpl(const std::type_info &, void *)
Return the cost reference.
const std::shared_ptr< StateAbstract > & get_state() const
Return the state.
std::size_t nu_
Control dimension.
VectorXs unone_
No control vector.
const std::shared_ptr< ResidualModelAbstract > & get_residual() const
Return the residual model.
ReferenceType get_reference()
Return the cost reference.
CostModelAbstractTpl(std::shared_ptr< StateAbstract > state, std::shared_ptr< ActivationModelAbstract > activation)
std::shared_ptr< ResidualModelAbstract > residual_
Residual model.
virtual void calcDiff(const std::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)=0
Compute the Jacobian and Hessian of cost and its residual vector.
std::size_t get_nu() const
Return the dimension of the control input.
Abstract class for residual models.
Abstract class for the state representation.