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
33 typedef _Scalar Scalar;
41 typedef boost::function<void(
const VectorXs&,
const VectorXs&)>
60 virtual void calc(
const boost::shared_ptr<ResidualDataAbstract>& data,
61 const Eigen::Ref<const VectorXs>& x,
62 const Eigen::Ref<const VectorXs>& u);
68 virtual void calc(
const boost::shared_ptr<ResidualDataAbstract>& data,
69 const Eigen::Ref<const VectorXs>& x);
74 virtual void calcDiff(
const boost::shared_ptr<ResidualDataAbstract>& data,
75 const Eigen::Ref<const VectorXs>& x,
76 const Eigen::Ref<const VectorXs>& u);
83 virtual void calcDiff(
const boost::shared_ptr<ResidualDataAbstract>& data,
84 const Eigen::Ref<const VectorXs>& x);
89 virtual boost::shared_ptr<ResidualDataAbstract>
createData(
116 void set_reevals(
const std::vector<ReevaluationFunction>& reevals);
135 void assertStableStateFD(
const Eigen::Ref<const VectorXs>& );
137 boost::shared_ptr<Base> model_;
141 std::vector<ReevaluationFunction>
145 template <
typename _Scalar>
147 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
149 typedef _Scalar Scalar;
162 template <
template <
typename Scalar>
class Model>
165 :
Base(model, shared_data),
166 dx(model->get_state()->get_ndx()),
167 xp(model->get_state()->get_nx()),
169 up(model->get_nu()) {
175 const std::size_t& ndx = model->get_model()->get_state()->get_ndx();
176 const std::size_t& nu = model->get_model()->get_nu();
177 data_0 = model->get_model()->createData(shared_data);
178 for (std::size_t i = 0; i < ndx; ++i) {
179 data_x.push_back(model->get_model()->createData(shared_data));
181 for (std::size_t i = 0; i < nu; ++i) {
182 data_u.push_back(model->get_model()->createData(shared_data));
205 std::vector<boost::shared_ptr<Base> >
207 std::vector<boost::shared_ptr<Base> >
216 #include "crocoddyl/core/numdiff/residual.hxx"
Abstract class for residual models.
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 residual model.
virtual void calc(const boost::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
const Scalar get_disturbance() const
Return the disturbance constant used by the numerical differentiation routine.
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 void calcDiff(const boost::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
void set_disturbance(const Scalar disturbance)
Modify the disturbance constant used by the numerical differentiation routine.
ResidualModelNumDiffTpl(const boost::shared_ptr< Base > &model)
Initialize the numdiff residual model.
virtual void calc(const boost::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the residual vector.
virtual void calcDiff(const boost::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the Jacobian of the residual vector.
const boost::shared_ptr< Base > & get_model() const
Return the original residual model.
virtual boost::shared_ptr< ResidualDataAbstract > createData(DataCollectorAbstract *const data)
Create the residual data.
virtual ~ResidualModelNumDiffTpl()
Initialize the numdiff residual model.
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.
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 .
ResidualDataNumDiffTpl(Model< Scalar > *const model, DataCollectorAbstract *const shared_data)
Initialize the numdiff residual data.
VectorXs du
Control disturbance.
std::vector< boost::shared_ptr< Base > > data_x
The temporary data associated with the state variation.
VectorXs dx
State disturbance.