12 #ifndef CROCODDYL_CORE_NUMDIFF_COST_HPP_
13 #define CROCODDYL_CORE_NUMDIFF_COST_HPP_
15 #include <boost/function.hpp>
17 #include "crocoddyl/core/cost-base.hpp"
18 #include "crocoddyl/multibody/fwd.hpp"
33 template <
typename _Scalar>
36 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
38 typedef _Scalar Scalar;
46 typedef boost::function<void(
const VectorXs&,
const VectorXs&)>
65 virtual void calc(
const boost::shared_ptr<CostDataAbstract>& data,
66 const Eigen::Ref<const VectorXs>& x,
67 const Eigen::Ref<const VectorXs>& u);
73 virtual void calc(
const boost::shared_ptr<CostDataAbstract>& data,
74 const Eigen::Ref<const VectorXs>& x);
79 virtual void calcDiff(
const boost::shared_ptr<CostDataAbstract>& data,
80 const Eigen::Ref<const VectorXs>& x,
81 const Eigen::Ref<const VectorXs>& u);
87 virtual void calcDiff(
const boost::shared_ptr<CostDataAbstract>& data,
88 const Eigen::Ref<const VectorXs>& x);
131 void set_reevals(
const std::vector<ReevaluationFunction>& reevals);
151 void assertStableStateFD(
const Eigen::Ref<const VectorXs>& );
153 boost::shared_ptr<Base> model_;
157 std::vector<ReevaluationFunction>
161 template <
typename _Scalar>
163 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
165 typedef _Scalar Scalar;
178 template <
template <
typename Scalar>
class Model>
181 :
Base(model, shared_data),
182 dx(model->get_state()->get_ndx()),
183 xp(model->get_state()->get_nx()),
185 up(model->get_nu()) {
191 const std::size_t ndx = model->get_model()->get_state()->get_ndx();
192 const std::size_t nu = model->get_model()->get_nu();
193 data_0 = model->get_model()->createData(shared_data);
194 for (std::size_t i = 0; i < ndx; ++i) {
195 data_x.push_back(model->get_model()->createData(shared_data));
197 for (std::size_t i = 0; i < nu; ++i) {
198 data_u.push_back(model->get_model()->createData(shared_data));
204 using Base::activation;
211 using Base::residual;
226 std::vector<boost::shared_ptr<Base> >
228 std::vector<boost::shared_ptr<Base> >
237 #include "crocoddyl/core/numdiff/cost.hxx"
Abstract class for cost models.
boost::shared_ptr< ActivationModelAbstract > activation_
Activation model.
boost::shared_ptr< StateAbstract > state_
State description.
std::size_t nu_
Control dimension.
VectorXs unone_
No control vector.
This class computes the numerical differentiation of a cost model.
virtual boost::shared_ptr< CostDataAbstract > createData(DataCollectorAbstract *const data)
Create a numdiff cost data.
virtual void calcDiff(const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
const Scalar get_disturbance() const
Return the disturbance constant used by the numerical differentiation routine.
bool get_with_gauss_approx()
Identify if the Gauss approximation is going to be used or not.
void set_reevals(const std::vector< ReevaluationFunction > &reevals)
Register functions that updates the shared data computed for a system rollout The updated data is use...
virtual ~CostModelNumDiffTpl()
Initialize the numdiff cost model.
void set_disturbance(const Scalar disturbance)
Modify the disturbance constant used by the numerical differentiation routine.
virtual void calc(const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the cost value and its residual vector.
CostModelNumDiffTpl(const boost::shared_ptr< Base > &model)
Initialize the numdiff cost model.
virtual void calcDiff(const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the Jacobian and Hessian of cost and its residual vector.
const boost::shared_ptr< Base > & get_model() const
Return the original cost model.
virtual void calc(const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
std::vector< boost::shared_ptr< Base > > data_u
The temporary data associated with the control variation.
Scalar x_norm
Norm of the state vector.
boost::shared_ptr< Base > data_0
The data at the approximation point.
Scalar uh_jac
Disturbance value used for computing .
Scalar xh_jac
Disturbance value used for computing .
VectorXs du
Control disturbance.
std::vector< boost::shared_ptr< Base > > data_x
The temporary data associated with the state variation.
VectorXs dx
State disturbance.
CostDataNumDiffTpl(Model< Scalar > *const model, DataCollectorAbstract *const shared_data)
Initialize the numdiff cost data.