Crocoddyl
 
Loading...
Searching...
No Matches
residual.hpp
1
2// BSD 3-Clause License
3//
4// Copyright (C) 2021-2023, University of Edinburgh, Heriot-Watt University
5// Copyright note valid unless otherwise stated in individual files.
6// All rights reserved.
8
9#ifndef CROCODDYL_CORE_COSTS_RESIDUAL_COST_HPP_
10#define CROCODDYL_CORE_COSTS_RESIDUAL_COST_HPP_
11
12#include "crocoddyl/core/cost-base.hpp"
13#include "crocoddyl/core/fwd.hpp"
14#include "crocoddyl/core/residual-base.hpp"
15
16namespace crocoddyl {
17
38template <typename _Scalar>
40 public:
41 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
42
43 typedef _Scalar Scalar;
51 typedef typename MathBase::VectorXs VectorXs;
52 typedef typename MathBase::MatrixXs MatrixXs;
53
61 CostModelResidualTpl(std::shared_ptr<typename Base::StateAbstract> state,
62 std::shared_ptr<ActivationModelAbstract> activation,
63 std::shared_ptr<ResidualModelAbstract> residual);
73 CostModelResidualTpl(std::shared_ptr<typename Base::StateAbstract> state,
74 std::shared_ptr<ResidualModelAbstract> residual);
75 virtual ~CostModelResidualTpl();
76
84 virtual void calc(const std::shared_ptr<CostDataAbstract>& data,
85 const Eigen::Ref<const VectorXs>& x,
86 const Eigen::Ref<const VectorXs>& u);
87
97 virtual void calc(const std::shared_ptr<CostDataAbstract>& data,
98 const Eigen::Ref<const VectorXs>& x);
99
107 virtual void calcDiff(const std::shared_ptr<CostDataAbstract>& data,
108 const Eigen::Ref<const VectorXs>& x,
109 const Eigen::Ref<const VectorXs>& u);
110
122 virtual void calcDiff(const std::shared_ptr<CostDataAbstract>& data,
123 const Eigen::Ref<const VectorXs>& x);
124
128 virtual std::shared_ptr<CostDataAbstract> createData(
129 DataCollectorAbstract* const data);
130
136 virtual void print(std::ostream& os) const;
137
138 protected:
139 using Base::activation_;
140 using Base::nu_;
141 using Base::residual_;
142 using Base::state_;
143 using Base::unone_;
144};
145
146template <typename _Scalar>
147struct CostDataResidualTpl : public CostDataAbstractTpl<_Scalar> {
148 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
149
150 typedef _Scalar Scalar;
154
155 template <template <typename Scalar> class Model>
156 CostDataResidualTpl(Model<Scalar>* const model,
157 DataCollectorAbstract* const data)
158 : Base(model, data) {}
159
160 using Base::activation;
161 using Base::cost;
162 using Base::Lu;
163 using Base::Luu;
164 using Base::Lx;
165 using Base::Lxu;
166 using Base::Lxx;
167 using Base::residual;
168 using Base::shared;
169};
170
171} // namespace crocoddyl
172
173/* --- Details -------------------------------------------------------------- */
174/* --- Details -------------------------------------------------------------- */
175/* --- Details -------------------------------------------------------------- */
176#include "crocoddyl/core/costs/residual.hxx"
177
178#endif // CROCODDYL_CORE_COSTS_RESIDUAL_COST_HPP_
Abstract class for cost models.
Definition cost-base.hpp:59
std::shared_ptr< ActivationModelAbstract > activation_
Activation model.
std::shared_ptr< StateAbstract > state_
State description.
std::size_t nu_
Control dimension.
VectorXs unone_
No control vector.
std::shared_ptr< ResidualModelAbstract > residual_
Residual model.
Residual-based cost.
Definition residual.hpp:39
virtual void calcDiff(const std::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the derivatives of the residual cost with respect to the state only.
virtual void calc(const std::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the residual cost based on state only.
CostModelResidualTpl(std::shared_ptr< typename Base::StateAbstract > state, std::shared_ptr< ResidualModelAbstract > residual)
Initialize the residual cost model.
virtual void print(std::ostream &os) const
Print relevant information of the cost-residual model.
CostModelResidualTpl(std::shared_ptr< typename Base::StateAbstract > state, std::shared_ptr< ActivationModelAbstract > activation, std::shared_ptr< ResidualModelAbstract > residual)
Initialize the residual cost model.
virtual std::shared_ptr< CostDataAbstract > createData(DataCollectorAbstract *const data)
Create the residual cost data.
virtual void calc(const std::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the residual cost.
virtual void calcDiff(const std::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the derivatives of the residual cost.
Abstract class for residual models.