9 #ifndef CROCODDYL_CORE_NUMDIFF_RESIDUAL_HPP_
10 #define CROCODDYL_CORE_NUMDIFF_RESIDUAL_HPP_
12 #include <boost/function.hpp>
14 #include "crocoddyl/core/residual-base.hpp"
15 #include "crocoddyl/multibody/fwd.hpp"
28 template <
typename _Scalar>
31 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
34 typedef _Scalar Scalar;
42 typedef boost::function<void(
const VectorXs&,
const VectorXs&)>
61 virtual void calc(
const std::shared_ptr<ResidualDataAbstract>& data,
62 const Eigen::Ref<const VectorXs>& x,
63 const Eigen::Ref<const VectorXs>& u)
override;
69 virtual void calc(
const std::shared_ptr<ResidualDataAbstract>& data,
70 const Eigen::Ref<const VectorXs>& x)
override;
75 virtual void calcDiff(
const std::shared_ptr<ResidualDataAbstract>& data,
76 const Eigen::Ref<const VectorXs>& x,
77 const Eigen::Ref<const VectorXs>& u)
override;
84 virtual void calcDiff(
const std::shared_ptr<ResidualDataAbstract>& data,
85 const Eigen::Ref<const VectorXs>& x)
override;
90 virtual std::shared_ptr<ResidualDataAbstract>
createData(
93 template <
typename NewScalar>
120 void set_reevals(
const std::vector<ReevaluationFunction>& reevals);
139 void assertStableStateFD(
const Eigen::Ref<const VectorXs>& );
141 std::shared_ptr<Base> model_;
145 std::vector<ReevaluationFunction>
149 template <
typename _Scalar>
151 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
153 typedef _Scalar Scalar;
166 template <
template <
typename Scalar>
class Model>
169 :
Base(model, shared_data),
170 dx(model->get_state()->get_ndx()),
171 xp(model->get_state()->get_nx()),
173 up(model->get_nu()) {
179 const std::size_t& ndx = model->get_model()->get_state()->get_ndx();
180 const std::size_t& nu = model->get_model()->get_nu();
181 data_0 = model->get_model()->createData(shared_data);
182 for (std::size_t i = 0; i < ndx; ++i) {
183 data_x.push_back(model->get_model()->createData(shared_data));
185 for (std::size_t i = 0; i < nu; ++i) {
186 data_u.push_back(model->get_model()->createData(shared_data));
209 std::vector<std::shared_ptr<Base> >
211 std::vector<std::shared_ptr<Base> >
220 #include "crocoddyl/core/numdiff/residual.hxx"
Abstract class for residual models.
std::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 residual model.
const std::shared_ptr< Base > & get_model() const
Return the original residual model.
const Scalar get_disturbance() const
Return the disturbance constant used by the numerical differentiation routine.
virtual void calc(const std::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &x) override
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...
void set_disturbance(const Scalar disturbance)
Modify the disturbance constant used by the numerical differentiation routine.
virtual void calcDiff(const std::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u) override
Compute the Jacobian of the residual vector.
virtual ~ResidualModelNumDiffTpl()=default
Initialize the numdiff residual model.
ResidualModelNumDiffTpl(const std::shared_ptr< Base > &model)
Initialize the numdiff residual model.
virtual void calc(const std::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u) override
Compute the residual vector.
virtual std::shared_ptr< ResidualDataAbstract > createData(DataCollectorAbstract *const data) override
Create the residual data.
virtual void calcDiff(const std::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &x) override
MatrixXs Ru
Jacobian of the residual vector with respect the control.
MatrixXs Rx
Jacobian of the residual vector with respect the state.
DataCollectorAbstract * shared
Shared data allocated by the action model.
VectorXs r
Residual vector.
Scalar x_norm
Norm of the state vector.
std::vector< std::shared_ptr< Base > > data_x
The temporary data associated with the state variation.
Scalar uh_jac
Disturbance value used for computing .
std::vector< std::shared_ptr< Base > > data_u
The temporary data associated with the control variation.
Scalar xh_jac
Disturbance value used for computing .
ResidualDataNumDiffTpl(Model< Scalar > *const model, DataCollectorAbstract *const shared_data)
Initialize the numdiff residual data.
VectorXs du
Control disturbance.
std::shared_ptr< Base > data_0
The data at the approximation point.
VectorXs dx
State disturbance.