crocoddyl 1.9.0
Contact RObot COntrol by Differential DYnamic programming Library (Crocoddyl)
 
Loading...
Searching...
No Matches
residual.hpp
1
2// BSD 3-Clause License
3//
4// Copyright (C) 2021, University of Edinburgh
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/fwd.hpp"
13#include "crocoddyl/core/cost-base.hpp"
14#include "crocoddyl/core/residual-base.hpp"
15
16namespace crocoddyl {
17
35template <typename _Scalar>
37 public:
38 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
39
40 typedef _Scalar Scalar;
48 typedef typename MathBase::VectorXs VectorXs;
49 typedef typename MathBase::MatrixXs MatrixXs;
50
58 CostModelResidualTpl(boost::shared_ptr<typename Base::StateAbstract> state,
59 boost::shared_ptr<ActivationModelAbstract> activation,
60 boost::shared_ptr<ResidualModelAbstract> residual);
69 CostModelResidualTpl(boost::shared_ptr<typename Base::StateAbstract> state,
70 boost::shared_ptr<ResidualModelAbstract> residual);
71 virtual ~CostModelResidualTpl();
72
80 virtual void calc(const boost::shared_ptr<CostDataAbstract>& data, const Eigen::Ref<const VectorXs>& x,
81 const Eigen::Ref<const VectorXs>& u);
82
92 virtual void calc(const boost::shared_ptr<CostDataAbstract>& data, const Eigen::Ref<const VectorXs>& x);
93
101 virtual void calcDiff(const boost::shared_ptr<CostDataAbstract>& data, const Eigen::Ref<const VectorXs>& x,
102 const Eigen::Ref<const VectorXs>& u);
103
113 virtual void calcDiff(const boost::shared_ptr<CostDataAbstract>& data, const Eigen::Ref<const VectorXs>& x);
114
118 virtual boost::shared_ptr<CostDataAbstract> createData(DataCollectorAbstract* const data);
119
125 virtual void print(std::ostream& os) const;
126
127 protected:
128 using Base::activation_;
129 using Base::nu_;
130 using Base::residual_;
131 using Base::state_;
132 using Base::unone_;
133};
134
135template <typename _Scalar>
136struct CostDataResidualTpl : public CostDataAbstractTpl<_Scalar> {
137 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
138
139 typedef _Scalar Scalar;
143 typedef typename MathBase::MatrixXs MatrixXs;
144
145 template <template <typename Scalar> class Model>
146 CostDataResidualTpl(Model<Scalar>* const model, DataCollectorAbstract* const data)
147 : Base(model, data),
148 Arr_Rx(model->get_residual()->get_nr(), model->get_state()->get_ndx()),
149 Arr_Ru(model->get_residual()->get_nr(), model->get_nu()) {
150 Arr_Rx.setZero();
151 Arr_Ru.setZero();
152 }
153
154 MatrixXs Arr_Rx;
155 MatrixXs Arr_Ru;
156 using Base::activation;
157 using Base::cost;
158 using Base::Lu;
159 using Base::Luu;
160 using Base::Lx;
161 using Base::Lxu;
162 using Base::Lxx;
163 using Base::residual;
164 using Base::shared;
165};
166
167} // namespace crocoddyl
168
169/* --- Details -------------------------------------------------------------- */
170/* --- Details -------------------------------------------------------------- */
171/* --- Details -------------------------------------------------------------- */
172#include "crocoddyl/core/costs/residual.hxx"
173
174#endif // CROCODDYL_CORE_COSTS_RESIDUAL_COST_HPP_
Abstract class for cost models.
Definition: cost-base.hpp:49
boost::shared_ptr< ActivationModelAbstract > activation_
Activation model.
Definition: cost-base.hpp:241
boost::shared_ptr< StateAbstract > state_
State description.
Definition: cost-base.hpp:240
std::size_t nu_
Control dimension.
Definition: cost-base.hpp:243
VectorXs unone_
No control vector.
Definition: cost-base.hpp:244
boost::shared_ptr< ResidualModelAbstract > residual_
Residual model.
Definition: cost-base.hpp:242
Residual-based cost.
Definition: residual.hpp:36
CostModelResidualTpl(boost::shared_ptr< typename Base::StateAbstract > state, boost::shared_ptr< ResidualModelAbstract > residual)
Initialize the residual cost model.
virtual void calcDiff(const boost::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 print(std::ostream &os) const
Print relevant information of the cost-residual model.
virtual void calc(const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the residual cost.
virtual void calcDiff(const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the derivatives of the residual cost.
virtual boost::shared_ptr< CostDataAbstract > createData(DataCollectorAbstract *const data)
Create the residual cost data.
CostModelResidualTpl(boost::shared_ptr< typename Base::StateAbstract > state, boost::shared_ptr< ActivationModelAbstract > activation, boost::shared_ptr< ResidualModelAbstract > residual)
Initialize the residual cost model.
virtual void calc(const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the residual cost based on state only.
Abstract class for residual models.