10 #ifndef CROCODDYL_CORE_NUMDIFF_COST_HPP_ 11 #define CROCODDYL_CORE_NUMDIFF_COST_HPP_ 13 #include <boost/function.hpp> 14 #include "crocoddyl/multibody/fwd.hpp" 15 #include "crocoddyl/core/cost-base.hpp" 19 template <
typename _Scalar>
22 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
24 typedef _Scalar Scalar;
32 typedef boost::function<void(const VectorXs&, const VectorXs&)> ReevaluationFunction;
49 virtual void calc(
const boost::shared_ptr<CostDataAbstract>& data,
const Eigen::Ref<const VectorXs>& x,
50 const Eigen::Ref<const VectorXs>& u);
55 virtual void calcDiff(
const boost::shared_ptr<CostDataAbstract>& data,
const Eigen::Ref<const VectorXs>& x,
56 const Eigen::Ref<const VectorXs>& u);
64 virtual boost::shared_ptr<CostDataAbstract>
createData(DataCollectorAbstract*
const data);
69 const boost::shared_ptr<Base>&
get_model()
const;
95 void set_reevals(
const std::vector<ReevaluationFunction>& reevals);
124 void assertStableStateFD(
const Eigen::Ref<const VectorXs>& );
127 template <
typename _Scalar>
129 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
131 typedef _Scalar Scalar;
138 template <
template <
typename Scalar>
class Model>
139 explicit CostDataNumDiffTpl(Model<Scalar>*
const model, DataCollectorAbstract*
const shared_data)
140 : Base(model, shared_data),
141 dx(model->get_state()->get_ndx()),
142 xp(model->get_state()->get_nx()),
144 up(model->get_nu()) {
150 const std::size_t ndx = model->get_model()->get_state()->get_ndx();
151 const std::size_t nu = model->get_model()->get_nu();
152 data_0 = model->get_model()->createData(shared_data);
153 for (std::size_t i = 0; i < ndx; ++i) {
154 data_x.push_back(model->get_model()->createData(shared_data));
156 for (std::size_t i = 0; i < nu; ++i) {
157 data_u.push_back(model->get_model()->createData(shared_data));
161 virtual ~CostDataNumDiffTpl() {}
163 using Base::activation;
180 std::vector<boost::shared_ptr<Base> >
data_x;
181 std::vector<boost::shared_ptr<Base> >
data_u;
189 #include "crocoddyl/core/numdiff/cost.hxx" 191 #endif // CROCODDYL_CORE_NUMDIFF_COST_HPP_ Abstract class for cost models.
virtual ~CostModelNumDiffTpl()
Initialize the numdiff cost model.
bool get_with_gauss_approx()
Identify if the Gauss approximation is going to be used or not.
virtual boost::shared_ptr< CostDataAbstract > createData(DataCollectorAbstract *const data)
Create a Data object.
CostModelNumDiffTpl(const boost::shared_ptr< Base > &model)
Initialize the numdiff cost model.
std::vector< boost::shared_ptr< Base > > data_x
The temporary data associated with the state variation.
boost::shared_ptr< ActivationModelAbstract > activation_
Activation model.
void set_disturbance(const Scalar disturbance)
Modify the disturbance value used by the numdiff routine.
std::vector< boost::shared_ptr< Base > > data_u
The temporary data associated with the control variation.
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...
VectorXs up
The integrated control from the disturbance on one DoF "\f$ \int u du_i = u + du \f$".
VectorXs du
Control disturbance.
VectorXs xp
The integrated state from the disturbance on one DoF "\f$ \int x dx_i \f$".
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.
const Scalar get_disturbance() const
Return the disturbance value used by the numdiff routine.
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.
Scalar disturbance_
Numerical disturbance used in the numerical differentiation.
const boost::shared_ptr< Base > & get_model() const
Return the original cost model.
VectorXs unone_
No control vector.
std::vector< ReevaluationFunction > reevals_
Functions that needs execution before calc or calcDiff.
VectorXs dx
State disturbance.
boost::shared_ptr< Base > data_0
The data at the approximation point.
std::size_t nu_
Control dimension.
boost::shared_ptr< StateAbstract > state_
State description.
boost::shared_ptr< Base > model_
Model of the cost.