11 #ifndef CROCODDYL_CORE_NUMDIFF_DIFF_ACTION_HPP_
12 #define CROCODDYL_CORE_NUMDIFF_DIFF_ACTION_HPP_
14 #include "crocoddyl/core/diff-action-base.hpp"
43 template <
typename _Scalar>
47 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
51 typedef _Scalar Scalar;
57 typedef typename MathBase::VectorXs VectorXs;
58 typedef typename MathBase::MatrixXs MatrixXs;
69 std::shared_ptr<Base> model,
const bool with_gauss_approx =
false);
75 virtual void calc(
const std::shared_ptr<DifferentialActionDataAbstract>& data,
76 const Eigen::Ref<const VectorXs>& x,
77 const Eigen::Ref<const VectorXs>& u)
override;
84 virtual void calc(
const std::shared_ptr<DifferentialActionDataAbstract>& data,
85 const Eigen::Ref<const VectorXs>& x)
override;
91 const std::shared_ptr<DifferentialActionDataAbstract>& data,
92 const Eigen::Ref<const VectorXs>& x,
93 const Eigen::Ref<const VectorXs>& u)
override;
101 const std::shared_ptr<DifferentialActionDataAbstract>& data,
102 const Eigen::Ref<const VectorXs>& x)
override;
107 virtual std::shared_ptr<DifferentialActionDataAbstract>
createData()
override;
118 template <
typename NewScalar>
125 const std::shared_ptr<DifferentialActionDataAbstract>& data,
126 Eigen::Ref<VectorXs> u,
const Eigen::Ref<const VectorXs>& x,
127 const std::size_t maxiter = 100,
128 const Scalar tol = Scalar(1e-9))
override;
158 virtual void print(std::ostream& os)
const override;
170 void assertStableStateFD(
const Eigen::Ref<const VectorXs>& x);
171 std::shared_ptr<Base> model_;
172 bool with_gauss_approx_;
179 template <
typename _Scalar>
182 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
184 typedef _Scalar Scalar;
187 typedef typename MathBase::VectorXs VectorXs;
188 typedef typename MathBase::MatrixXs MatrixXs;
196 template <
template <
typename Scalar>
class Model>
199 Rx(model->get_model()->get_nr(),
200 model->get_model()->get_state()->get_ndx()),
201 Ru(model->get_model()->get_nr(), model->get_model()->get_nu()),
202 dx(model->get_model()->get_state()->get_ndx()),
203 du(model->get_model()->get_nu()),
204 xp(model->get_model()->get_state()->get_nx()) {
211 const std::size_t ndx = model->get_model()->get_state()->get_ndx();
212 const std::size_t nu = model->get_model()->get_nu();
213 data_0 = model->get_model()->createData();
214 for (std::size_t i = 0; i < ndx; ++i) {
215 data_x.push_back(model->get_model()->createData());
217 for (std::size_t i = 0; i < nu; ++i) {
218 data_u.push_back(model->get_model()->createData());
233 Scalar xuh_hess_pow2;
239 std::shared_ptr<Base> data_0;
240 std::vector<std::shared_ptr<Base> > data_x;
241 std::vector<std::shared_ptr<Base> > data_u;
266 #include "crocoddyl/core/numdiff/diff-action.hxx"
268 CROCODDYL_DECLARE_EXTERN_TEMPLATE_CLASS(
270 CROCODDYL_DECLARE_EXTERN_TEMPLATE_STRUCT(
Abstract class for differential action model.
std::shared_ptr< StateAbstract > state_
Model of the state.
VectorXs u_lb_
Lower control limits.
VectorXs u_ub_
Upper control limits.
std::size_t nu_
Control dimension.
std::size_t nr_
Dimension of the cost residual.
This class computes the numerical differentiation of a differential action model.
const std::shared_ptr< Base > & get_model() const
Return the differential acton model that we use to numerical differentiate.
virtual void calcDiff(const std::shared_ptr< DifferentialActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x) override
virtual void calc(const std::shared_ptr< DifferentialActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u) override
Compute the system acceleration and cost value.
const Scalar get_disturbance() const
Return the disturbance constant used in the numerical differentiation routine.
bool get_with_gauss_approx()
Identify if the Gauss approximation is going to be used or not.
void set_disturbance(const Scalar disturbance)
Modify the disturbance constant used in the numerical differentiation routine.
virtual std::shared_ptr< DifferentialActionDataAbstract > createData() override
Create the differential action data.
DifferentialActionModelNumDiffTpl< NewScalar > cast() const
Cast the diff-action numdiff model to a different scalar type.
DifferentialActionModelNumDiffTpl(std::shared_ptr< Base > model, const bool with_gauss_approx=false)
Initialize the numdiff differential action model.
virtual void calc(const std::shared_ptr< DifferentialActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x) override
virtual void quasiStatic(const std::shared_ptr< DifferentialActionDataAbstract > &data, Eigen::Ref< VectorXs > u, const Eigen::Ref< const VectorXs > &x, const std::size_t maxiter=100, const Scalar tol=Scalar(1e-9)) override
Computes the quasic static commands.
virtual void print(std::ostream &os) const override
Print relevant information of the action numdiff model.
virtual void calcDiff(const std::shared_ptr< DifferentialActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u) override
Compute the derivatives of the dynamics and cost functions.
MatrixXs Fx
Jacobian of the dynamics w.r.t. the state .
MatrixXs Fu
Jacobian of the dynamics w.r.t. the control .
VectorXs h
Equality constraint values.
MatrixXs Luu
Hessian of the cost w.r.t. the control .
VectorXs g
Inequality constraint values.
VectorXs Lx
Jacobian of the cost w.r.t. the state .
MatrixXs Lxx
Hessian of the cost w.r.t. the state .
VectorXs Lu
Jacobian of the cost w.r.t. the control .
VectorXs xout
evolution state
DifferentialActionDataNumDiffTpl(Model< Scalar > *const model)
Construct a new ActionDataNumDiff object.
Scalar x_norm
Norm of the state vector.
Scalar uh_jac
Disturbance value used for computing .
Scalar xh_jac
Disturbance value used for computing .