11 #ifndef CROCODDYL_CORE_NUMDIFF_ACTION_HPP_
12 #define CROCODDYL_CORE_NUMDIFF_ACTION_HPP_
14 #include "crocoddyl/core/action-base.hpp"
15 #include "crocoddyl/core/fwd.hpp"
43 template <
typename _Scalar>
46 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
49 typedef _Scalar Scalar;
66 bool with_gauss_approx =
false);
72 virtual void calc(
const std::shared_ptr<ActionDataAbstract>& data,
73 const Eigen::Ref<const VectorXs>& x,
74 const Eigen::Ref<const VectorXs>& u)
override;
80 virtual void calc(
const std::shared_ptr<ActionDataAbstract>& data,
81 const Eigen::Ref<const VectorXs>& x)
override;
86 virtual void calcDiff(
const std::shared_ptr<ActionDataAbstract>& data,
87 const Eigen::Ref<const VectorXs>& x,
88 const Eigen::Ref<const VectorXs>& u)
override;
94 virtual void calcDiff(
const std::shared_ptr<ActionDataAbstract>& data,
95 const Eigen::Ref<const VectorXs>& x)
override;
100 virtual std::shared_ptr<ActionDataAbstract>
createData()
override;
105 virtual void quasiStatic(
const std::shared_ptr<ActionDataAbstract>& data,
106 Eigen::Ref<VectorXs> u,
107 const Eigen::Ref<const VectorXs>& x,
108 const std::size_t maxiter = 100,
109 const Scalar tol = Scalar(1e-9))
override;
120 template <
typename NewScalar>
150 virtual void print(std::ostream& os)
const override;
173 void assertStableStateFD(
const Eigen::Ref<const VectorXs>& x);
175 std::shared_ptr<Base> model_;
181 bool with_gauss_approx_;
185 template <
typename _Scalar>
187 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
189 typedef _Scalar Scalar;
201 template <
template <
typename Scalar>
class Model>
204 Rx(model->get_model()->get_nr(),
205 model->get_model()->get_state()->get_ndx()),
206 Ru(model->get_model()->get_nr(), model->get_model()->get_nu()),
207 dx(model->get_model()->get_state()->get_ndx()),
208 du(model->get_model()->get_nu()),
209 xp(model->get_model()->get_state()->get_nx()) {
216 const std::size_t ndx = model->get_model()->get_state()->get_ndx();
217 const std::size_t nu = model->get_model()->get_nu();
218 data_0 = model->get_model()->createData();
219 for (std::size_t i = 0; i < ndx; ++i) {
220 data_x.push_back(model->get_model()->createData());
222 for (std::size_t i = 0; i < nu; ++i) {
223 data_u.push_back(model->get_model()->createData());
249 Scalar xuh_hess_pow2;
257 std::vector<std::shared_ptr<Base> >
259 std::vector<std::shared_ptr<Base> >
268 #include "crocoddyl/core/numdiff/action.hxx"
Abstract class for 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 an action model.
const std::shared_ptr< Base > & get_model() const
Return the acton model that we use to numerical differentiate.
virtual void calc(const std::shared_ptr< ActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u) override
Compute the next state and cost value.
virtual std::shared_ptr< ActionDataAbstract > createData() override
Create the action data.
virtual void calcDiff(const std::shared_ptr< ActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x) override
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.
ActionModelNumDiffTpl(std::shared_ptr< Base > model, bool with_gauss_approx=false)
Initialize the numdiff action model.
virtual void quasiStatic(const std::shared_ptr< ActionDataAbstract > &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.
ActionModelNumDiffTpl< NewScalar > cast() const
Cast the action numdiff model to a different scalar type.
virtual void calc(const std::shared_ptr< ActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x) override
virtual void calcDiff(const std::shared_ptr< ActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u) override
Compute the derivatives of the dynamics and cost functions.
virtual void print(std::ostream &os) const override
Print relevant information of the diff-action numdiff model.
VectorXs xnext
evolution state
MatrixXs Fx
Jacobian of the dynamics w.r.t. the state .
MatrixXs Fu
Jacobian of the dynamics w.r.t. the control .
MatrixXs Luu
Hessian of the cost w.r.t. the control .
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 .
Scalar x_norm
Norm of the state vector.
MatrixXs Ru
Cost residual jacobian: .
MatrixXs Rx
Cost residual jacobian: .
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 .
VectorXs du
Control disturbance.
std::shared_ptr< Base > data_0
The data that contains the final results.
ActionDataNumDiffTpl(Model< Scalar > *const model)
Initialize the numdiff action data.
VectorXs dx
State disturbance.